chiplet 0.3.0 → 0.5.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/README.md +2 -5
- package/dist/assets/positioning.css.ts.vanilla-BLJ90UCF.css +60 -0
- package/dist/component/button/Button.js +5 -5
- package/dist/component/button/Button.js.map +1 -1
- package/dist/component/button/IconButton.js +1 -1
- package/dist/component/button/IconButton.js.map +1 -1
- package/dist/component/button/Interactive.js +2 -17
- package/dist/component/button/Interactive.js.map +1 -1
- package/dist/component/button/LinkButton.js +7 -5
- package/dist/component/button/LinkButton.js.map +1 -1
- package/dist/component/button/index.js +1 -0
- package/dist/component/button/index.js.map +1 -1
- package/dist/component/button/style/{index.css.vanilla.js → index.css.js} +5 -5
- package/dist/component/button/style/index.css.js.map +1 -0
- package/dist/component/checkbox/Checkbox.js +9 -19
- package/dist/component/checkbox/Checkbox.js.map +1 -1
- package/dist/component/checkbox/CheckboxGroup.js +2 -17
- package/dist/component/checkbox/CheckboxGroup.js.map +1 -1
- package/dist/component/checkbox/Radio.js +7 -18
- package/dist/component/checkbox/Radio.js.map +1 -1
- package/dist/component/checkbox/RadioGroup.js +2 -17
- package/dist/component/checkbox/RadioGroup.js.map +1 -1
- package/dist/component/checkbox/Switch.js +2 -2
- package/dist/component/checkbox/Switch.js.map +1 -1
- package/dist/component/checkbox/icon/index.js +0 -29
- package/dist/component/checkbox/icon/index.js.map +1 -1
- package/dist/component/checkbox/style/{index.css.vanilla.js → index.css.js} +4 -5
- package/dist/component/checkbox/style/index.css.js.map +1 -0
- package/dist/component/header/Header.js +2 -2
- package/dist/component/header/Header.js.map +1 -1
- package/dist/component/header/style/index.css.js +7 -0
- package/dist/component/header/style/index.css.js.map +1 -0
- package/dist/component/index.js +21 -19
- package/dist/component/index.js.map +1 -1
- package/dist/component/input/Input.js +7 -18
- package/dist/component/input/Input.js.map +1 -1
- package/dist/component/input/SearchInput.js +7 -13
- package/dist/component/input/SearchInput.js.map +1 -1
- package/dist/component/input/style/{index.css.vanilla.js → index.css.js} +5 -5
- package/dist/component/input/style/index.css.js.map +1 -0
- package/dist/component/menu/Menu.js +2 -28
- package/dist/component/menu/Menu.js.map +1 -1
- package/dist/component/menu/MenuButton.js +1 -3
- package/dist/component/menu/MenuButton.js.map +1 -1
- package/dist/component/menu/MenuItem.js +2 -18
- package/dist/component/menu/MenuItem.js.map +1 -1
- package/dist/component/menu/MenuItemCheckbox.js +4 -31
- package/dist/component/menu/MenuItemCheckbox.js.map +1 -1
- package/dist/component/menu/MenuItemRadio.js +5 -32
- package/dist/component/menu/MenuItemRadio.js.map +1 -1
- package/dist/component/menu/renderMenuItem.js +6 -2
- package/dist/component/menu/renderMenuItem.js.map +1 -1
- package/dist/component/popover/Dialog.js +2 -17
- package/dist/component/popover/Dialog.js.map +1 -1
- package/dist/component/popover/DismissButton.js +2 -19
- package/dist/component/popover/DismissButton.js.map +1 -1
- package/dist/component/popover/Popover.js +2 -17
- package/dist/component/popover/Popover.js.map +1 -1
- package/dist/component/popover/ShadowRoot.js +34 -0
- package/dist/component/popover/ShadowRoot.js.map +1 -0
- package/dist/component/popover/Tooltip.js +4 -18
- package/dist/component/popover/Tooltip.js.map +1 -1
- package/dist/component/popover/index.js +1 -0
- package/dist/component/popover/index.js.map +1 -1
- package/dist/component/popover/style/{index.css.vanilla.js → index.css.js} +5 -5
- package/dist/component/popover/style/index.css.js.map +1 -0
- package/dist/component/progress/Spinner.js +1 -1
- package/dist/component/progress/style/{index.css.vanilla.js → index.css.js} +4 -5
- package/dist/component/progress/style/index.css.js.map +1 -0
- package/dist/component/select/AutoComplete.js +7 -30
- package/dist/component/select/AutoComplete.js.map +1 -1
- package/dist/component/select/Group.js +3 -18
- package/dist/component/select/Group.js.map +1 -1
- package/dist/component/select/Option.js +7 -22
- package/dist/component/select/Option.js.map +1 -1
- package/dist/component/select/Select.js +6 -29
- package/dist/component/select/Select.js.map +1 -1
- package/dist/component/select/Separator.js +1 -1
- package/dist/component/select/style/{index.css.vanilla.js → index.css.js} +5 -5
- package/dist/component/select/style/index.css.js.map +1 -0
- package/dist/component/style/article.css.js +6 -0
- package/dist/component/style/article.css.js.map +1 -0
- package/dist/component/style/index.js +1 -1
- package/dist/component/typography/Body1.js +1 -1
- package/dist/component/typography/Body2.js +1 -1
- package/dist/component/typography/Body3.js +1 -1
- package/dist/component/typography/Caption1.js +1 -1
- package/dist/component/typography/Caption2.js +1 -1
- package/dist/component/typography/Heading1.js +1 -1
- package/dist/component/typography/Heading2.js +1 -1
- package/dist/component/typography/Heading3.js +1 -1
- package/dist/component/typography/Heading4.js +1 -1
- package/dist/component/typography/style/{index.css.vanilla.js → index.css.js} +4 -5
- package/dist/component/typography/style/index.css.js.map +1 -0
- package/dist/hook/accessibility/keyboard/Keyboard.js +6 -18
- package/dist/hook/accessibility/keyboard/Keyboard.js.map +1 -1
- package/dist/hook/accessibility/keyboard/Roving.js +0 -15
- package/dist/hook/accessibility/keyboard/Roving.js.map +1 -1
- package/dist/hook/accessibility/keyboard/context/index.js.map +1 -1
- package/dist/hook/accessibility/keyboard/hook/useLastFocused.js +1 -4
- package/dist/hook/accessibility/keyboard/hook/useLastFocused.js.map +1 -1
- package/dist/hook/accessibility/keyboard/hook/useNavigate.js.map +1 -1
- package/dist/hook/accessibility/keyboard/resolve.js +1 -4
- package/dist/hook/accessibility/keyboard/resolve.js.map +1 -1
- package/dist/hook/accessibility/keyboard/sort.js +0 -3
- package/dist/hook/accessibility/keyboard/sort.js.map +1 -1
- package/dist/hook/accessibility/keyboard/tree.js +1 -4
- package/dist/hook/accessibility/keyboard/tree.js.map +1 -1
- package/dist/hook/accessibility/keyboard/useController.js +2 -15
- package/dist/hook/accessibility/keyboard/useController.js.map +1 -1
- package/dist/hook/accessibility/keyboard/useKeyboard.js +2 -16
- package/dist/hook/accessibility/keyboard/useKeyboard.js.map +1 -1
- package/dist/hook/document/useHighlight.js +1 -6
- package/dist/hook/document/useHighlight.js.map +1 -1
- package/dist/hook/form/context/index.js.map +1 -1
- package/dist/hook/form/useAutoComplete.js +2 -16
- package/dist/hook/form/useAutoComplete.js.map +1 -1
- package/dist/hook/form/useChange.js.map +1 -1
- package/dist/hook/form/useCheckbox.js +0 -16
- package/dist/hook/form/useCheckbox.js.map +1 -1
- package/dist/hook/form/useChecked.js +1 -14
- package/dist/hook/form/useChecked.js.map +1 -1
- package/dist/hook/form/useForm.js +1 -15
- package/dist/hook/form/useForm.js.map +1 -1
- package/dist/hook/form/useGroup.js +18 -30
- package/dist/hook/form/useGroup.js.map +1 -1
- package/dist/hook/form/useName.js.map +1 -1
- package/dist/hook/form/useOption.js +0 -16
- package/dist/hook/form/useOption.js.map +1 -1
- package/dist/hook/form/useRadio.js +0 -16
- package/dist/hook/form/useRadio.js.map +1 -1
- package/dist/hook/form/useSelect.js +0 -16
- package/dist/hook/form/useSelect.js.map +1 -1
- package/dist/hook/form/useValue.js +0 -15
- package/dist/hook/form/useValue.js.map +1 -1
- package/dist/hook/index.js +22 -21
- package/dist/hook/index.js.map +1 -1
- package/dist/hook/observable/useObservable.js +6 -1
- package/dist/hook/observable/useObservable.js.map +1 -1
- package/dist/hook/popover/context/index.js.map +1 -1
- package/dist/hook/popover/index.js +2 -1
- package/dist/hook/popover/index.js.map +1 -1
- package/dist/hook/popover/style/positioning.css.js +13 -0
- package/dist/hook/popover/style/positioning.css.js.map +1 -0
- package/dist/hook/popover/useAnchorPositioning.js +6 -88
- package/dist/hook/popover/useAnchorPositioning.js.map +1 -1
- package/dist/hook/popover/useDialog.js +1 -15
- package/dist/hook/popover/useDialog.js.map +1 -1
- package/dist/hook/popover/useLightDismiss.js +16 -4
- package/dist/hook/popover/useLightDismiss.js.map +1 -1
- package/dist/hook/popover/useOverlay.js +8 -20
- package/dist/hook/popover/useOverlay.js.map +1 -1
- package/dist/hook/popover/usePopover.js +12 -23
- package/dist/hook/popover/usePopover.js.map +1 -1
- package/dist/hook/popover/usePositioning.js +10 -16
- package/dist/hook/popover/usePositioning.js.map +1 -1
- package/dist/hook/popover/useReturnFocus.js.map +1 -1
- package/dist/hook/popover/useTooltip.js +4 -15
- package/dist/hook/popover/useTooltip.js.map +1 -1
- package/dist/hook/promise/usePromise.js +1 -1
- package/dist/hook/promise/usePromise.js.map +1 -1
- package/dist/hook/react/refValue.js +0 -3
- package/dist/hook/react/refValue.js.map +1 -1
- package/dist/hook/react/useActivate.js +4 -4
- package/dist/hook/react/useActivate.js.map +1 -1
- package/dist/hook/react/useConst.js +3 -2
- package/dist/hook/react/useConst.js.map +1 -1
- package/dist/hook/react/useInteractive.js +1 -4
- package/dist/hook/react/useInteractive.js.map +1 -1
- package/dist/hook/react/useRefCallback.js.map +1 -1
- package/dist/hook/react/useUniqueId.js +1 -4
- package/dist/hook/react/useUniqueId.js.map +1 -1
- package/dist/index.js +112 -109
- package/dist/index.js.map +1 -1
- package/dist/infra/index.js +1 -1
- package/dist/infra/logging/logger.js +13 -10
- package/dist/infra/logging/logger.js.map +1 -1
- package/dist/theme/defineTheme.js +0 -3
- package/dist/theme/defineTheme.js.map +1 -1
- package/dist/theme/{global.css.vanilla.js → global.css.js} +4 -4
- package/dist/theme/global.css.js.map +1 -0
- package/dist/theme/index.js +5 -3
- package/dist/theme/index.js.map +1 -1
- package/dist/theme/{theme.css.vanilla.js → theme.css.js} +3 -3
- package/dist/theme/theme.css.js.map +1 -0
- package/dist/theme/{token.css.vanilla.js → token.css.js} +2 -2
- package/dist/theme/token.css.js.map +1 -0
- package/dist/theme/useSystemColorScheme.js +16 -16
- package/dist/theme/useSystemColorScheme.js.map +1 -1
- package/dist/util/array/index.js +0 -1
- package/dist/util/array/index.js.map +1 -1
- package/dist/util/document/{accessibility.css.vanilla.js → accessibility.css.js} +1 -1
- package/dist/util/document/accessibility.css.js.map +1 -0
- package/dist/util/document/index.js +1 -1
- package/dist/util/file/readAsDataURL.js +15 -4
- package/dist/util/file/readAsDataURL.js.map +1 -1
- package/dist/util/index.js +28 -30
- package/dist/util/index.js.map +1 -1
- package/dist/util/linked-list/buildLinkedList.js.map +1 -1
- package/dist/util/lock/lock.js +0 -2
- package/dist/util/lock/lock.js.map +1 -1
- package/dist/util/random/index.js +0 -1
- package/dist/util/random/index.js.map +1 -1
- package/dist/util/tree/addTreeNode.js.map +1 -1
- package/dist/util/tree/attachChild.js +7 -1
- package/dist/util/tree/attachChild.js.map +1 -1
- package/dist/util/tree/buildTree.js.map +1 -1
- package/dist/util/tree/detachChild.js +3 -0
- package/dist/util/tree/detachChild.js.map +1 -1
- package/dist/util/tree/iterateChildren.js.map +1 -1
- package/dist/util/tree/iterateTree.js.map +1 -1
- package/package.json +49 -47
- package/src/component/button/Button.tsx +4 -5
- package/src/component/button/IconButton.tsx +1 -1
- package/src/component/button/LinkButton.tsx +14 -6
- package/src/component/button/index.ts +1 -0
- package/src/component/checkbox/Checkbox.tsx +8 -1
- package/src/component/checkbox/Radio.tsx +5 -1
- package/src/component/checkbox/Switch.tsx +1 -1
- package/src/component/checkbox/icon/index.ts +1 -1
- package/src/component/header/Header.tsx +1 -1
- package/src/component/input/Input.tsx +5 -1
- package/src/component/input/SearchInput.tsx +10 -9
- package/src/component/menu/Menu.tsx +1 -1
- package/src/component/menu/MenuItemCheckbox.tsx +1 -1
- package/src/component/menu/MenuItemRadio.tsx +1 -1
- package/src/component/menu/renderMenuItem.tsx +5 -1
- package/src/component/popover/ShadowRoot.tsx +42 -0
- package/src/component/popover/Tooltip.tsx +2 -2
- package/src/component/popover/index.ts +1 -0
- package/src/component/select/AutoComplete.tsx +3 -7
- package/src/component/select/Group.tsx +1 -1
- package/src/component/select/Option.tsx +1 -1
- package/src/component/select/Select.tsx +3 -7
- package/src/hook/accessibility/keyboard/Keyboard.tsx +1 -1
- package/src/hook/accessibility/keyboard/Roving.tsx +1 -1
- package/src/hook/accessibility/keyboard/context/index.ts +2 -2
- package/src/hook/accessibility/keyboard/hook/useLastFocused.ts +7 -1
- package/src/hook/accessibility/keyboard/hook/useNavigate.ts +1 -1
- package/src/hook/accessibility/keyboard/resolve.ts +1 -1
- package/src/hook/accessibility/keyboard/useController.ts +3 -2
- package/src/hook/accessibility/keyboard/useKeyboard.ts +3 -2
- package/src/hook/document/useHighlight.ts +5 -4
- package/src/hook/form/context/index.ts +1 -1
- package/src/hook/form/useAutoComplete.ts +14 -14
- package/src/hook/form/useChange.ts +1 -1
- package/src/hook/form/useCheckbox.ts +2 -2
- package/src/hook/form/useChecked.ts +3 -2
- package/src/hook/form/useForm.ts +1 -1
- package/src/hook/form/useGroup.ts +20 -21
- package/src/hook/form/useName.ts +1 -1
- package/src/hook/form/useOption.ts +2 -2
- package/src/hook/form/useRadio.ts +2 -2
- package/src/hook/form/useSelect.ts +15 -12
- package/src/hook/form/useValue.ts +3 -2
- package/src/hook/observable/useObservable.ts +14 -1
- package/src/hook/popover/context/index.ts +1 -1
- package/src/hook/popover/style/positioning.css.ts +112 -0
- package/src/hook/popover/useAnchorPositioning.ts +16 -105
- package/src/hook/popover/useDialog.ts +5 -4
- package/src/hook/popover/useLightDismiss.ts +27 -0
- package/src/hook/popover/useOverlay.ts +17 -8
- package/src/hook/popover/usePopover.ts +22 -24
- package/src/hook/popover/usePositioning.ts +17 -20
- package/src/hook/popover/useReturnFocus.ts +12 -3
- package/src/hook/popover/useTooltip.ts +10 -9
- package/src/hook/promise/usePromise.ts +4 -1
- package/src/hook/react/useActivate.ts +8 -1
- package/src/hook/react/useConst.ts +3 -3
- package/src/hook/react/useRefCallback.ts +3 -1
- package/src/infra/logging/logger.ts +43 -19
- package/src/theme/global.css.ts +1 -28
- package/src/theme/index.ts +4 -0
- package/src/theme/useSystemColorScheme.ts +22 -20
- package/src/util/array/index.ts +0 -1
- package/src/util/document/accessibility.css.ts +1 -1
- package/src/util/file/readAsDataURL.ts +17 -4
- package/src/util/linked-list/buildLinkedList.ts +1 -1
- package/src/util/number/index.ts +2 -0
- package/src/util/random/index.ts +4 -1
- package/src/util/tree/addTreeNode.ts +1 -1
- package/src/util/tree/attachChild.ts +13 -2
- package/src/util/tree/buildTree.ts +1 -1
- package/src/util/tree/detachChild.ts +7 -1
- package/src/util/tree/iterateChildren.ts +1 -1
- package/src/util/tree/iterateTree.ts +1 -1
- package/dist/component/button/style/index.css.vanilla.js.map +0 -1
- package/dist/component/checkbox/style/index.css.vanilla.js.map +0 -1
- package/dist/component/header/style/index.css.vanilla.js +0 -7
- package/dist/component/header/style/index.css.vanilla.js.map +0 -1
- package/dist/component/input/style/index.css.vanilla.js.map +0 -1
- package/dist/component/popover/style/index.css.vanilla.js.map +0 -1
- package/dist/component/progress/style/index.css.vanilla.js.map +0 -1
- package/dist/component/select/style/index.css.vanilla.js.map +0 -1
- package/dist/component/style/article.css.vanilla.js +0 -6
- package/dist/component/style/article.css.vanilla.js.map +0 -1
- package/dist/component/typography/style/index.css.vanilla.js.map +0 -1
- package/dist/theme/global.css.vanilla.js.map +0 -1
- package/dist/theme/theme.css.vanilla.js.map +0 -1
- package/dist/theme/token.css.vanilla.js.map +0 -1
- package/dist/util/array/fromAsync.js +0 -11
- package/dist/util/array/fromAsync.js.map +0 -1
- package/dist/util/document/accessibility.css.vanilla.js.map +0 -1
- package/src/util/array/fromAsync.ts +0 -11
- /package/dist/{article.css → assets/article.css.ts.vanilla-s_HEpsy3.css} +0 -0
- /package/dist/{global.css → assets/global.css.ts.vanilla-CTwjHiaM.css} +0 -0
- /package/dist/{index8.css → assets/index.css.ts.vanilla-9qGDrdgn.css} +0 -0
- /package/dist/{index6.css → assets/index.css.ts.vanilla-BsBngo8U.css} +0 -0
- /package/dist/{index2.css → assets/index.css.ts.vanilla-CVNLkHc9.css} +0 -0
- /package/dist/{index3.css → assets/index.css.ts.vanilla-C_RzxiYH.css} +0 -0
- /package/dist/{index5.css → assets/index.css.ts.vanilla-CvQQLJ-M.css} +0 -0
- /package/dist/{index.css → assets/index.css.ts.vanilla-DGmHFJbF.css} +0 -0
- /package/dist/{index4.css → assets/index.css.ts.vanilla-VHSAjLub.css} +0 -0
- /package/dist/{index7.css → assets/index.css.ts.vanilla-kgyRRvgH.css} +0 -0
- /package/dist/{theme.css → assets/theme.css.ts.vanilla-Bjn8sb_B.css} +0 -0
- /package/dist/{token.css → assets/token.css.ts.vanilla-B3LtFaO7.css} +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { entries, fromEntries, keys } from '#util'
|
|
2
|
+
import type { Alignment, Placement } from '@floating-ui/utils'
|
|
3
|
+
import { globalStyle } from '@vanilla-extract/css'
|
|
4
|
+
import type { Simplify } from 'type-fest'
|
|
5
|
+
import { generateDeterministicId } from '../../../util/random/generateDeterministicId'
|
|
6
|
+
|
|
7
|
+
export type Side = 'above' | 'below' | 'before' | 'after'
|
|
8
|
+
export type Axis = 'block' | 'inline'
|
|
9
|
+
export type Position = Simplify<Side | `${Side}-${Alignment}`>
|
|
10
|
+
|
|
11
|
+
export const Position = [
|
|
12
|
+
'above',
|
|
13
|
+
'below',
|
|
14
|
+
'before',
|
|
15
|
+
'after',
|
|
16
|
+
'above-start',
|
|
17
|
+
'above-end',
|
|
18
|
+
'below-start',
|
|
19
|
+
'below-end',
|
|
20
|
+
'before-start',
|
|
21
|
+
'before-end',
|
|
22
|
+
'after-start',
|
|
23
|
+
'after-end',
|
|
24
|
+
] as const
|
|
25
|
+
|
|
26
|
+
export const positionMap: Record<Position, Placement> = {
|
|
27
|
+
'above': 'top',
|
|
28
|
+
'below': 'bottom',
|
|
29
|
+
'before': 'left',
|
|
30
|
+
'after': 'right',
|
|
31
|
+
'above-start': 'top-start',
|
|
32
|
+
'above-end': 'top-end',
|
|
33
|
+
'below-start': 'bottom-start',
|
|
34
|
+
'below-end': 'bottom-end',
|
|
35
|
+
'before-start': 'left-start',
|
|
36
|
+
'before-end': 'left-end',
|
|
37
|
+
'after-start': 'right-start',
|
|
38
|
+
'after-end': 'right-end',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const placementMap: Record<Placement, Position> = fromEntries(
|
|
42
|
+
entries(positionMap).map(([position, placement]) => [placement, position])
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
export const positionAxisMap: Record<Position, Axis> = {
|
|
46
|
+
'above': 'block',
|
|
47
|
+
'above-start': 'block',
|
|
48
|
+
'above-end': 'block',
|
|
49
|
+
'below': 'block',
|
|
50
|
+
'below-start': 'block',
|
|
51
|
+
'below-end': 'block',
|
|
52
|
+
'before': 'inline',
|
|
53
|
+
'before-start': 'inline',
|
|
54
|
+
'before-end': 'inline',
|
|
55
|
+
'after': 'inline',
|
|
56
|
+
'after-start': 'inline',
|
|
57
|
+
'after-end': 'inline',
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* https://developer.mozilla.org/en-US/docs/Web/CSS/position-area_value#logical_grid_keyword_defaults
|
|
62
|
+
*/
|
|
63
|
+
export const positionAreaMap: Record<Position, string> = {
|
|
64
|
+
'above': 'block-start',
|
|
65
|
+
'below': 'block-end',
|
|
66
|
+
'before': 'inline-start',
|
|
67
|
+
'after': 'inline-end',
|
|
68
|
+
'above-start': 'start span-end',
|
|
69
|
+
'above-end': 'start span-start',
|
|
70
|
+
'below-start': 'end span-end',
|
|
71
|
+
'below-end': 'end span-start',
|
|
72
|
+
'before-start': 'inline-start span-block-end',
|
|
73
|
+
'before-end': 'inline-start span-block-start',
|
|
74
|
+
'after-start': 'inline-end span-block-end',
|
|
75
|
+
'after-end': 'inline-end span-block-start',
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const positionInsetMap: Record<Position, keyof React.CSSProperties> = {
|
|
79
|
+
'above': 'insetBlockEnd',
|
|
80
|
+
'above-start': 'insetBlockEnd',
|
|
81
|
+
'above-end': 'insetBlockEnd',
|
|
82
|
+
'below': 'insetBlockStart',
|
|
83
|
+
'below-start': 'insetBlockStart',
|
|
84
|
+
'below-end': 'insetBlockStart',
|
|
85
|
+
'before': 'insetInlineEnd',
|
|
86
|
+
'before-start': 'insetInlineEnd',
|
|
87
|
+
'before-end': 'insetInlineEnd',
|
|
88
|
+
'after': 'insetInlineStart',
|
|
89
|
+
'after-start': 'insetInlineStart',
|
|
90
|
+
'after-end': 'insetInlineStart',
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const PositionOffset = generateDeterministicId('--offset')
|
|
94
|
+
|
|
95
|
+
const PositionTryOptionName = generateDeterministicId('')
|
|
96
|
+
|
|
97
|
+
export const positionTryOptionMap: Record<Position, string> = fromEntries(
|
|
98
|
+
keys(positionMap).map((position) => [
|
|
99
|
+
position,
|
|
100
|
+
`--position-try-option-${position}-${PositionTryOptionName}`,
|
|
101
|
+
])
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
for (const [position, area] of entries(positionAreaMap)) {
|
|
105
|
+
globalStyle(`@position-try ${positionTryOptionMap[position]}`, {
|
|
106
|
+
inset: 'auto',
|
|
107
|
+
[positionInsetMap[position]]: `var(${PositionOffset})`,
|
|
108
|
+
positionArea: area,
|
|
109
|
+
// TODO: extend 'positionTryOptionMap', add '@starting-style' entry
|
|
110
|
+
// animation, and try to reuse 'PopoverStyle'
|
|
111
|
+
})
|
|
112
|
+
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { entries, fromEntries } from '#util'
|
|
2
1
|
import {
|
|
3
2
|
getAlignment,
|
|
4
3
|
getExpandedPlacements,
|
|
5
4
|
getOppositeAxisPlacements,
|
|
6
5
|
getOppositePlacement,
|
|
7
|
-
type Alignment,
|
|
8
|
-
type Placement,
|
|
9
6
|
} from '@floating-ui/utils'
|
|
10
7
|
import { useMemo } from 'react'
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
8
|
+
import { useUniqueId } from '../react/useUniqueId'
|
|
9
|
+
import {
|
|
10
|
+
placementMap,
|
|
11
|
+
positionAreaMap,
|
|
12
|
+
positionAxisMap,
|
|
13
|
+
positionInsetMap,
|
|
14
|
+
positionMap,
|
|
15
|
+
PositionOffset,
|
|
16
|
+
positionTryOptionMap,
|
|
17
|
+
type Position,
|
|
18
|
+
} from './style/positioning.css'
|
|
13
19
|
import type { Positioning, PositioningOptions } from './usePositioning'
|
|
14
20
|
|
|
15
21
|
/**
|
|
@@ -36,22 +42,19 @@ export function useAnchorPositioning(options: PositioningOptions): Positioning {
|
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
positionedStyle = {
|
|
45
|
+
[PositionOffset]: `${offset}px`,
|
|
39
46
|
position: strategy,
|
|
40
47
|
positionAnchor: anchorName,
|
|
41
48
|
positionArea: positionAreaMap[position],
|
|
42
|
-
// TODO: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@position-try
|
|
43
49
|
positionTry: fallback
|
|
44
|
-
.map((position) =>
|
|
50
|
+
.map((position) => positionTryOptionMap[position])
|
|
45
51
|
.join(', '),
|
|
46
52
|
margin: '0',
|
|
47
|
-
inset: 'auto',
|
|
48
|
-
|
|
49
|
-
// When an anchor-positioned element is positioned using the position-area property,
|
|
50
|
-
// any inset properties set, such as top or inset-inline-end, specify offsets from the position-area.
|
|
51
|
-
[insetMap[position]]: `${offset}px`,
|
|
53
|
+
inset: 'auto',
|
|
54
|
+
[positionInsetMap[position]]: `var(${PositionOffset})`,
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
switch (options.align &&
|
|
57
|
+
switch (options.align && positionAxisMap[position]) {
|
|
55
58
|
case 'block':
|
|
56
59
|
positionedStyle.minInlineSize = `min(100vi, 100%, anchor-size(self-inline))`
|
|
57
60
|
break
|
|
@@ -71,83 +74,6 @@ export function useAnchorPositioning(options: PositioningOptions): Positioning {
|
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
type Side = 'above' | 'below' | 'before' | 'after'
|
|
75
|
-
|
|
76
|
-
export type Position = Simplify<Side | `${Side}-${Alignment}`>
|
|
77
|
-
|
|
78
|
-
export const Position = [
|
|
79
|
-
'above',
|
|
80
|
-
'below',
|
|
81
|
-
'before',
|
|
82
|
-
'after',
|
|
83
|
-
'above-start',
|
|
84
|
-
'above-end',
|
|
85
|
-
'below-start',
|
|
86
|
-
'below-end',
|
|
87
|
-
'before-start',
|
|
88
|
-
'before-end',
|
|
89
|
-
'after-start',
|
|
90
|
-
'after-end',
|
|
91
|
-
] as const
|
|
92
|
-
|
|
93
|
-
type Axis = 'block' | 'inline'
|
|
94
|
-
|
|
95
|
-
function positionSide(position: Position): Side {
|
|
96
|
-
return position.split('-')[0] as Side
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function positionAxis(position: Position): Axis {
|
|
100
|
-
switch (positionSide(position)) {
|
|
101
|
-
case 'above':
|
|
102
|
-
case 'below':
|
|
103
|
-
return 'block'
|
|
104
|
-
case 'before':
|
|
105
|
-
case 'after':
|
|
106
|
-
return 'inline'
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export const positionMap: Record<Position, Placement> = {
|
|
111
|
-
'above': 'top',
|
|
112
|
-
'below': 'bottom',
|
|
113
|
-
'before': 'left',
|
|
114
|
-
'after': 'right',
|
|
115
|
-
'above-start': 'top-start',
|
|
116
|
-
'above-end': 'top-end',
|
|
117
|
-
'below-start': 'bottom-start',
|
|
118
|
-
'below-end': 'bottom-end',
|
|
119
|
-
'before-start': 'left-start',
|
|
120
|
-
'before-end': 'left-end',
|
|
121
|
-
'after-start': 'right-start',
|
|
122
|
-
'after-end': 'right-end',
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export const placementMap: Record<Placement, Position> = fromEntries(
|
|
126
|
-
entries(positionMap).map(([position, placement]) => [placement, position])
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* TODO
|
|
131
|
-
* - above => [flip-block, flip-start, flip-start flip-inline]
|
|
132
|
-
* - above-start => [flip-inline, flip-block, flip-block flip-inline, flip-start, flip-start flip-block, flip-start flip-inline, flip-start flip-inline flip-block]
|
|
133
|
-
*
|
|
134
|
-
* https://developer.mozilla.org/en-US/docs/Web/CSS/position-area_value#logical_grid_keyword_defaults
|
|
135
|
-
*/
|
|
136
|
-
export const positionAreaMap: Record<Position, string> = {
|
|
137
|
-
'above': 'block-start',
|
|
138
|
-
'below': 'block-end',
|
|
139
|
-
'before': 'inline-start',
|
|
140
|
-
'after': 'inline-end',
|
|
141
|
-
'above-start': 'start span-end',
|
|
142
|
-
'above-end': 'start span-start',
|
|
143
|
-
'below-start': 'end span-end',
|
|
144
|
-
'below-end': 'end span-start',
|
|
145
|
-
'before-start': 'inline-start span-block-end',
|
|
146
|
-
'before-end': 'inline-start span-block-start',
|
|
147
|
-
'after-start': 'inline-end span-block-end',
|
|
148
|
-
'after-end': 'inline-end span-block-start',
|
|
149
|
-
}
|
|
150
|
-
|
|
151
77
|
/**
|
|
152
78
|
* https://floating-ui.com/docs/flip#fallbackplacements
|
|
153
79
|
*
|
|
@@ -167,21 +93,6 @@ export function positionTry(position: Position, tryCrossAxis?: boolean) {
|
|
|
167
93
|
).map((placement) => placementMap[placement])
|
|
168
94
|
}
|
|
169
95
|
|
|
170
|
-
const insetMap: Record<Position, string> = {
|
|
171
|
-
'above': 'insetBlock', // TODO: when flipping to the before/after position, we should use the `inset-inline` property instead.
|
|
172
|
-
'below': 'insetBlock',
|
|
173
|
-
'before': 'insetInline',
|
|
174
|
-
'after': 'insetInline',
|
|
175
|
-
'above-start': 'insetBlock',
|
|
176
|
-
'above-end': 'insetBlock',
|
|
177
|
-
'below-start': 'insetBlock',
|
|
178
|
-
'below-end': 'insetBlock',
|
|
179
|
-
'before-start': 'insetInline',
|
|
180
|
-
'before-end': 'insetInline',
|
|
181
|
-
'after-start': 'insetInline',
|
|
182
|
-
'after-end': 'insetInline',
|
|
183
|
-
}
|
|
184
|
-
|
|
185
96
|
export function usePositioningOptions(options: PositioningOptions) {
|
|
186
97
|
const { position = 'below' } = options
|
|
187
98
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { useRefObject, useUniqueId } from '#hook'
|
|
3
2
|
import {
|
|
4
3
|
cloneElement,
|
|
5
4
|
createElement,
|
|
@@ -7,16 +6,18 @@ import {
|
|
|
7
6
|
useLayoutEffect,
|
|
8
7
|
useRef,
|
|
9
8
|
} from 'react'
|
|
9
|
+
import { useRefObject } from '../react/useRefObject'
|
|
10
|
+
import { useUniqueId } from '../react/useUniqueId'
|
|
10
11
|
import { OverlayContext } from './context'
|
|
11
12
|
import { useAnchor } from './useAnchor'
|
|
13
|
+
import { useLightDismiss } from './useLightDismiss'
|
|
12
14
|
import {
|
|
13
|
-
useLightDismiss,
|
|
14
15
|
useOverlay,
|
|
15
|
-
useReturnFocus,
|
|
16
16
|
type Overlay,
|
|
17
17
|
type OverlayAnchorProps,
|
|
18
18
|
type ToggleCallback,
|
|
19
|
-
} from '
|
|
19
|
+
} from './useOverlay'
|
|
20
|
+
import { useReturnFocus } from './useReturnFocus'
|
|
20
21
|
|
|
21
22
|
type DialogTag = 'dialog'
|
|
22
23
|
|
|
@@ -28,6 +28,33 @@ export function useLightDismiss<
|
|
|
28
28
|
ref.current.source = source
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
+
{
|
|
32
|
+
const { onKeyDown } = anchorProps
|
|
33
|
+
|
|
34
|
+
anchorProps = {
|
|
35
|
+
...anchorProps,
|
|
36
|
+
onKeyDown: useCallback<NonNullable<typeof onKeyDown>>(
|
|
37
|
+
(ev) => {
|
|
38
|
+
onKeyDown?.(ev)
|
|
39
|
+
|
|
40
|
+
// A pending open or close claims the escape key to abort
|
|
41
|
+
// itself by reverting to the committed state. A committed
|
|
42
|
+
// open or an idle overlay toggles to a no-op and defers to
|
|
43
|
+
// the document listener below, which closes the topmost
|
|
44
|
+
// overlay instead.
|
|
45
|
+
if (
|
|
46
|
+
!ev.defaultPrevented &&
|
|
47
|
+
isEscapeKey(ev) &&
|
|
48
|
+
ref.current.overlay.toggle(ev, ref.current.overlay.open, 'escape')
|
|
49
|
+
) {
|
|
50
|
+
ev.preventDefault()
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
[onKeyDown]
|
|
54
|
+
),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
31
58
|
{
|
|
32
59
|
const { onClickCapture } = positionedProps
|
|
33
60
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { useDefault } from '#hook'
|
|
3
|
-
import type { GlobalAttributes } from '#hook/react/element.d'
|
|
4
2
|
import { useCallback, useLayoutEffect, useMemo, useRef } from 'react'
|
|
3
|
+
import { useDefault } from '../form/useDefault'
|
|
4
|
+
import type { GlobalAttributes } from '../react/element.d'
|
|
5
5
|
|
|
6
6
|
export interface OverlayAnchorProps
|
|
7
7
|
extends GlobalAttributes, React.AriaAttributes, React.RefAttributes<Element> {
|
|
@@ -9,6 +9,7 @@ export interface OverlayAnchorProps
|
|
|
9
9
|
onFocus?: React.FocusEventHandler<Element> | undefined
|
|
10
10
|
onBlur?: React.FocusEventHandler<Element> | undefined
|
|
11
11
|
onClick?: React.MouseEventHandler<Element> | undefined
|
|
12
|
+
onKeyDown?: React.KeyboardEventHandler<Element> | undefined
|
|
12
13
|
onPointerEnter?: React.PointerEventHandler<Element> | undefined
|
|
13
14
|
onPointerLeave?: React.PointerEventHandler<Element> | undefined
|
|
14
15
|
}
|
|
@@ -33,7 +34,7 @@ export interface Overlay<T extends HTMLElement = HTMLElement> {
|
|
|
33
34
|
ev: Event | React.SyntheticEvent,
|
|
34
35
|
open?: boolean,
|
|
35
36
|
hint?: string
|
|
36
|
-
) =>
|
|
37
|
+
) => boolean
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export function useOverlay<T extends HTMLElement>(options: OverlayOptions<T>) {
|
|
@@ -55,13 +56,21 @@ export function useOverlay<T extends HTMLElement>(options: OverlayOptions<T>) {
|
|
|
55
56
|
(ev, open, hint) => {
|
|
56
57
|
open ??= !ref.current
|
|
57
58
|
|
|
58
|
-
if (ref.current
|
|
59
|
-
|
|
59
|
+
if (ref.current === open) {
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setOpen(ev, open, hint)
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
// A vetoed change (`onToggle` preventing the event) never commits in
|
|
66
|
+
// `useDefault`, so the uncommitted mirror in `ref` must not advance.
|
|
67
|
+
if (ev.defaultPrevented) {
|
|
68
|
+
return false
|
|
64
69
|
}
|
|
70
|
+
|
|
71
|
+
ref.current = open
|
|
72
|
+
|
|
73
|
+
return true
|
|
65
74
|
},
|
|
66
75
|
[setOpen]
|
|
67
76
|
)
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import {
|
|
3
|
-
Keyboard,
|
|
4
|
-
useController,
|
|
5
|
-
useRefCallback,
|
|
6
|
-
useRefObject,
|
|
7
|
-
useUniqueId,
|
|
8
|
-
type KeyboardOptions,
|
|
9
|
-
type KeyboardProps,
|
|
10
|
-
type NavigationDirection,
|
|
11
|
-
} from '#hook'
|
|
12
|
-
import type { HTMLElementRef } from '#hook/react/element.d'
|
|
13
2
|
import {
|
|
14
3
|
cloneElement,
|
|
15
4
|
createElement,
|
|
@@ -17,6 +6,17 @@ import {
|
|
|
17
6
|
useLayoutEffect,
|
|
18
7
|
useRef,
|
|
19
8
|
} from 'react'
|
|
9
|
+
import {
|
|
10
|
+
Keyboard,
|
|
11
|
+
type KeyboardOptions,
|
|
12
|
+
type KeyboardProps,
|
|
13
|
+
type NavigationDirection,
|
|
14
|
+
} from '../accessibility/keyboard/Keyboard'
|
|
15
|
+
import { useController } from '../accessibility/keyboard/useController'
|
|
16
|
+
import type { HTMLElementRef } from '../react/element.d'
|
|
17
|
+
import { useRefCallback } from '../react/useRefCallback'
|
|
18
|
+
import { useRefObject } from '../react/useRefObject'
|
|
19
|
+
import { useUniqueId } from '../react/useUniqueId'
|
|
20
20
|
import { OverlayContext } from './context'
|
|
21
21
|
import { useAnchor } from './useAnchor'
|
|
22
22
|
import { useLightDismiss } from './useLightDismiss'
|
|
@@ -149,6 +149,12 @@ export function usePopover<T extends React.HTMLElementType = 'div'>(
|
|
|
149
149
|
ref: anchorRef,
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
keyboardProps = {
|
|
153
|
+
...keyboardProps,
|
|
154
|
+
ref: setKeyboardRef,
|
|
155
|
+
children,
|
|
156
|
+
}
|
|
157
|
+
|
|
152
158
|
positionedProps = {
|
|
153
159
|
...positionedProps,
|
|
154
160
|
role: positionedProps.role || 'dialog',
|
|
@@ -160,21 +166,13 @@ export function usePopover<T extends React.HTMLElementType = 'div'>(
|
|
|
160
166
|
...positionedProps.style,
|
|
161
167
|
},
|
|
162
168
|
ref: positionedRef,
|
|
169
|
+
children: createElement(
|
|
170
|
+
OverlayContext,
|
|
171
|
+
{ value: overlay },
|
|
172
|
+
createElement(Keyboard, keyboardProps)
|
|
173
|
+
),
|
|
163
174
|
}
|
|
164
175
|
|
|
165
|
-
keyboardProps = {
|
|
166
|
-
...keyboardProps,
|
|
167
|
-
ref: setKeyboardRef,
|
|
168
|
-
children,
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// eslint-disable-next-line react-hooks/refs
|
|
172
|
-
positionedProps.children = createElement(
|
|
173
|
-
OverlayContext,
|
|
174
|
-
{ value: overlay },
|
|
175
|
-
createElement(Keyboard, keyboardProps)
|
|
176
|
-
)
|
|
177
|
-
|
|
178
176
|
return {
|
|
179
177
|
overlay,
|
|
180
178
|
position: positioning.position,
|
|
@@ -13,15 +13,20 @@ import {
|
|
|
13
13
|
} from '@floating-ui/dom'
|
|
14
14
|
import { getOppositePlacement, getSide } from '@floating-ui/utils'
|
|
15
15
|
import { isEqual } from 'lodash-es'
|
|
16
|
-
import {
|
|
16
|
+
import { useLayoutEffect, useRef, useState } from 'react'
|
|
17
17
|
import { flushSync } from 'react-dom'
|
|
18
|
-
import { refValue, type RefValue } from '../react'
|
|
19
|
-
import type { Position } from './
|
|
20
|
-
import {
|
|
18
|
+
import { refValue, type RefValue } from '../react/refValue'
|
|
19
|
+
import type { Position } from './style/positioning.css'
|
|
20
|
+
import { placementMap, positionMap } from './style/positioning.css'
|
|
21
|
+
import { usePositioningOptions } from './useAnchorPositioning'
|
|
22
|
+
|
|
23
|
+
export {
|
|
21
24
|
placementMap,
|
|
25
|
+
Position,
|
|
26
|
+
positionAreaMap,
|
|
27
|
+
positionAxisMap,
|
|
22
28
|
positionMap,
|
|
23
|
-
|
|
24
|
-
} from './useAnchorPositioning'
|
|
29
|
+
} from './style/positioning.css'
|
|
25
30
|
|
|
26
31
|
export interface PositioningOptions {
|
|
27
32
|
disabled?: boolean | undefined
|
|
@@ -61,22 +66,14 @@ export function usePositioning(
|
|
|
61
66
|
arrowRef?: RefValue<HTMLElement> | undefined
|
|
62
67
|
}
|
|
63
68
|
): Positioning {
|
|
64
|
-
|
|
65
|
-
const ref = useRef(_options)
|
|
69
|
+
const [stableOptions, setStableOptions] = useState(_options)
|
|
66
70
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// eslint-disable-next-line react-hooks/immutability, react-hooks/refs
|
|
70
|
-
_options = ref.current
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
ref.current = _options
|
|
75
|
-
})
|
|
71
|
+
if (!isEqual(_options, stableOptions)) {
|
|
72
|
+
setStableOptions(_options)
|
|
76
73
|
}
|
|
77
74
|
|
|
78
|
-
const { anchorRef, positionedRef, arrowRef } =
|
|
79
|
-
const options = usePositioningOptions(
|
|
75
|
+
const { anchorRef, positionedRef, arrowRef } = stableOptions
|
|
76
|
+
const options = usePositioningOptions(stableOptions)
|
|
80
77
|
const { position, strategy } = options
|
|
81
78
|
const [state, setState] = useState<State>({ x: 0, y: 0, position, strategy })
|
|
82
79
|
const ref = useRef({ state })
|
|
@@ -96,7 +93,7 @@ export function usePositioning(
|
|
|
96
93
|
const { signal } = (controller = new AbortController())
|
|
97
94
|
|
|
98
95
|
try {
|
|
99
|
-
const isRTL = await platform.isRTL(positionedEl) // https://github.com/floating-ui/floating-ui/blob/
|
|
96
|
+
const isRTL = await platform.isRTL(positionedEl) // https://github.com/floating-ui/floating-ui/blob/c3042f1f37d96dfadff1d8894daa31e120d89ed4/packages/core/src/computePosition.ts#L35
|
|
100
97
|
const placement = resolve(positionMap[options.position], isRTL)
|
|
101
98
|
const fallbackPlacements = options.fallback.map((position) =>
|
|
102
99
|
resolve(positionMap[position], isRTL)
|
|
@@ -28,8 +28,14 @@ export function useReturnFocus(overlay: Overlay) {
|
|
|
28
28
|
}
|
|
29
29
|
}, [overlay.open])
|
|
30
30
|
|
|
31
|
-
//
|
|
32
|
-
//
|
|
31
|
+
// React records the active element before its mutation phase and, at the
|
|
32
|
+
// end of that phase, moves focus back to it when focus moved elsewhere
|
|
33
|
+
// and the element is still connected. The 'useLayoutEffect' cleanup of a
|
|
34
|
+
// component deleted during the commit runs inside the mutation phase, so
|
|
35
|
+
// focus it restores is immediately moved back by React. The passive
|
|
36
|
+
// 'useEffect' cleanup runs after the commit, so its restoration survives.
|
|
37
|
+
// See the 'useReturnFocus - unmount while open' test in
|
|
38
|
+
// 'useReturnFocus.browser.test.tsx'.
|
|
33
39
|
useEffect(() => {
|
|
34
40
|
const anchor = ref.current.source
|
|
35
41
|
const { positioned } = ref.current
|
|
@@ -70,7 +76,10 @@ export function useReturnFocus(overlay: Overlay) {
|
|
|
70
76
|
}
|
|
71
77
|
}, [overlay.open])
|
|
72
78
|
|
|
73
|
-
//
|
|
79
|
+
// The focused element is tracked by the document-level 'focusin' listener
|
|
80
|
+
// above rather than by React state, so the latest value can only be read
|
|
81
|
+
// from the ref. Returning it during render is intentional: consumers use
|
|
82
|
+
// it to know where focus will return.
|
|
74
83
|
// eslint-disable-next-line react-hooks/refs
|
|
75
84
|
return ref.current.source
|
|
76
85
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { useRefObject, useUniqueId } from '#hook'
|
|
3
2
|
import {
|
|
4
3
|
cloneElement,
|
|
5
4
|
useCallback,
|
|
@@ -7,16 +6,17 @@ import {
|
|
|
7
6
|
useLayoutEffect,
|
|
8
7
|
useRef,
|
|
9
8
|
} from 'react'
|
|
9
|
+
import { useRefObject } from '../react/useRefObject'
|
|
10
|
+
import { useUniqueId } from '../react/useUniqueId'
|
|
11
|
+
import { useLightDismiss } from './useLightDismiss'
|
|
10
12
|
import {
|
|
11
|
-
useLightDismiss,
|
|
12
13
|
useOverlay,
|
|
13
|
-
usePositioning,
|
|
14
|
-
useReturnFocus,
|
|
15
14
|
type Overlay,
|
|
16
15
|
type OverlayAnchorProps,
|
|
17
|
-
type PositioningOptions,
|
|
18
16
|
type ToggleCallback,
|
|
19
|
-
} from '
|
|
17
|
+
} from './useOverlay'
|
|
18
|
+
import { usePositioning, type PositioningOptions } from './usePositioning'
|
|
19
|
+
import { useReturnFocus } from './useReturnFocus'
|
|
20
20
|
|
|
21
21
|
type TooltipTag = 'div'
|
|
22
22
|
|
|
@@ -48,7 +48,6 @@ export function useTooltip(options: TooltipOptions) {
|
|
|
48
48
|
|
|
49
49
|
let anchorProps: OverlayAnchorProps = { ...anchor?.props }
|
|
50
50
|
let positionedProps: React.JSX.IntrinsicElements[TooltipTag] = { ...props }
|
|
51
|
-
let arrowProps: React.ComponentProps<'div'>
|
|
52
51
|
|
|
53
52
|
const _id = useUniqueId('tooltip-')
|
|
54
53
|
positionedProps.id ||= _id
|
|
@@ -237,8 +236,7 @@ export function useTooltip(options: TooltipOptions) {
|
|
|
237
236
|
ref: positionedRef,
|
|
238
237
|
}
|
|
239
238
|
|
|
240
|
-
|
|
241
|
-
arrowProps = {
|
|
239
|
+
const arrowProps: React.ComponentProps<'div'> = {
|
|
242
240
|
style: {
|
|
243
241
|
...positioning.arrowStyle,
|
|
244
242
|
},
|
|
@@ -248,6 +246,9 @@ export function useTooltip(options: TooltipOptions) {
|
|
|
248
246
|
return {
|
|
249
247
|
overlay,
|
|
250
248
|
position: positioning.position,
|
|
249
|
+
// Passing the anchor ref through 'cloneElement' is the standard anchor
|
|
250
|
+
// injection pattern; the rule cannot prove the element is not a function
|
|
251
|
+
// component, so it conservatively flags the ref.
|
|
251
252
|
// eslint-disable-next-line react-hooks/refs
|
|
252
253
|
anchor: anchor == null ? null : cloneElement(anchor, anchorProps),
|
|
253
254
|
positioned: { props: positionedProps },
|
|
@@ -43,7 +43,10 @@ export function usePromise<T>(
|
|
|
43
43
|
return () => {
|
|
44
44
|
destroyed = true
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
// Depend on the signal instance, not its 'aborted' state, so the effect
|
|
47
|
+
// re-runs and the callbacks close over the latest signal when it is
|
|
48
|
+
// swapped between renders.
|
|
49
|
+
}, [promise, signal])
|
|
47
50
|
|
|
48
51
|
useEffect(() => {
|
|
49
52
|
if (error) {
|
|
@@ -21,12 +21,19 @@ export function useActivate(onActivate?: ActivateCallback) {
|
|
|
21
21
|
|
|
22
22
|
const ref = useRef({ isActivated, onActivate })
|
|
23
23
|
|
|
24
|
+
// Keep the ref in sync so 'activate' always invokes the latest
|
|
25
|
+
// 'onActivate', not the one captured when 'activate' was memoized.
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
ref.current.onActivate = onActivate
|
|
28
|
+
})
|
|
29
|
+
|
|
24
30
|
useLayoutEffect(() => {
|
|
25
31
|
const handleBlur = (ev: FocusEvent) => {
|
|
26
32
|
setIsActivated((ref.current.isActivated = false))
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
// The 'keyup'
|
|
35
|
+
// The 'keyup' may not fire on this element, so watch for it on the
|
|
36
|
+
// document.
|
|
30
37
|
const handleKeyUp = (ev: KeyboardEvent) => {
|
|
31
38
|
if (ref.current.isActivated && isSpaceKey(ev)) {
|
|
32
39
|
setIsActivated((ref.current.isActivated = false))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState } from 'react'
|
|
2
2
|
|
|
3
3
|
export function useConst<T>(initialize: () => T): T {
|
|
4
|
-
|
|
5
|
-
return
|
|
4
|
+
const [value] = useState(initialize)
|
|
5
|
+
return value
|
|
6
6
|
}
|
|
@@ -13,7 +13,9 @@ export function useRefCallback<T>(ref: Ref<T> | undefined) {
|
|
|
13
13
|
if (typeof ref === 'function') {
|
|
14
14
|
destroy = ref(current)
|
|
15
15
|
} else if (ref) {
|
|
16
|
-
//
|
|
16
|
+
// Writing to the forwarded 'ref' argument is the purpose of this
|
|
17
|
+
// hook; the rules conservatively forbid mutating hook arguments.
|
|
18
|
+
// eslint-disable-next-line react-hooks/immutability, react-compiler/react-compiler
|
|
17
19
|
ref.current = current
|
|
18
20
|
}
|
|
19
21
|
|