@refraktor/core 0.0.4 → 0.0.5
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/build/components/progress-circle/progress-circle.d.ts.map +1 -1
- package/build/components/progress-circle/progress-circle.js +6 -6
- package/build/components/progress-circle/progress-circle.styles.d.ts +2 -7
- package/build/components/progress-circle/progress-circle.styles.d.ts.map +1 -1
- package/build/components/progress-circle/progress-circle.styles.js +2 -23
- package/build/components/progress-circle/progress-circle.types.d.ts +4 -3
- package/build/components/progress-circle/progress-circle.types.d.ts.map +1 -1
- package/build/components/slider/slider.d.ts.map +1 -1
- package/build/components/slider/slider.js +69 -20
- package/build/components/tooltip/tooltip.js +1 -1
- package/build/style.css +2 -2
- package/package.json +30 -3
- package/.turbo/turbo-build.log +0 -4
- package/refraktor-core-0.0.1-alpha.0.tgz +0 -0
- package/src/components/accordion/accordion-control/accordion-control.tsx +0 -156
- package/src/components/accordion/accordion-control/index.ts +0 -1
- package/src/components/accordion/accordion-item/accordion-item.tsx +0 -40
- package/src/components/accordion/accordion-item/index.ts +0 -1
- package/src/components/accordion/accordion-panel/accordion-panel.tsx +0 -58
- package/src/components/accordion/accordion-panel/index.ts +0 -1
- package/src/components/accordion/accordion.context.ts +0 -93
- package/src/components/accordion/accordion.styles.ts +0 -60
- package/src/components/accordion/accordion.test.tsx +0 -174
- package/src/components/accordion/accordion.tsx +0 -203
- package/src/components/accordion/accordion.types.ts +0 -126
- package/src/components/accordion/index.ts +0 -17
- package/src/components/avatar/avatar-group/avatar-group.tsx +0 -73
- package/src/components/avatar/avatar-group/index.ts +0 -1
- package/src/components/avatar/avatar.styles.ts +0 -11
- package/src/components/avatar/avatar.tsx +0 -142
- package/src/components/avatar/avatar.types.ts +0 -86
- package/src/components/avatar/index.ts +0 -8
- package/src/components/badge/badge.styles.ts +0 -21
- package/src/components/badge/badge.tsx +0 -62
- package/src/components/badge/badge.types.ts +0 -40
- package/src/components/badge/index.ts +0 -2
- package/src/components/breadcrumbs/breadcrumbs.styles.ts +0 -55
- package/src/components/breadcrumbs/breadcrumbs.test.tsx +0 -136
- package/src/components/breadcrumbs/breadcrumbs.tsx +0 -199
- package/src/components/breadcrumbs/breadcrumbs.types.ts +0 -78
- package/src/components/breadcrumbs/breadcrumbs.utils.ts +0 -70
- package/src/components/breadcrumbs/index.ts +0 -6
- package/src/components/button/button.styles.ts +0 -28
- package/src/components/button/button.test.tsx +0 -57
- package/src/components/button/button.tsx +0 -110
- package/src/components/button/button.types.ts +0 -69
- package/src/components/button/index.ts +0 -2
- package/src/components/checkbox/checkbox-group/checkbox-group.tsx +0 -93
- package/src/components/checkbox/checkbox-group/index.ts +0 -1
- package/src/components/checkbox/checkbox.context.ts +0 -14
- package/src/components/checkbox/checkbox.styles.ts +0 -49
- package/src/components/checkbox/checkbox.test.tsx +0 -80
- package/src/components/checkbox/checkbox.tsx +0 -192
- package/src/components/checkbox/checkbox.types.ts +0 -125
- package/src/components/checkbox/index.ts +0 -10
- package/src/components/chip/chip-group/chip-group.tsx +0 -107
- package/src/components/chip/chip-group/index.ts +0 -1
- package/src/components/chip/chip.context.ts +0 -15
- package/src/components/chip/chip.styles.ts +0 -36
- package/src/components/chip/chip.test.tsx +0 -197
- package/src/components/chip/chip.tsx +0 -208
- package/src/components/chip/chip.types.ts +0 -134
- package/src/components/chip/index.ts +0 -10
- package/src/components/color-swatch/color-swatch.styles.ts +0 -11
- package/src/components/color-swatch/color-swatch.test.tsx +0 -80
- package/src/components/color-swatch/color-swatch.tsx +0 -84
- package/src/components/color-swatch/color-swatch.types.ts +0 -46
- package/src/components/color-swatch/index.ts +0 -2
- package/src/components/drawer/drawer-body/drawer-body.tsx +0 -29
- package/src/components/drawer/drawer-body/index.ts +0 -1
- package/src/components/drawer/drawer-close/drawer-close.tsx +0 -43
- package/src/components/drawer/drawer-close/index.ts +0 -1
- package/src/components/drawer/drawer-content/drawer-content.tsx +0 -135
- package/src/components/drawer/drawer-content/index.ts +0 -1
- package/src/components/drawer/drawer-header/drawer-header.tsx +0 -40
- package/src/components/drawer/drawer-header/index.ts +0 -1
- package/src/components/drawer/drawer-overlay/drawer-overlay.tsx +0 -87
- package/src/components/drawer/drawer-overlay/index.ts +0 -1
- package/src/components/drawer/drawer-root/drawer-root.tsx +0 -93
- package/src/components/drawer/drawer-root/index.ts +0 -1
- package/src/components/drawer/drawer.context.ts +0 -26
- package/src/components/drawer/drawer.styles.ts +0 -32
- package/src/components/drawer/drawer.test.tsx +0 -274
- package/src/components/drawer/drawer.tsx +0 -58
- package/src/components/drawer/drawer.types.ts +0 -192
- package/src/components/drawer/index.ts +0 -18
- package/src/components/drawer/use-drawer.ts +0 -94
- package/src/components/file-input/file-input.test.tsx +0 -134
- package/src/components/file-input/file-input.tsx +0 -224
- package/src/components/file-input/file-input.types.ts +0 -78
- package/src/components/file-input/file-input.utils.test.ts +0 -36
- package/src/components/file-input/file-input.utils.ts +0 -130
- package/src/components/file-input/index.ts +0 -2
- package/src/components/for/for.test.tsx +0 -66
- package/src/components/for/for.tsx +0 -53
- package/src/components/for/for.types.ts +0 -40
- package/src/components/for/index.ts +0 -2
- package/src/components/index.ts +0 -35
- package/src/components/input/index.ts +0 -2
- package/src/components/input/input-description/index.ts +0 -2
- package/src/components/input/input-description/input-description.tsx +0 -36
- package/src/components/input/input-error/index.ts +0 -2
- package/src/components/input/input-error/input-error.tsx +0 -36
- package/src/components/input/input-field/index.ts +0 -1
- package/src/components/input/input-field/input-field.styles.ts +0 -23
- package/src/components/input/input-field/input-field.tsx +0 -94
- package/src/components/input/input-label/index.ts +0 -2
- package/src/components/input/input-label/input-label.tsx +0 -47
- package/src/components/input/input-wrapper/index.ts +0 -2
- package/src/components/input/input-wrapper/input-wrapper.tsx +0 -43
- package/src/components/input/input.tsx +0 -71
- package/src/components/input/input.types.ts +0 -111
- package/src/components/loader/index.ts +0 -2
- package/src/components/loader/loader.tsx +0 -89
- package/src/components/loader/loader.types.ts +0 -33
- package/src/components/menu/index.ts +0 -24
- package/src/components/menu/menu-dropdown/index.ts +0 -1
- package/src/components/menu/menu-dropdown/menu-dropdown.tsx +0 -220
- package/src/components/menu/menu-item/index.ts +0 -1
- package/src/components/menu/menu-item/menu-item.tsx +0 -126
- package/src/components/menu/menu-label/index.ts +0 -1
- package/src/components/menu/menu-label/menu-label.tsx +0 -30
- package/src/components/menu/menu-separator/index.ts +0 -1
- package/src/components/menu/menu-separator/menu-separator.tsx +0 -28
- package/src/components/menu/menu-sub/index.ts +0 -1
- package/src/components/menu/menu-sub/menu-sub.tsx +0 -117
- package/src/components/menu/menu-sub-dropdown/index.ts +0 -1
- package/src/components/menu/menu-sub-dropdown/menu-sub-dropdown.tsx +0 -221
- package/src/components/menu/menu-sub-trigger/index.ts +0 -1
- package/src/components/menu/menu-sub-trigger/menu-sub-trigger.tsx +0 -164
- package/src/components/menu/menu-trigger/index.ts +0 -1
- package/src/components/menu/menu-trigger/menu-trigger.tsx +0 -98
- package/src/components/menu/menu.context.ts +0 -162
- package/src/components/menu/menu.test.tsx +0 -136
- package/src/components/menu/menu.tsx +0 -133
- package/src/components/menu/menu.types.ts +0 -291
- package/src/components/menu/use-menu.ts +0 -204
- package/src/components/modal/index.ts +0 -18
- package/src/components/modal/modal-body/index.ts +0 -1
- package/src/components/modal/modal-body/modal-body.tsx +0 -29
- package/src/components/modal/modal-close/index.ts +0 -1
- package/src/components/modal/modal-close/modal-close.tsx +0 -43
- package/src/components/modal/modal-content/index.ts +0 -1
- package/src/components/modal/modal-content/modal-content.tsx +0 -119
- package/src/components/modal/modal-header/index.ts +0 -1
- package/src/components/modal/modal-header/modal-header.tsx +0 -40
- package/src/components/modal/modal-overlay/index.ts +0 -1
- package/src/components/modal/modal-overlay/modal-overlay.tsx +0 -87
- package/src/components/modal/modal-root/index.ts +0 -1
- package/src/components/modal/modal-root/modal-root.tsx +0 -93
- package/src/components/modal/modal.context.ts +0 -26
- package/src/components/modal/modal.test.tsx +0 -316
- package/src/components/modal/modal.tsx +0 -58
- package/src/components/modal/modal.types.ts +0 -189
- package/src/components/modal/use-modal.ts +0 -94
- package/src/components/number-input/index.ts +0 -2
- package/src/components/number-input/number-input.styles.ts +0 -37
- package/src/components/number-input/number-input.test.tsx +0 -22
- package/src/components/number-input/number-input.tsx +0 -381
- package/src/components/number-input/number-input.types.ts +0 -58
- package/src/components/pagination/index.ts +0 -7
- package/src/components/pagination/pagination.styles.ts +0 -84
- package/src/components/pagination/pagination.test.tsx +0 -117
- package/src/components/pagination/pagination.tsx +0 -371
- package/src/components/pagination/pagination.types.ts +0 -95
- package/src/components/pagination/pagination.utils.ts +0 -88
- package/src/components/password-input/index.ts +0 -2
- package/src/components/password-input/password-input.test.tsx +0 -72
- package/src/components/password-input/password-input.tsx +0 -85
- package/src/components/password-input/password-input.types.ts +0 -30
- package/src/components/pin-input/index.ts +0 -2
- package/src/components/pin-input/pin-input.test.tsx +0 -149
- package/src/components/pin-input/pin-input.tsx +0 -473
- package/src/components/pin-input/pin-input.types.ts +0 -78
- package/src/components/popover/index.ts +0 -12
- package/src/components/popover/popover-dropdown/index.ts +0 -1
- package/src/components/popover/popover-dropdown/popover-dropdown.tsx +0 -94
- package/src/components/popover/popover-trigger/index.ts +0 -1
- package/src/components/popover/popover-trigger/popover-trigger.tsx +0 -49
- package/src/components/popover/popover.context.ts +0 -20
- package/src/components/popover/popover.tsx +0 -113
- package/src/components/popover/popover.types.ts +0 -137
- package/src/components/popover/use-popover.ts +0 -219
- package/src/components/portal/index.ts +0 -2
- package/src/components/portal/portal.test.tsx +0 -39
- package/src/components/portal/portal.tsx +0 -104
- package/src/components/portal/portal.types.ts +0 -31
- package/src/components/progress/index.ts +0 -2
- package/src/components/progress/progress.styles.ts +0 -25
- package/src/components/progress/progress.test.tsx +0 -107
- package/src/components/progress/progress.tsx +0 -93
- package/src/components/progress/progress.types.ts +0 -52
- package/src/components/progress-circle/index.ts +0 -5
- package/src/components/progress-circle/progress-circle.styles.ts +0 -31
- package/src/components/progress-circle/progress-circle.test.tsx +0 -140
- package/src/components/progress-circle/progress-circle.tsx +0 -124
- package/src/components/progress-circle/progress-circle.types.ts +0 -52
- package/src/components/radio/index.ts +0 -10
- package/src/components/radio/radio-group/index.ts +0 -1
- package/src/components/radio/radio-group/radio-group.tsx +0 -89
- package/src/components/radio/radio.context.ts +0 -14
- package/src/components/radio/radio.styles.ts +0 -49
- package/src/components/radio/radio.test.tsx +0 -75
- package/src/components/radio/radio.tsx +0 -173
- package/src/components/radio/radio.types.ts +0 -126
- package/src/components/scroll-area/index.ts +0 -6
- package/src/components/scroll-area/scroll-area.test.tsx +0 -72
- package/src/components/scroll-area/scroll-area.tsx +0 -70
- package/src/components/scroll-area/scroll-area.types.ts +0 -37
- package/src/components/segmented-control/index.ts +0 -6
- package/src/components/segmented-control/segmented-control.styles.ts +0 -37
- package/src/components/segmented-control/segmented-control.test.tsx +0 -170
- package/src/components/segmented-control/segmented-control.tsx +0 -255
- package/src/components/segmented-control/segmented-control.types.ts +0 -78
- package/src/components/select/index.ts +0 -20
- package/src/components/select/select-dropdown/index.ts +0 -1
- package/src/components/select/select-dropdown/select-dropdown.tsx +0 -299
- package/src/components/select/select-group/index.ts +0 -1
- package/src/components/select/select-group/select-group.tsx +0 -47
- package/src/components/select/select-item/index.ts +0 -1
- package/src/components/select/select-item/select-item.tsx +0 -157
- package/src/components/select/select-root/index.ts +0 -1
- package/src/components/select/select-root/select-root.tsx +0 -333
- package/src/components/select/select-trigger/index.ts +0 -1
- package/src/components/select/select-trigger/select-trigger.tsx +0 -123
- package/src/components/select/select.context.ts +0 -140
- package/src/components/select/select.test.tsx +0 -190
- package/src/components/select/select.tsx +0 -82
- package/src/components/select/select.types.ts +0 -272
- package/src/components/select/use-select.ts +0 -170
- package/src/components/slider/index.ts +0 -7
- package/src/components/slider/slider.styles.ts +0 -37
- package/src/components/slider/slider.tsx +0 -275
- package/src/components/slider/slider.types.ts +0 -82
- package/src/components/switch/index.ts +0 -2
- package/src/components/switch/switch.styles.ts +0 -31
- package/src/components/switch/switch.tsx +0 -132
- package/src/components/switch/switch.types.ts +0 -62
- package/src/components/table/index.ts +0 -24
- package/src/components/table/table-body/index.ts +0 -1
- package/src/components/table/table-body/table-body.tsx +0 -37
- package/src/components/table/table-caption/index.ts +0 -1
- package/src/components/table/table-caption/table-caption.tsx +0 -32
- package/src/components/table/table-cell/index.ts +0 -1
- package/src/components/table/table-cell/table-cell.tsx +0 -33
- package/src/components/table/table-head/index.ts +0 -1
- package/src/components/table/table-head/table-head.tsx +0 -29
- package/src/components/table/table-header-cell/index.ts +0 -1
- package/src/components/table/table-header-cell/table-header-cell.tsx +0 -33
- package/src/components/table/table-row/index.ts +0 -1
- package/src/components/table/table-row/table-row.tsx +0 -30
- package/src/components/table/table.context.ts +0 -18
- package/src/components/table/table.styles.ts +0 -62
- package/src/components/table/table.test.tsx +0 -145
- package/src/components/table/table.tsx +0 -91
- package/src/components/table/table.types.ts +0 -145
- package/src/components/tabs/index.ts +0 -18
- package/src/components/tabs/tabs-list/index.ts +0 -1
- package/src/components/tabs/tabs-list/tabs-list.tsx +0 -42
- package/src/components/tabs/tabs-panel/index.ts +0 -1
- package/src/components/tabs/tabs-panel/tabs-panel.tsx +0 -58
- package/src/components/tabs/tabs-tab/index.ts +0 -1
- package/src/components/tabs/tabs-tab/tabs-tab.tsx +0 -210
- package/src/components/tabs/tabs.context.ts +0 -88
- package/src/components/tabs/tabs.styles.ts +0 -92
- package/src/components/tabs/tabs.test.tsx +0 -167
- package/src/components/tabs/tabs.tsx +0 -137
- package/src/components/tabs/tabs.types.ts +0 -128
- package/src/components/textarea/index.ts +0 -2
- package/src/components/textarea/textarea-field/index.ts +0 -1
- package/src/components/textarea/textarea-field/textarea-field.styles.ts +0 -34
- package/src/components/textarea/textarea-field/textarea-field.tsx +0 -96
- package/src/components/textarea/textarea.tsx +0 -64
- package/src/components/textarea/textarea.types.ts +0 -80
- package/src/components/timeline/index.ts +0 -11
- package/src/components/timeline/timeline-item/index.ts +0 -1
- package/src/components/timeline/timeline-item/timeline-item.tsx +0 -158
- package/src/components/timeline/timeline.context.ts +0 -21
- package/src/components/timeline/timeline.styles.ts +0 -135
- package/src/components/timeline/timeline.test.tsx +0 -150
- package/src/components/timeline/timeline.tsx +0 -124
- package/src/components/timeline/timeline.types.ts +0 -91
- package/src/components/tooltip/index.ts +0 -8
- package/src/components/tooltip/tooltip.tsx +0 -164
- package/src/components/tooltip/tooltip.types.ts +0 -104
- package/src/components/tooltip/use-tooltip.ts +0 -200
- package/src/components/transition/index.ts +0 -11
- package/src/components/transition/transition.test.tsx +0 -126
- package/src/components/transition/transition.tsx +0 -441
- package/src/components/transition/transition.types.ts +0 -97
- package/src/components/transition/transitions.ts +0 -140
- package/src/icons/check.tsx +0 -25
- package/src/icons/chevron.tsx +0 -46
- package/src/icons/eye-off.tsx +0 -30
- package/src/icons/eye.tsx +0 -24
- package/src/icons/index.ts +0 -7
- package/src/icons/minus.tsx +0 -24
- package/src/icons/types.ts +0 -9
- package/src/icons/user.tsx +0 -18
- package/src/icons/x.tsx +0 -35
- package/src/index.ts +0 -5
- package/src/style.css +0 -334
- package/src/theme/ThemeProvider/ThemeProvider.tsx +0 -111
- package/src/theme/ThemeProvider/context.ts +0 -7
- package/src/theme/ThemeProvider/generateVariables.test.ts +0 -49
- package/src/theme/ThemeProvider/generateVariables.ts +0 -124
- package/src/theme/ThemeProvider/index.ts +0 -3
- package/src/theme/ThemeProvider/types.ts +0 -37
- package/src/theme/createTheme/createTheme.ts +0 -41
- package/src/theme/createTheme/index.ts +0 -7
- package/src/theme/createTheme/types.ts +0 -62
- package/src/theme/defaults/colors.ts +0 -203
- package/src/theme/defaults/settings.ts +0 -8
- package/src/theme/index.ts +0 -4
- package/src/theme/types.ts +0 -31
- package/src/theme/utils/get-radius.ts +0 -23
- package/src/theme/utils/get-shade.ts +0 -16
- package/src/theme/utils/index.ts +0 -3
- package/src/theme/utils/use-theme.ts +0 -27
- package/src/utils/configs/create-config.ts +0 -15
- package/src/utils/configs/index.ts +0 -3
- package/src/utils/configs/use-class-names.ts +0 -41
- package/src/utils/configs/use-props.ts +0 -55
- package/src/utils/cx/index.ts +0 -6
- package/src/utils/factory/factory.ts +0 -23
- package/src/utils/factory/index.ts +0 -14
- package/src/utils/factory/types.ts +0 -92
- package/src/utils/index.ts +0 -3
- package/src/vitest/index.ts +0 -1
- package/src/vitest/setup.tsx +0 -20
- package/src/vitest/utils.tsx +0 -59
- package/tsconfig.json +0 -13
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.js +0 -19
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { render, screen, userEvent, waitFor } from "../../vitest";
|
|
3
|
-
import Drawer from "./drawer";
|
|
4
|
-
import { DrawerBody } from "./drawer-body";
|
|
5
|
-
import { DrawerContent } from "./drawer-content";
|
|
6
|
-
import { DrawerOverlay } from "./drawer-overlay";
|
|
7
|
-
import { DrawerRoot } from "./drawer-root";
|
|
8
|
-
|
|
9
|
-
describe("@refraktor/core/Drawer", () => {
|
|
10
|
-
const transitionProps = {
|
|
11
|
-
duration: 0,
|
|
12
|
-
immediate: true
|
|
13
|
-
} as const;
|
|
14
|
-
|
|
15
|
-
it("renders with compound subcomponents and closes with header close button", async () => {
|
|
16
|
-
const user = userEvent.setup();
|
|
17
|
-
|
|
18
|
-
await render(
|
|
19
|
-
<Drawer.Root defaultOpened transitionProps={transitionProps}>
|
|
20
|
-
<Drawer.Overlay />
|
|
21
|
-
|
|
22
|
-
<Drawer.Content>
|
|
23
|
-
<Drawer.Header text="Edit profile" />
|
|
24
|
-
<Drawer.Body>
|
|
25
|
-
<p>Drawer body</p>
|
|
26
|
-
</Drawer.Body>
|
|
27
|
-
</Drawer.Content>
|
|
28
|
-
</Drawer.Root>
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
expect(
|
|
32
|
-
await screen.findByRole("dialog", { name: "Edit profile" })
|
|
33
|
-
).toBeInTheDocument();
|
|
34
|
-
|
|
35
|
-
await user.click(screen.getByRole("button", { name: "Close" }));
|
|
36
|
-
|
|
37
|
-
await waitFor(() => {
|
|
38
|
-
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("calls onOpenedChange when clicking overlay in controlled mode", async () => {
|
|
43
|
-
const user = userEvent.setup();
|
|
44
|
-
const onOpenedChange = vi.fn();
|
|
45
|
-
|
|
46
|
-
await render(
|
|
47
|
-
<Drawer.Root
|
|
48
|
-
opened
|
|
49
|
-
onOpenedChange={onOpenedChange}
|
|
50
|
-
transitionProps={transitionProps}
|
|
51
|
-
>
|
|
52
|
-
<Drawer.Overlay data-testid="overlay" />
|
|
53
|
-
<Drawer.Content>Controlled drawer</Drawer.Content>
|
|
54
|
-
</Drawer.Root>
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
await user.click(await screen.findByTestId("overlay"));
|
|
58
|
-
|
|
59
|
-
expect(onOpenedChange).toHaveBeenCalledWith(false);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("closes on Escape key", async () => {
|
|
63
|
-
const user = userEvent.setup();
|
|
64
|
-
|
|
65
|
-
await render(
|
|
66
|
-
<Drawer.Root defaultOpened transitionProps={transitionProps}>
|
|
67
|
-
<Drawer.Content>Keyboard close</Drawer.Content>
|
|
68
|
-
</Drawer.Root>
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
await screen.findByRole("dialog");
|
|
72
|
-
|
|
73
|
-
await user.keyboard("{Escape}");
|
|
74
|
-
|
|
75
|
-
await waitFor(() => {
|
|
76
|
-
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("supports standalone subcomponents with DrawerRoot", async () => {
|
|
81
|
-
await render(
|
|
82
|
-
<DrawerRoot defaultOpened transitionProps={transitionProps}>
|
|
83
|
-
<DrawerOverlay />
|
|
84
|
-
<DrawerContent>Standalone composition</DrawerContent>
|
|
85
|
-
</DrawerRoot>
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
expect(await screen.findByRole("dialog")).toBeInTheDocument();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("applies custom overlay background opacity and blur", async () => {
|
|
92
|
-
await render(
|
|
93
|
-
<Drawer.Root defaultOpened transitionProps={transitionProps}>
|
|
94
|
-
<Drawer.Overlay
|
|
95
|
-
data-testid="overlay"
|
|
96
|
-
backgroundOpacity={0.4}
|
|
97
|
-
blur={6}
|
|
98
|
-
/>
|
|
99
|
-
<Drawer.Content>Styled overlay</Drawer.Content>
|
|
100
|
-
</Drawer.Root>
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
const overlay = await screen.findByTestId("overlay");
|
|
104
|
-
|
|
105
|
-
expect(overlay).toHaveStyle({
|
|
106
|
-
backgroundColor: "rgba(0, 0, 0, 0.4)",
|
|
107
|
-
backdropFilter: "blur(6px)"
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("supports different positions and predefined sizes", async () => {
|
|
112
|
-
await render(
|
|
113
|
-
<>
|
|
114
|
-
<Drawer.Root
|
|
115
|
-
defaultOpened
|
|
116
|
-
position="left"
|
|
117
|
-
size="sm"
|
|
118
|
-
transitionProps={transitionProps}
|
|
119
|
-
>
|
|
120
|
-
<Drawer.Content data-testid="left-content">
|
|
121
|
-
Left
|
|
122
|
-
</Drawer.Content>
|
|
123
|
-
</Drawer.Root>
|
|
124
|
-
|
|
125
|
-
<Drawer.Root
|
|
126
|
-
defaultOpened
|
|
127
|
-
position="bottom"
|
|
128
|
-
size="xl"
|
|
129
|
-
transitionProps={transitionProps}
|
|
130
|
-
>
|
|
131
|
-
<Drawer.Content data-testid="bottom-content">
|
|
132
|
-
Bottom
|
|
133
|
-
</Drawer.Content>
|
|
134
|
-
</Drawer.Root>
|
|
135
|
-
</>
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const leftContent = await screen.findByTestId("left-content");
|
|
139
|
-
const bottomContent = await screen.findByTestId("bottom-content");
|
|
140
|
-
|
|
141
|
-
expect(leftContent).toHaveAttribute("data-position", "left");
|
|
142
|
-
expect(leftContent).toHaveStyle({ width: "20rem" });
|
|
143
|
-
expect(bottomContent).toHaveAttribute("data-position", "bottom");
|
|
144
|
-
expect(bottomContent).toHaveStyle({ height: "36rem" });
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("renders Drawer.Body subcomponent", async () => {
|
|
148
|
-
await render(
|
|
149
|
-
<Drawer.Root defaultOpened transitionProps={transitionProps}>
|
|
150
|
-
<Drawer.Content>
|
|
151
|
-
<Drawer.Body data-testid="body">Body content</Drawer.Body>
|
|
152
|
-
</Drawer.Content>
|
|
153
|
-
</Drawer.Root>
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
const body = await screen.findByTestId("body");
|
|
157
|
-
expect(body).toBeInTheDocument();
|
|
158
|
-
expect(body).toHaveTextContent("Body content");
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("renders standalone DrawerBody component", async () => {
|
|
162
|
-
await render(
|
|
163
|
-
<DrawerRoot defaultOpened transitionProps={transitionProps}>
|
|
164
|
-
<DrawerContent>
|
|
165
|
-
<DrawerBody data-testid="body">Standalone body</DrawerBody>
|
|
166
|
-
</DrawerContent>
|
|
167
|
-
</DrawerRoot>
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
expect(await screen.findByTestId("body")).toHaveTextContent(
|
|
171
|
-
"Standalone body"
|
|
172
|
-
);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe("single-component shorthand API", () => {
|
|
176
|
-
it("renders with title, overlay, close button, and body", async () => {
|
|
177
|
-
await render(
|
|
178
|
-
<Drawer
|
|
179
|
-
defaultOpened
|
|
180
|
-
title="Edit profile"
|
|
181
|
-
transitionProps={transitionProps}
|
|
182
|
-
>
|
|
183
|
-
<p>Profile form</p>
|
|
184
|
-
</Drawer>
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
expect(
|
|
188
|
-
await screen.findByRole("dialog", { name: "Edit profile" })
|
|
189
|
-
).toBeInTheDocument();
|
|
190
|
-
expect(screen.getByText("Profile form")).toBeInTheDocument();
|
|
191
|
-
expect(
|
|
192
|
-
screen.getByRole("button", { name: "Close" })
|
|
193
|
-
).toBeInTheDocument();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("hides overlay when withOverlay is false", async () => {
|
|
197
|
-
const { container } = await render(
|
|
198
|
-
<Drawer
|
|
199
|
-
defaultOpened
|
|
200
|
-
title="No overlay"
|
|
201
|
-
withOverlay={false}
|
|
202
|
-
transitionProps={transitionProps}
|
|
203
|
-
/>
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
expect(await screen.findByRole("dialog")).toBeInTheDocument();
|
|
207
|
-
expect(
|
|
208
|
-
container.ownerDocument.querySelector("[aria-hidden='true']")
|
|
209
|
-
).toBeNull();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("hides close button when withCloseButton is false", async () => {
|
|
213
|
-
await render(
|
|
214
|
-
<Drawer
|
|
215
|
-
defaultOpened
|
|
216
|
-
title="No close"
|
|
217
|
-
withCloseButton={false}
|
|
218
|
-
transitionProps={transitionProps}
|
|
219
|
-
/>
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
await screen.findByRole("dialog");
|
|
223
|
-
expect(
|
|
224
|
-
screen.queryByRole("button", { name: "Close" })
|
|
225
|
-
).not.toBeInTheDocument();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("closes via shorthand close button", async () => {
|
|
229
|
-
const user = userEvent.setup();
|
|
230
|
-
|
|
231
|
-
await render(
|
|
232
|
-
<Drawer
|
|
233
|
-
defaultOpened
|
|
234
|
-
title="Closeable"
|
|
235
|
-
transitionProps={transitionProps}
|
|
236
|
-
>
|
|
237
|
-
Content
|
|
238
|
-
</Drawer>
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
await screen.findByRole("dialog");
|
|
242
|
-
|
|
243
|
-
await user.click(screen.getByRole("button", { name: "Close" }));
|
|
244
|
-
|
|
245
|
-
await waitFor(() => {
|
|
246
|
-
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it("passes overlayProps to the overlay", async () => {
|
|
251
|
-
await render(
|
|
252
|
-
<Drawer
|
|
253
|
-
defaultOpened
|
|
254
|
-
title="Custom overlay"
|
|
255
|
-
overlayProps={{
|
|
256
|
-
backgroundOpacity: 0.8,
|
|
257
|
-
blur: 10,
|
|
258
|
-
"data-testid": "shorthand-overlay"
|
|
259
|
-
} as any}
|
|
260
|
-
transitionProps={transitionProps}
|
|
261
|
-
>
|
|
262
|
-
Content
|
|
263
|
-
</Drawer>
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
const overlay = await screen.findByTestId("shorthand-overlay");
|
|
267
|
-
|
|
268
|
-
expect(overlay).toHaveStyle({
|
|
269
|
-
backgroundColor: "rgba(0, 0, 0, 0.8)",
|
|
270
|
-
backdropFilter: "blur(10px)"
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createClassNamesConfig,
|
|
3
|
-
createComponentConfig,
|
|
4
|
-
factory
|
|
5
|
-
} from "../../utils";
|
|
6
|
-
import { DrawerBody } from "./drawer-body";
|
|
7
|
-
import { DrawerClose } from "./drawer-close";
|
|
8
|
-
import { DrawerContent } from "./drawer-content";
|
|
9
|
-
import { DrawerHeader } from "./drawer-header";
|
|
10
|
-
import { DrawerOverlay } from "./drawer-overlay";
|
|
11
|
-
import { DrawerRoot } from "./drawer-root";
|
|
12
|
-
import {
|
|
13
|
-
DrawerClassNames,
|
|
14
|
-
DrawerFactoryPayload,
|
|
15
|
-
DrawerProps
|
|
16
|
-
} from "./drawer.types";
|
|
17
|
-
|
|
18
|
-
const Drawer = factory<DrawerFactoryPayload>(
|
|
19
|
-
(
|
|
20
|
-
{
|
|
21
|
-
title,
|
|
22
|
-
withOverlay = true,
|
|
23
|
-
withCloseButton = true,
|
|
24
|
-
overlayProps,
|
|
25
|
-
children,
|
|
26
|
-
...rootProps
|
|
27
|
-
},
|
|
28
|
-
ref
|
|
29
|
-
) => {
|
|
30
|
-
return (
|
|
31
|
-
<DrawerRoot {...rootProps} ref={ref}>
|
|
32
|
-
{withOverlay && <DrawerOverlay {...overlayProps} />}
|
|
33
|
-
|
|
34
|
-
<DrawerContent>
|
|
35
|
-
{(title || withCloseButton) && (
|
|
36
|
-
<DrawerHeader withClose={withCloseButton}>
|
|
37
|
-
{title}
|
|
38
|
-
</DrawerHeader>
|
|
39
|
-
)}
|
|
40
|
-
|
|
41
|
-
<DrawerBody>{children}</DrawerBody>
|
|
42
|
-
</DrawerContent>
|
|
43
|
-
</DrawerRoot>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
Drawer.displayName = "@refraktor/core/Drawer";
|
|
49
|
-
Drawer.configure = createComponentConfig<DrawerProps>();
|
|
50
|
-
Drawer.classNames = createClassNamesConfig<DrawerClassNames>();
|
|
51
|
-
Drawer.Root = DrawerRoot;
|
|
52
|
-
Drawer.Overlay = DrawerOverlay;
|
|
53
|
-
Drawer.Content = DrawerContent;
|
|
54
|
-
Drawer.Header = DrawerHeader;
|
|
55
|
-
Drawer.Body = DrawerBody;
|
|
56
|
-
Drawer.Close = DrawerClose;
|
|
57
|
-
|
|
58
|
-
export default Drawer;
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { ComponentPropsWithoutRef, MouseEvent, ReactNode } from "react";
|
|
2
|
-
import {
|
|
3
|
-
createClassNamesConfig,
|
|
4
|
-
createComponentConfig,
|
|
5
|
-
FactoryPayload
|
|
6
|
-
} from "../../utils";
|
|
7
|
-
import { RefraktorRadius, RefraktorSize } from "../../theme";
|
|
8
|
-
import { TransitionProps } from "../transition";
|
|
9
|
-
import { DrawerRoot } from "./drawer-root";
|
|
10
|
-
import { DrawerOverlay } from "./drawer-overlay";
|
|
11
|
-
import { DrawerContent } from "./drawer-content";
|
|
12
|
-
import { DrawerHeader } from "./drawer-header";
|
|
13
|
-
import { DrawerBody } from "./drawer-body";
|
|
14
|
-
import { DrawerClose } from "./drawer-close";
|
|
15
|
-
|
|
16
|
-
export type DrawerPosition = "left" | "right" | "top" | "bottom";
|
|
17
|
-
|
|
18
|
-
export type DrawerClassNames = {
|
|
19
|
-
root?: string;
|
|
20
|
-
overlay?: string;
|
|
21
|
-
content?: string;
|
|
22
|
-
header?: string;
|
|
23
|
-
body?: string;
|
|
24
|
-
close?: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export interface DrawerRootProps extends ComponentPropsWithoutRef<"div"> {
|
|
28
|
-
/** Children containing drawer subcomponents */
|
|
29
|
-
children?: ReactNode;
|
|
30
|
-
|
|
31
|
-
/** State of the drawer (controlled) */
|
|
32
|
-
opened?: boolean;
|
|
33
|
-
|
|
34
|
-
/** Initial state of the drawer (uncontrolled) */
|
|
35
|
-
defaultOpened?: boolean;
|
|
36
|
-
|
|
37
|
-
/** Callback called when drawer state changes */
|
|
38
|
-
onOpenedChange?: (opened: boolean) => void;
|
|
39
|
-
|
|
40
|
-
/** Whether to close drawer on overlay/outside click @default `true` */
|
|
41
|
-
closeOnClickOutside?: boolean;
|
|
42
|
-
|
|
43
|
-
/** Whether to close drawer on Escape key @default `true` */
|
|
44
|
-
closeOnEscape?: boolean;
|
|
45
|
-
|
|
46
|
-
/** Whether to lock body scroll while opened @default `true` */
|
|
47
|
-
lockScroll?: boolean;
|
|
48
|
-
|
|
49
|
-
/** Whether to render overlay/content inside portal @default `true` */
|
|
50
|
-
withinPortal?: boolean;
|
|
51
|
-
|
|
52
|
-
/** Radius for drawer content @default `none` */
|
|
53
|
-
radius?: RefraktorRadius;
|
|
54
|
-
|
|
55
|
-
/** Side where drawer appears @default `right` */
|
|
56
|
-
position?: DrawerPosition;
|
|
57
|
-
|
|
58
|
-
/** Drawer size scale (width for left/right, height for top/bottom) @default `md` */
|
|
59
|
-
size?: RefraktorSize;
|
|
60
|
-
|
|
61
|
-
/** Whether to trap focus within the drawer @default `true` */
|
|
62
|
-
trapFocus?: boolean;
|
|
63
|
-
|
|
64
|
-
/** Whether to return focus to trigger after close @default `true` */
|
|
65
|
-
returnFocus?: boolean;
|
|
66
|
-
|
|
67
|
-
/** Transition props for overlay/content, uses Transition internally */
|
|
68
|
-
transitionProps?: Omit<TransitionProps, "children" | "mounted">;
|
|
69
|
-
|
|
70
|
-
/** Used for editing root class name */
|
|
71
|
-
className?: string;
|
|
72
|
-
|
|
73
|
-
/** Used for styling different parts of the component */
|
|
74
|
-
classNames?: DrawerClassNames;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface DrawerProps extends Omit<DrawerRootProps, "title"> {
|
|
78
|
-
/** Title text rendered in the header */
|
|
79
|
-
title?: ReactNode;
|
|
80
|
-
|
|
81
|
-
/** Whether to render the overlay @default `true` */
|
|
82
|
-
withOverlay?: boolean;
|
|
83
|
-
|
|
84
|
-
/** Whether to show the close button in the header @default `true` */
|
|
85
|
-
withCloseButton?: boolean;
|
|
86
|
-
|
|
87
|
-
/** Props passed to the Overlay subcomponent */
|
|
88
|
-
overlayProps?: DrawerOverlayProps;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface DrawerOverlayProps extends ComponentPropsWithoutRef<"div"> {
|
|
92
|
-
/** Whether clicking the overlay closes drawer @default `true` */
|
|
93
|
-
closeOnClick?: boolean;
|
|
94
|
-
|
|
95
|
-
/** Overlay background opacity @default `0.5` */
|
|
96
|
-
backgroundOpacity?: number;
|
|
97
|
-
|
|
98
|
-
/** Backdrop blur amount in px (or any CSS length) @default `0` */
|
|
99
|
-
blur?: number | string;
|
|
100
|
-
|
|
101
|
-
/** Used for editing root class name */
|
|
102
|
-
className?: string;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export interface DrawerContentProps extends ComponentPropsWithoutRef<"div"> {
|
|
106
|
-
/** Drawer body content */
|
|
107
|
-
children: ReactNode;
|
|
108
|
-
|
|
109
|
-
/** Used for editing root class name */
|
|
110
|
-
className?: string;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface DrawerHeaderProps extends ComponentPropsWithoutRef<"div"> {
|
|
114
|
-
/** Header content */
|
|
115
|
-
children?: ReactNode;
|
|
116
|
-
|
|
117
|
-
/** Shorthand header text */
|
|
118
|
-
text?: ReactNode;
|
|
119
|
-
|
|
120
|
-
/** Whether to show close button inside header @default `true` */
|
|
121
|
-
withClose?: boolean;
|
|
122
|
-
|
|
123
|
-
/** Used for editing root class name */
|
|
124
|
-
className?: string;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export interface DrawerBodyProps extends ComponentPropsWithoutRef<"div"> {
|
|
128
|
-
/** Body content */
|
|
129
|
-
children?: ReactNode;
|
|
130
|
-
|
|
131
|
-
/** Used for editing root class name */
|
|
132
|
-
className?: string;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export interface DrawerCloseProps extends Omit<
|
|
136
|
-
ComponentPropsWithoutRef<"button">,
|
|
137
|
-
"onClick"
|
|
138
|
-
> {
|
|
139
|
-
/** Optional close content (defaults to `x`) */
|
|
140
|
-
children?: ReactNode;
|
|
141
|
-
|
|
142
|
-
/** Click callback fired before closing */
|
|
143
|
-
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
144
|
-
|
|
145
|
-
/** Used for editing root class name */
|
|
146
|
-
className?: string;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export interface DrawerFactoryPayload extends FactoryPayload {
|
|
150
|
-
props: DrawerProps;
|
|
151
|
-
ref: HTMLDivElement;
|
|
152
|
-
compound: {
|
|
153
|
-
configure: ReturnType<typeof createComponentConfig<DrawerProps>>;
|
|
154
|
-
classNames: ReturnType<typeof createClassNamesConfig<DrawerClassNames>>;
|
|
155
|
-
Root: typeof DrawerRoot;
|
|
156
|
-
Overlay: typeof DrawerOverlay;
|
|
157
|
-
Content: typeof DrawerContent;
|
|
158
|
-
Header: typeof DrawerHeader;
|
|
159
|
-
Body: typeof DrawerBody;
|
|
160
|
-
Close: typeof DrawerClose;
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export interface DrawerRootFactoryPayload extends FactoryPayload {
|
|
165
|
-
props: DrawerRootProps;
|
|
166
|
-
ref: HTMLDivElement;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export interface DrawerOverlayFactoryPayload extends FactoryPayload {
|
|
170
|
-
props: DrawerOverlayProps;
|
|
171
|
-
ref: HTMLDivElement;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export interface DrawerContentFactoryPayload extends FactoryPayload {
|
|
175
|
-
props: DrawerContentProps;
|
|
176
|
-
ref: HTMLDivElement;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export interface DrawerHeaderFactoryPayload extends FactoryPayload {
|
|
180
|
-
props: DrawerHeaderProps;
|
|
181
|
-
ref: HTMLDivElement;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export interface DrawerBodyFactoryPayload extends FactoryPayload {
|
|
185
|
-
props: DrawerBodyProps;
|
|
186
|
-
ref: HTMLDivElement;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export interface DrawerCloseFactoryPayload extends FactoryPayload {
|
|
190
|
-
props: DrawerCloseProps;
|
|
191
|
-
ref: HTMLButtonElement;
|
|
192
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export { default as Drawer } from "./drawer";
|
|
2
|
-
export { DrawerRoot } from "./drawer-root";
|
|
3
|
-
export { DrawerOverlay } from "./drawer-overlay";
|
|
4
|
-
export { DrawerContent } from "./drawer-content";
|
|
5
|
-
export { DrawerHeader } from "./drawer-header";
|
|
6
|
-
export { DrawerBody } from "./drawer-body";
|
|
7
|
-
export { DrawerClose } from "./drawer-close";
|
|
8
|
-
export type {
|
|
9
|
-
DrawerProps,
|
|
10
|
-
DrawerRootProps,
|
|
11
|
-
DrawerOverlayProps,
|
|
12
|
-
DrawerContentProps,
|
|
13
|
-
DrawerHeaderProps,
|
|
14
|
-
DrawerBodyProps,
|
|
15
|
-
DrawerCloseProps,
|
|
16
|
-
DrawerClassNames,
|
|
17
|
-
DrawerPosition
|
|
18
|
-
} from "./drawer.types";
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { useUncontrolled } from "@refraktor/utils";
|
|
2
|
-
import {
|
|
3
|
-
FloatingContext,
|
|
4
|
-
useDismiss,
|
|
5
|
-
useFloating,
|
|
6
|
-
useInteractions,
|
|
7
|
-
useRole
|
|
8
|
-
} from "@floating-ui/react";
|
|
9
|
-
import { useCallback } from "react";
|
|
10
|
-
|
|
11
|
-
interface UseDrawerProps {
|
|
12
|
-
opened?: boolean;
|
|
13
|
-
defaultOpened?: boolean;
|
|
14
|
-
onOpenedChange?: (opened: boolean) => void;
|
|
15
|
-
closeOnClickOutside?: boolean;
|
|
16
|
-
closeOnEscape?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface UseDrawerReturn {
|
|
20
|
-
opened: boolean;
|
|
21
|
-
open: () => void;
|
|
22
|
-
close: () => void;
|
|
23
|
-
toggle: () => void;
|
|
24
|
-
context: FloatingContext;
|
|
25
|
-
refs: {
|
|
26
|
-
setReference: (node: HTMLElement | null) => void;
|
|
27
|
-
setFloating: (node: HTMLElement | null) => void;
|
|
28
|
-
floating: React.MutableRefObject<HTMLElement | null>;
|
|
29
|
-
};
|
|
30
|
-
getFloatingProps: (
|
|
31
|
-
userProps?: React.HTMLAttributes<HTMLElement>
|
|
32
|
-
) => Record<string, unknown>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function useDrawer(options: UseDrawerProps): UseDrawerReturn {
|
|
36
|
-
const {
|
|
37
|
-
opened,
|
|
38
|
-
defaultOpened,
|
|
39
|
-
onOpenedChange,
|
|
40
|
-
closeOnClickOutside = true,
|
|
41
|
-
closeOnEscape = true
|
|
42
|
-
} = options;
|
|
43
|
-
|
|
44
|
-
const [isOpen, setIsOpen] = useUncontrolled({
|
|
45
|
-
value: opened,
|
|
46
|
-
defaultValue: defaultOpened,
|
|
47
|
-
finalValue: false,
|
|
48
|
-
onChange: onOpenedChange
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const floating = useFloating({
|
|
52
|
-
open: isOpen,
|
|
53
|
-
onOpenChange: setIsOpen
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const dismiss = useDismiss(floating.context, {
|
|
57
|
-
outsidePress: closeOnClickOutside,
|
|
58
|
-
outsidePressEvent: "mousedown",
|
|
59
|
-
escapeKey: closeOnEscape
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const role = useRole(floating.context, {
|
|
63
|
-
role: "dialog"
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const { getFloatingProps } = useInteractions([dismiss, role]);
|
|
67
|
-
|
|
68
|
-
const open = useCallback(() => {
|
|
69
|
-
setIsOpen(true);
|
|
70
|
-
}, [setIsOpen]);
|
|
71
|
-
|
|
72
|
-
const close = useCallback(() => {
|
|
73
|
-
setIsOpen(false);
|
|
74
|
-
}, [setIsOpen]);
|
|
75
|
-
|
|
76
|
-
const toggle = useCallback(() => {
|
|
77
|
-
setIsOpen(!isOpen);
|
|
78
|
-
}, [isOpen, setIsOpen]);
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
opened: isOpen,
|
|
82
|
-
open,
|
|
83
|
-
close,
|
|
84
|
-
toggle,
|
|
85
|
-
context: floating.context,
|
|
86
|
-
refs: {
|
|
87
|
-
setReference: floating.refs.setReference,
|
|
88
|
-
setFloating: floating.refs.setFloating,
|
|
89
|
-
floating: floating.refs
|
|
90
|
-
.floating as React.MutableRefObject<HTMLElement | null>
|
|
91
|
-
},
|
|
92
|
-
getFloatingProps
|
|
93
|
-
};
|
|
94
|
-
}
|