@primer/components 31.0.2-rc.c7dafefb → 31.2.0-rc.2a086bac
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/main.js +7 -9
- package/.storybook/preview.js +5 -1
- package/CHANGELOG.md +21 -1
- package/dist/browser.esm.js +623 -620
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +164 -161
- package/dist/browser.umd.js.map +1 -1
- package/docs/content/ActionList2.mdx +354 -0
- package/docs/content/FilterList.md +2 -2
- package/docs/content/TextInputWithTokens.mdx +114 -0
- package/docs/content/theming.md +23 -0
- package/docs/src/@primer/gatsby-theme-doctocat/components/hero.js +1 -3
- package/docs/src/@primer/gatsby-theme-doctocat/components/live-preview-wrapper.js +1 -1
- package/docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js +17 -0
- package/lib/ActionList/Header.js +1 -1
- package/lib/ActionList2/Description.d.ts +12 -0
- package/lib/ActionList2/Description.js +53 -0
- package/lib/ActionList2/Divider.d.ts +5 -0
- package/lib/ActionList2/Divider.js +35 -0
- package/lib/ActionList2/Group.d.ts +11 -0
- package/lib/ActionList2/Group.js +57 -0
- package/lib/ActionList2/Header.d.ts +26 -0
- package/lib/ActionList2/Header.js +55 -0
- package/lib/ActionList2/Item.d.ts +63 -0
- package/lib/ActionList2/Item.js +234 -0
- package/lib/ActionList2/LinkItem.d.ts +17 -0
- package/lib/ActionList2/LinkItem.js +57 -0
- package/lib/ActionList2/List.d.ts +26 -0
- package/lib/ActionList2/List.js +59 -0
- package/lib/ActionList2/Selection.d.ts +5 -0
- package/lib/ActionList2/Selection.js +70 -0
- package/lib/ActionList2/Visuals.d.ts +9 -0
- package/lib/ActionList2/Visuals.js +90 -0
- package/lib/ActionList2/index.d.ts +36 -0
- package/lib/ActionList2/index.js +47 -0
- package/lib/Autocomplete/Autocomplete.d.ts +4 -4
- package/lib/Autocomplete/AutocompleteInput.d.ts +4 -4
- package/lib/Button/Button.d.ts +5 -5
- package/lib/Button/ButtonBase.d.ts +1 -1
- package/lib/Button/ButtonClose.d.ts +3 -3
- package/lib/Button/ButtonDanger.d.ts +5 -5
- package/lib/Button/ButtonInvisible.d.ts +5 -5
- package/lib/Button/ButtonOutline.d.ts +5 -5
- package/lib/Button/ButtonPrimary.d.ts +5 -5
- package/lib/CircleBadge.d.ts +2 -2
- package/lib/CircleOcticon.d.ts +4 -4
- package/lib/Dialog.d.ts +4 -4
- package/lib/Dropdown.d.ts +16 -16
- package/lib/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib/FilterList.d.ts +3 -3
- package/lib/Flash.d.ts +1 -1
- package/lib/Label.d.ts +1 -1
- package/lib/Overlay.js +3 -1
- package/lib/Portal/Portal.js +3 -2
- package/lib/Position.d.ts +4 -4
- package/lib/ProgressBar.d.ts +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +24 -24
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/TextInputWithTokens.d.ts +8 -4
- package/lib/TextInputWithTokens.js +61 -8
- package/lib/Timeline.d.ts +4 -4
- package/lib/Token/AvatarToken.d.ts +1 -1
- package/lib/Token/IssueLabelToken.d.ts +1 -1
- package/lib/Token/Token.d.ts +1 -1
- package/lib/_TextInputWrapper.d.ts +1 -1
- package/lib/_TextInputWrapper.js +2 -2
- package/lib/__tests__/ActionList2.test.d.ts +1 -0
- package/lib/__tests__/ActionList2.test.js +53 -0
- package/lib/__tests__/AnchoredOverlay.test.js +4 -2
- package/lib/__tests__/KeyPaths.types.test.d.ts +11 -0
- package/lib/__tests__/KeyPaths.types.test.js +10 -0
- package/lib/__tests__/TextInputWithTokens.test.js +138 -7
- package/lib/__tests__/utils/createSlots.test.d.ts +1 -0
- package/lib/__tests__/utils/createSlots.test.js +75 -0
- package/lib/hooks/useAnchoredPosition.js +3 -2
- package/lib/hooks/useCombinedRefs.d.ts +2 -2
- package/lib/hooks/useCombinedRefs.js +4 -6
- package/lib/hooks/useResizeObserver.js +2 -2
- package/lib/stories/ActionList2.stories.js +875 -0
- package/lib/stories/TextInput.stories.js +144 -0
- package/lib/stories/TextInputWithTokens.stories.js +18 -1
- package/lib/stories/Token.stories.js +19 -2
- package/lib/sx.d.ts +10 -2
- package/lib/sx.js +8 -0
- package/lib/theme-preval.js +81 -2
- package/lib/theme.d.ts +78 -0
- package/lib/theme.js +3 -1
- package/lib/unreleased.d.ts +7 -0
- package/lib/unreleased.js +18 -0
- package/lib/utils/create-slots.d.ts +17 -0
- package/lib/utils/create-slots.js +105 -0
- package/lib/utils/testing.d.ts +14 -1
- package/lib/utils/types/KeyPaths.d.ts +3 -0
- package/lib/utils/types/KeyPaths.js +1 -0
- package/lib/utils/use-force-update.d.ts +1 -0
- package/lib/utils/use-force-update.js +19 -0
- package/lib/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib/utils/useIsomorphicLayoutEffect.js +12 -0
- package/lib-esm/ActionList/Header.js +1 -1
- package/lib-esm/ActionList2/Description.d.ts +12 -0
- package/lib-esm/ActionList2/Description.js +37 -0
- package/lib-esm/ActionList2/Divider.d.ts +5 -0
- package/lib-esm/ActionList2/Divider.js +23 -0
- package/lib-esm/ActionList2/Group.d.ts +11 -0
- package/lib-esm/ActionList2/Group.js +40 -0
- package/lib-esm/ActionList2/Header.d.ts +26 -0
- package/lib-esm/ActionList2/Header.js +44 -0
- package/lib-esm/ActionList2/Item.d.ts +63 -0
- package/lib-esm/ActionList2/Item.js +201 -0
- package/lib-esm/ActionList2/LinkItem.d.ts +17 -0
- package/lib-esm/ActionList2/LinkItem.js +43 -0
- package/lib-esm/ActionList2/List.d.ts +26 -0
- package/lib-esm/ActionList2/List.js +37 -0
- package/lib-esm/ActionList2/Selection.d.ts +5 -0
- package/lib-esm/ActionList2/Selection.js +52 -0
- package/lib-esm/ActionList2/Visuals.d.ts +9 -0
- package/lib-esm/ActionList2/Visuals.js +68 -0
- package/lib-esm/ActionList2/index.d.ts +36 -0
- package/lib-esm/ActionList2/index.js +33 -0
- package/lib-esm/Autocomplete/Autocomplete.d.ts +4 -4
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +4 -4
- package/lib-esm/Button/Button.d.ts +5 -5
- package/lib-esm/Button/ButtonBase.d.ts +1 -1
- package/lib-esm/Button/ButtonClose.d.ts +3 -3
- package/lib-esm/Button/ButtonDanger.d.ts +5 -5
- package/lib-esm/Button/ButtonInvisible.d.ts +5 -5
- package/lib-esm/Button/ButtonOutline.d.ts +5 -5
- package/lib-esm/Button/ButtonPrimary.d.ts +5 -5
- package/lib-esm/CircleBadge.d.ts +2 -2
- package/lib-esm/CircleOcticon.d.ts +4 -4
- package/lib-esm/Dialog.d.ts +4 -4
- package/lib-esm/Dropdown.d.ts +16 -16
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib-esm/FilterList.d.ts +3 -3
- package/lib-esm/Flash.d.ts +1 -1
- package/lib-esm/Label.d.ts +1 -1
- package/lib-esm/Overlay.js +2 -1
- package/lib-esm/Portal/Portal.js +2 -1
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/ProgressBar.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +24 -24
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.d.ts +8 -4
- package/lib-esm/TextInputWithTokens.js +60 -8
- package/lib-esm/Timeline.d.ts +4 -4
- package/lib-esm/Token/AvatarToken.d.ts +1 -1
- package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
- package/lib-esm/Token/Token.d.ts +1 -1
- package/lib-esm/_TextInputWrapper.d.ts +1 -1
- package/lib-esm/_TextInputWrapper.js +2 -2
- package/lib-esm/__tests__/ActionList2.test.d.ts +1 -0
- package/lib-esm/__tests__/ActionList2.test.js +41 -0
- package/lib-esm/__tests__/AnchoredOverlay.test.js +4 -2
- package/lib-esm/__tests__/KeyPaths.types.test.d.ts +11 -0
- package/lib-esm/__tests__/KeyPaths.types.test.js +3 -0
- package/lib-esm/__tests__/TextInputWithTokens.test.js +132 -8
- package/lib-esm/__tests__/utils/createSlots.test.d.ts +1 -0
- package/lib-esm/__tests__/utils/createSlots.test.js +67 -0
- package/lib-esm/hooks/useAnchoredPosition.js +2 -1
- package/lib-esm/hooks/useCombinedRefs.d.ts +2 -2
- package/lib-esm/hooks/useCombinedRefs.js +3 -2
- package/lib-esm/hooks/useResizeObserver.js +2 -2
- package/lib-esm/stories/ActionList2.stories.js +764 -0
- package/lib-esm/stories/TextInput.stories.js +117 -0
- package/lib-esm/stories/TextInputWithTokens.stories.js +14 -0
- package/lib-esm/stories/Token.stories.js +14 -1
- package/lib-esm/sx.d.ts +10 -2
- package/lib-esm/sx.js +3 -1
- package/lib-esm/theme-preval.js +81 -2
- package/lib-esm/theme.d.ts +78 -0
- package/lib-esm/theme.js +2 -1
- package/lib-esm/unreleased.d.ts +7 -0
- package/lib-esm/unreleased.js +8 -0
- package/lib-esm/utils/create-slots.d.ts +17 -0
- package/lib-esm/utils/create-slots.js +84 -0
- package/lib-esm/utils/testing.d.ts +14 -1
- package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
- package/lib-esm/utils/types/KeyPaths.js +1 -0
- package/lib-esm/utils/use-force-update.d.ts +1 -0
- package/lib-esm/utils/use-force-update.js +6 -0
- package/lib-esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib-esm/utils/useIsomorphicLayoutEffect.js +3 -0
- package/migrating.md +1 -1
- package/package-lock.json +38098 -45
- package/package.json +7 -3
- package/script/build +2 -0
- package/src/ActionList/Header.tsx +1 -1
- package/src/ActionList2/Description.tsx +49 -0
- package/src/ActionList2/Divider.tsx +24 -0
- package/src/ActionList2/Group.tsx +34 -0
- package/src/ActionList2/Header.tsx +58 -0
- package/src/ActionList2/Item.tsx +228 -0
- package/src/ActionList2/LinkItem.tsx +49 -0
- package/src/ActionList2/List.tsx +55 -0
- package/src/ActionList2/Selection.tsx +40 -0
- package/src/ActionList2/Visuals.tsx +76 -0
- package/src/ActionList2/index.ts +39 -0
- package/src/Overlay.tsx +2 -1
- package/src/Portal/Portal.tsx +2 -1
- package/src/TextInputWithTokens.tsx +64 -8
- package/src/_TextInputWrapper.tsx +8 -0
- package/src/__tests__/ActionList2.test.tsx +47 -0
- package/src/__tests__/AnchoredOverlay.test.tsx +2 -2
- package/src/__tests__/KeyPaths.types.test.ts +14 -0
- package/src/__tests__/TextInputWithTokens.test.tsx +123 -1
- package/src/__tests__/__snapshots__/ActionList2.test.tsx.snap +14 -0
- package/src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap +35 -135
- package/src/__tests__/__snapshots__/Autocomplete.test.tsx.snap +7 -0
- package/src/__tests__/__snapshots__/TextInput.test.tsx.snap +6 -0
- package/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap +463 -0
- package/src/__tests__/utils/__snapshots__/createSlots.test.tsx.snap +55 -0
- package/src/__tests__/utils/createSlots.test.tsx +74 -0
- package/src/hooks/useAnchoredPosition.ts +2 -1
- package/src/hooks/useCombinedRefs.ts +3 -3
- package/src/hooks/useResizeObserver.ts +2 -2
- package/src/stories/ActionList2.stories.tsx +1279 -0
- package/src/stories/Button.stories.tsx +1 -1
- package/src/stories/TextInput.stories.tsx +113 -0
- package/src/stories/TextInputWithTokens.stories.tsx +9 -0
- package/src/stories/Token.stories.tsx +12 -1
- package/src/sx.ts +17 -2
- package/src/theme-preval.js +1 -0
- package/src/theme.ts +86 -0
- package/src/unreleased.ts +9 -0
- package/src/utils/create-slots.tsx +96 -0
- package/src/utils/types/KeyPaths.ts +10 -0
- package/src/utils/use-force-update.ts +7 -0
- package/src/utils/useIsomorphicLayoutEffect.ts +10 -0
- package/stats.html +1 -1
@@ -77,7 +77,7 @@ export const buttonGroup = (args: StrictButtonStyleProps) => (
|
|
77
77
|
export const buttonTableList = (args: ButtonStyleProps) => (
|
78
78
|
<ButtonTableList {...args}>Button Table List</ButtonTableList>
|
79
79
|
)
|
80
|
-
export const disabledButton = (args:
|
80
|
+
export const disabledButton = (args: StrictButtonStyleProps) => {
|
81
81
|
const props = {disabled: true, ...args}
|
82
82
|
return <Button {...props}>Disabled</Button>
|
83
83
|
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import React, {useState, ReactNode} from 'react'
|
2
|
+
import {Meta} from '@storybook/react'
|
3
|
+
|
4
|
+
import {BaseStyles, Box, ThemeProvider, Text} from '..'
|
5
|
+
import TextInput, {TextInputProps} from '../TextInput'
|
6
|
+
import {CheckIcon} from '@primer/octicons-react'
|
7
|
+
|
8
|
+
export default {
|
9
|
+
title: 'Forms/Text Input',
|
10
|
+
component: TextInput,
|
11
|
+
decorators: [
|
12
|
+
Story => {
|
13
|
+
return (
|
14
|
+
<ThemeProvider>
|
15
|
+
<BaseStyles>
|
16
|
+
<Box paddingTop={5}>{Story()}</Box>
|
17
|
+
</BaseStyles>
|
18
|
+
</ThemeProvider>
|
19
|
+
)
|
20
|
+
}
|
21
|
+
],
|
22
|
+
argTypes: {
|
23
|
+
sx: {
|
24
|
+
table: {
|
25
|
+
disable: true
|
26
|
+
}
|
27
|
+
},
|
28
|
+
block: {
|
29
|
+
name: 'Block',
|
30
|
+
defaultValue: false,
|
31
|
+
control: {
|
32
|
+
type: 'boolean'
|
33
|
+
}
|
34
|
+
},
|
35
|
+
disabled: {
|
36
|
+
name: 'Disabled',
|
37
|
+
defaultValue: false,
|
38
|
+
control: {
|
39
|
+
type: 'boolean'
|
40
|
+
}
|
41
|
+
},
|
42
|
+
variant: {
|
43
|
+
name: 'Variants',
|
44
|
+
options: ['small', 'medium', 'large'],
|
45
|
+
control: {type: 'radio'}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
} as Meta
|
49
|
+
|
50
|
+
const Label = ({htmlFor, children}: {htmlFor: string; children: ReactNode}) => (
|
51
|
+
<Text as="label" htmlFor={htmlFor} sx={{fontWeight: 600, fontSize: 14}}>
|
52
|
+
{children}
|
53
|
+
</Text>
|
54
|
+
)
|
55
|
+
|
56
|
+
export const Default = (args: TextInputProps) => {
|
57
|
+
const [value, setValue] = useState('')
|
58
|
+
|
59
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
60
|
+
setValue(event.target.value)
|
61
|
+
}
|
62
|
+
|
63
|
+
const inputId = 'basic-text-input'
|
64
|
+
|
65
|
+
return (
|
66
|
+
<form>
|
67
|
+
<div className="form-group">
|
68
|
+
<div className="form-group-header">
|
69
|
+
<Label htmlFor={inputId}>Example label</Label>
|
70
|
+
</div>
|
71
|
+
<div className="form-group-body">
|
72
|
+
<TextInput id={inputId} value={value} onChange={handleChange} {...args} />
|
73
|
+
</div>
|
74
|
+
</div>
|
75
|
+
</form>
|
76
|
+
)
|
77
|
+
}
|
78
|
+
|
79
|
+
export const WithLeadingIcon = (args: TextInputProps) => {
|
80
|
+
const [value, setValue] = useState('')
|
81
|
+
|
82
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
83
|
+
setValue(event.target.value)
|
84
|
+
}
|
85
|
+
|
86
|
+
const inputId = 'basic-text-input-with-leading-icon'
|
87
|
+
|
88
|
+
return (
|
89
|
+
<form>
|
90
|
+
<Label htmlFor={inputId}>Example label</Label>
|
91
|
+
<br />
|
92
|
+
<TextInput icon={CheckIcon} id={inputId} value={value} onChange={handleChange} type="password" {...args} />
|
93
|
+
</form>
|
94
|
+
)
|
95
|
+
}
|
96
|
+
|
97
|
+
export const Password = (args: TextInputProps) => {
|
98
|
+
const [value, setValue] = useState('')
|
99
|
+
|
100
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
101
|
+
setValue(event.target.value)
|
102
|
+
}
|
103
|
+
|
104
|
+
const inputId = 'basic-text-input-as-password'
|
105
|
+
|
106
|
+
return (
|
107
|
+
<form>
|
108
|
+
<Label htmlFor={inputId}>Password</Label>
|
109
|
+
<br />
|
110
|
+
<TextInput type="password" id={inputId} value={value} onChange={handleChange} {...args} />
|
111
|
+
</form>
|
112
|
+
)
|
113
|
+
}
|
@@ -121,6 +121,15 @@ export const TokenRemoveButtonsHidden = () => {
|
|
121
121
|
return <TextInputWithTokens hideTokenRemoveButtons tokens={tokens} onTokenRemove={onTokenRemove} />
|
122
122
|
}
|
123
123
|
|
124
|
+
export const WithVisibleTokenCount = () => {
|
125
|
+
const [tokens, setTokens] = useState([...mockTokens].slice(0, 5))
|
126
|
+
const onTokenRemove: (tokenId: string | number) => void = tokenId => {
|
127
|
+
setTokens(tokens.filter(token => token.id !== tokenId))
|
128
|
+
}
|
129
|
+
|
130
|
+
return <TextInputWithTokens tokens={tokens} onTokenRemove={onTokenRemove} visibleTokenCount={2} />
|
131
|
+
}
|
132
|
+
|
124
133
|
export const Unstyled = () => {
|
125
134
|
const [tokens, setTokens] = useState([...mockTokens].slice(0, 2))
|
126
135
|
const onTokenRemove: (tokenId: string | number) => void = tokenId => {
|
@@ -7,6 +7,7 @@ import {BaseStyles, ThemeProvider} from '..'
|
|
7
7
|
import Box from '../Box'
|
8
8
|
import Token, {TokenProps} from '../Token/Token'
|
9
9
|
import Text from '../Text'
|
10
|
+
import {GitBranchIcon} from '@primer/octicons-react'
|
10
11
|
|
11
12
|
export default {
|
12
13
|
title: 'Tokens/Default',
|
@@ -29,7 +30,7 @@ export default {
|
|
29
30
|
]
|
30
31
|
} as Meta
|
31
32
|
|
32
|
-
const excludedControlKeys = ['id', 'as', 'tabIndex', 'onRemove']
|
33
|
+
const excludedControlKeys = ['id', 'as', 'tabIndex', 'onRemove', 'leadingVisual']
|
33
34
|
|
34
35
|
const SingleExampleContainer: React.FC<{label?: string}> = ({children, label}) => (
|
35
36
|
<Box
|
@@ -94,6 +95,16 @@ export const Interactive = (args: Omit<TokenProps, 'ref' | 'text'>) => {
|
|
94
95
|
}
|
95
96
|
Interactive.parameters = {controls: {exclude: [...excludedControlKeys, 'hideRemoveButton', 'text']}}
|
96
97
|
|
98
|
+
export const WithLeadingVisual = (args: Omit<TokenProps, 'ref'>) => {
|
99
|
+
return (
|
100
|
+
<ExampleCollectionContainer>
|
101
|
+
<Token {...args} leadingVisual={() => <GitBranchIcon />} />
|
102
|
+
</ExampleCollectionContainer>
|
103
|
+
)
|
104
|
+
}
|
105
|
+
WithLeadingVisual.storyName = 'with leadingVisual'
|
106
|
+
WithLeadingVisual.parameters = {controls: {exclude: [...excludedControlKeys, 'hideRemoveButton']}}
|
107
|
+
|
97
108
|
export const WithOnRemoveFn = (args: Omit<TokenProps, 'ref'>) => {
|
98
109
|
return (
|
99
110
|
<ExampleCollectionContainer>
|
package/src/sx.ts
CHANGED
@@ -1,9 +1,24 @@
|
|
1
|
-
import css, {SystemStyleObject} from '@styled-system/css'
|
1
|
+
import css, {SystemCssProperties, SystemStyleObject} from '@styled-system/css'
|
2
|
+
import {ThemeColorPaths, ThemeShadowPaths} from './theme'
|
3
|
+
import {ColorProps, ShadowProps} from 'styled-system'
|
4
|
+
import merge from 'deepmerge'
|
5
|
+
|
6
|
+
export type BetterCssProperties = {
|
7
|
+
[K in keyof SystemCssProperties]: K extends keyof ColorProps
|
8
|
+
? ThemeColorPaths | SystemCssProperties[K]
|
9
|
+
: K extends keyof ShadowProps
|
10
|
+
? ThemeShadowPaths | SystemCssProperties[K]
|
11
|
+
: SystemCssProperties[K]
|
12
|
+
}
|
13
|
+
|
14
|
+
export type BetterSystemStyleObject = BetterCssProperties | SystemStyleObject
|
2
15
|
|
3
16
|
export interface SxProp {
|
4
|
-
sx?:
|
17
|
+
sx?: BetterSystemStyleObject
|
5
18
|
}
|
6
19
|
|
7
20
|
const sx = (props: SxProp) => css(props.sx)
|
8
21
|
|
9
22
|
export default sx
|
23
|
+
|
24
|
+
export {merge}
|
package/src/theme-preval.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
// @preval
|
2
2
|
// This file needs to be a JavaScript file using CommonJS to be compatiable with preval
|
3
|
+
// Cache bust: 2021-11-04 12:00:00 GMT (This file is cached by our deployment tooling, update this timestamp to rebuild this file)
|
3
4
|
|
4
5
|
const {default: primitives} = require('@primer/primitives')
|
5
6
|
const {partitionColors, fontStack, omitScale} = require('./utils/theme')
|
package/src/theme.ts
CHANGED
@@ -1,3 +1,89 @@
|
|
1
1
|
import {theme} from './theme-preval'
|
2
|
+
import {KeyPaths} from './utils/types/KeyPaths'
|
2
3
|
|
3
4
|
export default theme
|
5
|
+
|
6
|
+
// NOTE: for now, ThemeColors and ThemeShadows are handcrafted types. It would be nice if these
|
7
|
+
// were exports from primitives (or a different shape but derived from those exports).
|
8
|
+
|
9
|
+
type ThemeColors = {
|
10
|
+
fg: {
|
11
|
+
default: string
|
12
|
+
muted: string
|
13
|
+
subtle: string
|
14
|
+
onEmphasis: string
|
15
|
+
}
|
16
|
+
canvas: {
|
17
|
+
default: string
|
18
|
+
overlay: string
|
19
|
+
inset: string
|
20
|
+
subtle: string
|
21
|
+
}
|
22
|
+
border: {
|
23
|
+
default: string
|
24
|
+
muted: string
|
25
|
+
subtle: string
|
26
|
+
}
|
27
|
+
|
28
|
+
// Roles
|
29
|
+
neutral: {
|
30
|
+
emphasisPlus: string
|
31
|
+
emphasis: string
|
32
|
+
muted: string
|
33
|
+
subtle: string
|
34
|
+
}
|
35
|
+
accent: {
|
36
|
+
fg: string
|
37
|
+
emphasis: string
|
38
|
+
muted: string
|
39
|
+
subtle: string
|
40
|
+
}
|
41
|
+
success: {
|
42
|
+
fg: string
|
43
|
+
emphasis: string
|
44
|
+
muted: string
|
45
|
+
subtle: string
|
46
|
+
}
|
47
|
+
attention: {
|
48
|
+
fg: string
|
49
|
+
emphasis: string
|
50
|
+
muted: string
|
51
|
+
subtle: string
|
52
|
+
}
|
53
|
+
severe: {
|
54
|
+
fg: string
|
55
|
+
emphasis: string
|
56
|
+
muted: string
|
57
|
+
subtle: string
|
58
|
+
}
|
59
|
+
danger: {
|
60
|
+
fg: string
|
61
|
+
emphasis: string
|
62
|
+
muted: string
|
63
|
+
subtle: string
|
64
|
+
}
|
65
|
+
done: {
|
66
|
+
fg: string
|
67
|
+
emphasis: string
|
68
|
+
muted: string
|
69
|
+
subtle: string
|
70
|
+
}
|
71
|
+
sponsors: {
|
72
|
+
fg: string
|
73
|
+
emphasis: string
|
74
|
+
muted: string
|
75
|
+
subtle: string
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
type ThemeShadows = {
|
80
|
+
shadow: {
|
81
|
+
small: string
|
82
|
+
medium: string
|
83
|
+
large: string
|
84
|
+
extraLarge: string
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
export type ThemeColorPaths = KeyPaths<ThemeColors>
|
89
|
+
export type ThemeShadowPaths = KeyPaths<ThemeShadows>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/** This is the place where we keep components that are not part of the public
|
2
|
+
* api yet (not in main bundle). We don't recommend using it in production.
|
3
|
+
*
|
4
|
+
* But, they are published on npm and you can import them for experimentation/feedback.
|
5
|
+
* example: import {ActionList} from '@primer/components/unreleased
|
6
|
+
*/
|
7
|
+
|
8
|
+
// Components
|
9
|
+
export * from './ActionList2'
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import {useForceUpdate} from './use-force-update'
|
3
|
+
|
4
|
+
/** createSlots is a factory that can create a
|
5
|
+
* typesafe Slots + Slot pair to use in a component definition
|
6
|
+
* For example: ActionList.Item uses createSlots to get a Slots wrapper
|
7
|
+
* + Slot component that is used by LeadingVisual, Description
|
8
|
+
*/
|
9
|
+
const createSlots = <SlotNames extends string>(slotNames: SlotNames[]) => {
|
10
|
+
type Slots = {
|
11
|
+
[key in SlotNames]?: React.ReactNode
|
12
|
+
}
|
13
|
+
|
14
|
+
type ContextProps = {
|
15
|
+
registerSlot: (name: SlotNames, contents: React.ReactNode) => void
|
16
|
+
unregisterSlot: (name: SlotNames) => void
|
17
|
+
context: Record<string, unknown>
|
18
|
+
}
|
19
|
+
const SlotsContext = React.createContext<ContextProps>({
|
20
|
+
registerSlot: () => null,
|
21
|
+
unregisterSlot: () => null,
|
22
|
+
context: {}
|
23
|
+
})
|
24
|
+
|
25
|
+
/** Slots uses a Double render strategy inspired by [reach-ui/descendants](https://github.com/reach/reach-ui/tree/develop/packages/descendants)
|
26
|
+
* Slot registers themself with the Slots parent.
|
27
|
+
* When all the children have mounted = registered themselves in slot,
|
28
|
+
* we re-render the parent component to render with slots
|
29
|
+
*/
|
30
|
+
const Slots: React.FC<{
|
31
|
+
context?: ContextProps['context']
|
32
|
+
children: (slots: Slots) => React.ReactNode
|
33
|
+
}> = ({context = {}, children}) => {
|
34
|
+
// initialise slots
|
35
|
+
const slotsDefinition: Slots = {}
|
36
|
+
slotNames.map(name => (slotsDefinition[name] = null))
|
37
|
+
const slotsRef = React.useRef<Slots>(slotsDefinition)
|
38
|
+
|
39
|
+
const rerenderWithSlots = useForceUpdate()
|
40
|
+
const [isMounted, setIsMounted] = React.useState(false)
|
41
|
+
|
42
|
+
// fires after all the effects in children
|
43
|
+
React.useEffect(() => {
|
44
|
+
rerenderWithSlots()
|
45
|
+
setIsMounted(true)
|
46
|
+
}, [rerenderWithSlots])
|
47
|
+
|
48
|
+
const registerSlot = React.useCallback(
|
49
|
+
(name: SlotNames, contents: React.ReactNode) => {
|
50
|
+
slotsRef.current[name] = contents
|
51
|
+
|
52
|
+
// don't render until the component mounts = all slots are registered
|
53
|
+
if (isMounted) rerenderWithSlots()
|
54
|
+
},
|
55
|
+
[isMounted, rerenderWithSlots]
|
56
|
+
)
|
57
|
+
|
58
|
+
// Slot can be removed from the tree as well,
|
59
|
+
// we need to unregister them from the slot
|
60
|
+
const unregisterSlot = React.useCallback(
|
61
|
+
(name: SlotNames) => {
|
62
|
+
slotsRef.current[name] = null
|
63
|
+
rerenderWithSlots()
|
64
|
+
},
|
65
|
+
[rerenderWithSlots]
|
66
|
+
)
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Slots uses a render prop API so abstract the
|
70
|
+
* implementation detail of using a context provider.
|
71
|
+
*/
|
72
|
+
const slots = slotsRef.current
|
73
|
+
|
74
|
+
return (
|
75
|
+
<SlotsContext.Provider value={{registerSlot, unregisterSlot, context}}>{children(slots)}</SlotsContext.Provider>
|
76
|
+
)
|
77
|
+
}
|
78
|
+
|
79
|
+
const Slot: React.FC<{
|
80
|
+
name: SlotNames
|
81
|
+
children: React.ReactNode
|
82
|
+
}> = ({name, children}) => {
|
83
|
+
const {registerSlot, unregisterSlot, context} = React.useContext(SlotsContext)
|
84
|
+
|
85
|
+
React.useEffect(() => {
|
86
|
+
registerSlot(name, typeof children === 'function' ? children(context) : children)
|
87
|
+
return () => unregisterSlot(name)
|
88
|
+
}, [name, children, registerSlot, unregisterSlot, context])
|
89
|
+
|
90
|
+
return null
|
91
|
+
}
|
92
|
+
|
93
|
+
return {Slots, Slot}
|
94
|
+
}
|
95
|
+
|
96
|
+
export default createSlots
|
@@ -0,0 +1,10 @@
|
|
1
|
+
// Produces a union of dot-delimited keypaths to the string values in a nested object:
|
2
|
+
export type KeyPaths<O extends Record<string, unknown>> = {
|
3
|
+
[K in keyof O]: K extends string
|
4
|
+
? O[K] extends string
|
5
|
+
? `${K}`
|
6
|
+
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
7
|
+
// @ts-ignore TypeScript has bested me, but the KeyPaths type is tested.
|
8
|
+
`${K}.${KeyPaths<O[K]>}`
|
9
|
+
: never
|
10
|
+
}[keyof O]
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// Inspired from reach-ui: https://github.com/reach/reach-ui/blob/develop/packages/utils/src/use-force-update.ts
|
2
|
+
import React from 'react'
|
3
|
+
|
4
|
+
export const useForceUpdate = () => {
|
5
|
+
const [, rerender] = React.useState({})
|
6
|
+
return React.useCallback(() => rerender({}), [])
|
7
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import {useEffect, useLayoutEffect} from 'react'
|
2
|
+
|
3
|
+
const useIsomorphicLayoutEffect =
|
4
|
+
typeof window !== 'undefined' &&
|
5
|
+
typeof window.document !== 'undefined' &&
|
6
|
+
typeof window.document.createElement !== 'undefined'
|
7
|
+
? useLayoutEffect
|
8
|
+
: useEffect
|
9
|
+
|
10
|
+
export default useIsomorphicLayoutEffect
|