Skip to content

Commit 1ae0845

Browse files
committed
feat(Alert): require labelClose when closable is true
BREAKING CHANGE: Alert component now requires `labelClose` prop if `closable` is enabled. This will be converted into button aria-label attribute, make sure the passed value is properly translated.
1 parent ab88ee9 commit 1ae0845

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

packages/orbit-components/src/Alert/Alert.ct-story.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function TestAlert() {
4747
type={type}
4848
icon={false}
4949
closable
50+
labelClose="Close"
5051
inlineActions={
5152
<AlertButton type={type} href="#">
5253
Link
@@ -65,6 +66,7 @@ export function TestAlert() {
6566
type={type}
6667
icon={<Icons.Ai />}
6768
closable
69+
labelClose="Close"
6870
inlineActions={
6971
<AlertButton type={type} href="#">
7072
Link
@@ -90,7 +92,7 @@ export function TestAlert() {
9092
<h2>With multiline text, closable, without icon</h2>
9193
<div className="gap-400 flex flex-col items-stretch">
9294
{Object.values(TYPE_OPTIONS).map(type => (
93-
<Alert type={type} closable icon={false}>
95+
<Alert type={type} closable icon={false} labelClose="Close">
9496
<p>
9597
<TextLink type="primary">This is</TextLink> a primary textlink.
9698
<br />

packages/orbit-components/src/Alert/Alert.stories.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const meta: Meta<typeof Alert> = {
3131
closable: false,
3232
spaceAfter: SPACINGS_AFTER.SMALL,
3333
suppressed: false,
34+
labelClose: "Close",
3435
},
3536

3637
argTypes: {
@@ -295,7 +296,7 @@ export const Rtl: Story = {
295296
Make sure you know your visa requirements for these countries:
296297
</Heading>
297298
<List>
298-
<ListItem icon={<CountryFlag code="pl" name="Poland" />}>Poland</ListItem>
299+
<ListItem icon={<CountryFlag code="pl" />}>Poland</ListItem>
299300
</List>
300301
</Stack>
301302
<AlertButton type="info">Check Visa Requirements</AlertButton>

packages/orbit-components/src/Alert/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The table below contains all types of the props available in Alert component.
2626
| inlineActions | `React.Node` | | Renders action to a right side of a Alert. [See Functional specs](#functional-specs) |
2727
| onClose | `() => void \| Promise` | | Function for handling Alert onClose. |
2828
| spaceAfter | `enum` | | Additional `margin-bottom` after component. |
29-
| title | `Translation` | | The title of the Alert. |
29+
| title | `string` | | The title of the Alert. |
3030
| **type** | [`enum`](#enum) | `"info"` | The type of Alert. |
3131
| suppressed | `boolean` | | If `suppressed` is on, Alert will not have colored background |
3232
| labelClose | `string` | | The label of the close button. |

packages/orbit-components/src/Alert/__tests__/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("Alert", () => {
2121
it("should be closable", async () => {
2222
const onClose = jest.fn();
2323
render(
24-
<Alert onClose={onClose} closable>
24+
<Alert onClose={onClose} closable labelClose="Close">
2525
{message}
2626
</Alert>,
2727
);

packages/orbit-components/src/Alert/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const Alert = (props: Props) => {
130130
return (
131131
<div
132132
className={cx(
133+
"orbit-alert",
133134
"rounded-150 text-ink-dark font-base text-normal p-300 relative box-border flex w-full border border-t-[3px] leading-normal",
134135
"lm:border-s-[3px] lm:border-t",
135136
"tb:rounded-100",

packages/orbit-components/src/Alert/types.d.ts

+19-11
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@ import type * as React from "react";
66
import type * as Common from "../common/types";
77

88
export type Type = "info" | "success" | "warning" | "critical";
9-
export interface Props extends Common.Globals, Common.SpaceAfter {
10-
readonly type?: Type;
11-
readonly children?: React.ReactNode;
12-
readonly title?: Common.Translation;
13-
readonly icon?: React.ReactNode;
14-
readonly closable?: boolean;
15-
readonly inlineActions?: React.ReactNode;
16-
readonly labelClose?: string;
17-
readonly onClose?: Common.Callback;
18-
readonly suppressed?: boolean;
19-
}
9+
export type Props = Common.Globals &
10+
Common.SpaceAfter & {
11+
readonly type?: Type;
12+
readonly children?: React.ReactNode;
13+
readonly title?: Common.Translation;
14+
readonly icon?: React.ReactNode;
15+
readonly inlineActions?: React.ReactNode;
16+
readonly onClose?: Common.Callback;
17+
readonly suppressed?: boolean;
18+
/**
19+
* When closable is true, labelClose is required.
20+
*/
21+
} & (
22+
| {
23+
readonly closable: true;
24+
readonly labelClose: string;
25+
}
26+
| { readonly closable?: false; readonly labelClose?: string }
27+
);

0 commit comments

Comments
 (0)