@refraktor/core 0.0.3 → 0.0.4
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/.turbo/turbo-build.log +1 -1
- package/build/components/button/button.styles.js +5 -5
- package/build/components/chip/chip-group/chip-group.d.ts +4 -0
- package/build/components/chip/chip-group/chip-group.d.ts.map +1 -0
- package/build/components/chip/chip-group/chip-group.js +43 -0
- package/build/components/chip/chip-group/index.d.ts +2 -0
- package/build/components/chip/chip-group/index.d.ts.map +1 -0
- package/build/components/chip/chip-group/index.js +1 -0
- package/build/components/chip/chip.context.d.ts +15 -0
- package/build/components/chip/chip.context.d.ts.map +1 -0
- package/build/components/chip/chip.context.js +2 -0
- package/build/components/chip/chip.d.ts +4 -0
- package/build/components/chip/chip.d.ts.map +1 -0
- package/build/components/chip/chip.js +85 -0
- package/build/components/chip/chip.styles.d.ts +5 -0
- package/build/components/chip/chip.styles.d.ts.map +1 -0
- package/build/components/chip/chip.styles.js +19 -0
- package/build/components/chip/chip.test.d.ts +2 -0
- package/build/components/chip/chip.test.d.ts.map +1 -0
- package/build/components/chip/chip.test.js +107 -0
- package/build/components/chip/chip.types.d.ts +95 -0
- package/build/components/chip/chip.types.d.ts.map +1 -0
- package/build/components/chip/chip.types.js +1 -0
- package/build/components/chip/index.d.ts +4 -0
- package/build/components/chip/index.d.ts.map +1 -0
- package/build/components/chip/index.js +2 -0
- package/build/components/combobox/combobox-dropdown/combobox-dropdown.d.ts +4 -0
- package/build/components/combobox/combobox-dropdown/combobox-dropdown.d.ts.map +1 -0
- package/build/components/combobox/combobox-dropdown/combobox-dropdown.js +21 -0
- package/build/components/combobox/combobox-dropdown/index.d.ts +2 -0
- package/build/components/combobox/combobox-dropdown/index.d.ts.map +1 -0
- package/build/components/combobox/combobox-dropdown/index.js +1 -0
- package/build/components/combobox/combobox-group/combobox-group.d.ts +4 -0
- package/build/components/combobox/combobox-group/combobox-group.d.ts.map +1 -0
- package/build/components/combobox/combobox-group/combobox-group.js +15 -0
- package/build/components/combobox/combobox-group/index.d.ts +2 -0
- package/build/components/combobox/combobox-group/index.d.ts.map +1 -0
- package/build/components/combobox/combobox-group/index.js +1 -0
- package/build/components/combobox/combobox-input/combobox-input.d.ts +4 -0
- package/build/components/combobox/combobox-input/combobox-input.d.ts.map +1 -0
- package/build/components/combobox/combobox-input/combobox-input.js +101 -0
- package/build/components/combobox/combobox-input/index.d.ts +2 -0
- package/build/components/combobox/combobox-input/index.d.ts.map +1 -0
- package/build/components/combobox/combobox-input/index.js +1 -0
- package/build/components/combobox/combobox-option/combobox-option.d.ts +4 -0
- package/build/components/combobox/combobox-option/combobox-option.d.ts.map +1 -0
- package/build/components/combobox/combobox-option/combobox-option.js +86 -0
- package/build/components/combobox/combobox-option/index.d.ts +2 -0
- package/build/components/combobox/combobox-option/index.d.ts.map +1 -0
- package/build/components/combobox/combobox-option/index.js +1 -0
- package/build/components/combobox/combobox-root/combobox-root.d.ts +4 -0
- package/build/components/combobox/combobox-root/combobox-root.d.ts.map +1 -0
- package/build/components/combobox/combobox-root/combobox-root.js +282 -0
- package/build/components/combobox/combobox-root/index.d.ts +2 -0
- package/build/components/combobox/combobox-root/index.d.ts.map +1 -0
- package/build/components/combobox/combobox-root/index.js +1 -0
- package/build/components/combobox/combobox.context.d.ts +73 -0
- package/build/components/combobox/combobox.context.d.ts.map +1 -0
- package/build/components/combobox/combobox.context.js +50 -0
- package/build/components/combobox/combobox.d.ts +4 -0
- package/build/components/combobox/combobox.d.ts.map +1 -0
- package/build/components/combobox/combobox.js +31 -0
- package/build/components/combobox/combobox.test.d.ts +2 -0
- package/build/components/combobox/combobox.test.d.ts.map +1 -0
- package/build/components/combobox/combobox.test.js +104 -0
- package/build/components/combobox/combobox.types.d.ts +205 -0
- package/build/components/combobox/combobox.types.d.ts.map +1 -0
- package/build/components/combobox/combobox.types.js +1 -0
- package/build/components/combobox/index.d.ts +8 -0
- package/build/components/combobox/index.d.ts.map +1 -0
- package/build/components/combobox/index.js +6 -0
- package/build/components/combobox/use-combobox.d.ts +32 -0
- package/build/components/combobox/use-combobox.d.ts.map +1 -0
- package/build/components/combobox/use-combobox.js +80 -0
- package/build/components/drawer/drawer-body/drawer-body.d.ts +4 -0
- package/build/components/drawer/drawer-body/drawer-body.d.ts.map +1 -0
- package/build/components/drawer/drawer-body/drawer-body.js +11 -0
- package/build/components/drawer/drawer-body/index.d.ts +2 -0
- package/build/components/drawer/drawer-body/index.d.ts.map +1 -0
- package/build/components/drawer/drawer-body/index.js +1 -0
- package/build/components/drawer/drawer-content/drawer-content.d.ts.map +1 -1
- package/build/components/drawer/drawer-content/drawer-content.js +9 -6
- package/build/components/drawer/drawer-overlay/drawer-overlay.d.ts.map +1 -1
- package/build/components/drawer/drawer-overlay/drawer-overlay.js +4 -4
- package/build/components/drawer/drawer-root/drawer-root.d.ts.map +1 -1
- package/build/components/drawer/drawer-root/drawer-root.js +8 -9
- package/build/components/drawer/drawer.context.d.ts +2 -1
- package/build/components/drawer/drawer.context.d.ts.map +1 -1
- package/build/components/drawer/drawer.d.ts.map +1 -1
- package/build/components/drawer/drawer.js +5 -3
- package/build/components/drawer/drawer.test.js +55 -16
- package/build/components/drawer/drawer.types.d.ts +29 -3
- package/build/components/drawer/drawer.types.d.ts.map +1 -1
- package/build/components/drawer/index.d.ts +2 -1
- package/build/components/drawer/index.d.ts.map +1 -1
- package/build/components/drawer/index.js +1 -0
- package/build/components/drawer/use-drawer.d.ts +8 -1
- package/build/components/drawer/use-drawer.d.ts.map +1 -1
- package/build/components/drawer/use-drawer.js +25 -38
- package/build/components/file-input/file-input.d.ts +4 -0
- package/build/components/file-input/file-input.d.ts.map +1 -0
- package/build/components/file-input/file-input.js +88 -0
- package/build/components/file-input/file-input.test.d.ts +2 -0
- package/build/components/file-input/file-input.test.d.ts.map +1 -0
- package/build/components/file-input/file-input.test.js +74 -0
- package/build/components/file-input/file-input.types.d.ts +46 -0
- package/build/components/file-input/file-input.types.d.ts.map +1 -0
- package/build/components/file-input/file-input.types.js +1 -0
- package/build/components/file-input/file-input.utils.d.ts +11 -0
- package/build/components/file-input/file-input.utils.d.ts.map +1 -0
- package/build/components/file-input/file-input.utils.js +67 -0
- package/build/components/file-input/file-input.utils.test.d.ts +2 -0
- package/build/components/file-input/file-input.utils.test.d.ts.map +1 -0
- package/build/components/file-input/file-input.utils.test.js +27 -0
- package/build/components/file-input/index.d.ts +3 -0
- package/build/components/file-input/index.d.ts.map +1 -0
- package/build/components/file-input/index.js +2 -0
- package/build/components/for/for.d.ts +8 -0
- package/build/components/for/for.d.ts.map +1 -0
- package/build/components/for/for.js +32 -0
- package/build/components/for/for.test.d.ts +2 -0
- package/build/components/for/for.test.d.ts.map +1 -0
- package/build/components/for/for.test.js +31 -0
- package/build/components/for/for.types.d.ts +33 -0
- package/build/components/for/for.types.d.ts.map +1 -0
- package/build/components/for/for.types.js +1 -0
- package/build/components/for/index.d.ts +3 -0
- package/build/components/for/index.d.ts.map +1 -0
- package/build/components/for/index.js +1 -0
- package/build/components/index.d.ts +6 -0
- package/build/components/index.d.ts.map +1 -1
- package/build/components/index.js +6 -0
- package/build/components/modal/index.d.ts +2 -1
- package/build/components/modal/index.d.ts.map +1 -1
- package/build/components/modal/index.js +1 -0
- package/build/components/modal/modal-body/index.d.ts +2 -0
- package/build/components/modal/modal-body/index.d.ts.map +1 -0
- package/build/components/modal/modal-body/index.js +1 -0
- package/build/components/modal/modal-body/modal-body.d.ts +4 -0
- package/build/components/modal/modal-body/modal-body.d.ts.map +1 -0
- package/build/components/modal/modal-body/modal-body.js +11 -0
- package/build/components/modal/modal-content/modal-content.d.ts.map +1 -1
- package/build/components/modal/modal-content/modal-content.js +13 -5
- package/build/components/modal/modal-header/modal-header.js +2 -2
- package/build/components/modal/modal-overlay/modal-overlay.d.ts.map +1 -1
- package/build/components/modal/modal-overlay/modal-overlay.js +4 -4
- package/build/components/modal/modal-root/modal-root.d.ts.map +1 -1
- package/build/components/modal/modal-root/modal-root.js +12 -9
- package/build/components/modal/modal.context.d.ts +5 -2
- package/build/components/modal/modal.context.d.ts.map +1 -1
- package/build/components/modal/modal.d.ts.map +1 -1
- package/build/components/modal/modal.js +5 -3
- package/build/components/modal/modal.test.js +78 -13
- package/build/components/modal/modal.types.d.ts +34 -5
- package/build/components/modal/modal.types.d.ts.map +1 -1
- package/build/components/modal/use-modal.d.ts +8 -1
- package/build/components/modal/use-modal.d.ts.map +1 -1
- package/build/components/modal/use-modal.js +25 -38
- package/build/components/password-input/index.d.ts +3 -0
- package/build/components/password-input/index.d.ts.map +1 -0
- package/build/components/password-input/index.js +2 -0
- package/build/components/password-input/password-input.d.ts +4 -0
- package/build/components/password-input/password-input.d.ts.map +1 -0
- package/build/components/password-input/password-input.js +32 -0
- package/build/components/password-input/password-input.test.d.ts +2 -0
- package/build/components/password-input/password-input.test.d.ts.map +1 -0
- package/build/components/password-input/password-input.test.js +47 -0
- package/build/components/password-input/password-input.types.d.ts +24 -0
- package/build/components/password-input/password-input.types.d.ts.map +1 -0
- package/build/components/password-input/password-input.types.js +1 -0
- package/build/components/pin-input/index.d.ts +3 -0
- package/build/components/pin-input/index.d.ts.map +1 -0
- package/build/components/pin-input/index.js +2 -0
- package/build/components/pin-input/pin-input.d.ts +4 -0
- package/build/components/pin-input/pin-input.d.ts.map +1 -0
- package/build/components/pin-input/pin-input.js +245 -0
- package/build/components/pin-input/pin-input.test.d.ts +2 -0
- package/build/components/pin-input/pin-input.test.d.ts.map +1 -0
- package/build/components/pin-input/pin-input.test.js +87 -0
- package/build/components/pin-input/pin-input.types.d.ts +44 -0
- package/build/components/pin-input/pin-input.types.d.ts.map +1 -0
- package/build/components/pin-input/pin-input.types.js +1 -0
- package/build/components/scroll-area/index.d.ts +3 -0
- package/build/components/scroll-area/index.d.ts.map +1 -0
- package/build/components/scroll-area/index.js +1 -0
- package/build/components/scroll-area/scroll-area.d.ts +4 -0
- package/build/components/scroll-area/scroll-area.d.ts.map +1 -0
- package/build/components/scroll-area/scroll-area.js +30 -0
- package/build/components/scroll-area/scroll-area.test.d.ts +2 -0
- package/build/components/scroll-area/scroll-area.test.d.ts.map +1 -0
- package/build/components/scroll-area/scroll-area.test.js +39 -0
- package/build/components/scroll-area/scroll-area.types.d.ts +25 -0
- package/build/components/scroll-area/scroll-area.types.d.ts.map +1 -0
- package/build/components/scroll-area/scroll-area.types.js +1 -0
- package/build/components/segmented-control/segmented-control.d.ts.map +1 -1
- package/build/components/segmented-control/segmented-control.js +3 -3
- package/build/components/segmented-control/segmented-control.styles.js +13 -13
- package/build/components/segmented-control/segmented-control.test.js +11 -0
- package/build/components/segmented-control/segmented-control.types.d.ts +2 -0
- package/build/components/segmented-control/segmented-control.types.d.ts.map +1 -1
- package/build/icons/eye-off.d.ts +4 -0
- package/build/icons/eye-off.d.ts.map +1 -0
- package/build/icons/eye-off.js +5 -0
- package/build/icons/eye.d.ts +4 -0
- package/build/icons/eye.d.ts.map +1 -0
- package/build/icons/eye.js +5 -0
- package/build/icons/index.d.ts +2 -0
- package/build/icons/index.d.ts.map +1 -1
- package/build/icons/index.js +2 -0
- package/build/style.css +1 -1
- package/package.json +2 -2
- package/src/components/button/button.styles.ts +5 -5
- package/src/components/chip/chip-group/chip-group.tsx +107 -0
- package/src/components/chip/chip-group/index.ts +1 -0
- package/src/components/chip/chip.context.ts +15 -0
- package/src/components/chip/chip.styles.ts +36 -0
- package/src/components/chip/chip.test.tsx +197 -0
- package/src/components/chip/chip.tsx +208 -0
- package/src/components/chip/chip.types.ts +134 -0
- package/src/components/chip/index.ts +10 -0
- package/src/components/drawer/drawer-body/drawer-body.tsx +29 -0
- package/src/components/drawer/drawer-body/index.ts +1 -0
- package/src/components/drawer/drawer-content/drawer-content.tsx +63 -26
- package/src/components/drawer/drawer-overlay/drawer-overlay.tsx +6 -5
- package/src/components/drawer/drawer-root/drawer-root.tsx +17 -18
- package/src/components/drawer/drawer.context.ts +2 -1
- package/src/components/drawer/drawer.test.tsx +144 -36
- package/src/components/drawer/drawer.tsx +31 -3
- package/src/components/drawer/drawer.types.ts +37 -3
- package/src/components/drawer/index.ts +2 -0
- package/src/components/drawer/use-drawer.ts +44 -51
- package/src/components/file-input/file-input.test.tsx +134 -0
- package/src/components/file-input/file-input.tsx +224 -0
- package/src/components/file-input/file-input.types.ts +78 -0
- package/src/components/file-input/file-input.utils.test.ts +36 -0
- package/src/components/file-input/file-input.utils.ts +130 -0
- package/src/components/file-input/index.ts +2 -0
- package/src/components/for/for.test.tsx +66 -0
- package/src/components/for/for.tsx +53 -0
- package/src/components/for/for.types.ts +40 -0
- package/src/components/for/index.ts +2 -0
- package/src/components/index.ts +6 -0
- package/src/components/menu/menu-dropdown/menu-dropdown.tsx +220 -220
- package/src/components/menu/menu-sub-dropdown/menu-sub-dropdown.tsx +221 -221
- package/src/components/modal/index.ts +4 -1
- package/src/components/modal/modal-body/index.ts +1 -0
- package/src/components/modal/modal-body/modal-body.tsx +29 -0
- package/src/components/modal/modal-content/modal-content.tsx +71 -24
- package/src/components/modal/modal-header/modal-header.tsx +2 -2
- package/src/components/modal/modal-overlay/modal-overlay.tsx +46 -45
- package/src/components/modal/modal-root/modal-root.tsx +22 -17
- package/src/components/modal/modal.context.ts +5 -2
- package/src/components/modal/modal.test.tsx +234 -64
- package/src/components/modal/modal.tsx +36 -4
- package/src/components/modal/modal.types.ts +49 -8
- package/src/components/modal/use-modal.ts +44 -51
- package/src/components/password-input/index.ts +2 -0
- package/src/components/password-input/password-input.test.tsx +72 -0
- package/src/components/password-input/password-input.tsx +85 -0
- package/src/components/password-input/password-input.types.ts +30 -0
- package/src/components/pin-input/index.ts +2 -0
- package/src/components/pin-input/pin-input.test.tsx +149 -0
- package/src/components/pin-input/pin-input.tsx +473 -0
- package/src/components/pin-input/pin-input.types.ts +78 -0
- package/src/components/scroll-area/index.ts +6 -0
- package/src/components/scroll-area/scroll-area.test.tsx +72 -0
- package/src/components/scroll-area/scroll-area.tsx +70 -0
- package/src/components/scroll-area/scroll-area.types.ts +37 -0
- package/src/components/segmented-control/segmented-control.styles.ts +13 -13
- package/src/components/segmented-control/segmented-control.test.tsx +18 -0
- package/src/components/segmented-control/segmented-control.tsx +11 -1
- package/src/components/segmented-control/segmented-control.types.ts +3 -0
- package/src/components/select/select-dropdown/select-dropdown.tsx +299 -299
- package/src/components/select/select-root/select-root.tsx +333 -333
- package/src/components/select/select-trigger/select-trigger.tsx +123 -123
- package/src/components/select/select.context.ts +140 -140
- package/src/components/select/select.test.tsx +190 -190
- package/src/components/select/select.types.ts +272 -272
- package/src/components/select/use-select.ts +170 -170
- package/src/icons/eye-off.tsx +30 -0
- package/src/icons/eye.tsx +24 -0
- package/src/icons/index.ts +2 -0
- package/src/style.css +14 -8
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { render, screen, userEvent } from "../../vitest";
|
|
4
|
+
import FileInput from "./file-input";
|
|
5
|
+
const createFile = (name, type, size) => new File([new Uint8Array(size)], name, { type });
|
|
6
|
+
describe("@refraktor/core/FileInput", () => {
|
|
7
|
+
it("supports input wrapper props", async () => {
|
|
8
|
+
await render(_jsx(FileInput, { label: "Documents", description: "Upload PDF files", error: "At least one file is required" }));
|
|
9
|
+
const input = screen.getByLabelText("Documents");
|
|
10
|
+
expect(input).toHaveAttribute("type", "file");
|
|
11
|
+
expect(input).toHaveAttribute("aria-invalid", "true");
|
|
12
|
+
expect(screen.getByText("Upload PDF files")).toBeInTheDocument();
|
|
13
|
+
expect(screen.getByText("At least one file is required")).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
it("handles single file selection", async () => {
|
|
16
|
+
const user = userEvent.setup();
|
|
17
|
+
const onChange = vi.fn();
|
|
18
|
+
await render(_jsx(FileInput, { label: "Upload", onChange: onChange }));
|
|
19
|
+
const input = screen.getByLabelText("Upload");
|
|
20
|
+
const file = new File(["hello"], "hello.txt", { type: "text/plain" });
|
|
21
|
+
await user.upload(input, file);
|
|
22
|
+
expect(onChange).toHaveBeenLastCalledWith([file]);
|
|
23
|
+
expect(screen.getByText("hello.txt")).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
it("enforces max files in multiple mode", async () => {
|
|
26
|
+
const user = userEvent.setup({ applyAccept: false });
|
|
27
|
+
const onChange = vi.fn();
|
|
28
|
+
const onReject = vi.fn();
|
|
29
|
+
await render(_jsx(FileInput, { label: "Attachments", multiple: true, maxFiles: 2, onChange: onChange, onReject: onReject }));
|
|
30
|
+
const input = screen.getByLabelText("Attachments");
|
|
31
|
+
const first = createFile("first.txt", "text/plain", 2);
|
|
32
|
+
const second = createFile("second.txt", "text/plain", 3);
|
|
33
|
+
const third = createFile("third.txt", "text/plain", 4);
|
|
34
|
+
await user.upload(input, [first, second, third]);
|
|
35
|
+
expect(onChange).toHaveBeenLastCalledWith([first, second]);
|
|
36
|
+
expect(onReject).toHaveBeenCalledWith(expect.arrayContaining([
|
|
37
|
+
expect.objectContaining({
|
|
38
|
+
file: third,
|
|
39
|
+
code: "too-many-files"
|
|
40
|
+
})
|
|
41
|
+
]));
|
|
42
|
+
});
|
|
43
|
+
it("rejects invalid type and invalid size files", async () => {
|
|
44
|
+
const user = userEvent.setup();
|
|
45
|
+
const onChange = vi.fn();
|
|
46
|
+
const onReject = vi.fn();
|
|
47
|
+
await render(_jsx(FileInput, { label: "Media", multiple: true, accept: "image/*,.pdf", minSize: 2, maxSize: 4, onChange: onChange, onReject: onReject }));
|
|
48
|
+
const input = screen.getByLabelText("Media");
|
|
49
|
+
const valid = createFile("photo.png", "image/png", 3);
|
|
50
|
+
const invalidType = createFile("script.js", "application/javascript", 3);
|
|
51
|
+
const tooSmall = createFile("tiny.png", "image/png", 1);
|
|
52
|
+
const tooLarge = createFile("large.pdf", "application/pdf", 6);
|
|
53
|
+
await user.upload(input, [valid, invalidType, tooSmall, tooLarge]);
|
|
54
|
+
expect(onChange).toHaveBeenLastCalledWith([valid]);
|
|
55
|
+
const rejectionPayload = onReject.mock.calls[onReject.mock.calls.length - 1]?.[0] ?? [];
|
|
56
|
+
const rejectionCodes = rejectionPayload.map((item) => item.code);
|
|
57
|
+
expect(rejectionCodes).toEqual(expect.arrayContaining([
|
|
58
|
+
"file-too-small",
|
|
59
|
+
"file-too-large"
|
|
60
|
+
]));
|
|
61
|
+
});
|
|
62
|
+
it("clears selected files", async () => {
|
|
63
|
+
const user = userEvent.setup();
|
|
64
|
+
const onChange = vi.fn();
|
|
65
|
+
await render(_jsx(FileInput, { label: "Receipt", onChange: onChange }));
|
|
66
|
+
const input = screen.getByLabelText("Receipt");
|
|
67
|
+
const file = createFile("receipt.pdf", "application/pdf", 3);
|
|
68
|
+
await user.upload(input, file);
|
|
69
|
+
const clearButton = screen.getByRole("button", { name: "Clear file" });
|
|
70
|
+
await user.click(clearButton);
|
|
71
|
+
expect(onChange).toHaveBeenLastCalledWith([]);
|
|
72
|
+
expect(screen.getByText("Select file")).toBeInTheDocument();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createClassNamesConfig, createComponentConfig, FactoryPayload } from "../../utils";
|
|
2
|
+
import type { InputProps } from "../input";
|
|
3
|
+
export type FileInputRejectCode = "invalid-type" | "file-too-large" | "file-too-small" | "too-many-files";
|
|
4
|
+
export interface FileInputRejection {
|
|
5
|
+
/** Rejected file */
|
|
6
|
+
file: File;
|
|
7
|
+
/** Rejection reason code */
|
|
8
|
+
code: FileInputRejectCode;
|
|
9
|
+
/** Human-readable rejection reason */
|
|
10
|
+
message: string;
|
|
11
|
+
}
|
|
12
|
+
export type FileInputClassNames = {
|
|
13
|
+
root?: string;
|
|
14
|
+
trigger?: string;
|
|
15
|
+
value?: string;
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
files?: string;
|
|
18
|
+
clear?: string;
|
|
19
|
+
};
|
|
20
|
+
export interface FileInputProps extends Omit<InputProps, "type" | "value" | "defaultValue" | "onChange" | "leftSection" | "rightSection"> {
|
|
21
|
+
/** Placeholder shown when no files are selected */
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
/** Whether to show clear button when value exists @default `true` */
|
|
24
|
+
clearable?: boolean;
|
|
25
|
+
/** Maximum allowed file size in bytes */
|
|
26
|
+
maxSize?: number;
|
|
27
|
+
/** Minimum allowed file size in bytes */
|
|
28
|
+
minSize?: number;
|
|
29
|
+
/** Maximum allowed number of files */
|
|
30
|
+
maxFiles?: number;
|
|
31
|
+
/** Callback called with accepted files */
|
|
32
|
+
onChange?: (files: File[]) => void;
|
|
33
|
+
/** Callback called with rejected files */
|
|
34
|
+
onReject?: (rejections: FileInputRejection[]) => void;
|
|
35
|
+
/** Used for styling different parts of the component */
|
|
36
|
+
classNames?: FileInputClassNames;
|
|
37
|
+
}
|
|
38
|
+
export interface FileInputFactoryPayload extends FactoryPayload {
|
|
39
|
+
props: FileInputProps;
|
|
40
|
+
ref: HTMLInputElement;
|
|
41
|
+
compound: {
|
|
42
|
+
configure: ReturnType<typeof createComponentConfig<FileInputProps>>;
|
|
43
|
+
classNames: ReturnType<typeof createClassNamesConfig<FileInputClassNames>>;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=file-input.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-input.types.d.ts","sourceRoot":"","sources":["../../../src/components/file-input/file-input.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GACzB,cAAc,GACd,gBAAgB,GAChB,gBAAgB,GAChB,gBAAgB,CAAC;AAEvB,MAAM,WAAW,kBAAkB;IAC/B,oBAAoB;IACpB,IAAI,EAAE,IAAI,CAAC;IAEX,4BAA4B;IAC5B,IAAI,EAAE,mBAAmB,CAAC;IAE1B,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,mBAAmB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,cACb,SAAQ,IAAI,CACR,UAAU,EACR,MAAM,GACN,OAAO,GACP,cAAc,GACd,UAAU,GACV,aAAa,GACb,cAAc,CACnB;IACD,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,qEAAqE;IACrE,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IAEnC,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IAEtD,wDAAwD;IACxD,UAAU,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC3D,KAAK,EAAE,cAAc,CAAC;IACtB,GAAG,EAAE,gBAAgB,CAAC;IACtB,QAAQ,EAAE;QACN,SAAS,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,cAAc,CAAC,CAAC,CAAC;QACpE,UAAU,EAAE,UAAU,CAClB,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,CACrD,CAAC;KACL,CAAC;CACL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileInputRejection, FileInputProps } from "./file-input.types";
|
|
2
|
+
type ValidationOptions = Pick<FileInputProps, "accept" | "maxFiles" | "maxSize" | "minSize" | "multiple">;
|
|
3
|
+
type ValidationResult = {
|
|
4
|
+
accepted: File[];
|
|
5
|
+
rejections: FileInputRejection[];
|
|
6
|
+
};
|
|
7
|
+
export declare const matchesAccept: (file: File, accept?: string) => boolean;
|
|
8
|
+
export declare const validateFiles: (files: File[], { accept, minSize, maxSize, maxFiles, multiple }: ValidationOptions) => ValidationResult;
|
|
9
|
+
export declare const formatFileSummary: (files: File[]) => string;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=file-input.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-input.utils.d.ts","sourceRoot":"","sources":["../../../src/components/file-input/file-input.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,kBAAkB,EAClB,cAAc,EACjB,MAAM,oBAAoB,CAAC;AAE5B,KAAK,iBAAiB,GAAG,IAAI,CACzB,cAAc,EACd,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAC7D,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACpB,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjB,UAAU,EAAE,kBAAkB,EAAE,CAAC;CACpC,CAAC;AAQF,eAAO,MAAM,aAAa,GAAI,MAAM,IAAI,EAAE,SAAS,MAAM,KAAG,OAgC3D,CAAC;AAEF,eAAO,MAAM,aAAa,GACtB,OAAO,IAAI,EAAE,EACb,kDAAkD,iBAAiB,KACpE,gBA0DF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,OAAO,IAAI,EAAE,KAAG,MAUjD,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const createRejection = (file, code, message) => ({ file, code, message });
|
|
2
|
+
export const matchesAccept = (file, accept) => {
|
|
3
|
+
if (!accept) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
const tokens = accept
|
|
7
|
+
.split(",")
|
|
8
|
+
.map((token) => token.trim().toLowerCase())
|
|
9
|
+
.filter(Boolean);
|
|
10
|
+
if (tokens.length === 0) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
const fileType = file.type.toLowerCase();
|
|
14
|
+
const fileName = file.name.toLowerCase();
|
|
15
|
+
return tokens.some((token) => {
|
|
16
|
+
if (token === "*/*") {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (token.startsWith(".")) {
|
|
20
|
+
return fileName.endsWith(token);
|
|
21
|
+
}
|
|
22
|
+
if (token.endsWith("/*")) {
|
|
23
|
+
return fileType.startsWith(token.slice(0, -1));
|
|
24
|
+
}
|
|
25
|
+
return fileType === token;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
export const validateFiles = (files, { accept, minSize, maxSize, maxFiles, multiple }) => {
|
|
29
|
+
const accepted = [];
|
|
30
|
+
const rejections = [];
|
|
31
|
+
const isMinSizeDefined = typeof minSize === "number" && minSize >= 0;
|
|
32
|
+
const isMaxSizeDefined = typeof maxSize === "number" && maxSize >= 0;
|
|
33
|
+
const maxAllowedFiles = typeof maxFiles === "number"
|
|
34
|
+
? Math.max(0, Math.floor(maxFiles))
|
|
35
|
+
: multiple
|
|
36
|
+
? Number.POSITIVE_INFINITY
|
|
37
|
+
: 1;
|
|
38
|
+
files.forEach((file, index) => {
|
|
39
|
+
if (index >= maxAllowedFiles) {
|
|
40
|
+
rejections.push(createRejection(file, "too-many-files", `Only ${maxAllowedFiles} file${maxAllowedFiles === 1 ? "" : "s"} allowed`));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!matchesAccept(file, accept)) {
|
|
44
|
+
rejections.push(createRejection(file, "invalid-type", "File type is not allowed"));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (isMinSizeDefined && file.size < minSize) {
|
|
48
|
+
rejections.push(createRejection(file, "file-too-small", `File is smaller than ${minSize} bytes`));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (isMaxSizeDefined && file.size > maxSize) {
|
|
52
|
+
rejections.push(createRejection(file, "file-too-large", `File exceeds ${maxSize} bytes`));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
accepted.push(file);
|
|
56
|
+
});
|
|
57
|
+
return { accepted, rejections };
|
|
58
|
+
};
|
|
59
|
+
export const formatFileSummary = (files) => {
|
|
60
|
+
if (files.length === 0) {
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
if (files.length === 1) {
|
|
64
|
+
return files[0].name;
|
|
65
|
+
}
|
|
66
|
+
return `${files.length} files selected`;
|
|
67
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-input.utils.test.d.ts","sourceRoot":"","sources":["../../../src/components/file-input/file-input.utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { matchesAccept, validateFiles } from "./file-input.utils";
|
|
3
|
+
const createFile = (name, type, size) => new File([new Uint8Array(size)], name, { type });
|
|
4
|
+
describe("@refraktor/core/FileInput utils", () => {
|
|
5
|
+
it("matches files against accept rules", () => {
|
|
6
|
+
const image = createFile("avatar.png", "image/png", 3);
|
|
7
|
+
const pdf = createFile("sheet.pdf", "application/pdf", 3);
|
|
8
|
+
expect(matchesAccept(image, "image/*")).toBe(true);
|
|
9
|
+
expect(matchesAccept(pdf, "image/*")).toBe(false);
|
|
10
|
+
expect(matchesAccept(pdf, ".pdf")).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
it("rejects invalid file types", () => {
|
|
13
|
+
const image = createFile("avatar.png", "image/png", 3);
|
|
14
|
+
const script = createFile("script.js", "application/javascript", 3);
|
|
15
|
+
const result = validateFiles([image, script], {
|
|
16
|
+
multiple: true,
|
|
17
|
+
accept: "image/*"
|
|
18
|
+
});
|
|
19
|
+
expect(result.accepted).toEqual([image]);
|
|
20
|
+
expect(result.rejections).toEqual(expect.arrayContaining([
|
|
21
|
+
expect.objectContaining({
|
|
22
|
+
file: script,
|
|
23
|
+
code: "invalid-type"
|
|
24
|
+
})
|
|
25
|
+
]));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/file-input/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import type { ForProps } from "./for.types";
|
|
3
|
+
declare const For: {
|
|
4
|
+
<T>({ each, children, fallback, keyExtractor }: ForProps<T>): JSX.Element | null;
|
|
5
|
+
displayName: string;
|
|
6
|
+
};
|
|
7
|
+
export default For;
|
|
8
|
+
//# sourceMappingURL=for.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"for.d.ts","sourceRoot":"","sources":["../../../src/components/for/for.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAc5C,QAAA,MAAM,GAAG;KAAI,CAAC,8CAKX,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI;;CA2BlC,CAAC;AAIF,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
const normalize = (collection) => {
|
|
4
|
+
if (!collection) {
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
7
|
+
if (Array.isArray(collection)) {
|
|
8
|
+
return collection.slice();
|
|
9
|
+
}
|
|
10
|
+
return Array.from(collection);
|
|
11
|
+
};
|
|
12
|
+
const For = ({ each, children, fallback = null, keyExtractor }) => {
|
|
13
|
+
const items = normalize(each);
|
|
14
|
+
if (items.length === 0) {
|
|
15
|
+
return fallback === null ? null : _jsx(_Fragment, { children: fallback });
|
|
16
|
+
}
|
|
17
|
+
const lastIndex = items.length - 1;
|
|
18
|
+
return (_jsx(_Fragment, { children: items.map((item, index) => {
|
|
19
|
+
const meta = {
|
|
20
|
+
index,
|
|
21
|
+
length: items.length,
|
|
22
|
+
isFirst: index === 0,
|
|
23
|
+
isLast: index === lastIndex,
|
|
24
|
+
previous: index > 0 ? items[index - 1] : undefined,
|
|
25
|
+
next: index < lastIndex ? items[index + 1] : undefined
|
|
26
|
+
};
|
|
27
|
+
const key = keyExtractor?.(item, index) ?? index;
|
|
28
|
+
return _jsx(Fragment, { children: children(item, meta) }, key);
|
|
29
|
+
}) }));
|
|
30
|
+
};
|
|
31
|
+
For.displayName = "@refraktor/core/For";
|
|
32
|
+
export default For;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"for.test.d.ts","sourceRoot":"","sources":["../../../src/components/for/for.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { render, screen } from "../../vitest";
|
|
4
|
+
import For from "./for";
|
|
5
|
+
describe("@refraktor/core/For", () => {
|
|
6
|
+
it("renders fallback for empty collections", async () => {
|
|
7
|
+
const children = vi.fn(() => _jsx("span", { children: "Should not render" }));
|
|
8
|
+
await render(_jsx(For, { each: [], fallback: _jsx("span", { children: "No items" }), children: children }));
|
|
9
|
+
expect(screen.getByText("No items")).toBeInTheDocument();
|
|
10
|
+
expect(children).not.toHaveBeenCalled();
|
|
11
|
+
});
|
|
12
|
+
it("renders nothing when collection is empty and fallback is not set", async () => {
|
|
13
|
+
const { container } = await render(_jsx(For, { each: [], children: () => _jsx("span", { children: "Should not render" }) }));
|
|
14
|
+
expect(container).toBeEmptyDOMElement();
|
|
15
|
+
});
|
|
16
|
+
it("passes item metadata to children", async () => {
|
|
17
|
+
await render(_jsx(For, { each: ["alpha", "beta", "gamma"], children: (item, meta) => (_jsxs("div", { "data-testid": item, children: [item, ":", meta.index, ":", meta.length, ":", String(meta.isFirst), ":", String(meta.isLast), ":", meta.previous ?? "none", ":", meta.next ?? "none"] })) }));
|
|
18
|
+
expect(screen.getByTestId("alpha")).toHaveTextContent("alpha:0:3:true:false:none:beta");
|
|
19
|
+
expect(screen.getByTestId("beta")).toHaveTextContent("beta:1:3:false:false:alpha:gamma");
|
|
20
|
+
expect(screen.getByTestId("gamma")).toHaveTextContent("gamma:2:3:false:true:beta:none");
|
|
21
|
+
});
|
|
22
|
+
it("supports iterable collections and calls key extractor", async () => {
|
|
23
|
+
const values = new Set(["one", "two"]);
|
|
24
|
+
const keyExtractor = vi.fn((item) => item);
|
|
25
|
+
await render(_jsx(For, { each: values, keyExtractor: keyExtractor, children: (item) => _jsx("span", { children: item }) }));
|
|
26
|
+
expect(screen.getByText("one")).toBeInTheDocument();
|
|
27
|
+
expect(screen.getByText("two")).toBeInTheDocument();
|
|
28
|
+
expect(keyExtractor).toHaveBeenNthCalledWith(1, "one", 0);
|
|
29
|
+
expect(keyExtractor).toHaveBeenNthCalledWith(2, "two", 1);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Key, ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Supported collections for the For component. Accepts arrays, array-likes and iterables.
|
|
4
|
+
*/
|
|
5
|
+
export type ForList<T> = readonly T[] | Iterable<T> | ArrayLike<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Metadata passed to the render function for each item in the collection.
|
|
8
|
+
*/
|
|
9
|
+
export type ForRenderMeta<T> = {
|
|
10
|
+
/** Index of the current item in the collection. */
|
|
11
|
+
index: number;
|
|
12
|
+
/** Total number of items in the collection. */
|
|
13
|
+
length: number;
|
|
14
|
+
/** Indicates whether the current item is the first in the collection. */
|
|
15
|
+
isFirst: boolean;
|
|
16
|
+
/** Indicates whether the current item is the last in the collection. */
|
|
17
|
+
isLast: boolean;
|
|
18
|
+
/** Previous item in the collection if it exists. */
|
|
19
|
+
previous?: T;
|
|
20
|
+
/** Next item in the collection if it exists. */
|
|
21
|
+
next?: T;
|
|
22
|
+
};
|
|
23
|
+
export type ForProps<T> = {
|
|
24
|
+
/** Collection that should be iterated. */
|
|
25
|
+
each?: ForList<T> | null;
|
|
26
|
+
/** Render function that receives the current item and helpful metadata. */
|
|
27
|
+
children: (item: T, meta: ForRenderMeta<T>) => ReactNode;
|
|
28
|
+
/** Node rendered when the collection is empty. */
|
|
29
|
+
fallback?: ReactNode;
|
|
30
|
+
/** Optional function to derive a stable React key for each item. */
|
|
31
|
+
keyExtractor?: (item: T, index: number) => Key;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=for.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"for.types.d.ts","sourceRoot":"","sources":["../../../src/components/for/for.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,SAAS,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC3B,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IAEd,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IAEf,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;IAEjB,wEAAwE;IACxE,MAAM,EAAE,OAAO,CAAC;IAEhB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEb,gDAAgD;IAChD,IAAI,CAAC,EAAE,CAAC,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACtB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;IACzD,kDAAkD;IAClD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,oEAAoE;IACpE,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;CAClD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/for/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC;AACvC,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as For } from "./for";
|
|
@@ -4,19 +4,25 @@ export * from "./badge";
|
|
|
4
4
|
export * from "./breadcrumbs";
|
|
5
5
|
export * from "./button";
|
|
6
6
|
export * from "./checkbox";
|
|
7
|
+
export * from "./chip";
|
|
7
8
|
export * from "./color-swatch";
|
|
8
9
|
export * from "./drawer";
|
|
10
|
+
export * from "./file-input";
|
|
11
|
+
export * from "./for";
|
|
9
12
|
export * from "./input";
|
|
10
13
|
export * from "./loader";
|
|
11
14
|
export * from "./modal";
|
|
12
15
|
export * from "./menu";
|
|
13
16
|
export * from "./number-input";
|
|
17
|
+
export * from "./password-input";
|
|
18
|
+
export * from "./pin-input";
|
|
14
19
|
export * from "./pagination";
|
|
15
20
|
export * from "./popover";
|
|
16
21
|
export * from "./portal";
|
|
17
22
|
export * from "./progress";
|
|
18
23
|
export * from "./progress-circle";
|
|
19
24
|
export * from "./radio";
|
|
25
|
+
export * from "./scroll-area";
|
|
20
26
|
export * from "./select";
|
|
21
27
|
export * from "./segmented-control";
|
|
22
28
|
export * from "./slider";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
@@ -4,19 +4,25 @@ export * from "./badge";
|
|
|
4
4
|
export * from "./breadcrumbs";
|
|
5
5
|
export * from "./button";
|
|
6
6
|
export * from "./checkbox";
|
|
7
|
+
export * from "./chip";
|
|
7
8
|
export * from "./color-swatch";
|
|
8
9
|
export * from "./drawer";
|
|
10
|
+
export * from "./file-input";
|
|
11
|
+
export * from "./for";
|
|
9
12
|
export * from "./input";
|
|
10
13
|
export * from "./loader";
|
|
11
14
|
export * from "./modal";
|
|
12
15
|
export * from "./menu";
|
|
13
16
|
export * from "./number-input";
|
|
17
|
+
export * from "./password-input";
|
|
18
|
+
export * from "./pin-input";
|
|
14
19
|
export * from "./pagination";
|
|
15
20
|
export * from "./popover";
|
|
16
21
|
export * from "./portal";
|
|
17
22
|
export * from "./progress";
|
|
18
23
|
export * from "./progress-circle";
|
|
19
24
|
export * from "./radio";
|
|
25
|
+
export * from "./scroll-area";
|
|
20
26
|
export * from "./select";
|
|
21
27
|
export * from "./segmented-control";
|
|
22
28
|
export * from "./slider";
|
|
@@ -3,6 +3,7 @@ export { ModalRoot } from "./modal-root";
|
|
|
3
3
|
export { ModalOverlay } from "./modal-overlay";
|
|
4
4
|
export { ModalContent } from "./modal-content";
|
|
5
5
|
export { ModalHeader } from "./modal-header";
|
|
6
|
+
export { ModalBody } from "./modal-body";
|
|
6
7
|
export { ModalClose } from "./modal-close";
|
|
7
|
-
export type { ModalProps, ModalRootProps, ModalOverlayProps, ModalContentProps, ModalHeaderProps, ModalCloseProps, ModalClassNames } from "./modal.types";
|
|
8
|
+
export type { ModalProps, ModalRootProps, ModalOverlayProps, ModalContentProps, ModalHeaderProps, ModalBodyProps, ModalCloseProps, ModalClassNames, ModalSize } from "./modal.types";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/modal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACR,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/modal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACR,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,eAAe,EACf,SAAS,EACZ,MAAM,eAAe,CAAC"}
|
|
@@ -3,4 +3,5 @@ export { ModalRoot } from "./modal-root";
|
|
|
3
3
|
export { ModalOverlay } from "./modal-overlay";
|
|
4
4
|
export { ModalContent } from "./modal-content";
|
|
5
5
|
export { ModalHeader } from "./modal-header";
|
|
6
|
+
export { ModalBody } from "./modal-body";
|
|
6
7
|
export { ModalClose } from "./modal-close";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/modal-body/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ModalBody } from "./modal-body";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal-body.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/modal-body/modal-body.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,QAAA,MAAM,SAAS,gEAmBd,CAAC;AAIF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from "../../../theme";
|
|
3
|
+
import { factory } from "../../../utils";
|
|
4
|
+
import { useModalContext } from "../modal.context";
|
|
5
|
+
const ModalBody = factory(({ children, className, ...props }, ref) => {
|
|
6
|
+
const { cx } = useTheme();
|
|
7
|
+
const { getStyles } = useModalContext();
|
|
8
|
+
return (_jsx("div", { ref: ref, className: cx("overflow-y-auto", getStyles("body"), className), ...props, children: children }));
|
|
9
|
+
});
|
|
10
|
+
ModalBody.displayName = "@refraktor/core/Modal.Body";
|
|
11
|
+
export default ModalBody;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal-content.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/modal-content/modal-content.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"modal-content.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/modal-content/modal-content.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,0BAA0B,EAAa,MAAM,gBAAgB,CAAC;AAWvE,QAAA,MAAM,YAAY,mEA+FjB,CAAC;AAIF,eAAe,YAAY,CAAC"}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FloatingFocusManager, FloatingPortal } from "@floating-ui/react";
|
|
2
3
|
import { useTheme } from "../../../theme";
|
|
3
4
|
import { factory } from "../../../utils";
|
|
4
|
-
import { Portal } from "../../portal";
|
|
5
5
|
import { Transition } from "../../transition";
|
|
6
6
|
import { useModalContext } from "../modal.context";
|
|
7
|
+
const sizeClasses = {
|
|
8
|
+
xs: "max-w-xs",
|
|
9
|
+
sm: "max-w-sm",
|
|
10
|
+
md: "max-w-md",
|
|
11
|
+
lg: "max-w-lg",
|
|
12
|
+
xl: "max-w-xl",
|
|
13
|
+
full: "max-w-full"
|
|
14
|
+
};
|
|
7
15
|
const ModalContent = factory(({ children, className, style, ...props }, ref) => {
|
|
8
16
|
const { cx, getRadius } = useTheme();
|
|
9
|
-
const { modal, withinPortal, radius, transitionProps, headerId,
|
|
17
|
+
const { modal, withinPortal, radius, size, centered, trapFocus, returnFocus, transitionProps, headerId, getStyles } = useModalContext();
|
|
10
18
|
const setRefs = (node) => {
|
|
11
|
-
|
|
19
|
+
modal.refs.setFloating(node);
|
|
12
20
|
if (typeof ref === "function") {
|
|
13
21
|
ref(node);
|
|
14
22
|
}
|
|
@@ -17,8 +25,8 @@ const ModalContent = factory(({ children, className, style, ...props }, ref) =>
|
|
|
17
25
|
}
|
|
18
26
|
};
|
|
19
27
|
const { className: transitionClassName, ...resolvedTransitionProps } = transitionProps ?? {};
|
|
20
|
-
const content = (_jsx(Transition, { transition: "scale", duration: 150, mounted: modal.opened, ...resolvedTransitionProps, className: cx("fixed inset-0 z-50 grid place-items-center
|
|
21
|
-
return withinPortal ? _jsx(
|
|
28
|
+
const content = (_jsx(Transition, { transition: "scale", duration: 150, mounted: modal.opened, ...resolvedTransitionProps, className: cx("fixed inset-0 z-50 grid pointer-events-none", centered ? "place-items-center" : "items-start justify-center pt-12", transitionClassName), children: modal.opened ? (_jsx(FloatingFocusManager, { context: modal.context, modal: trapFocus, returnFocus: returnFocus, outsideElementsInert: false, children: _jsx("div", { ref: setRefs, "aria-labelledby": headerId, "data-opened": modal.opened, style: style, className: cx("pointer-events-auto relative z-50 w-full", "border border-[var(--refraktor-border)] bg-[var(--refraktor-bg)] p-4 text-[var(--refraktor-text)] shadow-md", sizeClasses[size], getRadius(radius), getStyles("content"), className), ...modal.getFloatingProps(), ...props, children: children }) })) : (_jsx("div", { ref: setRefs, "aria-labelledby": headerId, "data-opened": modal.opened, style: style, className: cx("pointer-events-auto relative z-50 w-full", "border border-[var(--refraktor-border)] bg-[var(--refraktor-bg)] p-4 text-[var(--refraktor-text)] shadow-md", sizeClasses[size], getRadius(radius), getStyles("content"), className), ...props, children: children })) }));
|
|
29
|
+
return withinPortal ? (_jsx(FloatingPortal, { children: content })) : (content);
|
|
22
30
|
});
|
|
23
31
|
ModalContent.displayName = "@refraktor/core/Modal.Content";
|
|
24
32
|
export default ModalContent;
|
|
@@ -3,11 +3,11 @@ import { useTheme } from "../../../theme";
|
|
|
3
3
|
import { factory } from "../../../utils";
|
|
4
4
|
import { ModalClose } from "../modal-close";
|
|
5
5
|
import { useModalContext } from "../modal.context";
|
|
6
|
-
const ModalHeader = factory(({ children, className, id,
|
|
6
|
+
const ModalHeader = factory(({ children, className, id, withClose = true, ...props }, ref) => {
|
|
7
7
|
const { cx } = useTheme();
|
|
8
8
|
const { headerId, getStyles } = useModalContext();
|
|
9
9
|
const resolvedId = id ?? headerId;
|
|
10
|
-
return (_jsxs("div", { ref: ref, className: cx("mb-4 flex items-center justify-between", getStyles("header"), className), ...props, children: [_jsx("div", { id: resolvedId, className: "min-w-0 flex-1 text-sm font-semibold leading-5 text-[var(--refraktor-text)]", children:
|
|
10
|
+
return (_jsxs("div", { ref: ref, className: cx("mb-4 flex items-center justify-between", getStyles("header"), className), ...props, children: [_jsx("div", { id: resolvedId, className: "min-w-0 flex-1 text-sm font-semibold leading-5 text-[var(--refraktor-text)]", children: children }), withClose && (_jsx(ModalClose, { className: "static shrink-0 self-center" }))] }));
|
|
11
11
|
});
|
|
12
12
|
ModalHeader.displayName = "@refraktor/core/Modal.Header";
|
|
13
13
|
export default ModalHeader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal-overlay.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/modal-overlay/modal-overlay.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE5D,QAAA,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"modal-overlay.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/modal-overlay/modal-overlay.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE5D,QAAA,MAAM,YAAY,mEA2EjB,CAAC;AAIF,eAAe,YAAY,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FloatingOverlay, FloatingPortal } from "@floating-ui/react";
|
|
2
3
|
import { useTheme } from "../../../theme";
|
|
3
4
|
import { factory } from "../../../utils";
|
|
4
|
-
import { Portal } from "../../portal";
|
|
5
5
|
import { Transition } from "../../transition";
|
|
6
6
|
import { useModalContext } from "../modal.context";
|
|
7
7
|
const ModalOverlay = factory(({ closeOnClick = true, backgroundOpacity = 0.5, blur = 0, className, onMouseDown, style, ...props }, ref) => {
|
|
8
8
|
const { cx } = useTheme();
|
|
9
|
-
const { modal, closeOnClickOutside, withinPortal, transitionProps, getStyles } = useModalContext();
|
|
9
|
+
const { modal, closeOnClickOutside, lockScroll, withinPortal, transitionProps, getStyles } = useModalContext();
|
|
10
10
|
const blurValue = typeof blur === "number" ? `${blur}px` : blur;
|
|
11
11
|
const backdropFilterValue = blurValue !== "0" && blurValue !== "0px"
|
|
12
12
|
? `blur(${blurValue})`
|
|
@@ -20,12 +20,12 @@ const ModalOverlay = factory(({ closeOnClick = true, backgroundOpacity = 0.5, bl
|
|
|
20
20
|
}
|
|
21
21
|
modal.close();
|
|
22
22
|
};
|
|
23
|
-
const overlayContent = (_jsx(Transition, { transition: "fade", duration: 150, mounted: modal.opened, ...transitionProps, children: _jsx(
|
|
23
|
+
const overlayContent = (_jsx(Transition, { transition: "fade", duration: 150, mounted: modal.opened, ...transitionProps, children: _jsx(FloatingOverlay, { lockScroll: lockScroll, ref: ref, className: cx("z-40", getStyles("overlay"), className), style: {
|
|
24
24
|
backgroundColor: `rgba(0, 0, 0, ${backgroundOpacity})`,
|
|
25
25
|
backdropFilter: backdropFilterValue,
|
|
26
26
|
...style
|
|
27
27
|
}, onMouseDown: handleMouseDown, ...props }) }));
|
|
28
|
-
return withinPortal ? (_jsx(
|
|
28
|
+
return withinPortal ? (_jsx(FloatingPortal, { children: overlayContent })) : (overlayContent);
|
|
29
29
|
});
|
|
30
30
|
ModalOverlay.displayName = "@refraktor/core/Modal.Overlay";
|
|
31
31
|
export default ModalOverlay;
|