Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dialog] Create new component and hook #372

Merged
merged 107 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
577dcfc
Wrap the native dialog API
michaldudak Apr 29, 2024
774d060
Experiment
michaldudak Apr 29, 2024
d58c3ff
Directory structure
michaldudak May 1, 2024
b91aef2
Uncontrolled open/close
michaldudak May 1, 2024
e8d09d3
Wire up aria attributes
michaldudak May 1, 2024
369c620
Lint + proptypes
michaldudak May 1, 2024
f9b3ab8
closeOnClickOutside
michaldudak May 1, 2024
09fc8c4
Use ClickAwayListener
michaldudak May 3, 2024
cfdf07c
Trying out FocusTrap
michaldudak May 3, 2024
8a58db0
Use Floating UI to trap focus
michaldudak May 3, 2024
975edb8
useDialogRoot
michaldudak May 3, 2024
b5cfa50
Popup hook
michaldudak May 6, 2024
a315473
Fix Fragment props warning
michaldudak May 6, 2024
91bac5b
useBaseUIComponentRenderer
michaldudak May 6, 2024
1621d04
More hooks
michaldudak May 6, 2024
2af67f4
Backdrop types
michaldudak May 6, 2024
96174bb
Proptypes
michaldudak May 6, 2024
c7d248d
Improvements to the experiment
michaldudak May 6, 2024
f937183
Exports and API docs
michaldudak May 6, 2024
cc88b1a
Conformance tests
michaldudak May 7, 2024
3315a9c
Tests
michaldudak May 8, 2024
ab473ce
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak May 8, 2024
985fd41
More tests
michaldudak May 8, 2024
98ecc8f
Revert popup
michaldudak May 8, 2024
e30f281
Tests
michaldudak May 8, 2024
2479109
Restore the experiment
michaldudak May 8, 2024
5406250
Simplify
michaldudak May 8, 2024
9c6e81a
docs:i18n
michaldudak May 8, 2024
4983100
Playing with transitions
michaldudak May 8, 2024
b8b7985
Using the `animation` prop
michaldudak May 9, 2024
1e9eb84
useTransitionStatus
michaldudak May 9, 2024
78b963c
Fix demos
michaldudak May 9, 2024
82be3d8
Docs
michaldudak May 10, 2024
06d8764
Do not use legacy animation hooks
michaldudak May 10, 2024
8f1433b
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak May 10, 2024
f4906b5
Use data-state for transitions
michaldudak May 10, 2024
de14c09
useDialogBackdrop hook
michaldudak May 10, 2024
5e849dc
Fix tests
michaldudak May 10, 2024
e0e2b92
JSDocs
michaldudak May 13, 2024
425e8a5
Transitions with two states
michaldudak May 13, 2024
123397b
Animations with a glitch
michaldudak May 13, 2024
fbe6bcc
Include the Dialog in the package
michaldudak May 13, 2024
b7adc71
Animations demo
michaldudak May 14, 2024
8c16a70
Merge branch 'master' into dialog
michaldudak May 14, 2024
052d402
Do not read context from hooks
michaldudak May 14, 2024
a1a509e
Fix tests
michaldudak May 14, 2024
f7dd341
Remove support for transitions
michaldudak May 20, 2024
2b883e9
Support nested dialogs
michaldudak May 21, 2024
c17ba54
Try out @starting-style
michaldudak May 21, 2024
b5b23e4
Fix API docs gen
michaldudak May 21, 2024
7bb60e4
Fixing the build
michaldudak May 21, 2024
fbb2a23
Nested children info
michaldudak May 21, 2024
cb6575a
Nested dialogs with fancy transitions
michaldudak May 21, 2024
cefdfc8
Do not use implicit asChild in Trigger
michaldudak May 22, 2024
3ebc2e6
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak May 22, 2024
4f88adf
Do not close all parent dialogs when clicking outside
michaldudak May 22, 2024
c804959
JSDocs
michaldudak May 22, 2024
37a9830
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak May 22, 2024
906ca99
Nested dialog docs
michaldudak May 22, 2024
4ef48dd
Fix focus in animated dialog demo
michaldudak May 23, 2024
7ccf6fd
Introduction demo
michaldudak May 23, 2024
76cce38
Update the nested dialogs demo
michaldudak May 24, 2024
941182f
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak May 24, 2024
af90f41
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak May 28, 2024
848c22f
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak May 29, 2024
87870e8
Fixes
michaldudak May 29, 2024
22850e0
[Tooltip][docs] Use the correct version of ComponentLinkHeader (#425)
michaldudak May 29, 2024
4da94f9
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak May 29, 2024
3156e7e
Add the container prop to Popup
michaldudak May 29, 2024
8ba9468
Use common animation primitives
michaldudak May 29, 2024
61d2696
Update animation playground
michaldudak May 29, 2024
8c9c23c
Fix the build
michaldudak May 29, 2024
592ac01
Animation docs
michaldudak May 29, 2024
ab72fda
Prettier
michaldudak May 29, 2024
d5ff23c
Fix the CI
michaldudak May 29, 2024
5b0e258
Merge branch 'master' into dialog
michaldudak Jun 3, 2024
f2cdfd7
Correct the docs about Trigger
michaldudak Jun 5, 2024
7c153c1
Lock scroll
michaldudak Jun 5, 2024
f689774
James' feedback
michaldudak Jun 5, 2024
43acf9e
Remove unnecessary files
michaldudak Jun 5, 2024
7c4b3c4
Revert ClickAwayListener changes
michaldudak Jun 5, 2024
7149a7d
Revert Popup changes
michaldudak Jun 5, 2024
64fbdeb
useScrollLock docs
michaldudak Jun 5, 2024
0978384
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak Jun 5, 2024
f9a4622
Update the intro demo
michaldudak Jun 5, 2024
02fb4f1
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak Jun 11, 2024
3bb7912
Add AlertDialog component
michaldudak Jun 11, 2024
7dcf980
Merge remote-tracking branch 'upstream/master' into dialog
michaldudak Jun 11, 2024
dd7cc9b
Alert Dialog docs
michaldudak Jun 11, 2024
9372780
Throw warning when Backdrop is missing
michaldudak Jun 12, 2024
b34abca
Update docs
michaldudak Jun 12, 2024
2ad929f
dismissible/keyboardDismissible
michaldudak Jun 12, 2024
1a70349
Prettier
michaldudak Jun 12, 2024
79dfff0
Add missing AlertDialog subcomponents
michaldudak Jun 13, 2024
ddc96ea
docs:api
michaldudak Jun 13, 2024
f4e08de
Use the correct context
michaldudak Jun 13, 2024
266a449
Fix soft close
michaldudak Jun 13, 2024
d34358a
Remove the keyboardDismissible prop
michaldudak Jun 13, 2024
d5dbeb2
Merge branch 'master' into dialog
michaldudak Jun 13, 2024
97794d6
Slow down the tests
michaldudak Jun 13, 2024
6c9f081
Set closeOnFocus=false
michaldudak Jun 13, 2024
0a0eb8e
Use layout effect to set ids
michaldudak Jun 13, 2024
d2d7c4b
Move the `animated` prop to the root
michaldudak Jun 14, 2024
faeaed2
Test the `animated` prop
michaldudak Jun 14, 2024
064d6a8
Look for inaccessible elements in tests
michaldudak Jun 14, 2024
b34c367
Close the topmost dialog on escape press
michaldudak Jun 17, 2024
c045fe2
Merge branch 'master' into dialog
michaldudak Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions docs/pages/experiments/dialog.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.page {
max-width: 1000px;
margin: 0 auto;
padding: 16px;
font-family: IBM Plex Sans;

h1 {
font-family: General Sans;
font-weight: 600;
font-size: 2rem;
}

h2 {
font-size: 1.5rem;
font-weight: 600;
}
}

.dialog {
background: #fff;
border: 1px solid #f5f5f5;
min-width: 300px;
max-width: 500px;
border-radius: 4px;
box-shadow: rgba(0, 0, 0, 0.2) 0px 18px 50px -10px;
padding: 16px;

&::backdrop {
backdrop-filter: blur(8px);
background: radial-gradient(#cecdcf36, #8b94ab47);
}
}

.button {
background: #eee;
padding: 8px 16px;
border: 1px solid #d8d8d8;
border-radius: 4px;
font-family: inherit;

&:hover {
background: #ffbf2b;
}

&:focus-visible {
outline: 2px solid #ffbf2b;
}

&:active {
background: #cc9922;
border-color: #cc9922;

&:focus-visible {
outline-color: #cc9922;
}
}

& + .button {
margin-left: 8px;
}
}

.form {
display: flex;
gap: 16px;
margin-top: 24px;

& > * {
flex: 1;
margin: 0;
}
}

.nonmodal {
top: 20vh;
}
91 changes: 91 additions & 0 deletions docs/pages/experiments/dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import * as React from 'react';
import * as Dialog from '@base_ui/react/Dialog';
import clsx from 'clsx';
import classes from './dialog.module.css';

function UncontrolledDialogDemo() {
return (
<div>
<Dialog.Root closeOnClickOutside>
<Dialog.Trigger>
<button type="button" className={classes.button}>
Open
</button>
</Dialog.Trigger>
<Dialog.Popup className={classes.dialog}>
<Dialog.Title className={classes.title}>Dialog</Dialog.Title>
<Dialog.Description>This is a sample dialog</Dialog.Description>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eget sapien id dolor rutrum
porta. Sed enim nulla, placerat eu tincidunt non, ultrices in lectus. Curabitur
pellentesque diam nec ligula hendrerit dapibus.
</p>

<form method="dialog" className={classes.form}>
<button type="submit" className={classes.button}>
Submit
</button>
<Dialog.Close className={classes.button}>Cancel</Dialog.Close>
</form>
</Dialog.Popup>
</Dialog.Root>
</div>
);
}

function ControlledDialogDemo() {
const [open, setOpen] = React.useState(false);
const [modal, setModal] = React.useState(true);

function setState(shouldOpen: boolean, shouldBeModal?: boolean) {
return () => {
setOpen(shouldOpen);
if (shouldBeModal !== undefined) {
setModal(shouldBeModal);
}
};
}

return (
<div>
<button type="button" className={classes.button} onClick={setState(true, false)}>
Open non-modal
</button>
<button type="button" className={classes.button} onClick={setState(true, true)}>
Open modal
</button>
<Dialog.Root open={open} modal={modal} onOpenChange={setState(false)} closeOnClickOutside>
<Dialog.Popup className={clsx(classes.dialog, modal ? classes.modal : classes.nonmodal)}>
<Dialog.Title className={classes.title}>Dialog</Dialog.Title>
<Dialog.Description>This is a sample dialog</Dialog.Description>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eget sapien id dolor rutrum
porta. Sed enim nulla, placerat eu tincidunt non, ultrices in lectus. Curabitur
pellentesque diam nec ligula hendrerit dapibus.
</p>

<form method="dialog" className={classes.form}>
<button type="submit" className={classes.button}>
Submit
</button>
<button type="button" className={classes.button} onClick={setState(false)}>
Cancel
</button>
</form>
</Dialog.Popup>
</Dialog.Root>
</div>
);
}

export default function DialogExperiment() {
return (
<div className={classes.page}>
<h1>Dialog</h1>
<h2>Uncontrolled</h2>
<UncontrolledDialogDemo />
<h2>Controlled</h2>
<ControlledDialogDemo />
</div>
);
}
38 changes: 38 additions & 0 deletions packages/mui-base/src/Dialog/Close/DialogClose.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { defaultRenderFunctions } from '../../utils/defaultRenderFunctions';
import { useDialogRootContext } from '../Root/DialogRootContext';

const DialogClose = React.forwardRef(function DialogClose(
props: React.ComponentPropsWithRef<'button'>,
forwardedRef: React.ForwardedRef<HTMLButtonElement>,
) {
const { open, onOpenChange } = useDialogRootContext();

const handleClick = React.useCallback(() => {
if (open) {
onOpenChange?.(false);
}
}, [open, onOpenChange]);

const rootProps = {
...props,
onClick: handleClick,
ref: forwardedRef,
};

return defaultRenderFunctions.button(rootProps);
});

DialogClose.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* @ignore
*/
children: PropTypes.node,
} as any;

export { DialogClose };
46 changes: 46 additions & 0 deletions packages/mui-base/src/Dialog/Description/DialogDescription.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { defaultRenderFunctions } from '../../utils/defaultRenderFunctions';
import { useId } from '../../utils/useId';
import { useDialogRootContext } from '../Root/DialogRootContext';

const DialogDescription = React.forwardRef(function DialogDescription(
props: React.ComponentPropsWithRef<'p'>,
forwardedRef: React.ForwardedRef<HTMLParagraphElement>,
) {
const { id: idProp } = props;
const { registerDescription } = useDialogRootContext();
const id = useId(idProp);

React.useEffect(() => {
registerDescription(id ?? null);
return () => {
registerDescription(null);
};
}, [id, registerDescription]);

const rootProps = {
...props,
id,
ref: forwardedRef,
};

return defaultRenderFunctions.p(rootProps);
});

DialogDescription.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* @ignore
*/
children: PropTypes.node,
/**
* @ignore
*/
id: PropTypes.string,
} as any;

export { DialogDescription };
Loading