@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,316 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { render, screen, userEvent, waitFor } from "../../vitest";
|
|
3
|
-
import Modal from "./modal";
|
|
4
|
-
import { ModalBody } from "./modal-body";
|
|
5
|
-
import { ModalContent } from "./modal-content";
|
|
6
|
-
import { ModalOverlay } from "./modal-overlay";
|
|
7
|
-
import { ModalRoot } from "./modal-root";
|
|
8
|
-
|
|
9
|
-
describe("@refraktor/core/Modal", () => {
|
|
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
|
-
<Modal.Root defaultOpened transitionProps={transitionProps}>
|
|
20
|
-
<Modal.Overlay />
|
|
21
|
-
|
|
22
|
-
<Modal.Content>
|
|
23
|
-
<Modal.Header>Delete item</Modal.Header>
|
|
24
|
-
<Modal.Body>
|
|
25
|
-
<p>Are you sure?</p>
|
|
26
|
-
</Modal.Body>
|
|
27
|
-
</Modal.Content>
|
|
28
|
-
</Modal.Root>
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
expect(
|
|
32
|
-
await screen.findByRole("dialog", { name: "Delete item" })
|
|
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
|
-
<Modal.Root
|
|
48
|
-
opened
|
|
49
|
-
onOpenedChange={onOpenedChange}
|
|
50
|
-
transitionProps={transitionProps}
|
|
51
|
-
>
|
|
52
|
-
<Modal.Overlay data-testid="overlay" />
|
|
53
|
-
<Modal.Content>Controlled modal</Modal.Content>
|
|
54
|
-
</Modal.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
|
-
<Modal.Root defaultOpened transitionProps={transitionProps}>
|
|
67
|
-
<Modal.Content>Keyboard close</Modal.Content>
|
|
68
|
-
</Modal.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 ModalRoot", async () => {
|
|
81
|
-
await render(
|
|
82
|
-
<ModalRoot defaultOpened transitionProps={transitionProps}>
|
|
83
|
-
<ModalOverlay />
|
|
84
|
-
<ModalContent>Standalone composition</ModalContent>
|
|
85
|
-
</ModalRoot>
|
|
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
|
-
<Modal.Root defaultOpened transitionProps={transitionProps}>
|
|
94
|
-
<Modal.Overlay
|
|
95
|
-
data-testid="overlay"
|
|
96
|
-
backgroundOpacity={0.4}
|
|
97
|
-
blur={6}
|
|
98
|
-
/>
|
|
99
|
-
<Modal.Content>Styled overlay</Modal.Content>
|
|
100
|
-
</Modal.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("does not set backdrop blur for zero blur", async () => {
|
|
112
|
-
await render(
|
|
113
|
-
<Modal.Root defaultOpened transitionProps={transitionProps}>
|
|
114
|
-
<Modal.Overlay data-testid="overlay" blur={0} />
|
|
115
|
-
<Modal.Content>No blur</Modal.Content>
|
|
116
|
-
</Modal.Root>
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
const overlay = await screen.findByTestId("overlay");
|
|
120
|
-
|
|
121
|
-
expect(overlay).toHaveStyle({
|
|
122
|
-
backgroundColor: "rgba(0, 0, 0, 0.5)"
|
|
123
|
-
});
|
|
124
|
-
expect(overlay.style.backdropFilter).toBe("");
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("renders Modal.Body subcomponent", async () => {
|
|
128
|
-
await render(
|
|
129
|
-
<Modal.Root defaultOpened transitionProps={transitionProps}>
|
|
130
|
-
<Modal.Content>
|
|
131
|
-
<Modal.Body data-testid="body">Body content</Modal.Body>
|
|
132
|
-
</Modal.Content>
|
|
133
|
-
</Modal.Root>
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
const body = await screen.findByTestId("body");
|
|
137
|
-
expect(body).toBeInTheDocument();
|
|
138
|
-
expect(body).toHaveTextContent("Body content");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("renders standalone ModalBody component", async () => {
|
|
142
|
-
await render(
|
|
143
|
-
<ModalRoot defaultOpened transitionProps={transitionProps}>
|
|
144
|
-
<ModalContent>
|
|
145
|
-
<ModalBody data-testid="body">Standalone body</ModalBody>
|
|
146
|
-
</ModalContent>
|
|
147
|
-
</ModalRoot>
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
expect(await screen.findByTestId("body")).toHaveTextContent(
|
|
151
|
-
"Standalone body"
|
|
152
|
-
);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe("single-component shorthand API", () => {
|
|
156
|
-
it("renders with title, overlay, close button, and body", async () => {
|
|
157
|
-
await render(
|
|
158
|
-
<Modal
|
|
159
|
-
defaultOpened
|
|
160
|
-
title="Confirm action"
|
|
161
|
-
transitionProps={transitionProps}
|
|
162
|
-
>
|
|
163
|
-
<p>Are you sure?</p>
|
|
164
|
-
</Modal>
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
expect(
|
|
168
|
-
await screen.findByRole("dialog", { name: "Confirm action" })
|
|
169
|
-
).toBeInTheDocument();
|
|
170
|
-
expect(screen.getByText("Are you sure?")).toBeInTheDocument();
|
|
171
|
-
expect(
|
|
172
|
-
screen.getByRole("button", { name: "Close" })
|
|
173
|
-
).toBeInTheDocument();
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("hides overlay when withOverlay is false", async () => {
|
|
177
|
-
const { container } = await render(
|
|
178
|
-
<Modal
|
|
179
|
-
defaultOpened
|
|
180
|
-
title="No overlay"
|
|
181
|
-
withOverlay={false}
|
|
182
|
-
transitionProps={transitionProps}
|
|
183
|
-
/>
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
expect(await screen.findByRole("dialog")).toBeInTheDocument();
|
|
187
|
-
expect(
|
|
188
|
-
container.ownerDocument.querySelector("[aria-hidden='true']")
|
|
189
|
-
).toBeNull();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("hides close button when withCloseButton is false", async () => {
|
|
193
|
-
await render(
|
|
194
|
-
<Modal
|
|
195
|
-
defaultOpened
|
|
196
|
-
title="No close"
|
|
197
|
-
withCloseButton={false}
|
|
198
|
-
transitionProps={transitionProps}
|
|
199
|
-
/>
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
await screen.findByRole("dialog");
|
|
203
|
-
expect(
|
|
204
|
-
screen.queryByRole("button", { name: "Close" })
|
|
205
|
-
).not.toBeInTheDocument();
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("closes via shorthand close button", async () => {
|
|
209
|
-
const user = userEvent.setup();
|
|
210
|
-
|
|
211
|
-
await render(
|
|
212
|
-
<Modal
|
|
213
|
-
defaultOpened
|
|
214
|
-
title="Closeable"
|
|
215
|
-
transitionProps={transitionProps}
|
|
216
|
-
>
|
|
217
|
-
Content
|
|
218
|
-
</Modal>
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
await screen.findByRole("dialog");
|
|
222
|
-
|
|
223
|
-
await user.click(screen.getByRole("button", { name: "Close" }));
|
|
224
|
-
|
|
225
|
-
await waitFor(() => {
|
|
226
|
-
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it("passes overlayProps to the overlay", async () => {
|
|
231
|
-
await render(
|
|
232
|
-
<Modal
|
|
233
|
-
defaultOpened
|
|
234
|
-
title="Custom overlay"
|
|
235
|
-
overlayProps={{
|
|
236
|
-
backgroundOpacity: 0.8,
|
|
237
|
-
blur: 10,
|
|
238
|
-
"data-testid": "shorthand-overlay"
|
|
239
|
-
} as any}
|
|
240
|
-
transitionProps={transitionProps}
|
|
241
|
-
>
|
|
242
|
-
Content
|
|
243
|
-
</Modal>
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
const overlay = await screen.findByTestId("shorthand-overlay");
|
|
247
|
-
|
|
248
|
-
expect(overlay).toHaveStyle({
|
|
249
|
-
backgroundColor: "rgba(0, 0, 0, 0.8)",
|
|
250
|
-
backdropFilter: "blur(10px)"
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
describe("size prop", () => {
|
|
256
|
-
it("applies md size by default", async () => {
|
|
257
|
-
await render(
|
|
258
|
-
<Modal.Root defaultOpened transitionProps={transitionProps}>
|
|
259
|
-
<Modal.Content data-testid="content">
|
|
260
|
-
Default size
|
|
261
|
-
</Modal.Content>
|
|
262
|
-
</Modal.Root>
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
const dialog = await screen.findByRole("dialog");
|
|
266
|
-
expect(dialog.className).toContain("max-w-md");
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("applies custom size", async () => {
|
|
270
|
-
await render(
|
|
271
|
-
<Modal.Root
|
|
272
|
-
defaultOpened
|
|
273
|
-
size="lg"
|
|
274
|
-
transitionProps={transitionProps}
|
|
275
|
-
>
|
|
276
|
-
<Modal.Content>Large modal</Modal.Content>
|
|
277
|
-
</Modal.Root>
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
const dialog = await screen.findByRole("dialog");
|
|
281
|
-
expect(dialog.className).toContain("max-w-lg");
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
describe("centered prop", () => {
|
|
286
|
-
it("centers vertically by default", async () => {
|
|
287
|
-
await render(
|
|
288
|
-
<Modal.Root defaultOpened transitionProps={transitionProps}>
|
|
289
|
-
<Modal.Content>Centered</Modal.Content>
|
|
290
|
-
</Modal.Root>
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
await screen.findByRole("dialog");
|
|
294
|
-
const wrapper =
|
|
295
|
-
screen.getByRole("dialog").parentElement?.parentElement;
|
|
296
|
-
expect(wrapper?.className).toContain("place-items-center");
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it("positions at top when centered is false", async () => {
|
|
300
|
-
await render(
|
|
301
|
-
<Modal.Root
|
|
302
|
-
defaultOpened
|
|
303
|
-
centered={false}
|
|
304
|
-
transitionProps={transitionProps}
|
|
305
|
-
>
|
|
306
|
-
<Modal.Content>Top aligned</Modal.Content>
|
|
307
|
-
</Modal.Root>
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
await screen.findByRole("dialog");
|
|
311
|
-
const wrapper =
|
|
312
|
-
screen.getByRole("dialog").parentElement?.parentElement;
|
|
313
|
-
expect(wrapper?.className).toContain("items-start");
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createClassNamesConfig,
|
|
3
|
-
createComponentConfig,
|
|
4
|
-
factory
|
|
5
|
-
} from "../../utils";
|
|
6
|
-
import { ModalBody } from "./modal-body";
|
|
7
|
-
import { ModalClose } from "./modal-close";
|
|
8
|
-
import { ModalContent } from "./modal-content";
|
|
9
|
-
import { ModalHeader } from "./modal-header";
|
|
10
|
-
import { ModalOverlay } from "./modal-overlay";
|
|
11
|
-
import { ModalRoot } from "./modal-root";
|
|
12
|
-
import {
|
|
13
|
-
ModalClassNames,
|
|
14
|
-
ModalFactoryPayload,
|
|
15
|
-
ModalProps
|
|
16
|
-
} from "./modal.types";
|
|
17
|
-
|
|
18
|
-
const Modal = factory<ModalFactoryPayload>(
|
|
19
|
-
(
|
|
20
|
-
{
|
|
21
|
-
title,
|
|
22
|
-
withOverlay = true,
|
|
23
|
-
withCloseButton = true,
|
|
24
|
-
overlayProps,
|
|
25
|
-
children,
|
|
26
|
-
...rootProps
|
|
27
|
-
},
|
|
28
|
-
ref
|
|
29
|
-
) => {
|
|
30
|
-
return (
|
|
31
|
-
<ModalRoot {...rootProps} ref={ref}>
|
|
32
|
-
{withOverlay && <ModalOverlay {...overlayProps} />}
|
|
33
|
-
|
|
34
|
-
<ModalContent>
|
|
35
|
-
{(title || withCloseButton) && (
|
|
36
|
-
<ModalHeader withClose={withCloseButton}>
|
|
37
|
-
{title}
|
|
38
|
-
</ModalHeader>
|
|
39
|
-
)}
|
|
40
|
-
|
|
41
|
-
<ModalBody>{children}</ModalBody>
|
|
42
|
-
</ModalContent>
|
|
43
|
-
</ModalRoot>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
Modal.displayName = "@refraktor/core/Modal";
|
|
49
|
-
Modal.configure = createComponentConfig<ModalProps>();
|
|
50
|
-
Modal.classNames = createClassNamesConfig<ModalClassNames>();
|
|
51
|
-
Modal.Root = ModalRoot;
|
|
52
|
-
Modal.Overlay = ModalOverlay;
|
|
53
|
-
Modal.Content = ModalContent;
|
|
54
|
-
Modal.Header = ModalHeader;
|
|
55
|
-
Modal.Body = ModalBody;
|
|
56
|
-
Modal.Close = ModalClose;
|
|
57
|
-
|
|
58
|
-
export default Modal;
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { ComponentPropsWithoutRef, MouseEvent, ReactNode } from "react";
|
|
2
|
-
import {
|
|
3
|
-
createClassNamesConfig,
|
|
4
|
-
createComponentConfig,
|
|
5
|
-
FactoryPayload
|
|
6
|
-
} from "../../utils";
|
|
7
|
-
import { RefraktorRadius } from "../../theme";
|
|
8
|
-
import { TransitionProps } from "../transition";
|
|
9
|
-
import { ModalRoot } from "./modal-root";
|
|
10
|
-
import { ModalOverlay } from "./modal-overlay";
|
|
11
|
-
import { ModalContent } from "./modal-content";
|
|
12
|
-
import { ModalHeader } from "./modal-header";
|
|
13
|
-
import { ModalBody } from "./modal-body";
|
|
14
|
-
import { ModalClose } from "./modal-close";
|
|
15
|
-
|
|
16
|
-
export type ModalSize = "xs" | "sm" | "md" | "lg" | "xl" | "full";
|
|
17
|
-
|
|
18
|
-
export type ModalClassNames = {
|
|
19
|
-
root?: string;
|
|
20
|
-
overlay?: string;
|
|
21
|
-
content?: string;
|
|
22
|
-
header?: string;
|
|
23
|
-
body?: string;
|
|
24
|
-
close?: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export interface ModalRootProps extends ComponentPropsWithoutRef<"div"> {
|
|
28
|
-
/** Children containing modal subcomponents */
|
|
29
|
-
children?: ReactNode;
|
|
30
|
-
|
|
31
|
-
/** State of the modal (controlled) */
|
|
32
|
-
opened?: boolean;
|
|
33
|
-
|
|
34
|
-
/** Initial state of the modal (uncontrolled) */
|
|
35
|
-
defaultOpened?: boolean;
|
|
36
|
-
|
|
37
|
-
/** Callback called when modal state changes */
|
|
38
|
-
onOpenedChange?: (opened: boolean) => void;
|
|
39
|
-
|
|
40
|
-
/** Whether to close modal on overlay/outside click @default `true` */
|
|
41
|
-
closeOnClickOutside?: boolean;
|
|
42
|
-
|
|
43
|
-
/** Whether to close modal 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 modal content @default `md` */
|
|
53
|
-
radius?: RefraktorRadius;
|
|
54
|
-
|
|
55
|
-
/** Modal content width @default `md` */
|
|
56
|
-
size?: ModalSize;
|
|
57
|
-
|
|
58
|
-
/** Whether to center modal vertically @default `true` */
|
|
59
|
-
centered?: boolean;
|
|
60
|
-
|
|
61
|
-
/** Whether to trap focus within the modal @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?: ModalClassNames;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface ModalProps extends Omit<ModalRootProps, "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?: ModalOverlayProps;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface ModalOverlayProps extends ComponentPropsWithoutRef<"div"> {
|
|
92
|
-
/** Whether clicking the overlay closes modal @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 ModalContentProps extends ComponentPropsWithoutRef<"div"> {
|
|
106
|
-
/** Modal body content */
|
|
107
|
-
children: ReactNode;
|
|
108
|
-
|
|
109
|
-
/** Used for editing root class name */
|
|
110
|
-
className?: string;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface ModalHeaderProps extends ComponentPropsWithoutRef<"div"> {
|
|
114
|
-
/** Header content */
|
|
115
|
-
children?: ReactNode;
|
|
116
|
-
|
|
117
|
-
/** Whether to show close button inside header @default `true` */
|
|
118
|
-
withClose?: boolean;
|
|
119
|
-
|
|
120
|
-
/** Used for editing root class name */
|
|
121
|
-
className?: string;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface ModalBodyProps extends ComponentPropsWithoutRef<"div"> {
|
|
125
|
-
/** Body content */
|
|
126
|
-
children?: ReactNode;
|
|
127
|
-
|
|
128
|
-
/** Used for editing root class name */
|
|
129
|
-
className?: string;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export interface ModalCloseProps extends Omit<
|
|
133
|
-
ComponentPropsWithoutRef<"button">,
|
|
134
|
-
"onClick"
|
|
135
|
-
> {
|
|
136
|
-
/** Optional close content (defaults to `x`) */
|
|
137
|
-
children?: ReactNode;
|
|
138
|
-
|
|
139
|
-
/** Click callback fired before closing */
|
|
140
|
-
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
141
|
-
|
|
142
|
-
/** Used for editing root class name */
|
|
143
|
-
className?: string;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export interface ModalFactoryPayload extends FactoryPayload {
|
|
147
|
-
props: ModalProps;
|
|
148
|
-
ref: HTMLDivElement;
|
|
149
|
-
compound: {
|
|
150
|
-
configure: ReturnType<typeof createComponentConfig<ModalProps>>;
|
|
151
|
-
classNames: ReturnType<typeof createClassNamesConfig<ModalClassNames>>;
|
|
152
|
-
Root: typeof ModalRoot;
|
|
153
|
-
Overlay: typeof ModalOverlay;
|
|
154
|
-
Content: typeof ModalContent;
|
|
155
|
-
Header: typeof ModalHeader;
|
|
156
|
-
Body: typeof ModalBody;
|
|
157
|
-
Close: typeof ModalClose;
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export interface ModalRootFactoryPayload extends FactoryPayload {
|
|
162
|
-
props: ModalRootProps;
|
|
163
|
-
ref: HTMLDivElement;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export interface ModalOverlayFactoryPayload extends FactoryPayload {
|
|
167
|
-
props: ModalOverlayProps;
|
|
168
|
-
ref: HTMLDivElement;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export interface ModalContentFactoryPayload extends FactoryPayload {
|
|
172
|
-
props: ModalContentProps;
|
|
173
|
-
ref: HTMLDivElement;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export interface ModalHeaderFactoryPayload extends FactoryPayload {
|
|
177
|
-
props: ModalHeaderProps;
|
|
178
|
-
ref: HTMLDivElement;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export interface ModalBodyFactoryPayload extends FactoryPayload {
|
|
182
|
-
props: ModalBodyProps;
|
|
183
|
-
ref: HTMLDivElement;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export interface ModalCloseFactoryPayload extends FactoryPayload {
|
|
187
|
-
props: ModalCloseProps;
|
|
188
|
-
ref: HTMLButtonElement;
|
|
189
|
-
}
|
|
@@ -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 UseModalProps {
|
|
12
|
-
opened?: boolean;
|
|
13
|
-
defaultOpened?: boolean;
|
|
14
|
-
onOpenedChange?: (opened: boolean) => void;
|
|
15
|
-
closeOnClickOutside?: boolean;
|
|
16
|
-
closeOnEscape?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface UseModalReturn {
|
|
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 useModal(options: UseModalProps): UseModalReturn {
|
|
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
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { RefraktorSize } from "../../theme";
|
|
2
|
-
|
|
3
|
-
const controlSizes = {
|
|
4
|
-
xs: {
|
|
5
|
-
width: "w-3",
|
|
6
|
-
iconSize: 8,
|
|
7
|
-
leftSpacing: "mr-0.5",
|
|
8
|
-
rightSpacing: "ml-0.5"
|
|
9
|
-
},
|
|
10
|
-
sm: {
|
|
11
|
-
width: "w-4",
|
|
12
|
-
iconSize: 10,
|
|
13
|
-
leftSpacing: "mr-0.5",
|
|
14
|
-
rightSpacing: "ml-0.5"
|
|
15
|
-
},
|
|
16
|
-
md: {
|
|
17
|
-
width: "w-5",
|
|
18
|
-
iconSize: 12,
|
|
19
|
-
leftSpacing: "mr-1",
|
|
20
|
-
rightSpacing: "ml-1"
|
|
21
|
-
},
|
|
22
|
-
lg: {
|
|
23
|
-
width: "w-6",
|
|
24
|
-
iconSize: 14,
|
|
25
|
-
leftSpacing: "mr-1",
|
|
26
|
-
rightSpacing: "ml-1"
|
|
27
|
-
},
|
|
28
|
-
xl: {
|
|
29
|
-
width: "w-7",
|
|
30
|
-
iconSize: 16,
|
|
31
|
-
leftSpacing: "mr-1.5",
|
|
32
|
-
rightSpacing: "ml-1.5"
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const getControlSize = (size: RefraktorSize = "md") =>
|
|
37
|
-
controlSizes[size];
|