@sanity/ui 1.8.1 → 1.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "sideEffects": false,
5
5
  "types": "./dist/index.d.ts",
6
6
  "source": "./src/index.ts",
@@ -1,7 +1,21 @@
1
- import {PopoverMargins} from '../../types'
1
+ import {Placement, PopoverMargins} from '../../types'
2
2
 
3
3
  export const DEFAULT_POPOVER_DISTANCE = 4
4
4
  export const DEFAULT_POPOVER_PADDING = 4
5
5
  export const DEFAULT_POPOVER_ARROW_WIDTH = 27
6
6
  export const DEFAULT_POPOVER_ARROW_HEIGHT = 11
7
7
  export const DEFAULT_POPOVER_MARGINS: PopoverMargins = [0, 0, 0, 0]
8
+ export const DEFAULT_FALLBACK_PLACEMENTS: Record<Placement, Placement[]> = {
9
+ top: ['bottom', 'left', 'right'],
10
+ 'top-start': ['bottom-start', 'left-start', 'right-start'],
11
+ 'top-end': ['bottom-end', 'left-end', 'right-end'],
12
+ bottom: ['top', 'left', 'right'],
13
+ 'bottom-start': ['top-start', 'left-start', 'right-start'],
14
+ 'bottom-end': ['top-end', 'left-end', 'right-end'],
15
+ left: ['right', 'top', 'bottom'],
16
+ 'left-start': ['right-start', 'top-start', 'bottom-start'],
17
+ 'left-end': ['right-end', 'top-end', 'bottom-end'],
18
+ right: ['left', 'top', 'bottom'],
19
+ 'right-start': ['left-start', 'top-start', 'bottom-start'],
20
+ 'right-end': ['left-end', 'top-end', 'bottom-end'],
21
+ }
@@ -28,6 +28,7 @@ import {ResponsiveRadiusProps, ResponsiveShadowProps} from '../types'
28
28
  import {
29
29
  DEFAULT_POPOVER_DISTANCE,
30
30
  DEFAULT_POPOVER_MARGINS,
31
+ DEFAULT_FALLBACK_PLACEMENTS,
31
32
  DEFAULT_POPOVER_PADDING,
32
33
  } from './constants'
33
34
  import {size} from './floating-ui/size'
@@ -89,7 +90,8 @@ export const Popover = memo(
89
90
  constrainSize = false,
90
91
  content,
91
92
  disabled,
92
- fallbackPlacements,
93
+ fallbackPlacements = props.fallbackPlacements ??
94
+ DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
93
95
  matchReferenceWidth,
94
96
  floatingBoundary = props.boundaryElement ?? boundaryElementContext.element,
95
97
  open,
@@ -0,0 +1,16 @@
1
+ import {Placement} from '@floating-ui/react-dom'
2
+
3
+ export const DEFAULT_FALLBACK_PLACEMENTS: Record<Placement, Placement[]> = {
4
+ top: ['bottom', 'left', 'right'],
5
+ 'top-start': ['bottom-start', 'left-start', 'right-start'],
6
+ 'top-end': ['bottom-end', 'left-end', 'right-end'],
7
+ bottom: ['top', 'left', 'right'],
8
+ 'bottom-start': ['top-start', 'left-start', 'right-start'],
9
+ 'bottom-end': ['top-end', 'left-end', 'right-end'],
10
+ left: ['right', 'top', 'bottom'],
11
+ 'left-start': ['right-start', 'top-start', 'bottom-start'],
12
+ 'left-end': ['right-end', 'top-end', 'bottom-end'],
13
+ right: ['left', 'top', 'bottom'],
14
+ 'right-start': ['left-start', 'top-start', 'bottom-start'],
15
+ 'right-end': ['left-end', 'top-end', 'bottom-end'],
16
+ }
@@ -31,6 +31,7 @@ import {Placement} from '../../types'
31
31
  import {Layer, LayerProps, Portal, useBoundaryElement} from '../../utils'
32
32
  import {Card} from '../card'
33
33
  import {Delay} from '../types'
34
+ import {DEFAULT_FALLBACK_PLACEMENTS} from './constants'
34
35
  import {TooltipArrow} from './tooltipArrow'
35
36
  import {useTooltipDelayGroup} from './tooltipDelayGroup'
36
37
 
@@ -78,7 +79,8 @@ export const Tooltip = forwardRef(function Tooltip(
78
79
  children: childProp,
79
80
  content,
80
81
  disabled,
81
- fallbackPlacements: fallbackPlacementsProp,
82
+ fallbackPlacements: fallbackPlacementsProp = props.fallbackPlacements ??
83
+ DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
82
84
  padding,
83
85
  placement: placementProp = 'bottom',
84
86
  portal,