@sanity/ui 2.3.1 → 2.3.3

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.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { buildTheme, createColorTheme as createColorTheme$1, hexToRgb as hexToRgb$1, hslToRgb as hslToRgb$1, multiply as multiply$1, parseColor as parseColor$1, rgbToHex as rgbToHex$1, rgbToHsl as rgbToHsl$1, rgba as rgba$1, screen as screen$1, getTheme_v2, getScopedTheme } from "@sanity/ui/theme";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import { useMemo, useState, useRef, useEffect, createContext, useContext, useSyncExternalStore, useImperativeHandle, forwardRef, useId, useCallback, cloneElement, isValidElement, createElement, Component, memo, useReducer, Children, Fragment as Fragment$1, startTransition } from "react";
3
+ import { useMemo, useState, useRef, useEffect, createContext, useContext, useSyncExternalStore, useImperativeHandle, forwardRef, useId, useCallback, cloneElement, isValidElement, Component, memo, useReducer, Children, Fragment as Fragment$1, startTransition } from "react";
4
4
  import ReactIs, { isElement as isElement$1, isFragment, isValidElementType } from "react-is";
5
5
  import { ThemeProvider as ThemeProvider$1, useTheme as useTheme$1, css, styled, keyframes } from "styled-components";
6
6
  import { SpinnerIcon, CheckmarkIcon, RemoveIcon, ChevronDownIcon, CloseIcon, ChevronRightIcon, ToggleArrowRightIcon } from "@sanity/icons";
@@ -630,7 +630,8 @@ function useForwardedRef(ref) {
630
630
  }
631
631
  function useCustomValidity(ref, customValidity) {
632
632
  useEffect(() => {
633
- ref.current && ref.current.setCustomValidity(customValidity || "");
633
+ var _a;
634
+ (_a = ref.current) == null || _a.setCustomValidity(customValidity || "");
634
635
  }, [customValidity, ref]);
635
636
  }
636
637
  function responsiveBorderStyle() {
@@ -1995,8 +1996,8 @@ const Root$t = styled.button(responsiveRadiusStyle, buttonBaseStyles, buttonColo
1995
1996
  children,
1996
1997
  disabled,
1997
1998
  fontSize: fontSize2 = 1,
1998
- icon,
1999
- iconRight,
1999
+ icon: IconComponent,
2000
+ iconRight: IconRightComponent,
2000
2001
  justify: justifyProp = "center",
2001
2002
  loading,
2002
2003
  mode = "default",
@@ -2046,10 +2047,10 @@ const Root$t = styled.button(responsiveRadiusStyle, buttonBaseStyles, buttonColo
2046
2047
  $width: width,
2047
2048
  children: [
2048
2049
  !!loading && /* @__PURE__ */ jsx(LoadingBox, { children: /* @__PURE__ */ jsx(Spinner, {}) }),
2049
- (icon || text || iconRight) && /* @__PURE__ */ jsx(Box, { as: "span", ...boxProps, children: /* @__PURE__ */ jsxs(Flex, { as: "span", justify, gap: space, children: [
2050
- icon && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
2051
- isValidElement(icon) && icon,
2052
- isValidElementType(icon) && createElement(icon)
2050
+ (IconComponent || text || IconRightComponent) && /* @__PURE__ */ jsx(Box, { as: "span", ...boxProps, children: /* @__PURE__ */ jsxs(Flex, { as: "span", justify, gap: space, children: [
2051
+ IconComponent && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
2052
+ isValidElement(IconComponent) && IconComponent,
2053
+ isValidElementType(IconComponent) && /* @__PURE__ */ jsx(IconComponent, {})
2053
2054
  ] }),
2054
2055
  text && /* @__PURE__ */ jsx(
2055
2056
  Text,
@@ -2062,9 +2063,9 @@ const Root$t = styled.button(responsiveRadiusStyle, buttonBaseStyles, buttonColo
2062
2063
  children: text
2063
2064
  }
2064
2065
  ),
2065
- iconRight && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
2066
- isValidElement(iconRight) && iconRight,
2067
- isValidElementType(iconRight) && createElement(iconRight)
2066
+ IconRightComponent && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
2067
+ isValidElement(IconRightComponent) && IconRightComponent,
2068
+ isValidElementType(IconRightComponent) && /* @__PURE__ */ jsx(IconRightComponent, {})
2068
2069
  ] })
2069
2070
  ] }) }),
2070
2071
  children && /* @__PURE__ */ jsx(Box, { as: "span", ...boxProps, children })
@@ -4076,8 +4077,8 @@ const Root$d = styled.span(switchBaseStyles), Input$2 = styled.input(switchInput
4076
4077
  clearButton,
4077
4078
  disabled = !1,
4078
4079
  fontSize: fontSizeProp = 2,
4079
- icon,
4080
- iconRight,
4080
+ icon: IconComponent,
4081
+ iconRight: IconRightComponent,
4081
4082
  onClear,
4082
4083
  padding: paddingProp = 3,
4083
4084
  prefix,
@@ -4089,7 +4090,7 @@ const Root$d = styled.span(switchBaseStyles), Input$2 = styled.input(switchInput
4089
4090
  type = "text",
4090
4091
  weight,
4091
4092
  ...restProps
4092
- } = props, ref = useRef(null), rootTheme = useRootTheme(), fontSize2 = useArrayProp(fontSizeProp), padding = useArrayProp(paddingProp), radius = useArrayProp(radiusProp), space = useArrayProp(spaceProp), $hasClearButton = !!clearButton, $hasIcon = !!icon, $hasIconRight = !!iconRight, $hasSuffix = !!suffix, $hasPrefix = !!prefix;
4093
+ } = props, ref = useRef(null), rootTheme = useRootTheme(), fontSize2 = useArrayProp(fontSizeProp), padding = useArrayProp(paddingProp), radius = useArrayProp(radiusProp), space = useArrayProp(spaceProp), $hasClearButton = !!clearButton, $hasIcon = !!IconComponent, $hasIconRight = !!IconRightComponent, $hasSuffix = !!suffix, $hasPrefix = !!prefix;
4093
4094
  useImperativeHandle(
4094
4095
  forwardedRef,
4095
4096
  () => ref.current
@@ -4119,13 +4120,13 @@ const Root$d = styled.span(switchBaseStyles), Input$2 = styled.input(switchInput
4119
4120
  "data-scheme": rootTheme.scheme,
4120
4121
  "data-tone": rootTheme.tone,
4121
4122
  children: [
4122
- icon && /* @__PURE__ */ jsx(LeftBox, { padding, children: /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
4123
- isValidElement(icon) && icon,
4124
- isValidElementType(icon) && createElement(icon)
4123
+ IconComponent && /* @__PURE__ */ jsx(LeftBox, { padding, children: /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
4124
+ isValidElement(IconComponent) && IconComponent,
4125
+ isValidElementType(IconComponent) && /* @__PURE__ */ jsx(IconComponent, {})
4125
4126
  ] }) }),
4126
- !$hasClearButton && iconRight && /* @__PURE__ */ jsx(RightBox, { padding, children: /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
4127
- isValidElement(iconRight) && iconRight,
4128
- isValidElementType(iconRight) && createElement(iconRight)
4127
+ !$hasClearButton && IconRightComponent && /* @__PURE__ */ jsx(RightBox, { padding, children: /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
4128
+ isValidElement(IconRightComponent) && IconRightComponent,
4129
+ isValidElementType(IconRightComponent) && /* @__PURE__ */ jsx(IconRightComponent, {})
4129
4130
  ] }) })
4130
4131
  ]
4131
4132
  }
@@ -4134,8 +4135,8 @@ const Root$d = styled.span(switchBaseStyles), Input$2 = styled.input(switchInput
4134
4135
  __unstable_disableFocusRing,
4135
4136
  border2,
4136
4137
  fontSize2,
4137
- icon,
4138
- iconRight,
4138
+ IconComponent,
4139
+ IconRightComponent,
4139
4140
  padding,
4140
4141
  radius,
4141
4142
  rootTheme,
@@ -4474,19 +4475,14 @@ const Root$a = styled(Layer)`
4474
4475
  ref.current = node, refs.setFloating(node);
4475
4476
  },
4476
4477
  [refs]
4477
- ), childRef = childProp == null ? void 0 : childProp.ref, setReference = useCallback(
4478
- (node) => {
4479
- typeof childRef == "function" ? childRef(node) : childRef && (childRef.current = node), setReferenceElement(node);
4480
- },
4481
- [childRef]
4482
- ), child = useMemo(() => childProp ? cloneElement(childProp, {
4478
+ ), childRef = useRef(null), child = useMemo(() => childProp ? cloneElement(childProp, {
4483
4479
  onBlur: handleBlur,
4484
4480
  onFocus: handleFocus,
4485
4481
  onMouseEnter: handleMouseEnter,
4486
4482
  onMouseLeave: handleMouseLeave,
4487
4483
  onClick: handleClick,
4488
4484
  onContextMenu: handleContextMenu,
4489
- ref: setReference
4485
+ ref: childRef
4490
4486
  }) : null, [
4491
4487
  childProp,
4492
4488
  handleBlur,
@@ -4494,10 +4490,12 @@ const Root$a = styled(Layer)`
4494
4490
  handleContextMenu,
4495
4491
  handleFocus,
4496
4492
  handleMouseEnter,
4497
- handleMouseLeave,
4498
- setReference
4493
+ handleMouseLeave
4499
4494
  ]);
4500
- if (!child) return /* @__PURE__ */ jsx(Fragment, {});
4495
+ if (useEffect(() => {
4496
+ if (child)
4497
+ return setReferenceElement(childRef.current), () => setReferenceElement(null);
4498
+ }, [child]), !child) return /* @__PURE__ */ jsx(Fragment, {});
4501
4499
  if (disabled) return child;
4502
4500
  const tooltip = /* @__PURE__ */ jsx(
4503
4501
  Root$a,
@@ -5524,7 +5522,7 @@ const Root$5 = styled(Box)`
5524
5522
  children: /* @__PURE__ */ jsx(Stack, { space, children })
5525
5523
  }
5526
5524
  ) });
5527
- }), MenuButton = forwardRef(function(props, ref) {
5525
+ }), MenuButton = forwardRef(function(props, forwardedRef) {
5528
5526
  const {
5529
5527
  __unstable_disableRestoreFocusOnClose: disableRestoreFocusOnClose = !1,
5530
5528
  boundaryElement: deprecated_boundaryElement,
@@ -5612,12 +5610,7 @@ const Root$5 = styled(Box)`
5612
5610
  registerElement,
5613
5611
  shouldFocus
5614
5612
  ]
5615
- ), menu = menuProp && cloneElement(menuProp, menuProps), setButtonRef = useCallback(
5616
- (el) => {
5617
- typeof ref == "function" ? ref(el) : ref && (ref.current = el), setButtonElement(el);
5618
- },
5619
- [ref]
5620
- ), button = useMemo(
5613
+ ), menu = menuProp && cloneElement(menuProp, menuProps), ref = useRef(null), button = useMemo(
5621
5614
  () => buttonProp && cloneElement(buttonProp, {
5622
5615
  "data-ui": "MenuButton",
5623
5616
  id,
@@ -5626,11 +5619,19 @@ const Root$5 = styled(Box)`
5626
5619
  onMouseDown: handleMouseDown,
5627
5620
  "aria-haspopup": !0,
5628
5621
  "aria-expanded": open,
5629
- ref: setButtonRef,
5622
+ ref,
5630
5623
  selected: open
5631
5624
  }),
5632
- [buttonProp, handleButtonClick, handleButtonKeyDown, handleMouseDown, id, open, setButtonRef]
5633
- ), popoverProps = useMemo(
5625
+ [buttonProp, handleButtonClick, handleButtonKeyDown, handleMouseDown, id, open]
5626
+ );
5627
+ useImperativeHandle(
5628
+ forwardedRef,
5629
+ () => ref.current
5630
+ ), useEffect(() => {
5631
+ if (button)
5632
+ return setButtonElement(ref.current), () => setButtonElement(null);
5633
+ }, [button]);
5634
+ const popoverProps = useMemo(
5634
5635
  () => ({
5635
5636
  boundaryElement: deprecated_boundaryElement,
5636
5637
  overflow: "auto",
@@ -5772,7 +5773,7 @@ function MenuGroup(props) {
5772
5773
  as = "button",
5773
5774
  children,
5774
5775
  fontSize: fontSize2 = 1,
5775
- icon,
5776
+ icon: IconComponent,
5776
5777
  onClick,
5777
5778
  padding = 3,
5778
5779
  popover,
@@ -5857,9 +5858,9 @@ function MenuGroup(props) {
5857
5858
  tabIndex: -1,
5858
5859
  type: as === "button" ? "button" : void 0,
5859
5860
  children: /* @__PURE__ */ jsxs(Flex, { gap: space, padding, children: [
5860
- icon && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
5861
- isValidElement(icon) && icon,
5862
- isValidElementType(icon) && createElement(icon)
5861
+ IconComponent && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
5862
+ isValidElement(IconComponent) && IconComponent,
5863
+ isValidElementType(IconComponent) && /* @__PURE__ */ jsx(IconComponent, {})
5863
5864
  ] }),
5864
5865
  /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(Text, { size: fontSize2, textOverflow: "ellipsis", weight: "medium", children: text }) }),
5865
5866
  /* @__PURE__ */ jsx(Text, { size: fontSize2, children: /* @__PURE__ */ jsx(ChevronRightIcon, {}) })
@@ -5874,8 +5875,8 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
5874
5875
  disabled,
5875
5876
  fontSize: fontSize2 = 1,
5876
5877
  hotkeys,
5877
- icon,
5878
- iconRight,
5878
+ icon: IconComponent,
5879
+ iconRight: IconRightComponent,
5879
5880
  onClick,
5880
5881
  padding = 3,
5881
5882
  paddingX,
@@ -5941,10 +5942,10 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
5941
5942
  tabIndex: -1,
5942
5943
  type: as === "button" ? "button" : void 0,
5943
5944
  children: [
5944
- (icon || text || iconRight) && /* @__PURE__ */ jsxs(Flex, { as: "span", gap: space, align: "center", ...paddingProps, children: [
5945
- icon && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
5946
- isValidElement(icon) && icon,
5947
- isValidElementType(icon) && createElement(icon)
5945
+ (IconComponent || text || IconRightComponent) && /* @__PURE__ */ jsxs(Flex, { as: "span", gap: space, align: "center", ...paddingProps, children: [
5946
+ IconComponent && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
5947
+ isValidElement(IconComponent) && IconComponent,
5948
+ isValidElementType(IconComponent) && /* @__PURE__ */ jsx(IconComponent, {})
5948
5949
  ] }),
5949
5950
  text && /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(Text, { size: fontSize2, textOverflow: "ellipsis", weight: "medium", children: text }) }),
5950
5951
  hotkeys && /* @__PURE__ */ jsx(
@@ -5955,9 +5956,9 @@ const MenuItem = forwardRef(function(props, forwardedRef) {
5955
5956
  style: { marginTop: -4, marginBottom: -4 }
5956
5957
  }
5957
5958
  ),
5958
- iconRight && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
5959
- isValidElement(iconRight) && iconRight,
5960
- isValidElementType(iconRight) && createElement(iconRight)
5959
+ IconRightComponent && /* @__PURE__ */ jsxs(Text, { size: fontSize2, children: [
5960
+ isValidElement(IconRightComponent) && IconRightComponent,
5961
+ isValidElementType(IconRightComponent) && /* @__PURE__ */ jsx(IconRightComponent, {})
5961
5962
  ] })
5962
5963
  ] }),
5963
5964
  children && /* @__PURE__ */ jsx(Box, { as: "span", ...paddingProps, children })
@@ -6606,7 +6607,7 @@ const TreeGroup = memo(function(props) {
6606
6607
  expanded: expandedProp = !1,
6607
6608
  fontSize: fontSize2 = 1,
6608
6609
  href,
6609
- icon,
6610
+ icon: IconComponent,
6610
6611
  id: idProp,
6611
6612
  linkAs,
6612
6613
  muted,
@@ -6645,10 +6646,13 @@ const TreeGroup = memo(function(props) {
6645
6646
  Box,
6646
6647
  {
6647
6648
  marginRight: space,
6648
- style: { visibility: icon || children ? "visible" : "hidden", pointerEvents: "none" },
6649
+ style: {
6650
+ visibility: IconComponent || children ? "visible" : "hidden",
6651
+ pointerEvents: "none"
6652
+ },
6649
6653
  children: [
6650
- icon && /* @__PURE__ */ jsx(Text, { muted, size: fontSize2, weight, children: createElement(icon) }),
6651
- !icon && /* @__PURE__ */ jsx(ToggleArrowText, { muted, size: fontSize2, weight, children: /* @__PURE__ */ jsx(ToggleArrowRightIcon, { style: { transform: expanded ? "rotate(90deg)" : void 0 } }) })
6654
+ IconComponent && /* @__PURE__ */ jsx(Text, { muted, size: fontSize2, weight, children: /* @__PURE__ */ jsx(IconComponent, {}) }),
6655
+ !IconComponent && /* @__PURE__ */ jsx(ToggleArrowText, { muted, size: fontSize2, weight, children: /* @__PURE__ */ jsx(ToggleArrowRightIcon, { style: { transform: expanded ? "rotate(90deg)" : void 0 } }) })
6652
6656
  ]
6653
6657
  }
6654
6658
  ),