-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-dialog): Dialog initial implementation
#23933
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
feat(react-dialog): Dialog initial implementation
#23933
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 700b6c1:
|
ec3e699 to
66c7fe3
Compare
📊 Bundle size report
🤖 This report was generated against bb5ec4f8d3f9891901064e92d81e89c3c8022951 |
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: bb5ec4f8d3f9891901064e92d81e89c3c8022951 (build) |
04bfee6 to
8aec66a
Compare
Perf Analysis (
|
| Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
|---|---|---|---|---|---|
| Avatar | mount | 1315 | 1301 | 5000 | |
| Button | mount | 912 | 917 | 5000 | |
| FluentProvider | mount | 1745 | 1755 | 5000 | |
| FluentProviderWithTheme | mount | 609 | 613 | 10 | |
| FluentProviderWithTheme | virtual-rerender | 571 | 578 | 10 | |
| FluentProviderWithTheme | virtual-rerender-with-unmount | 626 | 633 | 10 | |
| MakeStyles | mount | 1970 | 1912 | 50000 | |
| SpinButton | mount | 2643 | 2563 | 5000 |
f768687 to
1bdea0f
Compare
1bdea0f to
3f8781d
Compare
Dialog initial implementation
packages/react-components/react-dialog/src/components/Dialog/Dialog.test.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-dialog/src/components/Dialog/Dialog.test.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts
Show resolved
Hide resolved
packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts
Show resolved
Hide resolved
packages/react-components/react-dialog/src/components/Dialog/useDialog.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-dialog/src/components/Dialog/useDialog.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-dialog/src/components/Dialog/useDialog.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-dialog/src/components/Dialog/useDialog.ts
Outdated
Show resolved
Hide resolved
…ialog.test.tsx Co-authored-by: ling1726 <[email protected]>
…ialog.test.tsx Co-authored-by: ling1726 <[email protected]>
c306410 to
7f0b267
Compare
…seDialog.ts Co-authored-by: ling1726 <[email protected]>
7f0b267 to
06e90c4
Compare
packages/react-components/react-dialog/bundle-size/Dialog.fixture.js
Outdated
Show resolved
Hide resolved
packages/react-components/react-dialog/src/components/Dialog/useDialog.test.ts
Outdated
Show resolved
Hide resolved
…seDialog.test.ts Co-authored-by: Miroslav Stastny <[email protected]>
…ure.js Co-authored-by: Miroslav Stastny <[email protected]>
packages/react-components/react-dialog/src/utils/isTargetDisabled.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-dialog/src/contexts/dialogContext.ts
Outdated
Show resolved
Hide resolved
…led.ts Co-authored-by: ling1726 <[email protected]>
0755173 to
700b6c1
Compare
| | { type: 'escapeKeyDown'; open: boolean; event: React.KeyboardEvent } | ||
| /** | ||
| * document escape keydown defers from internal escape keydown events because of the synthetic event API | ||
| */ | ||
| | { type: 'documentEscapeKeyDown'; open: boolean; event: KeyboardEvent } | ||
| | { type: 'overlayClick'; open: boolean; event: React.MouseEvent } | ||
| | { type: 'triggerClick'; open: boolean; event: React.MouseEvent }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please clarify why event is passed in data?
<Dialog onOpenChange={(event, data) => {
// What `event` should I use?
console.log(event, data.event)
}} />IMO this looks redundant and confusing...
| }, | ||
| }); | ||
|
|
||
| const requestOpenChange = useEventCallback((data: DialogRequestOpenChangeData) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not a big fun of using "request" prefix as there are clear actions for be executed... Something like toggleOpen/setOpen/dispatchOpen sounds better. But it's all IMO
| }); | ||
|
|
||
| const requestOpenChange = useEventCallback((data: DialogRequestOpenChangeData) => { | ||
| const getNextOpen = normalizeSetStateAction(data.open); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I briefly checked all existing usages and it looks for that it would be better to pass just a string there: as a single case when it could a function it's a trigger that uses strings...
If you just have there action: 'open' | 'close' | 'toggle' it will be more straightforward IMO
|
|
||
| const requestOpenChange = useEventCallback((data: DialogRequestOpenChangeData) => { | ||
| const getNextOpen = normalizeSetStateAction(data.open); | ||
| const isDefaultPrevented = normalizeDefaultPrevented(data.event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A dumb question, but why it's needed? defaultPrevented exists on React's SyntheticEvent... Why it cannot be simply event.defaultPrevented?
| * Checks if dialog is opening | ||
| */ | ||
| function isOpening(current: boolean, next: Extract<React.SetStateAction<boolean>, Function>) { | ||
| return !current && next(current) === true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(☞゚∀゚)☞ return !current && next(current)
(no reason to use === true)
| } else { | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| // eslint-disable-next-line no-console | ||
| console.warn('A Dialog should have at least one focusable element inside DialogContent'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: But I would think on how to emit this warning once to avoid spam in console
| // TODO Add default styles for the root element | ||
| overlay: { | ||
| position: 'fixed', | ||
| backgroundColor: 'rgba(0, 0, 0, 0.4)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a token for that?
| export const useDialogStyles_unstable = (state: DialogState): DialogState => { | ||
| const styles = useStyles(); | ||
| state.root.className = mergeClasses(dialogClassNames.root, styles.root, state.root.className); | ||
| const isNestedDialog = useHasParentContext(DialogContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to move this to state otherwise it will not be accessible as a value for composition and cannot be used on consumer side
| * Don't forget to call `jest.mock(**\/dialogContext.ts)` while using this | ||
| * @param options Menu context values to set for testing | ||
| */ | ||
| export const mockUseDialogContext = (options: Partial<DialogContextValue> = {}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid mocks if possible. I would rather use a mocked Provider in tests with wrapper
Provides initial implementation for the
Dialogcomponent