@primer/components 31.0.2-rc.95622264 → 31.2.0-rc.0b631515
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 +17 -1
- package/dist/browser.esm.js +178 -178
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +179 -179
- package/dist/browser.umd.js.map +1 -1
- package/docs/content/FilterList.md +2 -2
- 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/lib/ActionList/Header.js +1 -1
- 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 +4 -4
- 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/__tests__/KeyPaths.types.test.d.ts +11 -0
- package/lib/__tests__/KeyPaths.types.test.js +10 -0
- package/lib/__tests__/TextInputWithTokens.test.js +1 -10
- 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/Token.stories.js +19 -2
- package/lib/sx.d.ts +8 -2
- package/lib/theme.d.ts +78 -0
- package/lib/theme.js +3 -1
- package/lib/utils/types/KeyPaths.d.ts +3 -0
- package/lib/utils/types/KeyPaths.js +1 -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/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 +4 -4
- 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/__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 +1 -10
- 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/Token.stories.js +14 -1
- package/lib-esm/sx.d.ts +8 -2
- package/lib-esm/theme.d.ts +78 -0
- package/lib-esm/theme.js +2 -1
- package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
- package/lib-esm/utils/types/KeyPaths.js +1 -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 +37956 -42
- package/package.json +4 -2
- package/script/build +2 -0
- package/src/ActionList/Header.tsx +1 -1
- package/src/Overlay.tsx +2 -1
- package/src/Portal/Portal.tsx +2 -1
- package/src/__tests__/KeyPaths.types.test.ts +14 -0
- package/src/__tests__/TextInputWithTokens.test.tsx +0 -10
- package/src/hooks/useAnchoredPosition.ts +2 -1
- package/src/hooks/useCombinedRefs.ts +3 -3
- package/src/hooks/useResizeObserver.ts +2 -2
- package/src/stories/Button.stories.tsx +1 -1
- package/src/stories/Token.stories.tsx +12 -1
- package/src/sx.ts +14 -2
- package/src/theme.ts +86 -0
- package/src/utils/types/KeyPaths.ts +10 -0
- package/src/utils/useIsomorphicLayoutEffect.ts +10 -0
- package/stats.html +1 -1
- package/.changeset/tiny-ghosts-repeat.md +0 -5
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@primer/components",
|
3
|
-
"version": "31.0
|
3
|
+
"version": "31.2.0-rc.0b631515",
|
4
4
|
"description": "Primer react components",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"module": "lib-esm/index.js",
|
@@ -15,7 +15,7 @@
|
|
15
15
|
"start": "concurrently npm:start:*",
|
16
16
|
"start:docs": "cd docs && npm run develop",
|
17
17
|
"start:storybook": "start-storybook -p 6006",
|
18
|
-
"lint": "eslint '**/*.{js,ts,tsx,md,mdx}'",
|
18
|
+
"lint": "eslint '**/*.{js,ts,tsx,md,mdx}' --max-warnings=0",
|
19
19
|
"lint:fix": "npm run lint -- --fix",
|
20
20
|
"test": "jest",
|
21
21
|
"test:update": "npm run test -- --updateSnapshot",
|
@@ -132,7 +132,9 @@
|
|
132
132
|
"rollup-plugin-visualizer": "5.5.0",
|
133
133
|
"semver": "7.3.5",
|
134
134
|
"size-limit": "5.0.2",
|
135
|
+
"storybook-addon-performance": "0.16.1",
|
135
136
|
"styled-components": "4.4.1",
|
137
|
+
"ts-toolbelt": "9.6.0",
|
136
138
|
"typescript": "4.2.2"
|
137
139
|
},
|
138
140
|
"peerDependencies": {
|
package/script/build
CHANGED
package/src/Overlay.tsx
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import styled from 'styled-components'
|
2
|
-
import React, {ReactElement, useEffect,
|
2
|
+
import React, {ReactElement, useEffect, useRef} from 'react'
|
3
3
|
import {get, COMMON, SystemPositionProps, SystemCommonProps} from './constants'
|
4
4
|
import {ComponentProps} from './utils/types'
|
5
|
+
import useLayoutEffect from './utils/useIsomorphicLayoutEffect'
|
5
6
|
import {useOverlay, TouchOrMouseEvent} from './hooks'
|
6
7
|
import Portal from './Portal'
|
7
8
|
import sx, {SxProp} from './sx'
|
package/src/Portal/Portal.tsx
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import React from 'react'
|
2
2
|
import {createPortal} from 'react-dom'
|
3
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect'
|
3
4
|
|
4
5
|
const PRIMER_PORTAL_ROOT_ID = '__primerPortalRoot__'
|
5
6
|
const DEFAULT_PORTAL_CONTAINER_NAME = '__default__'
|
@@ -69,7 +70,7 @@ export const Portal: React.FC<PortalProps> = ({children, onMount, containerName:
|
|
69
70
|
hostElement.style.zIndex = '1'
|
70
71
|
const elementRef = React.useRef(hostElement)
|
71
72
|
|
72
|
-
|
73
|
+
useLayoutEffect(() => {
|
73
74
|
let containerName = _containerName
|
74
75
|
if (containerName === undefined) {
|
75
76
|
containerName = DEFAULT_PORTAL_CONTAINER_NAME
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import {Union} from 'ts-toolbelt'
|
2
|
+
import {KeyPaths} from '../utils/types/KeyPaths'
|
3
|
+
|
4
|
+
type NestedObject = {
|
5
|
+
a: string
|
6
|
+
b: {
|
7
|
+
b1: string
|
8
|
+
b2: string
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
export function generatesKeyPathsFromObject(x: Union.Diff<KeyPaths<NestedObject>, 'a' | 'b.b1' | 'b.b2'>): never {
|
13
|
+
return x
|
14
|
+
}
|
@@ -29,16 +29,6 @@ const LabelledTextInputWithTokens: React.FC<TextInputWithTokensProps> = ({onToke
|
|
29
29
|
</>
|
30
30
|
)
|
31
31
|
|
32
|
-
// describe('axe test', () => {
|
33
|
-
// it('should have no axe violations', async () => {
|
34
|
-
// const onRemoveMock = jest.fn()
|
35
|
-
// const {container} = HTMLRender(<LabelledTextInputWithTokens tokens={mockTokens} onTokenRemove={onRemoveMock} />)
|
36
|
-
// const results = await axe(container)
|
37
|
-
// expect(results).toHaveNoViolations()
|
38
|
-
// cleanup()
|
39
|
-
// })
|
40
|
-
// })
|
41
|
-
|
42
32
|
jest.useFakeTimers()
|
43
33
|
|
44
34
|
describe('TextInputWithTokens', () => {
|
@@ -2,6 +2,7 @@ import React from 'react'
|
|
2
2
|
import {PositionSettings, getAnchoredPosition, AnchorPosition} from '../behaviors/anchoredPosition'
|
3
3
|
import {useProvidedRefOrCreate} from './useProvidedRefOrCreate'
|
4
4
|
import {useResizeObserver} from './useResizeObserver'
|
5
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect'
|
5
6
|
|
6
7
|
export interface AnchoredPositionHookSettings extends Partial<PositionSettings> {
|
7
8
|
floatingElementRef?: React.RefObject<Element>
|
@@ -41,7 +42,7 @@ export function useAnchoredPosition(
|
|
41
42
|
[floatingElementRef, anchorElementRef, ...dependencies]
|
42
43
|
)
|
43
44
|
|
44
|
-
|
45
|
+
useLayoutEffect(updatePosition, [updatePosition])
|
45
46
|
|
46
47
|
useResizeObserver(updatePosition)
|
47
48
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import {ForwardedRef, useRef} from 'react'
|
2
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect'
|
2
3
|
|
3
4
|
/**
|
4
5
|
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
@@ -11,7 +12,7 @@ import React, {ForwardedRef, useRef} from 'react'
|
|
11
12
|
export function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]) {
|
12
13
|
const combinedRef = useRef<T | null>(null)
|
13
14
|
|
14
|
-
|
15
|
+
useLayoutEffect(() => {
|
15
16
|
function setRefs(current: T | null = null) {
|
16
17
|
for (const ref of refs) {
|
17
18
|
if (!ref) {
|
@@ -32,7 +33,6 @@ export function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)
|
|
32
33
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
33
34
|
setRefs(combinedRef.current)
|
34
35
|
}
|
35
|
-
|
36
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
37
37
|
}, [...refs, combinedRef.current])
|
38
38
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect'
|
2
2
|
|
3
3
|
export function useResizeObserver(callback: () => void) {
|
4
|
-
|
4
|
+
useLayoutEffect(() => {
|
5
5
|
const observer = new window.ResizeObserver(() => callback())
|
6
6
|
observer.observe(document.documentElement)
|
7
7
|
return () => {
|
@@ -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
|
}
|
@@ -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,7 +1,19 @@
|
|
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
|
+
|
5
|
+
export type BetterCssProperties = {
|
6
|
+
[K in keyof SystemCssProperties]: K extends keyof ColorProps
|
7
|
+
? ThemeColorPaths | SystemCssProperties[K]
|
8
|
+
: K extends keyof ShadowProps
|
9
|
+
? ThemeShadowPaths | SystemCssProperties[K]
|
10
|
+
: SystemCssProperties[K]
|
11
|
+
}
|
12
|
+
|
13
|
+
export type BetterSystemStyleObject = BetterCssProperties | SystemStyleObject
|
2
14
|
|
3
15
|
export interface SxProp {
|
4
|
-
sx?:
|
16
|
+
sx?: BetterSystemStyleObject
|
5
17
|
}
|
6
18
|
|
7
19
|
const sx = (props: SxProp) => css(props.sx)
|
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,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,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
|