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

Add SelectPanel alpha component #1224

Merged
merged 9 commits into from
May 18, 2021
Merged

Add SelectPanel alpha component #1224

merged 9 commits into from
May 18, 2021

Conversation

dgreif
Copy link
Member

@dgreif dgreif commented May 13, 2021

This is the initial pass at SelectPanel (#1071). There are still a number of enhancements that will need to be made, to be implemented in subsequent PRs. Basic scaffolding for docs and tests have been added since this component is Alpha.

Also including the FilteredActionList component. We could incorporate this component directly into the SelectPanel, but I think it's a little easier to separate responsibilities by pulling it out. If we intend to use it elsewhere without SelectPanel, we will need to add additional docs and tests.

I'm definitely open to discussing the API and implementation. The current API makes this component ultra controlled, which means flexibility, but also a lot of setup on the consumer side to use it. I think this is evident if you look at the story and tests. There are ~10 props required to use it properly.

Screenshots

image

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

@dgreif dgreif requested review from smockle and colebemis May 13, 2021 05:03
@changeset-bot
Copy link

changeset-bot bot commented May 13, 2021

🦋 Changeset detected

Latest commit: 3d13326

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/components Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel
Copy link

vercel bot commented May 13, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/primer/primer-components/EydoRgXfqwLsaA3zRk6MPsGRttac
✅ Preview: https://primer-components-git-select-panel-primer.vercel.app

@vercel vercel bot temporarily deployed to Preview May 13, 2021 20:22 Inactive

## Example

## Component props
Copy link
Member

@smockle smockle May 14, 2021

Choose a reason for hiding this comment

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

  1. Would you mind opening an issue tracking either a. “Promote SelectPanel to “beta” status” or b. “Provide examples in the SelectPanel docs”?
  2. What do you think about incorporating some of the prop documentation from SelectPanel #1071 and DropdownMenu #1070?

return
}

if (selectionVariant === 'single') {
Copy link
Member

Choose a reason for hiding this comment

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

Lines 69–76 could be refactored, depending on https://github.com/primer/components/pull/1224/files#r632789982

export interface SelectPanelProps extends Omit<FilteredActionListProps, 'onChange'> {
open: boolean
onOpen: (gesture: 'anchor-click' | 'anchor-key-press') => unknown
onClose: (gesture: 'click-outside' | 'escape') => unknown
Copy link
Member

Choose a reason for hiding this comment

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

ActionMenu uses open and setOpen—should we be consistent (either changing ActionMenu to use open/onOpen/onClose, or changing SelectPanel to use open/setOpen)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Going with the setOpen approach, passing setOpen(open: boolean, gesture: 'possible gestures here'). We will need to circle back and probably change the DropdownMenu and AnchoredOverlay to have the same API

Copy link
Member

@smockle smockle May 14, 2021

Choose a reason for hiding this comment

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

Going with the setOpen approach, passing setOpen(open: boolean, gesture: 'possible gestures here').

👍 Sounds good, thanks!

We will need to circle back and probably change the DropdownMenu and AnchoredOverlay to have the same API.

Great idea! Could you please open an issue to track API consistency updates?

onClose: (gesture: 'click-outside' | 'escape') => unknown
renderAnchor?: <T extends React.HTMLAttributes<HTMLElement>>(props: T) => JSX.Element
placeholder?: string
selectedItems: ItemInput[]
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking: I wonder if we should merge items and selectedItems, i.e. add a selected boolean to selected items in items. Since items updates as filters are applied (possible to exclude selected items not matching the current filter), we’d need to refactor some logic/assumptions (e.g. perhaps always retaining the full list of items, and adding an additional matchesFilter boolean).

Copy link
Member Author

Choose a reason for hiding this comment

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

This could get really tricky with combined local/remote loaded items. I think the current API provides the most flexibility for now, but I'm willing to reconsider as we work on solidifying the API for all the layered components

selectedItems={selectedItems}
onChange={setSelectedItems}
filterValue={filterValue}
onFilterChange={onFilterChange}
Copy link
Member

Choose a reason for hiding this comment

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

From @dgreif in #1224 (comment):

The current API makes this component ultra controlled, which means flexibility, but also a lot of setup on the consumer side to use it. I think this is evident if you look at the story and tests. There are ~10 props required to use it properly.

It’s interesting to consider how a slotted children API could reduce the props of SelectPanel, e.g. if SelectPanel had a SelectPanel.Filter child, placeholderText, filterValue, and onFilterChange could be moved there. cc @colebemis

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'm interested to see if we could simplify the props by using the content-as-children API.

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

This looks great for an alpha component ✨ Thanks for all your hard work and attention to detail on this, @dgreif! ❤️ I'll give this a more thorough review after you've addressed @smockle's thoughtful comments.

Before we promote this to beta, let's explore a content-as-children API to simplify the props.

src/stories/SelectPanel.stories.tsx Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview May 14, 2021 23:44 Inactive
@vercel vercel bot temporarily deployed to Preview May 17, 2021 15:21 Inactive
@vercel vercel bot temporarily deployed to Preview May 17, 2021 15:32 Inactive
@vercel vercel bot temporarily deployed to Preview May 17, 2021 22:29 Inactive
loading?: boolean
placeholderText: string
onFilterChange: (value: string, e: React.ChangeEvent<HTMLInputElement>) => void
textInputProps?: Partial<TextInputProps>
Copy link
Contributor

@colebemis colebemis May 17, 2021

Choose a reason for hiding this comment

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

Should we omit onChange from this type because it could clash with onFilterChange?

@vercel vercel bot temporarily deployed to Preview May 17, 2021 23:32 Inactive
@vercel vercel bot temporarily deployed to Preview May 18, 2021 03:33 Inactive
Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Looks good for alpha 👍 Let's experiment with the API a bit more before promoting to beta.

Excellent work, @dgreif

@vercel vercel bot temporarily deployed to Preview May 18, 2021 21:40 Inactive
@dgreif dgreif enabled auto-merge (squash) May 18, 2021 21:41
@dgreif dgreif merged commit 909ada5 into main May 18, 2021
@dgreif dgreif deleted the select-panel branch May 18, 2021 21:44
@github-actions github-actions bot mentioned this pull request May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants