@sanity/ui 1.3.3 → 1.4.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/index.cjs.mjs +2 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.esm.js +70 -25
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +71 -24
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/primitives/popover/__workshop__/PositionStory.tsx +103 -0
- package/src/primitives/popover/__workshop__/index.ts +5 -0
- package/src/primitives/popover/index.ts +3 -0
- package/src/primitives/popover/popover.test.tsx +164 -0
- package/src/primitives/popover/popover.tsx +8 -0
- package/src/primitives/popover/popoverContext.tsx +9 -0
- package/src/primitives/popover/popoverProvider.tsx +29 -0
- package/src/primitives/popover/types.ts +8 -0
- package/src/primitives/popover/useOnForcedUpdate.ts +15 -0
- package/src/primitives/popover/usePopover.ts +24 -0
package/dist/index.cjs.mjs
CHANGED
|
@@ -36,6 +36,7 @@ export const MenuDivider = cjs.MenuDivider;
|
|
|
36
36
|
export const MenuGroup = cjs.MenuGroup;
|
|
37
37
|
export const MenuItem = cjs.MenuItem;
|
|
38
38
|
export const Popover = cjs.Popover;
|
|
39
|
+
export const PopoverProvider = cjs.PopoverProvider;
|
|
39
40
|
export const Portal = cjs.Portal;
|
|
40
41
|
export const PortalProvider = cjs.PortalProvider;
|
|
41
42
|
export const Radio = cjs.Radio;
|
|
@@ -109,6 +110,7 @@ export const useForwardedRef = cjs.useForwardedRef;
|
|
|
109
110
|
export const useGlobalKeyDown = cjs.useGlobalKeyDown;
|
|
110
111
|
export const useLayer = cjs.useLayer;
|
|
111
112
|
export const useMediaIndex = cjs.useMediaIndex;
|
|
113
|
+
export const usePopover = cjs.usePopover;
|
|
112
114
|
export const usePortal = cjs.usePortal;
|
|
113
115
|
export const usePrefersDark = cjs.usePrefersDark;
|
|
114
116
|
export const usePrefersReducedMotion = cjs.usePrefersReducedMotion;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {HTMLProps} from 'react'
|
|
|
8
8
|
import {MemoExoticComponent} from 'react'
|
|
9
9
|
import {NamedExoticComponent} from 'react'
|
|
10
10
|
import {PropsWithChildren} from 'react'
|
|
11
|
+
import {default as React_2} from 'react'
|
|
11
12
|
import {ReactElement} from 'react'
|
|
12
13
|
import {ReactNode} from 'react'
|
|
13
14
|
import {Ref} from 'react'
|
|
@@ -1343,6 +1344,15 @@ export declare const Popover: MemoExoticComponent<
|
|
|
1343
1344
|
>
|
|
1344
1345
|
>
|
|
1345
1346
|
|
|
1347
|
+
/**
|
|
1348
|
+
* @public
|
|
1349
|
+
*/
|
|
1350
|
+
export declare interface PopoverContextValue {
|
|
1351
|
+
version: number
|
|
1352
|
+
forceUpdate: () => void
|
|
1353
|
+
lastUpdateId: string | null
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1346
1356
|
/**
|
|
1347
1357
|
* @beta
|
|
1348
1358
|
*/
|
|
@@ -1379,6 +1389,18 @@ export declare interface PopoverProps
|
|
|
1379
1389
|
tone?: CardTone
|
|
1380
1390
|
}
|
|
1381
1391
|
|
|
1392
|
+
/**
|
|
1393
|
+
* @public
|
|
1394
|
+
*/
|
|
1395
|
+
export declare const PopoverProvider: ({children}: PopoverProviderProps) => React_2.ReactElement
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* @public
|
|
1399
|
+
*/
|
|
1400
|
+
export declare interface PopoverProviderProps {
|
|
1401
|
+
children?: React_2.ReactNode
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1382
1404
|
/**
|
|
1383
1405
|
* @public
|
|
1384
1406
|
*/
|
|
@@ -2806,6 +2828,11 @@ export declare function useLayer(): LayerContextValue
|
|
|
2806
2828
|
*/
|
|
2807
2829
|
export declare function useMediaIndex(): number
|
|
2808
2830
|
|
|
2831
|
+
/**
|
|
2832
|
+
* @public
|
|
2833
|
+
*/
|
|
2834
|
+
export declare function usePopover(): PopoverContextValue
|
|
2835
|
+
|
|
2809
2836
|
/**
|
|
2810
2837
|
* @public
|
|
2811
2838
|
*/
|
package/dist/index.esm.js
CHANGED
|
@@ -3063,9 +3063,9 @@ function getGlobalScope() {
|
|
|
3063
3063
|
throw new Error("@sanity/ui: could not locate global scope");
|
|
3064
3064
|
}
|
|
3065
3065
|
const globalScope = getGlobalScope();
|
|
3066
|
-
const key$
|
|
3067
|
-
globalScope[key$
|
|
3068
|
-
const ThemeContext = globalScope[key$
|
|
3066
|
+
const key$8 = Symbol.for("@sanity/ui/context/theme");
|
|
3067
|
+
globalScope[key$8] = globalScope[key$8] || createContext(null);
|
|
3068
|
+
const ThemeContext = globalScope[key$8];
|
|
3069
3069
|
function ThemeProvider(props) {
|
|
3070
3070
|
const parentTheme = useContext(ThemeContext);
|
|
3071
3071
|
const {
|
|
@@ -5155,9 +5155,9 @@ const KBD = forwardRef(function KBD2(props, ref) {
|
|
|
5155
5155
|
})
|
|
5156
5156
|
});
|
|
5157
5157
|
});
|
|
5158
|
-
const key$
|
|
5159
|
-
globalScope[key$
|
|
5160
|
-
const BoundaryElementContext = globalScope[key$
|
|
5158
|
+
const key$7 = Symbol.for("@sanity/ui/context/boundaryElement");
|
|
5159
|
+
globalScope[key$7] = globalScope[key$7] || createContext(null);
|
|
5160
|
+
const BoundaryElementContext = globalScope[key$7];
|
|
5161
5161
|
function BoundaryElementProvider(props) {
|
|
5162
5162
|
const {
|
|
5163
5163
|
children,
|
|
@@ -5275,9 +5275,9 @@ function getLayerContext(contextValue) {
|
|
|
5275
5275
|
}
|
|
5276
5276
|
throw new Error("could not get layer context");
|
|
5277
5277
|
}
|
|
5278
|
-
const key$
|
|
5279
|
-
globalScope[key$
|
|
5280
|
-
const LayerContext = globalScope[key$
|
|
5278
|
+
const key$6 = Symbol.for("@sanity/ui/context/layer");
|
|
5279
|
+
globalScope[key$6] = globalScope[key$6] || createContext(null);
|
|
5280
|
+
const LayerContext = globalScope[key$6];
|
|
5281
5281
|
function useLayer() {
|
|
5282
5282
|
const value = useContext(LayerContext);
|
|
5283
5283
|
if (!value) {
|
|
@@ -5514,7 +5514,7 @@ const Layer = forwardRef(function Layer2(props, ref) {
|
|
|
5514
5514
|
})
|
|
5515
5515
|
});
|
|
5516
5516
|
});
|
|
5517
|
-
const key$
|
|
5517
|
+
const key$5 = Symbol.for("@sanity/ui/context/portal");
|
|
5518
5518
|
const elementKey = Symbol.for("@sanity/ui/context/portal/element");
|
|
5519
5519
|
globalScope[elementKey] = null;
|
|
5520
5520
|
const defaultContextValue = {
|
|
@@ -5533,8 +5533,8 @@ const defaultContextValue = {
|
|
|
5533
5533
|
return globalScope[elementKey];
|
|
5534
5534
|
}
|
|
5535
5535
|
};
|
|
5536
|
-
globalScope[key$
|
|
5537
|
-
const PortalContext = globalScope[key$
|
|
5536
|
+
globalScope[key$5] = globalScope[key$5] || createContext(defaultContextValue);
|
|
5537
|
+
const PortalContext = globalScope[key$5];
|
|
5538
5538
|
function usePortal() {
|
|
5539
5539
|
const value = useContext(PortalContext);
|
|
5540
5540
|
if (!value) {
|
|
@@ -5914,6 +5914,17 @@ const PopoverCard = memo(forwardRef(function PopoverCard2(props, ref) {
|
|
|
5914
5914
|
});
|
|
5915
5915
|
}));
|
|
5916
5916
|
PopoverCard.displayName = "PopoverCard";
|
|
5917
|
+
const key$4 = Symbol.for("@sanity/ui/context/popover");
|
|
5918
|
+
globalScope[key$4] = globalScope[key$4] || createContext(null);
|
|
5919
|
+
const PopoverContext = globalScope[key$4];
|
|
5920
|
+
const useOnForcedUpdate = eventHandler => {
|
|
5921
|
+
const contextValue = useContext(PopoverContext);
|
|
5922
|
+
useEffect(() => {
|
|
5923
|
+
if ((contextValue == null ? void 0 : contextValue.lastUpdateId) !== null) {
|
|
5924
|
+
eventHandler == null ? void 0 : eventHandler();
|
|
5925
|
+
}
|
|
5926
|
+
}, [contextValue == null ? void 0 : contextValue.lastUpdateId]);
|
|
5927
|
+
};
|
|
5917
5928
|
const Popover = memo(forwardRef(function Popover2(props, ref) {
|
|
5918
5929
|
var _a, _b, _c, _d, _e;
|
|
5919
5930
|
const theme = useTheme();
|
|
@@ -6020,9 +6031,13 @@ const Popover = memo(forwardRef(function Popover2(props, ref) {
|
|
|
6020
6031
|
placement,
|
|
6021
6032
|
reference: referenceRef,
|
|
6022
6033
|
floating: floatingRef,
|
|
6034
|
+
update: floatingUpdate,
|
|
6023
6035
|
middlewareData,
|
|
6024
6036
|
strategy
|
|
6025
6037
|
} = useFloating(floatingProps);
|
|
6038
|
+
const handleForcedUpdate = useCallback(() => {
|
|
6039
|
+
floatingUpdate();
|
|
6040
|
+
}, [floatingUpdate]);
|
|
6026
6041
|
const referenceHidden = (_c = middlewareData.hide) == null ? void 0 : _c.referenceHidden;
|
|
6027
6042
|
const arrowX = (_d = middlewareData.arrow) == null ? void 0 : _d.x;
|
|
6028
6043
|
const arrowY = (_e = middlewareData.arrow) == null ? void 0 : _e.y;
|
|
@@ -6051,6 +6066,7 @@ const Popover = memo(forwardRef(function Popover2(props, ref) {
|
|
|
6051
6066
|
useEffect(() => {
|
|
6052
6067
|
referenceRef(referenceElement || null);
|
|
6053
6068
|
}, [referenceRef, referenceElement]);
|
|
6069
|
+
useOnForcedUpdate(handleForcedUpdate);
|
|
6054
6070
|
if (disabled) {
|
|
6055
6071
|
return childProp || /* @__PURE__ */jsx(Fragment, {});
|
|
6056
6072
|
}
|
|
@@ -6090,6 +6106,35 @@ const Popover = memo(forwardRef(function Popover2(props, ref) {
|
|
|
6090
6106
|
});
|
|
6091
6107
|
}));
|
|
6092
6108
|
Popover.displayName = "Popover";
|
|
6109
|
+
const PopoverProvider = _ref22 => {
|
|
6110
|
+
let {
|
|
6111
|
+
children
|
|
6112
|
+
} = _ref22;
|
|
6113
|
+
const [lastUpdateId, setUpdateId] = useState(null);
|
|
6114
|
+
const forceUpdate = useCallback(() => {
|
|
6115
|
+
const newId = Math.random().toString(36).substr(2, 9);
|
|
6116
|
+
setUpdateId(newId);
|
|
6117
|
+
}, []);
|
|
6118
|
+
const value = useMemo(() => ({
|
|
6119
|
+
version: 0,
|
|
6120
|
+
lastUpdateId,
|
|
6121
|
+
forceUpdate
|
|
6122
|
+
}), [lastUpdateId, forceUpdate]);
|
|
6123
|
+
return /* @__PURE__ */jsx(PopoverContext.Provider, {
|
|
6124
|
+
value,
|
|
6125
|
+
children
|
|
6126
|
+
});
|
|
6127
|
+
};
|
|
6128
|
+
function usePopover() {
|
|
6129
|
+
const value = useContext(PopoverContext);
|
|
6130
|
+
if (!value) {
|
|
6131
|
+
throw new Error("usePopover(): missing context value");
|
|
6132
|
+
}
|
|
6133
|
+
if (!isRecord(value) || value.version !== 0) {
|
|
6134
|
+
throw new Error("usePopover(): the context value is not compatible");
|
|
6135
|
+
}
|
|
6136
|
+
return value;
|
|
6137
|
+
}
|
|
6093
6138
|
function radioBaseStyle() {
|
|
6094
6139
|
return css(_templateObject36 || (_templateObject36 = _taggedTemplateLiteral(["\n position: relative;\n\n &:not([hidden]) {\n display: inline-block;\n }\n\n &[data-read-only] {\n outline: 1px solid red;\n }\n "])));
|
|
6095
6140
|
}
|
|
@@ -6921,10 +6966,10 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete2(props, ref) {
|
|
|
6921
6966
|
query,
|
|
6922
6967
|
value
|
|
6923
6968
|
} = state;
|
|
6924
|
-
const defaultRenderOption = useCallback(
|
|
6969
|
+
const defaultRenderOption = useCallback(_ref23 => {
|
|
6925
6970
|
let {
|
|
6926
6971
|
value: value2
|
|
6927
|
-
} =
|
|
6972
|
+
} = _ref23;
|
|
6928
6973
|
return /* @__PURE__ */jsx(Card, {
|
|
6929
6974
|
"data-as": "button",
|
|
6930
6975
|
padding: paddingProp,
|
|
@@ -7371,10 +7416,10 @@ const Breadcrumbs = forwardRef(function Breadcrumbs2(props, ref) {
|
|
|
7371
7416
|
}, itemIndex))
|
|
7372
7417
|
});
|
|
7373
7418
|
});
|
|
7374
|
-
function dialogStyle(
|
|
7419
|
+
function dialogStyle(_ref24) {
|
|
7375
7420
|
let {
|
|
7376
7421
|
theme
|
|
7377
|
-
} =
|
|
7422
|
+
} = _ref24;
|
|
7378
7423
|
const color = theme.sanity.color.base;
|
|
7379
7424
|
return {
|
|
7380
7425
|
"&:not([hidden])": {
|
|
@@ -8394,15 +8439,15 @@ const MenuItem = forwardRef(function MenuItem2(props, forwardedRef) {
|
|
|
8394
8439
|
});
|
|
8395
8440
|
const keyframe = keyframes(_templateObject78 || (_templateObject78 = _taggedTemplateLiteral(["\n 0% {\n background-position: 100%;\n }\n 100% {\n background-position: -100%;\n }\n"])));
|
|
8396
8441
|
const animation = css(_templateObject79 || (_templateObject79 = _taggedTemplateLiteral(["\n background-image: linear-gradient(\n to right,\n var(--card-skeleton-color-from),\n var(--card-skeleton-color-to),\n var(--card-skeleton-color-from),\n var(--card-skeleton-color-from),\n var(--card-skeleton-color-from)\n );\n background-position: 100%;\n background-size: 200% 100%;\n background-attachment: fixed;\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n animation-iteration-count: infinite;\n animation-duration: 2000ms;\n"])), keyframe);
|
|
8397
|
-
const skeletonStyle = css(_templateObject80 || (_templateObject80 = _taggedTemplateLiteral(["\n opacity: ", ";\n transition: opacity 200ms ease-in;\n\n @media screen and (prefers-reduced-motion: no-preference) {\n ", "\n }\n\n @media screen and (prefers-reduced-motion: reduce) {\n background-color: var(--card-skeleton-color-from);\n }\n"])),
|
|
8442
|
+
const skeletonStyle = css(_templateObject80 || (_templateObject80 = _taggedTemplateLiteral(["\n opacity: ", ";\n transition: opacity 200ms ease-in;\n\n @media screen and (prefers-reduced-motion: no-preference) {\n ", "\n }\n\n @media screen and (prefers-reduced-motion: reduce) {\n background-color: var(--card-skeleton-color-from);\n }\n"])), _ref25 => {
|
|
8398
8443
|
let {
|
|
8399
8444
|
$visible
|
|
8400
|
-
} =
|
|
8445
|
+
} = _ref25;
|
|
8401
8446
|
return $visible ? 1 : 0;
|
|
8402
|
-
},
|
|
8447
|
+
}, _ref26 => {
|
|
8403
8448
|
let {
|
|
8404
8449
|
$animated
|
|
8405
|
-
} =
|
|
8450
|
+
} = _ref26;
|
|
8406
8451
|
return $animated ? animation : css(_templateObject81 || (_templateObject81 = _taggedTemplateLiteral(["\n background-color: var(--card-skeleton-color-from);\n "])));
|
|
8407
8452
|
});
|
|
8408
8453
|
const Root$4 = styled(Box)(responsiveRadiusStyle, skeletonStyle);
|
|
@@ -8433,12 +8478,12 @@ const Skeleton = forwardRef(function Skeleton2(props, ref) {
|
|
|
8433
8478
|
ref
|
|
8434
8479
|
});
|
|
8435
8480
|
});
|
|
8436
|
-
const Root$3 = styled(Skeleton)(
|
|
8481
|
+
const Root$3 = styled(Skeleton)(_ref27 => {
|
|
8437
8482
|
let {
|
|
8438
8483
|
$size,
|
|
8439
8484
|
$style,
|
|
8440
8485
|
theme
|
|
8441
|
-
} =
|
|
8486
|
+
} = _ref27;
|
|
8442
8487
|
const {
|
|
8443
8488
|
media
|
|
8444
8489
|
} = theme.sanity;
|
|
@@ -8759,12 +8804,12 @@ function ToastProvider(props) {
|
|
|
8759
8804
|
paddingY,
|
|
8760
8805
|
children: /* @__PURE__ */jsx(AnimatePresence, {
|
|
8761
8806
|
initial: false,
|
|
8762
|
-
children: state.map(
|
|
8807
|
+
children: state.map(_ref28 => {
|
|
8763
8808
|
let {
|
|
8764
8809
|
dismiss,
|
|
8765
8810
|
id,
|
|
8766
8811
|
params
|
|
8767
|
-
} =
|
|
8812
|
+
} = _ref28;
|
|
8768
8813
|
return /* @__PURE__ */jsx(motion.div, {
|
|
8769
8814
|
animate: {
|
|
8770
8815
|
opacity: 1,
|
|
@@ -9244,5 +9289,5 @@ const TreeItem = memo(function TreeItem2(props) {
|
|
|
9244
9289
|
})]
|
|
9245
9290
|
});
|
|
9246
9291
|
});
|
|
9247
|
-
export { Autocomplete, Avatar, AvatarCounter, AvatarStack, Badge, BoundaryElementProvider, Box, Breadcrumbs, Button, Card, Checkbox, Code, CodeSkeleton, Container, Dialog, DialogContext, DialogProvider, ElementQuery, ErrorBoundary, Flex, Grid, Heading, HeadingSkeleton, Hotkeys, Inline, KBD, Label, LabelSkeleton, Layer, LayerProvider, Menu, MenuButton, MenuDivider, MenuGroup, MenuItem, Popover, Portal, PortalProvider, Radio, Select, Skeleton, Spinner, SrOnly, Stack, Switch, Tab, TabList, TabPanel, Text, TextArea, TextInput, TextSkeleton, ThemeColorProvider, ThemeProvider, Toast, ToastProvider, Tooltip, Tree, TreeItem, VirtualList, _ResizeObserver, _elementSizeObserver, _fillCSSObject, _getArrayProp, _getResponsiveSpace, _hasFocus, _isEnterToClickElement, _isScrollable, _raf, _raf2, _responsive, attemptFocus, containsOrEqualsElement, createColorTheme, focusFirstDescendant, focusLastDescendant, hexToRgb, hslToRgb, isFocusable, isHTMLAnchorElement, isHTMLButtonElement, isHTMLElement, isHTMLInputElement, isHTMLSelectElement, isHTMLTextAreaElement, multiply$1 as multiply, parseColor, rem, responsiveCodeFontStyle, responsiveHeadingFont, responsiveLabelFont, responsiveTextAlignStyle, responsiveTextFont, rgbToHex, rgbToHsl, rgba, screen$1 as screen, studioTheme, useArrayProp, useBoundaryElement, useClickOutside, useCustomValidity, useDialog, useElementRect, useElementSize, useForwardedRef, useGlobalKeyDown, useLayer, useMediaIndex, usePortal, usePrefersDark, usePrefersReducedMotion, useRootTheme, useTheme, useToast, useTree };
|
|
9292
|
+
export { Autocomplete, Avatar, AvatarCounter, AvatarStack, Badge, BoundaryElementProvider, Box, Breadcrumbs, Button, Card, Checkbox, Code, CodeSkeleton, Container, Dialog, DialogContext, DialogProvider, ElementQuery, ErrorBoundary, Flex, Grid, Heading, HeadingSkeleton, Hotkeys, Inline, KBD, Label, LabelSkeleton, Layer, LayerProvider, Menu, MenuButton, MenuDivider, MenuGroup, MenuItem, Popover, PopoverProvider, Portal, PortalProvider, Radio, Select, Skeleton, Spinner, SrOnly, Stack, Switch, Tab, TabList, TabPanel, Text, TextArea, TextInput, TextSkeleton, ThemeColorProvider, ThemeProvider, Toast, ToastProvider, Tooltip, Tree, TreeItem, VirtualList, _ResizeObserver, _elementSizeObserver, _fillCSSObject, _getArrayProp, _getResponsiveSpace, _hasFocus, _isEnterToClickElement, _isScrollable, _raf, _raf2, _responsive, attemptFocus, containsOrEqualsElement, createColorTheme, focusFirstDescendant, focusLastDescendant, hexToRgb, hslToRgb, isFocusable, isHTMLAnchorElement, isHTMLButtonElement, isHTMLElement, isHTMLInputElement, isHTMLSelectElement, isHTMLTextAreaElement, multiply$1 as multiply, parseColor, rem, responsiveCodeFontStyle, responsiveHeadingFont, responsiveLabelFont, responsiveTextAlignStyle, responsiveTextFont, rgbToHex, rgbToHsl, rgba, screen$1 as screen, studioTheme, useArrayProp, useBoundaryElement, useClickOutside, useCustomValidity, useDialog, useElementRect, useElementSize, useForwardedRef, useGlobalKeyDown, useLayer, useMediaIndex, usePopover, usePortal, usePrefersDark, usePrefersReducedMotion, useRootTheme, useTheme, useToast, useTree };
|
|
9248
9293
|
//# sourceMappingURL=index.esm.js.map
|