Skip to content

Commit

Permalink
ActionList Composable API (#1517)
Browse files Browse the repository at this point in the history
New ActionList component, bundled in @primer/components/unreleased

Co-authored-by: Jonathan Fuchs <jfuchs@github.com>
Co-authored-by: Cole Bemis <colebemis@github.com>
  • Loading branch information
3 people authored Nov 11, 2021
1 parent 8d3d491 commit 561c0bd
Show file tree
Hide file tree
Showing 25 changed files with 2,762 additions and 8 deletions.
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
354 changes: 354 additions & 0 deletions docs/content/ActionList2.mdx

Large diffs are not rendered by default.

17 changes: 17 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,6 @@
import React from 'react'
import * as primerComponents from '@primer/components'
import * as unreleased from '@primer/components/unreleased'
import * as doctocatComponents from '@primer/gatsby-theme-doctocat'
import {
CheckIcon,
Expand All @@ -18,6 +20,10 @@ import {
GearIcon,
TypographyIcon,
VersionsIcon,
LinkIcon,
LawIcon,
StarIcon,
AlertIcon,
ArrowRightIcon
} from '@primer/octicons-react'
import State from '../../../components/State'
Expand All @@ -26,9 +32,16 @@ import {AnchoredOverlay} from '../../../../src/AnchoredOverlay'
import {ConfirmationDialog, useConfirm} from '../../../../src/Dialog/ConfirmationDialog'
import {SelectPanel} from '../../../../src/SelectPanel/SelectPanel'

const ReactRouterLink = ({to, ...props}) => {
// eslint-disable-next-line jsx-a11y/anchor-has-content
return <a href={to} {...props} />
}

export default {
...doctocatComponents,
...primerComponents,
unreleased,
ReactRouterLink,
State,
CheckIcon,
SearchIcon,
Expand All @@ -47,6 +60,10 @@ export default {
GearIcon,
TypographyIcon,
VersionsIcon,
LinkIcon,
LawIcon,
StarIcon,
AlertIcon,
ArrowRightIcon,
Dialog2,
ConfirmationDialog,
Expand Down
153 changes: 146 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"license": "MIT",
"dependencies": {
"@primer/octicons-react": "^13.0.0",
"@primer/primitives": "5.1.0",
"@primer/primitives": "6.1.0",
"@radix-ui/react-polymorphic": "0.0.14",
"@react-aria/ssr": "3.1.0",
"@styled-system/css": "5.1.5",
Expand Down Expand Up @@ -124,6 +124,8 @@
"lodash.isobject": "3.0.2",
"prettier": "2.3.2",
"react": "17.0.2",
"react-dnd": "14.0.4",
"react-dnd-html5-backend": "14.0.2",
"react-dom": "17.0.2",
"react-test-renderer": "17.0.2",
"rollup": "2.56.3",
Expand Down
49 changes: 49 additions & 0 deletions src/ActionList2/Description.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react'
import Box from '../Box'
import {SxProp, merge} from '../sx'
import Truncate from '../Truncate'
import {Slot, ItemContext} from './Item'

export type DescriptionProps = {
/**
* Secondary text style variations.
*
* - `"inline"` - Secondary text is positioned beside primary text.
* - `"block"` - Secondary text is positioned below primary text.
*/
variant?: 'inline' | 'block'
} & SxProp

export const Description: React.FC<DescriptionProps> = ({variant = 'inline', sx = {}, ...props}) => {
const styles = {
color: 'fg.muted',
fontSize: 0,
lineHeight: '16px',
flexGrow: 1,
flexBasis: 0,
minWidth: 0,
marginLeft: variant === 'block' ? 0 : 2
}

return (
<Slot name={variant === 'block' ? 'BlockDescription' : 'InlineDescription'}>
{({blockDescriptionId, inlineDescriptionId}: ItemContext) =>
variant === 'block' ? (
<Box as="span" sx={merge(styles, sx as SxProp)} id={blockDescriptionId}>
{props.children}
</Box>
) : (
<Truncate
id={inlineDescriptionId}
sx={merge(styles, sx as SxProp)}
title={props.children as string}
inline={true}
maxWidth="100%"
>
{props.children}
</Truncate>
)
}
</Slot>
)
}
24 changes: 24 additions & 0 deletions src/ActionList2/Divider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import Box from '../Box'
import {get} from '../constants'
import {Theme} from '../ThemeProvider'

/**
* Visually separates `Item`s or `Group`s in an `ActionList`.
*/
export function Divider(): JSX.Element {
return (
<Box
as="li"
role="separator"
sx={{
height: 1,
backgroundColor: 'actionListItem.inlineDivider',
marginTop: (theme: Theme) => `calc(${get('space.2')(theme)} - 1px)`,
marginBottom: 2,
listStyle: 'none' // hide the ::marker inserted by browser's stylesheet
}}
data-component="ActionList.Divider"
/>
)
}
Loading

0 comments on commit 561c0bd

Please sign in to comment.