@sanity/ui 2.6.4-canary.0 → 2.6.4-canary.2

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.
Files changed (55) hide show
  1. package/dist/index.d.mts +51 -15
  2. package/dist/index.d.ts +51 -15
  3. package/dist/index.esm.js +103 -167
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +102 -167
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +103 -167
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/theme.d.mts +14 -14
  10. package/dist/theme.d.ts +14 -14
  11. package/dist/theme.esm.js.map +1 -1
  12. package/dist/theme.js.map +1 -1
  13. package/dist/theme.mjs.map +1 -1
  14. package/package.json +28 -27
  15. package/src/core/__workshop__/constants.ts +36 -36
  16. package/src/core/components/autocomplete/autocomplete.tsx +1 -1
  17. package/src/core/components/breadcrumbs/breadcrumbs.tsx +15 -6
  18. package/src/core/components/dialog/dialog.tsx +12 -21
  19. package/src/core/components/dialog/styles.ts +8 -8
  20. package/src/core/components/menu/menu.tsx +11 -18
  21. package/src/core/components/menu/menuButton.tsx +11 -11
  22. package/src/core/components/menu/menuContext.ts +1 -1
  23. package/src/core/components/menu/useMenuController.ts +11 -18
  24. package/src/core/components/tab/tab.tsx +8 -8
  25. package/src/core/components/tab/tabPanel.tsx +1 -1
  26. package/src/core/components/toast/useToast.ts +1 -0
  27. package/src/core/components/tree/tree.tsx +1 -0
  28. package/src/core/components/tree/treeItem.tsx +1 -0
  29. package/src/core/hooks/index.ts +3 -2
  30. package/src/core/hooks/useClickOutside.ts +37 -74
  31. package/src/core/hooks/useMatchMedia.ts +46 -0
  32. package/src/core/hooks/useMediaIndex/useMediaIndex.ts +2 -11
  33. package/src/core/hooks/usePrefersDark.ts +10 -58
  34. package/src/core/hooks/usePrefersReducedMotion.ts +10 -58
  35. package/src/core/primitives/avatar/styles.ts +42 -42
  36. package/src/core/primitives/badge/styles.ts +2 -2
  37. package/src/core/primitives/button/styles.ts +4 -4
  38. package/src/core/primitives/inline/styles.ts +2 -2
  39. package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +9 -7
  40. package/src/core/primitives/popover/constants.ts +4 -4
  41. package/src/core/primitives/stack/styles.ts +2 -2
  42. package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +9 -7
  43. package/src/core/primitives/tooltip/constants.ts +4 -4
  44. package/src/core/primitives/tooltip/tooltip.tsx +45 -27
  45. package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +1 -0
  46. package/src/core/styles/font/responsiveFont.ts +8 -8
  47. package/src/core/theme/__workshop__/debug/story.tsx +11 -11
  48. package/src/core/utils/layer/layerProvider.tsx +1 -0
  49. package/src/core/utils/portal/__workshop__/named.tsx +10 -8
  50. package/src/core/utils/portal/portalProvider.tsx +7 -14
  51. package/src/theme/build/buildColorTheme.test.ts +13 -13
  52. package/src/theme/config/tokens/color/types.ts +14 -14
  53. package/src/theme/defaults/colorTokens.ts +36 -36
  54. package/src/core/hooks/_internal/index.ts +0 -1
  55. package/src/core/hooks/_internal/useUnique.ts +0 -34
package/dist/index.d.mts CHANGED
@@ -628,7 +628,7 @@ export declare interface CheckboxProps {
628
628
  /**
629
629
  * @public
630
630
  */
631
- export declare type ClickOutsideListener = (event: MouseEvent) => void
631
+ export declare type ClickOutsideListener = (event: MouseEvent | TouchEvent) => void
632
632
 
633
633
  /**
634
634
  * @public
@@ -1432,7 +1432,7 @@ export declare interface MenuProps extends ResponsivePaddingProps {
1432
1432
  * @deprecated Use `shouldFocus="last"` instead.
1433
1433
  */
1434
1434
  focusLast?: boolean
1435
- onClickOutside?: (event: MouseEvent) => void
1435
+ onClickOutside?: (event: MouseEvent | TouchEvent) => void
1436
1436
  onEscape?: () => void
1437
1437
  onItemClick?: () => void
1438
1438
  onItemSelect?: (index: number) => void
@@ -2069,7 +2069,7 @@ export declare interface TabPanelProps extends BoxProps {
2069
2069
  * The `id` of the correlating `Tab` component.
2070
2070
  */
2071
2071
  'aria-labelledby': string
2072
- id: string
2072
+ 'id': string
2073
2073
  }
2074
2074
 
2075
2075
  /**
@@ -2080,14 +2080,14 @@ export declare interface TabProps {
2080
2080
  * The `id` of the correlating `TabPanel` component.
2081
2081
  */
2082
2082
  'aria-controls': string
2083
- id: string
2084
- icon?: React.ElementType | React.ReactNode
2085
- focused?: boolean
2086
- fontSize?: number | number[]
2087
- label?: React.ReactNode
2088
- padding?: number | number[]
2089
- selected?: boolean
2090
- tone?: ButtonTone
2083
+ 'id': string
2084
+ 'icon'?: React.ElementType | React.ReactNode
2085
+ 'focused'?: boolean
2086
+ 'fontSize'?: number | number[]
2087
+ 'label'?: React.ReactNode
2088
+ 'padding'?: number | number[]
2089
+ 'selected'?: boolean
2090
+ 'tone'?: ButtonTone
2091
2091
  }
2092
2092
 
2093
2093
  /**
@@ -2649,13 +2649,22 @@ export declare function useArrayProp<T extends ArrayPropPrimitive = ArrayPropPri
2649
2649
  export declare function useBoundaryElement(): BoundaryElementContextValue
2650
2650
 
2651
2651
  /**
2652
+ * Use the callback version of `elementsArg` if you're using `useRef` to handle elements:
2653
+ * ```tsx
2654
+ * useClickOutside(
2655
+ * () => {},
2656
+ * () => [ref.current],
2657
+ * )
2658
+ *
2652
2659
  * @public
2653
2660
  */
2654
2661
  export declare function useClickOutside(
2655
2662
  listener: ClickOutsideListener,
2656
- elementsArg?: Array<HTMLElement | HTMLElement[] | null>,
2663
+ elementsArg?:
2664
+ | Array<HTMLElement | HTMLElement[] | null>
2665
+ | (() => Array<HTMLElement | HTMLElement[] | null>),
2657
2666
  boundaryElement?: HTMLElement | null,
2658
- ): (el: HTMLElement | null) => void
2667
+ ): void
2659
2668
 
2660
2669
  /**
2661
2670
  * @beta
@@ -2713,6 +2722,18 @@ export declare function useGlobalKeyDown(onKeyDown: (event: KeyboardEvent) => vo
2713
2722
  */
2714
2723
  export declare function useLayer(): LayerContextValue
2715
2724
 
2725
+ /**
2726
+ * Efficiently subscribes to `window.matchMedia` queries
2727
+ *
2728
+ * @param getServerSnapshot - Only called during server-side rendering, and hydration if using hydrateRoot. Required if the hook is called during SSR (https://react.dev/reference/react/useSyncExternalStore#adding-support-for-server-rendering)
2729
+ *
2730
+ * @public
2731
+ */
2732
+ export declare function useMatchMedia(
2733
+ mediaQueryString: `(${string})`,
2734
+ getServerSnapshot?: () => boolean,
2735
+ ): boolean
2736
+
2716
2737
  /**
2717
2738
  * This API might change. DO NOT USE IN PRODUCTION.
2718
2739
  * @beta
@@ -2725,15 +2746,30 @@ export declare function useMediaIndex(): number
2725
2746
  export declare function usePortal(): PortalContextValue
2726
2747
 
2727
2748
  /**
2749
+ * Returns true if a dark color scheme is preferred, false if a light color scheme is preferred or the preference is not known.
2750
+ *
2751
+ * @param getServerSnapshot - Only called during server-side rendering, and hydration if using hydrateRoot. Since the server environment doesn't have access to the DOM, we can't determine the current value of the media query and we assume `(prefers-color-scheme: light)` since it's the most common scheme (https://react.dev/reference/react/useSyncExternalStore#adding-support-for-server-rendering)
2752
+ *
2753
+ * If you persist the detected preference in a cookie or a header then you may implement your own server snapshot to read it.
2754
+ * Chrome supports reading the `prefers-color-scheme` media query from a header if the server response: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Prefers-Color-Scheme
2755
+ * @example https://gist.github.com/stipsan/13c0cccf8dfc34f4b44bb1b984baf7df
2756
+ *
2728
2757
  * @public
2729
2758
  */
2730
- export declare function usePrefersDark(): boolean
2759
+ export declare function usePrefersDark(getServerSnapshot?: () => boolean): boolean
2731
2760
 
2732
2761
  /**
2733
2762
  * Returns true if motion should be reduced
2763
+ *
2764
+ * @param getServerSnapshot - Only called during server-side rendering, and hydration if using hydrateRoot. Since the server environment doesn't have access to the DOM, we can't determine the current value of the media query and we assume `(prefers-reduced-motion: no-preference)` since it's the most common scheme (https://react.dev/reference/react/useSyncExternalStore#adding-support-for-server-rendering)
2765
+ *
2766
+ * If you persist the detected preference in a cookie or a header then you may implement your own server snapshot to read it.
2767
+ * Chrome supports reading the `prefers-reduced-motion` media query from a header if the server response: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Prefers-Reduced-Motion
2768
+ * @example https://gist.github.com/stipsan/0c0f839a27842249cada893e9fb7767b
2769
+ *
2734
2770
  * @public
2735
2771
  */
2736
- export declare function usePrefersReducedMotion(): boolean
2772
+ export declare function usePrefersReducedMotion(getServerSnapshot?: () => boolean): boolean
2737
2773
 
2738
2774
  /**
2739
2775
  * @public
package/dist/index.d.ts CHANGED
@@ -628,7 +628,7 @@ export declare interface CheckboxProps {
628
628
  /**
629
629
  * @public
630
630
  */
631
- export declare type ClickOutsideListener = (event: MouseEvent) => void
631
+ export declare type ClickOutsideListener = (event: MouseEvent | TouchEvent) => void
632
632
 
633
633
  /**
634
634
  * @public
@@ -1432,7 +1432,7 @@ export declare interface MenuProps extends ResponsivePaddingProps {
1432
1432
  * @deprecated Use `shouldFocus="last"` instead.
1433
1433
  */
1434
1434
  focusLast?: boolean
1435
- onClickOutside?: (event: MouseEvent) => void
1435
+ onClickOutside?: (event: MouseEvent | TouchEvent) => void
1436
1436
  onEscape?: () => void
1437
1437
  onItemClick?: () => void
1438
1438
  onItemSelect?: (index: number) => void
@@ -2069,7 +2069,7 @@ export declare interface TabPanelProps extends BoxProps {
2069
2069
  * The `id` of the correlating `Tab` component.
2070
2070
  */
2071
2071
  'aria-labelledby': string
2072
- id: string
2072
+ 'id': string
2073
2073
  }
2074
2074
 
2075
2075
  /**
@@ -2080,14 +2080,14 @@ export declare interface TabProps {
2080
2080
  * The `id` of the correlating `TabPanel` component.
2081
2081
  */
2082
2082
  'aria-controls': string
2083
- id: string
2084
- icon?: React.ElementType | React.ReactNode
2085
- focused?: boolean
2086
- fontSize?: number | number[]
2087
- label?: React.ReactNode
2088
- padding?: number | number[]
2089
- selected?: boolean
2090
- tone?: ButtonTone
2083
+ 'id': string
2084
+ 'icon'?: React.ElementType | React.ReactNode
2085
+ 'focused'?: boolean
2086
+ 'fontSize'?: number | number[]
2087
+ 'label'?: React.ReactNode
2088
+ 'padding'?: number | number[]
2089
+ 'selected'?: boolean
2090
+ 'tone'?: ButtonTone
2091
2091
  }
2092
2092
 
2093
2093
  /**
@@ -2649,13 +2649,22 @@ export declare function useArrayProp<T extends ArrayPropPrimitive = ArrayPropPri
2649
2649
  export declare function useBoundaryElement(): BoundaryElementContextValue
2650
2650
 
2651
2651
  /**
2652
+ * Use the callback version of `elementsArg` if you're using `useRef` to handle elements:
2653
+ * ```tsx
2654
+ * useClickOutside(
2655
+ * () => {},
2656
+ * () => [ref.current],
2657
+ * )
2658
+ *
2652
2659
  * @public
2653
2660
  */
2654
2661
  export declare function useClickOutside(
2655
2662
  listener: ClickOutsideListener,
2656
- elementsArg?: Array<HTMLElement | HTMLElement[] | null>,
2663
+ elementsArg?:
2664
+ | Array<HTMLElement | HTMLElement[] | null>
2665
+ | (() => Array<HTMLElement | HTMLElement[] | null>),
2657
2666
  boundaryElement?: HTMLElement | null,
2658
- ): (el: HTMLElement | null) => void
2667
+ ): void
2659
2668
 
2660
2669
  /**
2661
2670
  * @beta
@@ -2713,6 +2722,18 @@ export declare function useGlobalKeyDown(onKeyDown: (event: KeyboardEvent) => vo
2713
2722
  */
2714
2723
  export declare function useLayer(): LayerContextValue
2715
2724
 
2725
+ /**
2726
+ * Efficiently subscribes to `window.matchMedia` queries
2727
+ *
2728
+ * @param getServerSnapshot - Only called during server-side rendering, and hydration if using hydrateRoot. Required if the hook is called during SSR (https://react.dev/reference/react/useSyncExternalStore#adding-support-for-server-rendering)
2729
+ *
2730
+ * @public
2731
+ */
2732
+ export declare function useMatchMedia(
2733
+ mediaQueryString: `(${string})`,
2734
+ getServerSnapshot?: () => boolean,
2735
+ ): boolean
2736
+
2716
2737
  /**
2717
2738
  * This API might change. DO NOT USE IN PRODUCTION.
2718
2739
  * @beta
@@ -2725,15 +2746,30 @@ export declare function useMediaIndex(): number
2725
2746
  export declare function usePortal(): PortalContextValue
2726
2747
 
2727
2748
  /**
2749
+ * Returns true if a dark color scheme is preferred, false if a light color scheme is preferred or the preference is not known.
2750
+ *
2751
+ * @param getServerSnapshot - Only called during server-side rendering, and hydration if using hydrateRoot. Since the server environment doesn't have access to the DOM, we can't determine the current value of the media query and we assume `(prefers-color-scheme: light)` since it's the most common scheme (https://react.dev/reference/react/useSyncExternalStore#adding-support-for-server-rendering)
2752
+ *
2753
+ * If you persist the detected preference in a cookie or a header then you may implement your own server snapshot to read it.
2754
+ * Chrome supports reading the `prefers-color-scheme` media query from a header if the server response: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Prefers-Color-Scheme
2755
+ * @example https://gist.github.com/stipsan/13c0cccf8dfc34f4b44bb1b984baf7df
2756
+ *
2728
2757
  * @public
2729
2758
  */
2730
- export declare function usePrefersDark(): boolean
2759
+ export declare function usePrefersDark(getServerSnapshot?: () => boolean): boolean
2731
2760
 
2732
2761
  /**
2733
2762
  * Returns true if motion should be reduced
2763
+ *
2764
+ * @param getServerSnapshot - Only called during server-side rendering, and hydration if using hydrateRoot. Since the server environment doesn't have access to the DOM, we can't determine the current value of the media query and we assume `(prefers-reduced-motion: no-preference)` since it's the most common scheme (https://react.dev/reference/react/useSyncExternalStore#adding-support-for-server-rendering)
2765
+ *
2766
+ * If you persist the detected preference in a cookie or a header then you may implement your own server snapshot to read it.
2767
+ * Chrome supports reading the `prefers-reduced-motion` media query from a header if the server response: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-Prefers-Reduced-Motion
2768
+ * @example https://gist.github.com/stipsan/0c0f839a27842249cada893e9fb7767b
2769
+ *
2734
2770
  * @public
2735
2771
  */
2736
- export declare function usePrefersReducedMotion(): boolean
2772
+ export declare function usePrefersReducedMotion(getServerSnapshot?: () => boolean): boolean
2737
2773
 
2738
2774
  /**
2739
2775
  * @public