@refraktor/core 0.0.1 → 0.0.3
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/breadcrumbs/breadcrumbs.d.ts +4 -0
- package/build/components/breadcrumbs/breadcrumbs.d.ts.map +1 -0
- package/build/components/breadcrumbs/breadcrumbs.js +64 -0
- package/build/components/breadcrumbs/breadcrumbs.styles.d.ts +12 -0
- package/build/components/breadcrumbs/breadcrumbs.styles.d.ts.map +1 -0
- package/build/components/breadcrumbs/breadcrumbs.styles.js +43 -0
- package/build/components/breadcrumbs/breadcrumbs.test.d.ts +2 -0
- package/build/components/breadcrumbs/breadcrumbs.test.d.ts.map +1 -0
- package/build/components/breadcrumbs/breadcrumbs.test.js +72 -0
- package/build/components/breadcrumbs/breadcrumbs.types.d.ts +56 -0
- package/build/components/breadcrumbs/breadcrumbs.types.d.ts.map +1 -0
- package/build/components/breadcrumbs/breadcrumbs.types.js +1 -0
- package/build/components/breadcrumbs/breadcrumbs.utils.d.ts +10 -0
- package/build/components/breadcrumbs/breadcrumbs.utils.d.ts.map +1 -0
- package/build/components/breadcrumbs/breadcrumbs.utils.js +36 -0
- package/build/components/breadcrumbs/index.d.ts +3 -0
- package/build/components/breadcrumbs/index.d.ts.map +1 -0
- package/build/components/breadcrumbs/index.js +1 -0
- package/build/components/drawer/drawer-close/drawer-close.d.ts +4 -0
- package/build/components/drawer/drawer-close/drawer-close.d.ts.map +1 -0
- package/build/components/drawer/drawer-close/drawer-close.js +19 -0
- package/build/components/drawer/drawer-close/index.d.ts +2 -0
- package/build/components/drawer/drawer-close/index.d.ts.map +1 -0
- package/build/components/drawer/drawer-close/index.js +1 -0
- package/build/components/drawer/drawer-content/drawer-content.d.ts +4 -0
- package/build/components/drawer/drawer-content/drawer-content.d.ts.map +1 -0
- package/build/components/drawer/drawer-content/drawer-content.js +41 -0
- package/build/components/drawer/drawer-content/index.d.ts +2 -0
- package/build/components/drawer/drawer-content/index.d.ts.map +1 -0
- package/build/components/drawer/drawer-content/index.js +1 -0
- package/build/components/drawer/drawer-header/drawer-header.d.ts +4 -0
- package/build/components/drawer/drawer-header/drawer-header.d.ts.map +1 -0
- package/build/components/drawer/drawer-header/drawer-header.js +13 -0
- package/build/components/drawer/drawer-header/index.d.ts +2 -0
- package/build/components/drawer/drawer-header/index.d.ts.map +1 -0
- package/build/components/drawer/drawer-header/index.js +1 -0
- package/build/components/drawer/drawer-overlay/drawer-overlay.d.ts +4 -0
- package/build/components/drawer/drawer-overlay/drawer-overlay.d.ts.map +1 -0
- package/build/components/drawer/drawer-overlay/drawer-overlay.js +31 -0
- package/build/components/drawer/drawer-overlay/index.d.ts +2 -0
- package/build/components/drawer/drawer-overlay/index.d.ts.map +1 -0
- package/build/components/drawer/drawer-overlay/index.js +1 -0
- package/build/components/drawer/drawer-root/drawer-root.d.ts +4 -0
- package/build/components/drawer/drawer-root/drawer-root.d.ts.map +1 -0
- package/build/components/drawer/drawer-root/drawer-root.js +50 -0
- package/build/components/drawer/drawer-root/index.d.ts +2 -0
- package/build/components/drawer/drawer-root/index.d.ts.map +1 -0
- package/build/components/drawer/drawer-root/index.js +1 -0
- package/build/components/drawer/drawer.context.d.ts +23 -0
- package/build/components/drawer/drawer.context.d.ts.map +1 -0
- package/build/components/drawer/drawer.context.js +2 -0
- package/build/components/drawer/drawer.d.ts +4 -0
- package/build/components/drawer/drawer.d.ts.map +1 -0
- package/build/components/drawer/drawer.js +19 -0
- package/build/components/drawer/drawer.styles.d.ts +6 -0
- package/build/components/drawer/drawer.styles.d.ts.map +1 -0
- package/build/components/drawer/drawer.styles.js +21 -0
- package/build/components/drawer/drawer.test.d.ts +2 -0
- package/build/components/drawer/drawer.test.d.ts.map +1 -0
- package/build/components/drawer/drawer.test.js +70 -0
- package/build/components/drawer/drawer.types.d.ts +116 -0
- package/build/components/drawer/drawer.types.d.ts.map +1 -0
- package/build/components/drawer/drawer.types.js +1 -0
- package/build/components/drawer/index.d.ts +8 -0
- package/build/components/drawer/index.d.ts.map +1 -0
- package/build/components/drawer/index.js +6 -0
- package/build/components/drawer/use-drawer.d.ts +17 -0
- package/build/components/drawer/use-drawer.d.ts.map +1 -0
- package/build/components/drawer/use-drawer.js +61 -0
- package/build/components/index.d.ts +4 -0
- package/build/components/index.d.ts.map +1 -1
- package/build/components/index.js +4 -0
- package/build/components/menu/menu-dropdown/menu-dropdown.d.ts.map +1 -1
- package/build/components/menu/menu-dropdown/menu-dropdown.js +3 -2
- package/build/components/menu/menu-sub-dropdown/menu-sub-dropdown.d.ts.map +1 -1
- package/build/components/menu/menu-sub-dropdown/menu-sub-dropdown.js +2 -1
- package/build/components/menu/use-menu.d.ts.map +1 -1
- package/build/components/menu/use-menu.js +2 -1
- package/build/components/modal/modal-close/modal-close.d.ts.map +1 -1
- package/build/components/modal/modal-close/modal-close.js +1 -1
- package/build/components/modal/modal-content/modal-content.d.ts.map +1 -1
- package/build/components/modal/modal-content/modal-content.js +1 -1
- package/build/components/modal/modal-header/modal-header.d.ts.map +1 -1
- package/build/components/modal/modal-header/modal-header.js +1 -1
- package/build/components/modal/modal-overlay/modal-overlay.d.ts.map +1 -1
- package/build/components/modal/modal-overlay/modal-overlay.js +10 -2
- package/build/components/modal/modal.test.js +16 -0
- package/build/components/modal/modal.types.d.ts +4 -0
- package/build/components/modal/modal.types.d.ts.map +1 -1
- package/build/components/number-input/number-input.d.ts.map +1 -1
- package/build/components/number-input/number-input.js +22 -15
- package/build/components/number-input/number-input.test.d.ts +2 -0
- package/build/components/number-input/number-input.test.d.ts.map +1 -0
- package/build/components/number-input/number-input.test.js +14 -0
- package/build/components/number-input/number-input.types.d.ts +2 -2
- package/build/components/number-input/number-input.types.d.ts.map +1 -1
- package/build/components/popover/popover-dropdown/popover-dropdown.d.ts.map +1 -1
- package/build/components/popover/popover-dropdown/popover-dropdown.js +2 -1
- package/build/components/popover/use-popover.d.ts.map +1 -1
- package/build/components/popover/use-popover.js +2 -1
- package/build/components/portal/portal.js +1 -1
- package/build/components/segmented-control/index.d.ts +3 -0
- package/build/components/segmented-control/index.d.ts.map +1 -0
- package/build/components/segmented-control/index.js +1 -0
- package/build/components/segmented-control/segmented-control.d.ts +4 -0
- package/build/components/segmented-control/segmented-control.d.ts.map +1 -0
- package/build/components/segmented-control/segmented-control.js +113 -0
- package/build/components/segmented-control/segmented-control.styles.d.ts +9 -0
- package/build/components/segmented-control/segmented-control.styles.d.ts.map +1 -0
- package/build/components/segmented-control/segmented-control.styles.js +28 -0
- package/build/components/segmented-control/segmented-control.test.d.ts +2 -0
- package/build/components/segmented-control/segmented-control.test.d.ts.map +1 -0
- package/build/components/segmented-control/segmented-control.test.js +81 -0
- package/build/components/segmented-control/segmented-control.types.d.ts +49 -0
- package/build/components/segmented-control/segmented-control.types.d.ts.map +1 -0
- package/build/components/segmented-control/segmented-control.types.js +1 -0
- package/build/components/select/select-dropdown/select-dropdown.d.ts.map +1 -1
- package/build/components/select/select-dropdown/select-dropdown.js +3 -2
- package/build/components/select/select-item/select-item.d.ts.map +1 -1
- package/build/components/select/select-item/select-item.js +1 -1
- package/build/components/select/select-root/select-root.d.ts.map +1 -1
- package/build/components/select/select-root/select-root.js +36 -6
- package/build/components/select/select-trigger/select-trigger.d.ts.map +1 -1
- package/build/components/select/select-trigger/select-trigger.js +1 -1
- package/build/components/select/select.context.d.ts +2 -0
- package/build/components/select/select.context.d.ts.map +1 -1
- package/build/components/select/select.test.js +17 -0
- package/build/components/select/select.types.d.ts +10 -0
- package/build/components/select/select.types.d.ts.map +1 -1
- package/build/components/select/use-select.d.ts.map +1 -1
- package/build/components/select/use-select.js +2 -1
- package/build/components/split-pane/index.d.ts +3 -0
- package/build/components/split-pane/index.d.ts.map +1 -0
- package/build/components/split-pane/index.js +1 -0
- package/build/components/split-pane/split-pane.d.ts +4 -0
- package/build/components/split-pane/split-pane.d.ts.map +1 -0
- package/build/components/split-pane/split-pane.js +201 -0
- package/build/components/split-pane/split-pane.styles.d.ts +3 -0
- package/build/components/split-pane/split-pane.styles.d.ts.map +1 -0
- package/build/components/split-pane/split-pane.styles.js +8 -0
- package/build/components/split-pane/split-pane.test.d.ts +2 -0
- package/build/components/split-pane/split-pane.test.d.ts.map +1 -0
- package/build/components/split-pane/split-pane.test.js +105 -0
- package/build/components/split-pane/split-pane.types.d.ts +51 -0
- package/build/components/split-pane/split-pane.types.d.ts.map +1 -0
- package/build/components/split-pane/split-pane.types.js +1 -0
- package/build/components/switch/switch.js +1 -1
- package/build/components/table/index.d.ts +9 -0
- package/build/components/table/index.d.ts.map +1 -0
- package/build/components/table/index.js +7 -0
- package/build/components/table/table-body/index.d.ts +2 -0
- package/build/components/table/table-body/index.d.ts.map +1 -0
- package/build/components/table/table-body/index.js +1 -0
- package/build/components/table/table-body/table-body.d.ts +4 -0
- package/build/components/table/table-body/table-body.d.ts.map +1 -0
- package/build/components/table/table-body/table-body.js +17 -0
- package/build/components/table/table-caption/index.d.ts +2 -0
- package/build/components/table/table-caption/index.d.ts.map +1 -0
- package/build/components/table/table-caption/index.js +1 -0
- package/build/components/table/table-caption/table-caption.d.ts +4 -0
- package/build/components/table/table-caption/table-caption.d.ts.map +1 -0
- package/build/components/table/table-caption/table-caption.js +13 -0
- package/build/components/table/table-cell/index.d.ts +2 -0
- package/build/components/table/table-cell/index.d.ts.map +1 -0
- package/build/components/table/table-cell/index.js +1 -0
- package/build/components/table/table-cell/table-cell.d.ts +4 -0
- package/build/components/table/table-cell/table-cell.d.ts.map +1 -0
- package/build/components/table/table-cell/table-cell.js +13 -0
- package/build/components/table/table-head/index.d.ts +2 -0
- package/build/components/table/table-head/index.d.ts.map +1 -0
- package/build/components/table/table-head/index.js +1 -0
- package/build/components/table/table-head/table-head.d.ts +4 -0
- package/build/components/table/table-head/table-head.d.ts.map +1 -0
- package/build/components/table/table-head/table-head.js +11 -0
- package/build/components/table/table-header-cell/index.d.ts +2 -0
- package/build/components/table/table-header-cell/index.d.ts.map +1 -0
- package/build/components/table/table-header-cell/index.js +1 -0
- package/build/components/table/table-header-cell/table-header-cell.d.ts +4 -0
- package/build/components/table/table-header-cell/table-header-cell.d.ts.map +1 -0
- package/build/components/table/table-header-cell/table-header-cell.js +13 -0
- package/build/components/table/table-row/index.d.ts +2 -0
- package/build/components/table/table-row/index.d.ts.map +1 -0
- package/build/components/table/table-row/index.js +1 -0
- package/build/components/table/table-row/table-row.d.ts +4 -0
- package/build/components/table/table-row/table-row.d.ts.map +1 -0
- package/build/components/table/table-row/table-row.js +11 -0
- package/build/components/table/table.context.d.ts +16 -0
- package/build/components/table/table.context.d.ts.map +1 -0
- package/build/components/table/table.context.js +2 -0
- package/build/components/table/table.d.ts +4 -0
- package/build/components/table/table.d.ts.map +1 -0
- package/build/components/table/table.js +46 -0
- package/build/components/table/table.styles.d.ts +16 -0
- package/build/components/table/table.styles.d.ts.map +1 -0
- package/build/components/table/table.styles.js +39 -0
- package/build/components/table/table.test.d.ts +2 -0
- package/build/components/table/table.test.d.ts.map +1 -0
- package/build/components/table/table.test.js +59 -0
- package/build/components/table/table.types.d.ts +113 -0
- package/build/components/table/table.types.d.ts.map +1 -0
- package/build/components/table/table.types.js +1 -0
- package/build/components/tabs/tabs-tab/tabs-tab.d.ts.map +1 -1
- package/build/components/tabs/tabs-tab/tabs-tab.js +0 -6
- package/build/components/tooltip/tooltip.d.ts.map +1 -1
- package/build/components/tooltip/tooltip.js +7 -3
- package/build/components/tooltip/use-tooltip.d.ts.map +1 -1
- package/build/components/tooltip/use-tooltip.js +2 -1
- package/build/components/transition/transition.d.ts.map +1 -1
- package/build/components/transition/transition.js +16 -12
- package/build/style.css +1 -1
- package/package.json +2 -2
- package/src/components/breadcrumbs/breadcrumbs.styles.ts +55 -0
- package/src/components/breadcrumbs/breadcrumbs.test.tsx +136 -0
- package/src/components/breadcrumbs/breadcrumbs.tsx +199 -0
- package/src/components/breadcrumbs/breadcrumbs.types.ts +78 -0
- package/src/components/breadcrumbs/breadcrumbs.utils.ts +70 -0
- package/src/components/breadcrumbs/index.ts +6 -0
- package/src/components/drawer/drawer-close/drawer-close.tsx +43 -0
- package/src/components/drawer/drawer-close/index.ts +1 -0
- package/src/components/drawer/drawer-content/drawer-content.tsx +98 -0
- package/src/components/drawer/drawer-content/index.ts +1 -0
- package/src/components/drawer/drawer-header/drawer-header.tsx +40 -0
- package/src/components/drawer/drawer-header/index.ts +1 -0
- package/src/components/drawer/drawer-overlay/drawer-overlay.tsx +86 -0
- package/src/components/drawer/drawer-overlay/index.ts +1 -0
- package/src/components/drawer/drawer-root/drawer-root.tsx +94 -0
- package/src/components/drawer/drawer-root/index.ts +1 -0
- package/src/components/drawer/drawer.context.ts +25 -0
- package/src/components/drawer/drawer.styles.ts +32 -0
- package/src/components/drawer/drawer.test.tsx +166 -0
- package/src/components/drawer/drawer.tsx +30 -0
- package/src/components/drawer/drawer.types.ts +158 -0
- package/src/components/drawer/index.ts +16 -0
- package/src/components/drawer/use-drawer.ts +101 -0
- package/src/components/index.ts +10 -6
- package/src/components/menu/menu-dropdown/menu-dropdown.tsx +4 -3
- package/src/components/menu/menu-sub-dropdown/menu-sub-dropdown.tsx +2 -0
- package/src/components/menu/use-menu.ts +2 -1
- package/src/components/modal/modal-close/modal-close.tsx +1 -5
- package/src/components/modal/modal-content/modal-content.tsx +3 -4
- package/src/components/modal/modal-header/modal-header.tsx +4 -2
- package/src/components/modal/modal-overlay/modal-overlay.tsx +66 -44
- package/src/components/modal/modal.test.tsx +124 -88
- package/src/components/modal/modal.types.ts +6 -0
- package/src/components/modal/use-modal.ts +101 -101
- package/src/components/number-input/number-input.test.tsx +22 -0
- package/src/components/number-input/number-input.tsx +79 -51
- package/src/components/number-input/number-input.types.ts +8 -8
- package/src/components/popover/popover-dropdown/popover-dropdown.tsx +2 -0
- package/src/components/popover/use-popover.ts +2 -1
- package/src/components/portal/portal.tsx +1 -1
- package/src/components/segmented-control/index.ts +6 -0
- package/src/components/segmented-control/segmented-control.styles.ts +37 -0
- package/src/components/segmented-control/segmented-control.test.tsx +152 -0
- package/src/components/segmented-control/segmented-control.tsx +245 -0
- package/src/components/segmented-control/segmented-control.types.ts +75 -0
- package/src/components/select/select-dropdown/select-dropdown.tsx +4 -3
- package/src/components/select/select-item/select-item.tsx +1 -2
- package/src/components/select/select-root/select-root.tsx +87 -11
- package/src/components/select/select-trigger/select-trigger.tsx +2 -0
- package/src/components/select/select.context.ts +2 -0
- package/src/components/select/select.test.tsx +35 -0
- package/src/components/select/select.types.ts +15 -0
- package/src/components/select/use-select.ts +2 -1
- package/src/components/switch/switch.tsx +1 -1
- package/src/components/table/index.ts +24 -0
- package/src/components/table/table-body/index.ts +1 -0
- package/src/components/table/table-body/table-body.tsx +37 -0
- package/src/components/table/table-caption/index.ts +1 -0
- package/src/components/table/table-caption/table-caption.tsx +32 -0
- package/src/components/table/table-cell/index.ts +1 -0
- package/src/components/table/table-cell/table-cell.tsx +33 -0
- package/src/components/table/table-head/index.ts +1 -0
- package/src/components/table/table-head/table-head.tsx +29 -0
- package/src/components/table/table-header-cell/index.ts +1 -0
- package/src/components/table/table-header-cell/table-header-cell.tsx +33 -0
- package/src/components/table/table-row/index.ts +1 -0
- package/src/components/table/table-row/table-row.tsx +30 -0
- package/src/components/table/table.context.ts +18 -0
- package/src/components/table/table.styles.ts +62 -0
- package/src/components/table/table.test.tsx +145 -0
- package/src/components/table/table.tsx +91 -0
- package/src/components/table/table.types.ts +145 -0
- package/src/components/tabs/tabs-tab/tabs-tab.tsx +0 -8
- package/src/components/tooltip/tooltip.tsx +7 -1
- package/src/components/tooltip/use-tooltip.ts +2 -1
- package/src/components/transition/transition.tsx +18 -14
- package/src/style.css +0 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -39,6 +39,22 @@ describe("@refraktor/core/Modal", () => {
|
|
|
39
39
|
await render(_jsxs(ModalRoot, { defaultOpened: true, transitionProps: transitionProps, children: [_jsx(ModalOverlay, {}), _jsx(ModalContent, { children: "Standalone composition" })] }));
|
|
40
40
|
expect(await screen.findByRole("dialog")).toBeInTheDocument();
|
|
41
41
|
});
|
|
42
|
+
it("applies custom overlay background opacity and blur", async () => {
|
|
43
|
+
await render(_jsxs(Modal, { defaultOpened: true, transitionProps: transitionProps, children: [_jsx(Modal.Overlay, { "data-testid": "overlay", backgroundOpacity: 0.4, blur: 6 }), _jsx(Modal.Content, { children: "Styled overlay" })] }));
|
|
44
|
+
const overlay = await screen.findByTestId("overlay");
|
|
45
|
+
expect(overlay).toHaveStyle({
|
|
46
|
+
backgroundColor: "rgba(0, 0, 0, 0.4)",
|
|
47
|
+
backdropFilter: "blur(6px)"
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it("does not set backdrop blur for zero blur", async () => {
|
|
51
|
+
await render(_jsxs(Modal, { defaultOpened: true, transitionProps: transitionProps, children: [_jsx(Modal.Overlay, { "data-testid": "overlay", blur: 0 }), _jsx(Modal.Content, { children: "No blur" })] }));
|
|
52
|
+
const overlay = await screen.findByTestId("overlay");
|
|
53
|
+
expect(overlay).toHaveStyle({
|
|
54
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)"
|
|
55
|
+
});
|
|
56
|
+
expect(overlay.style.backdropFilter).toBe("");
|
|
57
|
+
});
|
|
42
58
|
it("locks and unlocks body scroll when enabled", async () => {
|
|
43
59
|
const user = userEvent.setup();
|
|
44
60
|
await render(_jsx(Modal, { defaultOpened: true, lockScroll: true, transitionProps: transitionProps, children: _jsxs(Modal.Content, { children: ["Scroll locked", _jsx(Modal.Close, {})] }) }));
|
|
@@ -44,6 +44,10 @@ export type ModalRootProps = ModalProps;
|
|
|
44
44
|
export interface ModalOverlayProps extends ComponentPropsWithoutRef<"div"> {
|
|
45
45
|
/** Whether clicking the overlay closes modal @default `true` */
|
|
46
46
|
closeOnClick?: boolean;
|
|
47
|
+
/** Overlay background opacity @default `0.5` */
|
|
48
|
+
backgroundOpacity?: number;
|
|
49
|
+
/** Backdrop blur amount in px (or any CSS length) @default `0` */
|
|
50
|
+
blur?: number | string;
|
|
47
51
|
/** Used for editing root class name */
|
|
48
52
|
className?: string;
|
|
49
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.types.d.ts","sourceRoot":"","sources":["../../../src/components/modal/modal.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,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;AAE3C,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,UAAW,SAAQ,wBAAwB,CAAC,KAAK,CAAC;IAC/D,8CAA8C;IAC9C,QAAQ,EAAE,SAAS,CAAC;IAEpB,sCAAsC;IACtC,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,gDAAgD;IAChD,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAE3C,sEAAsE;IACtE,mBAAmB,CAAC,EAAE,OAA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,KAAK,IAAI,CAAC;IAEzD,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACvD,KAAK,EAAE,UAAU,CAAC;IAClB,GAAG,EAAE,cAAc,CAAC;IACpB,QAAQ,EAAE;QACN,SAAS,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC;QAChE,UAAU,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,eAAe,CAAC,CAAC,CAAC;QACvE,IAAI,EAAE,OAAO,SAAS,CAAC;QACvB,OAAO,EAAE,OAAO,YAAY,CAAC;QAC7B,OAAO,EAAE,OAAO,YAAY,CAAC;QAC7B,MAAM,EAAE,OAAO,WAAW,CAAC;QAC3B,KAAK,EAAE,OAAO,UAAU,CAAC;KAC5B,CAAC;CACL;AAED,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC3D,KAAK,EAAE,cAAc,CAAC;IACtB,GAAG,EAAE,cAAc,CAAC;CACvB;AAED,MAAM,WAAW,0BAA2B,SAAQ,cAAc;IAC9D,KAAK,EAAE,iBAAiB,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACvB;AAED,MAAM,WAAW,0BAA2B,SAAQ,cAAc;IAC9D,KAAK,EAAE,iBAAiB,CAAC;IACzB,GAAG,EAAE,cAAc,CAAC;CACvB;AAED,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC7D,KAAK,EAAE,gBAAgB,CAAC;IACxB,GAAG,EAAE,cAAc,CAAC;CACvB;AAED,MAAM,WAAW,wBAAyB,SAAQ,cAAc;IAC5D,KAAK,EAAE,eAAe,CAAC;IACvB,GAAG,EAAE,iBAAiB,CAAC;CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-input.d.ts","sourceRoot":"","sources":["../../../src/components/number-input/number-input.tsx"],"names":[],"mappings":"AASA,OAAO,EAEH,yBAAyB,EAE5B,MAAM,sBAAsB,CAAC;AAsD9B,QAAA,MAAM,WAAW,+
|
|
1
|
+
{"version":3,"file":"number-input.d.ts","sourceRoot":"","sources":["../../../src/components/number-input/number-input.tsx"],"names":[],"mappings":"AASA,OAAO,EAEH,yBAAyB,EAE5B,MAAM,sBAAsB,CAAC;AAsD9B,QAAA,MAAM,WAAW,+DAmTf,CAAC;AAMH,eAAe,WAAW,CAAC"}
|
|
@@ -44,7 +44,7 @@ const defaultProps = {
|
|
|
44
44
|
};
|
|
45
45
|
const NumberInput = factory((_props, ref) => {
|
|
46
46
|
const { cx } = useTheme();
|
|
47
|
-
const { id, value, defaultValue, size, onChange, min, max, step, precision, controlsPosition, disabled, className, classNames, ...props } = useProps("NumberInput", defaultProps, _props);
|
|
47
|
+
const { id, label, description, error, required, withAsterisk, value, defaultValue, size, onChange, min, max, step, precision, controlsPosition, disabled, className, classNames, ...props } = useProps("NumberInput", defaultProps, _props);
|
|
48
48
|
const classes = useClassNames("NumberInput", classNames);
|
|
49
49
|
const _id = useId(id);
|
|
50
50
|
const [_value, setValue] = useUncontrolled({
|
|
@@ -84,9 +84,9 @@ const NumberInput = factory((_props, ref) => {
|
|
|
84
84
|
};
|
|
85
85
|
const stopHold = () => {
|
|
86
86
|
if (holdTimer.current)
|
|
87
|
-
|
|
87
|
+
clearInterval(holdTimer.current);
|
|
88
88
|
if (repeatTimer.current)
|
|
89
|
-
|
|
89
|
+
clearTimeout(repeatTimer.current);
|
|
90
90
|
holdTimer.current = null;
|
|
91
91
|
repeatTimer.current = null;
|
|
92
92
|
};
|
|
@@ -173,18 +173,25 @@ const NumberInput = factory((_props, ref) => {
|
|
|
173
173
|
startHold("decrement");
|
|
174
174
|
}, onMouseUp: stopHold, onMouseLeave: stopHold, onTouchEnd: stopHold, children: _jsx(ChevronIcon, { direction: "down", size: controlSizing.iconSize, className: cx("block", !canDecrement && "opacity-50") }) })] }));
|
|
175
175
|
}, [controlsPosition, canIncrement, canDecrement, classes, controlSizing]);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
176
|
+
const hasWrapper = label || description || error;
|
|
177
|
+
const field = (_jsx(InputField, { ref: ref, id: _id, type: "number", required: required, error: !!error, disabled: disabled, size: size, min: min, max: max, step: step, value: _value, onChange: handleChange, onBlur: handleBlur, onKeyDown: handleKeyDown, onWheel: handleWheel, leftSection: controlsPosition === "left" ? controls : undefined, rightSection: controlsPosition === "right" ? controls : undefined, className: className, classNames: {
|
|
178
|
+
root: cx("px-0 gap-0 items-stretch overflow-hidden", controlsPosition === "none"
|
|
179
|
+
? "px-2"
|
|
180
|
+
: controlsPosition === "left"
|
|
181
|
+
? "pr-2"
|
|
182
|
+
: "pl-2", classes.root),
|
|
183
|
+
leftSection: cx("h-full self-stretch", controlsPosition === "left" && controlSizing.leftSpacing, classes.leftSection),
|
|
184
|
+
rightSection: cx("h-full self-stretch", controlsPosition === "right" && controlSizing.rightSpacing, classes.rightSection),
|
|
185
|
+
...classes
|
|
186
|
+
}, "aria-describedby": error
|
|
187
|
+
? `${_id}-error`
|
|
188
|
+
: description
|
|
189
|
+
? `${_id}-description`
|
|
190
|
+
: undefined, "aria-disabled": disabled, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": Number(_value), ...props }));
|
|
191
|
+
if (!hasWrapper) {
|
|
192
|
+
return field;
|
|
193
|
+
}
|
|
194
|
+
return (_jsx(InputWrapper, { label: label, description: description, error: error, required: required, withAsterisk: withAsterisk, inputId: _id, children: field }));
|
|
188
195
|
});
|
|
189
196
|
NumberInput.displayName = "@refraktor/core/NumberInput";
|
|
190
197
|
NumberInput.configure = createComponentConfig();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-input.test.d.ts","sourceRoot":"","sources":["../../../src/components/number-input/number-input.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { render, screen } from "../../vitest";
|
|
4
|
+
import NumberInput from "./number-input";
|
|
5
|
+
describe("@refraktor/core/NumberInput", () => {
|
|
6
|
+
it("supports input wrapper props", async () => {
|
|
7
|
+
await render(_jsx(NumberInput, { label: "Quantity", description: "Enter desired amount", error: "Quantity is required" }));
|
|
8
|
+
const input = screen.getByLabelText("Quantity");
|
|
9
|
+
expect(input).toHaveAttribute("type", "number");
|
|
10
|
+
expect(input).toHaveAttribute("aria-invalid", "true");
|
|
11
|
+
expect(screen.getByText("Enter desired amount")).toBeInTheDocument();
|
|
12
|
+
expect(screen.getByText("Quantity is required")).toBeInTheDocument();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createClassNamesConfig, createComponentConfig, FactoryPayload } from "../../utils";
|
|
2
|
-
import { InputFieldClassNames,
|
|
2
|
+
import { InputFieldClassNames, InputProps } from "../input";
|
|
3
3
|
export type NumberInputControlsPosition = "left" | "right" | "none";
|
|
4
4
|
export interface NumberInputClassNames extends InputFieldClassNames {
|
|
5
5
|
controls?: string;
|
|
@@ -27,7 +27,7 @@ export interface _NumberInputProps {
|
|
|
27
27
|
/** Used for styling different parts of the component */
|
|
28
28
|
classNames?: NumberInputClassNames;
|
|
29
29
|
}
|
|
30
|
-
export type NumberInputProps = _NumberInputProps & Omit<
|
|
30
|
+
export type NumberInputProps = _NumberInputProps & Omit<InputProps, "onChange" | "type" | keyof _NumberInputProps>;
|
|
31
31
|
export interface NumberInputFactoryPayload extends FactoryPayload {
|
|
32
32
|
props: NumberInputProps;
|
|
33
33
|
ref: HTMLInputElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-input.types.d.ts","sourceRoot":"","sources":["../../../src/components/number-input/number-input.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"number-input.types.d.ts","sourceRoot":"","sources":["../../../src/components/number-input/number-input.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE5D,MAAM,MAAM,2BAA2B,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE,MAAM,WAAW,qBAAsB,SAAQ,oBAAoB;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,iBAAiB;IAC9B,yBAAyB;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAExB,mCAAmC;IACnC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE/B,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAC;IAE5C,oBAAoB;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,oBAAoB;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,2BAA2B,CAAC;IAE/C,wDAAwD;IACxD,UAAU,CAAC,EAAE,qBAAqB,CAAC;CACtC;AAED,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAC5C,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,iBAAiB,CAAC,CAAC;AAEpE,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC7D,KAAK,EAAE,gBAAgB,CAAC;IACxB,GAAG,EAAE,gBAAgB,CAAC;IACtB,QAAQ,EAAE;QACN,SAAS,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CAAC;QACtE,UAAU,EAAE,UAAU,CAClB,OAAO,sBAAsB,CAAC,qBAAqB,CAAC,CACvD,CAAC;KACL,CAAC;CACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover-dropdown.d.ts","sourceRoot":"","sources":["../../../../src/components/popover/popover-dropdown/popover-dropdown.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AASjE,QAAA,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"popover-dropdown.d.ts","sourceRoot":"","sources":["../../../../src/components/popover/popover-dropdown/popover-dropdown.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AASjE,QAAA,MAAM,eAAe,sEA8EpB,CAAC;AAIF,eAAe,eAAe,CAAC"}
|
|
@@ -7,7 +7,7 @@ import { FloatingArrow, FloatingFocusManager, FloatingPortal } from "@floating-u
|
|
|
7
7
|
const PopoverDropdown = factory(({ children, className, style, ...props }, ref) => {
|
|
8
8
|
const { cx, getRadius } = useTheme();
|
|
9
9
|
const { popover, showArrow, radius, withinPortal, transitionProps, getStyles } = usePopoverContext();
|
|
10
|
-
const dropdownContent = (_jsx(Transition, { transition: "fade", duration: 200, mounted: popover.opened, ...transitionProps, children: _jsxs("div", { ref: (node) => {
|
|
10
|
+
const dropdownContent = (_jsx(Transition, { transition: "fade", duration: 200, mounted: popover.opened, style: { position: "relative", zIndex: 1000 }, ...transitionProps, children: _jsxs("div", { ref: (node) => {
|
|
11
11
|
popover.refs.setFloating(node);
|
|
12
12
|
if (typeof ref === "function") {
|
|
13
13
|
ref(node);
|
|
@@ -17,6 +17,7 @@ const PopoverDropdown = factory(({ children, className, style, ...props }, ref)
|
|
|
17
17
|
}
|
|
18
18
|
}, role: "dialog", "aria-modal": "true", style: {
|
|
19
19
|
...popover.floatingStyles,
|
|
20
|
+
zIndex: 1000,
|
|
20
21
|
...style
|
|
21
22
|
}, className: cx("z-50 p-2 bg-[var(--refraktor-bg)] text-[var(--refraktor-text)] shadow-md text-sm border-0", getRadius(radius), getStyles("dropdown"), className), ...popover.getFloatingProps(), ...props, children: [children, showArrow && (_jsx(FloatingArrow, { ref: popover.arrowRef, context: popover.context, width: 10, height: 5, className: cx("fill-[var(--refraktor-bg)]", getStyles("arrow")) }))] }) }));
|
|
22
23
|
const wrappedContent = popover.opened ? (_jsx(FloatingFocusManager, { context: popover.context, modal: false, children: dropdownContent })) : (dropdownContent);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-popover.d.ts","sourceRoot":"","sources":["../../../src/components/popover/use-popover.ts"],"names":[],"mappings":"AACA,OAAO,EACH,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAIH,eAAe,EAIf,SAAS,EAUZ,MAAM,oBAAoB,CAAC;AAG5B,UAAU,eAAe;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mBAAmB,CAAC,EAAE,OAAO,C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WAAW,CAAC,KAC5C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,gBAAgB,EAAE,CACd,SAAS,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,KAC5C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IAChD,SAAS,EAAE,SAAS,CAAC;CACxB;AAED,wBAAgB,UAAU,CAAC,OAAO,GAAE,eAAoB,GAAG,gBAAgB,CAyJ1E"}
|
|
@@ -43,7 +43,8 @@ export function usePopover(options = {}) {
|
|
|
43
43
|
open: isOpen,
|
|
44
44
|
onOpenChange: setIsOpen,
|
|
45
45
|
middleware: middleware,
|
|
46
|
-
whileElementsMounted: autoUpdate
|
|
46
|
+
whileElementsMounted: autoUpdate,
|
|
47
|
+
strategy: "fixed"
|
|
47
48
|
});
|
|
48
49
|
const click = useClick(floating.context, {
|
|
49
50
|
enabled: trigger === "click" && !disabled
|
|
@@ -71,6 +71,6 @@ const Portal = factory((_props, ref) => {
|
|
|
71
71
|
}
|
|
72
72
|
return createPortal(_jsx(_Fragment, { children: children }), nodeRef.current);
|
|
73
73
|
});
|
|
74
|
-
Portal.displayName = "@
|
|
74
|
+
Portal.displayName = "@refraktor/core/Portal";
|
|
75
75
|
Portal.configure = createComponentConfig();
|
|
76
76
|
export default Portal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/segmented-control/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAClE,YAAY,EACR,qBAAqB,EACrB,0BAA0B,EAC1B,oBAAoB,EACvB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SegmentedControl } from "./segmented-control";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmented-control.d.ts","sourceRoot":"","sources":["../../../src/components/segmented-control/segmented-control.tsx"],"names":[],"mappings":"AAWA,OAAO,EAEH,8BAA8B,EAEjC,MAAM,2BAA2B,CAAC;AASnC,QAAA,MAAM,gBAAgB,oEAqNrB,CAAC;AAOF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useUncontrolled } from "@refraktor/utils";
|
|
3
|
+
import { useMemo, useRef } from "react";
|
|
4
|
+
import { useTheme } from "../../theme";
|
|
5
|
+
import { createClassNamesConfig, createComponentConfig, factory, useClassNames, useProps } from "../../utils";
|
|
6
|
+
import { getSize } from "./segmented-control.styles";
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
size: "md",
|
|
9
|
+
radius: "default",
|
|
10
|
+
fullWidth: false,
|
|
11
|
+
disabled: false
|
|
12
|
+
};
|
|
13
|
+
const SegmentedControl = factory((_props, ref) => {
|
|
14
|
+
const { cx, getRadius } = useTheme();
|
|
15
|
+
const { id, data, value, defaultValue, onChange, size, radius, fullWidth, disabled, name, className, classNames, ...props } = useProps("SegmentedControl", defaultProps, _props);
|
|
16
|
+
const classes = useClassNames("SegmentedControl", classNames);
|
|
17
|
+
const _id = useId(id);
|
|
18
|
+
const firstEnabledValue = useMemo(() => data.find((item) => !item.disabled)?.value ?? "", [data]);
|
|
19
|
+
const [selectedValue, setSelectedValue] = useUncontrolled({
|
|
20
|
+
value,
|
|
21
|
+
defaultValue,
|
|
22
|
+
finalValue: firstEnabledValue,
|
|
23
|
+
onChange
|
|
24
|
+
});
|
|
25
|
+
const sizeStyles = getSize(size);
|
|
26
|
+
const controlRefs = useRef([]);
|
|
27
|
+
const enabledIndexes = useMemo(() => {
|
|
28
|
+
const indexes = [];
|
|
29
|
+
data.forEach((item, index) => {
|
|
30
|
+
if (!item.disabled) {
|
|
31
|
+
indexes.push(index);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return indexes;
|
|
35
|
+
}, [data]);
|
|
36
|
+
const activeIndex = useMemo(() => data.findIndex((item) => item.value === selectedValue), [data, selectedValue]);
|
|
37
|
+
const tabStopIndex = useMemo(() => {
|
|
38
|
+
if (activeIndex !== -1 && !data[activeIndex]?.disabled) {
|
|
39
|
+
return activeIndex;
|
|
40
|
+
}
|
|
41
|
+
return enabledIndexes[0] ?? -1;
|
|
42
|
+
}, [activeIndex, data, enabledIndexes]);
|
|
43
|
+
const selectByIndex = (index) => {
|
|
44
|
+
const item = data[index];
|
|
45
|
+
if (!item ||
|
|
46
|
+
disabled ||
|
|
47
|
+
item.disabled ||
|
|
48
|
+
item.value === selectedValue) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
setSelectedValue(item.value);
|
|
52
|
+
};
|
|
53
|
+
const moveSelection = (currentIndex, direction) => {
|
|
54
|
+
if (disabled || enabledIndexes.length === 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const currentEnabledPosition = enabledIndexes.indexOf(currentIndex);
|
|
58
|
+
const basePosition = currentEnabledPosition === -1 ? 0 : currentEnabledPosition;
|
|
59
|
+
const nextPosition = (basePosition + direction + enabledIndexes.length) %
|
|
60
|
+
enabledIndexes.length;
|
|
61
|
+
const nextIndex = enabledIndexes[nextPosition];
|
|
62
|
+
selectByIndex(nextIndex);
|
|
63
|
+
controlRefs.current[nextIndex]?.focus();
|
|
64
|
+
};
|
|
65
|
+
const handleKeyDown = (event, index, isControlDisabled) => {
|
|
66
|
+
if (event.defaultPrevented || disabled || isControlDisabled) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
moveSelection(index, 1);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
moveSelection(index, -1);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (event.key === "Home") {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
const firstEnabledIndex = enabledIndexes[0];
|
|
82
|
+
if (firstEnabledIndex !== undefined) {
|
|
83
|
+
selectByIndex(firstEnabledIndex);
|
|
84
|
+
controlRefs.current[firstEnabledIndex]?.focus();
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (event.key === "End") {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
const lastEnabledIndex = enabledIndexes[enabledIndexes.length - 1];
|
|
91
|
+
if (lastEnabledIndex !== undefined) {
|
|
92
|
+
selectByIndex(lastEnabledIndex);
|
|
93
|
+
controlRefs.current[lastEnabledIndex]?.focus();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return (_jsxs("div", { ref: ref, id: _id, role: "radiogroup", "data-disabled": disabled, "aria-disabled": disabled, className: cx("relative inline-flex items-stretch border border-[var(--refraktor-border)]", "bg-[var(--refraktor-bg-subtle)]", "data-[disabled=true]:opacity-50", fullWidth && "w-full", sizeStyles.root, getRadius(radius), classes.root, className), ...props, children: [data.map((item, index) => {
|
|
98
|
+
const isActive = item.value === selectedValue;
|
|
99
|
+
const isControlDisabled = !!(disabled || item.disabled);
|
|
100
|
+
return (_jsx("button", { ref: (node) => {
|
|
101
|
+
controlRefs.current[index] = node;
|
|
102
|
+
}, type: "button", role: "radio", id: `${_id}-control-${index}`, "aria-checked": isActive, "aria-disabled": isControlDisabled, "data-active": isActive, "data-disabled": isControlDisabled, disabled: isControlDisabled, tabIndex: isControlDisabled || tabStopIndex !== index
|
|
103
|
+
? -1
|
|
104
|
+
: 0, className: cx("relative inline-flex items-center justify-center whitespace-nowrap select-none outline-none transition-colors", "focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--refraktor-primary)]", "data-[disabled=true]:opacity-50 data-[disabled=true]:pointer-events-none data-[disabled=true]:cursor-not-allowed", fullWidth && "flex-1", sizeStyles.control, sizeStyles.label, getRadius(radius), isActive
|
|
105
|
+
? "bg-[var(--refraktor-primary)] text-[var(--refraktor-primary-text)]"
|
|
106
|
+
: "text-[var(--refraktor-text-secondary)] hover:bg-[var(--refraktor-bg-hover)] hover:text-[var(--refraktor-text)]", classes.control), onClick: () => selectByIndex(index), onKeyDown: (event) => handleKeyDown(event, index, isControlDisabled), children: _jsx("span", { className: cx("leading-none", classes.label), children: item.label }) }, item.value));
|
|
107
|
+
}), name && (_jsx("input", { type: "hidden", name: name, value: selectedValue }))] }));
|
|
108
|
+
});
|
|
109
|
+
SegmentedControl.displayName = "@refraktor/core/SegmentedControl";
|
|
110
|
+
SegmentedControl.configure = createComponentConfig();
|
|
111
|
+
SegmentedControl.classNames =
|
|
112
|
+
createClassNamesConfig();
|
|
113
|
+
export default SegmentedControl;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RefraktorSize } from "../../theme";
|
|
2
|
+
type SegmentedControlSizeStyles = {
|
|
3
|
+
root: string;
|
|
4
|
+
control: string;
|
|
5
|
+
label: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const getSize: (size?: RefraktorSize) => SegmentedControlSizeStyles;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=segmented-control.styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmented-control.styles.d.ts","sourceRoot":"","sources":["../../../src/components/segmented-control/segmented-control.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,KAAK,0BAA0B,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AA8BF,eAAO,MAAM,OAAO,GAAI,OAAM,aAAoB,+BAAgB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const sizes = {
|
|
2
|
+
xs: {
|
|
3
|
+
root: "p-0.5 gap-0.5",
|
|
4
|
+
control: "h-6 px-2 min-w-7",
|
|
5
|
+
label: "text-[10px]"
|
|
6
|
+
},
|
|
7
|
+
sm: {
|
|
8
|
+
root: "p-0.5 gap-0.5",
|
|
9
|
+
control: "h-7 px-2.5 min-w-8",
|
|
10
|
+
label: "text-xs"
|
|
11
|
+
},
|
|
12
|
+
md: {
|
|
13
|
+
root: "p-1 gap-1",
|
|
14
|
+
control: "h-8 px-3 min-w-9",
|
|
15
|
+
label: "text-sm"
|
|
16
|
+
},
|
|
17
|
+
lg: {
|
|
18
|
+
root: "p-1 gap-1",
|
|
19
|
+
control: "h-9 px-3.5 min-w-10",
|
|
20
|
+
label: "text-base"
|
|
21
|
+
},
|
|
22
|
+
xl: {
|
|
23
|
+
root: "p-1.5 gap-1.5",
|
|
24
|
+
control: "h-10 px-4 min-w-11",
|
|
25
|
+
label: "text-lg"
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export const getSize = (size = "md") => sizes[size];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmented-control.test.d.ts","sourceRoot":"","sources":["../../../src/components/segmented-control/segmented-control.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createRef, useState } from "react";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { render, screen, userEvent } from "../../vitest";
|
|
5
|
+
import SegmentedControl from "./segmented-control";
|
|
6
|
+
const data = [
|
|
7
|
+
{ value: "react", label: "React" },
|
|
8
|
+
{ value: "vue", label: "Vue" },
|
|
9
|
+
{ value: "svelte", label: "Svelte" }
|
|
10
|
+
];
|
|
11
|
+
describe("@refraktor/core/SegmentedControl", () => {
|
|
12
|
+
it("renders options and selected value", async () => {
|
|
13
|
+
await render(_jsx(SegmentedControl, { data: data, defaultValue: "react" }));
|
|
14
|
+
expect(screen.getByRole("radiogroup")).toBeInTheDocument();
|
|
15
|
+
expect(screen.getByRole("radio", { name: "React" })).toHaveAttribute("aria-checked", "true");
|
|
16
|
+
expect(screen.getByRole("radio", { name: "Vue" })).toHaveAttribute("aria-checked", "false");
|
|
17
|
+
});
|
|
18
|
+
it("forwards ref correctly", async () => {
|
|
19
|
+
const ref = createRef();
|
|
20
|
+
await render(_jsx(SegmentedControl, { ref: ref, data: data }));
|
|
21
|
+
expect(ref.current).toBeInstanceOf(HTMLDivElement);
|
|
22
|
+
expect(ref.current?.tagName).toBe("DIV");
|
|
23
|
+
});
|
|
24
|
+
it("handles click change events", async () => {
|
|
25
|
+
const user = userEvent.setup();
|
|
26
|
+
const onChange = vi.fn();
|
|
27
|
+
await render(_jsx(SegmentedControl, { data: data, defaultValue: "react", onChange: onChange }));
|
|
28
|
+
await user.click(screen.getByRole("radio", { name: "Vue" }));
|
|
29
|
+
expect(onChange).toHaveBeenCalledWith("vue");
|
|
30
|
+
expect(screen.getByRole("radio", { name: "Vue" })).toHaveAttribute("aria-checked", "true");
|
|
31
|
+
});
|
|
32
|
+
it("supports controlled mode", async () => {
|
|
33
|
+
const user = userEvent.setup();
|
|
34
|
+
function Demo() {
|
|
35
|
+
const [value, setValue] = useState("react");
|
|
36
|
+
return (_jsx(SegmentedControl, { data: data, value: value, onChange: setValue }));
|
|
37
|
+
}
|
|
38
|
+
await render(_jsx(Demo, {}));
|
|
39
|
+
await user.click(screen.getByRole("radio", { name: "Svelte" }));
|
|
40
|
+
expect(screen.getByRole("radio", { name: "Svelte" })).toHaveAttribute("aria-checked", "true");
|
|
41
|
+
});
|
|
42
|
+
it("does not select disabled item", async () => {
|
|
43
|
+
const user = userEvent.setup();
|
|
44
|
+
const onChange = vi.fn();
|
|
45
|
+
await render(_jsx(SegmentedControl, { defaultValue: "react", onChange: onChange, data: [
|
|
46
|
+
{ value: "react", label: "React" },
|
|
47
|
+
{ value: "vue", label: "Vue", disabled: true }
|
|
48
|
+
] }));
|
|
49
|
+
const disabledControl = screen.getByRole("radio", { name: "Vue" });
|
|
50
|
+
expect(disabledControl).toBeDisabled();
|
|
51
|
+
await user.click(disabledControl);
|
|
52
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
53
|
+
expect(disabledControl).toHaveAttribute("aria-checked", "false");
|
|
54
|
+
});
|
|
55
|
+
it("supports keyboard navigation and skips disabled items", async () => {
|
|
56
|
+
const user = userEvent.setup();
|
|
57
|
+
await render(_jsx(SegmentedControl, { defaultValue: "react", data: [
|
|
58
|
+
{ value: "react", label: "React" },
|
|
59
|
+
{ value: "vue", label: "Vue", disabled: true },
|
|
60
|
+
{ value: "svelte", label: "Svelte" }
|
|
61
|
+
] }));
|
|
62
|
+
const reactControl = screen.getByRole("radio", { name: "React" });
|
|
63
|
+
reactControl.focus();
|
|
64
|
+
await user.keyboard("{ArrowRight}");
|
|
65
|
+
const svelteControl = screen.getByRole("radio", { name: "Svelte" });
|
|
66
|
+
expect(svelteControl).toHaveFocus();
|
|
67
|
+
expect(svelteControl).toHaveAttribute("aria-checked", "true");
|
|
68
|
+
});
|
|
69
|
+
it("supports root and slot class names", async () => {
|
|
70
|
+
const { container } = await render(_jsx(SegmentedControl, { data: data, className: "custom-root", classNames: {
|
|
71
|
+
control: "custom-control",
|
|
72
|
+
label: "custom-label"
|
|
73
|
+
} }));
|
|
74
|
+
const root = container.firstElementChild;
|
|
75
|
+
const control = screen.getByRole("radio", { name: "React" });
|
|
76
|
+
const label = screen.getByText("React");
|
|
77
|
+
expect(root).toHaveClass("custom-root");
|
|
78
|
+
expect(control).toHaveClass("custom-control");
|
|
79
|
+
expect(label).toHaveClass("custom-label");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import { RefraktorRadius, RefraktorSize } from "../../theme";
|
|
3
|
+
import { createClassNamesConfig, createComponentConfig, FactoryPayload } from "../../utils";
|
|
4
|
+
export interface SegmentedControlItem {
|
|
5
|
+
/** Item value */
|
|
6
|
+
value: string;
|
|
7
|
+
/** Item label */
|
|
8
|
+
label: ReactNode;
|
|
9
|
+
/** Whether item is disabled */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type SegmentedControlClassNames = {
|
|
13
|
+
root?: string;
|
|
14
|
+
control?: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
};
|
|
17
|
+
export interface SegmentedControlProps extends Omit<ComponentPropsWithoutRef<"div">, "onChange"> {
|
|
18
|
+
/** Items to render */
|
|
19
|
+
data: SegmentedControlItem[];
|
|
20
|
+
/** Selected value (controlled) */
|
|
21
|
+
value?: string;
|
|
22
|
+
/** Initial selected value (uncontrolled) */
|
|
23
|
+
defaultValue?: string;
|
|
24
|
+
/** Callback called when selected value changes */
|
|
25
|
+
onChange?: (value: string) => void;
|
|
26
|
+
/** The size of segmented control @default `md` */
|
|
27
|
+
size?: RefraktorSize;
|
|
28
|
+
/** The radius of segmented control @default `default` */
|
|
29
|
+
radius?: RefraktorRadius;
|
|
30
|
+
/** Whether segmented control should take full width @default `false` */
|
|
31
|
+
fullWidth?: boolean;
|
|
32
|
+
/** Whether segmented control is disabled @default `false` */
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/** Hidden input name for forms */
|
|
35
|
+
name?: string;
|
|
36
|
+
/** Used for editing root class name */
|
|
37
|
+
className?: string;
|
|
38
|
+
/** Used for styling different parts of the component */
|
|
39
|
+
classNames?: SegmentedControlClassNames;
|
|
40
|
+
}
|
|
41
|
+
export interface SegmentedControlFactoryPayload extends FactoryPayload {
|
|
42
|
+
props: SegmentedControlProps;
|
|
43
|
+
ref: HTMLDivElement;
|
|
44
|
+
compound: {
|
|
45
|
+
configure: ReturnType<typeof createComponentConfig<SegmentedControlProps>>;
|
|
46
|
+
classNames: ReturnType<typeof createClassNamesConfig<SegmentedControlClassNames>>;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=segmented-control.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmented-control.types.d.ts","sourceRoot":"","sources":["../../../src/components/segmented-control/segmented-control.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACjB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,oBAAoB;IACjC,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IAEd,iBAAiB;IACjB,KAAK,EAAE,SAAS,CAAC;IAEjB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,0BAA0B,GAAG;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAC/C,wBAAwB,CAAC,KAAK,CAAC,EAC/B,UAAU,CACb;IACG,sBAAsB;IACtB,IAAI,EAAE,oBAAoB,EAAE,CAAC;IAE7B,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,4CAA4C;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAEnC,kDAAkD;IAClD,IAAI,CAAC,EAAE,aAAa,CAAC;IAErB,yDAAyD;IACzD,MAAM,CAAC,EAAE,eAAe,CAAC;IAEzB,wEAAwE;IACxE,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,wDAAwD;IACxD,UAAU,CAAC,EAAE,0BAA0B,CAAC;CAC3C;AAED,MAAM,WAAW,8BAA+B,SAAQ,cAAc;IAClE,KAAK,EAAE,qBAAqB,CAAC;IAC7B,GAAG,EAAE,cAAc,CAAC;IACpB,QAAQ,EAAE;QACN,SAAS,EAAE,UAAU,CACjB,OAAO,qBAAqB,CAAC,qBAAqB,CAAC,CACtD,CAAC;QACF,UAAU,EAAE,UAAU,CAClB,OAAO,sBAAsB,CAAC,0BAA0B,CAAC,CAC5D,CAAC;KACL,CAAC;CACL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-dropdown.d.ts","sourceRoot":"","sources":["../../../../src/components/select/select-dropdown/select-dropdown.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAOpE,QAAA,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"select-dropdown.d.ts","sourceRoot":"","sources":["../../../../src/components/select/select-dropdown/select-dropdown.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAOpE,QAAA,MAAM,cAAc,qEAoRnB,CAAC;AAIF,eAAe,cAAc,CAAC"}
|
|
@@ -142,8 +142,9 @@ const SelectDropdown = factory(({ children, className, style, onKeyDown, ...prop
|
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
const referenceWidth = select.select.refs.reference.current?.offsetWidth;
|
|
145
|
-
const dropdownContent = (_jsx(Transition, { transition: "fade", duration: 150, mounted: select.select.opened, ...select.transitionProps, children: _jsxs("div", { ref: useMergeRefs([ref, select.select.refs.setFloating]), id: select.listId, role: "listbox", "aria-labelledby": select.triggerId, tabIndex: -1, style: {
|
|
145
|
+
const dropdownContent = (_jsx(Transition, { transition: "fade", duration: 150, mounted: select.select.opened, style: { position: "relative", zIndex: 1000 }, ...select.transitionProps, children: _jsxs("div", { ref: useMergeRefs([ref, select.select.refs.setFloating]), id: select.listId, role: "listbox", "aria-labelledby": select.triggerId, tabIndex: -1, style: {
|
|
146
146
|
...select.select.floatingStyles,
|
|
147
|
+
zIndex: 1000,
|
|
147
148
|
width: referenceWidth,
|
|
148
149
|
...style
|
|
149
150
|
}, className: cx("z-50 min-w-32 bg-[var(--refraktor-bg)] text-[var(--refraktor-text)] shadow-md border border-[var(--refraktor-border)]", getRadius(select.radius), select.getStyles("dropdown"), className), ...select.select.getFloatingProps({
|
|
@@ -153,7 +154,7 @@ const SelectDropdown = factory(({ children, className, style, onKeyDown, ...prop
|
|
|
153
154
|
}, value: select.search, onChange: (event) => {
|
|
154
155
|
select.setSearch(event.currentTarget.value);
|
|
155
156
|
}, size: select.size, radius: select.radius, variant: select.variant, placeholder: select.searchPlaceholder, autoComplete: "off", className: select.getStyles("searchInput") }) })), _jsxs("div", { className: cx("max-h-80 overflow-y-auto refraktor-scrollbar p-1", select.getStyles("options")), children: [children, !select.hasVisibleItems() && (_jsx("div", { className: cx("px-1.5 py-1.5 text-sm text-[var(--refraktor-text-secondary)]", select.getStyles("empty")), children: select.nothingFound }))] })] }) }));
|
|
156
|
-
const wrappedContent =
|
|
157
|
+
const wrappedContent = (_jsx(FloatingFocusManager, { context: select.select.context, modal: false, initialFocus: -1, disabled: !select.select.opened, children: dropdownContent }));
|
|
157
158
|
return select.withinPortal ? (_jsx(FloatingPortal, { children: wrappedContent })) : (wrappedContent);
|
|
158
159
|
});
|
|
159
160
|
SelectDropdown.displayName = "@refraktor/core/Select.Dropdown";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-item.d.ts","sourceRoot":"","sources":["../../../../src/components/select/select-item/select-item.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE,QAAA,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"select-item.d.ts","sourceRoot":"","sources":["../../../../src/components/select/select-item/select-item.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE,QAAA,MAAM,UAAU,iEA2If,CAAC;AAIF,eAAe,UAAU,CAAC"}
|
|
@@ -49,7 +49,7 @@ const SelectItem = factory(({ id, value, children, disabled, textValue, classNam
|
|
|
49
49
|
else if (ref) {
|
|
50
50
|
ref.current = node;
|
|
51
51
|
}
|
|
52
|
-
}, id: _id, type: "button", role: "option", tabIndex: -1, disabled: disabled, hidden: !isVisible, "data-selected": isSelected, "data-disabled": disabled, "aria-selected": isSelected, "aria-disabled": disabled, className: cx("w-full text-left p-1.5 text-
|
|
52
|
+
}, id: _id, type: "button", role: "option", tabIndex: -1, disabled: disabled, hidden: !isVisible, "data-selected": isSelected, "data-disabled": disabled, "aria-selected": isSelected, "aria-disabled": disabled, className: cx("w-full text-left p-1.5 text-xs rounded-none appearance-none border-none bg-transparent", "inline-flex items-center gap-2 outline-none transition-colors", "hover:bg-[var(--refraktor-bg-hover)] focus-visible:bg-[var(--refraktor-bg-hover)]", "data-[disabled=true]:opacity-50 data-[disabled=true]:pointer-events-none data-[disabled=true]:cursor-not-allowed", getRadius(select.radius), select.getStyles("item"), className), onMouseMove: (event) => {
|
|
53
53
|
onMouseMove?.(event);
|
|
54
54
|
if (!disabled &&
|
|
55
55
|
document.activeElement !== event.currentTarget) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-root.d.ts","sourceRoot":"","sources":["../../../../src/components/select/select-root/select-root.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"select-root.d.ts","sourceRoot":"","sources":["../../../../src/components/select/select-root/select-root.tsx"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAER,wBAAwB,EAE3B,MAAM,iBAAiB,CAAC;AA0DzB,QAAA,MAAM,UAAU,iEAmPd,CAAC;AAIH,eAAe,UAAU,CAAC"}
|