@sanity/ui 1.0.0-beta.30 → 1.0.0-beta.32

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 (28) hide show
  1. package/dist/sanity-ui.esm.js +163 -95
  2. package/dist/sanity-ui.esm.js.map +1 -1
  3. package/dist/sanity-ui.js +162 -94
  4. package/dist/sanity-ui.js.map +1 -1
  5. package/dist/types/src/index.d.ts +0 -6
  6. package/package.json +4 -4
  7. package/src/__workshop__/constants.ts +31 -22
  8. package/src/components/autocomplete/autocomplete.styles.tsx +1 -10
  9. package/src/components/autocomplete/autocomplete.tsx +13 -3
  10. package/src/components/menu/__workshop__/closableMenuButton.tsx +6 -2
  11. package/src/components/menu/__workshop__/constrainedInBoundary.tsx +5 -11
  12. package/src/components/menu/__workshop__/disableFocusOnClose.tsx +7 -2
  13. package/src/components/menu/__workshop__/groups.tsx +16 -3
  14. package/src/components/menu/__workshop__/menuButton.tsx +11 -1
  15. package/src/components/menu/__workshop__/menuGroupRight.tsx +8 -1
  16. package/src/components/menu/__workshop__/onCloseMenuButton.tsx +6 -2
  17. package/src/components/menu/__workshop__/selectedItem.tsx +16 -2
  18. package/src/components/menu/__workshop__/withoutArrow.tsx +12 -10
  19. package/src/primitives/card/styles.ts +3 -1
  20. package/src/primitives/popover/__workshop__/{RightAlignedStory.tsx → AlignedStory.tsx} +19 -7
  21. package/src/primitives/popover/__workshop__/PlainStory.tsx +24 -21
  22. package/src/primitives/popover/__workshop__/TestStory.tsx +2 -0
  23. package/src/primitives/popover/__workshop__/index.ts +3 -3
  24. package/src/primitives/popover/constants.ts +10 -0
  25. package/src/primitives/popover/floating-ui/size.ts +67 -0
  26. package/src/primitives/popover/popover.tsx +43 -50
  27. package/src/primitives/popover/popoverArrow.tsx +10 -9
  28. package/src/primitives/popover/popoverCard.tsx +39 -29
@@ -8592,8 +8592,6 @@ export declare interface PopoverProps
8592
8592
  * @beta
8593
8593
  */
8594
8594
  __unstable_margins?: PopoverMargins
8595
- /** @deprecated Use `fallbackPlacements` instead. */
8596
- allowedAutoPlacements?: Placement[]
8597
8595
  arrow?: boolean
8598
8596
  boundaryElement?: HTMLElement | null
8599
8597
  children?: React.ReactElement
@@ -8610,10 +8608,6 @@ export declare interface PopoverProps
8610
8608
  referenceElement?: HTMLElement | null
8611
8609
  matchReferenceWidth?: boolean
8612
8610
  scheme?: ThemeColorSchemeKey
8613
- /** @deprecated No longer supported. */
8614
- tether?: boolean
8615
- /** @deprecated No longer supported. */
8616
- tetherOffset?: number | ((...args: any[]) => number)
8617
8611
  tone?: CardTone
8618
8612
  }
8619
8613
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "1.0.0-beta.30",
3
+ "version": "1.0.0-beta.32",
4
4
  "sideEffects": false,
5
5
  "types": "./dist/types/src/index.d.ts",
6
6
  "source": "./src/index.ts",
@@ -33,8 +33,8 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@floating-ui/react-dom": "^1.0.0",
36
- "@sanity/color": "2.1.19-beta.1",
37
- "@sanity/icons": "1.3.9-beta.1",
36
+ "@sanity/color": "2.1.19-beta.3",
37
+ "@sanity/icons": "1.3.9-beta.3",
38
38
  "framer-motion": "^7.5.3",
39
39
  "react-refractor": "^2.1.7"
40
40
  },
@@ -69,5 +69,5 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
- "gitHead": "9555be81dc9d9ad2997ab34ecb59c91ec0b27a49"
72
+ "gitHead": "4b884675a828c6aad24f80390a96af14e8084ddc"
73
73
  }
@@ -8,6 +8,7 @@ import {
8
8
  ButtonTone,
9
9
  CardTone,
10
10
  DialogPosition,
11
+ FlexAlign,
11
12
  FlexJustify,
12
13
  Placement,
13
14
  TextAlign,
@@ -105,14 +106,22 @@ export const WORKSHOP_FLEX_DIRECTION_OPTIONS: {[key: string]: 'row' | 'column'}
105
106
  Column: 'column',
106
107
  }
107
108
 
108
- export const WORKSHOP_FLEX_JUSTIFY_OPTIONS: FlexJustify[] = [
109
- 'flex-start',
110
- 'flex-end',
111
- 'center',
112
- 'space-between',
113
- 'space-around',
114
- 'space-evenly',
115
- ]
109
+ export const WORKSHOP_FLEX_ALIGN_OPTIONS: Record<FlexAlign, FlexAlign> = {
110
+ baseline: 'baseline',
111
+ center: 'center',
112
+ 'flex-end': 'flex-end',
113
+ 'flex-start': 'flex-start',
114
+ stretch: 'stretch',
115
+ }
116
+
117
+ export const WORKSHOP_FLEX_JUSTIFY_OPTIONS: Record<FlexJustify, FlexJustify> = {
118
+ center: 'center',
119
+ 'flex-end': 'flex-end',
120
+ 'flex-start': 'flex-start',
121
+ 'space-around': 'space-around',
122
+ 'space-between': 'space-between',
123
+ 'space-evenly': 'space-evenly',
124
+ }
116
125
 
117
126
  export const WORKSHOP_FONT_WEIGHT_OPTIONS: {[key: string]: ThemeFontWeightKey} = {
118
127
  Regular: 'regular',
@@ -148,19 +157,19 @@ export const WORKSHOP_LABEL_FONT_SIZE_OPTIONS = {
148
157
  '4': 4,
149
158
  }
150
159
 
151
- export const WORKSHOP_PLACEMENT_OPTIONS: {[key: string]: Placement} = {
152
- Top: 'top',
153
- 'Top start': 'top-start',
154
- 'Top end': 'top-end',
155
- Right: 'right',
156
- 'Right start': 'right-start',
157
- 'Right end': 'right-end',
158
- Left: 'left',
159
- 'Left start': 'left-start',
160
- 'Left end': 'left-end',
161
- Bottom: 'bottom',
162
- 'Bottom start': 'bottom-start',
163
- 'Bottom end': 'bottom-end',
160
+ export const WORKSHOP_PLACEMENT_OPTIONS: Record<Placement, Placement> = {
161
+ top: 'top',
162
+ 'top-start': 'top-start',
163
+ 'top-end': 'top-end',
164
+ right: 'right',
165
+ 'right-start': 'right-start',
166
+ 'right-end': 'right-end',
167
+ left: 'left',
168
+ 'left-start': 'left-start',
169
+ 'left-end': 'left-end',
170
+ bottom: 'bottom',
171
+ 'bottom-start': 'bottom-start',
172
+ 'bottom-end': 'bottom-end',
164
173
  }
165
174
 
166
175
  export const WORKSHOP_RADIUS_OPTIONS = {
@@ -278,11 +287,11 @@ export const WORKSHOP_TOAST_STATUS_OPTIONS: {
278
287
  }
279
288
 
280
289
  export const WORKSHOP_WIDTH_OPTIONS: {[key: string]: number | 'auto'} = {
290
+ Auto: 'auto',
281
291
  '0': 0,
282
292
  '1': 1,
283
293
  '2': 2,
284
294
  '3': 3,
285
295
  '4': 4,
286
296
  '5': 5,
287
- Auto: 'auto',
288
297
  }
@@ -1,6 +1,6 @@
1
1
  import {SpinnerIcon} from '@sanity/icons'
2
2
  import styled, {keyframes} from 'styled-components'
3
- import {Box, Popover} from '../../primitives'
3
+ import {Box} from '../../primitives'
4
4
 
5
5
  /**
6
6
  * @internal
@@ -20,15 +20,6 @@ export const ListBox = styled(Box)`
20
20
  }
21
21
  `
22
22
 
23
- /**
24
- * @internal
25
- */
26
- export const ResultsPopover = styled(Popover)`
27
- &[data-popper-reference-hidden='true'] {
28
- display: none;
29
- }
30
- `
31
-
32
23
  const rotate = keyframes`
33
24
  from {
34
25
  transform: rotate(0deg);
@@ -20,8 +20,18 @@ import {
20
20
  import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
21
21
  import {_hasFocus, _raf, focusFirstDescendant} from '../../helpers'
22
22
  import {useArrayProp, useForwardedRef} from '../../hooks'
23
- import {Box, BoxProps, Button, Card, PopoverProps, Stack, Text, TextInput} from '../../primitives'
24
- import {AnimatedSpinnerIcon, ListBox, ResultsPopover, Root} from './autocomplete.styles'
23
+ import {
24
+ Box,
25
+ BoxProps,
26
+ Button,
27
+ Card,
28
+ Popover,
29
+ PopoverProps,
30
+ Stack,
31
+ Text,
32
+ TextInput,
33
+ } from '../../primitives'
34
+ import {AnimatedSpinnerIcon, ListBox, Root} from './autocomplete.styles'
25
35
  import {AutocompleteOption} from './autocompleteOption'
26
36
  import {autocompleteReducer} from './autocompleteReducer'
27
37
  import {
@@ -630,7 +640,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
630
640
  }
631
641
 
632
642
  return (
633
- <ResultsPopover
643
+ <Popover
634
644
  __unstable_margins={AUTOCOMPLETE_POPOVER_MARGINS}
635
645
  arrow={false}
636
646
  constrainSize
@@ -1,7 +1,11 @@
1
1
  import {AddIcon} from '@sanity/icons'
2
- import {Box, Button, Menu, MenuButton, MenuItem, Stack} from '@sanity/ui'
2
+ import {Box, Button, Menu, MenuButton, MenuButtonProps, MenuItem, Stack} from '@sanity/ui'
3
3
  import {useRef} from 'react'
4
4
 
5
+ const POPOVER_PROPS: MenuButtonProps['popover'] = {
6
+ constrainSize: true,
7
+ }
8
+
5
9
  export default function ClosableMenuButtonStory() {
6
10
  const ref = useRef<HTMLButtonElement | null>(null)
7
11
 
@@ -33,7 +37,7 @@ export default function ClosableMenuButtonStory() {
33
37
  </Stack>
34
38
  </Menu>
35
39
  }
36
- popover={{constrainSize: true}}
40
+ popover={POPOVER_PROPS}
37
41
  ref={ref}
38
42
  />
39
43
  </Stack>
@@ -18,8 +18,6 @@ const POPOVER_PROPS: MenuButtonProps['popover'] = {
18
18
  constrainSize: true,
19
19
  placement: 'bottom',
20
20
  portal: true,
21
- // preventOverflow: true,
22
- // width: 1,
23
21
  }
24
22
 
25
23
  const items: {tone: SelectableTone; message: string}[] = [
@@ -115,15 +113,11 @@ export default function ConstrainedInBoundaryStory() {
115
113
  id="validation-menu"
116
114
  menu={
117
115
  <Menu>
118
- {items.map((item, itemIndex) => {
119
- return (
120
- <MenuItem key={itemIndex} tone={item.tone}>
121
- <Box padding={3}>
122
- <Text>{item.message}</Text>
123
- </Box>
124
- </MenuItem>
125
- )
126
- })}
116
+ {items.map((item, itemIndex) => (
117
+ <MenuItem key={itemIndex} padding={5} tone={item.tone}>
118
+ <Text>{item.message}</Text>
119
+ </MenuItem>
120
+ ))}
127
121
  </Menu>
128
122
  }
129
123
  popover={POPOVER_PROPS}
@@ -1,7 +1,12 @@
1
1
  import {SelectIcon} from '@sanity/icons'
2
- import {Button, Flex, Menu, MenuButton, MenuItem} from '@sanity/ui'
2
+ import {Button, Flex, Menu, MenuButton, MenuButtonProps, MenuItem} from '@sanity/ui'
3
3
  import {useBoolean} from '@sanity/ui-workshop'
4
4
 
5
+ const POPOVER_PROPS: MenuButtonProps['popover'] = {
6
+ constrainSize: true,
7
+ matchReferenceWidth: true,
8
+ }
9
+
5
10
  export default function DisableFocusOnCloseStory() {
6
11
  const disableRestoreFocusOnClose = useBoolean('Disable restore focus on close', false)
7
12
 
@@ -28,7 +33,7 @@ export default function DisableFocusOnCloseStory() {
28
33
  <MenuItem text="Test 3" />
29
34
  </Menu>
30
35
  }
31
- popover={{constrainSize: true, matchReferenceWidth: true}}
36
+ popover={POPOVER_PROPS}
32
37
  />
33
38
  </Flex>
34
39
  )
@@ -6,12 +6,25 @@ import {
6
6
  LayerProvider,
7
7
  Menu,
8
8
  MenuButton,
9
+ MenuButtonProps,
9
10
  MenuDivider,
10
11
  MenuGroup,
11
12
  MenuItem,
12
13
  } from '@sanity/ui'
13
14
  import {useAction} from '@sanity/ui-workshop'
14
15
 
16
+ const POPOVER_PROPS: MenuButtonProps['popover'] = {
17
+ placement: 'bottom',
18
+ portal: true,
19
+ preventOverflow: true,
20
+ }
21
+
22
+ const NESTED_POPOVER_PROPS: MenuButtonProps['popover'] = {
23
+ placement: 'right-start',
24
+ portal: true,
25
+ preventOverflow: true,
26
+ }
27
+
15
28
  export default function GroupsStory() {
16
29
  return (
17
30
  <Box padding={[4, 5, 6]}>
@@ -63,7 +76,7 @@ export default function GroupsStory() {
63
76
  fontSize={1}
64
77
  onClick={useAction('Share')}
65
78
  padding={2}
66
- popover={{placement: 'right-start', portal: true}}
79
+ popover={NESTED_POPOVER_PROPS}
67
80
  text="Share"
68
81
  >
69
82
  <MenuItem
@@ -89,7 +102,7 @@ export default function GroupsStory() {
89
102
  fontSize={1}
90
103
  onClick={useAction('Share / More')}
91
104
  padding={2}
92
- popover={{placement: 'right-start', portal: true}}
105
+ popover={NESTED_POPOVER_PROPS}
93
106
  text="More"
94
107
  >
95
108
  <MenuItem
@@ -128,7 +141,7 @@ export default function GroupsStory() {
128
141
  />
129
142
  </Menu>
130
143
  }
131
- // popover={{constrainSize: true, portal: true, preventOverflow: true}}
144
+ popover={POPOVER_PROPS}
132
145
  />
133
146
  </LayerProvider>
134
147
 
@@ -7,16 +7,26 @@ import {
7
7
  LayerProvider,
8
8
  Menu,
9
9
  MenuButton,
10
+ MenuButtonProps,
10
11
  MenuDivider,
11
12
  MenuItem,
12
13
  } from '@sanity/ui'
13
14
  import {useAction, useBoolean, useSelect} from '@sanity/ui-workshop'
15
+ import {useMemo} from 'react'
14
16
  import {WORKSHOP_CARD_TONE_OPTIONS} from '../../../__workshop__/constants'
15
17
 
16
18
  export default function MenuButtonStory() {
17
19
  const layoutTone = useSelect('Layout tone', WORKSHOP_CARD_TONE_OPTIONS, 'default', 'Props')
18
20
  const portal = useBoolean('Portal', false, 'Props')
19
21
 
22
+ const popover: MenuButtonProps['popover'] = useMemo(
23
+ () => ({
24
+ constrainSize: true,
25
+ portal,
26
+ }),
27
+ [portal]
28
+ )
29
+
20
30
  return (
21
31
  <Card height="fill" tone={layoutTone}>
22
32
  <Box padding={[4, 5, 6]}>
@@ -56,7 +66,7 @@ export default function MenuButtonStory() {
56
66
  />
57
67
  </Menu>
58
68
  }
59
- popover={{constrainSize: true, portal}}
69
+ popover={popover}
60
70
  />
61
71
  </LayerProvider>
62
72
  <Button mode="ghost" id="next-button" text="Next" />
@@ -14,11 +14,18 @@ import {
14
14
  Flex,
15
15
  Menu,
16
16
  MenuButton,
17
+ MenuButtonProps,
17
18
  MenuDivider,
18
19
  MenuGroup,
19
20
  MenuItem,
20
21
  } from '@sanity/ui'
21
22
 
23
+ const POPOVER_PROPS: MenuButtonProps['popover'] = {
24
+ placement: 'right',
25
+ portal: true,
26
+ preventOverflow: true,
27
+ }
28
+
22
29
  export default function MenuGroupRightStory() {
23
30
  return (
24
31
  <Card height="fill" tone="transparent">
@@ -46,7 +53,7 @@ export default function MenuGroupRightStory() {
46
53
  <MenuItem icon={TrashIcon} text="Remove" tone="critical" />
47
54
  </Menu>
48
55
  }
49
- popover={{placement: 'right', portal: true}}
56
+ popover={POPOVER_PROPS}
50
57
  />
51
58
  </Box>
52
59
  </Flex>
@@ -1,6 +1,10 @@
1
- import {Box, Button, Menu, MenuButton, MenuItem, Stack, useToast} from '@sanity/ui'
1
+ import {Box, Button, Menu, MenuButton, MenuButtonProps, MenuItem, Stack, useToast} from '@sanity/ui'
2
2
  import {useCallback} from 'react'
3
3
 
4
+ const POPOVER_PROPS: MenuButtonProps['popover'] = {
5
+ constrainSize: true,
6
+ }
7
+
4
8
  export default function OnCloseMenuButton() {
5
9
  const {push} = useToast()
6
10
 
@@ -28,7 +32,7 @@ export default function OnCloseMenuButton() {
28
32
  </Stack>
29
33
  </Menu>
30
34
  }
31
- popover={{constrainSize: true}}
35
+ popover={POPOVER_PROPS}
32
36
  />
33
37
  <Button text="Blur test button" mode="ghost" />
34
38
  </Stack>
@@ -1,7 +1,21 @@
1
1
  import {CheckmarkIcon, ClockIcon, ExpandIcon, SearchIcon} from '@sanity/icons'
2
- import {Box, Button, Code, Menu, MenuButton, MenuDivider, MenuItem, Stack} from '@sanity/ui'
2
+ import {
3
+ Box,
4
+ Button,
5
+ Code,
6
+ Menu,
7
+ MenuButton,
8
+ MenuButtonProps,
9
+ MenuDivider,
10
+ MenuItem,
11
+ Stack,
12
+ } from '@sanity/ui'
3
13
  import {useState} from 'react'
4
14
 
15
+ const POPOVER_PROPS: MenuButtonProps['popover'] = {
16
+ matchReferenceWidth: true,
17
+ }
18
+
5
19
  export default function SelectedItemStory() {
6
20
  const [selectedIndex, setSelectedIndex] = useState(0)
7
21
 
@@ -42,7 +56,7 @@ export default function SelectedItemStory() {
42
56
  />
43
57
  </Menu>
44
58
  }
45
- popover={{matchReferenceWidth: true}}
59
+ popover={POPOVER_PROPS}
46
60
  />
47
61
  </Stack>
48
62
  </Box>
@@ -1,4 +1,14 @@
1
- import {Box, Button, Menu, MenuButton, MenuItem, Stack} from '@sanity/ui'
1
+ import {Box, Button, Menu, MenuButton, MenuButtonProps, MenuItem, Stack} from '@sanity/ui'
2
+
3
+ const POPOVER_PROPS: MenuButtonProps['popover'] = {
4
+ __unstable_margins: [1, 1, 1, 1],
5
+ arrow: false,
6
+ constrainSize: true,
7
+ fallbackPlacements: ['top-start'],
8
+ matchReferenceWidth: true,
9
+ radius: 0,
10
+ placement: 'bottom-start',
11
+ }
2
12
 
3
13
  export default function WithoutArrowStory() {
4
14
  return (
@@ -14,15 +24,7 @@ export default function WithoutArrowStory() {
14
24
  <MenuItem text="Item 3" />
15
25
  </Menu>
16
26
  }
17
- popover={{
18
- __unstable_margins: [1, 1, 1, 1],
19
- arrow: false,
20
- constrainSize: true,
21
- fallbackPlacements: ['top-start'],
22
- matchReferenceWidth: true,
23
- radius: 0,
24
- placement: 'bottom-start',
25
- }}
27
+ popover={POPOVER_PROPS}
26
28
  />
27
29
  </Stack>
28
30
  </Box>
@@ -48,10 +48,12 @@ export function cardBaseStyle(props: CardStyleProps & ThemeProps): FlattenSimple
48
48
  export function cardColorStyle(props: CardStyleProps & ThemeProps): FlattenSimpleInterpolation {
49
49
  const {$checkered, $focusRing, theme} = props
50
50
  const {focusRing} = theme.sanity
51
- const {base, card} = theme.sanity.color
51
+ const {base, card, dark} = theme.sanity.color
52
52
  const border = {width: 0, color: 'var(--card-border-color)'}
53
53
 
54
54
  return css`
55
+ color-scheme: ${dark ? 'dark' : 'light'};
56
+
55
57
  ${_colorVarsStyle(base, card.enabled, $checkered)}
56
58
 
57
59
  background-color: var(--card-bg-color);
@@ -1,10 +1,22 @@
1
1
  import {EllipsisVerticalIcon} from '@sanity/icons'
2
2
  import {Button, Card, Flex, Popover, Text, useClickOutside} from '@sanity/ui'
3
- import {useBoolean} from '@sanity/ui-workshop'
3
+ import {useBoolean, useSelect} from '@sanity/ui-workshop'
4
4
  import {useCallback, useState} from 'react'
5
+ import {
6
+ WORKSHOP_FLEX_ALIGN_OPTIONS,
7
+ WORKSHOP_FLEX_JUSTIFY_OPTIONS,
8
+ WORKSHOP_PLACEMENT_OPTIONS,
9
+ WORKSHOP_WIDTH_OPTIONS,
10
+ } from '../../../__workshop__/constants'
5
11
 
6
- export default function RightAlignedStory() {
12
+ export default function AlignedStory() {
7
13
  const constrainSize = useBoolean('Constrain size', false)
14
+ const placement = useSelect('Placement', WORKSHOP_PLACEMENT_OPTIONS, 'bottom')
15
+ const portal = useBoolean('Portal', true)
16
+ const width = useSelect('Width', WORKSHOP_WIDTH_OPTIONS, 'auto')
17
+
18
+ const flexAlign = useSelect('Align', WORKSHOP_FLEX_ALIGN_OPTIONS, 'flex-start')
19
+ const flexJustify = useSelect('Justify', WORKSHOP_FLEX_JUSTIFY_OPTIONS, 'flex-end')
8
20
 
9
21
  const [open, setOpen] = useState(false)
10
22
  const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
@@ -33,18 +45,18 @@ export default function RightAlignedStory() {
33
45
 
34
46
  return (
35
47
  <Card height="fill" padding={[4, 5, 6]} sizing="border" tone="transparent">
36
- <Card height="fill" padding={2} ref={setBoundaryElement} shadow={1}>
37
- <Flex justify="flex-end" padding={0}>
48
+ <Card height="fill" padding={2} ref={setBoundaryElement} shadow={1} sizing="border">
49
+ <Flex align={flexAlign} height="fill" justify={flexJustify}>
38
50
  <Popover
39
51
  boundaryElement={boundaryElement}
40
52
  constrainSize={constrainSize}
41
53
  content={content}
42
54
  open={open}
43
- overflow="auto"
44
55
  padding={3}
45
- portal
46
- placement="bottom"
56
+ portal={portal}
57
+ placement={placement}
47
58
  ref={setPopoverElement}
59
+ width={width}
48
60
  >
49
61
  <Button
50
62
  icon={EllipsisVerticalIcon}
@@ -24,28 +24,31 @@ export default function PlainStory() {
24
24
  const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
25
25
 
26
26
  return (
27
- <PortalProvider element={portalElement}>
28
- <Text muted size={1} style={{position: 'absolute', top: 40, left: 60}}>
29
- Scroll this box to reveal the popover
30
- </Text>
31
- <div
32
- ref={setBoundaryElement}
33
- style={{
34
- height: 'calc(100vh - 120px)',
35
- position: 'relative',
36
- margin: 60,
37
- overflow: 'auto',
38
- outline: '1px solid red',
39
- width: 'calc(100vw - 120px)',
40
- }}
41
- >
42
- <Card padding={4} style={{textAlign: 'center'}}>
43
- <div style={{padding: '150vh 0'}}>
27
+ <Card height="fill" padding={3} sizing="border">
28
+ <PortalProvider element={portalElement}>
29
+ <Text align="center" muted size={1}>
30
+ Scroll this box to reveal the popover
31
+ </Text>
32
+ <div
33
+ ref={setBoundaryElement}
34
+ style={{
35
+ height: 'calc(100vh - 120px)',
36
+ position: 'absolute',
37
+ top: 0,
38
+ left: 0,
39
+ margin: 60,
40
+ overflow: 'auto',
41
+ outline: '1px solid red',
42
+ width: 'calc(100vw - 120px)',
43
+ }}
44
+ >
45
+ <div style={{padding: '150vh 0', textAlign: 'center'}}>
44
46
  <Popover
45
47
  __unstable_margins={[1, 1, 1, 1]}
46
48
  arrow={arrow}
47
49
  boundaryElement={boundaryElementFlag ? boundaryElement : undefined}
48
50
  constrainSize={constrainSize}
51
+ content={<Text>popover content</Text>}
49
52
  fallbackPlacements={['top', 'bottom']}
50
53
  matchReferenceWidth={matchReferenceWidth}
51
54
  open={open}
@@ -60,9 +63,9 @@ export default function PlainStory() {
60
63
  <Button text="This button is the popover reference" />
61
64
  </Popover>
62
65
  </div>
63
- </Card>
64
- </div>
65
- <div ref={setPortalElement} />
66
- </PortalProvider>
66
+ </div>
67
+ <div ref={setPortalElement} />
68
+ </PortalProvider>
69
+ </Card>
67
70
  )
68
71
  }
@@ -15,6 +15,7 @@ export default function TestStory(): ReactElement {
15
15
  const [portalElement, setPortalElement] = useState<HTMLDivElement | null>(null)
16
16
  const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
17
17
  const arrow = useBoolean('Arrow', true)
18
+ const constrainSize = useBoolean('Constrain size', true)
18
19
  const matchReferenceWidth = useBoolean('Match reference width', false)
19
20
  const open = useBoolean('Open', true)
20
21
  const placement = useSelect('Placement', WORKSHOP_PLACEMENT_OPTIONS, 'bottom')
@@ -58,6 +59,7 @@ export default function TestStory(): ReactElement {
58
59
  <Popover
59
60
  arrow={arrow}
60
61
  content={<Text size={1}>{text}</Text>}
62
+ constrainSize={constrainSize}
61
63
  fallbackPlacements={['left', 'bottom', 'right', 'top']}
62
64
  matchReferenceWidth={matchReferenceWidth}
63
65
  open={open}
@@ -28,8 +28,8 @@ export default defineScope('primitives/popover', 'Popover', [
28
28
  component: lazy(() => import('./MarginsStory')),
29
29
  },
30
30
  {
31
- name: 'right-aligned',
32
- title: 'Right-aligned',
33
- component: lazy(() => import('./RightAlignedStory')),
31
+ name: 'aligned',
32
+ title: 'Aligned',
33
+ component: lazy(() => import('./AlignedStory')),
34
34
  },
35
35
  ])
@@ -0,0 +1,10 @@
1
+ import {PopoverMargins} from '../../types'
2
+
3
+ export const DEFAULT_POPOVER_DISTANCE = 4
4
+
5
+ export const DEFAULT_POPOVER_PADDING = 4
6
+
7
+ export const DEFAULT_POPOVER_ARROW_WIDTH = 27
8
+ export const DEFAULT_POPOVER_ARROW_HEIGHT = 11
9
+
10
+ export const DEFAULT_POPOVER_MARGINS: PopoverMargins = [0, 0, 0, 0]