Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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/action-list-small-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

ActionList: Add a `size` prop with a `small` option for compact lists.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions e2e/components/ActionList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const stories = [
title: 'Simple List',
id: 'components-actionlist-features--simple-list',
},
{
title: 'Small List',
id: 'components-actionlist-features--small-list',
},
{
title: 'Single Divider',
id: 'components-actionlist-features--single-divider',
Expand Down
10 changes: 8 additions & 2 deletions packages/react/src/ActionList/ActionList.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"defaultValue": "",
"description": "Whether multiple items or a single item can be selected."
},
{
"name": "size",
"type": "'small' | 'medium'",
"defaultValue": "'medium'",
"description": "The size of the ActionList items."
},
{
"name": "showDividers",
"type": "boolean",
Expand Down Expand Up @@ -57,7 +63,7 @@
},
{
"name": "size",
"type": "'medium' | 'large'",
"type": "'small' | 'medium' | 'large'",
"defaultValue": "'medium'",
"description": "The block size of the ActionList items."
},
Expand Down Expand Up @@ -355,4 +361,4 @@
]
}
]
}
}
21 changes: 21 additions & 0 deletions packages/react/src/ActionList/ActionList.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ export const SimpleList = () => (
</ActionList>
)

export const SmallList = () => (
<ActionList size="small">
<ActionList.Item>
<ActionList.LeadingVisual>
<LinkIcon />
</ActionList.LeadingVisual>
Copy link
</ActionList.Item>
<ActionList.Item>
Quote reply
<ActionList.Description>Reply with selected text</ActionList.Description>
</ActionList.Item>
<ActionList.LinkItem href="https://github.com/primer/react">
<ActionList.LeadingVisual>
<BookIcon />
</ActionList.LeadingVisual>
View repository
</ActionList.LinkItem>
</ActionList>
)

export const WithVisualListHeading = () => (
<ActionList>
<ActionList.Heading as="h2" size="small">
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/ActionList/ActionList.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,16 @@
padding-block: var(--control-large-paddingBlock);
}

&[data-size='small'] {
/* stylelint-disable-next-line primer/spacing */
padding-block: var(--control-small-paddingBlock);

& .ItemLabel,
& .TrailingVisual {
font-size: var(--text-body-size-small);
}
}

/* collapsible item [aria-expanded] */

&[aria-expanded='true'] {
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/ActionList/ActionList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const Playground: StoryFn<ActionListProps> = args => (
</ActionList>
)
Playground.args = {
size: 'medium',
showDividers: false,
selectionVariant: undefined,
variant: 'inset',
Expand All @@ -46,6 +47,12 @@ Playground.argTypes = {
},
options: ['inset', 'horizontal-inset', 'full'],
},
size: {
control: {
type: 'radio',
},
options: ['small', 'medium'],
},
selectionVariant: {
control: {
type: 'radio',
Expand Down
18 changes: 18 additions & 0 deletions packages/react/src/ActionList/ActionList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ describe('ActionList', () => {
expect(linkElements[1]).toHaveAttribute('data-size', 'medium')
expect(linkElements[2]).toHaveAttribute('data-size', 'medium') // default should be medium
})

it('should support size prop on ActionList', () => {
const {container} = HTMLRender(
<ActionList size="small">
<ActionList.Item>Small Item</ActionList.Item>
<ActionList.LinkItem href="//github.com">Small Link Item</ActionList.LinkItem>
<ActionList.Item size="large">Large Item</ActionList.Item>
</ActionList>,
)

const actionList = container.querySelector('[data-component="ActionList"]')
const itemElements = container.querySelectorAll('button, a')

expect(actionList).toHaveAttribute('data-size', 'small')
expect(itemElements[0]).toHaveAttribute('data-size', 'small')
expect(itemElements[1]).toHaveAttribute('data-size', 'small')
expect(itemElements[2]).toHaveAttribute('data-size', 'large')
})
})

describe('ActionList data-component attributes', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const listRoleTypes = ['listbox', 'menu', 'list', 'tree']
const UnwrappedItem = <As extends React.ElementType = 'li'>(
{
variant = 'default',
size = 'medium',
size: sizeProp,
disabled = false,
inactiveText,
selected = undefined,
Expand Down Expand Up @@ -118,8 +118,9 @@ const UnwrappedItem = <As extends React.ElementType = 'li'>(
) : null
const trailingVisual = slots.trailingVisual ?? wrappedDefaultTrailingVisual

const {role: listRole, selectionVariant: listSelectionVariant} = React.useContext(ListContext)
const {role: listRole, selectionVariant: listSelectionVariant, size: listSize} = React.useContext(ListContext)
const {selectionVariant: groupSelectionVariant} = React.useContext(GroupContext)
const size = sizeProp ?? listSize ?? 'medium'
const inactive = Boolean(inactiveText)
// TODO change `menuContext` check to ```listRole !== undefined && ['menu', 'listbox'].includes(listRole)```
// once we have a better way to handle existing usage in dotcom that incorrectly use ActionList.TrailingAction
Expand Down
5 changes: 4 additions & 1 deletion packages/react/src/ActionList/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const UnwrappedList = <As extends React.ElementType = 'ul'>(
as: Component = 'ul',
variant = 'inset',
selectionVariant,
size = 'medium',
showDividers = false,
role,
disableFocusZone = false,
Expand Down Expand Up @@ -62,11 +63,12 @@ const UnwrappedList = <As extends React.ElementType = 'ul'>(
() => ({
variant,
selectionVariant: selectionVariant || containerSelectionVariant,
size,
showDividers,
role: listRole,
headingId,
}),
[variant, selectionVariant, containerSelectionVariant, showDividers, listRole, headingId],
[variant, selectionVariant, containerSelectionVariant, size, showDividers, listRole, headingId],
)

// Replaces a CSS `:has([data-has-description])` selector that caused full-subtree
Expand Down Expand Up @@ -109,6 +111,7 @@ const UnwrappedList = <As extends React.ElementType = 'ul'>(
data-component="ActionList"
data-dividers={showDividers}
data-variant={variant}
data-size={size}
data-item-gap={itemGapEnabled ? '' : undefined}
{...restProps}
>
Expand Down
8 changes: 6 additions & 2 deletions packages/react/src/ActionList/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type ActionListItemProps<As extends React.ElementType = 'li'> = ExcludeSe
* - `"danger"` - A destructive action `Item`.
*/
variant?: 'default' | 'danger'
size?: 'medium' | 'large'
size?: 'small' | 'medium' | 'large'
/**
* Items that are disabled can not be clicked, selected, or navigated through.
*/
Expand Down Expand Up @@ -143,6 +143,10 @@ export type ActionListProps<As extends React.ElementType = 'ul'> = PolymorphicPr
* Whether multiple Items or a single Item can be selected.
*/
selectionVariant?: 'single' | 'radio' | 'multiple'
/**
* The size of the ActionList items.
*/
size?: 'small' | 'medium'
/**
* Display a divider above each `Item` in this `List` when it does not follow a `Header` or `Divider`.
*/
Expand All @@ -161,7 +165,7 @@ export type ActionListProps<As extends React.ElementType = 'ul'> = PolymorphicPr

type ContextProps = Pick<
ActionListProps<React.ElementType>,
'variant' | 'selectionVariant' | 'showDividers' | 'role'
'variant' | 'selectionVariant' | 'showDividers' | 'role' | 'size'
> & {
headingId?: string
}
Expand Down
Loading