@sanity/ui 1.9.1 → 1.9.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.9.1",
3
+ "version": "1.9.2",
4
4
  "sideEffects": false,
5
5
  "types": "./dist/index.d.ts",
6
6
  "source": "./src/index.ts",
@@ -10,15 +10,5 @@ export default defineScope({
10
10
  title: 'Props',
11
11
  component: lazy(() => import('./props')),
12
12
  },
13
- {
14
- name: 'resizableBoundary',
15
- title: 'Resizable Boundary',
16
- component: lazy(() => import('./resizableBoundary')),
17
- },
18
- {
19
- name: 'overflowBoundary',
20
- title: 'Overflowing Boundary',
21
- component: lazy(() => import('./overflowingBoundary')),
22
- },
23
13
  ],
24
14
  })
@@ -1,6 +1,5 @@
1
1
  import {Placement} from '@floating-ui/react-dom'
2
2
 
3
- export const DEFAULT_TOOLTIP_PADDING = 4
4
3
  export const DEFAULT_FALLBACK_PLACEMENTS: Record<Placement, Placement[]> = {
5
4
  top: ['bottom', 'left', 'right'],
6
5
  'top-start': ['bottom-start', 'left-start', 'right-start'],
@@ -8,6 +8,7 @@ import {
8
8
  useFloating,
9
9
  Middleware,
10
10
  RootBoundary,
11
+ size,
11
12
  } from '@floating-ui/react-dom'
12
13
  import {
13
14
  cloneElement,
@@ -30,7 +31,7 @@ import {Placement} from '../../types'
30
31
  import {Layer, LayerProps, Portal, useBoundaryElement} from '../../utils'
31
32
  import {Card} from '../card'
32
33
  import {Delay} from '../types'
33
- import {DEFAULT_FALLBACK_PLACEMENTS, DEFAULT_TOOLTIP_PADDING} from './constants'
34
+ import {DEFAULT_FALLBACK_PLACEMENTS} from './constants'
34
35
  import {TooltipArrow} from './tooltipArrow'
35
36
  import {useTooltipDelayGroup} from './tooltipDelayGroup'
36
37
 
@@ -62,9 +63,6 @@ export interface TooltipProps extends Omit<LayerProps, 'as'> {
62
63
 
63
64
  const Root = styled(Layer)`
64
65
  pointer-events: none;
65
- // Note that 100vw doesn't exclude system scrollbars.
66
- // This should be sufficiently small enough to not trigger overflow-x scrollbars when portalled.
67
- max-width: calc(100vw - ${DEFAULT_TOOLTIP_PADDING * 10}px);
68
66
  `
69
67
 
70
68
  /**
@@ -104,22 +102,35 @@ export const Tooltip = forwardRef(function Tooltip(
104
102
  // Flip the floating element when leaving the boundary box
105
103
  ret.push(
106
104
  flip({
107
- boundary: portal ? undefined : boundaryElement || undefined,
105
+ boundary: boundaryElement || undefined,
108
106
  fallbackPlacements,
109
- padding: DEFAULT_TOOLTIP_PADDING,
107
+ padding: 4,
110
108
  rootBoundary,
109
+ mainAxis: false,
111
110
  }),
112
111
  )
113
112
 
114
113
  // Define distance between reference and floating element
115
114
  ret.push(offset({mainAxis: 3}))
116
115
 
117
- // Shift the tooltip so its sits with the boundary element
116
+ // Set width and height on the floating element
117
+ ret.push(
118
+ size({
119
+ apply({availableWidth, availableHeight, elements}) {
120
+ Object.assign(elements.floating.style, {
121
+ maxWidth: `${availableWidth - 4 * 2}px`, // the padding is `4px`
122
+ maxHeight: `${availableHeight - 4 * 2}px`, // the padding is `4px`
123
+ })
124
+ },
125
+ }),
126
+ )
127
+
128
+ // Shift the tooltip so its sits with the boundary eleement
118
129
  ret.push(
119
130
  shift({
120
- boundary: portal ? undefined : boundaryElement || undefined,
131
+ boundary: boundaryElement || undefined,
121
132
  rootBoundary,
122
- padding: DEFAULT_TOOLTIP_PADDING,
133
+ padding: 4,
123
134
  }),
124
135
  )
125
136
 
@@ -127,7 +138,7 @@ export const Tooltip = forwardRef(function Tooltip(
127
138
  ret.push(arrow({element: arrowRef, padding: 2}))
128
139
 
129
140
  return ret
130
- }, [boundaryElement, fallbackPlacements, portal])
141
+ }, [boundaryElement, fallbackPlacements])
131
142
 
132
143
  const {floatingStyles, placement, middlewareData, refs, update} = useFloating({
133
144
  middleware,
@@ -1,53 +0,0 @@
1
- import {BoundaryElementProvider, Button, Card, Code, Flex, Text, Tooltip} from '@sanity/ui'
2
- import {useBoolean, useSelect, useText} from '@sanity/ui-workshop'
3
- import {useState} from 'react'
4
- import {WORKSHOP_PLACEMENT_OPTIONS} from '../../../__workshop__/constants'
5
-
6
- export default function OverflowingBoundaryStory() {
7
- const content = useText(
8
- 'Content',
9
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut mollis consectetur malesuada. Sed lobortis est dolor, eget imperdiet velit placerat et. Aenean posuere mi non aliquet iaculis. Donec fermentum pulvinar purus at sagittis. Ut tincidunt massa odio, sed finibus justo ullamcorper id. Nam venenatis justo non ligula elementum cursus. Pellentesque laoreet justo in mollis sagittis. In lacinia ornare ultrices. Suspendisse potenti.',
10
- )
11
- const placement = useSelect('Placement', WORKSHOP_PLACEMENT_OPTIONS, 'top')
12
- const portal = useBoolean('Portal', false)
13
- const useBoundaryElement = useBoolean('Use boundary element', true)
14
-
15
- const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
16
-
17
- return (
18
- <Flex align="center" height="fill" justify="center" style={{height: '200vh'}}>
19
- <BoundaryElementProvider element={useBoundaryElement ? boundaryElement : null}>
20
- <Card
21
- border
22
- ref={setBoundaryElement}
23
- style={{
24
- height: 'calc(100vh - 100px)',
25
- overflow: 'hidden',
26
- position: 'relative',
27
- resize: 'both',
28
- width: '500px',
29
- }}
30
- >
31
- <Flex align="center" height="fill" justify="center">
32
- <Flex justify="center">
33
- <Code size={1}>Placement: {placement}</Code>
34
- </Flex>
35
- </Flex>
36
-
37
- <Tooltip
38
- content={<Text size={1}>{content}</Text>}
39
- padding={2}
40
- placement={placement}
41
- portal={portal}
42
- >
43
- <Button
44
- mode="bleed"
45
- style={{position: 'absolute', top: 10, right: 10}}
46
- text="Tooltip"
47
- />
48
- </Tooltip>
49
- </Card>
50
- </BoundaryElementProvider>
51
- </Flex>
52
- )
53
- }
@@ -1,85 +0,0 @@
1
- import {BoundaryElementProvider, Button, Card, Code, Flex, Text, Tooltip} from '@sanity/ui'
2
- import {useBoolean, useSelect, useText} from '@sanity/ui-workshop'
3
- import {useState} from 'react'
4
- import {WORKSHOP_PLACEMENT_OPTIONS} from '../../../__workshop__/constants'
5
-
6
- export default function ResizableBoundaryStory() {
7
- const content = useText(
8
- 'Content',
9
- 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut mollis consectetur malesuada. Sed lobortis est dolor, eget imperdiet velit placerat et. Aenean posuere mi non aliquet iaculis. Donec fermentum pulvinar purus at sagittis. Ut tincidunt massa odio, sed finibus justo ullamcorper id. Nam venenatis justo non ligula elementum cursus. Pellentesque laoreet justo in mollis sagittis. In lacinia ornare ultrices. Suspendisse potenti.',
10
- )
11
- const placement = useSelect('Placement', WORKSHOP_PLACEMENT_OPTIONS, 'right')
12
- const portal = useBoolean('Portal', true)
13
- const useBoundaryElement = useBoolean('Use boundary element', true)
14
-
15
- const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
16
-
17
- return (
18
- <Flex align="center" height="fill" justify="center">
19
- <BoundaryElementProvider element={useBoundaryElement ? boundaryElement : null}>
20
- <Card
21
- border
22
- ref={setBoundaryElement}
23
- style={{
24
- height: 'calc(100vh - 100px)',
25
- overflow: 'hidden',
26
- position: 'relative',
27
- resize: 'both',
28
- width: '500px',
29
- }}
30
- >
31
- <Flex align="center" height="fill" justify="center">
32
- <Flex justify="center">
33
- <Code size={1}>Placement: {placement}</Code>
34
- </Flex>
35
- </Flex>
36
-
37
- <Tooltip
38
- content={<Text size={1}>{content}</Text>}
39
- padding={2}
40
- placement={placement}
41
- portal={portal}
42
- >
43
- <Button mode="bleed" style={{position: 'absolute', top: 10, left: 10}} text="Tooltip" />
44
- </Tooltip>
45
- <Tooltip
46
- content={<Text size={1}>{content}</Text>}
47
- padding={2}
48
- placement={placement}
49
- portal={portal}
50
- >
51
- <Button
52
- mode="bleed"
53
- style={{position: 'absolute', top: 10, right: 10}}
54
- text="Tooltip"
55
- />
56
- </Tooltip>
57
- <Tooltip
58
- content={<Text size={1}>{content}</Text>}
59
- padding={2}
60
- placement={placement}
61
- portal={portal}
62
- >
63
- <Button
64
- mode="bleed"
65
- style={{position: 'absolute', bottom: 10, left: 10}}
66
- text="Tooltip"
67
- />
68
- </Tooltip>
69
- <Tooltip
70
- content={<Text size={1}>{content}</Text>}
71
- padding={2}
72
- placement={placement}
73
- portal={portal}
74
- >
75
- <Button
76
- mode="bleed"
77
- style={{position: 'absolute', bottom: 10, right: 10}}
78
- text="Tooltip"
79
- />
80
- </Tooltip>
81
- </Card>
82
- </BoundaryElementProvider>
83
- </Flex>
84
- )
85
- }