Skip to content

Commit b766fc4

Browse files
committed
feat: add Dialog component
1 parent 4dcd26d commit b766fc4

10 files changed

Lines changed: 169 additions & 5 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
@use "../theme/base" as *;
2+
3+
/*
4+
* Card
5+
*/
6+
.#{$shale}dialog {
7+
--#{$shale}dialog-transition-duration: 0.125s;
8+
9+
transition:
10+
display var(--#{$shale}dialog-transition-duration) allow-discrete,
11+
overlay var(--#{$shale}dialog-transition-duration) allow-discrete;
12+
animation: #{$shale}dialog-exit var(--#{$shale}dialog-transition-duration)
13+
ease-out;
14+
background: var(--#{$shale}background);
15+
border-radius: 0.4em;
16+
border: 1px solid var(--#{$shale}secondary-border);
17+
box-shadow: var(--#{$shale}shadow-puffy);
18+
padding: 0;
19+
20+
&::backdrop {
21+
animation: #{$shale}dialog-backdrop-exit
22+
var(--#{$shale}dialog-transition-duration) ease-in;
23+
transition: overlay var(--#{$shale}dialog-transition-duration)
24+
allow-discrete;
25+
background: var(--#{$shale}dialog-backdrop);
26+
}
27+
28+
&[open] {
29+
animation: #{$shale}dialog-enter var(--#{$shale}dialog-transition-duration)
30+
ease-out;
31+
}
32+
&[open]::backdrop {
33+
animation: #{$shale}dialog-backdrop-enter
34+
var(--#{$shale}dialog-transition-duration) ease-in;
35+
}
36+
}
37+
38+
@media (prefers-reduced-motion: reduce) {
39+
.#{$shale}dialog {
40+
transition: none !important;
41+
animation: none !important;
42+
43+
&::backdrop {
44+
transition: none !important;
45+
animation: none !important;
46+
}
47+
}
48+
}
49+
50+
@keyframes #{$shale}dialog-enter {
51+
from {
52+
opacity: 0;
53+
transform: scaleX(1) scaleY(0);
54+
}
55+
56+
to {
57+
opacity: 1;
58+
transform: scaleX(1) scaleY(1);
59+
}
60+
}
61+
62+
@keyframes #{$shale}dialog-exit {
63+
from {
64+
opacity: 1;
65+
transform: scaleX(1) scaleY(1);
66+
}
67+
68+
to {
69+
opacity: 0;
70+
transform: scaleX(1) scaleY(0);
71+
}
72+
}
73+
74+
@keyframes #{$shale}dialog-backdrop-enter {
75+
from {
76+
opacity: 0;
77+
}
78+
79+
to {
80+
opacity: 1;
81+
}
82+
}
83+
84+
@keyframes #{$shale}dialog-backdrop-exit {
85+
from {
86+
opacity: 1;
87+
}
88+
89+
to {
90+
opacity: 0;
91+
}
92+
}

workspaces/core/scss/shale.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
@use "components/card";
1818
@use "components/command-bar";
1919
@use "components/container";
20+
@use "components/dialog";
2021
@use "components/footer";
2122
@use "components/icons";
2223
@use "components/input";

workspaces/core/scss/theme/_contrast.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
--#{$shale}button-inset-border-hover: Highlight;
8383
--#{$shale}button-inset-border-active: Highlight;
8484

85+
/* Dialog */
86+
--#{$shale}dialog-backdrop: rgba(0, 0, 0, 0.85);
87+
8588
/* Input */
8689
--#{$shale}input-background: Canvas;
8790
--#{$shale}input-background-disabled: transparent;

workspaces/core/scss/theme/_dark.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
--#{$shale}button-inset-border-hover: #666;
8686
--#{$shale}button-inset-border-active: var(--#{$shale}accent-800);
8787

88+
/* Dialog */
89+
--#{$shale}dialog-backdrop: rgba(0, 0, 0, 0.6);
90+
8891
/* Input */
8992
--#{$shale}input-background: #555 linear-gradient(#606060, #555);
9093
--#{$shale}input-background-disabled: #444 linear-gradient(#444, #333);

workspaces/core/scss/theme/_light.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
--#{$shale}button-inset-border-hover: #fdfdfd;
8888
--#{$shale}button-inset-border-active: var(--#{$shale}accent-200);
8989

90+
/* Dialog */
91+
--#{$shale}dialog-backdrop: rgba(0, 0, 0, 0.6);
92+
9093
/* Input */
9194
--#{$shale}input-background: white linear-gradient(#f9f9f9, white);
9295
--#{$shale}input-background-disabled: #e3e3e3

workspaces/react/reports/react.api.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export type ComponentProp<C extends ElementType> = {
7272
// @alpha
7373
export const Container: PolymorphicComponent<"div", {}>;
7474

75+
// @alpha
76+
export const Dialog: FC<DialogProps>;
77+
78+
// @alpha (undocumented)
79+
export interface DialogProps extends React.HTMLAttributes<HTMLDialogElement> {
80+
}
81+
7582
// @alpha
7683
export const FlexContainer: PolymorphicComponent<"div", BaseFlexContainerProps>;
7784

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { FC } from "react";
2+
import { css } from "../utils/css";
3+
4+
/** @alpha */
5+
export interface DialogProps extends React.HTMLAttributes<HTMLDialogElement> {}
6+
7+
/**
8+
* The Dialog component is a modal dialog box that overlays the current page.
9+
* It is based on the native HTML `<dialog>` element and cannot be moved or resized.
10+
*
11+
* @example Basic usage with actions
12+
* ```tsx
13+
* <>
14+
* <Button type="button" command="show-modal" commandfor="my-dialog" aria-haspopup="dialog">Open Dialog</Button>
15+
*
16+
* <Dialog id="my-dialog" style={{ minWidth: "400px" }}>
17+
* <Header>
18+
* <HeaderTitle>
19+
* <HeaderText>This is a dialog</HeaderText>
20+
* </HeaderTitle>
21+
* <CaptionMenu>
22+
* <CaptionButton title="Close" type="button" commandfor="my-dialog" command="close">
23+
* ×
24+
* </CaptionButton>
25+
* </CaptionMenu>
26+
* </Header>
27+
* <FlexContainer variant="center">
28+
* <P>Here, have some actions to choose from.</P>
29+
* </FlexContainer>
30+
* <CommandBar variant="space-between" gutter>
31+
* <Button className="shale-v1-flex-grow">Nothing</Button>
32+
* <Button className="shale-v1-flex-grow">Nothing</Button>
33+
* <Button className="shale-v1-flex-grow" commandfor="my-dialog" command="close">Close</Button>
34+
* </CommandBar>
35+
* </Dialog>
36+
* </>
37+
* ```
38+
*
39+
* @alpha
40+
*/
41+
export const Dialog: FC<DialogProps> = (props) => {
42+
return (
43+
<dialog {...props} className={css("shale-v1-dialog", props.className)}>
44+
{props.children}
45+
</dialog>
46+
);
47+
};

workspaces/react/src/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
// Core types
99
export type {
10+
ComponentProp,
1011
PolymorphicComponent,
1112
PolymorphicComponentProp,
12-
ComponentProp,
1313
} from "./types/helpers";
14-
export type { StateVariant, ShadowVariant } from "./types/variants";
14+
export type { ShadowVariant, StateVariant } from "./types/variants";
1515

1616
// Layout & Structure
1717
export { Container, FlexContainer, FlexForm } from "./components/Container";
@@ -23,8 +23,12 @@ export type { FlexItemProps } from "./components/FlexItem";
2323
export { Card } from "./components/Card";
2424
export type { CardProps } from "./components/Card";
2525

26+
// Dialog
27+
export { Dialog } from "./components/Dialog";
28+
export type { DialogProps } from "./components/Dialog";
29+
2630
// Typography
27-
export { H1, H2, H3, H4, H5, H6, P, Code } from "./components/Typography";
31+
export { Code, H1, H2, H3, H4, H5, H6, P } from "./components/Typography";
2832

2933
// Forms & Inputs
3034
export { Button } from "./components/Button";
@@ -43,11 +47,11 @@ export { Link } from "./components/Link";
4347
export type { BaseLinkProps } from "./components/Link";
4448

4549
// Navigation
46-
export { Header, HeaderTitle, HeaderText } from "./components/Header";
50+
export { Header, HeaderText, HeaderTitle } from "./components/Header";
4751
export type { BaseHeaderProps } from "./components/Header";
4852

4953
export { Footer } from "./components/Footer";
50-
export { Nav, MenuBarButton } from "./components/Nav";
54+
export { MenuBarButton, Nav } from "./components/Nav";
5155

5256
export type { BaseMenuBarButtonProps } from "./components/Nav";
5357
export { SkipToContent } from "./components/SkipToContent";

workspaces/website/src/app/docs/components.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const components: Record<
1717
"/docs/card": { name: "Card", components: ["Card"] },
1818
"/docs/command-bar": { name: "CommandBar", components: ["CommandBar"] },
1919
"/docs/container": { name: "Container", components: ["Container"] },
20+
"/docs/dialog": { name: "Dialog", components: ["Dialog"] },
2021
"/docs/flex": {
2122
name: "Flex",
2223
components: ["FlexContainer", "FlexItem", "FlexForm"],
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { ComponentDocs } from "@/components/ComponentDoc/ComponentDoc";
2+
3+
export default () => <ComponentDocs pathname="/docs/dialog" />;

0 commit comments

Comments
 (0)