@sanity/ui 5.0.0-alpha.2 → 5.0.0-alpha.21

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 (140) hide show
  1. package/README.md +1 -1
  2. package/dist/LazyRefractor-CQ22IeXB.js +19 -0
  3. package/dist/LazyRefractor-CQ22IeXB.js.map +1 -0
  4. package/dist/cli/install.js +2 -1
  5. package/dist/index.d.ts +826 -855
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +2439 -1796
  8. package/dist/index.js.map +1 -1
  9. package/dist/polyfills.d.ts +1 -0
  10. package/dist/polyfills.js +5 -0
  11. package/dist/polyfills.js.map +1 -0
  12. package/dist/styles.css +1 -1
  13. package/package.json +16 -9
  14. package/src/cli/install.ts +2 -1
  15. package/src/components/avatar/Avatar.tsx +50 -0
  16. package/src/components/avatar/avatar.css +51 -0
  17. package/src/components/avatar/avatar.props.ts +57 -0
  18. package/src/components/avatar-counter/AvatarCounter.tsx +38 -0
  19. package/src/components/avatar-counter/avatar-counter.css +8 -0
  20. package/src/components/avatar-counter/avatarCounter.props.ts +44 -0
  21. package/src/components/avatar-stack/AvatarStack.tsx +60 -0
  22. package/src/components/avatar-stack/avatar-stack.css +16 -0
  23. package/src/components/avatar-stack/avatarStack.props.ts +20 -0
  24. package/src/components/badge/Badge.tsx +53 -0
  25. package/src/components/badge/badge.css +6 -0
  26. package/src/components/badge/badge.props.ts +31 -0
  27. package/src/components/box/box.css +5 -0
  28. package/src/components/box/box.props.ts +7 -2
  29. package/src/components/button/Button.tsx +7 -1
  30. package/src/components/button/button.css +51 -23
  31. package/src/components/button/button.props.ts +27 -9
  32. package/src/components/card/Card.tsx +1 -1
  33. package/src/components/card/card.props.ts +10 -5
  34. package/src/components/checkbox/Checkbox.tsx +15 -29
  35. package/src/components/checkbox/checkbox.css +19 -20
  36. package/src/components/checkbox/checkbox.props.ts +11 -12
  37. package/src/components/code/Code.tsx +18 -19
  38. package/src/components/code/code.props.ts +23 -14
  39. package/src/components/container/Container.tsx +5 -1
  40. package/src/components/container/container.css +4 -0
  41. package/src/components/container/container.props.ts +6 -2
  42. package/src/components/dialog/Dialog.tsx +139 -0
  43. package/src/components/dialog/dialog.css +49 -0
  44. package/src/components/dialog/dialog.props.ts +45 -0
  45. package/src/components/eyebrow/eyebrow.props.ts +6 -2
  46. package/src/components/flex/flex.css +5 -0
  47. package/src/components/flex/flex.props.ts +6 -2
  48. package/src/components/grid/grid.css +5 -0
  49. package/src/components/grid/grid.props.ts +14 -3
  50. package/src/components/h-stack/HStack.tsx +8 -14
  51. package/src/components/h-stack/hStack.props.ts +5 -13
  52. package/src/components/heading/Heading.tsx +8 -3
  53. package/src/components/heading/heading.css +0 -5
  54. package/src/components/heading/heading.props.ts +16 -5
  55. package/src/components/hotkeys/Hotkeys.tsx +29 -0
  56. package/src/components/hotkeys/hotkeys.css +3 -0
  57. package/src/components/hotkeys/hotkeys.props.ts +15 -0
  58. package/src/components/icon/Icon.tsx +22 -11
  59. package/src/components/icon/icon.props.ts +7 -3
  60. package/src/components/icon-button/iconButton.props.ts +7 -2
  61. package/src/components/index.css +12 -1
  62. package/src/components/indicator/indicator.css +1 -1
  63. package/src/components/indicator/indicator.props.ts +6 -2
  64. package/src/components/indicator-stack/indicatorStack.props.ts +3 -1
  65. package/src/components/inline/inline.props.ts +6 -2
  66. package/src/components/kbd/KBD.tsx +33 -0
  67. package/src/components/kbd/kbd.css +6 -0
  68. package/src/components/kbd/kbd.props.ts +20 -0
  69. package/src/components/link/link.props.ts +4 -4
  70. package/src/components/list/list.props.ts +27 -9
  71. package/src/components/popover/Popover.tsx +85 -0
  72. package/src/components/popover/popover.css +21 -0
  73. package/src/components/popover/popover.props.ts +38 -0
  74. package/src/components/press-area/pressArea.props.ts +3 -1
  75. package/src/components/radio/Radio.tsx +10 -28
  76. package/src/components/radio/radio.css +17 -32
  77. package/src/components/radio/radio.props.ts +1 -19
  78. package/src/components/select/Select.tsx +41 -0
  79. package/src/components/select/select.css +67 -0
  80. package/src/components/select/select.props.ts +18 -0
  81. package/src/components/skip-to-content/skipToContent.props.ts +9 -3
  82. package/src/components/spinner/Spinner.tsx +2 -1
  83. package/src/components/spinner/spinner.props.ts +3 -0
  84. package/src/components/switch/Switch.tsx +9 -21
  85. package/src/components/switch/switch.css +22 -23
  86. package/src/components/switch/switch.props.ts +7 -11
  87. package/src/components/tabs/Tabs.tsx +186 -0
  88. package/src/components/tabs/tabs.css +34 -0
  89. package/src/components/tabs/tabs.props.ts +66 -0
  90. package/src/components/text/text.props.ts +6 -2
  91. package/src/components/text-area/TextArea.tsx +32 -0
  92. package/src/components/text-area/text-area.css +56 -0
  93. package/src/components/text-area/textArea.props.ts +35 -0
  94. package/src/components/text-input/TextInput.tsx +32 -0
  95. package/src/components/text-input/text-input.css +55 -0
  96. package/src/components/text-input/textInput.props.ts +42 -0
  97. package/src/components/tooltip/Tooltip.tsx +59 -55
  98. package/src/components/tooltip/tooltip.css +21 -40
  99. package/src/components/tooltip/tooltip.props.ts +24 -8
  100. package/src/components/tooltip-group/TooltipGroup.tsx +2 -5
  101. package/src/components/tooltip-group/tooltipGroup.props.ts +3 -1
  102. package/src/components/v-stack/VStack.tsx +8 -14
  103. package/src/components/v-stack/vStack.props.ts +5 -13
  104. package/src/components/visually-hidden/visuallyHidden.props.ts +6 -2
  105. package/src/css/classes/dynamic/height.css +2 -0
  106. package/src/css/classes/generic/display.css +8 -8
  107. package/src/css/classes/generic/placement.css +105 -86
  108. package/src/css/classes/local/animation.css +4 -0
  109. package/src/css/classes/local/field-sizing.css +3 -0
  110. package/src/css/classes/local/index.css +3 -1
  111. package/src/css/classes/local/text-trim.css +11 -4
  112. package/src/css/classes/local/top-anchor.css +4 -0
  113. package/src/css/classes/system/shadow.css +6 -6
  114. package/src/css/classes/system/typography.css +0 -4
  115. package/src/css/global/reset.css +16 -1
  116. package/src/css/tokens/semantic.css +7 -6
  117. package/src/css/tokens/surface.css +80 -12
  118. package/src/hooks/useIsClient.ts +10 -0
  119. package/src/index.ts +17 -2
  120. package/src/polyfills.ts +17 -0
  121. package/src/props/formElement.ts +34 -0
  122. package/src/props/layout.ts +3 -3
  123. package/src/props/tone.ts +13 -2
  124. package/src/types/Avatar.ts +14 -0
  125. package/src/types/Code.ts +0 -3
  126. package/src/types/Eyebrow.ts +1 -1
  127. package/src/types/FormElement.ts +2 -0
  128. package/src/types/Heading.ts +1 -1
  129. package/src/types/TextAlign.ts +1 -1
  130. package/src/types/Tone.ts +2 -0
  131. package/src/utils/getProps.ts +1 -1
  132. package/src/utils/mergeTriggerProps.ts +66 -0
  133. package/src/utils/renderPortal.tsx +14 -0
  134. package/src/version.ts +2 -2
  135. package/dist/_chunks-es/LazyRefractor.js +0 -20
  136. package/dist/_chunks-es/LazyRefractor.js.map +0 -1
  137. package/src/components/label/Label.tsx +0 -34
  138. package/src/components/label/label.css +0 -3
  139. package/src/components/label/label.props.ts +0 -19
  140. package/src/css/classes/local/tone.css +0 -75
@@ -4,6 +4,9 @@ import type {Responsive} from '../../types/Responsive'
4
4
 
5
5
  /** @public */
6
6
  export interface SpinnerProps extends React.ComponentProps<'svg'> {
7
+ /**
8
+ * Size of the spinner icon.
9
+ */
7
10
  size?: Responsive<IconSize>
8
11
  }
9
12
 
@@ -3,45 +3,33 @@ import clsx from 'clsx'
3
3
  import {getProps} from '../../utils/getProps'
4
4
  import {suffixClassName} from '../../utils/suffixClassName'
5
5
  import {Flex} from '../flex/Flex'
6
- import {Label} from '../label/Label'
7
- import {VisuallyHidden} from '../visually-hidden/VisuallyHidden'
8
6
  import {type SwitchProps, switchProps} from './switch.props'
9
7
 
10
8
  const switchClassName = suffixClassName('sui-Switch')
11
9
  const switchInputClassName = suffixClassName('sui-SwitchInput')
12
- const switchMarkClassName = suffixClassName('sui-SwitchMark')
13
10
 
14
11
  /** @beta */
15
12
  export function Switch(props: SwitchProps) {
16
- const {className, style, disabled, error, label, ...rest} = getProps(props, switchProps)
13
+ const {className, style, hasError, ...rest} = getProps(props, switchProps)
17
14
 
18
15
  return (
19
- <Label
16
+ <Flex
17
+ as="span"
20
18
  className={clsx(switchClassName, className)}
21
19
  style={style}
22
20
  data-ui="Switch"
23
- disabled={props.disabled}
24
- error={error}
21
+ position="relative"
22
+ alignItems="center"
23
+ radius={6}
25
24
  >
26
- <VisuallyHidden
27
- as="input"
25
+ <input
28
26
  type="checkbox"
29
27
  role="switch"
30
28
  className={switchInputClassName}
31
- disabled={disabled}
29
+ aria-invalid={hasError || undefined}
32
30
  {...rest}
33
31
  />
34
-
35
- <Flex
36
- as="span"
37
- className={clsx(switchMarkClassName, error && 'sui-error')}
38
- alignItems="center"
39
- radius={6}
40
- aria-hidden="true"
41
- />
42
-
43
- {label}
44
- </Label>
32
+ </Flex>
45
33
  )
46
34
  }
47
35
 
@@ -1,9 +1,4 @@
1
- /**
2
- * Custom switch control, base
3
- */
4
- .sui-SwitchMark {
5
- /* Background and border colours are computed relatively in hover states;
6
- we use custom properties to make this easier */
1
+ .sui-Switch {
7
2
  --background-color: var(--backdrop);
8
3
  --border-color: var(--separator-high);
9
4
  /* Switch size stored as custom properties to be used with calc
@@ -17,10 +12,17 @@
17
12
  transition: var(--hover-transition);
18
13
  }
19
14
 
15
+ .sui-SwitchInput {
16
+ opacity: 0;
17
+ position: absolute;
18
+ /* Use negative inset for 24x24 pixel hit area */
19
+ inset: var(--form-element-inset);
20
+ }
21
+
20
22
  /**
21
23
  * Custom switch marker
22
24
  */
23
- .sui-SwitchMark:after {
25
+ .sui-Switch:before {
24
26
  content: '';
25
27
  display: block;
26
28
  background-color: var(--foreground-high);
@@ -34,16 +36,14 @@
34
36
  /**
35
37
  * Hover - uses relative border/background colours to darken/lighten in both normal & error state
36
38
  */
37
- /** Switch border (unchecked) */
38
- .sui-Switch:hover .sui-SwitchMark {
39
+ .sui-Switch:has(.sui-SwitchInput:hover) {
39
40
  border-color: light-dark(
40
41
  oklch(from var(--border-color) calc(l - var(--hover-lightness-delta)) c h),
41
42
  oklch(from var(--border-color) calc(l + var(--hover-lightness-delta)) c h)
42
43
  );
43
44
  }
44
45
 
45
- /* Switch background (checked) */
46
- .sui-Switch:hover .sui-SwitchInput:is(:checked) + .sui-SwitchMark {
46
+ .sui-Switch:has(.sui-SwitchInput:is(:checked):hover) {
47
47
  background-color: light-dark(
48
48
  oklch(from var(--background-color) calc(l - var(--hover-lightness-delta)) c h),
49
49
  oklch(from var(--background-color) calc(l + var(--hover-lightness-delta)) c h)
@@ -53,7 +53,7 @@
53
53
  /**
54
54
  * Focus
55
55
  */
56
- .sui-SwitchInput:focus-visible + .sui-SwitchMark {
56
+ .sui-Switch:has(.sui-SwitchInput:focus-visible) {
57
57
  outline: var(--focus-outline);
58
58
  outline-offset: var(--focus-offset);
59
59
  }
@@ -61,12 +61,12 @@
61
61
  /**
62
62
  * Checked
63
63
  */
64
- .sui-SwitchInput:checked + .sui-SwitchMark {
64
+ .sui-Switch:has(.sui-SwitchInput:checked) {
65
65
  --background-color: var(--active-background-emphasized);
66
66
  --border-color: transparent;
67
67
  }
68
68
 
69
- .sui-SwitchInput:checked + .sui-SwitchMark:after {
69
+ .sui-Switch:has(.sui-SwitchInput:checked):before {
70
70
  background-color: var(--active-foreground-emphasized);
71
71
  translate: calc(var(--width) - 175%);
72
72
  }
@@ -74,46 +74,45 @@
74
74
  /**
75
75
  * Disabled
76
76
  */
77
- .sui-SwitchInput:disabled + .sui-SwitchMark {
77
+ .sui-Switch:has(.sui-SwitchInput:disabled) {
78
78
  --background-color: var(--inert-background);
79
79
  --border-color: var(--separator-low);
80
80
  }
81
81
 
82
- .sui-SwitchInput:disabled + .sui-SwitchMark:after {
82
+ .sui-Switch:has(.sui-SwitchInput:disabled):before {
83
83
  background: var(--inert-foreground);
84
84
  }
85
85
 
86
- /* Turn hover (and all pointer events) off for disabled switches */
87
- .sui-Switch:has(:disabled) {
86
+ .sui-SwitchInput:disabled {
88
87
  pointer-events: none;
89
88
  }
90
89
 
91
90
  /**
92
91
  * Disabled and checked
93
92
  */
94
- .sui-SwitchInput:disabled:checked + .sui-SwitchMark {
93
+ .sui-Switch:has(.sui-SwitchInput:disabled:checked) {
95
94
  --background-color: var(--inert-foreground);
96
95
  --border-color: transparent;
97
96
  }
98
97
 
99
- .sui-SwitchInput:disabled:checked + .sui-SwitchMark:after {
98
+ .sui-Switch:has(.sui-SwitchInput:disabled:checked):before {
100
99
  background-color: var(--inert-background);
101
100
  }
102
101
 
103
102
  /**
104
103
  * Error
105
104
  */
106
- .sui-SwitchMark.sui-error {
105
+ .sui-Switch:has(.sui-SwitchInput[aria-invalid="true"]) {
107
106
  --border-color: var(--error-separator);
108
107
  }
109
108
 
110
- .sui-SwitchMark.sui-error:after {
109
+ .sui-Switch:has(.sui-SwitchInput:not(:checked)[aria-invalid="true"]):before {
111
110
  background-color: var(--error-separator);
112
111
  }
113
112
 
114
113
  /**
115
114
  * Error and checked
116
115
  */
117
- .sui-SwitchInput:checked + .sui-SwitchMark.sui-error {
116
+ .sui-Switch:has(.sui-SwitchInput:checked[aria-invalid="true"]) {
118
117
  --background-color: var(--error-background-emphasized);
119
118
  }
@@ -1,20 +1,16 @@
1
- import {type MarginProps, marginProps} from '../../props/margin'
2
1
  import {type PropDef} from '../../types/PropDef'
3
2
 
4
3
  /** @beta */
5
- export interface SwitchProps extends React.ComponentProps<'input'>, MarginProps {
6
- /** Error state */
7
- error?: boolean
8
- /** Input label */
9
- label: React.ReactNode
4
+ export interface SwitchProps extends React.ComponentProps<'input'> {
5
+ /**
6
+ * Applies error styling to the switch track for invalid states.
7
+ * @remarks Use when form validation fails. Pair with a visible error message.
8
+ */
9
+ hasError?: boolean
10
10
  }
11
11
 
12
12
  export const switchProps: Record<string, PropDef> = {
13
- error: {
13
+ hasError: {
14
14
  type: 'boolean',
15
15
  },
16
- label: {
17
- type: 'string',
18
- },
19
- ...marginProps,
20
16
  }
@@ -0,0 +1,186 @@
1
+ import clsx from 'clsx'
2
+ import {createContext, isValidElement, useContext, useId} from 'react'
3
+
4
+ import {getProps} from '../../utils/getProps'
5
+ import {suffixClassName} from '../../utils/suffixClassName'
6
+ import {Box} from '../box/Box'
7
+ import {HStack} from '../h-stack/HStack'
8
+ import {Icon} from '../icon/Icon'
9
+ import {
10
+ tabProps,
11
+ type TabProps,
12
+ tabsListProps,
13
+ type TabsListProps,
14
+ tabsPanelProps,
15
+ type TabsPanelProps,
16
+ type TabsProps,
17
+ tabsProps,
18
+ } from './tabs.props'
19
+
20
+ const tabsClassName = suffixClassName('sui-Tabs')
21
+
22
+ const TabsContext = createContext<{
23
+ value: string
24
+ onValueChange: (value: string) => void
25
+ tabsRootId: string
26
+ } | null>(null)
27
+
28
+ function useTabsContext() {
29
+ const context = useContext(TabsContext)
30
+ if (!context) throw new Error('Tabs.[subcomponents] must be rendered inside the Tabs component')
31
+ return context
32
+ }
33
+
34
+ function getTabId(tabsRootId: string, value: string): string {
35
+ const valueWithoutSpaces = value.replace(/\s/g, '-')
36
+ return `${tabsRootId}-${valueWithoutSpaces}-tab`
37
+ }
38
+
39
+ function getPanelId(tabsRootId: string, value: string): string {
40
+ const valueWithoutSpaces = value.replace(/\s/g, '-')
41
+ return `${tabsRootId}-${valueWithoutSpaces}-panel`
42
+ }
43
+
44
+ function TabsRoot({value, onValueChange, ...props}: TabsProps) {
45
+ const {children, className, style, ...rest} = getProps(props, tabsProps)
46
+
47
+ const tabsRootId = useId()
48
+
49
+ return (
50
+ <TabsContext.Provider value={{value, onValueChange, tabsRootId}}>
51
+ <div className={clsx(tabsClassName, className)} style={style} data-ui="Tabs" {...rest}>
52
+ {children}
53
+ </div>
54
+ </TabsContext.Provider>
55
+ )
56
+ }
57
+
58
+ function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
59
+ // Ignore keydowns if made with alt, ctrl, or meta
60
+ if (event.altKey || event.ctrlKey || event.metaKey) {
61
+ return
62
+ }
63
+
64
+ const tabsList = event.currentTarget
65
+ const focusedTab = event.target
66
+ const tabs = Array.from(tabsList.querySelectorAll<HTMLElement>('[role="tab"]'))
67
+ const focusedTabIndex = tabs.indexOf(focusedTab as HTMLElement)
68
+
69
+ if (event.key === 'ArrowLeft') {
70
+ event.preventDefault()
71
+ const previousTab = tabs[(focusedTabIndex - 1 + tabs.length) % tabs.length]
72
+ previousTab?.focus()
73
+ }
74
+ if (event.key === 'ArrowRight') {
75
+ event.preventDefault()
76
+ const nextTab = tabs[(focusedTabIndex + 1) % tabs.length]
77
+ nextTab?.focus()
78
+ }
79
+ if (event.key === 'Home') {
80
+ event.preventDefault()
81
+ tabs[0]?.focus()
82
+ }
83
+ if (event.key === 'End') {
84
+ event.preventDefault()
85
+ tabs[tabs.length - 1]?.focus()
86
+ }
87
+ }
88
+
89
+ function TabsList(props: TabsListProps) {
90
+ const {children, className, style, ...rest} = getProps(props, tabsListProps)
91
+
92
+ return (
93
+ <HStack
94
+ {...rest}
95
+ role="tablist"
96
+ className={className}
97
+ style={style}
98
+ data-ui="Tabs.List"
99
+ gap={1}
100
+ onKeyDown={handleKeyDown}
101
+ >
102
+ {children}
103
+ </HStack>
104
+ )
105
+ }
106
+
107
+ const tabClasses = clsx(
108
+ 'sui-display-inline-flex',
109
+ 'sui-align-items-center',
110
+ 'sui-gap1',
111
+ 'sui-px2',
112
+ 'sui-py1',
113
+ 'sui-radius2',
114
+ 'sui-text-body1',
115
+ 'sui-weight-medium',
116
+ )
117
+
118
+ function Tab({value, tone = 'neutral', ...props}: TabProps) {
119
+ const {icon: IconProp, label, className, style, ...rest} = getProps({tone, ...props}, tabProps)
120
+
121
+ const {tabsRootId, value: contextValue, onValueChange} = useTabsContext()
122
+ const selected = contextValue === value
123
+
124
+ return (
125
+ <button
126
+ className={clsx(tabClasses, className)}
127
+ style={style}
128
+ {...rest}
129
+ data-ui="Tabs.Tab"
130
+ type="button"
131
+ role="tab"
132
+ id={getTabId(tabsRootId, value)}
133
+ aria-controls={getPanelId(tabsRootId, value)}
134
+ aria-selected={selected}
135
+ /* Only the active tab should receive focus via Tab key; others focus via arrow keys */
136
+ tabIndex={selected ? 0 : -1}
137
+ onClick={(e) => {
138
+ props.onClick?.(e)
139
+ onValueChange(value)
140
+ }}
141
+ >
142
+ {IconProp &&
143
+ (isValidElement(IconProp) ? (
144
+ IconProp
145
+ ) : (
146
+ <Icon icon={IconProp} marginX={-1} marginY={-2} size={1} />
147
+ ))}
148
+ {label}
149
+ </button>
150
+ )
151
+ }
152
+
153
+ function TabPanel({value, ...props}: TabsPanelProps) {
154
+ const {children, className, style, ...rest} = getProps(props, tabsPanelProps)
155
+
156
+ const {tabsRootId, value: contextValue} = useTabsContext()
157
+ const selected = contextValue === value
158
+
159
+ return (
160
+ <Box
161
+ className={className}
162
+ style={style}
163
+ // Default tabIndex for panels without focusable content — consumer overrides if their panel content is focusable
164
+ tabIndex={0}
165
+ {...rest}
166
+ data-ui="Tabs.Panel"
167
+ display={selected ? 'block' : 'none'}
168
+ role="tabpanel"
169
+ id={getPanelId(tabsRootId, value)}
170
+ aria-labelledby={getTabId(tabsRootId, value)}
171
+ >
172
+ {children}
173
+ </Box>
174
+ )
175
+ }
176
+
177
+ TabsRoot.displayName = 'Tabs'
178
+
179
+ /** @public */
180
+ export const Tabs = TabsRoot
181
+
182
+ TabsRoot.List = TabsList
183
+ TabsRoot.Tab = Tab
184
+ TabsRoot.Panel = TabPanel
185
+
186
+ export type {TabsProps, TabsListProps, TabProps, TabsPanelProps}
@@ -0,0 +1,34 @@
1
+ .sui-Tabs [role="tab"] {
2
+ --background-color: transparent;
3
+ --foreground-color: var(--foreground-low);
4
+ --hover-blend-color: var(--foreground-low);
5
+ background-color: var(--background-color);
6
+ color: var(--foreground-color);
7
+ transition: var(--hover-transition);
8
+ }
9
+
10
+ .sui-Tabs [role="tab"] .sui-Icon {
11
+ color: var(--foreground-color);
12
+ }
13
+
14
+ .sui-Tabs [role="tab"]:hover {
15
+ background: color-mix(
16
+ in srgb,
17
+ var(--hover-blend-color) 12%,
18
+ var(--background-color)
19
+ );
20
+ }
21
+
22
+ .sui-Tabs [role="tab"]:focus-visible {
23
+ outline: var(--focus-outline);
24
+ outline-offset: var(--focus-offset);
25
+ }
26
+
27
+ .sui-Tabs [role="tab"]:active {
28
+ transform: scale(0.975);
29
+ }
30
+
31
+ .sui-Tabs [role="tab"][aria-selected="true"] {
32
+ --background-color: var(--background-low);
33
+ --foreground-color: var(--foreground-high);
34
+ }
@@ -0,0 +1,66 @@
1
+ import type {LayoutProps} from '../../props/layout'
2
+ import {toneProps, type ToneProps} from '../../props/tone'
3
+ import {type PropDef} from '../../types/PropDef'
4
+
5
+ /** @public */
6
+ export interface TabsProps extends React.ComponentProps<'div'> {
7
+ /** The `value` of the active Tabs.Tab */
8
+ value: string
9
+ /** An updater function to set `value` - will be invoked with the `value` of the selected Tabs.Tab */
10
+ onValueChange: (value: string) => void
11
+ }
12
+
13
+ export const tabsProps: Record<string, PropDef> = {
14
+ value: {
15
+ type: 'string',
16
+ },
17
+ }
18
+
19
+ // Tabs.List requires either aria-label or aria-labelledby
20
+ type TabsListLabelProps =
21
+ | {'aria-labelledby': string; 'aria-label'?: never}
22
+ | {'aria-label': string; 'aria-labelledby'?: never}
23
+
24
+ /** @public */
25
+ export type TabsListProps = Omit<React.ComponentProps<'div'>, 'id' | 'role'> & TabsListLabelProps
26
+
27
+ export const tabsListProps: Record<string, PropDef> = {}
28
+
29
+ /** @public */
30
+ export interface TabProps
31
+ extends
32
+ Omit<React.ComponentProps<'button'>, 'aria-disabled' | 'disabled' | 'id' | 'role'>,
33
+ ToneProps {
34
+ /** Optional icon for the tab */
35
+ icon?: React.ElementType | React.ReactNode
36
+ /** Text label to display in the tab */
37
+ label: string
38
+ /** Unique string used to identify this tab and its matching Tabs.Panel */
39
+ value: string
40
+ }
41
+
42
+ export const tabProps: Record<string, PropDef> = {
43
+ icon: {
44
+ type: 'string',
45
+ },
46
+ label: {
47
+ type: 'string',
48
+ },
49
+ value: {
50
+ type: 'string',
51
+ },
52
+ ...toneProps,
53
+ }
54
+
55
+ /** @public */
56
+ export interface TabsPanelProps
57
+ extends Omit<React.ComponentProps<'div'>, 'id' | 'role'>, LayoutProps {
58
+ /** Unique string used to identify this panel and its matching Tabs.Tab */
59
+ value: string
60
+ }
61
+
62
+ export const tabsPanelProps: Record<string, PropDef> = {
63
+ value: {
64
+ type: 'string',
65
+ },
66
+ }
@@ -5,9 +5,13 @@ import {TEXT_SIZE, type TextSize} from '../../types/Text'
5
5
 
6
6
  /** @public */
7
7
  export interface TextProps<T extends React.ElementType = 'span'> extends TypographyProps {
8
- /** Element to render */
8
+ /**
9
+ * HTML element to render.
10
+ */
9
11
  as?: T
10
- /** CSS **font-size** property */
12
+ /**
13
+ * Sets font size.
14
+ */
11
15
  size?: Responsive<TextSize>
12
16
  }
13
17
 
@@ -0,0 +1,32 @@
1
+ import clsx from 'clsx'
2
+
3
+ import {getProps} from '../../utils/getProps'
4
+ import {suffixClassName} from '../../utils/suffixClassName'
5
+ import {type TextAreaProps, textAreaProps} from './textArea.props'
6
+
7
+ const textAreaClassName = suffixClassName('sui-TextArea')
8
+
9
+ /** @public */
10
+ export function TextArea({
11
+ autoResize,
12
+ density = 'regular',
13
+ hasError,
14
+ rows = 5,
15
+ ...props
16
+ }: TextAreaProps) {
17
+ const {className, style, ...rest} = getProps({autoResize, density, rows, ...props}, textAreaProps)
18
+
19
+ const textAreaClasses = clsx(textAreaClassName, 'sui-radius2', 'sui-width-full', className)
20
+
21
+ return (
22
+ <textarea
23
+ className={textAreaClasses}
24
+ style={style}
25
+ data-ui="TextArea"
26
+ {...rest}
27
+ aria-invalid={hasError || undefined}
28
+ />
29
+ )
30
+ }
31
+
32
+ export type {TextAreaProps}
@@ -0,0 +1,56 @@
1
+ .sui-TextArea {
2
+ --background-color: var(--backdrop);
3
+ --border-color: var(--separator-high);
4
+ --color: var(--foreground-high);
5
+ background-color: var(--background-color);
6
+ border: 1px solid var(--border-color);
7
+ font: var(--form-element-text);
8
+ color: var(--color);
9
+ resize: none;
10
+ }
11
+
12
+ .sui-TextArea::placeholder {
13
+ color: oklch(from var(--color) l c h / var(--placeholder-opacity));
14
+ }
15
+
16
+ /**
17
+ * Error
18
+ */
19
+ .sui-TextArea[aria-invalid="true"] {
20
+ --border-color: var(--error-separator);
21
+ --color: var(--error-foreground);
22
+ }
23
+
24
+ /**
25
+ * Hover - uses relative border/background colours to darken/lighten in both normal & error state
26
+ */
27
+ .sui-TextArea:hover {
28
+ border-color: light-dark(
29
+ oklch(from var(--border-color) calc(l - var(--hover-lightness-delta)) c h),
30
+ oklch(from var(--border-color) calc(l + var(--hover-lightness-delta)) c h)
31
+ );
32
+ }
33
+
34
+ /**
35
+ * Disabled, read-only
36
+ */
37
+ .sui-TextArea:is(:disabled, :read-only) {
38
+ --background-color: var(--inert-background);
39
+ --border-color: var(--separator-low);
40
+ }
41
+
42
+ /**
43
+ * Disabled
44
+ */
45
+ .sui-TextArea:disabled {
46
+ --color: var(--inert-foreground);
47
+ pointer-events: none;
48
+ }
49
+
50
+ /**
51
+ * Focus
52
+ */
53
+ .sui-TextArea:focus-visible {
54
+ outline: var(--focus-outline);
55
+ outline-offset: var(--focus-offset);
56
+ }
@@ -0,0 +1,35 @@
1
+ import {formElementDensityProps, type FormElementDensityProps} from '../../props/formElement'
2
+ import {type HeightProps, heightProps} from '../../props/height'
3
+ import {type PropDef} from '../../types/PropDef'
4
+
5
+ /** @public */
6
+ export interface TextAreaProps
7
+ extends
8
+ React.ComponentProps<'textarea'>,
9
+ FormElementDensityProps,
10
+ Pick<HeightProps, 'maxHeight'> {
11
+ /**
12
+ * Sizes the textarea to its content via the CSS `field-sizing` property.
13
+ */
14
+ autoResize?: boolean
15
+ /**
16
+ * Used to trigger styling for invalid states.
17
+ */
18
+ hasError?: boolean
19
+ /**
20
+ * The html `rows` attribute. Defaults to 5.
21
+ */
22
+ rows?: number
23
+ }
24
+
25
+ export const textAreaProps: Record<string, PropDef> = {
26
+ autoResize: {
27
+ type: 'boolean',
28
+ className: 'field-sizing-content',
29
+ },
30
+ hasError: {
31
+ type: 'boolean',
32
+ },
33
+ maxHeight: heightProps['maxHeight'] as PropDef,
34
+ ...formElementDensityProps,
35
+ }
@@ -0,0 +1,32 @@
1
+ import clsx from 'clsx'
2
+
3
+ import {getProps} from '../../utils/getProps'
4
+ import {suffixClassName} from '../../utils/suffixClassName'
5
+ import {type TextInputProps, textInputProps} from './textInput.props'
6
+
7
+ const textInputClassName = suffixClassName('sui-TextInput')
8
+
9
+ /** @public */
10
+ export function TextInput({
11
+ density = 'regular',
12
+ hasError,
13
+ type = 'text',
14
+ ...props
15
+ }: TextInputProps) {
16
+ const {className, style, ...rest} = getProps({density, ...props}, textInputProps)
17
+
18
+ const textInputClasses = clsx(textInputClassName, 'sui-radius2', 'sui-width-full', className)
19
+
20
+ return (
21
+ <input
22
+ type={type}
23
+ className={textInputClasses}
24
+ style={style}
25
+ data-ui="TextInput"
26
+ {...rest}
27
+ aria-invalid={hasError || undefined}
28
+ />
29
+ )
30
+ }
31
+
32
+ export type {TextInputProps}