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

ActionList Composable API #1517

Merged
merged 117 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
0876cef
wip
siddharthkp Oct 11, 2021
6866c09
big chunk of parts
siddharthkp Oct 15, 2021
4d9d014
leading visual width fix
siddharthkp Oct 15, 2021
9119eea
Merge branch 'main' into action-list-2
siddharthkp Oct 15, 2021
e519b85
fix lint errors
siddharthkp Oct 15, 2021
2224f84
export list2 to see size diff
siddharthkp Oct 15, 2021
fed8f51
nested stories
siddharthkp Oct 15, 2021
0630556
tiny cleanup
siddharthkp Oct 15, 2021
4d1cc22
testing alternative slot implementation!
siddharthkp Oct 15, 2021
1c3ce94
Revert "testing alternative slot implementation!"
siddharthkp Oct 15, 2021
b07feef
double render strategy
siddharthkp Oct 15, 2021
a6acb35
add failing story for double render strategy
siddharthkp Oct 15, 2021
4dae4c7
more failing cases with stateful children
siddharthkp Oct 15, 2021
ef8f3a2
support children with side effect
siddharthkp Oct 15, 2021
cfd7e2d
one way to support dynamic description
siddharthkp Oct 15, 2021
1748dcf
register + unregister all slots
siddharthkp Oct 15, 2021
bcdff11
get the contents inside the effect
siddharthkp Oct 15, 2021
a07abf3
update tests
siddharthkp Oct 15, 2021
0fc658d
story doesnt have to be ugly
siddharthkp Oct 18, 2021
2f3a8cd
simplify with layout effect :)
siddharthkp Oct 18, 2021
0260e3a
visual alignment for story
siddharthkp Oct 18, 2021
72ef62d
wip: move slots implementation into a reusuable function
siddharthkp Oct 18, 2021
d065a63
types: simplify so that we can pair on it
siddharthkp Oct 18, 2021
a82a3c5
factory component to get typed pair!
siddharthkp Oct 18, 2021
1d57ed1
use provider
siddharthkp Oct 18, 2021
b7926ce
use a render prop api to include provider
siddharthkp Oct 18, 2021
6a7110e
can include register in deps
siddharthkp Oct 18, 2021
f69b7d5
useEffect instead of useLayoutEffect
siddharthkp Oct 18, 2021
3f77738
dont need isequal anymore :)
siddharthkp Oct 18, 2021
5ad3004
Merge branch 'main' into action-list-2
siddharthkp Oct 18, 2021
5c46373
update package-lock
siddharthkp Oct 18, 2021
d775083
add comments to create-slots
siddharthkp Oct 19, 2021
901c109
improve comment
siddharthkp Oct 19, 2021
769edb2
remove extra line for better example
siddharthkp Oct 19, 2021
6840f12
Merge branch 'main' into action-list-2
jfuchs Oct 19, 2021
ae97e51
Merge github.com:primer/react into action-list-2
siddharthkp Oct 21, 2021
199605e
Merge branch 'action-list-2' of github.com:primer/react into action-l…
siddharthkp Oct 21, 2021
be70024
add aria-labelledby + aria-describedby
siddharthkp Oct 21, 2021
8af4571
ConditionalBox experiment commit
siddharthkp Oct 21, 2021
fce4049
Revert "ConditionalBox experiment commit" - keep in history
siddharthkp Oct 21, 2021
249936a
Reverse metadata pattern for context
siddharthkp Oct 25, 2021
3eb2c3e
Make sure all item.child components accept sx prop
siddharthkp Oct 25, 2021
c14da85
Disabled Item
siddharthkp Oct 25, 2021
15334ef
Remove unused import
siddharthkp Oct 25, 2021
69190d9
All child components support sx prop
siddharthkp Oct 26, 2021
9462f46
add story with all conditionals
siddharthkp Oct 26, 2021
fe56433
ConditionalBox to reduce unnecessary nesting
siddharthkp Oct 26, 2021
32a729d
add docs + break check color
siddharthkp Oct 26, 2021
00cbf63
update table of content + break selection checkbox
siddharthkp Oct 26, 2021
2358926
rename onAction to onSelect
siddharthkp Oct 27, 2021
9a9489e
drop Item showDivider for List showDividers
siddharthkp Oct 27, 2021
569f633
accessible examples :)
siddharthkp Oct 28, 2021
868ebfd
selection inherits color from parent
siddharthkp Oct 28, 2021
fd99704
add role to docs for ActionList parent
siddharthkp Oct 28, 2021
4d782d7
add type docs in component definition
siddharthkp Oct 28, 2021
01ae72d
remove default value for selectionVariant
siddharthkp Oct 28, 2021
1b1d393
migrate notes to PR
siddharthkp Oct 28, 2021
39cdf97
change status to alpha
siddharthkp Oct 28, 2021
5bcb3a6
remove background for docs hero
siddharthkp Oct 28, 2021
b08807d
ActionMenu is one word
siddharthkp Oct 28, 2021
96eb536
SelectPanel is also one word
siddharthkp Oct 28, 2021
a8cf98e
add storybook link
siddharthkp Oct 28, 2021
dcc3baf
make storybook link relative
siddharthkp Oct 28, 2021
4acaa54
remove outdated comment
siddharthkp Oct 28, 2021
e5ae5e4
add description to new components
siddharthkp Oct 28, 2021
897d308
Merge branch 'main' into action-list-2
siddharthkp Oct 28, 2021
19b430b
add changeset
siddharthkp Oct 28, 2021
853569c
move ActionList2 to experiments scope
siddharthkp Oct 28, 2021
8473500
add import method in docs
siddharthkp Oct 28, 2021
9cb3517
add selectionVariant on Group
siddharthkp Oct 29, 2021
01eab7c
export types from experiment
siddharthkp Oct 29, 2021
4bd3c2d
add sortable story mimicing memex
siddharthkp Oct 29, 2021
f76d9c5
Merge branch 'main' into action-list-2
siddharthkp Oct 29, 2021
ee9b795
add story for async items
siddharthkp Nov 1, 2021
2ef3be1
play well with focus visible
siddharthkp Nov 1, 2021
76007b2
add toggle to anchor menu
siddharthkp Nov 1, 2021
a86b13b
embarrassing copy pasta
siddharthkp Nov 1, 2021
31b6809
move h1 to h2
siddharthkp Nov 2, 2021
3b83549
Add type comment for Description variant
siddharthkp Nov 2, 2021
15ae268
change header definition to const
siddharthkp Nov 2, 2021
c5cdff5
add comment for children in header
siddharthkp Nov 2, 2021
2541c94
remove usage of get
siddharthkp Nov 2, 2021
8e538c0
make row height a variable
siddharthkp Nov 2, 2021
02168c1
add ActionList.LinkItem
siddharthkp Nov 2, 2021
9672f10
dont need Link, absorbed it
siddharthkp Nov 2, 2021
0d97f39
make the LinkItem polymorphic
siddharthkp Nov 2, 2021
1cd0d32
replace hardcoded color with actionlist primitives 🥳
siddharthkp Nov 3, 2021
3dc13a2
danger hover + inline divider
siddharthkp Nov 3, 2021
2d13781
get rid of silly marker on divider
siddharthkp Nov 3, 2021
e8c3a5d
remove aria-label from selection, we apply it on the top level
siddharthkp Nov 3, 2021
12da5b1
maybe: adopt selected color
siddharthkp Nov 3, 2021
4870da1
Merge branch 'main' into action-list-2
siddharthkp Nov 3, 2021
b8ded7b
fix Group TS error
siddharthkp Nov 3, 2021
143e4c6
this is silly way to cache bust preval
siddharthkp Nov 3, 2021
221edfe
remove comment now that cache is busted
siddharthkp Nov 3, 2021
5fb716d
fix inline divider bug!
siddharthkp Nov 4, 2021
cace4bb
add example for LinkItem
siddharthkp Nov 4, 2021
99caa36
add Group example to docs
siddharthkp Nov 4, 2021
605044c
move group label to right position
siddharthkp Nov 4, 2021
c812437
add cache bust to preval
siddharthkp Nov 4, 2021
cacaec9
make context for slots optional
siddharthkp Nov 4, 2021
0e66876
create tests for create-slots
siddharthkp Nov 4, 2021
dee7775
rename ActionList test
siddharthkp Nov 4, 2021
d16d2d9
tmp: dont fail CI if build fails
siddharthkp Nov 4, 2021
ca4e451
delete duplicate test
siddharthkp Nov 4, 2021
1be1095
add support for id
siddharthkp Nov 4, 2021
93561e7
correct the path used in ActionList test
siddharthkp Nov 4, 2021
4809068
bring back set -e
siddharthkp Nov 4, 2021
0d0d1cb
dont use Box for base component :)
siddharthkp Nov 8, 2021
5f38e76
make async story overflow
siddharthkp Nov 8, 2021
1432420
simplify slot types
siddharthkp Nov 8, 2021
9d14e5a
add active color based on vini's feedback
siddharthkp Nov 8, 2021
71bc34e
LeadingVisualContainer should use VisualProps
siddharthkp Nov 10, 2021
bacd12c
accept html attributes on visual
siddharthkp Nov 10, 2021
859008e
rename propsSx to sxProp
siddharthkp Nov 10, 2021
6d6ddf5
rename experiments to unreleased
siddharthkp Nov 10, 2021
3cfc4f7
Merge branch 'main' into action-list-2
siddharthkp Nov 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-moles-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': minor
---

Add experimental `ActionList` with composable API
273 changes: 273 additions & 0 deletions docs/content/ActionList2.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
---
title: ActionList
siddharthkp marked this conversation as resolved.
Show resolved Hide resolved
status: Alpha
Copy link
Contributor

Choose a reason for hiding this comment

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

@colebemis - should we track this component in the Primer React component status sheet?

source: https://github.com/primer/react/tree/main/src/ActionList2
storybook: '/react/storybook?path=/story/composite-components-actionlist2'
description: An ActionList is a list of items which can be activated or selected. ActionList is the base component for many of our menu-type components, including DropdownMenu and ActionMenu.
---

import {BorderBox, Avatar} from '@primer/components'
import {ActionList} from '@primer/components/experiments'
import {Props} from '../src/props'

import {ImageContainer} from '@primer/gatsby-theme-doctocat'
import {LinkIcon, AlertIcon, ArrowRightIcon} from '@primer/octicons-react'

<br />
mperrotti marked this conversation as resolved.
Show resolved Hide resolved

<BorderBox sx={{padding: 6}}>
<ActionList sx={{width: 320}}>
<ActionList.Item>
<ActionList.LeadingVisual>
<LinkIcon />
</ActionList.LeadingVisual>
github.com/primer
<ActionList.Description variant="block">
A React implementation of GitHub's Primer Design System
</ActionList.Description>
</ActionList.Item>
<ActionList.Item>
<ActionList.LeadingVisual>
<Avatar src="https://github.com/mona.png" />
</ActionList.LeadingVisual>
mona
<ActionList.Description>Monalisa Octocat</ActionList.Description>
</ActionList.Item>
<ActionList.Item variant="danger">
<ActionList.LeadingVisual>
<AlertIcon />
</ActionList.LeadingVisual>
4 vulnerabilities
<ActionList.TrailingVisual>
<ArrowRightIcon />
</ActionList.TrailingVisual>
</ActionList.Item>
</ActionList>
</BorderBox>

<br />

```js
import {ActionList} from '@primer/components/experiments'
```

<br />

## Examples

## Minimal example

```javascript live noinline
const {ActionList} = experiments
Copy link
Member Author

@siddharthkp siddharthkp Oct 28, 2021

Choose a reason for hiding this comment

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

⚠️ Help wanted: Is there a way around this which makes the examples look pretty without without conflicting name in scope 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like experiments is in scope because it's imported in docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js

Nitpick: If I'm not a regular contributor to Primer React, I might get confused about where experiments is defined when looking at the examples.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! I'd really like a way to hide that but not sure without calling making the jsx look like this:

<ActionList2>
  <ActionList2.Item>New file</ActionList2.Item>
  <ActionList2.Item>Copy link</ActionList2.Item>
</ActionList2>


render(
<ActionList>
<ActionList.Item>New file</ActionList.Item>
<ActionList.Item>Copy link</ActionList.Item>
<ActionList.Item>Edit file</ActionList.Item>
<ActionList.Divider />
<ActionList.Item variant="danger">Delete file</ActionList.Item>
</ActionList>
)
```

<br />

## With Leading Visual

Leading visuals are optional and appear at the start of an item. They can be octicons, avatars, and other custom visuals that fit a small area.

```javascript live noinline
const {ActionList} = experiments

render(
<ActionList>
<ActionList.Item>New file</ActionList.Item>
<ActionList.Item>Copy link</ActionList.Item>
<ActionList.Item>Edit file</ActionList.Item>
<ActionList.Divider />
<ActionList.Item variant="danger">Delete file</ActionList.Item>
</ActionList>
)
```

<!-- prettier-ignore -->
```javascript live noinline
const {ActionList} = experiments

render(
<ActionList>
<ActionList.Item>
<ActionList.LeadingVisual><LinkIcon /></ActionList.LeadingVisual>
github.com/primer
</ActionList.Item>
<ActionList.Item variant="danger">
<ActionList.LeadingVisual><AlertIcon /></ActionList.LeadingVisual>
4 vulnerabilities
</ActionList.Item>
<ActionList.Item>
<ActionList.LeadingVisual><Avatar src="https://github.com/mona.png" /></ActionList.LeadingVisual>
mona
</ActionList.Item>
</ActionList>
)
```

<br />

## With Trailing Visual

Trailing visual and trailing text can display auxiliary information. They're placed at the right of the item, and can denote status, keyboard shortcuts, or be used to set expectations about what the action does.

```javascript live noinline
const {ActionList} = experiments

render(
<ActionList>
<ActionList.Item>
New file
<ActionList.TrailingVisual>⌘ + N</ActionList.TrailingVisual>
</ActionList.Item>
<ActionList.Item>
Copy link
<ActionList.TrailingVisual>⌘ + C</ActionList.TrailingVisual>
</ActionList.Item>
<ActionList.Item>
Edit file
<ActionList.TrailingVisual>⌘ + E</ActionList.TrailingVisual>
</ActionList.Item>
<ActionList.Item variant="danger">
Delete file
<ActionList.TrailingVisual>⌫</ActionList.TrailingVisual>
</ActionList.Item>
</ActionList>
)
```

<br />

## With Description and Dividers

Item dividers allow users to parse heavier amounts of information. They're placed between items and are useful in complex lists, particularly when descriptions or multi-line text is present.

```javascript live noinline
const {ActionList} = experiments

render(
<ActionList showDividers>
<ActionList.Item>
<ActionList.LeadingVisual>
<Avatar src="https://github.com/mona.png" />
</ActionList.LeadingVisual>
mona
<ActionList.Description>Monalisa Octocat</ActionList.Description>
</ActionList.Item>
<ActionList.Item>
<ActionList.LeadingVisual>
<Avatar src="https://github.com/hubot.png" />
</ActionList.LeadingVisual>
hubot
<ActionList.Description>Hubot</ActionList.Description>
</ActionList.Item>
<ActionList.Item>
<ActionList.LeadingVisual>
<Avatar src="https://github.com/primer-css.png" />
</ActionList.LeadingVisual>
primer-css
<ActionList.Description>GitHub Design Systems Bot</ActionList.Description>
</ActionList.Item>
</ActionList>
)
```

<br />

## Props / API reference

## ActionList

| Name | Type | Default | Description |
| :--------------- | :------------------------------------------------------------------------------------------------ | :-----: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| children\* | `ActionList.Item[]` or ActionList.LinkItem[] or `ActionList.Group[]` | - | Required. |
| variant | `'inset'` or `'full'` | 'inset' | Optional. Usage is discretionary, `inset` children are offset (vertically and horizontally) from `List`’s edges, `full` children are flush (vertically and horizontally) with `List` edges |
| selectionVariant | `'single'` or `'multiple'` | - | Optional. Whether multiple Items or a single Item can be selected. |
| showDivider | boolean | false | Optional. Display a divider above each `Item` in this `List` when it does not follow a `Header` or `Divider`. |
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |
| role | [AriaRole](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#roles) | - | Optional. The ARIA role describing the function of `List` component. `listbox` or `menu` are a common values. |

<br />

## ActionList.Item

| Name | Type | Default | Description |
| :--------- | :------------------------------------------------------------------------------------------------------------ | :---------: | :----------------------------------------------------------------------------------------------- |
| children\* | one of [`React.ReactNode`, `ActionList.LeadingVisual`, `ActionList.Description`, `ActionList.TrailingVisual`] | - | Required. |
| variant | `'default'` or `'danger'` | `'default'` | Optional. variant="danger" creates a destructive action `Item`. |
| onSelect | Function | - | Optional. Callback that will trigger both on click selection and keyboard selection. |
| selected | boolean | false | Optional. For `Item`s which can be selected, whether the `Item` is currently selected. |
| disabled | boolean | false | Optional. Items that are disabled can not be clicked, selected, or navigated through. |
| role | [AriaRole](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#roles) | - | Optional. The ARIA role describing the function of `Item` component. `option` is a common value. |
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |

<br />

## ActionList.LinkItem

| Name | Type | Default | Description |
| :-------------------------------------------------- | :------------------------------------------------------------------------------------------------------------ | :-----: | :------------------------------------------------------------- |
| children\* | one of [`React.ReactNode`, `ActionList.LeadingVisual`, `ActionList.Description`, `ActionList.TrailingVisual`] | - | Required. |
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |
| + AnchorHTMLAttributes like href, target, rel, etc. | | | |

<br />

## ActionList.LeadingVisual

| Name | Type | Default | Description |
| :--------- | :------------------ | :-----: | :------------------------------------------------------------- |
| children\* | `React.ReactNode` - | - | Required. Icon (or similar) positioned before `Item` text. |
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |

## ActionList.TrailingVisual

| Name | Type | Default | Description |
| :--------- | :------------------ | :-----: | :------------------------------------------------------------- |
| children\* | `React.ReactNode` - | - | Required. Visual positioned after `Item` text. |
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |

<br />

## ActionList.Description

| Name | Type | Default | Description |
| :--------- | :---------------------- | :--------: | :-------------------------------------------------------------------------------------------------------------------------------- |
| children\* | `React.ReactNode` - | - | Required. Visual positioned after `Item` text. |
| variant | `'inline'` or `'block'` | `'inline'` | Optional. `"inline"` secondary text is positioned beside primary text. `"block"` secondary text is positioned below primary text. |
| sx | sxProp | - | Optional. See guide to [Overriding styles](/overriding-styles) |

<br />

## ActionList.Group

| Name | Type | Default | Description |
| :--------------- | :------------------------------------------- | :--------: | :--------------------------------------------------------------------------------------------------------------------------------------- |
| children\* | `ActionList.Item[] or ActionList.LinkItem[]` | - | Required. |
| title | string | - | Optional. Primary text which names a `Group` |
| auxiliaryText | string | - | Optional. Secondary text which provides additional information about a `Group`. |
| variant | `'filled'` or `'subtle'` | `'subtle'` | Optional. `"filled"` - Superimposed on a background, offset from nearby content, `"subtle"` - Relatively less offset from nearby content |
| selectionVariant | `'single'` or `'multiple'` or `false` | - | Optional. Set `selectionVariant` at the group level |

<br />

## Further reading

[Interface guidelines: Action List](https://primer.style/design/components/action-list)

<br />

## Related components

- [ActionMenu](/ActionMenu)
- [SelectPanel](/SelectPanel)

<br />
10 changes: 10 additions & 0 deletions docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as primerComponents from '@primer/components'
import * as experiments from '@primer/components/experiments'
import * as doctocatComponents from '@primer/gatsby-theme-doctocat'
import {
CheckIcon,
Expand All @@ -18,6 +19,10 @@ import {
GearIcon,
TypographyIcon,
VersionsIcon,
LinkIcon,
LawIcon,
StarIcon,
AlertIcon,
ArrowRightIcon
} from '@primer/octicons-react'
import State from '../../../components/State'
Expand All @@ -29,6 +34,7 @@ import {SelectPanel} from '../../../../src/SelectPanel/SelectPanel'
export default {
...doctocatComponents,
...primerComponents,
experiments,
State,
CheckIcon,
SearchIcon,
Expand All @@ -47,6 +53,10 @@ export default {
GearIcon,
TypographyIcon,
VersionsIcon,
LinkIcon,
LawIcon,
StarIcon,
AlertIcon,
ArrowRightIcon,
Dialog2,
ConfirmationDialog,
Expand Down
Loading