@sanity/ui 2.3.4-canary.0 → 2.3.4
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.esm.js +25 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +23 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +33 -25
- package/src/core/components/menu/__workshop__/customSelectedState.tsx +38 -0
- package/src/core/components/menu/__workshop__/index.ts +5 -0
- package/src/core/components/menu/menuButton.tsx +1 -1
- package/src/core/primitives/avatar/avatarStack.tsx +3 -2
- package/src/core/primitives/helpers.ts +11 -0
- package/src/core/primitives/inline/inline.tsx +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "2.3.4
|
|
3
|
+
"version": "2.3.4",
|
|
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
|
+
"prepublishOnly": "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"
|
|
@@ -167,6 +193,7 @@
|
|
|
167
193
|
"react-is": "^18",
|
|
168
194
|
"styled-components": "^5.2 || ^6"
|
|
169
195
|
},
|
|
196
|
+
"packageManager": "pnpm@9.2.0",
|
|
170
197
|
"engines": {
|
|
171
198
|
"node": ">=14.0.0"
|
|
172
199
|
},
|
|
@@ -176,28 +203,9 @@
|
|
|
176
203
|
"esm.sh": {
|
|
177
204
|
"bundle": false
|
|
178
205
|
},
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
"cypress:dev": "run-p dev cypress:open",
|
|
184
|
-
"cypress:open": "cypress open",
|
|
185
|
-
"cypress:run": "cypress run",
|
|
186
|
-
"dev": "run-p storybook:dev workshop:dev",
|
|
187
|
-
"figma:pkg:build": "cd figma && pnpm build",
|
|
188
|
-
"format": "prettier --write --cache --ignore-unknown .",
|
|
189
|
-
"lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
|
|
190
|
-
"pkg:build": "pkg build --strict",
|
|
191
|
-
"pkg:check": "pkg --strict",
|
|
192
|
-
"release": "semantic-release",
|
|
193
|
-
"storybook:build": "storybook build",
|
|
194
|
-
"storybook:dev": "storybook dev -p 6006",
|
|
195
|
-
"test": "jest",
|
|
196
|
-
"test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
|
|
197
|
-
"ts:check": "tsc",
|
|
198
|
-
"watch": "pkg watch --strict",
|
|
199
|
-
"workshop:build": "workshop build",
|
|
200
|
-
"workshop:dev": "workshop dev",
|
|
201
|
-
"workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
|
|
206
|
+
"pnpm": {
|
|
207
|
+
"overrides": {
|
|
208
|
+
"conventional-changelog-conventionalcommits": ">= 8.0.0"
|
|
209
|
+
}
|
|
202
210
|
}
|
|
203
|
-
}
|
|
211
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {ChevronDownIcon} from '@sanity/icons'
|
|
2
|
+
import {useSelect} from '@sanity/ui-workshop'
|
|
3
|
+
import {Box, Button} from '../../../primitives'
|
|
4
|
+
import {Menu} from '../menu'
|
|
5
|
+
import {MenuButton} from '../menuButton'
|
|
6
|
+
import {MenuItem} from '../menuItem'
|
|
7
|
+
|
|
8
|
+
const selectedOptions = {
|
|
9
|
+
undefined: 'undefined',
|
|
10
|
+
true: true,
|
|
11
|
+
false: false,
|
|
12
|
+
} as const
|
|
13
|
+
|
|
14
|
+
export default function CustomSelectedStateStory() {
|
|
15
|
+
const selected = useSelect('Selected', selectedOptions, false)
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Box padding={4}>
|
|
19
|
+
<MenuButton
|
|
20
|
+
button={
|
|
21
|
+
<Button
|
|
22
|
+
icon={ChevronDownIcon}
|
|
23
|
+
mode="bleed"
|
|
24
|
+
selected={selected === 'undefined' ? undefined : selected}
|
|
25
|
+
text="Menu"
|
|
26
|
+
/>
|
|
27
|
+
}
|
|
28
|
+
id="test-menu"
|
|
29
|
+
menu={
|
|
30
|
+
<Menu>
|
|
31
|
+
<MenuItem text="Item 1" />
|
|
32
|
+
<MenuItem text="Item 2" />
|
|
33
|
+
</Menu>
|
|
34
|
+
}
|
|
35
|
+
/>
|
|
36
|
+
</Box>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -80,5 +80,10 @@ export default defineScope({
|
|
|
80
80
|
title: 'Avatar menu',
|
|
81
81
|
component: lazy(() => import('./avatarMenu')),
|
|
82
82
|
},
|
|
83
|
+
{
|
|
84
|
+
name: 'custom-selected-state',
|
|
85
|
+
title: 'Custom selected state',
|
|
86
|
+
component: lazy(() => import('./customSelectedState')),
|
|
87
|
+
},
|
|
83
88
|
],
|
|
84
89
|
})
|
|
@@ -241,7 +241,7 @@ export const MenuButton = forwardRef(function MenuButton(
|
|
|
241
241
|
'aria-haspopup': true,
|
|
242
242
|
'aria-expanded': open,
|
|
243
243
|
ref: ref,
|
|
244
|
-
selected: open,
|
|
244
|
+
selected: buttonProp.props.selected ?? open,
|
|
245
245
|
}),
|
|
246
246
|
[buttonProp, handleButtonClick, handleButtonKeyDown, handleMouseDown, id, open],
|
|
247
247
|
)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {getTheme_v2} from '@sanity/ui/theme'
|
|
2
|
-
import {
|
|
2
|
+
import {cloneElement, forwardRef} from 'react'
|
|
3
3
|
import {styled, css} from 'styled-components'
|
|
4
4
|
import {EMPTY_RECORD} from '../../constants'
|
|
5
5
|
import {useArrayProp} from '../../hooks'
|
|
6
6
|
import {rem, _responsive, ThemeProps} from '../../styles'
|
|
7
7
|
import {AvatarSize} from '../../types'
|
|
8
|
+
import {childrenToElementArray} from '../helpers'
|
|
8
9
|
import {AvatarCounter} from './avatarCounter'
|
|
9
10
|
|
|
10
11
|
const BASE_STYLES = css`
|
|
@@ -65,7 +66,7 @@ export const AvatarStack = forwardRef(function AvatarStack(
|
|
|
65
66
|
size: sizeProp = 1,
|
|
66
67
|
...restProps
|
|
67
68
|
} = props
|
|
68
|
-
const children =
|
|
69
|
+
const children = childrenToElementArray(childrenProp).filter(
|
|
69
70
|
(child) => typeof child !== 'string',
|
|
70
71
|
) as React.ReactElement[]
|
|
71
72
|
const maxLength = Math.max(maxLengthProp, 0)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {isElement, isFragment} from 'react-is'
|
|
2
|
+
|
|
3
|
+
export function childrenToElementArray(
|
|
4
|
+
children: React.ReactNode,
|
|
5
|
+
): Array<React.ReactElement | string> {
|
|
6
|
+
const childrenArray = Array.isArray(children) ? children : [children]
|
|
7
|
+
|
|
8
|
+
return childrenArray.filter(
|
|
9
|
+
(node) => isElement(node) || isFragment(node) || typeof node === 'string',
|
|
10
|
+
) as Array<React.ReactElement | string>
|
|
11
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {forwardRef, useMemo
|
|
1
|
+
import {forwardRef, useMemo} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
3
|
import {useArrayProp} from '../../hooks'
|
|
4
4
|
import {Box, BoxProps} from '../box'
|
|
5
|
+
import {childrenToElementArray} from '../helpers'
|
|
5
6
|
import {inlineBaseStyle, inlineSpaceStyle} from './styles'
|
|
6
7
|
import {ResponsiveInlineSpaceStyleProps} from './types'
|
|
7
8
|
|
|
@@ -27,7 +28,10 @@ export const Inline = forwardRef(function Inline(
|
|
|
27
28
|
const {as, children: childrenProp, space, ...restProps} = props
|
|
28
29
|
|
|
29
30
|
const children = useMemo(
|
|
30
|
-
() =>
|
|
31
|
+
() =>
|
|
32
|
+
childrenToElementArray(childrenProp)
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.map((child, idx) => <div key={idx}>{child}</div>),
|
|
31
35
|
[childrenProp],
|
|
32
36
|
)
|
|
33
37
|
|