@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,105 +1,107 @@
1
- import {CSSObject} from 'styled-components'
1
+ import {css, FlattenSimpleInterpolation} from 'styled-components'
2
2
  import {rem, ThemeProps} from '../../styles'
3
3
  import {_colorVarsStyle} from '../../styles/colorVars'
4
4
 
5
- export function treeItemRootStyle(): CSSObject {
6
- return {
7
- '&[role="none"] > [role="treeitem"]': {
8
- outline: 'none',
9
- cursor: 'default',
10
- borderRadius: '3px',
11
-
12
- '&:focus': {
13
- position: 'relative',
14
- },
15
- },
16
-
17
- '&[role="treeitem"]': {
18
- outline: 'none',
19
-
20
- '& > div': {
21
- cursor: 'default',
22
- borderRadius: '3px',
23
- },
24
-
25
- '&:focus > div': {
26
- position: 'relative',
27
- },
28
- },
29
- }
5
+ export function treeItemRootStyle(): FlattenSimpleInterpolation {
6
+ return css`
7
+ &[role='none'] > [role='treeitem'] {
8
+ outline: none;
9
+ cursor: default;
10
+ border-radius: 3px;
11
+
12
+ &:focus {
13
+ position: relative;
14
+ }
15
+ }
16
+
17
+ &[role='treeitem'] {
18
+ outline: none;
19
+
20
+ & > div {
21
+ cursor: default;
22
+ border-radius: 3px;
23
+ }
24
+
25
+ &:focus > div {
26
+ position: relative;
27
+ }
28
+ }
29
+ `
30
30
  }
31
31
 
32
- export function treeItemRootColorStyle(props: ThemeProps): CSSObject {
32
+ export function treeItemRootColorStyle(props: ThemeProps): FlattenSimpleInterpolation {
33
33
  const {theme} = props
34
34
  const $tone = 'default'
35
35
  const {base, muted, selectable} = theme.sanity.color
36
36
  // @todo: remove use of `muted` here
37
37
  const tone = selectable ? selectable[$tone] || selectable.default : muted[$tone] || muted.default
38
38
 
39
- return {
39
+ return css`
40
40
  /* <div role="none"><a data-ui="TreeItem__box" role="treeitem" tabIndex="0"></div> */
41
- '&[role="none"]': {
42
- '& > [role="treeitem"]': {
43
- ..._colorVarsStyle(base, tone.enabled),
41
+ &[role='none'] {
42
+ & > [role='treeitem'] {
43
+ ${_colorVarsStyle(base, tone.enabled)}
44
44
 
45
- backgroundColor: 'var(--card-bg-color)',
46
- color: 'var(--treeitem-fg-color)',
47
- },
45
+ background-color: var(--card-bg-color);
46
+ color: var(--treeitem-fg-color);
47
+ }
48
48
 
49
- '&[data-selected] > [role="treeitem"]': {
50
- ..._colorVarsStyle(base, tone.pressed),
51
- },
49
+ &[data-selected] > [role='treeitem'] {
50
+ ${_colorVarsStyle(base, tone.pressed)}
51
+ }
52
52
 
53
- '@media (hover: hover)': {
54
- '&:not([data-selected]) > [role="treeitem"]:not(:focus):hover': {
55
- ..._colorVarsStyle(base, tone.hovered),
56
- },
53
+ @media (hover: hover) {
54
+ &:not([data-selected]) > [role='treeitem']:not(:focus):hover {
55
+ ${_colorVarsStyle(base, tone.hovered)}
56
+ }
57
57
 
58
- '& > [role="treeitem"]:focus': {
59
- ..._colorVarsStyle(base, tone.selected),
60
- },
61
- },
62
- },
58
+ & > [role='treeitem']:focus {
59
+ ${_colorVarsStyle(base, tone.selected)}
60
+ }
61
+ }
62
+ }
63
63
 
64
64
  /* <div role="treeitem" tabIndex="0"><div data-ui="TreeItem__box"></div> */
65
- '&[role="treeitem"]': {
66
- '& > [data-ui="TreeItem__box"]': {
67
- ..._colorVarsStyle(base, tone.enabled),
68
-
69
- backgroundColor: 'var(--card-bg-color)',
70
- color: 'var(--card-fg-color)',
71
- },
72
-
73
- '&[data-selected] > [data-ui="TreeItem__box"]': {
74
- ..._colorVarsStyle(base, tone.pressed),
75
- },
76
-
77
- '@media (hover: hover)': {
78
- '&:not([data-selected]):not(:focus) > [data-ui="TreeItem__box"]:hover': {
79
- ..._colorVarsStyle(base, tone.hovered),
80
- },
81
-
82
- '&:focus > [data-ui="TreeItem__box"]': {
83
- ..._colorVarsStyle(base, tone.selected),
84
- },
85
- },
86
- },
87
- }
65
+ &[role='treeitem'] {
66
+ & > [data-ui='TreeItem__box'] {
67
+ ${_colorVarsStyle(base, tone.enabled)}
68
+
69
+ background-color: var(--card-bg-color);
70
+ color: var(--card-fg-color);
71
+ }
72
+
73
+ &[data-selected] > [data-ui='TreeItem__box'] {
74
+ ${_colorVarsStyle(base, tone.pressed)}
75
+ }
76
+
77
+ @media (hover: hover) {
78
+ &:not([data-selected]):not(:focus) > [data-ui='TreeItem__box']:hover {
79
+ ${_colorVarsStyle(base, tone.hovered)}
80
+ }
81
+
82
+ &:focus > [data-ui='TreeItem__box'] {
83
+ ${_colorVarsStyle(base, tone.selected)}
84
+ }
85
+ }
86
+ }
87
+ `
88
88
  }
89
89
 
90
90
  export interface TreeItemBoxStyleProps {
91
91
  $level: number
92
92
  }
93
93
 
94
- export function treeItemBoxStyle(props: TreeItemBoxStyleProps & ThemeProps): CSSObject {
94
+ export function treeItemBoxStyle(
95
+ props: TreeItemBoxStyleProps & ThemeProps
96
+ ): FlattenSimpleInterpolation {
95
97
  const {$level, theme} = props
96
98
  const {space} = theme.sanity
97
99
 
98
- return {
99
- paddingLeft: rem(space[2] * $level),
100
+ return css`
101
+ padding-left: ${rem(space[2] * $level)};
100
102
 
101
- '&[data-as="a"]': {
102
- textDecoration: 'none',
103
- },
104
- }
103
+ &[data-as='a'] {
104
+ text-decoration: none;
105
+ }
106
+ `
105
107
  }
@@ -2,7 +2,6 @@ import {ToggleArrowRightIcon} from '@sanity/icons'
2
2
  import {createElement, memo, useCallback, useEffect, useId, useMemo, useRef} from 'react'
3
3
  import styled from 'styled-components'
4
4
  import {Box, Flex, Text} from '../../primitives'
5
- import {compose} from '../../styles'
6
5
  import {ThemeFontWeightKey} from '../../theme'
7
6
  import {
8
7
  treeItemRootStyle,
@@ -27,19 +26,15 @@ export interface TreeItemProps {
27
26
  weight?: ThemeFontWeightKey
28
27
  }
29
28
 
30
- const Root = memo(compose('li', [treeItemRootStyle, treeItemRootColorStyle]))
29
+ const Root = memo(styled.li(treeItemRootStyle, treeItemRootColorStyle))
31
30
 
32
- const TreeItemBox = memo(
33
- styled(Box)['attrs']({forwardedAs: 'a'})<TreeItemBoxStyleProps>(treeItemBoxStyle)
34
- )
31
+ const TreeItemBox = styled(Box).attrs({forwardedAs: 'a'})<TreeItemBoxStyleProps>(treeItemBoxStyle)
35
32
 
36
- const ToggleArrowText = memo(
37
- styled(Text)({
38
- '& > svg': {
39
- transition: 'transform 100ms',
40
- },
41
- })
42
- )
33
+ const ToggleArrowText = styled(Text)`
34
+ & > svg {
35
+ transition: transform 100ms;
36
+ }
37
+ `
43
38
 
44
39
  /**
45
40
  * This API might change. DO NOT USE IN PRODUCTION.
@@ -1,6 +1,14 @@
1
1
  import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
- export default defineScope('hooks/useElementRect', 'useElementRect', [
5
- {name: 'example', title: 'Example', component: lazy(() => import('./example'))},
6
- ])
4
+ export default defineScope({
5
+ name: 'hooks/useElementRect',
6
+ title: 'useElementRect',
7
+ stories: [
8
+ {
9
+ name: 'example',
10
+ title: 'Example',
11
+ component: lazy(() => import('./example')),
12
+ },
13
+ ],
14
+ })
@@ -1,6 +1,14 @@
1
1
  import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
- export default defineScope('hooks/use-media-index', 'useMediaIndex', [
5
- {name: 'test', title: 'Test', component: lazy(() => import('./test'))},
6
- ])
4
+ export default defineScope({
5
+ name: 'hooks/use-media-index',
6
+ title: 'useMediaIndex',
7
+ stories: [
8
+ {
9
+ name: 'test',
10
+ title: 'Test',
11
+ component: lazy(() => import('./test')),
12
+ },
13
+ ],
14
+ })
@@ -1,4 +1,3 @@
1
- import {memo} from 'react'
2
1
  import styled from 'styled-components'
3
2
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/radius'
4
3
  import {Box} from '../box'
@@ -7,10 +6,8 @@ import {selectableBaseStyle, selectableColorStyle, SelectableStyleProps} from '.
7
6
  /**
8
7
  * @internal
9
8
  */
10
- export const Selectable = memo(
11
- styled(Box)<SelectableStyleProps & ResponsiveRadiusStyleProps>(
12
- responsiveRadiusStyle,
13
- selectableBaseStyle,
14
- selectableColorStyle
15
- )
9
+ export const Selectable = styled(Box)<SelectableStyleProps & ResponsiveRadiusStyleProps>(
10
+ responsiveRadiusStyle,
11
+ selectableBaseStyle,
12
+ selectableColorStyle
16
13
  )
@@ -1,4 +1,4 @@
1
- import {CSSObject} from 'styled-components'
1
+ import {css, FlattenSimpleInterpolation} from 'styled-components'
2
2
  import {ThemeProps} from '../../styles'
3
3
  import {_colorVarsStyle} from '../../styles/colorVars'
4
4
  import {SelectableTone} from '../../types/selectable'
@@ -10,99 +10,102 @@ export interface SelectableStyleProps {
10
10
  $tone: SelectableTone
11
11
  }
12
12
 
13
- export function selectableBaseStyle(): CSSObject {
14
- return {
15
- backgroundColor: 'inherit',
16
- color: 'inherit',
17
-
18
- '&[data-as="button"]': {
19
- WebkitFontSmoothing: 'inherit',
20
- appearance: 'none',
21
- outline: 'none',
22
- font: 'inherit',
23
- textAlign: 'inherit',
24
- border: 0,
25
- width: 'stretch',
26
- },
13
+ export function selectableBaseStyle(): FlattenSimpleInterpolation {
14
+ return css`
15
+ background-color: inherit;
16
+ color: inherit;
17
+
18
+ &[data-as='button'] {
19
+ -webkit-font-smoothing: inherit;
20
+ appearance: none;
21
+ outline: none;
22
+ font: inherit;
23
+ text-align: inherit;
24
+ border: 0;
25
+ width: stretch;
26
+ }
27
27
 
28
28
  /* &:is(a) */
29
- '&[data-as="a"]': {
30
- textDecoration: 'none',
31
- },
32
- }
29
+ &[data-as='a'] {
30
+ text-decoration: none;
31
+ }
32
+ `
33
33
  }
34
34
 
35
- export function selectableColorStyle(props: SelectableStyleProps & ThemeProps): CSSObject {
35
+ export function selectableColorStyle(
36
+ props: SelectableStyleProps & ThemeProps
37
+ ): FlattenSimpleInterpolation {
36
38
  const {$tone, theme} = props
37
39
  const {base, muted, selectable} = theme.sanity.color
38
40
  // @todo: remove use of `muted` here
39
41
  const tone = selectable ? selectable[$tone] || selectable.default : muted[$tone] || muted.default
40
42
 
41
- return {
42
- ..._colorVarsStyle(base, tone.enabled),
43
+ return css`
44
+ ${_colorVarsStyle(base, tone.enabled)}
43
45
 
44
- backgroundColor: 'var(--card-bg-color)',
45
- color: 'var(--card-fg-color)',
46
- outline: 'none',
46
+ background-color: var(--card-bg-color);
47
+ color: var(--card-fg-color);
48
+ outline: none;
47
49
 
48
50
  /* &:is(button) */
49
- '&[data-as="button"]': {
50
- '&:disabled': {
51
- ..._colorVarsStyle(base, tone.disabled),
52
- },
53
-
54
- '&:not(:disabled)': {
55
- '&[aria-pressed="true"]': {
56
- ..._colorVarsStyle(base, tone.pressed),
57
- },
58
-
59
- '&[data-selected], &[aria-selected="true"] > &': {
60
- ..._colorVarsStyle(base, tone.selected),
61
- },
62
-
63
- '@media (hover: hover)': {
64
- '&:not([data-selected])': {
65
- '&:hover': {
66
- ..._colorVarsStyle(base, tone.hovered),
67
- },
68
-
69
- '&:active': {
70
- ..._colorVarsStyle(base, tone.pressed),
71
- },
72
- },
73
- },
74
- },
75
- },
51
+ &[data-as='button'] {
52
+ &:disabled {
53
+ ${_colorVarsStyle(base, tone.disabled)}
54
+ }
55
+
56
+ &:not(:disabled) {
57
+ &[aria-pressed='true'] {
58
+ ${_colorVarsStyle(base, tone.pressed)}
59
+ }
60
+
61
+ &[data-selected],
62
+ &[aria-selected='true'] > & {
63
+ ${_colorVarsStyle(base, tone.selected)}
64
+ }
65
+
66
+ @media (hover: hover) {
67
+ &:not([data-selected]) {
68
+ &:hover {
69
+ ${_colorVarsStyle(base, tone.hovered)}
70
+ }
71
+
72
+ &:active {
73
+ ${_colorVarsStyle(base, tone.pressed)}
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
76
79
 
77
80
  /* &:is(a) */
78
- '&[data-as="a"]': {
79
- '&[data-disabled]': {
80
- ..._colorVarsStyle(base, tone.disabled),
81
- },
82
-
83
- '&:not([data-disabled])': {
84
- '&[data-pressed]': {
85
- ..._colorVarsStyle(base, tone.pressed),
86
- },
87
-
88
- '&[data-selected]': {
89
- ..._colorVarsStyle(base, tone.selected),
90
- },
91
-
92
- '@media (hover: hover)': {
93
- '&:not([data-selected])': {
94
- '&:hover': {
95
- ..._colorVarsStyle(base, tone.hovered),
96
- },
97
-
98
- '&:active': {
99
- ..._colorVarsStyle(base, tone.pressed),
100
- },
101
- },
102
- },
103
- },
104
- },
105
-
106
- ...theme.sanity.styles?.card?.root,
107
- }
81
+ &[data-as='a'] {
82
+ &[data-disabled] {
83
+ ${_colorVarsStyle(base, tone.disabled)}
84
+ }
85
+
86
+ &:not([data-disabled]) {
87
+ &[data-pressed] {
88
+ ${_colorVarsStyle(base, tone.pressed)}
89
+ }
90
+
91
+ &[data-selected] {
92
+ ${_colorVarsStyle(base, tone.selected)}
93
+ }
94
+
95
+ @media (hover: hover) {
96
+ &:not([data-selected]) {
97
+ &:hover {
98
+ ${_colorVarsStyle(base, tone.hovered)}
99
+ }
100
+
101
+ &:active {
102
+ ${_colorVarsStyle(base, tone.pressed)}
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ ${theme.sanity.styles?.card?.root}
110
+ `
108
111
  }
@@ -1,15 +1,19 @@
1
1
  import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
- export default defineScope('primitives/avatar', 'Avatar', [
5
- {
6
- name: 'as-button',
7
- title: 'As button',
8
- component: lazy(() => import('./asButton')),
9
- },
10
- {
11
- name: 'avatar-stack',
12
- title: 'Avatar stack',
13
- component: lazy(() => import('./stack')),
14
- },
15
- ])
4
+ export default defineScope({
5
+ name: 'primitives/avatar',
6
+ title: 'Avatar',
7
+ stories: [
8
+ {
9
+ name: 'as-button',
10
+ title: 'As button',
11
+ component: lazy(() => import('./asButton')),
12
+ },
13
+ {
14
+ name: 'avatar-stack',
15
+ title: 'Avatar stack',
16
+ component: lazy(() => import('./stack')),
17
+ },
18
+ ],
19
+ })
@@ -1,12 +1,11 @@
1
- import {forwardRef, memo, useCallback, useEffect, useId, useMemo, useState} from 'react'
1
+ import {forwardRef, useCallback, useEffect, useId, useMemo, useState} from 'react'
2
2
  import ReactIs from 'react-is'
3
+ import styled from 'styled-components'
3
4
  import {useArrayProp} from '../../hooks'
4
- import {compose} from '../../styles'
5
5
  import {ThemeColorSpotKey, useTheme} from '../../theme'
6
6
  import {AvatarPosition, AvatarSize, AvatarStatus} from '../../types'
7
7
  import {Text} from '../text'
8
8
  import {avatarStyle, responsiveAvatarSizeStyle} from './styles'
9
- import {AvatarRootStyleProps, ResponsiveAvatarSizeStyleProps} from './types'
10
9
 
11
10
  /**
12
11
  * @public
@@ -28,20 +27,18 @@ export interface AvatarProps {
28
27
  title?: string
29
28
  }
30
29
 
31
- const Root = memo(
32
- compose<AvatarRootStyleProps & ResponsiveAvatarSizeStyleProps>('div', [
33
- responsiveAvatarSizeStyle,
34
- avatarStyle.root,
35
- ])
30
+ const Root = styled.div<{$color: string; $size: AvatarSize[]}>(
31
+ responsiveAvatarSizeStyle,
32
+ avatarStyle.root
36
33
  )
37
34
 
38
- const Arrow = memo(compose('div', [avatarStyle.arrow]))
35
+ const Arrow = styled.div(avatarStyle.arrow)
39
36
 
40
- const BgStroke = memo(compose('ellipse', [avatarStyle.bgStroke]))
37
+ const BgStroke = styled.ellipse(avatarStyle.bgStroke)
41
38
 
42
- const Stroke = memo(compose('ellipse', [avatarStyle.stroke]))
39
+ const Stroke = styled.ellipse(avatarStyle.stroke)
43
40
 
44
- const Initials = memo(compose('div', [avatarStyle.initials]))
41
+ const Initials = styled.div(avatarStyle.initials)
45
42
 
46
43
  /**
47
44
  * @public
@@ -1,12 +1,12 @@
1
- import {forwardRef, memo, useMemo} from 'react'
2
- import {CSSObject} from 'styled-components'
1
+ import {forwardRef, useMemo} from 'react'
2
+ import styled, {css} from 'styled-components'
3
3
  import {EMPTY_RECORD} from '../../constants'
4
4
  import {useArrayProp} from '../../hooks'
5
- import {rem, _responsive, ThemeProps, compose} from '../../styles'
5
+ import {rem, _responsive, ThemeProps} from '../../styles'
6
6
  import {AvatarSize} from '../../types'
7
7
  import {Text} from '../text'
8
8
 
9
- function _responsiveAvatarCounterSizeStyle(props: {$size: AvatarSize[]} & ThemeProps): CSSObject[] {
9
+ function _responsiveAvatarCounterSizeStyle(props: {$size: AvatarSize[]} & ThemeProps) {
10
10
  const {theme} = props
11
11
  const {avatar, media} = theme.sanity
12
12
 
@@ -23,31 +23,29 @@ function _responsiveAvatarCounterSizeStyle(props: {$size: AvatarSize[]} & ThemeP
23
23
  })
24
24
  }
25
25
 
26
- function _avatarCounterBaseStyle(props: ThemeProps): CSSObject {
26
+ function _avatarCounterBaseStyle(props: ThemeProps) {
27
27
  const {theme} = props
28
28
 
29
- return {
30
- alignItems: 'center',
31
- justifyContent: 'center',
32
- boxSizing: 'border-box',
33
- userSelect: 'none',
34
- // color: 'inherit',
35
- color: 'var(--card-fg-color)',
36
- background: 'var(--card-bg-color)',
37
- boxShadow: '0 0 0 1px var(--card-bg-color), inset 0 0 0 1.5px var(--card-hairline-hard-color)',
38
- padding: `0 ${rem(theme.sanity.space[2])}`,
29
+ return css`
30
+ align-items: center;
31
+ justify-content: center;
32
+ box-sizing: border-box;
33
+ user-select: none;
34
+ color: inherit;
35
+ color: var(--card-fg-color);
36
+ background: var(--card-bg-color);
37
+ box-shadow: 0 0 0 1px var(--card-bg-color), inset 0 0 0 1.5px var(--card-hairline-hard-color);
38
+ padding: 0 ${rem(theme.sanity.space[2])};
39
39
 
40
- '&:not([hidden])': {
41
- display: 'flex',
42
- },
43
- }
40
+ &:not([hidden]) {
41
+ display: flex;
42
+ }
43
+ `
44
44
  }
45
45
 
46
- const Root = memo(
47
- compose<{$size: AvatarSize[]}>('div', [
48
- _responsiveAvatarCounterSizeStyle,
49
- _avatarCounterBaseStyle,
50
- ])
46
+ const Root = styled.div<{$size: AvatarSize[]}>(
47
+ _responsiveAvatarCounterSizeStyle,
48
+ _avatarCounterBaseStyle
51
49
  )
52
50
 
53
51
  /**
@@ -1,22 +1,26 @@
1
- import {cloneElement, forwardRef, memo} from 'react'
2
- import {CSSObject} from 'styled-components'
1
+ import {cloneElement, forwardRef} from 'react'
2
+ import styled, {css} from 'styled-components'
3
3
  import {EMPTY_RECORD} from '../../constants'
4
4
  import {useArrayProp} from '../../hooks'
5
- import {rem, _responsive, ThemeProps, compose} from '../../styles'
5
+ import {rem, _responsive, ThemeProps} from '../../styles'
6
6
  import {AvatarSize} from '../../types'
7
7
  import {childrenToElementArray} from '../helpers'
8
8
  import {AvatarCounter} from './avatarCounter'
9
9
 
10
- const BASE_STYLES: CSSObject = {
11
- whiteSpace: 'nowrap',
10
+ const BASE_STYLES = css`
11
+ white-space: nowrap;
12
12
 
13
- '& > div': {
14
- verticalAlign: 'top',
13
+ & > div {
14
+ vertical-align: top;
15
15
 
16
- '&:not([hidden])': {
17
- display: 'inline-block',
18
- },
19
- },
16
+ &:not([hidden]) {
17
+ display: inline-block;
18
+ }
19
+ }
20
+ `
21
+
22
+ function avatarStackStyle() {
23
+ return BASE_STYLES
20
24
  }
21
25
 
22
26
  function responsiveAvatarStackSizeStyle(props: {$size: AvatarSize[]} & ThemeProps) {
@@ -36,9 +40,7 @@ function responsiveAvatarStackSizeStyle(props: {$size: AvatarSize[]} & ThemeProp
36
40
  })
37
41
  }
38
42
 
39
- const Root = memo(
40
- compose<{$size: AvatarSize[]}>('div', [responsiveAvatarStackSizeStyle, BASE_STYLES])
41
- )
43
+ const Root = styled.div<{$size: AvatarSize[]}>(responsiveAvatarStackSizeStyle, avatarStackStyle)
42
44
 
43
45
  /**
44
46
  * @public