@sanity/ui 1.0.0-next.3 → 1.0.0

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.
Files changed (144) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -2
  3. package/dist/{types/src/index.d.ts → index.d.ts} +4450 -4398
  4. package/dist/{sanity-ui.esm.js → index.esm.js} +888 -2678
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/{sanity-ui.js → index.js} +882 -2688
  7. package/dist/index.js.map +1 -0
  8. package/package.json +112 -23
  9. package/src/components/autocomplete/__workshop__/example.tsx +1 -1
  10. package/src/components/autocomplete/__workshop__/index.ts +36 -32
  11. package/src/components/autocomplete/autocomplete.styles.tsx +22 -28
  12. package/src/components/autocomplete/autocomplete.tsx +1 -2
  13. package/src/components/autocomplete/constants.ts +3 -8
  14. package/src/components/breadcrumbs/__workshop__/index.ts +11 -7
  15. package/src/components/breadcrumbs/breadcrumbs.styles.ts +13 -18
  16. package/src/components/dialog/__workshop__/index.ts +13 -9
  17. package/src/components/dialog/dialog.tsx +53 -67
  18. package/src/components/hotkeys/__workshop__/index.ts +11 -3
  19. package/src/components/hotkeys/hotkeys.tsx +12 -16
  20. package/src/components/menu/__workshop__/index.ts +71 -67
  21. package/src/components/menu/menu.tsx +5 -7
  22. package/src/components/menu/menuButton.tsx +16 -14
  23. package/src/components/menu/menuDivider.ts +8 -10
  24. package/src/components/skeleton/__workshop__/index.ts +8 -4
  25. package/src/components/skeleton/skeleton.tsx +4 -6
  26. package/src/components/skeleton/styles.ts +13 -9
  27. package/src/components/skeleton/textSkeleton.tsx +12 -14
  28. package/src/components/tab/__workshop__/index.ts +11 -3
  29. package/src/components/toast/__workshop__/index.ts +16 -4
  30. package/src/components/toast/toast.tsx +6 -11
  31. package/src/components/toast/toastProvider.tsx +18 -22
  32. package/src/components/tree/__workshop__/basic.perf.ts +1 -14
  33. package/src/components/tree/__workshop__/basic.tsx +1 -1
  34. package/src/components/tree/__workshop__/index.ts +12 -8
  35. package/src/components/tree/style.ts +78 -76
  36. package/src/components/tree/treeItem.tsx +7 -12
  37. package/src/hooks/useElementRect/__workshop__/index.ts +11 -3
  38. package/src/hooks/useMediaIndex/__workshop__/index.ts +11 -3
  39. package/src/primitives/_selectable/selectable.tsx +4 -7
  40. package/src/primitives/_selectable/style.ts +85 -82
  41. package/src/primitives/avatar/__workshop__/index.ts +16 -12
  42. package/src/primitives/avatar/avatar.tsx +9 -12
  43. package/src/primitives/avatar/avatarCounter.tsx +22 -24
  44. package/src/primitives/avatar/avatarStack.tsx +16 -14
  45. package/src/primitives/avatar/styles.ts +1 -1
  46. package/src/primitives/badge/__workshop__/index.ts +16 -12
  47. package/src/primitives/badge/__workshop__/tones.tsx +1 -1
  48. package/src/primitives/badge/badge.tsx +6 -5
  49. package/src/primitives/box/__workshop__/index.ts +16 -4
  50. package/src/primitives/box/box.tsx +21 -49
  51. package/src/primitives/button/__workshop__/index.ts +51 -47
  52. package/src/primitives/button/__workshop__/sanityUploadButton.tsx +19 -20
  53. package/src/primitives/button/__workshop__/styled1.tsx +6 -6
  54. package/src/primitives/button/button.tsx +20 -26
  55. package/src/primitives/button/styles.ts +30 -29
  56. package/src/primitives/card/__workshop__/index.ts +15 -11
  57. package/src/primitives/card/card.tsx +9 -25
  58. package/src/primitives/card/styles.ts +119 -114
  59. package/src/primitives/checkbox/__workshop__/index.ts +10 -6
  60. package/src/primitives/checkbox/checkbox.tsx +4 -4
  61. package/src/primitives/checkbox/styles.ts +71 -69
  62. package/src/primitives/code/__workshop__/index.ts +16 -12
  63. package/src/primitives/code/code.tsx +3 -5
  64. package/src/primitives/code/styles.ts +20 -18
  65. package/src/primitives/container/__workshop__/index.ts +5 -3
  66. package/src/primitives/container/container.tsx +5 -4
  67. package/src/primitives/flex/__workshop__/index.ts +8 -4
  68. package/src/primitives/flex/flex.tsx +7 -23
  69. package/src/primitives/grid/__workshop__/index.ts +7 -3
  70. package/src/primitives/grid/grid.tsx +4 -27
  71. package/src/primitives/heading/__workshop__/index.ts +16 -12
  72. package/src/primitives/heading/heading.tsx +10 -17
  73. package/src/primitives/heading/styles.ts +45 -36
  74. package/src/primitives/inline/__workshop__/index.ts +5 -3
  75. package/src/primitives/inline/inline.tsx +3 -5
  76. package/src/primitives/kbd/__workshop__/index.ts +5 -3
  77. package/src/primitives/kbd/kbd.tsx +12 -13
  78. package/src/primitives/label/__workshop__/index.ts +16 -12
  79. package/src/primitives/label/label.tsx +13 -18
  80. package/src/primitives/label/styles.ts +24 -18
  81. package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -1
  82. package/src/primitives/popover/__workshop__/TestStory.tsx +0 -1
  83. package/src/primitives/popover/__workshop__/index.ts +36 -32
  84. package/src/primitives/popover/constants.ts +0 -3
  85. package/src/primitives/popover/floating-ui/size.ts +40 -25
  86. package/src/primitives/popover/popover.tsx +220 -196
  87. package/src/primitives/popover/popoverArrow.tsx +42 -48
  88. package/src/primitives/popover/popoverCard.tsx +12 -22
  89. package/src/primitives/radio/__workshop__/index.ts +8 -4
  90. package/src/primitives/radio/radio.tsx +3 -3
  91. package/src/primitives/radio/styles.ts +73 -73
  92. package/src/primitives/select/__workshop__/index.ts +8 -4
  93. package/src/primitives/select/select.tsx +9 -11
  94. package/src/primitives/select/styles.ts +77 -77
  95. package/src/primitives/spinner/__workshop__/index.ts +11 -7
  96. package/src/primitives/spinner/spinner.tsx +2 -5
  97. package/src/primitives/stack/__workshop__/index.ts +11 -7
  98. package/src/primitives/stack/stack.tsx +3 -5
  99. package/src/primitives/switch/__workshop__/index.ts +8 -4
  100. package/src/primitives/switch/styles.ts +119 -112
  101. package/src/primitives/switch/switch.tsx +6 -6
  102. package/src/primitives/text/__workshop__/index.ts +21 -17
  103. package/src/primitives/text/styles.ts +51 -45
  104. package/src/primitives/text/text.tsx +11 -16
  105. package/src/primitives/textArea/__workshop__/index.ts +11 -7
  106. package/src/primitives/textArea/textArea.tsx +15 -22
  107. package/src/primitives/textInput/__workshop__/index.ts +46 -42
  108. package/src/primitives/textInput/__workshop__/plain.tsx +2 -1
  109. package/src/primitives/textInput/textInput.tsx +49 -69
  110. package/src/primitives/tooltip/__workshop__/index.ts +11 -7
  111. package/src/primitives/tooltip/tooltip.tsx +3 -6
  112. package/src/primitives/tooltip/tooltipArrow.tsx +69 -59
  113. package/src/styles/border/borderStyle.ts +10 -18
  114. package/src/styles/box/boxStyle.ts +14 -18
  115. package/src/styles/flex/flexItemStyle.ts +7 -1
  116. package/src/styles/flex/flexStyle.ts +14 -9
  117. package/src/styles/grid/gridItemStyle.ts +18 -30
  118. package/src/styles/grid/gridStyle.ts +25 -33
  119. package/src/styles/helpers.ts +2 -2
  120. package/src/styles/index.ts +0 -1
  121. package/src/styles/input/textInputStyle.ts +127 -123
  122. package/src/styles/margin/marginStyle.ts +11 -10
  123. package/src/styles/margin/marginsStyle.test.ts +12 -10
  124. package/src/styles/padding/paddingStyle.test.ts +12 -10
  125. package/src/styles/padding/paddingStyle.ts +9 -10
  126. package/src/theme/__workshop__/index.ts +26 -22
  127. package/src/theme/{ThemeContext.ts → themeContext.ts} +0 -0
  128. package/src/utils/boundaryElement/__workshop__/index.ts +11 -7
  129. package/src/utils/elementQuery/__workshop__/index.ts +11 -7
  130. package/src/utils/layer/__workshop__/index.ts +21 -17
  131. package/src/utils/layer/layer.tsx +4 -6
  132. package/src/utils/portal/__workshop__/index.ts +11 -7
  133. package/src/utils/srOnly/srOnly.tsx +8 -10
  134. package/src/utils/virtualList/__workshop__/index.ts +26 -22
  135. package/src/utils/virtualList/virtualList.tsx +10 -14
  136. package/dist/sanity-ui.esm.js.map +0 -1
  137. package/dist/sanity-ui.js.map +0 -1
  138. package/src/__workshop__/color/overview.tsx +0 -101
  139. package/src/__workshop__/index.ts +0 -10
  140. package/src/icons/__workshop__/.eslintrc +0 -5
  141. package/src/icons/__workshop__/index.tsx +0 -6
  142. package/src/icons/__workshop__/overview.tsx +0 -76
  143. package/src/styles/compose.ts +0 -35
  144. package/src/utils/srOnly/__workshop__/.eslintrc +0 -5
@@ -1,101 +0,0 @@
1
- import {black, ColorTints, ColorValue, COLOR_HUES, hues, white} from '@sanity/color'
2
- import {Box, Card, Code, Flex, Grid, Heading, Stack, useToast} from '@sanity/ui'
3
- import {useCallback} from 'react'
4
- import {hexToRgb, rgbToHsl} from '../../theme'
5
-
6
- function ucfirst(str: string) {
7
- return str.slice(0, 1).toUpperCase() + str.slice(1)
8
- }
9
-
10
- const clipboard = {
11
- write(text: string) {
12
- const type = 'text/plain'
13
- const blob = new Blob([text], {type})
14
- const data = [new ClipboardItem({[type]: blob as any})]
15
-
16
- return navigator.clipboard.write(data)
17
- },
18
- }
19
-
20
- export default function ColorOverviewStory(): React.ReactElement {
21
- return (
22
- <Grid columns={[1, 1, 2, 3]} gapX={[4, 4, 5]} gapY={[5, 5, 6]} padding={[4, 5, 6]}>
23
- {COLOR_HUES.map((hueKey) => (
24
- <ColorHuePreview tints={hues[hueKey]} hueKey={hueKey} key={hueKey} />
25
- ))}
26
- </Grid>
27
- )
28
- }
29
-
30
- function ColorHuePreview(props: {hueKey: string; tints: ColorTints}) {
31
- const {hueKey, tints} = props
32
-
33
- return (
34
- <Box>
35
- <Heading as="h2" size={1}>
36
- {ucfirst(hueKey)}
37
- </Heading>
38
-
39
- <Stack marginTop={[3, 3, 4]} space={1}>
40
- {Object.entries(tints).map(([tintKey, tint]) => {
41
- return <ColorTintPreview key={tintKey} tint={tint} />
42
- })}
43
- </Stack>
44
- </Box>
45
- )
46
- }
47
-
48
- function ColorTintPreview(props: {tint: ColorValue}) {
49
- const {tint} = props
50
- const hsl = rgbToHsl(hexToRgb(tint.hex))
51
- const {push: pushToast} = useToast()
52
-
53
- const handleClick = useCallback(() => {
54
- clipboard
55
- .write(tint.hex)
56
- .then(() => {
57
- pushToast({
58
- title: (
59
- <>
60
- Copied {tint.title} (<code>{tint.hex}</code>) to clipboard!
61
- </>
62
- ),
63
- })
64
- })
65
- .catch((err) => {
66
- // eslint-disable-next-line no-console
67
- console.log(err)
68
- pushToast({
69
- status: 'error',
70
- title: <>Copied not write to clipboard!</>,
71
- })
72
- })
73
- }, [pushToast, tint])
74
-
75
- return (
76
- <Card
77
- __unstable_focusRing
78
- as="button"
79
- onClick={handleClick}
80
- radius={2}
81
- style={{
82
- ['--card-bg-color' as any]: tint.hex,
83
- ['--card-fg-color' as any]: hsl.l < 50 ? white.hex : black.hex,
84
- cursor: 'pointer',
85
- }}
86
- >
87
- <Flex padding={3}>
88
- <Box flex={1}>
89
- <Code size={1} style={{color: 'inherit'}}>
90
- {tint.title}
91
- </Code>
92
- </Box>
93
- <Box>
94
- <Code size={1} style={{color: 'inherit'}}>
95
- {tint.hex}
96
- </Code>
97
- </Box>
98
- </Flex>
99
- </Card>
100
- )
101
- }
@@ -1,10 +0,0 @@
1
- import {defineScope} from '@sanity/ui-workshop'
2
- import {lazy} from 'react'
3
-
4
- export default defineScope('color', 'Color', [
5
- {
6
- name: 'overview',
7
- title: 'Overview',
8
- component: lazy(() => import('./color/overview')),
9
- },
10
- ])
@@ -1,5 +0,0 @@
1
- {
2
- "rules": {
3
- "@typescript-eslint/explicit-module-boundary-types": "off"
4
- }
5
- }
@@ -1,6 +0,0 @@
1
- import {defineScope} from '@sanity/ui-workshop'
2
- import {lazy} from 'react'
3
-
4
- export default defineScope('icons', 'Icons', [
5
- {name: 'overview', title: 'Overview', component: lazy(() => import('./overview'))},
6
- ])
@@ -1,76 +0,0 @@
1
- import {Icon, icons, IconSymbol, SearchIcon} from '@sanity/icons'
2
- import {Box, Card, Code, Container, Flex, Heading, Stack, Text, TextInput} from '@sanity/ui'
3
- import {useCallback, useMemo, useState} from 'react'
4
- import {packages} from '$packages'
5
-
6
- function ucfirst(str: string) {
7
- return str.slice(0, 1).toUpperCase() + str.slice(1)
8
- }
9
-
10
- function toPascalCase(str: string) {
11
- const p = str.split('-')
12
-
13
- return p.map(ucfirst).join('')
14
- }
15
-
16
- export default function OverviewStory() {
17
- const [query, setQuery] = useState('')
18
-
19
- const iconKeys = useMemo(() => {
20
- return Object.keys(icons).filter((iconKey) => {
21
- return query === '' ? true : iconKey.includes(query.toLowerCase())
22
- })
23
- }, [query])
24
-
25
- const handleQueryChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
26
- setQuery(event.currentTarget.value)
27
- }, [])
28
-
29
- return (
30
- <Card padding={[4, 5, 6]}>
31
- <Container width={1}>
32
- <Stack space={4}>
33
- <Heading as="h1">@sanity/icons v{packages.icons?.version}</Heading>
34
- <Text as="p" muted>
35
- {packages.icons?.description}
36
- </Text>
37
- <Card border padding={3} radius={2}>
38
- <Code language="bash">{`npm install @sanity/icons\n\n# Install peer dependencies\nnpm install react`}</Code>
39
- </Card>
40
- </Stack>
41
-
42
- <Box marginTop={[3, 4, 5]} marginBottom={3}>
43
- <TextInput
44
- icon={SearchIcon}
45
- onChange={handleQueryChange}
46
- placeholder="Filter by name…"
47
- radius={2}
48
- value={query}
49
- />
50
- </Box>
51
-
52
- {iconKeys.length === 0 && <Text>No matches</Text>}
53
-
54
- {iconKeys.length > 0 && (
55
- <Stack space={3}>
56
- {iconKeys.map((iconKey) => (
57
- <Card border key={iconKey} overflow="hidden" radius={2}>
58
- <Flex align="center" gap={4} padding={4}>
59
- <Heading>
60
- <Icon symbol={iconKey as IconSymbol} />
61
- </Heading>
62
- <Text>{iconKey}</Text>
63
- </Flex>
64
- <Card overflow="auto" padding={4} tone="transparent">
65
- <Code language="typescript">{`import {${toPascalCase(
66
- iconKey
67
- )}Icon} from '@sanity/icons'`}</Code>
68
- </Card>
69
- </Card>
70
- ))}
71
- </Stack>
72
- )}
73
- </Container>
74
- </Card>
75
- )
76
- }
@@ -1,35 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-types */
2
-
3
- import {ComponentType} from 'react'
4
- import styled, {CSSObject, DefaultTheme, StyledComponent} from 'styled-components'
5
- import {ThemeProps} from './types'
6
-
7
- /** @internal */
8
- export interface CSSObjectFactory<P extends {} = {}> {
9
- (props: P & ThemeProps): CSSObject | CSSObject[]
10
- }
11
-
12
- const EMPTY_CSS: CSSObject = {}
13
-
14
- /** @internal */
15
- export function compose<
16
- // style props
17
- P extends {} = {},
18
- // type
19
- C extends keyof JSX.IntrinsicElements | ComponentType<any> = any
20
- >(
21
- type: C,
22
- styles: Array<CSSObjectFactory<P & ThemeProps> | CSSObject>
23
- ): StyledComponent<C, DefaultTheme, P> {
24
- if (styles.length === 0) {
25
- return styled(type)<P>(EMPTY_CSS)
26
- }
27
-
28
- let comp = type
29
-
30
- for (const style of styles) {
31
- comp = styled(comp)<P>(style) as any
32
- }
33
-
34
- return comp as any
35
- }
@@ -1,5 +0,0 @@
1
- {
2
- "rules": {
3
- "@typescript-eslint/explicit-module-boundary-types": "off"
4
- }
5
- }