Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: Add experimental
ConfirmDialog
(#34153)
* Proof of Concept * Improve UX to more closely resembles a native confirm * Remove unused import and outdated comment * Improve the story * Spelling fix * Remove debug code * Fix invalid props warning * Empty dependency array to avoid listener from being re-added at each render * Remove unused style * wip * Address code review suggestions partially, and refactor to use the existing component * Improve component by allowing it to be used without the `confirm` helper, remove dependency on `react-confirm` * Update README * Update confirm call in post-visibility * Remove role prop as it is not explicitely used at the moment * Add basic tests * Test that the Confirm closes when clicking the overlay * Test that the Confirm closes when pressing Escape * Fix types and forwardRef, and adapt to the new functional Modal component * Fix tests * Simple naive inline declarative usage without a Context * Fix z-index to show it above all elements, and forwardRef to Modal's wrapper element * Improve callback handler name * Make `onCancel` optional * Add styles.ts * Add more tests * Handle confirm on enter and add corresponding test * Rename to `ConfirmDialog` * Redo stories, improve types and `selfClose` handling * Fix tests after renaming to `ConfirmDialog` * Update the post-visibility example after renaming to `ConfirmDialog` * Forward all other props to the underlying `Modal` * Refactor tests to test controlled and uncontrolled scenarios * Mark it as experimental, linter autofixes and snapshot updates * Add a proper README * Fix typo * Fix grammar and add section about multiple instances to the README * Fix stories * Add message text knob to stories * Reset components/package.json * Misc changes after code review Co-authored-by: Marco Ciampini <[email protected]> * Abstract polymorphic event * Simplify tests to not use snapshots and be more explicit * Update README.md to reflect the new polymorphic event type * Make the `Cancel` button a `tertiary` and DRY and improve types - Create two interfaces that extend from a base prop type, and then unify them to let TypeScript structurally decide what to use during compile-time. - Add an optional `title` prop that will be used soon to implement an optional title in the dialog. * Make the title optional and adjust some styles * Fix typo * Update packages/components/src/confirm-dialog/README.md Co-authored-by: Haz <[email protected]> * Update packages/components/src/confirm-dialog/README.md Co-authored-by: Marco Ciampini <[email protected]> * Update packages/components/src/confirm-dialog/README.md Co-authored-by: Marco Ciampini <[email protected]> * Remove unused imported `MouseEvent` * Type `handleEvent`'s `callback` argument as optional Co-authored-by: Marco Ciampini <[email protected]> * Update packages/components/src/confirm-dialog/README.md Co-authored-by: Marco Ciampini <[email protected]> * Update packages/components/src/confirm-dialog/README.md Co-authored-by: Haz <[email protected]> * Remove portion about the singleton wrapper component as it will not be included now * Improve component types Use `never` for a slightly better semantic for communicating that the `UncontrolledProps` type must have not have `isOpen` set. * Use `props.children` to pass the dialog message contents * Add DOM structure tests * Convert all findBy* to getBy* We don't really need the additional functionality provided by findBy*. * Update README to reflect the new API * Improve title and xCloseButton tests * Add better and more concise description for the `title` prop in the README * Try stacked margin * Update packages/components/tsconfig.json Co-authored-by: Marco Ciampini <[email protected]> * Update packages/components/src/modal/index.js Co-authored-by: Marco Ciampini <[email protected]> * Destructure props in the function body in `Modal` to prevent TS errors from the consuming TS component, and use React's `forwardRef` to forward refs to `Modal` * Use VStack for a stacked margin approach and remove ability to set a Modal title Instead of hacking the visuals for the `Modal` component from `ConfirmDialog`, we actually move the logic to hide the title to the `Modal`. It won't render the header if `title` is falsey + a CSS class applied makes sure the additional margin for the header is reset. Also simplify the `ConfirmDialog` and do not allow passing an optional `title` as the message passed as the `props.children` should be enough. * Update snapshots for the `preferences-modal` unit tests * Update snapshots for the `keyboard-shortcut-help-modal` unit tests * Revert post-visibility sample changes * Keep modal's default behavior of showing the title div and remove an old confirm-dialog test that tested a title button that is not rendered anymore * Fix wrong message string in one of the stories * Remove unnecessary explanation about unset props * Rename selfClose to shouldSelfClose * Memoize callbacks * Extract `confirm` and `cancel` labels * Improve stories: use `Heading`, better status sentence * Temporarily enable knobs * Fix typo in test name * More descriptive storybook sentende, take 2 * Sort export alphabetically * Undo changes to `Modal` component (to be carried out in a separate PR) * Undo changes to `Modal`-related snapshots (to be carried out in a separate PR) * Refactor `showTitle` prop on the Modal to `__experimentalHideHeader` * CHANGELOG Co-authored-by: Marco Ciampini <[email protected]> Co-authored-by: Haz <[email protected]>
- Loading branch information