@sanity/ui 0.38.2 → 0.38.3-next.18
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/README.md +4 -5
- package/dist/sanity-ui.js +1 -1320
- package/dist/sanity-ui.js.map +1 -1
- package/dist/sanity-ui.mjs +2 -0
- package/dist/sanity-ui.mjs.map +1 -0
- package/dist/types/src/index.d.ts +228 -239
- package/package.json +23 -20
- package/src/__workshop__/color/overview.tsx +1 -1
- package/src/__workshop__/constants.ts +1 -0
- package/src/components/autocomplete/__workshop__/async.tsx +1 -1
- package/src/components/autocomplete/__workshop__/constrainedHeight.tsx +1 -1
- package/src/components/autocomplete/__workshop__/custom.tsx +1 -1
- package/src/components/autocomplete/__workshop__/example.tsx +1 -1
- package/src/components/autocomplete/__workshop__/focusAndBlur.tsx +1 -1
- package/src/components/autocomplete/__workshop__/fullscreen.tsx +1 -1
- package/src/components/autocomplete/autocomplete.tsx +31 -33
- package/src/components/autocomplete/autocompleteOption.tsx +1 -1
- package/src/components/autocomplete/autocompleteReducer.ts +0 -3
- package/src/components/breadcrumbs/__workshop__/example.tsx +0 -1
- package/src/components/breadcrumbs/breadcrumbs.tsx +1 -9
- package/src/components/dialog/__workshop__/autoFocus.tsx +0 -1
- package/src/components/dialog/__workshop__/layering.tsx +0 -1
- package/src/components/dialog/__workshop__/nested.tsx +1 -1
- package/src/components/dialog/__workshop__/onScroll.tsx +1 -1
- package/src/components/dialog/__workshop__/position.tsx +0 -1
- package/src/components/dialog/__workshop__/props.tsx +1 -1
- package/src/components/dialog/__workshop__/provider.tsx +0 -1
- package/src/components/dialog/dialog.tsx +1 -1
- package/src/components/dialog/dialogProvider.tsx +1 -1
- package/src/components/hotkeys/__workshop__/plain.tsx +0 -1
- package/src/components/hotkeys/hotkeys.tsx +1 -1
- package/src/components/menu/__workshop__/asComponent.tsx +1 -1
- package/src/components/menu/__workshop__/closableMenuButton.tsx +1 -1
- package/src/components/menu/__workshop__/constrainedInBoundary.tsx +1 -1
- package/src/components/menu/__workshop__/customMenuItem.tsx +0 -1
- package/src/components/menu/__workshop__/disableFocusOnClose.tsx +0 -1
- package/src/components/menu/__workshop__/groups.tsx +0 -1
- package/src/components/menu/__workshop__/menuButton.tsx +0 -1
- package/src/components/menu/__workshop__/menuGroupRight.tsx +0 -1
- package/src/components/menu/__workshop__/nestedMenu.tsx +0 -1
- package/src/components/menu/__workshop__/onCloseMenuButton.tsx +1 -1
- package/src/components/menu/__workshop__/selectedItem.tsx +1 -1
- package/src/components/menu/__workshop__/tones.tsx +0 -1
- package/src/components/menu/__workshop__/withoutArrow.tsx +0 -1
- package/src/components/menu/menu.test.tsx +3 -4
- package/src/components/menu/menu.tsx +1 -1
- package/src/components/menu/menuButton.tsx +1 -9
- package/src/components/menu/menuGroup.tsx +2 -2
- package/src/components/menu/menuItem.tsx +3 -3
- package/src/components/menu/useMenuController.ts +1 -1
- package/src/components/skeleton/__workshop__/delay.tsx +0 -1
- package/src/components/skeleton/__workshop__/skeleton.tsx +0 -1
- package/src/components/skeleton/skeleton.tsx +1 -1
- package/src/components/skeleton/textSkeleton.tsx +1 -1
- package/src/components/tab/__workshop__/example.tsx +1 -1
- package/src/components/tab/tab.tsx +2 -2
- package/src/components/tab/tabList.tsx +1 -1
- package/src/components/tab/tabPanel.tsx +1 -1
- package/src/components/toast/__workshop__/hook.tsx +0 -1
- package/src/components/toast/__workshop__/toast.tsx +0 -1
- package/src/components/toast/toast.test.tsx +3 -5
- package/src/components/toast/toast.tsx +0 -1
- package/src/components/toast/toastProvider.tsx +1 -1
- package/src/components/tree/__workshop__/basic.tsx +1 -1
- package/src/components/tree/tree.tsx +1 -1
- package/src/components/tree/treeGroup.tsx +1 -1
- package/src/components/tree/treeItem.tsx +4 -4
- package/src/hooks/useElementRect/__workshop__/example.tsx +0 -1
- package/src/hooks/useForwardedRef.ts +1 -1
- package/src/hooks/useMediaIndex/__workshop__/test.tsx +0 -1
- package/src/icons/__workshop__/overview.tsx +1 -1
- package/src/primitives/avatar/__workshop__/asButton.tsx +0 -1
- package/src/primitives/avatar/__workshop__/stack.tsx +0 -1
- package/src/primitives/avatar/avatar.tsx +2 -3
- package/src/primitives/avatar/avatarCounter.tsx +1 -1
- package/src/primitives/avatar/avatarStack.tsx +1 -1
- package/src/primitives/badge/__workshop__/props.tsx +0 -1
- package/src/primitives/badge/__workshop__/tones.tsx +0 -1
- package/src/primitives/badge/badge.test.tsx +13 -0
- package/src/primitives/badge/badge.tsx +1 -1
- package/src/primitives/box/__workshop__/props.tsx +0 -1
- package/src/primitives/box/__workshop__/responsive.tsx +0 -1
- package/src/primitives/box/box.tsx +1 -1
- package/src/primitives/button/__workshop__/custom.tsx +0 -1
- package/src/primitives/button/__workshop__/customIcons.tsx +0 -1
- package/src/primitives/button/__workshop__/mixedChildren.tsx +0 -1
- package/src/primitives/button/__workshop__/props.tsx +0 -1
- package/src/primitives/button/__workshop__/sanityUploadButton.tsx +0 -1
- package/src/primitives/button/__workshop__/stacked.tsx +0 -1
- package/src/primitives/button/__workshop__/styled1.tsx +0 -1
- package/src/primitives/button/__workshop__/styled2.tsx +0 -1
- package/src/primitives/button/__workshop__/uploadButton.tsx +1 -1
- package/src/primitives/button/button.test.tsx +41 -0
- package/src/primitives/button/button.tsx +3 -3
- package/src/primitives/card/__workshop__/allTones.tsx +0 -1
- package/src/primitives/card/__workshop__/asButton.tsx +0 -1
- package/src/primitives/card/__workshop__/asComponent.tsx +1 -1
- package/src/primitives/card/__workshop__/checkered.tsx +0 -1
- package/src/primitives/card/__workshop__/interactive.tsx +0 -1
- package/src/primitives/card/__workshop__/listNavigation.tsx +0 -1
- package/src/primitives/card/__workshop__/props.tsx +0 -1
- package/src/primitives/card/__workshop__/selected.tsx +0 -1
- package/src/primitives/card/__workshop__/styled.tsx +0 -1
- package/src/primitives/card/card.tsx +1 -1
- package/src/primitives/checkbox/__workshop__/example.tsx +1 -1
- package/src/primitives/checkbox/__workshop__/props.tsx +0 -1
- package/src/primitives/checkbox/__workshop__/readOnly.tsx +0 -1
- package/src/primitives/checkbox/__workshop__/tones.tsx +0 -1
- package/src/primitives/checkbox/checkbox.tsx +1 -1
- package/src/primitives/code/__workshop__/opticalAlignment.tsx +0 -1
- package/src/primitives/code/__workshop__/props.tsx +0 -1
- package/src/primitives/code/code.tsx +1 -1
- package/src/primitives/container/__workshop__/example.tsx +0 -1
- package/src/primitives/container/container.tsx +1 -1
- package/src/primitives/flex/__workshop__/example.tsx +0 -1
- package/src/primitives/flex/__workshop__/gap.tsx +0 -1
- package/src/primitives/flex/flex.tsx +1 -1
- package/src/primitives/grid/__workshop__/responsive.tsx +0 -1
- package/src/primitives/grid/grid.tsx +1 -1
- package/src/primitives/heading/__workshop__/opticalAlignment.tsx +0 -1
- package/src/primitives/heading/__workshop__/plain.tsx +0 -1
- package/src/primitives/heading/heading.tsx +1 -1
- package/src/primitives/inline/__workshop__/plain.tsx +0 -1
- package/src/primitives/inline/inline.tsx +1 -1
- package/src/primitives/kbd/__workshop__/plain.tsx +0 -1
- package/src/primitives/kbd/kbd.tsx +1 -1
- package/src/primitives/label/__workshop__/opticalAlignment.tsx +0 -1
- package/src/primitives/label/__workshop__/plain.tsx +0 -1
- package/src/primitives/label/label.tsx +1 -1
- package/src/primitives/popover/__workshop__/MarginsStory.tsx +0 -1
- package/src/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +0 -1
- package/src/primitives/popover/__workshop__/PlainStory.tsx +1 -1
- package/src/primitives/popover/__workshop__/RecursiveStory.tsx +1 -1
- package/src/primitives/popover/__workshop__/RightAlignedStory.tsx +1 -1
- package/src/primitives/popover/__workshop__/TestStory.tsx +1 -1
- package/src/primitives/popover/arrow.tsx +1 -1
- package/src/primitives/popover/popover.tsx +1 -9
- package/src/primitives/radio/__workshop__/example.tsx +1 -1
- package/src/primitives/radio/__workshop__/plain.tsx +0 -1
- package/src/primitives/radio/radio.tsx +1 -1
- package/src/primitives/select/__workshop__/plain.tsx +0 -1
- package/src/primitives/select/__workshop__/readOnly.tsx +0 -1
- package/src/primitives/select/select.tsx +1 -1
- package/src/primitives/spinner/__workshop__/Props.tsx +0 -1
- package/src/primitives/spinner/spinner.tsx +1 -1
- package/src/primitives/stack/__workshop__/plain.tsx +0 -1
- package/src/primitives/stack/stack.tsx +1 -1
- package/src/primitives/switch/__workshop__/example.tsx +1 -1
- package/src/primitives/switch/__workshop__/props.tsx +1 -1
- package/src/primitives/switch/switch.tsx +1 -1
- package/src/primitives/text/__workshop__/colored.tsx +0 -1
- package/src/primitives/text/__workshop__/example.tsx +0 -1
- package/src/primitives/text/__workshop__/opticalAlignment.tsx +0 -1
- package/src/primitives/text/text.tsx +1 -1
- package/src/primitives/textArea/__workshop__/plain.tsx +0 -1
- package/src/primitives/textArea/textArea.tsx +1 -1
- package/src/primitives/textInput/__workshop__/clearButton.tsx +1 -1
- package/src/primitives/textInput/__workshop__/customValidity.tsx +0 -1
- package/src/primitives/textInput/__workshop__/multipleTones.tsx +0 -1
- package/src/primitives/textInput/__workshop__/plain.tsx +1 -1
- package/src/primitives/textInput/__workshop__/readOnly.tsx +0 -1
- package/src/primitives/textInput/__workshop__/states.tsx +0 -1
- package/src/primitives/textInput/__workshop__/tones.tsx +0 -1
- package/src/primitives/textInput/__workshop__/typed.tsx +1 -1
- package/src/primitives/textInput/textInput.tsx +4 -3
- package/src/primitives/tooltip/__workshop__/props.tsx +0 -1
- package/src/primitives/tooltip/tooltip.tsx +1 -1
- package/src/primitives/tooltip/tooltipArrow.tsx +1 -1
- package/src/styles/font/responsiveFont.ts +13 -0
- package/src/theme/__workshop__/canvas.tsx +1 -1
- package/src/theme/__workshop__/color.tsx +0 -1
- package/src/theme/__workshop__/layer.tsx +1 -1
- package/src/theme/__workshop__/nestedProvider.tsx +0 -1
- package/src/theme/theme.test.tsx +3 -5
- package/src/theme/themeColorProvider.tsx +0 -1
- package/src/theme/themeProvider.tsx +1 -1
- package/src/utils/boundaryElement/__workshop__/plain.tsx +1 -1
- package/src/utils/boundaryElement/boundaryElement.test.tsx +3 -5
- package/src/utils/boundaryElement/boundaryElementProvider.tsx +1 -1
- package/src/utils/elementQuery/__workshop__/customMedia.tsx +0 -1
- package/src/utils/elementQuery/elementQuery.tsx +1 -1
- package/src/utils/errorBoundary.tsx +4 -4
- package/src/utils/layer/__workshop__/_debug.tsx +0 -1
- package/src/utils/layer/__workshop__/multipleRoots.tsx +0 -1
- package/src/utils/layer/__workshop__/plain.tsx +1 -1
- package/src/utils/layer/__workshop__/responsiveZOffset.tsx +0 -1
- package/src/utils/layer/layer.test.tsx +3 -5
- package/src/utils/layer/layer.tsx +1 -1
- package/src/utils/layer/layerProvider.tsx +1 -1
- package/src/utils/portal/__workshop__/named.tsx +1 -1
- package/src/utils/portal/portal.test.tsx +3 -5
- package/src/utils/portal/portal.ts +2 -3
- package/src/utils/portal/portalProvider.tsx +1 -1
- package/src/utils/srOnly/srOnly.tsx +1 -1
- package/src/utils/virtualList/__workshop__/changingProps.tsx +1 -1
- package/src/utils/virtualList/__workshop__/elementScroll.tsx +1 -1
- package/src/utils/virtualList/__workshop__/infiniteList.tsx +1 -1
- package/src/utils/virtualList/__workshop__/windowScrolll.tsx +1 -1
- package/src/utils/virtualList/virtualList.tsx +1 -1
- package/dist/sanity-ui.cjs +0 -1321
- package/dist/sanity-ui.cjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.3-next.18+f1216ee3",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"source": "./src/index.ts",
|
|
6
|
-
"module": "./dist/sanity-ui.js",
|
|
7
5
|
"types": "./dist/types/src/index.d.ts",
|
|
8
|
-
"
|
|
6
|
+
"source": "./src/index.ts",
|
|
7
|
+
"module": "./dist/sanity-ui.mjs",
|
|
8
|
+
"main": "./dist/sanity-ui.js",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/types/src/index.d.ts",
|
|
12
12
|
"source": "./src/index.ts",
|
|
13
|
-
"import": "./dist/sanity-ui.
|
|
14
|
-
"require": "./dist/sanity-ui.
|
|
15
|
-
"default": "./dist/sanity-ui.
|
|
13
|
+
"import": "./dist/sanity-ui.mjs",
|
|
14
|
+
"require": "./dist/sanity-ui.js",
|
|
15
|
+
"default": "./dist/sanity-ui.mjs"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
@@ -27,33 +27,36 @@
|
|
|
27
27
|
"lint": "eslint . --ext .js,.jsx,.mjs,.ts,.tsx --quiet",
|
|
28
28
|
"postbuild": "run-s check:package",
|
|
29
29
|
"prebuild": "run-s clean",
|
|
30
|
-
"test": "
|
|
30
|
+
"test": "jest",
|
|
31
31
|
"type-check": "tsc --build",
|
|
32
32
|
"watch": "pkg watch --tsconfig tsconfig.dist.json"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@juggle/resize-observer": "^3.4.0",
|
|
36
35
|
"@popperjs/core": "^2.11.6",
|
|
37
|
-
"@
|
|
38
|
-
"@sanity/
|
|
39
|
-
"
|
|
40
|
-
"framer-motion": "6.3.0",
|
|
36
|
+
"@sanity/color": "2.1.17-next.18+f1216ee3",
|
|
37
|
+
"@sanity/icons": "1.3.7-next.18+f1216ee3",
|
|
38
|
+
"framer-motion": "^7.3.5",
|
|
41
39
|
"popper-max-size-modifier": "^0.2.0",
|
|
42
|
-
"react-is": "^
|
|
40
|
+
"react-is": "^18.2.0",
|
|
43
41
|
"react-popper": "^2.3.0",
|
|
44
42
|
"react-refractor": "^2.1.7"
|
|
45
43
|
},
|
|
46
44
|
"devDependencies": {
|
|
45
|
+
"@floating-ui/react-dom": "^1.0.0",
|
|
46
|
+
"@juggle/resize-observer": "^3.4.0",
|
|
47
47
|
"@testing-library/dom": "^8.17.1",
|
|
48
|
-
"@testing-library/
|
|
48
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
49
|
+
"@testing-library/react": "^13.4.0",
|
|
49
50
|
"@types/refractor": "^3.0.2",
|
|
50
|
-
"
|
|
51
|
-
"react
|
|
51
|
+
"framer-motion": "^7.3.5",
|
|
52
|
+
"react": "^18.2.0",
|
|
53
|
+
"react-dom": "^18.2.0",
|
|
54
|
+
"react-refractor": "^2.1.7",
|
|
52
55
|
"styled-components": "^5.3.5"
|
|
53
56
|
},
|
|
54
57
|
"peerDependencies": {
|
|
55
|
-
"react": "^
|
|
56
|
-
"react-dom": "^
|
|
58
|
+
"react": "^18",
|
|
59
|
+
"react-dom": "^18",
|
|
57
60
|
"styled-components": "^5.2"
|
|
58
61
|
},
|
|
59
62
|
"repository": {
|
|
@@ -73,5 +76,5 @@
|
|
|
73
76
|
"publishConfig": {
|
|
74
77
|
"access": "public"
|
|
75
78
|
},
|
|
76
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "f1216ee3ef45b3710598c841bda1b3fc47ea97ac"
|
|
77
80
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {black, ColorTints, ColorValue, COLOR_HUES, hues, white} from '@sanity/color'
|
|
2
2
|
import {Box, Card, Code, Flex, Grid, Heading, Stack, useToast} from '@sanity/ui'
|
|
3
|
-
import
|
|
3
|
+
import {useCallback} from 'react'
|
|
4
4
|
import {hexToRgb, rgbToHsl} from '../../theme'
|
|
5
5
|
|
|
6
6
|
function ucfirst(str: string) {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
Stack,
|
|
11
11
|
Text,
|
|
12
12
|
} from '@sanity/ui'
|
|
13
|
-
import
|
|
13
|
+
import {useCallback, useEffect, useRef, useState} from 'react'
|
|
14
14
|
import {countriesStore} from '../__mocks__/apiStore'
|
|
15
15
|
|
|
16
16
|
export default function AsyncStory() {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
Stack,
|
|
8
8
|
Text,
|
|
9
9
|
} from '@sanity/ui'
|
|
10
|
-
import
|
|
10
|
+
import {useCallback, useState} from 'react'
|
|
11
11
|
import {Popover} from '../../../primitives'
|
|
12
12
|
import countries from '../__fixtures__/countries'
|
|
13
13
|
import {AutocompleteProps} from '../autocomplete'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Autocomplete, Box, Button, Card, Code, Stack, Text} from '@sanity/ui'
|
|
2
2
|
import {useBoolean, useSelect} from '@sanity/ui-workshop'
|
|
3
|
-
import
|
|
3
|
+
import {useCallback, useState} from 'react'
|
|
4
4
|
import {
|
|
5
5
|
WORKSHOP_RADIUS_OPTIONS,
|
|
6
6
|
WORKSHOP_SPACE_OPTIONS,
|
|
@@ -2,7 +2,7 @@ import {Autocomplete, Box, Card, Container, Stack, Text} from '@sanity/ui'
|
|
|
2
2
|
import {useBoolean, useSelect, useText} from '@sanity/ui-workshop'
|
|
3
3
|
import {PerfTestProps, usePerfTest} from '@sanity/ui-workshop'
|
|
4
4
|
import {fireEvent} from '@testing-library/dom'
|
|
5
|
-
import
|
|
5
|
+
import {useCallback, useMemo, useState} from 'react'
|
|
6
6
|
import {
|
|
7
7
|
WORKSHOP_CARD_TONE_OPTIONS,
|
|
8
8
|
WORKSHOP_RADIUS_OPTIONS,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
useToast,
|
|
19
19
|
} from '@sanity/ui'
|
|
20
20
|
import {useBoolean} from '@sanity/ui-workshop'
|
|
21
|
-
import
|
|
21
|
+
import {useCallback, useEffect, useMemo, useRef, useState} from 'react'
|
|
22
22
|
import {countriesStore} from '../__mocks__/apiStore'
|
|
23
23
|
|
|
24
24
|
export default function Fullscreen() {
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import {ChevronDownIcon} from '@sanity/icons'
|
|
2
|
-
import
|
|
3
|
-
cloneElement,
|
|
4
|
-
forwardRef,
|
|
5
|
-
useCallback,
|
|
6
|
-
useEffect,
|
|
7
|
-
useMemo,
|
|
8
|
-
useReducer,
|
|
9
|
-
useRef,
|
|
10
|
-
useState,
|
|
11
|
-
} from 'react'
|
|
2
|
+
import {cloneElement, forwardRef, useCallback, useEffect, useMemo, useReducer, useRef} from 'react'
|
|
12
3
|
import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
|
|
13
4
|
import {_hasFocus, _raf, focusFirstDescendant} from '../../helpers'
|
|
14
5
|
import {useForwardedRef, useArrayProp} from '../../hooks'
|
|
@@ -32,7 +23,7 @@ export interface AutocompleteProps<Option extends BaseAutocompleteOption = BaseA
|
|
|
32
23
|
customValidity?: string
|
|
33
24
|
filterOption?: (query: string, option: Option) => boolean
|
|
34
25
|
fontSize?: number | number[]
|
|
35
|
-
icon?: React.
|
|
26
|
+
icon?: React.ElementType | React.ReactNode
|
|
36
27
|
id: string
|
|
37
28
|
/**
|
|
38
29
|
* @beta
|
|
@@ -164,15 +155,21 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
164
155
|
typeof renderOptionProp === 'function' ? renderOptionProp : defaultRenderOption
|
|
165
156
|
const filterOption =
|
|
166
157
|
typeof filterOptionProp === 'function' ? filterOptionProp : defaultFilterOption
|
|
167
|
-
|
|
168
|
-
|
|
158
|
+
|
|
159
|
+
// Element refs
|
|
160
|
+
const rootElementRef = useRef<HTMLDivElement | null>(null)
|
|
161
|
+
const resultsPopoverElementRef = useRef<HTMLDivElement | null>(null)
|
|
169
162
|
const inputElementRef = useRef<HTMLInputElement | null>(null)
|
|
170
163
|
const listBoxElementRef = useRef<HTMLDivElement | null>(null)
|
|
171
|
-
|
|
164
|
+
|
|
165
|
+
// Value refs
|
|
166
|
+
const listFocusedRef = useRef(false)
|
|
172
167
|
const valueRef = useRef(value)
|
|
173
168
|
const valuePropRef = useRef(valueProp)
|
|
174
|
-
const forwardedRef = useForwardedRef(ref)
|
|
175
169
|
const popoverMouseWithinRef = useRef(false)
|
|
170
|
+
|
|
171
|
+
const forwardedRef = useForwardedRef(ref)
|
|
172
|
+
|
|
176
173
|
const listBoxId = `${id}-listbox`
|
|
177
174
|
const options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY
|
|
178
175
|
const padding = useArrayProp(paddingProp)
|
|
@@ -199,8 +196,8 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
199
196
|
}
|
|
200
197
|
|
|
201
198
|
const elements: HTMLElement[] = (relatedElements || []).concat(
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
rootElementRef.current ? [rootElementRef.current] : [],
|
|
200
|
+
resultsPopoverElementRef.current ? [resultsPopoverElementRef.current] : []
|
|
204
201
|
)
|
|
205
202
|
|
|
206
203
|
let focusInside = false
|
|
@@ -222,20 +219,19 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
222
219
|
}
|
|
223
220
|
}, 0)
|
|
224
221
|
},
|
|
225
|
-
[onBlur, onQueryChange, relatedElements
|
|
222
|
+
[onBlur, onQueryChange, relatedElements]
|
|
226
223
|
)
|
|
227
224
|
|
|
228
225
|
const handleRootFocus = useCallback((event: React.FocusEvent) => {
|
|
229
226
|
const listBoxElement = listBoxElementRef.current
|
|
230
227
|
const focusedElement = event.target instanceof HTMLElement ? event.target : null
|
|
228
|
+
const listFocused = listBoxElement?.contains(focusedElement) || false
|
|
231
229
|
|
|
232
|
-
|
|
230
|
+
if (listFocused !== listFocusedRef.current) {
|
|
231
|
+
listFocusedRef.current = listFocused
|
|
233
232
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
dispatch({type: 'root/setListFocused', listFocused: nextListFocused})
|
|
233
|
+
dispatch({type: 'root/setListFocused', listFocused})
|
|
234
|
+
}
|
|
239
235
|
}, [])
|
|
240
236
|
|
|
241
237
|
const handleOptionSelect = useCallback(
|
|
@@ -363,6 +359,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
363
359
|
|
|
364
360
|
// Change the value when `value` prop changes
|
|
365
361
|
useEffect(() => {
|
|
362
|
+
// If `valueProp` changed
|
|
366
363
|
if (valueProp !== valuePropRef.current) {
|
|
367
364
|
valuePropRef.current = valueProp
|
|
368
365
|
|
|
@@ -374,17 +371,18 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
374
371
|
return
|
|
375
372
|
}
|
|
376
373
|
|
|
377
|
-
|
|
374
|
+
// If `valueProp` is not equal to `value`
|
|
375
|
+
if (valueProp !== valueRef.current) {
|
|
376
|
+
valueRef.current = valueProp || null
|
|
377
|
+
|
|
378
378
|
dispatch({type: 'value/change', value: valueProp || null})
|
|
379
379
|
}
|
|
380
|
-
}, [valueProp
|
|
380
|
+
}, [valueProp])
|
|
381
381
|
|
|
382
382
|
// Reset active item when closing
|
|
383
383
|
useEffect(() => {
|
|
384
|
-
if (!focused) {
|
|
385
|
-
|
|
386
|
-
dispatch({type: 'root/setActiveValue', value: valueRef.current})
|
|
387
|
-
}
|
|
384
|
+
if (!focused && valueRef.current) {
|
|
385
|
+
dispatch({type: 'root/setActiveValue', value: valueRef.current})
|
|
388
386
|
}
|
|
389
387
|
}, [focused])
|
|
390
388
|
|
|
@@ -623,7 +621,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
623
621
|
onMouseEnter: handlePopoverMouseEnter,
|
|
624
622
|
onMouseLeave: handlePopoverMouseLeave,
|
|
625
623
|
},
|
|
626
|
-
|
|
624
|
+
resultsPopoverElementRef
|
|
627
625
|
)
|
|
628
626
|
}
|
|
629
627
|
|
|
@@ -645,7 +643,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
645
643
|
placement={AUTOCOMPLETE_POPOVER_PLACEMENT}
|
|
646
644
|
portal
|
|
647
645
|
radius={radius}
|
|
648
|
-
ref={
|
|
646
|
+
ref={resultsPopoverElementRef}
|
|
649
647
|
referenceElement={inputElementRef.current}
|
|
650
648
|
{...popover}
|
|
651
649
|
/>
|
|
@@ -667,7 +665,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
|
|
|
667
665
|
onBlur={handleRootBlur}
|
|
668
666
|
onFocus={handleRootFocus}
|
|
669
667
|
onKeyDown={handleRootKeyDown}
|
|
670
|
-
ref={
|
|
668
|
+
ref={rootElementRef}
|
|
671
669
|
>
|
|
672
670
|
{input}
|
|
673
671
|
{results}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
Children,
|
|
3
|
-
forwardRef,
|
|
4
|
-
Fragment,
|
|
5
|
-
isValidElement,
|
|
6
|
-
useCallback,
|
|
7
|
-
useMemo,
|
|
8
|
-
useState,
|
|
9
|
-
} from 'react'
|
|
1
|
+
import {Children, forwardRef, Fragment, isValidElement, useCallback, useMemo, useState} from 'react'
|
|
10
2
|
import {useArrayProp, useClickOutside} from '../../hooks'
|
|
11
3
|
import {Box, Popover, Stack, Text} from '../../primitives'
|
|
12
4
|
import {ExpandButton, Root} from './breadcrumbs.styles'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Box, Dialog, LayerProvider, Text} from '@sanity/ui'
|
|
2
2
|
import {useAction} from '@sanity/ui-workshop'
|
|
3
|
-
import
|
|
3
|
+
import {useEffect, useRef} from 'react'
|
|
4
4
|
|
|
5
5
|
export default function OnScrollStory() {
|
|
6
6
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {ArrowDownIcon, ArrowUpIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Dialog, LayerProvider, Stack, Text} from '@sanity/ui'
|
|
3
3
|
import {useBoolean, useSelect} from '@sanity/ui-workshop'
|
|
4
|
-
import React from 'react'
|
|
5
4
|
import {WORKSHOP_DIALOG_POSITION_OPTIONS} from '../../../__workshop__/constants'
|
|
6
5
|
|
|
7
6
|
export default function PositionStory() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Box, Button, Dialog, LayerProvider, Stack, Text} from '@sanity/ui'
|
|
2
2
|
import {useBoolean, useSelect, useText} from '@sanity/ui-workshop'
|
|
3
|
-
import
|
|
3
|
+
import {useCallback, useRef, useState} from 'react'
|
|
4
4
|
import {WORKSHOP_WIDTH_OPTIONS} from '../../../__workshop__/constants'
|
|
5
5
|
|
|
6
6
|
export default function PropsStory() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {CloseIcon} from '@sanity/icons'
|
|
2
|
-
import
|
|
2
|
+
import {forwardRef, useCallback, useEffect, useRef, useState} from 'react'
|
|
3
3
|
import styled from 'styled-components'
|
|
4
4
|
import {focusFirstDescendant, focusLastDescendant} from '../../helpers'
|
|
5
5
|
import {useArrayProp, useClickOutside, useForwardedRef, useGlobalKeyDown} from '../../hooks'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Button, Flex, Menu, MenuButton, MenuItem, Text} from '@sanity/ui'
|
|
2
|
-
import
|
|
2
|
+
import {forwardRef} from 'react'
|
|
3
3
|
|
|
4
4
|
const CustomLink = forwardRef(function CustomLink(
|
|
5
5
|
props: {req: string} & Omit<React.HTMLProps<HTMLAnchorElement>, 'as' | 'href'>,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {AddIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Button, Menu, MenuButton, MenuItem, Stack} from '@sanity/ui'
|
|
3
|
-
import
|
|
3
|
+
import {useRef} from 'react'
|
|
4
4
|
|
|
5
5
|
export default function ClosableMenuButtonStory() {
|
|
6
6
|
const ref = useRef<HTMLButtonElement | null>(null)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {SelectIcon} from '@sanity/icons'
|
|
2
2
|
import {Button, Flex, Menu, MenuButton, MenuItem} from '@sanity/ui'
|
|
3
3
|
import {useBoolean} from '@sanity/ui-workshop'
|
|
4
|
-
import React from 'react'
|
|
5
4
|
|
|
6
5
|
export default function DisableFocusOnCloseStory() {
|
|
7
6
|
const disableRestoreFocusOnClose = useBoolean('Disable restore focus on close', false)
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
MenuItem,
|
|
12
12
|
} from '@sanity/ui'
|
|
13
13
|
import {useAction, useBoolean, useSelect} from '@sanity/ui-workshop'
|
|
14
|
-
import React from 'react'
|
|
15
14
|
import {WORKSHOP_CARD_TONE_OPTIONS} from '../../../__workshop__/constants'
|
|
16
15
|
|
|
17
16
|
export default function MenuButtonStory() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {CheckmarkIcon, ClockIcon, ExpandIcon, SearchIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Button, Code, Menu, MenuButton, MenuDivider, MenuItem, Stack} from '@sanity/ui'
|
|
3
|
-
import
|
|
3
|
+
import {useState} from 'react'
|
|
4
4
|
|
|
5
5
|
export default function SelectedItemStory() {
|
|
6
6
|
const [selectedIndex, setSelectedIndex] = useState(0)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {SearchIcon} from '@sanity/icons'
|
|
2
2
|
import {Box, Card, LayerProvider, Menu, MenuItem} from '@sanity/ui'
|
|
3
3
|
import {useBoolean, useSelect} from '@sanity/ui-workshop'
|
|
4
|
-
import React from 'react'
|
|
5
4
|
import {WORKSHOP_CARD_TONE_OPTIONS} from '../../../__workshop__/constants'
|
|
6
5
|
|
|
7
6
|
export default function TonesStory() {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
|
|
3
3
|
import React, {useCallback, useMemo} from 'react'
|
|
4
|
-
import {vi} from 'vitest'
|
|
5
4
|
import {render} from '../../../test'
|
|
6
5
|
import {MenuContext, MenuContextValue} from './menuContext'
|
|
7
6
|
import {useMenu} from './useMenu'
|
|
@@ -9,7 +8,7 @@ import {useMenu} from './useMenu'
|
|
|
9
8
|
describe('components/menu', () => {
|
|
10
9
|
describe('useMenu', () => {
|
|
11
10
|
it('should get context value', async () => {
|
|
12
|
-
const log =
|
|
11
|
+
const log = jest.fn()
|
|
13
12
|
|
|
14
13
|
function Debug() {
|
|
15
14
|
const rootMenu = useMenu()
|
|
@@ -65,7 +64,7 @@ describe('components/menu', () => {
|
|
|
65
64
|
})
|
|
66
65
|
|
|
67
66
|
it('should fail when no context value is provided', async () => {
|
|
68
|
-
const log =
|
|
67
|
+
const log = jest.fn()
|
|
69
68
|
|
|
70
69
|
function Debug() {
|
|
71
70
|
try {
|
|
@@ -94,7 +93,7 @@ describe('components/menu', () => {
|
|
|
94
93
|
})
|
|
95
94
|
|
|
96
95
|
it('should fail when context value is not compatible', async () => {
|
|
97
|
-
const log =
|
|
96
|
+
const log = jest.fn()
|
|
98
97
|
|
|
99
98
|
function Debug() {
|
|
100
99
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {forwardRef, useCallback, useEffect, useMemo} from 'react'
|
|
2
2
|
import styled from 'styled-components'
|
|
3
3
|
import {useClickOutside, useForwardedRef, useGlobalKeyDown} from '../../hooks'
|
|
4
4
|
import {Box, Stack} from '../../primitives'
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
cloneElement,
|
|
3
|
-
forwardRef,
|
|
4
|
-
useCallback,
|
|
5
|
-
useMemo,
|
|
6
|
-
useState,
|
|
7
|
-
useEffect,
|
|
8
|
-
useRef,
|
|
9
|
-
} from 'react'
|
|
1
|
+
import {cloneElement, forwardRef, useCallback, useMemo, useState, useEffect, useRef} from 'react'
|
|
10
2
|
import {isElement} from 'react-is'
|
|
11
3
|
import {Popover, PopoverProps} from '../../primitives'
|
|
12
4
|
import {ThemeColorSchemeKey} from '../../theme'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ChevronRightIcon} from '@sanity/icons'
|
|
2
|
-
import
|
|
2
|
+
import {createElement, isValidElement, useCallback, useEffect, useRef, useState} from 'react'
|
|
3
3
|
import {isValidElementType} from 'react-is'
|
|
4
4
|
import {useArrayProp} from '../../hooks'
|
|
5
5
|
import {Box, Flex, Popover, PopoverProps, Text} from '../../primitives'
|
|
@@ -14,7 +14,7 @@ import {useMenu} from './useMenu'
|
|
|
14
14
|
export interface MenuGroupProps {
|
|
15
15
|
as?: React.ElementType | keyof JSX.IntrinsicElements
|
|
16
16
|
fontSize?: number | number[]
|
|
17
|
-
icon?: React.
|
|
17
|
+
icon?: React.ElementType | React.ReactNode
|
|
18
18
|
padding?: number | number[]
|
|
19
19
|
popover?: Omit<PopoverProps, 'content' | 'open'>
|
|
20
20
|
radius?: number | number[]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
2
|
createElement,
|
|
3
3
|
forwardRef,
|
|
4
4
|
isValidElement,
|
|
@@ -23,8 +23,8 @@ export interface MenuItemProps extends ResponsivePaddingProps, ResponsiveRadiusP
|
|
|
23
23
|
as?: React.ElementType | keyof JSX.IntrinsicElements
|
|
24
24
|
fontSize?: number | number[]
|
|
25
25
|
hotkeys?: string[]
|
|
26
|
-
icon?: React.
|
|
27
|
-
iconRight?: React.
|
|
26
|
+
icon?: React.ElementType | React.ReactNode
|
|
27
|
+
iconRight?: React.ElementType | React.ReactNode
|
|
28
28
|
pressed?: boolean
|
|
29
29
|
selected?: boolean
|
|
30
30
|
space?: number | number[]
|