Skip to content

Commit 492b8c3

Browse files
committedNov 25, 2022
chore: alert respond to pr comments
1 parent 71c526f commit 492b8c3

File tree

4 files changed

+79
-53
lines changed

4 files changed

+79
-53
lines changed
 

‎src/components/AerAlertDialog/AerAlertDialog.spec.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ describe("AlertDialog", () => {
2121
<button>Open the dialog</button>
2222
</AerAlertDialogTrigger>
2323
}
24-
dialogTitle={<>This is important!</>}
25-
dialogFooter={
24+
title={<>This is important!</>}
25+
footer={
2626
<AerAlertDialogFooter
27-
dialogCancel={<button>Cancel</button>}
28-
dialogAction={<button>Yes, do it!</button>}
27+
cancel={<button>Cancel</button>}
28+
action={<button>Yes, do it!</button>}
2929
/>
3030
}
31-
dialogContent={<p>Are you sure about all of that stuff?</p>}
31+
content={<p>Are you sure about all of that stuff?</p>}
3232
/>
3333
);
3434

@@ -50,14 +50,14 @@ describe("AlertDialog", () => {
5050
<button>Open the dialog</button>
5151
</AerAlertDialogTrigger>
5252
}
53-
dialogTitle={{ title: <>This is important!</>, hideTitle: true }}
54-
dialogFooter={
53+
title={{ title: <>This is important!</>, hideTitle: true }}
54+
footer={
5555
<AerAlertDialogFooter
56-
dialogCancel={<button>Cancel</button>}
57-
dialogAction={<button>Yes, do it!</button>}
56+
cancel={<button>Cancel</button>}
57+
action={<button>Yes, do it!</button>}
5858
/>
5959
}
60-
dialogContent={<p>Are you sure about all of that stuff?</p>}
60+
content={<p>Are you sure about all of that stuff?</p>}
6161
/>
6262
);
6363

@@ -79,14 +79,14 @@ describe("AlertDialog", () => {
7979
<button>Open the dialog</button>
8080
</AerAlertDialogTrigger>
8181
}
82-
dialogTitle={<>This is important!</>}
83-
dialogFooter={
82+
title={<>This is important!</>}
83+
footer={
8484
<AerAlertDialogFooter
85-
dialogCancel={<button onClick={cancelCb}>Cancel</button>}
86-
dialogAction={<button>Yes, do it!</button>}
85+
cancel={<button onClick={cancelCb}>Cancel</button>}
86+
action={<button>Yes, do it!</button>}
8787
/>
8888
}
89-
dialogContent={<p>Are you sure about all of that stuff?</p>}
89+
content={<p>Are you sure about all of that stuff?</p>}
9090
/>
9191
);
9292

@@ -109,14 +109,14 @@ describe("AlertDialog", () => {
109109
<button>Open the dialog</button>
110110
</AerAlertDialogTrigger>
111111
}
112-
dialogTitle={<>This is important!</>}
113-
dialogFooter={
112+
title={<>This is important!</>}
113+
footer={
114114
<AerAlertDialogFooter
115-
dialogCancel={<button>Cancel</button>}
116-
dialogAction={<button onClick={actionCb}>Yes, do it!</button>}
115+
cancel={<button>Cancel</button>}
116+
action={<button onClick={actionCb}>Yes, do it!</button>}
117117
/>
118118
}
119-
dialogContent={<p>Are you sure about all of that stuff?</p>}
119+
content={<p>Are you sure about all of that stuff?</p>}
120120
/>
121121
);
122122

‎src/components/AerAlertDialog/AerAlertDialog.stories.tsx

+23-6
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ Default.args = {
2626
<AerButton>Open the dialog</AerButton>
2727
</AerAlertDialogTrigger>
2828
),
29-
dialogTitle: <>This is important!</>,
30-
dialogContent: <p>Are you sure about all of that stuff?</p>,
31-
dialogFooter: (
29+
title: <>This is important!</>,
30+
content: <p>Are you sure about all of that stuff?</p>,
31+
footer: (
3232
<AerAlertDialogFooter
3333
style={{ justifyContent: "space-between", display: "flex" }}
34-
dialogCancel={<AerButton variant="important">Cancel</AerButton>}
35-
dialogAction={<AerButton variant="primary">Yes, do it!</AerButton>}
34+
cancel={<AerButton variant="important">Cancel</AerButton>}
35+
action={<AerButton variant="primary">Yes, do it!</AerButton>}
3636
/>
3737
),
3838
};
@@ -61,4 +61,21 @@ export const LocalTheme: ComponentStory<any> = () => (
6161
</>
6262
);
6363

64-
// todo make hidden title version
64+
export const VisuallyHiddenTitle = Template.bind({});
65+
66+
VisuallyHiddenTitle.args = {
67+
trigger: (
68+
<AerAlertDialogTrigger>
69+
<AerButton>Open the dialog</AerButton>
70+
</AerAlertDialogTrigger>
71+
),
72+
title: { title: <>This is important!</>, hideTitle: true },
73+
content: <p>Are you sure about all of that stuff?</p>,
74+
footer: (
75+
<AerAlertDialogFooter
76+
style={{ justifyContent: "space-between", display: "flex" }}
77+
cancel={<AerButton variant="important">Cancel</AerButton>}
78+
action={<AerButton variant="primary">Yes, do it!</AerButton>}
79+
/>
80+
),
81+
};

‎src/components/AerAlertDialog/AerAlertDialog.tsx

+31-22
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,81 @@ export const AerAlertDialogTrigger = ({ children }: DefaultProps<"button">) => (
1010

1111
export interface AlertDialogFooterProps extends DefaultProps<"footer"> {
1212
// An element (ideally a button) to cancel the alert dialog
13-
dialogCancel?: ReactElement;
13+
cancel?: ReactElement;
1414
// An element (ideally a button) to trigger the alert dialog action
15-
dialogAction: ReactElement;
15+
action: ReactElement;
1616
}
1717

1818
export const AerAlertDialogFooter = ({
19-
dialogCancel,
20-
dialogAction,
19+
cancel,
20+
action,
2121
...rest
2222
}: AlertDialogFooterProps) => (
2323
<footer {...rest}>
24-
{dialogCancel ? (
25-
<AlertDialog.Cancel asChild>{dialogCancel}</AlertDialog.Cancel>
26-
) : null}
27-
<AlertDialog.Action asChild>{dialogAction}</AlertDialog.Action>
24+
{cancel ? <AlertDialog.Cancel asChild>{cancel}</AlertDialog.Cancel> : null}
25+
<AlertDialog.Action asChild>{action}</AlertDialog.Action>
2826
</footer>
2927
);
3028

31-
const elementIsReactElement = (element: any): element is ReactElement => {
32-
return "props" in element;
29+
type TitleShape = {
30+
title: React.ReactElement | string;
31+
hideTitle: boolean;
32+
};
33+
34+
const elementIsTitleShape = (element: any): element is TitleShape => {
35+
return (
36+
typeof element === "object" &&
37+
!Array.isArray(element) &&
38+
"hideTitle" in element
39+
);
3340
};
3441

3542
export interface AerAlertDialogProps extends DefaultProps<"div"> {
3643
// The trigger should be an `AlertDialogTrigger`
3744
trigger: ReactElement;
3845
// `dialogTitle` is an object of the title and whether to hide the title (this defaults to true). NOTE: This is placed in an `<h2>`.
39-
dialogTitle: ReactElement | { title: ReactElement; hideTitle?: boolean };
46+
title: ReactElement | TitleShape;
4047
// The body content of the alert. NOTE: This will take the form of the element that you pass in.
41-
dialogContent: ReactElement;
48+
content: ReactElement;
4249
// An element that displays in the dialog footer that contains an action and an optional cancel button
43-
dialogFooter: ReactElement;
50+
footer: ReactElement;
4451
}
4552
/**
4653
* The AlertDialog interrupts a user's workflow to communicate an important message that requires a response. *NOTE:* This is different from the Dialog component
4754
*/
4855
export const AerAlertDialog = ({
4956
className,
5057
trigger,
51-
dialogTitle,
52-
dialogFooter,
53-
dialogContent,
58+
title,
59+
footer,
60+
content,
5461
}: AerAlertDialogProps) => {
62+
console.log({ dialogTitle: title });
63+
5564
return (
5665
<AlertDialog.Root>
5766
{trigger}
5867
<AlertDialog.Portal>
5968
<div className={className}>
6069
<AlertDialog.Overlay className={styles.overlay} />
6170
<AlertDialog.Content className={cx(styles.content)}>
62-
{elementIsReactElement(dialogTitle) ? (
71+
{!elementIsTitleShape(title) ? (
6372
<AlertDialog.Title className={cx(styles.title)}>
64-
{dialogTitle}
73+
{title}
6574
</AlertDialog.Title>
6675
) : (
6776
<AlertDialog.Title
6877
className={cx(styles.title, {
69-
[styles.visuallyHidden]: dialogTitle.hideTitle === false,
78+
[styles.visuallyHidden]: title.hideTitle,
7079
})}
7180
>
72-
{dialogTitle.title}
81+
{title.title}
7382
</AlertDialog.Title>
7483
)}
7584
<AlertDialog.Description className={styles.description} asChild>
76-
{dialogContent}
85+
{content}
7786
</AlertDialog.Description>
78-
{dialogFooter}
87+
{footer}
7988
</AlertDialog.Content>
8089
</div>
8190
</AlertDialog.Portal>

‎src/main.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ root.render(
2323
<AerButton>Open the dialog</AerButton>
2424
</AerAlertDialogTrigger>
2525
}
26-
dialogTitle={<>This is important!</>}
27-
dialogFooter={
26+
title={<>This is important!</>}
27+
footer={
2828
<AerAlertDialogFooter
2929
className={styles.footer}
30-
dialogCancel={<AerButton variant="important">Cancel</AerButton>}
31-
dialogAction={<AerButton variant="primary">Yes, do it!</AerButton>}
30+
cancel={<AerButton variant="important">Cancel</AerButton>}
31+
action={<AerButton variant="primary">Yes, do it!</AerButton>}
3232
/>
3333
}
34-
dialogContent={<p>Are you sure about all of that stuff?</p>}
34+
content={<p>Are you sure about all of that stuff?</p>}
3535
/>
3636
</React.StrictMode>
3737
);

0 commit comments

Comments
 (0)
Please sign in to comment.