@sanity/ui 0.37.14-next.6 → 0.37.16
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/lib/dts/src/components/autocomplete/autocomplete.styles.d.ts +1 -1
- package/lib/dts/src/components/autocomplete/autocomplete.styles.d.ts.map +1 -1
- package/lib/dts/src/components/autocomplete/constants.d.ts.map +1 -1
- package/lib/dts/src/constants.d.ts +0 -10
- package/lib/dts/src/constants.d.ts.map +1 -1
- package/lib/dts/src/primitives/popover/{popoverArrow.d.ts → arrow.d.ts} +1 -1
- package/lib/dts/src/primitives/popover/arrow.d.ts.map +1 -0
- package/lib/dts/src/primitives/popover/modifiers/getPopoverModifiers.d.ts +4 -0
- package/lib/dts/src/primitives/popover/modifiers/getPopoverModifiers.d.ts.map +1 -0
- package/lib/dts/src/primitives/popover/modifiers/index.d.ts +2 -0
- package/lib/dts/src/primitives/popover/modifiers/index.d.ts.map +1 -0
- package/lib/dts/src/primitives/popover/modifiers/types.d.ts +18 -0
- package/lib/dts/src/primitives/popover/modifiers/types.d.ts.map +1 -0
- package/lib/dts/src/primitives/popover/modifiers/usePopoverModifiers.d.ts +4 -0
- package/lib/dts/src/primitives/popover/modifiers/usePopoverModifiers.d.ts.map +1 -0
- package/lib/dts/src/primitives/popover/popover.d.ts +5 -6
- package/lib/dts/src/primitives/popover/popover.d.ts.map +1 -1
- package/lib/dts/src/primitives/textArea/textArea.d.ts.map +1 -1
- package/lib/dts/src/primitives/textInput/textInput.d.ts.map +1 -1
- package/lib/dts/src/primitives/tooltip/tooltip.d.ts +0 -2
- package/lib/dts/src/primitives/tooltip/tooltip.d.ts.map +1 -1
- package/lib/dts/src/primitives/tooltip/tooltipArrow.d.ts.map +1 -1
- package/lib/dts/src/styles/input/textInputStyle.d.ts +3 -1
- package/lib/dts/src/styles/input/textInputStyle.d.ts.map +1 -1
- package/lib/sanity-ui.js +465 -490
- package/lib/sanity-ui.js.map +1 -1
- package/lib/sanity-ui.modern.mjs +584 -566
- package/lib/sanity-ui.modern.mjs.map +1 -1
- package/lib/sanity-ui.module.js +465 -491
- package/lib/sanity-ui.module.js.map +1 -1
- package/package.json +6 -5
- package/src/components/autocomplete/autocomplete.styles.tsx +5 -0
- package/src/components/autocomplete/constants.ts +3 -3
- package/src/constants.ts +0 -17
- package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -1
- package/src/primitives/popover/__workshop__/RightAlignedStory.tsx +0 -1
- package/src/primitives/popover/__workshop__/TestStory.tsx +0 -1
- package/src/primitives/popover/{popoverArrow.tsx → arrow.tsx} +5 -5
- package/src/primitives/popover/modifiers/getPopoverModifiers.ts +137 -0
- package/src/primitives/popover/modifiers/index.ts +1 -0
- package/src/primitives/popover/modifiers/types.ts +18 -0
- package/src/primitives/popover/modifiers/usePopoverModifiers.ts +58 -0
- package/src/primitives/popover/popover.tsx +196 -229
- package/src/primitives/textArea/textArea.tsx +2 -0
- package/src/primitives/textInput/__workshop__/tones.tsx +222 -105
- package/src/primitives/textInput/textInput.tsx +5 -1
- package/src/primitives/tooltip/__workshop__/props.tsx +4 -5
- package/src/primitives/tooltip/tooltip.tsx +92 -159
- package/src/primitives/tooltip/tooltipArrow.tsx +10 -25
- package/src/styles/input/textInputStyle.ts +7 -5
- package/lib/dts/src/primitives/popover/popoverArrow.d.ts.map +0 -1
- package/lib/dts/src/primitives/popover/popoverCard.d.ts +0 -33
- package/lib/dts/src/primitives/popover/popoverCard.d.ts.map +0 -1
- package/src/primitives/popover/popoverCard.tsx +0 -160
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.16",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -30,14 +30,15 @@
|
|
|
30
30
|
"watch:es": "tsc --preserveWatchOutput -w --module ES6 --outDir lib/esm --project tsconfig.lib.json --rootDir src --target ES6"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@floating-ui/react-dom": "^1.0.0",
|
|
34
33
|
"@juggle/resize-observer": "^3.4.0",
|
|
34
|
+
"@popperjs/core": "^2.11.6",
|
|
35
35
|
"@reach/auto-id": "^0.17.0",
|
|
36
|
-
"@sanity/color": "2.1.13
|
|
37
|
-
"@sanity/icons": "1.3.3
|
|
36
|
+
"@sanity/color": "^2.1.13",
|
|
37
|
+
"@sanity/icons": "^1.3.3",
|
|
38
38
|
"framer-motion": "6.3.0",
|
|
39
39
|
"popper-max-size-modifier": "^0.2.0",
|
|
40
40
|
"react-is": "^17.0.2",
|
|
41
|
+
"react-popper": "^2.3.0",
|
|
41
42
|
"react-refractor": "^2.1.7"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
@@ -71,5 +72,5 @@
|
|
|
71
72
|
"publishConfig": {
|
|
72
73
|
"access": "public"
|
|
73
74
|
},
|
|
74
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "4650efb5fc7f539f42465ae515ad1b8312826091"
|
|
75
76
|
}
|
|
@@ -20,14 +20,14 @@ export const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
|
|
|
20
20
|
/**
|
|
21
21
|
* @internal
|
|
22
22
|
*/
|
|
23
|
-
export const AUTOCOMPLETE_POPOVER_MARGINS: PopoverMargins = [0, 1,
|
|
23
|
+
export const AUTOCOMPLETE_POPOVER_MARGINS: PopoverMargins = [0, 1, 1, 1]
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @internal
|
|
27
27
|
*/
|
|
28
|
-
export const AUTOCOMPLETE_POPOVER_PLACEMENT: Placement = 'bottom'
|
|
28
|
+
export const AUTOCOMPLETE_POPOVER_PLACEMENT: Placement = 'bottom-start'
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* @internal
|
|
32
32
|
*/
|
|
33
|
-
export const AUTOCOMPLETE_POPOVER_FALLBACK_PLACEMENTS: Placement[] = ['
|
|
33
|
+
export const AUTOCOMPLETE_POPOVER_FALLBACK_PLACEMENTS: Placement[] = ['top-start']
|
package/src/constants.ts
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
*/
|
|
4
1
|
export const EMPTY_ARRAY: any[] = []
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
2
|
export const EMPTY_RECORD: Record<string, any> = {}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export const FLOATING_STATIC_SIDES: Record<string, 'bottom' | 'left' | 'top' | 'right'> = {
|
|
15
|
-
top: 'bottom',
|
|
16
|
-
right: 'left',
|
|
17
|
-
bottom: 'top',
|
|
18
|
-
left: 'right',
|
|
19
|
-
}
|
|
@@ -17,11 +17,11 @@ const Root = styled.div`
|
|
|
17
17
|
transform-origin: 13.5px 13.5px;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
[data-placement^='top'] > & {
|
|
20
|
+
[data-popper-placement^='top'] > div > & {
|
|
21
21
|
bottom: -27px;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
[data-placement^='right'] > & {
|
|
24
|
+
[data-popper-placement^='right'] > div > & {
|
|
25
25
|
left: -27px;
|
|
26
26
|
|
|
27
27
|
& > svg {
|
|
@@ -29,7 +29,7 @@ const Root = styled.div`
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
[data-placement^='left'] > & {
|
|
32
|
+
[data-popper-placement^='left'] > div > & {
|
|
33
33
|
right: -27px;
|
|
34
34
|
|
|
35
35
|
& > svg {
|
|
@@ -37,7 +37,7 @@ const Root = styled.div`
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
[data-placement^='bottom'] > & {
|
|
40
|
+
[data-popper-placement^='bottom'] > div > & {
|
|
41
41
|
top: -27px;
|
|
42
42
|
|
|
43
43
|
& > svg {
|
|
@@ -59,7 +59,7 @@ export const PopoverArrow = forwardRef(function PopoverArrow(
|
|
|
59
59
|
ref: React.ForwardedRef<HTMLDivElement>
|
|
60
60
|
) {
|
|
61
61
|
return (
|
|
62
|
-
<Root data-ui="
|
|
62
|
+
<Root data-ui="PopoverArrow" {...props} ref={ref}>
|
|
63
63
|
<svg
|
|
64
64
|
width="27"
|
|
65
65
|
height="11"
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import maxSizeModifier from 'popper-max-size-modifier'
|
|
2
|
+
import {Modifier} from 'react-popper'
|
|
3
|
+
import {PopoverModifiersProps} from './types'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
|
|
7
|
+
The order of popper phases:
|
|
8
|
+
|
|
9
|
+
- beforeRead
|
|
10
|
+
- read
|
|
11
|
+
- afterRead
|
|
12
|
+
- beforeMain
|
|
13
|
+
- main
|
|
14
|
+
- afterMain
|
|
15
|
+
- beforeWrite
|
|
16
|
+
- write
|
|
17
|
+
- afterWrite
|
|
18
|
+
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export function getPopoverModifiers(props: PopoverModifiersProps): Modifier<any, any>[] {
|
|
22
|
+
const {
|
|
23
|
+
allowedAutoPlacements,
|
|
24
|
+
arrow,
|
|
25
|
+
arrowElement,
|
|
26
|
+
boundaryElement,
|
|
27
|
+
constrainSize,
|
|
28
|
+
distance,
|
|
29
|
+
fallbackPlacements,
|
|
30
|
+
margins,
|
|
31
|
+
matchReferenceWidth,
|
|
32
|
+
open,
|
|
33
|
+
preventOverflow,
|
|
34
|
+
skidding,
|
|
35
|
+
tether,
|
|
36
|
+
tetherOffset,
|
|
37
|
+
} = props
|
|
38
|
+
|
|
39
|
+
// NOTE: For later viewers:
|
|
40
|
+
// Prior to adding this change, the popover would get `maxWidth: 0` the 2nd time it
|
|
41
|
+
// was opened, when used with `constrainSize`. I was looking for a way to "reset"
|
|
42
|
+
// the size of the popover as measured by Popper.js, and this seems to be a workaround.
|
|
43
|
+
if (!open) {
|
|
44
|
+
return []
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const detectOverflowOptions = {
|
|
48
|
+
altAxis: !constrainSize,
|
|
49
|
+
boundary: boundaryElement || undefined,
|
|
50
|
+
padding: 8,
|
|
51
|
+
tether,
|
|
52
|
+
tetherOffset,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return [
|
|
56
|
+
constrainSize && {
|
|
57
|
+
...maxSizeModifier,
|
|
58
|
+
options: detectOverflowOptions,
|
|
59
|
+
},
|
|
60
|
+
constrainSize && {
|
|
61
|
+
name: 'applyMaxSize',
|
|
62
|
+
enabled: true,
|
|
63
|
+
phase: 'beforeWrite',
|
|
64
|
+
requires: ['maxSize'],
|
|
65
|
+
fn({state}: any) {
|
|
66
|
+
const {width, height} = state.modifiersData.maxSize
|
|
67
|
+
|
|
68
|
+
state.styles.popper = {
|
|
69
|
+
...state.styles.popper,
|
|
70
|
+
maxWidth: `${width}px`,
|
|
71
|
+
maxHeight: `${height}px`,
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
arrow && {
|
|
76
|
+
name: 'arrow',
|
|
77
|
+
options: {
|
|
78
|
+
element: arrowElement,
|
|
79
|
+
padding: 4,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
(constrainSize || preventOverflow) && {
|
|
83
|
+
name: 'preventOverflow',
|
|
84
|
+
options: detectOverflowOptions,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'offset',
|
|
88
|
+
options: {
|
|
89
|
+
offset: [skidding, distance],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
margins && {
|
|
93
|
+
name: 'margins',
|
|
94
|
+
enabled: true,
|
|
95
|
+
phase: 'beforeRead',
|
|
96
|
+
fn: ({state}: any) => {
|
|
97
|
+
const {rects} = state
|
|
98
|
+
|
|
99
|
+
if (rects.reference) {
|
|
100
|
+
rects.reference.x += margins[3]
|
|
101
|
+
rects.reference.y += margins[1]
|
|
102
|
+
rects.reference.width -= margins[1] + margins[3]
|
|
103
|
+
rects.reference.height -= margins[0] + margins[2]
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'flip',
|
|
109
|
+
options: {
|
|
110
|
+
allowedAutoPlacements,
|
|
111
|
+
boundary: boundaryElement || undefined,
|
|
112
|
+
fallbackPlacements,
|
|
113
|
+
padding: 8,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
matchReferenceWidth && {
|
|
117
|
+
name: 'matchWidth',
|
|
118
|
+
enabled: true,
|
|
119
|
+
phase: 'beforeWrite',
|
|
120
|
+
requires: ['computeStyles'],
|
|
121
|
+
fn({state}: any) {
|
|
122
|
+
const {width} = state.rects.reference
|
|
123
|
+
|
|
124
|
+
state.styles.popper.width = `${width}px`
|
|
125
|
+
},
|
|
126
|
+
effect: ({state}: any) => {
|
|
127
|
+
const refElement = state.elements.reference
|
|
128
|
+
|
|
129
|
+
if (refElement instanceof HTMLElement) {
|
|
130
|
+
state.elements.popper.style.width = `${
|
|
131
|
+
refElement.offsetWidth - (margins ? margins[1] + margins[3] : 0)
|
|
132
|
+
}px`
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
].filter(Boolean) as Modifier<any, any>[]
|
|
137
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './usePopoverModifiers'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {Placement} from '../../../types'
|
|
2
|
+
|
|
3
|
+
export interface PopoverModifiersProps {
|
|
4
|
+
allowedAutoPlacements?: Placement[]
|
|
5
|
+
arrow?: boolean
|
|
6
|
+
arrowElement?: HTMLElement | null
|
|
7
|
+
boundaryElement?: HTMLElement | null
|
|
8
|
+
constrainSize?: boolean
|
|
9
|
+
distance: number
|
|
10
|
+
fallbackPlacements?: Placement[]
|
|
11
|
+
margins?: [number, number, number, number]
|
|
12
|
+
matchReferenceWidth?: boolean
|
|
13
|
+
open: boolean
|
|
14
|
+
preventOverflow?: boolean
|
|
15
|
+
skidding: number
|
|
16
|
+
tether?: boolean
|
|
17
|
+
tetherOffset?: number | ((...args: any[]) => number)
|
|
18
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {useMemo} from 'react'
|
|
2
|
+
import {Modifier} from 'react-popper'
|
|
3
|
+
|
|
4
|
+
import {getPopoverModifiers} from './getPopoverModifiers'
|
|
5
|
+
import {PopoverModifiersProps} from './types'
|
|
6
|
+
|
|
7
|
+
export function usePopoverModifiers(props: PopoverModifiersProps): Modifier<any, any>[] {
|
|
8
|
+
const {
|
|
9
|
+
allowedAutoPlacements,
|
|
10
|
+
arrow,
|
|
11
|
+
arrowElement,
|
|
12
|
+
boundaryElement,
|
|
13
|
+
constrainSize,
|
|
14
|
+
distance,
|
|
15
|
+
fallbackPlacements,
|
|
16
|
+
margins,
|
|
17
|
+
matchReferenceWidth,
|
|
18
|
+
open,
|
|
19
|
+
preventOverflow,
|
|
20
|
+
skidding,
|
|
21
|
+
tether,
|
|
22
|
+
tetherOffset,
|
|
23
|
+
} = props
|
|
24
|
+
|
|
25
|
+
return useMemo(() => {
|
|
26
|
+
return getPopoverModifiers({
|
|
27
|
+
allowedAutoPlacements,
|
|
28
|
+
arrow,
|
|
29
|
+
arrowElement,
|
|
30
|
+
boundaryElement,
|
|
31
|
+
constrainSize,
|
|
32
|
+
distance,
|
|
33
|
+
fallbackPlacements,
|
|
34
|
+
margins,
|
|
35
|
+
matchReferenceWidth,
|
|
36
|
+
open,
|
|
37
|
+
preventOverflow,
|
|
38
|
+
skidding,
|
|
39
|
+
tether,
|
|
40
|
+
tetherOffset,
|
|
41
|
+
})
|
|
42
|
+
}, [
|
|
43
|
+
allowedAutoPlacements,
|
|
44
|
+
arrow,
|
|
45
|
+
arrowElement,
|
|
46
|
+
boundaryElement,
|
|
47
|
+
constrainSize,
|
|
48
|
+
distance,
|
|
49
|
+
fallbackPlacements,
|
|
50
|
+
margins,
|
|
51
|
+
matchReferenceWidth,
|
|
52
|
+
open,
|
|
53
|
+
preventOverflow,
|
|
54
|
+
skidding,
|
|
55
|
+
tether,
|
|
56
|
+
tetherOffset,
|
|
57
|
+
])
|
|
58
|
+
}
|