@sanity/ui 2.9.0-canary.6 → 2.9.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.
- package/dist/_chunks-cjs/getTheme_v2.js +26 -0
- package/dist/_chunks-cjs/getTheme_v2.js.map +1 -1
- package/dist/_chunks-es/getTheme_v2.mjs +26 -0
- package/dist/_chunks-es/getTheme_v2.mjs.map +1 -1
- package/dist/_legacy/getTheme_v2.esm.js +26 -0
- package/dist/_legacy/getTheme_v2.esm.js.map +1 -1
- package/dist/index.esm.js +652 -1048
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +651 -1047
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +652 -1048
- package/dist/index.mjs.map +1 -1
- package/dist/theme.d.mts +22 -28
- package/dist/theme.d.ts +22 -28
- package/dist/theme.esm.js +124 -260
- package/dist/theme.esm.js.map +1 -1
- package/dist/theme.js +124 -260
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +124 -260
- package/dist/theme.mjs.map +1 -1
- package/package.json +60 -53
- package/src/core/__workshop__/constants.ts +27 -31
- package/src/core/components/autocomplete/autocomplete.tsx +31 -42
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +47 -35
- package/src/core/components/dialog/dialog.tsx +1 -1
- package/src/core/components/menu/__workshop__/tones.tsx +5 -6
- package/src/core/components/menu/useMenuController.ts +21 -18
- package/src/core/components/toast/__workshop__/hook.tsx +1 -1
- package/src/core/components/toast/toast.tsx +2 -2
- package/src/core/components/tree/treeItem.tsx +15 -18
- package/src/core/hooks/useElementRect/__workshop__/example.tsx +2 -2
- package/src/core/hooks/useMatchMedia.ts +22 -12
- package/src/core/primitives/badge/__workshop__/tones.tsx +6 -13
- package/src/core/primitives/button/__workshop__/custom.tsx +4 -3
- package/src/core/primitives/card/__workshop__/allTones.tsx +6 -8
- package/src/core/primitives/card/__workshop__/asButton.tsx +42 -24
- package/src/core/primitives/card/__workshop__/asComponent.tsx +1 -1
- package/src/core/primitives/card/__workshop__/checkered.tsx +17 -7
- package/src/core/primitives/card/__workshop__/interactive.tsx +10 -3
- package/src/core/primitives/card/__workshop__/listNavigation.tsx +5 -3
- package/src/core/primitives/card/__workshop__/props.tsx +7 -5
- package/src/core/primitives/card/__workshop__/selected.tsx +4 -1
- package/src/core/primitives/checkbox/__workshop__/tones.tsx +6 -0
- package/src/core/primitives/code/__workshop__/props.tsx +1 -1
- package/src/core/primitives/container/__workshop__/example.tsx +1 -1
- package/src/core/primitives/flex/__workshop__/example.tsx +3 -3
- package/src/core/primitives/grid/__workshop__/responsive.tsx +12 -12
- package/src/core/primitives/heading/__workshop__/opticalAlignment.tsx +13 -25
- package/src/core/primitives/inline/__workshop__/plain.tsx +3 -3
- package/src/core/primitives/label/__workshop__/opticalAlignment.tsx +6 -6
- package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +1 -1
- package/src/core/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +3 -3
- package/src/core/primitives/popover/__workshop__/OpenOnMountStory.tsx +1 -1
- package/src/core/primitives/popover/__workshop__/PlainStory.tsx +1 -1
- package/src/core/primitives/popover/popover.tsx +140 -74
- package/src/core/primitives/popover/popoverCard.tsx +4 -1
- package/src/core/primitives/radio/__workshop__/plain.tsx +2 -2
- package/src/core/primitives/select/__workshop__/readOnly.tsx +1 -1
- package/src/core/primitives/text/__workshop__/example.tsx +6 -6
- package/src/core/primitives/text/__workshop__/opticalAlignment.tsx +11 -21
- package/src/core/primitives/textArea/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/index.ts +0 -5
- package/src/core/primitives/textInput/__workshop__/plain.tsx +1 -2
- package/src/core/primitives/textInput/__workshop__/readOnly.tsx +6 -2
- package/src/core/primitives/textInput/__workshop__/tones.tsx +38 -0
- package/src/core/primitives/tooltip/tooltip.tsx +17 -47
- package/src/core/styles/card/_cardColorStyle.ts +8 -0
- package/src/core/theme/__workshop__/debug/story.tsx +18 -11
- package/src/core/utils/portal/portalProvider.tsx +5 -5
- package/src/theme/build/_deprecated/color/factory.ts +1 -1
- package/src/theme/build/_deprecated/color/muted/createMuted.ts +2 -2
- package/src/theme/build/buildColorTheme.ts +47 -37
- package/src/theme/build/renderColorTheme.ts +26 -30
- package/src/theme/build/resolveColorTokens.ts +51 -115
- package/src/theme/config/tokens/color/types.ts +4 -18
- package/src/theme/defaults/colorTokens.ts +8 -5
- package/src/theme/getScopedTheme.ts +9 -2
- package/src/theme/system/color/_constants.ts +6 -2
- package/src/theme/system/color/badge.ts +3 -7
- package/src/theme/system/v0/color/_system.ts +8 -4
- package/src/theme/system/v0/color/color.ts +3 -2
- package/src/theme/versioning/themeColor_v0_v2.ts +26 -0
- package/src/theme/versioning/v0_v2.ts +4 -0
- package/src/core/primitives/textInput/__workshop__/multipleTones.tsx +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "2.9.0
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"sanity",
|
|
6
6
|
"ui",
|
|
@@ -51,6 +51,32 @@
|
|
|
51
51
|
"src",
|
|
52
52
|
"theme.js"
|
|
53
53
|
],
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "run-s clean pkg:build pkg:check figma:pkg:build",
|
|
56
|
+
"clean": "rimraf .workshop dist",
|
|
57
|
+
"commit": "cz",
|
|
58
|
+
"cypress:dev": "run-p dev cypress:open",
|
|
59
|
+
"cypress:open": "cypress open",
|
|
60
|
+
"cypress:run": "cypress run",
|
|
61
|
+
"dev": "run-p storybook:dev workshop:dev",
|
|
62
|
+
"figma:pkg:build": "cd figma && pnpm build",
|
|
63
|
+
"format": "prettier --write --cache --ignore-unknown .",
|
|
64
|
+
"lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
|
|
65
|
+
"pkg:build": "pkg build --strict",
|
|
66
|
+
"pkg:check": "pkg --strict",
|
|
67
|
+
"prepare": "husky install",
|
|
68
|
+
"prepack": "pnpm build",
|
|
69
|
+
"release": "semantic-release",
|
|
70
|
+
"storybook:build": "storybook build",
|
|
71
|
+
"storybook:dev": "storybook dev -p 6006",
|
|
72
|
+
"test": "jest",
|
|
73
|
+
"test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
|
|
74
|
+
"ts:check": "tsc",
|
|
75
|
+
"watch": "pkg watch --strict",
|
|
76
|
+
"workshop:build": "workshop build",
|
|
77
|
+
"workshop:dev": "workshop dev",
|
|
78
|
+
"workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
|
|
79
|
+
},
|
|
54
80
|
"commitlint": {
|
|
55
81
|
"extends": [
|
|
56
82
|
"@commitlint/config-conventional"
|
|
@@ -84,7 +110,7 @@
|
|
|
84
110
|
"@sanity/icons": "^3.4.0",
|
|
85
111
|
"csstype": "^3.1.3",
|
|
86
112
|
"framer-motion": "11.0.8",
|
|
87
|
-
"react-compiler-runtime": "19.0.0-beta-
|
|
113
|
+
"react-compiler-runtime": "19.0.0-beta-df7b47d-20241124",
|
|
88
114
|
"react-refractor": "^2.2.0",
|
|
89
115
|
"use-effect-event": "^1.0.2"
|
|
90
116
|
},
|
|
@@ -96,24 +122,24 @@
|
|
|
96
122
|
"@commitlint/cli": "^19.4.0",
|
|
97
123
|
"@commitlint/config-conventional": "^19.2.2",
|
|
98
124
|
"@juggle/resize-observer": "^3.4.0",
|
|
99
|
-
"@sanity/pkg-utils": "^6.11.
|
|
100
|
-
"@sanity/prettier-config": "^1.0.
|
|
125
|
+
"@sanity/pkg-utils": "^6.11.11",
|
|
126
|
+
"@sanity/prettier-config": "^1.0.3",
|
|
101
127
|
"@sanity/semantic-release-preset": "^5.0.0",
|
|
102
128
|
"@sanity/ui-workshop": "^2.0.16",
|
|
103
|
-
"@storybook/addon-a11y": "^8.
|
|
104
|
-
"@storybook/addon-docs": "^8.
|
|
105
|
-
"@storybook/addon-essentials": "^8.
|
|
106
|
-
"@storybook/addon-interactions": "^8.
|
|
107
|
-
"@storybook/addon-links": "^8.
|
|
108
|
-
"@storybook/addon-mdx-gfm": "^8.
|
|
109
|
-
"@storybook/addon-storysource": "^8.
|
|
110
|
-
"@storybook/addon-themes": "^8.
|
|
111
|
-
"@storybook/blocks": "^8.
|
|
112
|
-
"@storybook/manager-api": "^8.
|
|
113
|
-
"@storybook/react": "^8.
|
|
114
|
-
"@storybook/react-vite": "^8.
|
|
115
|
-
"@storybook/test": "^8.
|
|
116
|
-
"@storybook/theming": "^8.
|
|
129
|
+
"@storybook/addon-a11y": "^8.4.5",
|
|
130
|
+
"@storybook/addon-docs": "^8.4.5",
|
|
131
|
+
"@storybook/addon-essentials": "^8.4.5",
|
|
132
|
+
"@storybook/addon-interactions": "^8.4.5",
|
|
133
|
+
"@storybook/addon-links": "^8.4.5",
|
|
134
|
+
"@storybook/addon-mdx-gfm": "^8.4.5",
|
|
135
|
+
"@storybook/addon-storysource": "^8.4.5",
|
|
136
|
+
"@storybook/addon-themes": "^8.4.5",
|
|
137
|
+
"@storybook/blocks": "^8.4.5",
|
|
138
|
+
"@storybook/manager-api": "^8.4.5",
|
|
139
|
+
"@storybook/react": "^8.4.5",
|
|
140
|
+
"@storybook/react-vite": "^8.4.5",
|
|
141
|
+
"@storybook/test": "^8.4.5",
|
|
142
|
+
"@storybook/theming": "^8.4.5",
|
|
117
143
|
"@testing-library/dom": "^10.4.0",
|
|
118
144
|
"@testing-library/jest-dom": "^6.6.2",
|
|
119
145
|
"@testing-library/react": "^16.0.1",
|
|
@@ -128,7 +154,7 @@
|
|
|
128
154
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
129
155
|
"@typescript-eslint/parser": "^7.18.0",
|
|
130
156
|
"@vitejs/plugin-react": "^4.3.3",
|
|
131
|
-
"babel-plugin-react-compiler": "beta",
|
|
157
|
+
"babel-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
|
|
132
158
|
"commitizen": "^4.3.0",
|
|
133
159
|
"cypress": "^13.13.2",
|
|
134
160
|
"cypress-real-events": "^1.13.0",
|
|
@@ -140,9 +166,9 @@
|
|
|
140
166
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
141
167
|
"eslint-plugin-prettier": "^5.2.1",
|
|
142
168
|
"eslint-plugin-react": "^7.37.2",
|
|
143
|
-
"eslint-plugin-react-compiler": "beta",
|
|
169
|
+
"eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
|
|
144
170
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
145
|
-
"eslint-plugin-storybook": "^0.
|
|
171
|
+
"eslint-plugin-storybook": "^0.11.0",
|
|
146
172
|
"http-server": "^14.1.1",
|
|
147
173
|
"husky": "^8.0.3",
|
|
148
174
|
"jest": "^29.7.0",
|
|
@@ -153,57 +179,38 @@
|
|
|
153
179
|
"npm-run-all2": "^5.0.2",
|
|
154
180
|
"prettier": "^3.3.3",
|
|
155
181
|
"react": "^18.3.1",
|
|
156
|
-
"react-compiler-runtime": "beta",
|
|
157
182
|
"react-dom": "^18.3.1",
|
|
158
183
|
"react-is": "^18.3.1",
|
|
159
184
|
"refractor": "^4.8.1",
|
|
160
185
|
"rimraf": "^5.0.5",
|
|
161
186
|
"semantic-release": "^24.0.0",
|
|
162
187
|
"start-server-and-test": "^2.0.5",
|
|
163
|
-
"storybook": "^8.
|
|
188
|
+
"storybook": "^8.4.5",
|
|
164
189
|
"styled-components": "^6.1.13",
|
|
165
190
|
"tsconfig-paths": "^4.2.0",
|
|
166
|
-
"typescript": "5.
|
|
167
|
-
"vite": "^5.4.
|
|
191
|
+
"typescript": "5.6.3",
|
|
192
|
+
"vite": "^5.4.11",
|
|
168
193
|
"vite-tsconfig-paths": "^5.0.1"
|
|
169
194
|
},
|
|
170
195
|
"peerDependencies": {
|
|
171
|
-
"react": "^18",
|
|
172
|
-
"react-dom": "^18",
|
|
173
|
-
"react-is": "^18",
|
|
196
|
+
"react": "^18 || >=19.0.0-0",
|
|
197
|
+
"react-dom": "^18 || >=19.0.0-0",
|
|
198
|
+
"react-is": "^18 || >=19.0.0-0",
|
|
174
199
|
"styled-components": "^5.2 || ^6"
|
|
175
200
|
},
|
|
201
|
+
"packageManager": "pnpm@9.12.3",
|
|
176
202
|
"engines": {
|
|
177
203
|
"node": ">=14.0.0"
|
|
178
204
|
},
|
|
179
205
|
"publishConfig": {
|
|
180
206
|
"access": "public"
|
|
181
207
|
},
|
|
208
|
+
"pnpm": {
|
|
209
|
+
"overrides": {
|
|
210
|
+
"conventional-changelog-conventionalcommits": ">= 8.0.0"
|
|
211
|
+
}
|
|
212
|
+
},
|
|
182
213
|
"esm.sh": {
|
|
183
214
|
"bundle": false
|
|
184
|
-
},
|
|
185
|
-
"scripts": {
|
|
186
|
-
"build": "run-s clean pkg:build pkg:check figma:pkg:build",
|
|
187
|
-
"clean": "rimraf .workshop dist",
|
|
188
|
-
"commit": "cz",
|
|
189
|
-
"cypress:dev": "run-p dev cypress:open",
|
|
190
|
-
"cypress:open": "cypress open",
|
|
191
|
-
"cypress:run": "cypress run",
|
|
192
|
-
"dev": "run-p storybook:dev workshop:dev",
|
|
193
|
-
"figma:pkg:build": "cd figma && pnpm build",
|
|
194
|
-
"format": "prettier --write --cache --ignore-unknown .",
|
|
195
|
-
"lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
|
|
196
|
-
"pkg:build": "pkg build --strict",
|
|
197
|
-
"pkg:check": "pkg --strict",
|
|
198
|
-
"release": "semantic-release",
|
|
199
|
-
"storybook:build": "storybook build",
|
|
200
|
-
"storybook:dev": "storybook dev -p 6006",
|
|
201
|
-
"test": "jest",
|
|
202
|
-
"test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
|
|
203
|
-
"ts:check": "tsc",
|
|
204
|
-
"watch": "pkg watch --strict",
|
|
205
|
-
"workshop:build": "workshop build",
|
|
206
|
-
"workshop:dev": "workshop dev",
|
|
207
|
-
"workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
|
|
208
215
|
}
|
|
209
|
-
}
|
|
216
|
+
}
|
|
@@ -14,11 +14,11 @@ import {
|
|
|
14
14
|
TextAlign,
|
|
15
15
|
TextInputType,
|
|
16
16
|
} from '@sanity/ui'
|
|
17
|
-
import {
|
|
17
|
+
import {ThemeColorAvatarColorKey, ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
18
18
|
|
|
19
19
|
export const WORKSHOP_AVATAR_SIZE_OPTIONS: {[key: string]: AvatarSize} = {
|
|
20
20
|
'0': 0,
|
|
21
|
-
'1
|
|
21
|
+
'1': 1,
|
|
22
22
|
'2': 2,
|
|
23
23
|
'3': 3,
|
|
24
24
|
}
|
|
@@ -31,6 +31,7 @@ export const WORKSHOP_BADGE_MODE_OPTIONS: {[key: string]: BadgeMode} = {
|
|
|
31
31
|
export const WORKSHOP_BADGE_TONE_OPTIONS: {[key: string]: BadgeTone} = {
|
|
32
32
|
Default: 'default',
|
|
33
33
|
Primary: 'primary',
|
|
34
|
+
Suggest: 'suggest',
|
|
34
35
|
Positive: 'positive',
|
|
35
36
|
Caution: 'caution',
|
|
36
37
|
Critical: 'critical',
|
|
@@ -51,7 +52,9 @@ export const WORKSHOP_BUTTON_TEXT_ALIGN_OPTIONS: {[key: string]: ButtonTextAlign
|
|
|
51
52
|
|
|
52
53
|
export const WORKSHOP_BUTTON_TONE_OPTIONS: {[key: string]: ButtonTone} = {
|
|
53
54
|
Default: 'default',
|
|
55
|
+
Neutral: 'neutral',
|
|
54
56
|
Primary: 'primary',
|
|
57
|
+
Suggest: 'suggest',
|
|
55
58
|
Positive: 'positive',
|
|
56
59
|
Caution: 'caution',
|
|
57
60
|
Critical: 'critical',
|
|
@@ -60,22 +63,24 @@ export const WORKSHOP_BUTTON_TONE_OPTIONS: {[key: string]: ButtonTone} = {
|
|
|
60
63
|
export const WORKSHOP_CARD_AS_OPTIONS: {
|
|
61
64
|
[key: string]: 'div' | 'button' | 'span' | 'ol' | 'pre' | 'ul'
|
|
62
65
|
} = {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
DIV: 'div',
|
|
67
|
+
BUTTON: 'button',
|
|
68
|
+
SPAN: 'span',
|
|
69
|
+
OL: 'ol',
|
|
70
|
+
PRE: 'pre',
|
|
71
|
+
UL: 'ul',
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
export const WORKSHOP_CARD_TONE_OPTIONS: {[key: string]: CardTone} = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
'Inherit': 'inherit',
|
|
76
|
+
'Transparent': 'transparent',
|
|
77
|
+
'Default': 'default',
|
|
78
|
+
'Neutral': 'neutral',
|
|
79
|
+
'Primary (deprecated)': 'primary',
|
|
80
|
+
'Suggest': 'suggest',
|
|
81
|
+
'Positive': 'positive',
|
|
82
|
+
'Caution': 'caution',
|
|
83
|
+
'Critical': 'critical',
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
export const WORKSHOP_CODE_LANGUAGE_OPTIONS = {
|
|
@@ -132,7 +137,7 @@ export const WORKSHOP_FONT_WEIGHT_OPTIONS: {[key: string]: ThemeFontWeightKey} =
|
|
|
132
137
|
export const WORKSHOP_HEADING_FONT_SIZE_OPTIONS = {
|
|
133
138
|
'0': 0,
|
|
134
139
|
'1': 1,
|
|
135
|
-
'2
|
|
140
|
+
'2': 2,
|
|
136
141
|
'3': 3,
|
|
137
142
|
'4': 4,
|
|
138
143
|
}
|
|
@@ -203,7 +208,7 @@ export const WORKSHOP_SPACE_OPTIONS = {
|
|
|
203
208
|
'9': 9,
|
|
204
209
|
}
|
|
205
210
|
|
|
206
|
-
export const WORKSHOP_SPOT_COLOR_OPTIONS: {[key: string]:
|
|
211
|
+
export const WORKSHOP_SPOT_COLOR_OPTIONS: {[key: string]: ThemeColorAvatarColorKey} = {
|
|
207
212
|
Gray: 'gray',
|
|
208
213
|
Blue: 'blue',
|
|
209
214
|
Purple: 'purple',
|
|
@@ -254,25 +259,16 @@ export const WORKSHOP_TEXT_OVERFLOW_OPTIONS: {[key: string]: 'ellipsis' | ''} =
|
|
|
254
259
|
export const WORKSHOP_TEXT_SIZE_OPTIONS = {
|
|
255
260
|
'0': 0,
|
|
256
261
|
'1': 1,
|
|
257
|
-
'2
|
|
262
|
+
'2': 2,
|
|
258
263
|
'3': 3,
|
|
259
264
|
'4': 4,
|
|
260
265
|
}
|
|
261
266
|
|
|
262
267
|
export const WORKSHOP_TEXT_WEIGHT_OPTIONS: {[key: string]: ThemeFontWeightKey | ''} = {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export const WORKSHOP_THEME_COLOR_TONE_OPTIONS: {[key: string]: ThemeColorToneKey} = {
|
|
270
|
-
Default: 'default',
|
|
271
|
-
Transparent: 'transparent',
|
|
272
|
-
Primary: 'primary',
|
|
273
|
-
Positive: 'positive',
|
|
274
|
-
Caution: 'caution',
|
|
275
|
-
Critical: 'critical',
|
|
268
|
+
Regular: '',
|
|
269
|
+
Medium: 'medium',
|
|
270
|
+
Semibold: 'semibold',
|
|
271
|
+
Bold: 'bold',
|
|
276
272
|
}
|
|
277
273
|
|
|
278
274
|
export const WORKSHOP_TOAST_STATUS_OPTIONS: {
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
useMemo,
|
|
18
18
|
useReducer,
|
|
19
19
|
useRef,
|
|
20
|
-
useState,
|
|
21
20
|
} from 'react'
|
|
22
21
|
import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
|
|
23
22
|
import {_hasFocus, _raf, focusFirstDescendant} from '../../helpers'
|
|
@@ -185,22 +184,21 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
185
184
|
typeof filterOptionProp === 'function' ? filterOptionProp : DEFAULT_FILTER_OPTION
|
|
186
185
|
|
|
187
186
|
// Element refs
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
const
|
|
187
|
+
const rootElementRef = useRef<HTMLDivElement | null>(null)
|
|
188
|
+
const resultsPopoverElementRef = useRef<HTMLDivElement | null>(null)
|
|
189
|
+
const inputElementRef = useRef<HTMLInputElement | null>(null)
|
|
191
190
|
const listBoxElementRef = useRef<HTMLDivElement | null>(null)
|
|
192
191
|
|
|
193
192
|
// Value refs
|
|
194
193
|
const listFocusedRef = useRef(false)
|
|
195
194
|
const valueRef = useRef(value)
|
|
196
195
|
const valuePropRef = useRef(valueProp)
|
|
197
|
-
const
|
|
196
|
+
const popoverMouseWithinRef = useRef(false)
|
|
198
197
|
|
|
199
198
|
// Forward ref to parent
|
|
200
199
|
useImperativeHandle<HTMLInputElement | null, HTMLInputElement | null>(
|
|
201
200
|
forwardedRef,
|
|
202
|
-
() =>
|
|
203
|
-
[inputElement],
|
|
201
|
+
() => inputElementRef.current,
|
|
204
202
|
)
|
|
205
203
|
|
|
206
204
|
const listBoxId = `${id}-listbox`
|
|
@@ -224,13 +222,13 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
224
222
|
// NOTE: This is a workaround for a bug that may happen in Chrome (clicking the scrollbar
|
|
225
223
|
// closes the results in certain situations):
|
|
226
224
|
// - Do not handle blur if the mouse is within the popover
|
|
227
|
-
if (
|
|
225
|
+
if (popoverMouseWithinRef.current) {
|
|
228
226
|
return
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
const elements: HTMLElement[] = (relatedElements || []).concat(
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
rootElementRef.current ? [rootElementRef.current] : [],
|
|
231
|
+
resultsPopoverElementRef.current ? [resultsPopoverElementRef.current] : [],
|
|
234
232
|
)
|
|
235
233
|
|
|
236
234
|
let focusInside = false
|
|
@@ -246,20 +244,13 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
246
244
|
|
|
247
245
|
if (focusInside === false) {
|
|
248
246
|
dispatch({type: 'root/blur'})
|
|
249
|
-
|
|
247
|
+
popoverMouseWithinRef.current = false
|
|
250
248
|
if (onQueryChange) onQueryChange(null)
|
|
251
249
|
if (onBlur) onBlur(event)
|
|
252
250
|
}
|
|
253
251
|
}, 0)
|
|
254
252
|
},
|
|
255
|
-
[
|
|
256
|
-
onBlur,
|
|
257
|
-
onQueryChange,
|
|
258
|
-
popoverMouseWithin,
|
|
259
|
-
relatedElements,
|
|
260
|
-
resultsPopoverElement,
|
|
261
|
-
rootElement,
|
|
262
|
-
],
|
|
253
|
+
[onBlur, onQueryChange, relatedElements],
|
|
263
254
|
)
|
|
264
255
|
|
|
265
256
|
const handleRootFocus = useCallback((event: FocusEvent<HTMLDivElement>) => {
|
|
@@ -278,7 +269,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
278
269
|
(v: string) => {
|
|
279
270
|
dispatch({type: 'value/change', value: v})
|
|
280
271
|
|
|
281
|
-
|
|
272
|
+
popoverMouseWithinRef.current = false
|
|
282
273
|
|
|
283
274
|
if (onSelect) onSelect(v)
|
|
284
275
|
|
|
@@ -287,9 +278,9 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
287
278
|
if (onChange) onChange(v)
|
|
288
279
|
if (onQueryChange) onQueryChange(null)
|
|
289
280
|
|
|
290
|
-
|
|
281
|
+
inputElementRef.current?.focus()
|
|
291
282
|
},
|
|
292
|
-
[
|
|
283
|
+
[onChange, onSelect, onQueryChange],
|
|
293
284
|
)
|
|
294
285
|
|
|
295
286
|
const handleRootKeyDown = useCallback(
|
|
@@ -333,9 +324,9 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
333
324
|
|
|
334
325
|
if (event.key === 'Escape') {
|
|
335
326
|
dispatch({type: 'root/escape'})
|
|
336
|
-
|
|
327
|
+
popoverMouseWithinRef.current = false
|
|
337
328
|
if (onQueryChange) onQueryChange(null)
|
|
338
|
-
|
|
329
|
+
inputElementRef.current?.focus()
|
|
339
330
|
|
|
340
331
|
return
|
|
341
332
|
}
|
|
@@ -347,12 +338,12 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
347
338
|
(listEl === target || listEl?.contains(target)) &&
|
|
348
339
|
!AUTOCOMPLETE_LISTBOX_IGNORE_KEYS.includes(event.key)
|
|
349
340
|
) {
|
|
350
|
-
|
|
341
|
+
inputElementRef.current?.focus()
|
|
351
342
|
|
|
352
343
|
return
|
|
353
344
|
}
|
|
354
345
|
},
|
|
355
|
-
[activeValue, filteredOptions, filteredOptionsLen,
|
|
346
|
+
[activeValue, filteredOptions, filteredOptionsLen, onQueryChange],
|
|
356
347
|
)
|
|
357
348
|
|
|
358
349
|
const handleInputChange = useCallback(
|
|
@@ -386,11 +377,11 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
386
377
|
)
|
|
387
378
|
|
|
388
379
|
const handlePopoverMouseEnter = useCallback(() => {
|
|
389
|
-
|
|
380
|
+
popoverMouseWithinRef.current = true
|
|
390
381
|
}, [])
|
|
391
382
|
|
|
392
383
|
const handlePopoverMouseLeave = useCallback(() => {
|
|
393
|
-
|
|
384
|
+
popoverMouseWithinRef.current = false
|
|
394
385
|
}, [])
|
|
395
386
|
|
|
396
387
|
const handleClearButtonClick = useCallback(() => {
|
|
@@ -398,8 +389,8 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
398
389
|
valueRef.current = ''
|
|
399
390
|
if (onChange) onChange('')
|
|
400
391
|
if (onQueryChange) onQueryChange(null)
|
|
401
|
-
|
|
402
|
-
}, [
|
|
392
|
+
inputElementRef.current?.focus()
|
|
393
|
+
}, [onChange, onQueryChange])
|
|
403
394
|
|
|
404
395
|
const handleClearButtonFocus = useCallback(() => {
|
|
405
396
|
dispatch({type: 'input/focus'})
|
|
@@ -491,9 +482,9 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
491
482
|
|
|
492
483
|
if (openButtonProps.onClick) openButtonProps.onClick(event)
|
|
493
484
|
|
|
494
|
-
_raf(() =>
|
|
485
|
+
_raf(() => inputElementRef.current?.focus())
|
|
495
486
|
},
|
|
496
|
-
[
|
|
487
|
+
[openButtonProps, dispatchOpen],
|
|
497
488
|
)
|
|
498
489
|
|
|
499
490
|
const openButtonNode = useMemo(
|
|
@@ -563,7 +554,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
563
554
|
prefix={prefix}
|
|
564
555
|
radius={radius}
|
|
565
556
|
readOnly={readOnly}
|
|
566
|
-
ref={
|
|
557
|
+
ref={inputElementRef}
|
|
567
558
|
role="combobox"
|
|
568
559
|
spellCheck={false}
|
|
569
560
|
suffix={suffix || openButtonNode}
|
|
@@ -575,10 +566,10 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
575
566
|
(event: KeyboardEvent<HTMLDivElement>) => {
|
|
576
567
|
// If the focus is currently in the list, move focus to the input element
|
|
577
568
|
if (event.key === 'Tab') {
|
|
578
|
-
if (listFocused)
|
|
569
|
+
if (listFocused) inputElementRef.current?.focus()
|
|
579
570
|
}
|
|
580
571
|
},
|
|
581
|
-
[
|
|
572
|
+
[listFocused],
|
|
582
573
|
)
|
|
583
574
|
|
|
584
575
|
const content = useMemo(() => {
|
|
@@ -644,11 +635,11 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
644
635
|
{
|
|
645
636
|
content,
|
|
646
637
|
hidden: !expanded,
|
|
647
|
-
inputElement,
|
|
638
|
+
inputElement: inputElementRef.current,
|
|
648
639
|
onMouseEnter: handlePopoverMouseEnter,
|
|
649
640
|
onMouseLeave: handlePopoverMouseLeave,
|
|
650
641
|
},
|
|
651
|
-
|
|
642
|
+
resultsPopoverElementRef,
|
|
652
643
|
)
|
|
653
644
|
}
|
|
654
645
|
|
|
@@ -670,8 +661,8 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
670
661
|
placement={AUTOCOMPLETE_POPOVER_PLACEMENT}
|
|
671
662
|
portal
|
|
672
663
|
radius={radius}
|
|
673
|
-
ref={
|
|
674
|
-
referenceElement={
|
|
664
|
+
ref={resultsPopoverElementRef}
|
|
665
|
+
referenceElement={inputElementRef.current}
|
|
675
666
|
{...popover}
|
|
676
667
|
/>
|
|
677
668
|
)
|
|
@@ -681,11 +672,9 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
681
672
|
filteredOptionsLen,
|
|
682
673
|
handlePopoverMouseEnter,
|
|
683
674
|
handlePopoverMouseLeave,
|
|
684
|
-
inputElement,
|
|
685
675
|
popover,
|
|
686
676
|
radius,
|
|
687
677
|
renderPopover,
|
|
688
|
-
resultsPopoverElement,
|
|
689
678
|
])
|
|
690
679
|
|
|
691
680
|
return (
|
|
@@ -694,7 +683,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
694
683
|
onBlur={handleRootBlur}
|
|
695
684
|
onFocus={handleRootFocus}
|
|
696
685
|
onKeyDown={handleRootKeyDown}
|
|
697
|
-
ref={
|
|
686
|
+
ref={rootElementRef}
|
|
698
687
|
>
|
|
699
688
|
{input}
|
|
700
689
|
{results}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
forwardRef,
|
|
4
|
+
Fragment,
|
|
5
|
+
isValidElement,
|
|
6
|
+
useCallback,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from 'react'
|
|
2
11
|
import {useArrayProp, useClickOutsideEvent} from '../../hooks'
|
|
3
12
|
import {Box, Popover, Stack, Text} from '../../primitives'
|
|
4
13
|
import {ExpandButton, Root} from './breadcrumbs.styles'
|
|
@@ -30,43 +39,46 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
|
|
|
30
39
|
|
|
31
40
|
useClickOutsideEvent(collapse, () => [expandElementRef.current, popoverElementRef.current])
|
|
32
41
|
|
|
33
|
-
const rawItems = Children.toArray(children).filter(isValidElement)
|
|
42
|
+
const rawItems = useMemo(() => Children.toArray(children).filter(isValidElement), [children])
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
const items = useMemo(() => {
|
|
45
|
+
const len = rawItems.length
|
|
37
46
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
if (maxLength && len > maxLength) {
|
|
48
|
+
const beforeLength = Math.ceil(maxLength / 2)
|
|
49
|
+
const afterLength = Math.floor(maxLength / 2)
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
51
|
+
return [
|
|
52
|
+
...rawItems.slice(0, beforeLength - 1),
|
|
53
|
+
<Popover
|
|
54
|
+
constrainSize
|
|
55
|
+
content={
|
|
56
|
+
<Stack as="ol" overflow="auto" padding={space} space={space}>
|
|
57
|
+
{rawItems.slice(beforeLength - 1, len - afterLength)}
|
|
58
|
+
</Stack>
|
|
59
|
+
}
|
|
60
|
+
key="button"
|
|
61
|
+
open={open}
|
|
62
|
+
placement="top"
|
|
63
|
+
portal
|
|
64
|
+
ref={popoverElementRef}
|
|
65
|
+
>
|
|
66
|
+
<ExpandButton
|
|
67
|
+
fontSize={1}
|
|
68
|
+
mode="bleed"
|
|
69
|
+
onClick={open ? collapse : expand}
|
|
70
|
+
padding={1}
|
|
71
|
+
ref={expandElementRef}
|
|
72
|
+
selected={open}
|
|
73
|
+
text="…"
|
|
74
|
+
/>
|
|
75
|
+
</Popover>,
|
|
76
|
+
...rawItems.slice(len - afterLength),
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return rawItems
|
|
81
|
+
}, [collapse, expand, maxLength, open, rawItems, space])
|
|
70
82
|
|
|
71
83
|
return (
|
|
72
84
|
<Root data-ui="Breadcrumbs" {...restProps} ref={ref}>
|
|
@@ -241,7 +241,7 @@ const DialogCard = forwardRef(function DialogCard(
|
|
|
241
241
|
<DialogLayout direction="column">
|
|
242
242
|
{showHeader && (
|
|
243
243
|
<DialogHeader>
|
|
244
|
-
<Flex align="
|
|
244
|
+
<Flex align="flex-start" padding={3}>
|
|
245
245
|
<Box flex={1} padding={2}>
|
|
246
246
|
{header && (
|
|
247
247
|
<Text id={labelId} size={1} weight="semibold">
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {CubeIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Card, LayerProvider, Menu, MenuItem} from '@sanity/ui'
|
|
3
|
+
import {THEME_COLOR_STATE_TONES} from '@sanity/ui/theme'
|
|
3
4
|
import {useBoolean, useSelect} from '@sanity/ui-workshop'
|
|
4
5
|
import {WORKSHOP_CARD_TONE_OPTIONS} from '../../../__workshop__/constants'
|
|
5
6
|
|
|
@@ -12,11 +13,9 @@ export default function TonesStory() {
|
|
|
12
13
|
<Box padding={[4, 5, 6]}>
|
|
13
14
|
<Card radius={3} shadow={3} tone={parentTone}>
|
|
14
15
|
<Menu>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<MenuItem disabled={disabled} icon={SearchIcon} text="Caution" tone="caution" />
|
|
19
|
-
<MenuItem disabled={disabled} icon={SearchIcon} text="Critical" tone="critical" />
|
|
16
|
+
{THEME_COLOR_STATE_TONES.map((tone) => (
|
|
17
|
+
<MenuItem disabled={disabled} icon={CubeIcon} key={tone} text={tone} tone={tone} />
|
|
18
|
+
))}
|
|
20
19
|
</Menu>
|
|
21
20
|
</Card>
|
|
22
21
|
</Box>
|