@sanity/ui 1.8.0 → 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.0",
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,
@@ -132,6 +132,12 @@ const RightCard = styled(Card)`
132
132
  right: 0;
133
133
  `
134
134
 
135
+ const TextInputClearButton = styled(Button)({
136
+ '&:not([hidden])': {
137
+ display: 'block',
138
+ },
139
+ })
140
+
135
141
  /**
136
142
  * @public
137
143
  */
@@ -291,7 +297,7 @@ export const TextInput = forwardRef(function TextInput(
291
297
  style={CLEAR_BUTTON_BOX_STYLE}
292
298
  tone={customValidity ? 'critical' : 'inherit'}
293
299
  >
294
- <Button
300
+ <TextInputClearButton
295
301
  aria-label="Clear"
296
302
  data-qa="clear-button"
297
303
  fontSize={fontSize}
@@ -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,