@sanity/ui 0.37.20 → 0.37.21
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/breadcrumbs/breadcrumbs.d.ts.map +1 -1
- package/lib/dts/src/components/dialog/dialog.d.ts.map +1 -1
- package/lib/dts/src/components/dialog/styles.d.ts +1 -1
- package/lib/dts/src/components/dialog/styles.d.ts.map +1 -1
- package/lib/dts/src/components/hotkeys/hotkeys.d.ts.map +1 -1
- package/lib/dts/src/components/menu/menuGroup.d.ts.map +1 -1
- package/lib/dts/src/components/skeleton/skeleton.d.ts.map +1 -1
- package/lib/dts/src/hooks/index.d.ts +1 -2
- package/lib/dts/src/hooks/index.d.ts.map +1 -1
- package/lib/dts/src/hooks/useElementRect/useElementRect.d.ts +1 -1
- package/lib/dts/src/hooks/useElementRect/useElementRect.d.ts.map +1 -1
- package/lib/dts/src/hooks/useResponsiveProp.d.ts +6 -0
- package/lib/dts/src/hooks/useResponsiveProp.d.ts.map +1 -0
- package/lib/dts/src/index.d.ts +0 -1
- package/lib/dts/src/index.d.ts.map +1 -1
- package/lib/dts/src/primitives/_selectable/selectable.d.ts +2 -1
- package/lib/dts/src/primitives/_selectable/selectable.d.ts.map +1 -1
- package/lib/dts/src/primitives/avatar/avatar.d.ts.map +1 -1
- package/lib/dts/src/primitives/avatar/avatarCounter.d.ts.map +1 -1
- package/lib/dts/src/primitives/avatar/avatarStack.d.ts.map +1 -1
- package/lib/dts/src/primitives/avatar/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/badge/badge.d.ts.map +1 -1
- package/lib/dts/src/primitives/box/box.d.ts.map +1 -1
- package/lib/dts/src/primitives/button/button.d.ts.map +1 -1
- package/lib/dts/src/primitives/card/card.d.ts.map +1 -1
- package/lib/dts/src/primitives/code/code.d.ts.map +1 -1
- package/lib/dts/src/primitives/container/container.d.ts.map +1 -1
- package/lib/dts/src/primitives/container/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/container/types.d.ts +1 -1
- package/lib/dts/src/primitives/container/types.d.ts.map +1 -1
- package/lib/dts/src/primitives/flex/flex.d.ts.map +1 -1
- package/lib/dts/src/primitives/grid/grid.d.ts.map +1 -1
- package/lib/dts/src/primitives/heading/heading.d.ts.map +1 -1
- package/lib/dts/src/primitives/inline/inline.d.ts.map +1 -1
- package/lib/dts/src/primitives/inline/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/inline/types.d.ts +1 -1
- package/lib/dts/src/primitives/inline/types.d.ts.map +1 -1
- package/lib/dts/src/primitives/kbd/kbd.d.ts.map +1 -1
- package/lib/dts/src/primitives/label/label.d.ts.map +1 -1
- package/lib/dts/src/primitives/popover/popover.d.ts.map +1 -1
- package/lib/dts/src/primitives/select/styles.d.ts +1 -5
- package/lib/dts/src/primitives/select/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/stack/stack.d.ts.map +1 -1
- package/lib/dts/src/primitives/stack/styles.d.ts +1 -1
- package/lib/dts/src/primitives/stack/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/text/text.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.map +1 -1
- package/lib/dts/src/primitives/types.d.ts +1 -1
- package/lib/dts/src/primitives/types.d.ts.map +1 -1
- package/lib/dts/src/styles/border/types.d.ts +5 -5
- package/lib/dts/src/styles/border/types.d.ts.map +1 -1
- package/lib/dts/src/styles/box/types.d.ts +4 -4
- package/lib/dts/src/styles/box/types.d.ts.map +1 -1
- package/lib/dts/src/styles/flex/flexItemStyle.d.ts.map +1 -1
- package/lib/dts/src/styles/flex/types.d.ts +6 -6
- package/lib/dts/src/styles/flex/types.d.ts.map +1 -1
- package/lib/dts/src/styles/font/responsiveFont.d.ts.map +1 -1
- package/lib/dts/src/styles/font/types.d.ts +3 -3
- package/lib/dts/src/styles/font/types.d.ts.map +1 -1
- package/lib/dts/src/styles/grid/types.d.ts +14 -14
- package/lib/dts/src/styles/grid/types.d.ts.map +1 -1
- package/lib/dts/src/styles/helpers.d.ts +4 -4
- package/lib/dts/src/styles/helpers.d.ts.map +1 -1
- package/lib/dts/src/styles/input/responsiveInputPaddingStyle.d.ts +12 -12
- package/lib/dts/src/styles/input/responsiveInputPaddingStyle.d.ts.map +1 -1
- package/lib/dts/src/styles/input/textInputStyle.d.ts +2 -7
- package/lib/dts/src/styles/input/textInputStyle.d.ts.map +1 -1
- package/lib/dts/src/styles/margin/types.d.ts +7 -7
- package/lib/dts/src/styles/margin/types.d.ts.map +1 -1
- package/lib/dts/src/styles/padding/types.d.ts +7 -7
- package/lib/dts/src/styles/padding/types.d.ts.map +1 -1
- package/lib/dts/src/styles/radius/types.d.ts +1 -1
- package/lib/dts/src/styles/radius/types.d.ts.map +1 -1
- package/lib/dts/src/styles/shadow/shadowStyle.d.ts.map +1 -1
- package/lib/dts/src/styles/shadow/types.d.ts +1 -1
- package/lib/dts/src/styles/shadow/types.d.ts.map +1 -1
- package/lib/dts/src/theme/studioTheme/color.d.ts.map +1 -1
- package/lib/dts/src/utils/elementQuery/elementQuery.d.ts.map +1 -1
- package/lib/dts/src/utils/index.d.ts +1 -0
- package/lib/dts/src/utils/index.d.ts.map +1 -1
- package/lib/dts/src/utils/resizeObserver.d.ts +6 -0
- package/lib/dts/src/utils/resizeObserver.d.ts.map +1 -0
- package/lib/dts/src/utils/virtualList/virtualList.d.ts.map +1 -1
- package/lib/sanity-ui.js +570 -731
- package/lib/sanity-ui.js.map +1 -1
- package/lib/sanity-ui.modern.js +591 -762
- package/lib/sanity-ui.modern.js.map +1 -1
- package/lib/sanity-ui.module.js +566 -725
- package/lib/sanity-ui.module.js.map +1 -1
- package/package.json +11 -11
- package/src/__workshop__/color/overview.tsx +11 -9
- package/src/components/autocomplete/__workshop__/async.tsx +12 -14
- package/src/components/autocomplete/__workshop__/constrainedHeight.tsx +0 -36
- package/src/components/autocomplete/autocomplete.tsx +2 -2
- package/src/components/breadcrumbs/breadcrumbs.tsx +2 -3
- package/src/components/dialog/dialog.tsx +9 -17
- package/src/components/dialog/styles.ts +4 -4
- package/src/components/hotkeys/hotkeys.tsx +1 -3
- package/src/components/menu/__workshop__/constrainedInBoundary.tsx +14 -11
- package/src/components/menu/__workshop__/groups.tsx +1 -1
- package/src/components/menu/menuGroup.tsx +2 -3
- package/src/components/menu/menuItem.tsx +3 -3
- package/src/components/skeleton/skeleton.tsx +1 -10
- package/src/components/skeleton/textSkeleton.tsx +7 -7
- package/src/hooks/index.ts +1 -2
- package/src/hooks/useElementRect/useElementRect.ts +16 -4
- package/src/hooks/useResponsiveProp.ts +10 -0
- package/src/index.ts +0 -1
- package/src/primitives/_selectable/selectable.tsx +4 -5
- package/src/primitives/avatar/avatar.tsx +5 -7
- package/src/primitives/avatar/avatarCounter.tsx +11 -12
- package/src/primitives/avatar/avatarStack.tsx +10 -15
- package/src/primitives/avatar/styles.ts +2 -2
- package/src/primitives/badge/badge.tsx +2 -3
- package/src/primitives/box/box.tsx +25 -26
- package/src/primitives/button/button.tsx +10 -22
- package/src/primitives/card/card.tsx +7 -8
- package/src/primitives/checkbox/__workshop__/example.tsx +2 -4
- package/src/primitives/checkbox/__workshop__/props.tsx +2 -4
- package/src/primitives/checkbox/__workshop__/readOnly.tsx +2 -4
- package/src/primitives/code/__workshop__/props.tsx +1 -1
- package/src/primitives/code/code.tsx +1 -2
- package/src/primitives/container/container.tsx +1 -10
- package/src/primitives/container/styles.ts +2 -2
- package/src/primitives/container/types.ts +1 -1
- package/src/primitives/flex/flex.tsx +5 -6
- package/src/primitives/grid/__workshop__/responsive.tsx +12 -13
- package/src/primitives/grid/grid.tsx +8 -9
- package/src/primitives/heading/__workshop__/opticalAlignment.tsx +7 -19
- package/src/primitives/heading/heading.tsx +2 -3
- package/src/primitives/inline/inline.tsx +6 -12
- package/src/primitives/inline/styles.ts +2 -2
- package/src/primitives/inline/types.ts +1 -1
- package/src/primitives/kbd/kbd.tsx +1 -2
- package/src/primitives/label/label.tsx +3 -4
- package/src/primitives/popover/__workshop__/index.ts +5 -10
- package/src/primitives/popover/__workshop__/{MarginsStory.tsx → margins.tsx} +1 -1
- package/src/primitives/popover/__workshop__/{MatchReferenceWidthStory.tsx → matchReferenceWidth.tsx} +0 -0
- package/src/primitives/popover/__workshop__/{PlainStory.tsx → plain.tsx} +14 -12
- package/src/primitives/popover/__workshop__/{RecursiveStory.tsx → recursive.tsx} +1 -4
- package/src/primitives/popover/__workshop__/rightAligned.tsx +57 -0
- package/src/primitives/popover/popover.tsx +10 -29
- package/src/primitives/select/select.tsx +9 -9
- package/src/primitives/select/styles.ts +4 -10
- package/src/primitives/stack/stack.tsx +1 -2
- package/src/primitives/stack/styles.ts +3 -3
- package/src/primitives/text/__workshop__/opticalAlignment.tsx +5 -15
- package/src/primitives/text/text.tsx +2 -3
- package/src/primitives/textArea/__workshop__/plain.tsx +18 -23
- package/src/primitives/textArea/textArea.tsx +5 -21
- package/src/primitives/textInput/__workshop__/clearButton.tsx +8 -14
- package/src/primitives/textInput/__workshop__/index.ts +2 -2
- package/src/primitives/textInput/__workshop__/plain.tsx +32 -39
- package/src/primitives/textInput/__workshop__/tones.tsx +95 -234
- package/src/primitives/textInput/__workshop__/typed.tsx +2 -8
- package/src/primitives/textInput/textInput.tsx +12 -47
- package/src/primitives/tooltip/__workshop__/props.tsx +2 -7
- package/src/primitives/tooltip/tooltip.tsx +9 -19
- package/src/primitives/types.ts +1 -1
- package/src/styles/border/borderStyle.ts +6 -6
- package/src/styles/border/types.ts +5 -5
- package/src/styles/box/boxStyle.ts +5 -5
- package/src/styles/box/types.ts +4 -4
- package/src/styles/flex/flexItemStyle.ts +4 -5
- package/src/styles/flex/flexStyle.ts +6 -6
- package/src/styles/flex/types.ts +6 -6
- package/src/styles/font/responsiveFont.ts +4 -2
- package/src/styles/font/textAlignStyle.ts +2 -2
- package/src/styles/font/types.ts +3 -4
- package/src/styles/grid/gridItemStyle.ts +7 -7
- package/src/styles/grid/gridStyle.ts +9 -9
- package/src/styles/grid/types.ts +14 -14
- package/src/styles/helpers.ts +9 -9
- package/src/styles/input/responsiveInputPaddingStyle.ts +27 -24
- package/src/styles/input/textInputStyle.ts +80 -92
- package/src/styles/margin/marginStyle.ts +8 -8
- package/src/styles/margin/marginsStyle.test.ts +1 -1
- package/src/styles/margin/types.ts +7 -7
- package/src/styles/padding/paddingStyle.test.ts +1 -1
- package/src/styles/padding/paddingStyle.ts +8 -8
- package/src/styles/padding/types.ts +7 -7
- package/src/styles/radius/radiusStyle.ts +2 -2
- package/src/styles/radius/types.ts +1 -1
- package/src/styles/shadow/shadowStyle.ts +5 -2
- package/src/styles/shadow/types.ts +1 -1
- package/src/theme/studioTheme/color.ts +14 -15
- package/src/theme/studioTheme/fonts.ts +4 -4
- package/src/utils/elementQuery/elementQuery.tsx +18 -5
- package/src/utils/index.ts +1 -0
- package/src/utils/layer/layerProvider.tsx +2 -2
- package/src/{observers → utils}/resizeObserver.ts +3 -1
- package/src/utils/virtualList/virtualList.tsx +1 -3
- package/lib/dts/src/hooks/useArrayProp.d.ts +0 -7
- package/lib/dts/src/hooks/useArrayProp.d.ts.map +0 -1
- package/lib/dts/src/hooks/useElementSize.d.ts +0 -7
- package/lib/dts/src/hooks/useElementSize.d.ts.map +0 -1
- package/lib/dts/src/observers/elementSizeObserver.d.ts +0 -37
- package/lib/dts/src/observers/elementSizeObserver.d.ts.map +0 -1
- package/lib/dts/src/observers/index.d.ts +0 -3
- package/lib/dts/src/observers/index.d.ts.map +0 -1
- package/lib/dts/src/observers/resizeObserver.d.ts +0 -5
- package/lib/dts/src/observers/resizeObserver.d.ts.map +0 -1
- package/src/hooks/useArrayProp.ts +0 -23
- package/src/hooks/useElementSize.ts +0 -18
- package/src/observers/elementSizeObserver.ts +0 -116
- package/src/observers/index.ts +0 -2
- package/src/primitives/popover/__workshop__/RightAlignedStory.tsx +0 -60
- package/src/primitives/popover/__workshop__/TestStory.tsx +0 -79
|
@@ -17,19 +17,18 @@ const NEUTRAL_TONES = ['default', 'transparent']
|
|
|
17
17
|
export const color = createColorTheme({
|
|
18
18
|
base: ({dark, name}) => {
|
|
19
19
|
if (name === 'default') {
|
|
20
|
-
const
|
|
21
|
-
const skeletonFrom = dark ? tints[900].hex : tints[100].hex
|
|
20
|
+
const skeletonFrom = dark ? hues.gray[900].hex : hues.gray[100].hex
|
|
22
21
|
|
|
23
22
|
return {
|
|
24
23
|
fg: dark ? white.hex : black.hex,
|
|
25
24
|
bg: dark ? black.hex : white.hex,
|
|
26
|
-
border:
|
|
25
|
+
border: hues.gray[dark ? 800 : 200].hex,
|
|
27
26
|
focusRing: hues.blue[dark ? 500 : 500].hex,
|
|
28
27
|
shadow: {
|
|
29
|
-
outline: rgba(
|
|
30
|
-
umbra: dark ?
|
|
31
|
-
penumbra: dark ?
|
|
32
|
-
ambient: dark ?
|
|
28
|
+
outline: rgba(hues.gray[500].hex, 0.4),
|
|
29
|
+
umbra: rgba(dark ? black.hex : hues.gray[500].hex, 0.2),
|
|
30
|
+
penumbra: rgba(dark ? black.hex : hues.gray[500].hex, 0.14),
|
|
31
|
+
ambient: rgba(dark ? black.hex : hues.gray[500].hex, 0.12),
|
|
33
32
|
},
|
|
34
33
|
skeleton: {
|
|
35
34
|
from: skeletonFrom,
|
|
@@ -48,10 +47,10 @@ export const color = createColorTheme({
|
|
|
48
47
|
border: tints[dark ? 800 : 300].hex,
|
|
49
48
|
focusRing: hues.blue[500].hex,
|
|
50
49
|
shadow: {
|
|
51
|
-
outline: rgba(tints[500].hex, 0.4),
|
|
52
|
-
umbra: dark ?
|
|
53
|
-
penumbra: dark ?
|
|
54
|
-
ambient: dark ?
|
|
50
|
+
outline: rgba(tints[500].hex, dark ? 0.2 : 0.4),
|
|
51
|
+
umbra: rgba(dark ? black.hex : tints[500].hex, 0.2),
|
|
52
|
+
penumbra: rgba(dark ? black.hex : tints[500].hex, 0.14),
|
|
53
|
+
ambient: rgba(dark ? black.hex : tints[500].hex, 0.12),
|
|
55
54
|
},
|
|
56
55
|
skeleton: {
|
|
57
56
|
from: skeletonFrom,
|
|
@@ -69,10 +68,10 @@ export const color = createColorTheme({
|
|
|
69
68
|
border: tints[dark ? 800 : 200].hex,
|
|
70
69
|
focusRing: tints[500].hex,
|
|
71
70
|
shadow: {
|
|
72
|
-
outline: rgba(tints[500].hex, 0.4),
|
|
73
|
-
umbra: dark ?
|
|
74
|
-
penumbra: dark ?
|
|
75
|
-
ambient: dark ?
|
|
71
|
+
outline: rgba(tints[500].hex, dark ? 0.2 : 0.4),
|
|
72
|
+
umbra: rgba(dark ? black.hex : tints[500].hex, 0.2),
|
|
73
|
+
penumbra: rgba(dark ? black.hex : tints[500].hex, 0.14),
|
|
74
|
+
ambient: rgba(dark ? black.hex : tints[500].hex, 0.12),
|
|
76
75
|
},
|
|
77
76
|
skeleton: {
|
|
78
77
|
from: skeletonFrom,
|
|
@@ -95,16 +95,16 @@ export const fonts: ThemeFonts = {
|
|
|
95
95
|
letterSpacing: 0,
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
|
-
ascenderHeight:
|
|
99
|
-
descenderHeight:
|
|
98
|
+
ascenderHeight: 9,
|
|
99
|
+
descenderHeight: 7,
|
|
100
100
|
fontSize: 33,
|
|
101
101
|
iconSize: 49,
|
|
102
102
|
lineHeight: 39,
|
|
103
103
|
letterSpacing: 0,
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
|
-
ascenderHeight:
|
|
107
|
-
descenderHeight:
|
|
106
|
+
ascenderHeight: 10,
|
|
107
|
+
descenderHeight: 8,
|
|
108
108
|
fontSize: 38,
|
|
109
109
|
iconSize: 53,
|
|
110
110
|
lineHeight: 45,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React, {forwardRef, useCallback, useMemo, useState} from 'react'
|
|
2
|
-
import {
|
|
1
|
+
import React, {forwardRef, useCallback, useEffect, useMemo, useState} from 'react'
|
|
2
|
+
import {useForwardedRef} from '../../hooks'
|
|
3
3
|
import {useTheme} from '../../theme'
|
|
4
|
+
import {ResizeObserver} from '../resizeObserver'
|
|
4
5
|
import {findMaxBreakpoints, findMinBreakpoints} from './helpers'
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -22,11 +23,23 @@ export const ElementQuery = forwardRef(function ElementQuery(
|
|
|
22
23
|
) {
|
|
23
24
|
const theme = useTheme()
|
|
24
25
|
const {children, media = theme.sanity.media, ...restProps} = props
|
|
25
|
-
|
|
26
|
+
const [width, setWidth] = useState(() => window.innerWidth)
|
|
26
27
|
const forwardedRef = useForwardedRef(ref)
|
|
27
28
|
const [element, setElement] = useState<HTMLDivElement | null>(null)
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!element) return
|
|
32
|
+
|
|
33
|
+
const handleResizeEntries: ResizeObserverCallback = (entries) => {
|
|
34
|
+
setWidth(entries[0].contentRect.width)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const ro = new ResizeObserver(handleResizeEntries)
|
|
38
|
+
|
|
39
|
+
ro.observe(element)
|
|
40
|
+
|
|
41
|
+
return () => ro.disconnect()
|
|
42
|
+
}, [element])
|
|
30
43
|
|
|
31
44
|
const max = useMemo(() => findMaxBreakpoints(media, width), [media, width])
|
|
32
45
|
const min = useMemo(() => findMinBreakpoints(media, width), [media, width])
|
package/src/utils/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, {useCallback, useContext, useEffect, useMemo, useState} from 'react'
|
|
2
|
-
import {useMediaIndex,
|
|
2
|
+
import {useMediaIndex, useResponsiveProp} from '../../hooks'
|
|
3
3
|
import {LayerContext} from './layerContext'
|
|
4
4
|
import {LayerContextValue} from './types'
|
|
5
5
|
|
|
@@ -17,7 +17,7 @@ export interface LayerProviderProps {
|
|
|
17
17
|
export function LayerProvider(props: LayerProviderProps): React.ReactElement {
|
|
18
18
|
const {children, zOffset: zOffsetProp = 0} = props
|
|
19
19
|
const parent = useContext(LayerContext)
|
|
20
|
-
const zOffset =
|
|
20
|
+
const zOffset = useResponsiveProp(zOffsetProp)
|
|
21
21
|
const maxMediaIndex = zOffset.length - 1
|
|
22
22
|
const mediaIndex = Math.min(useMediaIndex(), maxMediaIndex)
|
|
23
23
|
const zIndex = parent ? parent.zIndex + zOffset[mediaIndex] : zOffset[mediaIndex]
|
|
@@ -3,7 +3,9 @@ import {ResizeObserver as ResizeObserverPolyfill} from '@juggle/resize-observer'
|
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
const RO: typeof ResizeObserver =
|
|
7
7
|
typeof window !== 'undefined' && window.ResizeObserver
|
|
8
8
|
? window.ResizeObserver
|
|
9
9
|
: ResizeObserverPolyfill
|
|
10
|
+
|
|
11
|
+
export {RO as ResizeObserver}
|
|
@@ -2,7 +2,6 @@ import React, {forwardRef, useEffect, useMemo, useRef, useState} from 'react'
|
|
|
2
2
|
import styled from 'styled-components'
|
|
3
3
|
import {_isScrollable} from '../../helpers'
|
|
4
4
|
import {useForwardedRef} from '../../hooks'
|
|
5
|
-
import {_ResizeObserver} from '../../observers'
|
|
6
5
|
import {StackProps} from '../../primitives'
|
|
7
6
|
import {useTheme} from '../../theme'
|
|
8
7
|
|
|
@@ -87,7 +86,7 @@ export const VirtualList = forwardRef(function VirtualList(
|
|
|
87
86
|
|
|
88
87
|
scrollEl.addEventListener('scroll', handleScroll, {passive: true})
|
|
89
88
|
|
|
90
|
-
const ro = new
|
|
89
|
+
const ro = new ResizeObserver((entries) => {
|
|
91
90
|
setScrollHeight(entries[0].contentRect.height)
|
|
92
91
|
})
|
|
93
92
|
|
|
@@ -97,7 +96,6 @@ export const VirtualList = forwardRef(function VirtualList(
|
|
|
97
96
|
|
|
98
97
|
return () => {
|
|
99
98
|
scrollEl.removeEventListener('scroll', handleScroll)
|
|
100
|
-
|
|
101
99
|
ro.unobserve(scrollEl)
|
|
102
100
|
ro.disconnect()
|
|
103
101
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare type Primitive = string | number | boolean | undefined | null;
|
|
2
|
-
/**
|
|
3
|
-
* This API might change. DO NOT USE IN PRODUCTION.
|
|
4
|
-
* @beta
|
|
5
|
-
*/
|
|
6
|
-
export declare function useArrayProp<T extends Primitive = Primitive>(val: T | T[] | undefined, defaultVal?: T[]): T[];
|
|
7
|
-
//# sourceMappingURL=useArrayProp.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useArrayProp.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useArrayProp.ts"],"names":[],"mappings":"AAGA,oBAAY,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAA;AAEpE;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAC1D,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,EACxB,UAAU,CAAC,EAAE,CAAC,EAAE,GACf,CAAC,EAAE,CAUL"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useElementSize.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useElementSize.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAuB,MAAM,kCAAkC,CAAA;AAElF;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAU9E"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @beta
|
|
3
|
-
*/
|
|
4
|
-
export interface ElementRectValue {
|
|
5
|
-
width: number;
|
|
6
|
-
height: number;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @beta
|
|
10
|
-
*/
|
|
11
|
-
export interface ElementSize {
|
|
12
|
-
content: ElementRectValue;
|
|
13
|
-
border: ElementRectValue;
|
|
14
|
-
/** @deprecated INTERNAL ONLY */
|
|
15
|
-
_contentRect: DOMRectReadOnly;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
export declare type _ElementSizeSubscriber = (elementRect: ElementSize) => void;
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
export interface _ElementSizeObserver {
|
|
25
|
-
subscribe: (element: HTMLElement, subscriber: _ElementSizeSubscriber) => () => void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export interface _ElementSizeListener {
|
|
31
|
-
subscribe: (element: HTMLElement, subscriber: _ElementSizeSubscriber) => () => void;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
export declare const _elementSizeObserver: _ElementSizeObserver;
|
|
37
|
-
//# sourceMappingURL=elementSizeObserver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"elementSizeObserver.d.ts","sourceRoot":"","sources":["../../../../src/observers/elementSizeObserver.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,gBAAgB,CAAA;IACzB,MAAM,EAAE,gBAAgB,CAAA;IAExB,gCAAgC;IAChC,YAAY,EAAE,eAAe,CAAA;CAC9B;AAED;;GAEG;AACH,oBAAY,sBAAsB,GAAG,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAA;AAEvE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,sBAAsB,KAAK,MAAM,IAAI,CAAA;CACpF;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,sBAAsB,KAAK,MAAM,IAAI,CAAA;CACpF;AAID;;GAEG;AACH,eAAO,MAAM,oBAAoB,sBAA+B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/observers/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resizeObserver.d.ts","sourceRoot":"","sources":["../../../../src/observers/resizeObserver.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,cAGT,CAAA"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {useMemo} from 'react'
|
|
2
|
-
import {_getArrayProp} from '../styles'
|
|
3
|
-
|
|
4
|
-
export type Primitive = string | number | boolean | undefined | null
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This API might change. DO NOT USE IN PRODUCTION.
|
|
8
|
-
* @beta
|
|
9
|
-
*/
|
|
10
|
-
export function useArrayProp<T extends Primitive = Primitive>(
|
|
11
|
-
val: T | T[] | undefined,
|
|
12
|
-
defaultVal?: T[]
|
|
13
|
-
): T[] {
|
|
14
|
-
const __perf_hash__ = JSON.stringify(val ?? defaultVal)
|
|
15
|
-
|
|
16
|
-
return useMemo(
|
|
17
|
-
() => _getArrayProp(val, defaultVal),
|
|
18
|
-
|
|
19
|
-
// Improve performance: Keep object identify for a given hash of the value
|
|
20
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
|
-
[__perf_hash__]
|
|
22
|
-
)
|
|
23
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {useEffect, useState} from 'react'
|
|
2
|
-
import {ElementSize, _elementSizeObserver} from '../observers/elementSizeObserver'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Subscribe to the size of a DOM element.
|
|
6
|
-
* @beta
|
|
7
|
-
*/
|
|
8
|
-
export function useElementSize(element: HTMLElement | null): ElementSize | null {
|
|
9
|
-
const [size, setSize] = useState<ElementSize | null>(null)
|
|
10
|
-
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (!element) return undefined
|
|
13
|
-
|
|
14
|
-
return _elementSizeObserver.subscribe(element, setSize)
|
|
15
|
-
}, [element])
|
|
16
|
-
|
|
17
|
-
return size
|
|
18
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import {_ResizeObserver} from './resizeObserver'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @beta
|
|
5
|
-
*/
|
|
6
|
-
export interface ElementRectValue {
|
|
7
|
-
width: number
|
|
8
|
-
height: number
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @beta
|
|
13
|
-
*/
|
|
14
|
-
export interface ElementSize {
|
|
15
|
-
content: ElementRectValue
|
|
16
|
-
border: ElementRectValue
|
|
17
|
-
|
|
18
|
-
/** @deprecated INTERNAL ONLY */
|
|
19
|
-
_contentRect: DOMRectReadOnly
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
export type _ElementSizeSubscriber = (elementRect: ElementSize) => void
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export interface _ElementSizeObserver {
|
|
31
|
-
subscribe: (element: HTMLElement, subscriber: _ElementSizeSubscriber) => () => void
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
export interface _ElementSizeListener {
|
|
38
|
-
subscribe: (element: HTMLElement, subscriber: _ElementSizeSubscriber) => () => void
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Initialize element size observer
|
|
42
|
-
// NOTE: this should NOT have size effects
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
export const _elementSizeObserver = _createElementSizeObserver()
|
|
47
|
-
|
|
48
|
-
function _createElementRectValueListener(): _ElementSizeListener {
|
|
49
|
-
return {
|
|
50
|
-
subscribe(element, subscriber) {
|
|
51
|
-
const resizeObserver = new _ResizeObserver(([entry]) => {
|
|
52
|
-
subscriber({
|
|
53
|
-
_contentRect: entry.contentRect,
|
|
54
|
-
border: {
|
|
55
|
-
width: entry.borderBoxSize[0].inlineSize,
|
|
56
|
-
height: entry.borderBoxSize[0].blockSize,
|
|
57
|
-
},
|
|
58
|
-
content: {
|
|
59
|
-
width: entry.contentRect.width,
|
|
60
|
-
height: entry.contentRect.height,
|
|
61
|
-
},
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
resizeObserver.observe(element)
|
|
66
|
-
|
|
67
|
-
return () => {
|
|
68
|
-
resizeObserver.unobserve(element)
|
|
69
|
-
resizeObserver.disconnect()
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function _createElementSizeObserver(): _ElementSizeObserver {
|
|
76
|
-
const disposeCache = new WeakMap<HTMLElement, () => void>()
|
|
77
|
-
const subscribersCache = new WeakMap<HTMLElement, _ElementSizeSubscriber[]>()
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
subscribe(element, subscriber) {
|
|
81
|
-
const subscribers = subscribersCache.get(element) || []
|
|
82
|
-
|
|
83
|
-
let dispose = disposeCache.get(element)
|
|
84
|
-
|
|
85
|
-
if (!subscribersCache.has(element)) {
|
|
86
|
-
subscribersCache.set(element, subscribers)
|
|
87
|
-
|
|
88
|
-
const listener = _createElementRectValueListener()
|
|
89
|
-
|
|
90
|
-
// listen
|
|
91
|
-
dispose = listener.subscribe(element, (elementRect) => {
|
|
92
|
-
for (const sub of subscribers) {
|
|
93
|
-
sub(elementRect)
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
subscribers.push(subscriber)
|
|
99
|
-
|
|
100
|
-
return () => {
|
|
101
|
-
// dispose
|
|
102
|
-
|
|
103
|
-
const idx = subscribers.indexOf(subscriber)
|
|
104
|
-
|
|
105
|
-
if (idx > -1) {
|
|
106
|
-
subscribers.splice(idx, 1)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (subscribers.length === 0) {
|
|
110
|
-
// unlisten
|
|
111
|
-
if (dispose) dispose()
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
}
|
|
116
|
-
}
|
package/src/observers/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {EllipsisVerticalIcon} from '@sanity/icons'
|
|
2
|
-
import {Button, Card, Flex, Popover, Text, useClickOutside} from '@sanity/ui'
|
|
3
|
-
import {useBoolean} from '@sanity/ui-workshop'
|
|
4
|
-
import React, {useCallback, useState} from 'react'
|
|
5
|
-
|
|
6
|
-
export default function RightAlignedStory() {
|
|
7
|
-
const constrainSize = useBoolean('Constrain size', false)
|
|
8
|
-
|
|
9
|
-
const [open, setOpen] = useState(false)
|
|
10
|
-
const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
|
|
11
|
-
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
|
|
12
|
-
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
|
13
|
-
|
|
14
|
-
const content = (
|
|
15
|
-
<Text>
|
|
16
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque at nisl at sem tempor
|
|
17
|
-
hendrerit scelerisque ut libero. Maecenas iaculis efficitur lorem, ac faucibus mi imperdiet
|
|
18
|
-
quis. Cras a consectetur erat. Fusce imperdiet, dolor et pellentesque iaculis, ex quam luctus
|
|
19
|
-
felis, non ultrices enim sem vitae quam. Duis lorem velit, lacinia at rhoncus a, tempus vel
|
|
20
|
-
neque. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae;
|
|
21
|
-
Sed id mauris quam. Nam finibus sapien non lacinia ultricies. Integer fermentum tortor at
|
|
22
|
-
pellentesque faucibus. In venenatis commodo placerat. Curabitur commodo tortor libero, vel
|
|
23
|
-
pellentesque elit luctus sodales. Donec mattis tristique nunc ac lacinia. Vestibulum non
|
|
24
|
-
pulvinar turpis, posuere consequat arcu. Fusce ut urna blandit, finibus nisi a, molestie elit.
|
|
25
|
-
Nulla sed eleifend mi.
|
|
26
|
-
</Text>
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
const handleToggleOpen = useCallback(() => setOpen((v) => !v), [])
|
|
30
|
-
const handleClose = useCallback(() => setOpen(false), [])
|
|
31
|
-
|
|
32
|
-
useClickOutside(handleClose, [buttonElement, popoverElement])
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<Card height="fill" padding={[4, 5, 6]} sizing="border" tone="transparent">
|
|
36
|
-
<Card height="fill" padding={2} ref={setBoundaryElement} shadow={1}>
|
|
37
|
-
<Flex justify="flex-end" padding={0}>
|
|
38
|
-
<Popover
|
|
39
|
-
boundaryElement={boundaryElement}
|
|
40
|
-
constrainSize={constrainSize}
|
|
41
|
-
content={content}
|
|
42
|
-
open={open}
|
|
43
|
-
padding={3}
|
|
44
|
-
portal
|
|
45
|
-
placement="bottom"
|
|
46
|
-
ref={setPopoverElement}
|
|
47
|
-
>
|
|
48
|
-
<Button
|
|
49
|
-
icon={EllipsisVerticalIcon}
|
|
50
|
-
mode="bleed"
|
|
51
|
-
onClick={handleToggleOpen}
|
|
52
|
-
ref={setButtonElement}
|
|
53
|
-
selected={open}
|
|
54
|
-
/>
|
|
55
|
-
</Popover>
|
|
56
|
-
</Flex>
|
|
57
|
-
</Card>
|
|
58
|
-
</Card>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import {useBoolean, useSelect, useText} from '@sanity/ui-workshop'
|
|
2
|
-
import React, {ReactElement, useState} from 'react'
|
|
3
|
-
import {
|
|
4
|
-
WORKSHOP_CONTAINER_WIDTH_OPTIONS,
|
|
5
|
-
WORKSHOP_PLACEMENT_OPTIONS,
|
|
6
|
-
WORKSHOP_RADIUS_OPTIONS,
|
|
7
|
-
} from '../../../__workshop__/constants'
|
|
8
|
-
import {BoundaryElementProvider, PortalProvider} from '../../../utils'
|
|
9
|
-
import {Button} from '../../button'
|
|
10
|
-
import {Card} from '../../card'
|
|
11
|
-
import {Text} from '../../text'
|
|
12
|
-
import {Popover} from '../popover'
|
|
13
|
-
|
|
14
|
-
export default function TestStory(): ReactElement {
|
|
15
|
-
const [portalElement, setPortalElement] = useState<HTMLDivElement | null>(null)
|
|
16
|
-
const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
|
|
17
|
-
const arrow = useBoolean('Arrow', true)
|
|
18
|
-
const matchReferenceWidth = useBoolean('Match reference width', false)
|
|
19
|
-
const open = useBoolean('Open', true)
|
|
20
|
-
const placement = useSelect('Placement', WORKSHOP_PLACEMENT_OPTIONS, 'bottom')
|
|
21
|
-
const preventOverflow = useBoolean('Prevent overflow', true)
|
|
22
|
-
const radius = useSelect('Radius', WORKSHOP_RADIUS_OPTIONS, 2)
|
|
23
|
-
const referenceWide = useBoolean('Reference wide?', false)
|
|
24
|
-
const width = useSelect('Width', WORKSHOP_CONTAINER_WIDTH_OPTIONS, 'auto')
|
|
25
|
-
|
|
26
|
-
const text = useText('Text', 'Test')
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Card
|
|
30
|
-
ref={setBoundaryElement}
|
|
31
|
-
shadow={2}
|
|
32
|
-
style={{
|
|
33
|
-
position: 'absolute',
|
|
34
|
-
top: 50,
|
|
35
|
-
right: 50,
|
|
36
|
-
bottom: 50,
|
|
37
|
-
left: 50,
|
|
38
|
-
}}
|
|
39
|
-
>
|
|
40
|
-
<div
|
|
41
|
-
data-portal=""
|
|
42
|
-
ref={setPortalElement}
|
|
43
|
-
style={{
|
|
44
|
-
position: 'absolute',
|
|
45
|
-
top: 0,
|
|
46
|
-
right: 0,
|
|
47
|
-
bottom: 0,
|
|
48
|
-
left: 0,
|
|
49
|
-
overflow: 'hidden',
|
|
50
|
-
pointerEvents: 'none',
|
|
51
|
-
}}
|
|
52
|
-
/>
|
|
53
|
-
|
|
54
|
-
<div style={{width: '100%', height: '100%', overflow: 'auto'}}>
|
|
55
|
-
<div style={{padding: '150vh'}}>
|
|
56
|
-
<PortalProvider element={portalElement}>
|
|
57
|
-
<BoundaryElementProvider element={boundaryElement}>
|
|
58
|
-
<Popover
|
|
59
|
-
arrow={arrow}
|
|
60
|
-
content={<Text size={1}>{text}</Text>}
|
|
61
|
-
fallbackPlacements={['left', 'bottom', 'right', 'top']}
|
|
62
|
-
matchReferenceWidth={matchReferenceWidth}
|
|
63
|
-
open={open}
|
|
64
|
-
padding={3}
|
|
65
|
-
placement={placement}
|
|
66
|
-
portal
|
|
67
|
-
preventOverflow={preventOverflow}
|
|
68
|
-
radius={radius}
|
|
69
|
-
width={width}
|
|
70
|
-
>
|
|
71
|
-
<Button text="reference" style={{width: referenceWide ? 300 : undefined}} />
|
|
72
|
-
</Popover>
|
|
73
|
-
</BoundaryElementProvider>
|
|
74
|
-
</PortalProvider>
|
|
75
|
-
</div>
|
|
76
|
-
</div>
|
|
77
|
-
</Card>
|
|
78
|
-
)
|
|
79
|
-
}
|