-
Notifications
You must be signed in to change notification settings - Fork 18
React 19 #2699
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
Merged
Merged
React 19 #2699
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
034131a
react 19
david-crespo 2d628ab
upgrade design-system (canary) and other libs to make install work
david-crespo 6ef5e92
upgrade @types libs too
david-crespo ec1b4e9
fix the easier type errors
david-crespo 69f3f38
bump design-system again
david-crespo a307f12
fix the two failing e2es
david-crespo b35169d
patch the right copy of react-remove-scroll
david-crespo 639caf1
fix some more type errors
david-crespo 53be384
elaborate rework of Button and Tooltip ref situation
david-crespo 58f322e
upgrade zustand to v5 to fix some last warnings
david-crespo c390d66
work around headless bug: change fragment to div
david-crespo a494e1f
good old design-system 2.2.2
david-crespo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| */ | ||
| import cn from 'classnames' | ||
| import * as m from 'motion/react-m' | ||
| import { forwardRef, type MouseEventHandler, type ReactNode } from 'react' | ||
| import { type MouseEventHandler, type ReactNode } from 'react' | ||
|
|
||
| import { Spinner } from '~/ui/lib/Spinner' | ||
| import { Tooltip } from '~/ui/lib/Tooltip' | ||
|
|
@@ -55,80 +55,82 @@ const noop: MouseEventHandler<HTMLButtonElement> = (e) => { | |
| e.preventDefault() | ||
| } | ||
|
|
||
| export interface ButtonProps | ||
| extends React.ComponentPropsWithRef<'button'>, | ||
| ButtonStyleProps { | ||
| export interface ButtonProps extends React.ComponentProps<'button'>, ButtonStyleProps { | ||
| innerClassName?: string | ||
| loading?: boolean | ||
| disabledReason?: ReactNode | ||
| } | ||
|
|
||
| // Use `forwardRef` so the ref points to the DOM element (not the React Component) | ||
| // so it can be focused using the DOM API (eg. this.buttonRef.current.focus()) | ||
| export const Button = forwardRef<HTMLButtonElement, ButtonProps>( | ||
| ( | ||
| { | ||
| type = 'button', | ||
| children, | ||
| size, | ||
| variant, | ||
| className, | ||
| loading, | ||
| innerClassName, | ||
| disabled, | ||
| onClick, | ||
| disabledReason, | ||
| // needs to be a spread because we sometimes get passed arbitrary <button> | ||
| // props by the parent | ||
| ...rest | ||
| }, | ||
| ref | ||
| ) => { | ||
| const isDisabled = disabled || loading | ||
| return ( | ||
| <Wrap | ||
| when={isDisabled && disabledReason} | ||
| with={<Tooltip content={disabledReason} ref={ref} placement="bottom" />} | ||
| // The ref situation is a little confusing. We need a ref prop for the button | ||
| // (and to pass it through to <button> so it actually does something) so we can | ||
| // focus to the button programmatically. There is an example in TlsCertsField | ||
| // in the silo create form: when there are no certs added, the validation error | ||
| // on submit focuses and scrolls to the add TLS cert button. All of that is | ||
| // normal. The confusing part is that when the button is disabled and wrapped | ||
| // in a tooltip, the tooltip component wants to add its own ref to the button | ||
| // so it can figure out where to place the tooltip. In order to make both refs | ||
| // work at the same time (so that, for example, in theory, a button could be | ||
| // simultaneously disabled with a tooltip *and* be focused programmatically [I | ||
| // tested this]), we merge the two refs inside Tooltip, using child.props.ref to | ||
| // get the original ref on the button. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important comment added |
||
|
|
||
| export const Button = ({ | ||
| type = 'button', | ||
| children, | ||
| size, | ||
| variant, | ||
| className, | ||
| loading, | ||
| innerClassName, | ||
| disabled, | ||
| onClick, | ||
| disabledReason, | ||
| // needs to be a spread because we sometimes get passed arbitrary <button> | ||
| // props by the parent | ||
| ...rest | ||
| }: ButtonProps) => { | ||
| const isDisabled = disabled || loading | ||
| return ( | ||
| <Wrap | ||
| when={isDisabled && disabledReason} | ||
| with={<Tooltip content={disabledReason} placement="bottom" />} | ||
| > | ||
| <button | ||
| className={cn( | ||
| buttonStyle({ size, variant }), | ||
| className, | ||
| { 'visually-disabled': isDisabled }, | ||
| 'overflow-hidden' | ||
| )} | ||
| /* eslint-disable-next-line react/button-has-type */ | ||
| type={type} | ||
| onMouseDown={isDisabled ? noop : undefined} | ||
| onClick={isDisabled ? noop : onClick} | ||
| aria-disabled={isDisabled} | ||
| /* this includes the ref. that's important. see big comment above */ | ||
| {...rest} | ||
| > | ||
| <button | ||
| className={cn( | ||
| buttonStyle({ size, variant }), | ||
| className, | ||
| { | ||
| 'visually-disabled': isDisabled, | ||
| }, | ||
| 'overflow-hidden' | ||
| )} | ||
| ref={ref} | ||
| /* eslint-disable-next-line react/button-has-type */ | ||
| type={type} | ||
| onMouseDown={isDisabled ? noop : undefined} | ||
| onClick={isDisabled ? noop : onClick} | ||
| aria-disabled={isDisabled} | ||
| {...rest} | ||
| > | ||
| {loading && ( | ||
| <m.span | ||
| animate={{ opacity: 1, y: '-50%', x: '-50%' }} | ||
| initial={{ opacity: 0, y: 'calc(-50% - 25px)', x: '-50%' }} | ||
| transition={{ type: 'spring', duration: 0.3, bounce: 0 }} | ||
| className="absolute left-1/2 top-1/2" | ||
| > | ||
| <Spinner variant={variant} /> | ||
| </m.span> | ||
| )} | ||
| {loading && ( | ||
| <m.span | ||
| className={cn('flex items-center', innerClassName)} | ||
| animate={{ | ||
| opacity: loading ? 0 : 1, | ||
| y: loading ? 25 : 0, | ||
| }} | ||
| animate={{ opacity: 1, y: '-50%', x: '-50%' }} | ||
| initial={{ opacity: 0, y: 'calc(-50% - 25px)', x: '-50%' }} | ||
| transition={{ type: 'spring', duration: 0.3, bounce: 0 }} | ||
| className="absolute left-1/2 top-1/2" | ||
| > | ||
| {children} | ||
| <Spinner variant={variant} /> | ||
| </m.span> | ||
| </button> | ||
| </Wrap> | ||
| ) | ||
| } | ||
| ) | ||
| )} | ||
| <m.span | ||
| className={cn('flex items-center', innerClassName)} | ||
| animate={{ | ||
| opacity: loading ? 0 : 1, | ||
| y: loading ? 25 : 0, | ||
| }} | ||
| transition={{ type: 'spring', duration: 0.3, bounce: 0 }} | ||
| > | ||
| {children} | ||
| </m.span> | ||
| </button> | ||
| </Wrap> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This was needed to fix the border between the
Listboxand the button after adding a wrapping div to work around the Headless bug. We can always change it back if want after they fix it.