@sanity/ui 5.0.0-alpha.17 → 5.0.0-alpha.19
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/dist/index.d.ts +42 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +125 -3
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- package/src/components/button/button.css +16 -0
- package/src/components/index.css +1 -0
- package/src/components/tabs/Tabs.tsx +186 -0
- package/src/components/tabs/tabs.css +34 -0
- package/src/components/tabs/tabs.props.ts +66 -0
- package/src/index.ts +1 -0
- package/src/version.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.19",
|
|
4
4
|
"description": "Sanity UI Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@sanity-labs/design-tokens": "0.0.2-alpha.
|
|
51
|
+
"@sanity-labs/design-tokens": "0.0.2-alpha.9",
|
|
52
52
|
"@sanity/icons": "^5.2.1",
|
|
53
53
|
"clsx": "^2.1.1",
|
|
54
54
|
"comment-json": "^5.0.0",
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
var(--hover-blend-color) 12%,
|
|
20
20
|
var(--background-color)
|
|
21
21
|
);
|
|
22
|
+
color: color-mix(
|
|
23
|
+
in srgb,
|
|
24
|
+
var(--foreground-high) 25%,
|
|
25
|
+
var(--foreground-color)
|
|
26
|
+
);
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
.sui-Button:focus-visible {
|
|
@@ -57,11 +62,22 @@
|
|
|
57
62
|
--hover-blend-color: light-dark(var(--gray-950), var(--gray-50));
|
|
58
63
|
}
|
|
59
64
|
|
|
65
|
+
.sui-Button.sui-button-level-primary:hover {
|
|
66
|
+
background: color-mix(
|
|
67
|
+
in srgb,
|
|
68
|
+
var(--hover-blend-color) 12%,
|
|
69
|
+
var(--background-color)
|
|
70
|
+
);
|
|
71
|
+
color: var(--foreground-low-emphasized);
|
|
72
|
+
}
|
|
73
|
+
|
|
60
74
|
.sui-button-level-primary.sui-tone-critical {
|
|
61
75
|
--background-color: var(--background-low-emphasized);
|
|
62
76
|
--hover-blend-color: light-dark(var(--red-950), var(--red-50));
|
|
63
77
|
}
|
|
64
78
|
|
|
79
|
+
|
|
80
|
+
|
|
65
81
|
/**
|
|
66
82
|
* Secondary
|
|
67
83
|
*/
|
package/src/components/index.css
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
@import './spinner/spinner.css';
|
|
30
30
|
@import './skip-to-content/skip-to-content.css';
|
|
31
31
|
@import './switch/switch.css';
|
|
32
|
+
@import './tabs/tabs.css';
|
|
32
33
|
@import './text/text.css';
|
|
33
34
|
@import './text-area/text-area.css';
|
|
34
35
|
@import './text-input/text-input.css';
|
|
@@ -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
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -34,6 +34,7 @@ export * from './components/select/Select'
|
|
|
34
34
|
export * from './components/skip-to-content/SkipToContent'
|
|
35
35
|
export * from './components/spinner/Spinner'
|
|
36
36
|
export * from './components/switch/Switch'
|
|
37
|
+
export * from './components/tabs/Tabs'
|
|
37
38
|
export * from './components/text/Text'
|
|
38
39
|
export * from './components/text-area/TextArea'
|
|
39
40
|
export * from './components/text-input/TextInput'
|
package/src/version.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// This file is generated by scripts/write-version.js. Do not edit.
|
|
2
|
-
export const VERSION = '
|
|
3
|
-
export const HASH = '
|
|
2
|
+
export const VERSION = '500alpha19'
|
|
3
|
+
export const HASH = 'e2bb29'
|