-
Notifications
You must be signed in to change notification settings - Fork 561
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
SelectPanel2: Types! #3929
SelectPanel2: Types! #3929
Conversation
siddharthkp
commented
Nov 10, 2023
•
edited
Loading
edited
- Add types for experimental SelectPanel
- Removed a bunch of ts-ignores :)
|
size-limit report 📦
|
Draft → Ready for review! |
This reverts commit 0afa927.
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.
Just left a couple comments/questions! Cool to see this all come together 🥳
SelectPanel.SecondaryButton = props => { | ||
return <Button {...props} size="small" type="button" block /> | ||
// TODO: is this the right way to add button props? | ||
const SelectPanelSecondaryButton: React.FC<ButtonProps> = props => { |
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.
Honestly this might be fine here (and is all React.FC is doing anyways) 🤷
const SelectPanelSecondaryButton: React.FC<ButtonProps> = props => { | |
const SelectPanelSecondaryButton = (props: ButtonProps) => { |
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.
Will sync with what we decide for https://github.com/primer/react/pull/3929/files#r1407598117
|
||
// @ts-ignore todo | ||
const SelectPanelSearchInput = props => { | ||
const SelectPanelSearchInput: React.FC<TextInputProps> = ({onChange: propsOnChange, ...props}) => { |
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.
For onChange
, do they need access to the event itself or could we provide the value of the input instead? (Or a similar onValueChange
). This might help to simplify the types if onChange
(or onValueChange
) is something like onChange({ value }: { value: string }): void;
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.
Good question, I don't think there is any benefit of event here.
onValueChange
is a good idea, but because this is on the text input (and not on top level), I don't think we should remove onChange
(or not support it) because that feels the most natural/intuitive to expect 🤔
onValueChange
could still be a useful shortcut, keeping both wouldn't simplify the types though 😅
Will think more about it, skipping for this PR
// sync open state | ||
React.useEffect(() => setInternalOpen(props.open), [props.open]) | ||
React.useEffect(() => setInternalOpen(propsOpen || false), [propsOpen]) |
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.
It could be worth keeping track of the previous value in state instead of in an effect, I feel like this is similar to the getDerivedStateFromProps
example from the hooks FAQ: https://legacy.reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
Curious if you agree or if there is a difference here 👀
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.
Good call! Updated :)
panelId: string | ||
onCancel: () => void | ||
onClearSelection: undefined | (() => void) | ||
searchQuery: string | ||
setSearchQuery: () => void | ||
setSearchQuery: React.Dispatch<React.SetStateAction<string>> |
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.
Broadly speaking, how would you two feel about borrowing the createContext
pattern from radix to help out with context usage like this across PRC? https://github.com/radix-ui/primitives/blob/main/packages/react/context/src/createContext.tsx#L3
I think the tl;dr is that this pattern has the context types itself be nullable (e.g. ContextValueType | null
) but they leverage a hook to enforce that the value is always defined so they don't have to deal with default values.
children: React.ReactNode | ||
} | ||
|
||
const Panel: React.FC<SelectPanelProps> = ({ |
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.
Super random question, is there a convention that is used to decide between React.FC<Props>
versus annotating the props directly e.g. const Component = (props: Props) => ...
?
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.
Not yet, I don't have strong opinions on this, happy to go either way.
Do we want to avoid React.FC
?
Co-authored-by: Josh Black <[email protected]>