@boxcustodia/library 2.0.0-alpha.11 → 2.0.0-alpha.13
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/dist/index.cjs.js +38 -38
- package/dist/index.css +1 -1
- package/dist/index.d.ts +28 -29
- package/dist/index.es.js +6804 -6792
- package/package.json +4 -3
- package/src/__doc__/Changelog.mdx +6 -0
- package/src/__doc__/Components.mdx +73 -0
- package/src/__doc__/Examples.tsx +69 -0
- package/src/__doc__/Icons.mdx +41 -0
- package/src/__doc__/Intro.mdx +138 -0
- package/src/__doc__/MCP.mdx +71 -0
- package/src/__doc__/Migration.mdx +451 -0
- package/src/__doc__/Theme.mdx +132 -0
- package/src/__doc__/Types.mdx +252 -0
- package/src/components/alert/alert.stories.tsx +142 -0
- package/src/components/alert/alert.tsx +109 -0
- package/src/components/alert/index.ts +7 -0
- package/src/components/alert-dialog/alert-dialog.stories.tsx +173 -0
- package/src/components/alert-dialog/alert-dialog.test.tsx +49 -0
- package/src/components/alert-dialog/alert-dialog.tsx +265 -0
- package/src/components/alert-dialog/index.ts +1 -0
- package/src/components/auto-complete/auto-complete-primitives.tsx +155 -0
- package/src/components/auto-complete/auto-complete.stories.tsx +241 -0
- package/src/components/auto-complete/auto-complete.tsx +82 -0
- package/src/components/auto-complete/index.ts +2 -0
- package/src/components/avatar/avatar.stories.tsx +84 -0
- package/src/components/avatar/avatar.test.tsx +61 -0
- package/src/components/avatar/avatar.tsx +104 -0
- package/src/components/avatar/index.ts +1 -0
- package/src/components/background-image/background-image.stories.tsx +21 -0
- package/src/components/background-image/background-image.test.tsx +29 -0
- package/src/components/background-image/background-image.tsx +23 -0
- package/src/components/background-image/index.ts +1 -0
- package/src/components/button/button.stories.tsx +396 -0
- package/src/components/button/button.test.tsx +58 -0
- package/src/components/button/button.tsx +31 -0
- package/src/components/button/button.variants.ts +44 -0
- package/src/components/button/components/base-button.tsx +86 -0
- package/src/components/button/components/loader-overlay.tsx +21 -0
- package/src/components/button/components/loading-icon.tsx +47 -0
- package/src/components/button/index.ts +3 -0
- package/src/components/calendar/calendar.model.ts +86 -0
- package/src/components/calendar/calendar.stories.tsx +155 -0
- package/src/components/calendar/calendar.test.tsx +12 -0
- package/src/components/calendar/calendar.tsx +185 -0
- package/src/components/calendar/components/calendar-navigation.tsx +141 -0
- package/src/components/calendar/components/day.tsx +61 -0
- package/src/components/calendar/components/decade-view.tsx +45 -0
- package/src/components/calendar/components/index.ts +6 -0
- package/src/components/calendar/components/month-view.tsx +58 -0
- package/src/components/calendar/components/week-days.tsx +27 -0
- package/src/components/calendar/components/year-view.tsx +29 -0
- package/src/components/calendar/hooks/index.ts +4 -0
- package/src/components/calendar/hooks/use-calendar-navigation.ts +79 -0
- package/src/components/calendar/hooks/use-calendar.ts +90 -0
- package/src/components/calendar/hooks/use-multiple-calendar.ts +34 -0
- package/src/components/calendar/hooks/use-range-calendar.ts +91 -0
- package/src/components/calendar/hooks/use-single-calendar.ts +18 -0
- package/src/components/calendar/index.ts +1 -0
- package/src/components/calendar/utils/typeguards.ts +7 -0
- package/src/components/card/card.stories.tsx +116 -0
- package/src/components/card/card.tsx +74 -0
- package/src/components/card/index.ts +1 -0
- package/src/components/center/center.stories.tsx +81 -0
- package/src/components/center/center.tsx +24 -0
- package/src/components/center/index.ts +1 -0
- package/src/components/checkbox/checkbox.stories.tsx +307 -0
- package/src/components/checkbox/checkbox.tsx +273 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/checkbox-group/checkbox-group.stories.tsx +104 -0
- package/src/components/checkbox-group/checkbox-group.tsx +16 -0
- package/src/components/checkbox-group/index.ts +1 -0
- package/src/components/combobox/combobox.stories.tsx +339 -0
- package/src/components/combobox/combobox.tsx +898 -0
- package/src/components/combobox/index.ts +1 -0
- package/src/components/date-picker/date-input.stories.tsx +158 -0
- package/src/components/date-picker/date-input.tsx +163 -0
- package/src/components/date-picker/date-picker.model.ts +90 -0
- package/src/components/date-picker/date-picker.stories.tsx +200 -0
- package/src/components/date-picker/date-picker.test.tsx +23 -0
- package/src/components/date-picker/date-picker.tsx +298 -0
- package/src/components/date-picker/date-picker.utils.ts +260 -0
- package/src/components/date-picker/index.ts +3 -0
- package/src/components/date-picker/use-date-input-popover.ts +48 -0
- package/src/components/date-picker/use-date-input.ts +125 -0
- package/src/components/dialog/dialog.stories.tsx +171 -0
- package/src/components/dialog/dialog.test.tsx +68 -0
- package/src/components/dialog/dialog.tsx +277 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/divider/divider.stories.tsx +139 -0
- package/src/components/divider/divider.test.tsx +22 -0
- package/src/components/divider/divider.tsx +23 -0
- package/src/components/divider/index.ts +1 -0
- package/src/components/dropzone/dropzone.stories.tsx +210 -0
- package/src/components/dropzone/dropzone.tsx +154 -0
- package/src/components/dropzone/file-types.ts +64 -0
- package/src/components/dropzone/index.ts +3 -0
- package/src/components/dropzone/upload-primitives.tsx +310 -0
- package/src/components/dropzone/use-dropzone.ts +122 -0
- package/src/components/empty-state/empty-state.stories.tsx +56 -0
- package/src/components/empty-state/empty-state.tsx +39 -0
- package/src/components/empty-state/index.ts +1 -0
- package/src/components/field/field.stories.tsx +223 -0
- package/src/components/field/field.tsx +229 -0
- package/src/components/field/index.ts +1 -0
- package/src/components/form/form.stories.tsx +594 -0
- package/src/components/form/form.tsx +30 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/heading/heading.stories.tsx +74 -0
- package/src/components/heading/heading.tsx +28 -0
- package/src/components/heading/heading.variants.ts +27 -0
- package/src/components/heading/index.ts +1 -0
- package/src/components/index.ts +46 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input/input.stories.tsx +104 -0
- package/src/components/input/input.tsx +75 -0
- package/src/components/kbd/index.ts +1 -0
- package/src/components/kbd/kbd.stories.tsx +40 -0
- package/src/components/kbd/kbd.tsx +31 -0
- package/src/components/kbd/kbd.variants.ts +26 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/label/label.stories.tsx +68 -0
- package/src/components/label/label.test.tsx +61 -0
- package/src/components/label/label.tsx +62 -0
- package/src/components/loader/index.ts +1 -0
- package/src/components/loader/loader.stories.tsx +60 -0
- package/src/components/loader/loader.test.tsx +26 -0
- package/src/components/loader/loader.tsx +60 -0
- package/src/components/menu/index.ts +2 -0
- package/src/components/menu/menu-primitives.tsx +248 -0
- package/src/components/menu/menu.stories.tsx +203 -0
- package/src/components/menu/menu.tsx +100 -0
- package/src/components/menu/util/render-menu-item.tsx +54 -0
- package/src/components/multi-select/hooks/use-multi-select.ts +66 -0
- package/src/components/multi-select/index.ts +1 -0
- package/src/components/multi-select/multi-select.stories.tsx +294 -0
- package/src/components/multi-select/multi-select.tsx +300 -0
- package/src/components/multi-select/multi-select.variants.ts +22 -0
- package/src/components/number-input/index.ts +1 -0
- package/src/components/number-input/number-input.stories.tsx +209 -0
- package/src/components/number-input/number-input.test.tsx +87 -0
- package/src/components/number-input/number-input.tsx +232 -0
- package/src/components/pagination/components/pagination-option.tsx +27 -0
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pagination/pagination.stories.tsx +80 -0
- package/src/components/pagination/pagination.test.tsx +76 -0
- package/src/components/pagination/pagination.tsx +102 -0
- package/src/components/password/index.ts +1 -0
- package/src/components/password/password.stories.tsx +104 -0
- package/src/components/password/password.tsx +75 -0
- package/src/components/popover/index.ts +1 -0
- package/src/components/popover/popover.stories.tsx +213 -0
- package/src/components/popover/popover.tsx +203 -0
- package/src/components/progress/index.ts +1 -0
- package/src/components/progress/progress.stories.tsx +124 -0
- package/src/components/progress/progress.test.tsx +25 -0
- package/src/components/progress/progress.tsx +124 -0
- package/src/components/scroll-area/index.ts +1 -0
- package/src/components/scroll-area/scroll-area.stories.tsx +166 -0
- package/src/components/scroll-area/scroll-area.tsx +64 -0
- package/src/components/select/index.ts +1 -0
- package/src/components/select/select.stories.tsx +253 -0
- package/src/components/select/select.tsx +430 -0
- package/src/components/show/index.ts +1 -0
- package/src/components/show/show.stories.tsx +197 -0
- package/src/components/show/show.test.tsx +41 -0
- package/src/components/show/show.tsx +16 -0
- package/src/components/skeleton/index.ts +1 -0
- package/src/components/skeleton/skeleton.stories.tsx +36 -0
- package/src/components/skeleton/skeleton.test.tsx +14 -0
- package/src/components/skeleton/skeleton.tsx +15 -0
- package/src/components/stack/index.ts +1 -0
- package/src/components/stack/stack.stories.tsx +194 -0
- package/src/components/stack/stack.tsx +52 -0
- package/src/components/stepper/Stepper.tsx +190 -0
- package/src/components/stepper/context/stepper-context.tsx +11 -0
- package/src/components/stepper/index.ts +1 -0
- package/src/components/stepper/stepper.stories.tsx +130 -0
- package/src/components/stepper/stepper.test.tsx +91 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/switch/switch.stories.tsx +122 -0
- package/src/components/switch/switch.test.tsx +30 -0
- package/src/components/switch/switch.tsx +86 -0
- package/src/components/table/index.ts +3 -0
- package/src/components/table/table-primitives.tsx +122 -0
- package/src/components/table/table.model.ts +20 -0
- package/src/components/table/table.stories.tsx +169 -0
- package/src/components/table/table.test.tsx +91 -0
- package/src/components/table/table.tsx +109 -0
- package/src/components/table-pagination/index.ts +2 -0
- package/src/components/table-pagination/table-pagination.model.ts +2 -0
- package/src/components/table-pagination/table-pagination.stories.tsx +23 -0
- package/src/components/table-pagination/table-pagination.test.tsx +32 -0
- package/src/components/table-pagination/table-pagination.tsx +108 -0
- package/src/components/tabs/context/tabs-context.tsx +14 -0
- package/src/components/tabs/index.ts +1 -0
- package/src/components/tabs/tabs.stories.tsx +182 -0
- package/src/components/tabs/tabs.test.tsx +61 -0
- package/src/components/tabs/tabs.tsx +175 -0
- package/src/components/tag/index.ts +2 -0
- package/src/components/tag/tag.stories.tsx +170 -0
- package/src/components/tag/tag.test.tsx +18 -0
- package/src/components/tag/tag.tsx +99 -0
- package/src/components/tag/tag.variants.ts +31 -0
- package/src/components/textarea/index.ts +1 -0
- package/src/components/textarea/textarea.stories.tsx +73 -0
- package/src/components/textarea/textarea.tsx +105 -0
- package/src/components/timeline/index.ts +1 -0
- package/src/components/timeline/timeline-status.ts +5 -0
- package/src/components/timeline/timeline.stories.tsx +84 -0
- package/src/components/timeline/timeline.tsx +147 -0
- package/src/components/toast/index.ts +1 -0
- package/src/components/toast/toast.stories.tsx +392 -0
- package/src/components/toast/toast.test.tsx +50 -0
- package/src/components/toast/toast.tsx +411 -0
- package/src/components/tooltip/index.ts +1 -0
- package/src/components/tooltip/tooltip.stories.tsx +226 -0
- package/src/components/tooltip/tooltip.test.tsx +46 -0
- package/src/components/tooltip/tooltip.tsx +171 -0
- package/src/components/tree/hooks/use-controllable-tree-state.ts +80 -0
- package/src/components/tree/index.ts +2 -0
- package/src/components/tree/tree-primitives.tsx +126 -0
- package/src/components/tree/tree.stories.tsx +468 -0
- package/src/components/tree/tree.tsx +42 -0
- package/src/hooks/index.ts +26 -0
- package/src/hooks/useArray/__doc__/useArray.stories.tsx +100 -0
- package/src/hooks/useArray/__test__/useArray.test.tsx +88 -0
- package/src/hooks/useArray/index.ts +1 -0
- package/src/hooks/useArray/useArray.ts +76 -0
- package/src/hooks/useAsync/__doc__/useAsync.stories.tsx +149 -0
- package/src/hooks/useAsync/__test__/useAsync.test.tsx +68 -0
- package/src/hooks/useAsync/index.ts +1 -0
- package/src/hooks/useAsync/useAsync.ts +58 -0
- package/src/hooks/useClickOutside/__doc__/useClickOutside.stories.tsx +40 -0
- package/src/hooks/useClickOutside/__test__/useClickOutside.test.tsx +33 -0
- package/src/hooks/useClickOutside/index.ts +1 -0
- package/src/hooks/useClickOutside/useClickOutside.ts +26 -0
- package/src/hooks/useClipboard/__doc__/useClipboard.stories.tsx +45 -0
- package/src/hooks/useClipboard/__test__/useClipboard.test.tsx +19 -0
- package/src/hooks/useClipboard/index.ts +1 -0
- package/src/hooks/useClipboard/useClipboard.tsx +28 -0
- package/src/hooks/useDebounceCallback/__doc__/useDebouncedCallback.stories.tsx +84 -0
- package/src/hooks/useDebounceCallback/index.ts +1 -0
- package/src/hooks/useDebounceCallback/useDebouncedCallback.ts +23 -0
- package/src/hooks/useDebounceValue/__doc__/useDebouncedValue.stories.tsx +75 -0
- package/src/hooks/useDebounceValue/index.ts +1 -0
- package/src/hooks/useDebounceValue/useDebouncedValue.ts +17 -0
- package/src/hooks/useDisclosure/__doc__/useDisclosure.stories.tsx +39 -0
- package/src/hooks/useDisclosure/__test__/useDisclosure.test.ts +43 -0
- package/src/hooks/useDisclosure/index.ts +1 -0
- package/src/hooks/useDisclosure/useDisclosure.ts +37 -0
- package/src/hooks/useDocumentTitle/__doc__/useDocumentTitle.stories.tsx +26 -0
- package/src/hooks/useDocumentTitle/index.ts +1 -0
- package/src/hooks/useDocumentTitle/useDocumentTitle.tsx +11 -0
- package/src/hooks/useEventListener/__doc__/useEventListener.stories.tsx +28 -0
- package/src/hooks/useEventListener/__test__/useEventListener.test.tsx +26 -0
- package/src/hooks/useEventListener/index.ts +1 -0
- package/src/hooks/useEventListener/useEventListener.ts +25 -0
- package/src/hooks/useFocusTrap/__doc__/useFocusTrap.stories.tsx +37 -0
- package/src/hooks/useFocusTrap/index.ts +1 -0
- package/src/hooks/useFocusTrap/scopeTab.ts +38 -0
- package/src/hooks/useFocusTrap/tabbable.ts +70 -0
- package/src/hooks/useFocusTrap/useFocusTrap.ts +78 -0
- package/src/hooks/useHotkey/__docs__/useHotkey.stories.tsx +116 -0
- package/src/hooks/useHotkey/__test__/useHotkey.test.tsx +105 -0
- package/src/hooks/useHotkey/__utils__/create-hotkey-listener.ts +25 -0
- package/src/hooks/useHotkey/__utils__/index.ts +3 -0
- package/src/hooks/useHotkey/__utils__/is-input-field.ts +14 -0
- package/src/hooks/useHotkey/__utils__/match-key-modifiers.ts +25 -0
- package/src/hooks/useHotkey/index.ts +1 -0
- package/src/hooks/useHotkey/useHotkey.ts +34 -0
- package/src/hooks/useHover/__doc__/useHover.stories.tsx +41 -0
- package/src/hooks/useHover/__test__/useHover.test.tsx +45 -0
- package/src/hooks/useHover/index.ts +1 -0
- package/src/hooks/useHover/useHover.tsx +40 -0
- package/src/hooks/useIsVisible/__doc__/useIsVisible.stories.tsx +60 -0
- package/src/hooks/useIsVisible/index.ts +1 -0
- package/src/hooks/useIsVisible/useIsVisible.tsx +50 -0
- package/src/hooks/useLocalStorage/__doc__/useLocalStorage.stories.tsx +86 -0
- package/src/hooks/useLocalStorage/__test__/useLocalStorage.test.ts +85 -0
- package/src/hooks/useLocalStorage/index.ts +1 -0
- package/src/hooks/useLocalStorage/useLocalStorage.ts +57 -0
- package/src/hooks/useMediaQuery/__doc__/useMediaQuery.stories.tsx +39 -0
- package/src/hooks/useMediaQuery/index.ts +1 -0
- package/src/hooks/useMediaQuery/useMediaQuery.ts +22 -0
- package/src/hooks/useMemoizedFn/index.ts +1 -0
- package/src/hooks/useMemoizedFn/useMemoizedFn.ts +32 -0
- package/src/hooks/useMutation/__doc__/useMutation.stories.tsx +111 -0
- package/src/hooks/useMutation/__test__/useMutation.test.tsx +83 -0
- package/src/hooks/useMutation/index.ts +1 -0
- package/src/hooks/useMutation/useMutation.tsx +60 -0
- package/src/hooks/useObject/__doc__/useObject.stories.tsx +119 -0
- package/src/hooks/useObject/__test__/useObject.test.tsx +87 -0
- package/src/hooks/useObject/index.ts +1 -0
- package/src/hooks/useObject/useObject.tsx +48 -0
- package/src/hooks/usePagination/__doc__/usePagination.stories.tsx +72 -0
- package/src/hooks/usePagination/__test__/usePagination.test.tsx +98 -0
- package/src/hooks/usePagination/index.ts +2 -0
- package/src/hooks/usePagination/usePagination.tsx +74 -0
- package/src/hooks/usePortal/__doc__/usePortal.stories.tsx +19 -0
- package/src/hooks/usePortal/__test__/usePortal.test.tsx +20 -0
- package/src/hooks/usePortal/index.ts +1 -0
- package/src/hooks/usePortal/usePortal.ts +40 -0
- package/src/hooks/usePreventCloseWindow/__doc__/usePreventCloseWindow.stories.tsx +32 -0
- package/src/hooks/usePreventCloseWindow/index.ts +1 -0
- package/src/hooks/usePreventCloseWindow/usePreventCloseWindow.ts +33 -0
- package/src/hooks/useRangePagination/__test__/useRangePagination.test.tsx +63 -0
- package/src/hooks/useRangePagination/index.ts +2 -0
- package/src/hooks/useRangePagination/useRangePagination.tsx +72 -0
- package/src/hooks/useSelection/__doc__/useSelection.stories.tsx +140 -0
- package/src/hooks/useSelection/__test__/useSelection.test.tsx +57 -0
- package/src/hooks/useSelection/index.ts +1 -0
- package/src/hooks/useSelection/useSelection.ts +121 -0
- package/src/hooks/useStep/__doc__/useStep.stories.tsx +98 -0
- package/src/hooks/useStep/__test__/useStep.test.ts +51 -0
- package/src/hooks/useStep/index.ts +1 -0
- package/src/hooks/useStep/useStep.ts +57 -0
- package/src/hooks/useToggle/__doc__/useToggle.stories.tsx +25 -0
- package/src/hooks/useToggle/__test__/useToggle.test.tsx +43 -0
- package/src/hooks/useToggle/index.ts +1 -0
- package/src/hooks/useToggle/useToggle.ts +16 -0
- package/src/index.ts +6 -0
- package/src/lib/cn.ts +8 -0
- package/src/lib/index.ts +1 -0
- package/src/models/Generic.model.ts +67 -0
- package/src/models/index.ts +1 -0
- package/src/providers/index.ts +2 -0
- package/src/providers/library-provider.tsx +44 -0
- package/src/providers/theme/ThemeProvider.tsx +25 -0
- package/src/providers/theme/index.ts +3 -0
- package/src/providers/theme/types.ts +11 -0
- package/src/providers/theme/useThemeProps.ts +25 -0
- package/src/stores/theme.store.ts +31 -0
- package/src/styles/components.css +4 -0
- package/src/styles/index.css +2 -0
- package/src/styles/library.css +2 -0
- package/src/styles/theme.css +232 -0
- package/src/utils/dates/parseDateRange.utility.ts +39 -0
- package/src/utils/form.tsx +91 -0
- package/src/utils/functions/createSafeContext.ts +17 -0
- package/src/utils/functions/ensureReactElement.tsx +30 -0
- package/src/utils/functions/getFormData.ts +19 -0
- package/src/utils/functions/index.ts +4 -0
- package/src/utils/functions/mergeRefs.ts +18 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/strings/extractInitials.utility.ts +10 -0
- package/src/utils/strings/index.ts +1 -0
- package/src/utils/tests/click.ts +3 -0
- package/src/utils/tests/index.ts +2 -0
- package/src/utils/tests/keyboard.ts +21 -0
- package/src/utils/tests/type.ts +6 -0
- package/dist/components.css +0 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { AlertDialog } from "../../components";
|
|
4
|
+
import { click } from "../../utils";
|
|
5
|
+
|
|
6
|
+
describe("AlertDialog component", () => {
|
|
7
|
+
it("should show custom title and description", () => {
|
|
8
|
+
render(
|
|
9
|
+
<AlertDialog
|
|
10
|
+
open
|
|
11
|
+
title="Custom title"
|
|
12
|
+
description="Custom description"
|
|
13
|
+
/>,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(screen.getByText("Custom title")).toBeInTheDocument();
|
|
17
|
+
expect(screen.getByText("Custom description")).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should cancel action", () => {
|
|
21
|
+
const onCancel = vi.fn();
|
|
22
|
+
render(
|
|
23
|
+
<AlertDialog
|
|
24
|
+
open
|
|
25
|
+
title="Custom title"
|
|
26
|
+
description="Custom description"
|
|
27
|
+
onClose={onCancel}
|
|
28
|
+
/>,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
click(screen.getByRole("button", { name: "Cancelar" }));
|
|
32
|
+
expect(onCancel).toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should confirm action", () => {
|
|
36
|
+
const onConfirm = vi.fn();
|
|
37
|
+
render(
|
|
38
|
+
<AlertDialog
|
|
39
|
+
open
|
|
40
|
+
title="Custom title"
|
|
41
|
+
description="Custom description"
|
|
42
|
+
onAction={onConfirm}
|
|
43
|
+
/>,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
click(screen.getByRole("button", { name: "Aceptar" }));
|
|
47
|
+
expect(onConfirm).toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { AlertDialog as AlertDialogBase } from "@base-ui/react/alert-dialog";
|
|
2
|
+
import type { VariantProps } from "class-variance-authority";
|
|
3
|
+
import type { HTMLAttributes, ReactElement, ReactNode } from "react";
|
|
4
|
+
import { cn } from "../../lib";
|
|
5
|
+
import { Button, buttonVariants } from "../button";
|
|
6
|
+
|
|
7
|
+
// ── Primitives ────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
/** Context root. Holds open state and wraps all dialog parts. */
|
|
10
|
+
export function AlertDialogRoot(props: AlertDialogBase.Root.Props) {
|
|
11
|
+
return <AlertDialogBase.Root {...props} />;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Renders as its `render` element (defaults to `<button>`).
|
|
16
|
+
* Because it uses Base UI's render prop — not Radix Slot — it composes cleanly
|
|
17
|
+
* with `<Tooltip>` and other Base UI triggers on the same DOM element.
|
|
18
|
+
*/
|
|
19
|
+
export function AlertDialogTrigger({
|
|
20
|
+
className,
|
|
21
|
+
...props
|
|
22
|
+
}: AlertDialogBase.Trigger.Props) {
|
|
23
|
+
return (
|
|
24
|
+
<AlertDialogBase.Trigger
|
|
25
|
+
data-slot="alert-dialog-trigger"
|
|
26
|
+
className={cn(className)}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Semi-transparent overlay rendered behind the popup. */
|
|
33
|
+
export function AlertDialogBackdrop({
|
|
34
|
+
className,
|
|
35
|
+
...props
|
|
36
|
+
}: AlertDialogBase.Backdrop.Props) {
|
|
37
|
+
return (
|
|
38
|
+
<AlertDialogBase.Backdrop
|
|
39
|
+
data-slot="alert-dialog-backdrop"
|
|
40
|
+
forceRender
|
|
41
|
+
className={cn(
|
|
42
|
+
"fixed inset-0 z-overlay bg-black/50",
|
|
43
|
+
"transition-opacity duration-200",
|
|
44
|
+
"data-starting-style:opacity-0 data-ending-style:opacity-0",
|
|
45
|
+
className,
|
|
46
|
+
)}
|
|
47
|
+
{...props}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Full-screen container that centers the popup. */
|
|
53
|
+
export function AlertDialogViewport({
|
|
54
|
+
className,
|
|
55
|
+
...props
|
|
56
|
+
}: AlertDialogBase.Viewport.Props) {
|
|
57
|
+
return (
|
|
58
|
+
<AlertDialogBase.Viewport
|
|
59
|
+
data-slot="alert-dialog-viewport"
|
|
60
|
+
className={cn(
|
|
61
|
+
"fixed inset-0 z-overlay flex items-center justify-center p-4",
|
|
62
|
+
className,
|
|
63
|
+
)}
|
|
64
|
+
{...props}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Dialog content container. Includes Portal, Backdrop and Viewport internally.
|
|
71
|
+
* Pass `portalProps` to configure the portal (e.g. a custom `container`).
|
|
72
|
+
*/
|
|
73
|
+
export function AlertDialogPopup({
|
|
74
|
+
className,
|
|
75
|
+
portalProps,
|
|
76
|
+
...props
|
|
77
|
+
}: AlertDialogBase.Popup.Props & {
|
|
78
|
+
portalProps?: AlertDialogBase.Portal.Props;
|
|
79
|
+
}) {
|
|
80
|
+
return (
|
|
81
|
+
<AlertDialogBase.Portal {...portalProps}>
|
|
82
|
+
<AlertDialogBackdrop />
|
|
83
|
+
<AlertDialogViewport>
|
|
84
|
+
<AlertDialogBase.Popup
|
|
85
|
+
data-slot="alert-dialog-popup"
|
|
86
|
+
className={cn(
|
|
87
|
+
"relative flex w-full max-w-lg flex-col gap-4 rounded-lg border bg-background p-6 shadow-lg",
|
|
88
|
+
"transition-[scale,opacity] duration-200 ease-out",
|
|
89
|
+
"data-starting-style:scale-95 data-starting-style:opacity-0",
|
|
90
|
+
"data-ending-style:scale-95 data-ending-style:opacity-0",
|
|
91
|
+
className,
|
|
92
|
+
)}
|
|
93
|
+
{...props}
|
|
94
|
+
/>
|
|
95
|
+
</AlertDialogViewport>
|
|
96
|
+
</AlertDialogBase.Portal>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Closes the dialog and merges an optional `onClick` into the `render` element. */
|
|
101
|
+
export function AlertDialogClose({
|
|
102
|
+
className,
|
|
103
|
+
...props
|
|
104
|
+
}: AlertDialogBase.Close.Props) {
|
|
105
|
+
return (
|
|
106
|
+
<AlertDialogBase.Close
|
|
107
|
+
data-slot="alert-dialog-close"
|
|
108
|
+
className={cn(className)}
|
|
109
|
+
{...props}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Accessible title rendered as `<h2>`. Required for a11y. */
|
|
115
|
+
export function AlertDialogTitle({
|
|
116
|
+
className,
|
|
117
|
+
...props
|
|
118
|
+
}: AlertDialogBase.Title.Props) {
|
|
119
|
+
return (
|
|
120
|
+
<AlertDialogBase.Title
|
|
121
|
+
data-slot="alert-dialog-title"
|
|
122
|
+
className={cn(
|
|
123
|
+
"text-lg font-semibold leading-none tracking-tight",
|
|
124
|
+
className,
|
|
125
|
+
)}
|
|
126
|
+
{...props}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Supplementary description rendered below the title. */
|
|
132
|
+
export function AlertDialogDescription({
|
|
133
|
+
className,
|
|
134
|
+
...props
|
|
135
|
+
}: AlertDialogBase.Description.Props) {
|
|
136
|
+
return (
|
|
137
|
+
<AlertDialogBase.Description
|
|
138
|
+
data-slot="alert-dialog-description"
|
|
139
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
140
|
+
{...props}
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Layout wrapper for title and description. */
|
|
146
|
+
export function AlertDialogHeader({
|
|
147
|
+
className,
|
|
148
|
+
...props
|
|
149
|
+
}: HTMLAttributes<HTMLDivElement>) {
|
|
150
|
+
return (
|
|
151
|
+
<div
|
|
152
|
+
data-slot="alert-dialog-header"
|
|
153
|
+
className={cn("flex flex-col gap-2", className)}
|
|
154
|
+
{...props}
|
|
155
|
+
/>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Layout wrapper for action buttons. */
|
|
160
|
+
export function AlertDialogFooter({
|
|
161
|
+
className,
|
|
162
|
+
...props
|
|
163
|
+
}: HTMLAttributes<HTMLDivElement>) {
|
|
164
|
+
return (
|
|
165
|
+
<div
|
|
166
|
+
data-slot="alert-dialog-footer"
|
|
167
|
+
className={cn(
|
|
168
|
+
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
|
169
|
+
className,
|
|
170
|
+
)}
|
|
171
|
+
{...props}
|
|
172
|
+
/>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ── Composite ─────────────────────────────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
export type AlertDialogProps = Omit<AlertDialogBase.Root.Props, "children"> & {
|
|
179
|
+
/** Element that opens the dialog on click. Passed as Base UI `render` prop — no DOM wrapper added. */
|
|
180
|
+
trigger?: ReactElement;
|
|
181
|
+
/** Dialog heading. */
|
|
182
|
+
title?: ReactNode;
|
|
183
|
+
/** Supporting text rendered below the title. */
|
|
184
|
+
description?: ReactNode;
|
|
185
|
+
/** Custom content rendered between the description and the footer buttons. */
|
|
186
|
+
children?: ReactNode;
|
|
187
|
+
/** Called when the cancel button is clicked. */
|
|
188
|
+
onClose?: () => void;
|
|
189
|
+
/** Called when the action button is clicked. */
|
|
190
|
+
onAction?: () => void;
|
|
191
|
+
/** Visual variant for the action button. @default "default" */
|
|
192
|
+
variant?: VariantProps<typeof buttonVariants>["variant"];
|
|
193
|
+
/** Label for the cancel button. @default "Cancel" */
|
|
194
|
+
closeText?: ReactNode;
|
|
195
|
+
/** Label for the action button. @default "Confirm" */
|
|
196
|
+
actionText?: ReactNode;
|
|
197
|
+
/** Additional className forwarded to the popup panel. */
|
|
198
|
+
className?: string;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Accessible confirmation dialog with cancel and action buttons.
|
|
203
|
+
*
|
|
204
|
+
* The `trigger` prop uses Base UI's `render` prop — no wrapper element is added —
|
|
205
|
+
* making it composable with `<Tooltip>` at the primitive level.
|
|
206
|
+
* For full structural control, use the exported primitives directly.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```tsx
|
|
210
|
+
* <AlertDialog
|
|
211
|
+
* trigger={<Button variant="error">Delete account</Button>}
|
|
212
|
+
* title="Delete account?"
|
|
213
|
+
* description="This action cannot be undone."
|
|
214
|
+
* variant="error"
|
|
215
|
+
* actionText="Delete"
|
|
216
|
+
* onAction={handleDelete}
|
|
217
|
+
* />
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export function AlertDialog({
|
|
221
|
+
trigger,
|
|
222
|
+
title,
|
|
223
|
+
description,
|
|
224
|
+
children,
|
|
225
|
+
onClose,
|
|
226
|
+
onAction,
|
|
227
|
+
variant = "default",
|
|
228
|
+
closeText = "Cancel",
|
|
229
|
+
actionText = "Confirm",
|
|
230
|
+
className,
|
|
231
|
+
...props
|
|
232
|
+
}: AlertDialogProps) {
|
|
233
|
+
return (
|
|
234
|
+
<AlertDialogRoot {...props}>
|
|
235
|
+
{trigger && <AlertDialogTrigger render={trigger} />}
|
|
236
|
+
<AlertDialogPopup className={className}>
|
|
237
|
+
{(title || description) && (
|
|
238
|
+
<AlertDialogHeader>
|
|
239
|
+
{title && <AlertDialogTitle>{title}</AlertDialogTitle>}
|
|
240
|
+
{description && (
|
|
241
|
+
<AlertDialogDescription>{description}</AlertDialogDescription>
|
|
242
|
+
)}
|
|
243
|
+
</AlertDialogHeader>
|
|
244
|
+
)}
|
|
245
|
+
{children}
|
|
246
|
+
<AlertDialogFooter>
|
|
247
|
+
<AlertDialogClose
|
|
248
|
+
render={<Button variant="secondary">{closeText}</Button>}
|
|
249
|
+
onClick={onClose}
|
|
250
|
+
/>
|
|
251
|
+
<AlertDialogClose
|
|
252
|
+
render={
|
|
253
|
+
<Button variant={variant ?? "default"}>{actionText}</Button>
|
|
254
|
+
}
|
|
255
|
+
onClick={onAction}
|
|
256
|
+
/>
|
|
257
|
+
</AlertDialogFooter>
|
|
258
|
+
</AlertDialogPopup>
|
|
259
|
+
</AlertDialogRoot>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ── Primitive escape hatch ────────────────────────────────────────────────────
|
|
264
|
+
|
|
265
|
+
export { AlertDialogBase as AlertDialogPrimitive };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./alert-dialog";
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { type DialogProps } from "@radix-ui/react-dialog";
|
|
2
|
+
import { Command } from "cmdk";
|
|
3
|
+
import { Search } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cn } from "../../lib";
|
|
6
|
+
import { DialogPopup, DialogRoot } from "../dialog";
|
|
7
|
+
|
|
8
|
+
const AutoCompleteRoot = ({
|
|
9
|
+
className,
|
|
10
|
+
...props
|
|
11
|
+
}: React.ComponentProps<typeof Command>) => (
|
|
12
|
+
<Command
|
|
13
|
+
data-slot="auto-complete"
|
|
14
|
+
className={cn(
|
|
15
|
+
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
|
16
|
+
className,
|
|
17
|
+
)}
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
interface AutoCompleteDialogProps extends DialogProps {}
|
|
23
|
+
|
|
24
|
+
const AutoCompleteDialog = ({
|
|
25
|
+
children,
|
|
26
|
+
...props
|
|
27
|
+
}: AutoCompleteDialogProps) => {
|
|
28
|
+
return (
|
|
29
|
+
<DialogRoot {...props} data-slot="auto-complete-dialog">
|
|
30
|
+
<DialogPopup
|
|
31
|
+
className="p-0 overflow-hidden shadow-lg"
|
|
32
|
+
data-slot="auto-complete-dialog-content"
|
|
33
|
+
>
|
|
34
|
+
<AutoCompleteRoot className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
|
35
|
+
{children}
|
|
36
|
+
</AutoCompleteRoot>
|
|
37
|
+
</DialogPopup>
|
|
38
|
+
</DialogRoot>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const AutoCompleteInput = ({
|
|
43
|
+
className,
|
|
44
|
+
...props
|
|
45
|
+
}: React.ComponentProps<typeof Command.Input>) => (
|
|
46
|
+
<div
|
|
47
|
+
className="flex items-center px-3 border-b"
|
|
48
|
+
data-slot="auto-complete-input-container"
|
|
49
|
+
>
|
|
50
|
+
<Search
|
|
51
|
+
className="w-4 h-4 mr-2 opacity-50 shrink-0"
|
|
52
|
+
data-slot="auto-complete-input-icon"
|
|
53
|
+
/>
|
|
54
|
+
<Command.Input
|
|
55
|
+
data-slot="auto-complete-input"
|
|
56
|
+
className={cn(
|
|
57
|
+
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
|
58
|
+
className,
|
|
59
|
+
)}
|
|
60
|
+
{...props}
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const AutoCompleteList = ({
|
|
66
|
+
className,
|
|
67
|
+
...props
|
|
68
|
+
}: React.ComponentProps<typeof Command.List>) => (
|
|
69
|
+
<Command.List
|
|
70
|
+
data-slot="auto-complete-list"
|
|
71
|
+
className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
|
|
72
|
+
{...props}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const AutoCompleteEmpty = (
|
|
77
|
+
props: React.ComponentProps<typeof Command.Empty>,
|
|
78
|
+
) => (
|
|
79
|
+
<Command.Empty
|
|
80
|
+
className="py-6 text-sm text-center"
|
|
81
|
+
data-slot="auto-complete-empty"
|
|
82
|
+
{...props}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const AutoCompleteGroup = ({
|
|
87
|
+
className,
|
|
88
|
+
...props
|
|
89
|
+
}: React.ComponentProps<typeof Command.Group>) => (
|
|
90
|
+
<Command.Group
|
|
91
|
+
data-slot="auto-complete-group"
|
|
92
|
+
className={cn(
|
|
93
|
+
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
|
|
94
|
+
className,
|
|
95
|
+
)}
|
|
96
|
+
{...props}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const AutoCompleteSeparator = ({
|
|
101
|
+
className,
|
|
102
|
+
...props
|
|
103
|
+
}: React.ComponentProps<typeof Command.Separator>) => (
|
|
104
|
+
<Command.Separator
|
|
105
|
+
data-slot="auto-complete-separator"
|
|
106
|
+
className={cn("-mx-1 h-px bg-input", className)}
|
|
107
|
+
{...props}
|
|
108
|
+
/>
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const AutoCompleteItem = ({
|
|
112
|
+
className,
|
|
113
|
+
...props
|
|
114
|
+
}: React.ComponentProps<typeof Command.Item>) => {
|
|
115
|
+
return (
|
|
116
|
+
<Command.Item
|
|
117
|
+
data-slot="auto-complete-item"
|
|
118
|
+
className={cn(
|
|
119
|
+
"aria-selected:bg-accent aria-selected:text-accent-foreground",
|
|
120
|
+
"aria-disabled:pointer-events-none aria-disabled:opacity-50",
|
|
121
|
+
"relative flex gap-2 cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none",
|
|
122
|
+
className,
|
|
123
|
+
)}
|
|
124
|
+
{...props}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const AutoCompleteShortcut = ({
|
|
130
|
+
className,
|
|
131
|
+
...props
|
|
132
|
+
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
|
133
|
+
return (
|
|
134
|
+
<span
|
|
135
|
+
data-slot="auto-complete-shortcut"
|
|
136
|
+
className={cn(
|
|
137
|
+
"ml-auto text-xs tracking-widest text-muted-foreground",
|
|
138
|
+
className,
|
|
139
|
+
)}
|
|
140
|
+
{...props}
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
AutoCompleteDialog,
|
|
147
|
+
AutoCompleteEmpty,
|
|
148
|
+
AutoCompleteGroup,
|
|
149
|
+
AutoCompleteInput,
|
|
150
|
+
AutoCompleteItem,
|
|
151
|
+
AutoCompleteList,
|
|
152
|
+
AutoCompleteRoot,
|
|
153
|
+
AutoCompleteSeparator,
|
|
154
|
+
AutoCompleteShortcut,
|
|
155
|
+
};
|