Skip to content

Commit 3339e88

Browse files
committed
Improve Alert API
1 parent 90d7de9 commit 3339e88

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/Alert.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,34 @@ export type AlertProps = {
2020
/** Default h3 */
2121
as?: `h${2 | 3 | 4 | 5 | 6}`;
2222
classes?: Partial<Record<"root" | "title" | "description" | "close", string>>;
23-
} & (AlertProps.Md | AlertProps.Sm) &
23+
} & (AlertProps.DefaultSize | AlertProps.Small) &
2424
(AlertProps.NonClosable | AlertProps.Closable);
2525

2626
export namespace AlertProps {
27-
export type Md = {
28-
isSmall?: false;
27+
export type DefaultSize = {
28+
/** Default false */
29+
small?: false;
2930
title: NonNullable<ReactNode>;
3031
description?: NonNullable<ReactNode>;
3132
};
3233

33-
export type Sm = {
34-
isSmall: true;
34+
export type Small = {
35+
/** Default false */
36+
small: true;
3537
title?: NonNullable<ReactNode>;
3638
description: NonNullable<ReactNode>;
3739
};
3840

3941
export type NonClosable = {
40-
isClosable?: false;
41-
isClosed?: undefined;
42-
onClose?: undefined;
42+
/** Default false */
43+
closable?: false;
44+
isClosed?: never;
45+
onClose?: never;
4346
};
4447

4548
export type Closable = {
46-
isClosable: true;
49+
/** Default false */
50+
closable: true;
4751
} & (Closable.Controlled | Closable.Uncontrolled);
4852

4953
export namespace Closable {
@@ -53,7 +57,7 @@ export namespace AlertProps {
5357
};
5458

5559
export type Uncontrolled = {
56-
isClosed?: undefined;
60+
isClosed?: never;
5761
onClose?: () => void;
5862
};
5963
}
@@ -73,10 +77,10 @@ export const Alert = memo(
7377
severity,
7478
as: HtmlTitleTag = "h3",
7579
classes = {},
76-
isSmall,
80+
small: isSmall,
7781
title,
7882
description,
79-
isClosable = false,
83+
closable: isClosable = false,
8084
isClosed: props_isClosed,
8185
onClose,
8286
...rest

stories/Alert.stories.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const { meta, getStory } = getStoryFactory<AlertProps>({
2929
"description": {
3030
"description": "Required when the `<Alert isSmall />`"
3131
},
32-
"isClosable": {
32+
"closable": {
3333
"description": "If the modal should have a close button"
3434
},
3535
"onClose": {
@@ -51,18 +51,18 @@ export default meta;
5151

5252
export const Default = getStory({
5353
"severity": "success",
54-
"isSmall": false,
54+
"small": false,
5555
"title": "Message successfully sent",
5656
"description": "Everything went well",
57-
"isClosable": true,
57+
"closable": true,
5858
"isClosed": undefined,
5959
...logCallbacks(["onClose"])
6060
});
6161

6262
export const SmallDescriptionOnlyInfo = getStory(
6363
{
6464
"severity": "info",
65-
"isSmall": true,
65+
"small": true,
6666
"description": "This is the description"
6767
},
6868
{
@@ -84,5 +84,5 @@ export const ClosableError = getStory({
8484
"severity": "error",
8585
"title": "This is the title",
8686
"description": "This is the description",
87-
"isClosable": true
87+
"closable": true
8888
});

0 commit comments

Comments
 (0)