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

SelectPanel2: Types! #3929

Merged
merged 29 commits into from
Dec 5, 2023
Merged

SelectPanel2: Types! #3929

merged 29 commits into from
Dec 5, 2023

Conversation

siddharthkp
Copy link
Member

@siddharthkp siddharthkp commented Nov 10, 2023

  • Add types for experimental SelectPanel
  • Removed a bunch of ts-ignores :)

@siddharthkp siddharthkp added the skip changeset This change does not need a changelog label Nov 10, 2023
@siddharthkp siddharthkp self-assigned this Nov 10, 2023
Copy link

changeset-bot bot commented Nov 10, 2023

⚠️ No Changeset found

Latest commit: 4acebcd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

github-actions bot commented Nov 10, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 104.4 KB (0%)
dist/browser.umd.js 104.93 KB (0%)

Base automatically changed from drafts-selectpanel-validation to main November 14, 2023 15:18
@github-actions github-actions bot temporarily deployed to storybook-preview-3929 November 16, 2023 13:06 Inactive
@siddharthkp siddharthkp marked this pull request as ready for review November 16, 2023 13:24
@siddharthkp siddharthkp requested a review from a team November 16, 2023 13:24
@siddharthkp
Copy link
Member Author

Draft → Ready for review!

Copy link
Member

@joshblack joshblack left a 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 => {
Copy link
Member

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) 🤷

Suggested change
const SelectPanelSecondaryButton: React.FC<ButtonProps> = props => {
const SelectPanelSecondaryButton = (props: ButtonProps) => {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// @ts-ignore todo
const SelectPanelSearchInput = props => {
const SelectPanelSearchInput: React.FC<TextInputProps> = ({onChange: propsOnChange, ...props}) => {
Copy link
Member

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;

Copy link
Member Author

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

src/drafts/SelectPanel2/SelectPanel.tsx Outdated Show resolved Hide resolved
// sync open state
React.useEffect(() => setInternalOpen(props.open), [props.open])
React.useEffect(() => setInternalOpen(propsOpen || false), [propsOpen])
Copy link
Member

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 👀

Copy link
Member Author

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>>
Copy link
Member

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> = ({
Copy link
Member

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) => ...?

Copy link
Member Author

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?

@siddharthkp siddharthkp added this pull request to the merge queue Dec 5, 2023
Merged via the queue into main with commit ffc0eba Dec 5, 2023
27 of 28 checks passed
@siddharthkp siddharthkp deleted the drafts-selectpanel-types branch December 5, 2023 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
react skip changeset This change does not need a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants