@sanity/ui 1.7.12 → 1.8.1
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 +3 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.esm.js +105 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +107 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useDelayed.test.ts +66 -0
- package/src/hooks/useDelayedState.ts +29 -0
- package/src/primitives/textInput/textInput.tsx +7 -1
- package/src/primitives/tooltip/__workshop__/props.tsx +86 -11
- package/src/primitives/tooltip/index.ts +1 -0
- package/src/primitives/tooltip/tooltip.test.tsx +278 -0
- package/src/primitives/tooltip/tooltip.tsx +59 -12
- package/src/primitives/tooltip/tooltipDelayGroup/index.ts +4 -0
- package/src/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupContext.tsx +13 -0
- package/src/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +61 -0
- package/src/primitives/tooltip/tooltipDelayGroup/types.ts +11 -0
- package/src/primitives/tooltip/tooltipDelayGroup/useTooltipDelayGroup.ts +12 -0
- package/src/primitives/types.ts +10 -0
package/dist/index.js
CHANGED
|
@@ -3074,9 +3074,9 @@ function getGlobalScope() {
|
|
|
3074
3074
|
throw new Error("@sanity/ui: could not locate global scope");
|
|
3075
3075
|
}
|
|
3076
3076
|
const globalScope = getGlobalScope();
|
|
3077
|
-
const key$
|
|
3078
|
-
globalScope[key$
|
|
3079
|
-
const ThemeContext = globalScope[key$
|
|
3077
|
+
const key$8 = Symbol.for("@sanity/ui/context/theme");
|
|
3078
|
+
globalScope[key$8] = globalScope[key$8] || react.createContext(null);
|
|
3079
|
+
const ThemeContext = globalScope[key$8];
|
|
3080
3080
|
function ThemeProvider(props) {
|
|
3081
3081
|
const parentTheme = react.useContext(ThemeContext);
|
|
3082
3082
|
const {
|
|
@@ -5269,9 +5269,9 @@ const KBD = react.forwardRef(function KBD2(props, ref) {
|
|
|
5269
5269
|
})
|
|
5270
5270
|
});
|
|
5271
5271
|
});
|
|
5272
|
-
const key$
|
|
5273
|
-
globalScope[key$
|
|
5274
|
-
const BoundaryElementContext = globalScope[key$
|
|
5272
|
+
const key$7 = Symbol.for("@sanity/ui/context/boundaryElement");
|
|
5273
|
+
globalScope[key$7] = globalScope[key$7] || react.createContext(null);
|
|
5274
|
+
const BoundaryElementContext = globalScope[key$7];
|
|
5275
5275
|
function BoundaryElementProvider(props) {
|
|
5276
5276
|
const {
|
|
5277
5277
|
children,
|
|
@@ -5400,9 +5400,9 @@ function getLayerContext(contextValue) {
|
|
|
5400
5400
|
}
|
|
5401
5401
|
throw new Error("could not get layer context");
|
|
5402
5402
|
}
|
|
5403
|
-
const key$
|
|
5404
|
-
globalScope[key$
|
|
5405
|
-
const LayerContext = globalScope[key$
|
|
5403
|
+
const key$6 = Symbol.for("@sanity/ui/context/layer");
|
|
5404
|
+
globalScope[key$6] = globalScope[key$6] || react.createContext(null);
|
|
5405
|
+
const LayerContext = globalScope[key$6];
|
|
5406
5406
|
function useLayer() {
|
|
5407
5407
|
const value = react.useContext(LayerContext);
|
|
5408
5408
|
if (!value) {
|
|
@@ -5639,7 +5639,7 @@ const Layer = react.forwardRef(function Layer2(props, ref) {
|
|
|
5639
5639
|
})
|
|
5640
5640
|
});
|
|
5641
5641
|
});
|
|
5642
|
-
const key$
|
|
5642
|
+
const key$5 = Symbol.for("@sanity/ui/context/portal");
|
|
5643
5643
|
const elementKey = Symbol.for("@sanity/ui/context/portal/element");
|
|
5644
5644
|
globalScope[elementKey] = null;
|
|
5645
5645
|
const defaultContextValue = {
|
|
@@ -5658,8 +5658,8 @@ const defaultContextValue = {
|
|
|
5658
5658
|
return globalScope[elementKey];
|
|
5659
5659
|
}
|
|
5660
5660
|
};
|
|
5661
|
-
globalScope[key$
|
|
5662
|
-
const PortalContext = globalScope[key$
|
|
5661
|
+
globalScope[key$5] = globalScope[key$5] || react.createContext(defaultContextValue);
|
|
5662
|
+
const PortalContext = globalScope[key$5];
|
|
5663
5663
|
function usePortal() {
|
|
5664
5664
|
const value = react.useContext(PortalContext);
|
|
5665
5665
|
if (!value) {
|
|
@@ -6681,6 +6681,11 @@ const Presentation = styled__default.default.span(responsiveRadiusStyle, textInp
|
|
|
6681
6681
|
const LeftBox = styled__default.default(Box)(_d$3 || (_d$3 = __template$g(["\n position: absolute;\n top: 0;\n left: 0;\n"])));
|
|
6682
6682
|
const RightBox = styled__default.default(Box)(_e$1 || (_e$1 = __template$g(["\n position: absolute;\n top: 0;\n right: 0;\n"])));
|
|
6683
6683
|
const RightCard = styled__default.default(Card)(_f$1 || (_f$1 = __template$g(["\n background-color: transparent;\n position: absolute;\n top: 0;\n right: 0;\n"])));
|
|
6684
|
+
const TextInputClearButton = styled__default.default(Button)({
|
|
6685
|
+
"&:not([hidden])": {
|
|
6686
|
+
display: "block"
|
|
6687
|
+
}
|
|
6688
|
+
});
|
|
6684
6689
|
const TextInput = react.forwardRef(function TextInput2(props, forwardedRef) {
|
|
6685
6690
|
const {
|
|
6686
6691
|
border = true,
|
|
@@ -6776,7 +6781,7 @@ const TextInput = react.forwardRef(function TextInput2(props, forwardedRef) {
|
|
|
6776
6781
|
padding: clearButtonBoxPadding,
|
|
6777
6782
|
style: CLEAR_BUTTON_BOX_STYLE,
|
|
6778
6783
|
tone: customValidity ? "critical" : "inherit",
|
|
6779
|
-
children: /* @__PURE__ */jsxRuntime.jsx(
|
|
6784
|
+
children: /* @__PURE__ */jsxRuntime.jsx(TextInputClearButton, {
|
|
6780
6785
|
"aria-label": "Clear",
|
|
6781
6786
|
"data-qa": "clear-button",
|
|
6782
6787
|
fontSize,
|
|
@@ -6825,6 +6830,22 @@ const TextInput = react.forwardRef(function TextInput2(props, forwardedRef) {
|
|
|
6825
6830
|
}), suffixNode]
|
|
6826
6831
|
});
|
|
6827
6832
|
});
|
|
6833
|
+
function useDelayedState(initialState) {
|
|
6834
|
+
const [state, setState] = react.useState(initialState);
|
|
6835
|
+
const delayedAction = react.useRef();
|
|
6836
|
+
const onStateChange = react.useCallback((nextState, delay) => {
|
|
6837
|
+
const action = () => {
|
|
6838
|
+
setState(nextState);
|
|
6839
|
+
};
|
|
6840
|
+
if (delayedAction.current) {
|
|
6841
|
+
clearTimeout(delayedAction.current);
|
|
6842
|
+
delayedAction.current = void 0;
|
|
6843
|
+
}
|
|
6844
|
+
if (!delay) return action();
|
|
6845
|
+
delayedAction.current = setTimeout(action, delay);
|
|
6846
|
+
}, []);
|
|
6847
|
+
return [state, onStateChange];
|
|
6848
|
+
}
|
|
6828
6849
|
var __freeze$f = Object.freeze;
|
|
6829
6850
|
var __defProp$f = Object.defineProperty;
|
|
6830
6851
|
var __template$f = (cooked, raw) => __freeze$f(__defProp$f(cooked, "raw", {
|
|
@@ -6854,6 +6875,40 @@ const TooltipArrow = react.forwardRef(function TooltipArrow2(props, ref) {
|
|
|
6854
6875
|
})
|
|
6855
6876
|
});
|
|
6856
6877
|
});
|
|
6878
|
+
const key$4 = Symbol.for("@sanity/ui/context/tooltipDelayGroup");
|
|
6879
|
+
globalScope[key$4] = globalScope[key$4] || react.createContext(null);
|
|
6880
|
+
const TooltipDelayGroupContext = globalScope[key$4];
|
|
6881
|
+
function useTooltipDelayGroup() {
|
|
6882
|
+
const value = react.useContext(TooltipDelayGroupContext);
|
|
6883
|
+
return value;
|
|
6884
|
+
}
|
|
6885
|
+
function TooltipDelayGroupProvider(props) {
|
|
6886
|
+
const {
|
|
6887
|
+
children,
|
|
6888
|
+
delay
|
|
6889
|
+
} = props;
|
|
6890
|
+
const [isGroupActive, setIsGroupActive] = useDelayedState(false);
|
|
6891
|
+
const [openTooltipId, setOpenTooltipId] = useDelayedState(null);
|
|
6892
|
+
const isInsideContext = useTooltipDelayGroup();
|
|
6893
|
+
if (isInsideContext) {
|
|
6894
|
+
throw new Error("TooltipDelayGroupProvider cannot be nested inside another TooltipDelayGroupProvider");
|
|
6895
|
+
}
|
|
6896
|
+
const openDelay = typeof delay === "number" ? delay : (delay == null ? void 0 : delay.open) || 0;
|
|
6897
|
+
const closeDelay = typeof delay === "number" ? delay : (delay == null ? void 0 : delay.close) || 0;
|
|
6898
|
+
const value = react.useMemo(() => ({
|
|
6899
|
+
isGroupActive,
|
|
6900
|
+
setIsGroupActive,
|
|
6901
|
+
openTooltipId,
|
|
6902
|
+
setOpenTooltipId,
|
|
6903
|
+
// When the group is active, we want the next tooltip to open immediately.
|
|
6904
|
+
openDelay: isGroupActive ? 1 : openDelay,
|
|
6905
|
+
closeDelay
|
|
6906
|
+
}), [closeDelay, isGroupActive, openDelay, openTooltipId, setIsGroupActive, setOpenTooltipId]);
|
|
6907
|
+
return /* @__PURE__ */jsxRuntime.jsx(TooltipDelayGroupContext.Provider, {
|
|
6908
|
+
value,
|
|
6909
|
+
children
|
|
6910
|
+
});
|
|
6911
|
+
}
|
|
6857
6912
|
var __freeze$e = Object.freeze;
|
|
6858
6913
|
var __defProp$e = Object.defineProperty;
|
|
6859
6914
|
var __template$e = (cooked, raw) => __freeze$e(__defProp$e(cooked, "raw", {
|
|
@@ -6877,6 +6932,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
6877
6932
|
scheme,
|
|
6878
6933
|
shadow = 2,
|
|
6879
6934
|
zOffset = (_a2 = theme.sanity.layer) == null ? void 0 : _a2.tooltip.zOffset,
|
|
6935
|
+
delay,
|
|
6880
6936
|
...restProps
|
|
6881
6937
|
} = props;
|
|
6882
6938
|
const fallbackPlacements = useArrayProp(fallbackPlacementsProp);
|
|
@@ -6947,18 +7003,41 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
6947
7003
|
if (staticSide) style[staticSide] = -15;
|
|
6948
7004
|
return style;
|
|
6949
7005
|
}, [arrowX, arrowY, staticSide]);
|
|
6950
|
-
const
|
|
6951
|
-
const
|
|
6952
|
-
const
|
|
6953
|
-
const
|
|
6954
|
-
const
|
|
7006
|
+
const tooltipId = react.useId();
|
|
7007
|
+
const [isOpen, setIsOpen] = useDelayedState(false);
|
|
7008
|
+
const delayGroupContext = useTooltipDelayGroup();
|
|
7009
|
+
const showTooltip = isOpen || (delayGroupContext == null ? void 0 : delayGroupContext.openTooltipId) === tooltipId;
|
|
7010
|
+
const isInsideGroup = delayGroupContext !== null;
|
|
7011
|
+
const openDelayProp = typeof delay === "number" ? delay : (delay == null ? void 0 : delay.open) || 0;
|
|
7012
|
+
const closeDelayProp = typeof delay === "number" ? delay : (delay == null ? void 0 : delay.close) || 0;
|
|
7013
|
+
const openDelay = isInsideGroup ? delayGroupContext.openDelay : openDelayProp;
|
|
7014
|
+
const closeDelay = isInsideGroup ? delayGroupContext.closeDelay : closeDelayProp;
|
|
7015
|
+
const handleIsOpenChange = react.useCallback(open => {
|
|
7016
|
+
if (isInsideGroup) {
|
|
7017
|
+
if (open) {
|
|
7018
|
+
delayGroupContext.setIsGroupActive(open, openDelay);
|
|
7019
|
+
delayGroupContext.setOpenTooltipId(tooltipId, openDelay);
|
|
7020
|
+
} else {
|
|
7021
|
+
const minimumGroupDeactivateDelay = 200;
|
|
7022
|
+
const groupDeactivateDelay = closeDelay > minimumGroupDeactivateDelay ? closeDelay : minimumGroupDeactivateDelay;
|
|
7023
|
+
delayGroupContext.setIsGroupActive(open, groupDeactivateDelay);
|
|
7024
|
+
delayGroupContext.setOpenTooltipId(null, closeDelay);
|
|
7025
|
+
}
|
|
7026
|
+
} else {
|
|
7027
|
+
setIsOpen(open, open ? openDelay : closeDelay);
|
|
7028
|
+
}
|
|
7029
|
+
}, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
|
|
7030
|
+
const handleBlur = react.useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
|
|
7031
|
+
const handleFocus = react.useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
|
|
7032
|
+
const handleMouseEnter = react.useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
|
|
7033
|
+
const handleMouseLeave = react.useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
|
|
6955
7034
|
react.useEffect(() => {
|
|
6956
7035
|
if (!isOpen) return;
|
|
6957
7036
|
function handleWindowMouseMove(event) {
|
|
6958
7037
|
if (!referenceElement) return;
|
|
6959
7038
|
const isHoveringReference = referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target);
|
|
6960
7039
|
if (!isHoveringReference) {
|
|
6961
|
-
|
|
7040
|
+
handleIsOpenChange(false);
|
|
6962
7041
|
window.removeEventListener("mousemove", handleWindowMouseMove);
|
|
6963
7042
|
}
|
|
6964
7043
|
}
|
|
@@ -6966,13 +7045,13 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
6966
7045
|
return () => {
|
|
6967
7046
|
window.removeEventListener("mousemove", handleWindowMouseMove);
|
|
6968
7047
|
};
|
|
6969
|
-
}, [isOpen, referenceElement]);
|
|
7048
|
+
}, [isOpen, referenceElement, handleIsOpenChange]);
|
|
6970
7049
|
react.useEffect(() => {
|
|
6971
|
-
if (disabled)
|
|
6972
|
-
}, [disabled]);
|
|
7050
|
+
if (disabled) handleIsOpenChange(false);
|
|
7051
|
+
}, [disabled, handleIsOpenChange]);
|
|
6973
7052
|
react.useEffect(() => {
|
|
6974
|
-
if (!content)
|
|
6975
|
-
}, [content]);
|
|
7053
|
+
if (!content) handleIsOpenChange(false);
|
|
7054
|
+
}, [content, handleIsOpenChange]);
|
|
6976
7055
|
react.useEffect(() => refs.setReference(referenceElement), [referenceElement, refs]);
|
|
6977
7056
|
const setArrow = react.useCallback(arrowEl => {
|
|
6978
7057
|
arrowRef.current = arrowEl;
|
|
@@ -7023,7 +7102,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
7023
7102
|
})
|
|
7024
7103
|
});
|
|
7025
7104
|
return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
7026
|
-
children: [child,
|
|
7105
|
+
children: [child, showTooltip && /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
7027
7106
|
children: portal ? /* @__PURE__ */jsxRuntime.jsx(Portal, {
|
|
7028
7107
|
__unstable_name: typeof portal === "string" ? portal : void 0,
|
|
7029
7108
|
children: root
|
|
@@ -9659,6 +9738,8 @@ exports.ThemeProvider = ThemeProvider;
|
|
|
9659
9738
|
exports.Toast = Toast;
|
|
9660
9739
|
exports.ToastProvider = ToastProvider;
|
|
9661
9740
|
exports.Tooltip = Tooltip;
|
|
9741
|
+
exports.TooltipDelayGroupContext = TooltipDelayGroupContext;
|
|
9742
|
+
exports.TooltipDelayGroupProvider = TooltipDelayGroupProvider;
|
|
9662
9743
|
exports.Tree = Tree;
|
|
9663
9744
|
exports.TreeItem = TreeItem;
|
|
9664
9745
|
exports.VirtualList = VirtualList;
|
|
@@ -9717,5 +9798,6 @@ exports.usePrefersReducedMotion = usePrefersReducedMotion;
|
|
|
9717
9798
|
exports.useRootTheme = useRootTheme;
|
|
9718
9799
|
exports.useTheme = useTheme;
|
|
9719
9800
|
exports.useToast = useToast;
|
|
9801
|
+
exports.useTooltipDelayGroup = useTooltipDelayGroup;
|
|
9720
9802
|
exports.useTree = useTree;
|
|
9721
9803
|
//# sourceMappingURL=index.js.map
|