@sanity/ui 2.13.4 → 2.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.13.4",
3
+ "version": "2.14.0",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -51,6 +51,9 @@ export function rootStyles(
51
51
  animation-name: ${loadingAnimation};
52
52
  animation-duration: ${props.$duration}ms;
53
53
  animation-fill-mode: both;
54
+ animation-timing-function: linear;
55
+ opacity: var(${POPOVER_MOTION_CONTENT_OPACITY_PROPERTY}, 1);
56
+ will-change: width;
54
57
  }
55
58
 
56
59
  & > * {
@@ -57,6 +57,12 @@ export function ToastProvider(props: ToastProviderProps): React.JSX.Element {
57
57
  const prefersReducedMotion = usePrefersReducedMotion()
58
58
  const variants = useMemo<Variants>(
59
59
  () => ({
60
+ /**
61
+ * These variants makes use of special timing, by using a negative opacity as a starting position,
62
+ * as well as double opacity as the end position.
63
+ * The purpose of this is to make the tooltip/popover container appear before the content, and when exiting
64
+ * we want the content to disappear faster than the container.
65
+ */
60
66
  initial: {
61
67
  opacity: 0,
62
68
  [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY]: -1,
@@ -25,8 +25,15 @@ export const POPOVER_MOTION_PROPS: {
25
25
  exit: Variant
26
26
  transition: Transition
27
27
  } = {
28
+ /**
29
+ * These variants makes use of special timing, by using a negative opacity as a starting position,
30
+ * as well as double opacity as the end position.
31
+ * The purpose of this is to make the tooltip/popover container appear before the content, and when exiting
32
+ * we want the content to disappear faster than the container.
33
+ */
28
34
  initial: {
29
35
  opacity: 0.5,
36
+ // the nagative opacity here, as well as the double opacity further down, are to make the content appear after the backgdrop, and when exiting the content should disappear first.
30
37
  [POPOVER_MOTION_CONTENT_OPACITY_PROPERTY as string]: -1,
31
38
  scale: 0.97,
32
39
  willChange: 'transform',
@@ -27,7 +27,7 @@ import {useArrayProp, useElementSize, useMediaIndex, usePrefersReducedMotion} fr
27
27
  import {origin} from '../../middleware/origin'
28
28
  import {useTheme_v2} from '../../theme'
29
29
  import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
30
- import {LayerProps, LayerProvider, Portal, useBoundaryElement} from '../../utils'
30
+ import {LayerProps, LayerProvider, Portal, useBoundaryElement, useLayer} from '../../utils'
31
31
  import {getElementRef} from '../../utils/getElementRef'
32
32
  import {ResponsiveRadiusProps, ResponsiveShadowProps} from '../types'
33
33
  import {
@@ -86,6 +86,13 @@ export interface PopoverProps
86
86
  * @defaultValue false
87
87
  */
88
88
  matchReferenceWidth?: boolean
89
+ /**
90
+ * When true, blocks all pointer interaction with elements beneath the popover until closed.
91
+ *
92
+ * @beta
93
+ * @defaultValue false
94
+ */
95
+ modal?: boolean
89
96
  open?: boolean
90
97
  overflow?: BoxOverflow
91
98
  padding?: number | number[]
@@ -108,6 +115,12 @@ export interface PopoverProps
108
115
  width?: PopoverWidth | PopoverWidth[]
109
116
  }
110
117
 
118
+ const ViewportOverlay = () => {
119
+ const {zIndex} = useLayer()
120
+
121
+ return <div style={{height: '100vh', inset: 0, position: 'fixed', width: '100vw', zIndex}} />
122
+ }
123
+
111
124
  /**
112
125
  * The `Popover` component is used to display some content on top of another.
113
126
  *
@@ -135,6 +148,7 @@ export const Popover = memo(
135
148
  DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
136
149
  matchReferenceWidth,
137
150
  floatingBoundary = props.boundaryElement ?? boundaryElementContext.element,
151
+ modal,
138
152
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
139
153
  onActivate,
140
154
  open,
@@ -395,6 +409,9 @@ export const Popover = memo(
395
409
 
396
410
  const popover = (
397
411
  <LayerProvider zOffset={zOffset}>
412
+ {/* Optional transparent blocking overlay at the top-most z-index layer. Must be positioned before the below popover card. */}
413
+ {modal && <ViewportOverlay />}
414
+
398
415
  <PopoverCard
399
416
  {...restProps}
400
417
  __unstable_margins={margins}