Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
add error variant for caption component
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry Archibald committed Mar 6, 2023
1 parent 2443dd4 commit 46e4c34
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions res/css/components/views/typography/_Caption.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ limitations under the License.
.mx_Caption {
font-size: $font-12px;
color: $secondary-content;

&.mx_Caption_error {
color: $alert;
}
}
11 changes: 9 additions & 2 deletions src/components/views/typography/Caption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import classNames from "classnames";
import React, { HTMLAttributes } from "react";

interface Props extends Omit<HTMLAttributes<HTMLSpanElement>, "className"> {
children: React.ReactNode;
isError?: boolean;
}

export const Caption: React.FC<Props> = ({ children, ...rest }) => {
export const Caption: React.FC<Props> = ({ children, isError, ...rest }) => {
return (
<span className="mx_Caption" {...rest}>
<span
className={classNames("mx_Caption", {
mx_Caption_error: isError,
})}
{...rest}
>
{children}
</span>
);
Expand Down
5 changes: 5 additions & 0 deletions test/components/views/typography/Caption-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe("<Caption />", () => {
expect({ container }).toMatchSnapshot();
});

it("renders an error message", () => {
const { container } = render(getComponent({ isError: true }));
expect({ container }).toMatchSnapshot();
});

it("renders react children", () => {
const children = (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Caption /> renders an error message 1`] = `
{
"container": <div>
<span
class="mx_Caption mx_Caption_error"
data-testid="test test id"
>
test
</span>
</div>,
}
`;

exports[`<Caption /> renders plain text children 1`] = `
{
"container": <div>
Expand Down

0 comments on commit 46e4c34

Please sign in to comment.