@kala-ui/react 0.0.1-beta.7 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/accordion/accordion-skeleton.js +1 -1
- package/dist/components/accordion/accordion.js +2 -1
- package/dist/components/action-icon/action-icon.d.ts +12 -0
- package/dist/components/action-icon/action-icon.js +35 -0
- package/dist/components/action-icon/action-icon.stories.d.ts +9 -0
- package/dist/components/action-icon/action-icon.stories.js +42 -0
- package/dist/components/action-icon/index.d.ts +1 -0
- package/dist/components/action-icon/index.js +1 -0
- package/dist/components/alert/alert-skeleton.js +4 -3
- package/dist/components/alert/alert.d.ts +2 -2
- package/dist/components/alert/alert.js +8 -6
- package/dist/components/alert/alert.stories.js +13 -9
- package/dist/components/alert/index.d.ts +1 -1
- package/dist/components/alert-dialog/alert-dialog.js +8 -5
- package/dist/components/app-shell/app-shell.d.ts +58 -0
- package/dist/components/app-shell/app-shell.js +111 -0
- package/dist/components/app-shell/app-shell.stories.d.ts +8 -0
- package/dist/components/app-shell/app-shell.stories.js +35 -0
- package/dist/components/app-shell/index.d.ts +1 -0
- package/dist/components/app-shell/index.js +1 -0
- package/dist/components/avatar/avatar.d.ts +2 -2
- package/dist/components/avatar/avatar.stories.js +1 -1
- package/dist/components/badge/badge.d.ts +1 -1
- package/dist/components/badge/badge.js +1 -1
- package/dist/components/badge/badge.stories.js +1 -1
- package/dist/components/banner/banner-skeleton.js +1 -1
- package/dist/components/banner/banner.d.ts +1 -1
- package/dist/components/banner/banner.stories.js +1 -1
- package/dist/components/box/box.d.ts +8 -0
- package/dist/components/box/box.js +10 -0
- package/dist/components/box/box.stories.d.ts +8 -0
- package/dist/components/box/box.stories.js +32 -0
- package/dist/components/box/index.d.ts +1 -0
- package/dist/components/box/index.js +1 -0
- package/dist/components/breadcrumbs/breadcrumbs-skeleton.js +1 -1
- package/dist/components/breadcrumbs/breadcrumbs.stories.js +1 -1
- package/dist/components/burger/burger.d.ts +8 -0
- package/dist/components/burger/burger.js +21 -0
- package/dist/components/burger/burger.stories.d.ts +8 -0
- package/dist/components/burger/burger.stories.js +31 -0
- package/dist/components/burger/index.d.ts +1 -0
- package/dist/components/burger/index.js +1 -0
- package/dist/components/button/button.d.ts +2 -2
- package/dist/components/button/button.stories.js +10 -7
- package/dist/components/button-group/button-group.stories.js +1 -1
- package/dist/components/calendar/calendar-skeleton.js +1 -1
- package/dist/components/calendar/calendar.d.ts +1 -1
- package/dist/components/calendar/calendar.js +1 -1
- package/dist/components/calendar/calendar.types.d.ts +3 -3
- package/dist/components/card/card-skeleton.js +2 -2
- package/dist/components/card/card.js +17 -14
- package/dist/components/card/index.d.ts +1 -1
- package/dist/components/center/center.d.ts +7 -0
- package/dist/components/center/center.js +10 -0
- package/dist/components/center/center.stories.d.ts +7 -0
- package/dist/components/center/center.stories.js +25 -0
- package/dist/components/center/index.d.ts +1 -0
- package/dist/components/center/index.js +1 -0
- package/dist/components/charts/area-chart.js +1 -1
- package/dist/components/charts/bar-chart.js +1 -1
- package/dist/components/charts/donut-chart.js +1 -1
- package/dist/components/charts/index.d.ts +2 -2
- package/dist/components/charts/index.js +2 -2
- package/dist/components/charts/line-chart.js +1 -1
- package/dist/components/charts/radial-bar-chart.js +1 -1
- package/dist/components/charts/theme-utils.d.ts +1 -1
- package/dist/components/charts/use-theme-aware-chart.d.ts +1 -1
- package/dist/components/charts/use-theme-aware-chart.js +2 -1
- package/dist/components/checkbox/checkbox.js +1 -1
- package/dist/components/checkbox/checkbox.stories.js +12 -8
- package/dist/components/close-button/close-button.d.ts +7 -0
- package/dist/components/close-button/close-button.js +9 -0
- package/dist/components/close-button/close-button.stories.d.ts +7 -0
- package/dist/components/close-button/close-button.stories.js +18 -0
- package/dist/components/close-button/index.d.ts +1 -0
- package/dist/components/close-button/index.js +1 -0
- package/dist/components/code/code.d.ts +8 -0
- package/dist/components/code/code.js +14 -0
- package/dist/components/code/code.stories.d.ts +8 -0
- package/dist/components/code/code.stories.js +31 -0
- package/dist/components/code/index.d.ts +1 -0
- package/dist/components/code/index.js +1 -0
- package/dist/components/collapse/collapse.d.ts +17 -0
- package/dist/components/collapse/collapse.js +34 -0
- package/dist/components/collapse/index.d.ts +1 -0
- package/dist/components/collapse/index.js +1 -0
- package/dist/components/color-input/color-input.d.ts +28 -0
- package/dist/components/color-input/color-input.js +35 -0
- package/dist/components/color-input/color-input.stories.d.ts +10 -0
- package/dist/components/color-input/color-input.stories.js +41 -0
- package/dist/components/color-input/index.d.ts +1 -0
- package/dist/components/color-input/index.js +1 -0
- package/dist/components/combobox/combobox-skeleton.js +1 -1
- package/dist/components/combobox/combobox.d.ts +1 -1
- package/dist/components/combobox/combobox.js +17 -8
- package/dist/components/combobox/combobox.stories.js +1 -1
- package/dist/components/command/command.d.ts +2 -2
- package/dist/components/command/command.stories.js +14 -19
- package/dist/components/container/container.d.ts +1 -1
- package/dist/components/container/index.d.ts +1 -1
- package/dist/components/container/index.js +1 -1
- package/dist/components/data-table/column-header-filter.js +11 -6
- package/dist/components/data-table/data-table-skeleton.js +5 -15
- package/dist/components/data-table/data-table.js +18 -15
- package/dist/components/data-table/data-table.stories.js +3 -5
- package/dist/components/date-picker/date-picker.d.ts +1 -1
- package/dist/components/date-picker/date-picker.js +3 -3
- package/dist/components/date-picker/date-picker.types.d.ts +1 -1
- package/dist/components/dialog/dialog-skeleton.js +1 -1
- package/dist/components/dialog/dialog.js +6 -4
- package/dist/components/dialog/dialog.stories.js +2 -2
- package/dist/components/dnd/dnd.d.ts +4 -5
- package/dist/components/dnd/dnd.js +5 -5
- package/dist/components/dnd/dnd.stories.js +48 -40
- package/dist/components/drawer/drawer.stories.js +2 -2
- package/dist/components/empty-state/empty-state-skeleton.js +2 -3
- package/dist/components/empty-state/empty-state.d.ts +1 -1
- package/dist/components/field/field-skeleton.js +1 -1
- package/dist/components/field/field.stories.js +1 -1
- package/dist/components/file-upload/file-upload-skeleton.js +1 -1
- package/dist/components/flex/flex.d.ts +7 -5
- package/dist/components/flex/flex.js +2 -2
- package/dist/components/flex/index.d.ts +1 -1
- package/dist/components/flex/index.js +1 -1
- package/dist/components/grid/grid.d.ts +24 -0
- package/dist/components/grid/grid.js +136 -0
- package/dist/components/grid/grid.stories.d.ts +8 -0
- package/dist/components/grid/grid.stories.js +31 -0
- package/dist/components/grid/index.d.ts +1 -0
- package/dist/components/grid/index.js +1 -0
- package/dist/components/group/group.d.ts +2 -2
- package/dist/components/group/group.js +1 -1
- package/dist/components/group/index.d.ts +1 -1
- package/dist/components/group/index.js +1 -1
- package/dist/components/header/header-skeleton.js +1 -1
- package/dist/components/header/header.d.ts +3 -3
- package/dist/components/header/header.js +17 -31
- package/dist/components/header/index.d.ts +1 -1
- package/dist/components/heading/heading.d.ts +4 -2
- package/dist/components/heading/heading.js +3 -7
- package/dist/components/heading/index.d.ts +1 -1
- package/dist/components/heading/index.js +1 -1
- package/dist/components/indicator/index.d.ts +1 -0
- package/dist/components/indicator/index.js +1 -0
- package/dist/components/indicator/indicator.d.ts +30 -0
- package/dist/components/indicator/indicator.js +89 -0
- package/dist/components/indicator/indicator.stories.d.ts +10 -0
- package/dist/components/indicator/indicator.stories.js +75 -0
- package/dist/components/input/input.js +1 -1
- package/dist/components/input/input.stories.js +1 -1
- package/dist/components/input-group/input-group.stories.js +1 -1
- package/dist/components/kbd/index.d.ts +1 -0
- package/dist/components/kbd/index.js +1 -0
- package/dist/components/kbd/kbd.d.ts +6 -0
- package/dist/components/kbd/kbd.js +13 -0
- package/dist/components/kbd/kbd.stories.d.ts +9 -0
- package/dist/components/kbd/kbd.stories.js +28 -0
- package/dist/components/label/label.stories.js +1 -1
- package/dist/components/list/list-skeleton.js +2 -2
- package/dist/components/list/list.js +1 -1
- package/dist/components/list/list.stories.js +1 -1
- package/dist/components/list/list.types.d.ts +2 -2
- package/dist/components/loading-overlay/index.d.ts +1 -0
- package/dist/components/loading-overlay/index.js +1 -0
- package/dist/components/loading-overlay/loading-overlay.d.ts +19 -0
- package/dist/components/loading-overlay/loading-overlay.js +19 -0
- package/dist/components/loading-overlay/loading-overlay.stories.d.ts +8 -0
- package/dist/components/loading-overlay/loading-overlay.stories.js +46 -0
- package/dist/components/metric-card/metric-card-skeleton.js +2 -2
- package/dist/components/metric-card/metric-card.js +1 -1
- package/dist/components/multi-select/multi-select-skeleton.js +1 -1
- package/dist/components/multi-select/multi-select.stories.js +1 -1
- package/dist/components/nav-link/index.d.ts +1 -0
- package/dist/components/nav-link/index.js +1 -0
- package/dist/components/nav-link/nav-link.d.ts +26 -0
- package/dist/components/nav-link/nav-link.js +26 -0
- package/dist/components/nav-link/nav-link.stories.d.ts +9 -0
- package/dist/components/nav-link/nav-link.stories.js +37 -0
- package/dist/components/navigation/navigation-skeleton.js +1 -1
- package/dist/components/number-input/index.d.ts +1 -0
- package/dist/components/number-input/index.js +1 -0
- package/dist/components/number-input/number-input.d.ts +40 -0
- package/dist/components/number-input/number-input.js +69 -0
- package/dist/components/number-input/number-input.stories.d.ts +11 -0
- package/dist/components/number-input/number-input.stories.js +54 -0
- package/dist/components/overlay/index.d.ts +1 -0
- package/dist/components/overlay/index.js +1 -0
- package/dist/components/overlay/overlay.d.ts +22 -0
- package/dist/components/overlay/overlay.js +45 -0
- package/dist/components/overlay/overlay.stories.d.ts +9 -0
- package/dist/components/overlay/overlay.stories.js +47 -0
- package/dist/components/page-transition/page-transition.stories.js +1 -1
- package/dist/components/pagination/index.d.ts +1 -1
- package/dist/components/pagination/index.js +1 -1
- package/dist/components/pagination/pagination-skeleton.js +1 -1
- package/dist/components/pagination/pagination.d.ts +44 -28
- package/dist/components/pagination/pagination.js +53 -79
- package/dist/components/pagination/pagination.stories.d.ts +1 -0
- package/dist/components/pagination/pagination.stories.js +31 -5
- package/dist/components/paper/index.d.ts +1 -0
- package/dist/components/paper/index.js +1 -0
- package/dist/components/paper/paper.d.ts +12 -0
- package/dist/components/paper/paper.js +39 -0
- package/dist/components/paper/paper.stories.d.ts +7 -0
- package/dist/components/paper/paper.stories.js +30 -0
- package/dist/components/password-strength-indicator/password-strength-indicator.stories.js +1 -1
- package/dist/components/popover/popover-skeleton.js +1 -1
- package/dist/components/popover/popover.stories.js +2 -2
- package/dist/components/progress/index.d.ts +1 -1
- package/dist/components/progress/progress.d.ts +1 -1
- package/dist/components/progress/progress.stories.js +1 -1
- package/dist/components/radio-group/radio-group-skeleton.js +1 -1
- package/dist/components/radio-group/radio-group.stories.js +1 -1
- package/dist/components/resizable/resizable.stories.js +8 -8
- package/dist/components/ring-progress/index.d.ts +1 -0
- package/dist/components/ring-progress/index.js +1 -0
- package/dist/components/ring-progress/ring-progress.d.ts +24 -0
- package/dist/components/ring-progress/ring-progress.js +20 -0
- package/dist/components/ring-progress/ring-progress.stories.d.ts +9 -0
- package/dist/components/ring-progress/ring-progress.stories.js +46 -0
- package/dist/components/scroll-area/scroll-area.stories.js +26 -26
- package/dist/components/segmented-control/index.d.ts +1 -0
- package/dist/components/segmented-control/index.js +1 -0
- package/dist/components/segmented-control/segmented-control.d.ts +19 -0
- package/dist/components/segmented-control/segmented-control.js +46 -0
- package/dist/components/segmented-control/segmented-control.stories.d.ts +10 -0
- package/dist/components/segmented-control/segmented-control.stories.js +53 -0
- package/dist/components/select/select.js +1 -1
- package/dist/components/select/select.stories.js +1 -1
- package/dist/components/separator/separator.stories.js +1 -1
- package/dist/components/session-card/session-card-skeleton.js +2 -2
- package/dist/components/session-card/session-card.js +1 -1
- package/dist/components/sidebar/sidebar-skeleton.js +2 -2
- package/dist/components/skeleton/index.d.ts +3 -3
- package/dist/components/skeleton/index.js +1 -1
- package/dist/components/skeleton/skeleton.types.d.ts +0 -249
- package/dist/components/slider/index.d.ts +1 -1
- package/dist/components/slider/slider.js +1 -1
- package/dist/components/slider/slider.stories.js +1 -1
- package/dist/components/social-login-button/social-login-button.js +6 -6
- package/dist/components/sparkline-chart/sparkline-chart.js +6 -3
- package/dist/components/sparkline-chart/sparkline-chart.stories.js +1 -1
- package/dist/components/spinner/spinner.d.ts +1 -1
- package/dist/components/spoiler/index.d.ts +1 -0
- package/dist/components/spoiler/index.js +1 -0
- package/dist/components/spoiler/spoiler.d.ts +14 -0
- package/dist/components/spoiler/spoiler.js +20 -0
- package/dist/components/spoiler/spoiler.stories.d.ts +8 -0
- package/dist/components/spoiler/spoiler.stories.js +35 -0
- package/dist/components/stack/index.d.ts +1 -1
- package/dist/components/stack/index.js +1 -1
- package/dist/components/stack/stack.d.ts +2 -2
- package/dist/components/stack/stack.js +1 -1
- package/dist/components/steps/steps-skeleton.js +1 -1
- package/dist/components/steps/steps.js +7 -5
- package/dist/components/steps/steps.stories.js +6 -2
- package/dist/components/switch/index.d.ts +1 -1
- package/dist/components/switch/switch.js +1 -1
- package/dist/components/switch/switch.stories.js +1 -1
- package/dist/components/table/table-skeleton.js +2 -2
- package/dist/components/table/table.js +4 -3
- package/dist/components/table/table.stories.js +10 -7
- package/dist/components/tabs/tabs-skeleton.js +1 -1
- package/dist/components/tabs/tabs.d.ts +3 -3
- package/dist/components/tabs/tabs.js +1 -1
- package/dist/components/tabs/tabs.stories.js +5 -5
- package/dist/components/text/index.d.ts +1 -1
- package/dist/components/text/index.js +1 -1
- package/dist/components/text/text.d.ts +7 -5
- package/dist/components/text/text.js +2 -2
- package/dist/components/text/text.stories.js +34 -3
- package/dist/components/textarea/textarea.js +1 -1
- package/dist/components/textarea/textarea.stories.js +1 -1
- package/dist/components/timeline/index.d.ts +1 -0
- package/dist/components/timeline/index.js +1 -0
- package/dist/components/timeline/timeline.d.ts +35 -0
- package/dist/components/timeline/timeline.js +36 -0
- package/dist/components/timeline/timeline.stories.d.ts +7 -0
- package/dist/components/timeline/timeline.stories.js +21 -0
- package/dist/components/toast/toast.js +6 -6
- package/dist/components/toggle/toggle.stories.js +1 -1
- package/dist/components/tooltip/tooltip.stories.js +1 -1
- package/dist/components/user-menu-dropdown/user-menu-dropdown.js +1 -1
- package/dist/config/tailwind-base.d.ts +10 -0
- package/dist/config/tailwind-base.js +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +25 -10
- package/dist/lib/animations.js +94 -94
- package/dist/primitives/command/Command.js +2 -1
- package/dist/styles/globals.css +415 -82
- package/package.json +101 -24
|
@@ -33,7 +33,8 @@ export function useThemeAwareChart() {
|
|
|
33
33
|
return;
|
|
34
34
|
const observer = new MutationObserver((mutations) => {
|
|
35
35
|
mutations.forEach((mutation) => {
|
|
36
|
-
if (mutation.type === "attributes" &&
|
|
36
|
+
if (mutation.type === "attributes" &&
|
|
37
|
+
mutation.attributeName === "class") {
|
|
37
38
|
const element = document.documentElement;
|
|
38
39
|
const classList = element.classList;
|
|
39
40
|
let newTheme = "light";
|
|
@@ -4,7 +4,7 @@ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
|
4
4
|
import { Check, Minus } from "lucide-react";
|
|
5
5
|
import { checkboxIndicatorStyles, checkboxStyles } from "../../config/checkbox";
|
|
6
6
|
import { cn } from "../../lib/utils";
|
|
7
|
-
import { Skeleton } from "../skeleton
|
|
7
|
+
import { Skeleton } from "../skeleton";
|
|
8
8
|
function Checkbox({ className, isLoading = false, ...props }) {
|
|
9
9
|
if (isLoading) {
|
|
10
10
|
return _jsx(Skeleton, { className: cn("h-4 w-4 rounded", className) });
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
+
import { Box } from "../box";
|
|
4
|
+
import { Flex } from "../flex";
|
|
3
5
|
import { Label } from "../label";
|
|
4
|
-
import { Skeleton } from "../skeleton
|
|
6
|
+
import { Skeleton } from "../skeleton";
|
|
7
|
+
import { Stack } from "../stack";
|
|
8
|
+
import { Text } from "../text";
|
|
5
9
|
import { Checkbox } from "./checkbox";
|
|
6
10
|
const meta = {
|
|
7
11
|
title: "Forms/Checkbox",
|
|
@@ -23,19 +27,19 @@ const meta = {
|
|
|
23
27
|
export default meta;
|
|
24
28
|
// All States Showcase
|
|
25
29
|
export const AllStates = {
|
|
26
|
-
render: () => (_jsxs(
|
|
30
|
+
render: () => (_jsxs(Stack, { gap: 4, children: [_jsxs(Flex, { align: "center", gap: 4, children: [_jsx(Text, { size: "sm", weight: "medium", className: "w-40", children: "Unchecked:" }), _jsx(Checkbox, { "aria-label": "Unchecked checkbox" })] }), _jsxs(Flex, { align: "center", gap: 4, children: [_jsx(Text, { size: "sm", weight: "medium", className: "w-40", children: "Checked:" }), _jsx(Checkbox, { defaultChecked: true, "aria-label": "Checked checkbox" })] }), _jsxs(Flex, { align: "center", gap: 4, children: [_jsx(Text, { size: "sm", weight: "medium", className: "w-40", children: "Indeterminate:" }), _jsx(Checkbox, { checked: "indeterminate", "aria-label": "Indeterminate checkbox" })] }), _jsxs(Flex, { align: "center", gap: 4, children: [_jsx(Text, { size: "sm", weight: "medium", className: "w-40", children: "Disabled:" }), _jsx(Checkbox, { disabled: true, "aria-label": "Disabled unchecked checkbox" })] }), _jsxs(Flex, { align: "center", gap: 4, children: [_jsx(Text, { size: "sm", weight: "medium", className: "w-40", children: "Disabled Checked:" }), _jsx(Checkbox, { disabled: true, defaultChecked: true, "aria-label": "Disabled checked checkbox" })] }), _jsxs(Flex, { align: "center", gap: 4, children: [_jsx(Text, { size: "sm", weight: "medium", className: "w-40", children: "Disabled Indeterminate:" }), _jsx(Checkbox, { disabled: true, checked: "indeterminate", "aria-label": "Disabled indeterminate checkbox" })] })] })),
|
|
27
31
|
};
|
|
28
32
|
// With Labels and Descriptions
|
|
29
33
|
export const WithLabels = {
|
|
30
|
-
render: () => (_jsxs(
|
|
34
|
+
render: () => (_jsxs(Stack, { gap: 6, children: [_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "simple-label" }), _jsx(Label, { htmlFor: "simple-label", children: "Accept terms and conditions" })] }), _jsxs(Flex, { align: "start", gap: 3, children: [_jsx(Checkbox, { id: "with-description", defaultChecked: true }), _jsxs(Box, { className: "grid gap-1.5", children: [_jsx(Label, { htmlFor: "with-description", children: "Enable notifications" }), _jsx(Text, { size: "sm", className: "text-muted-foreground", children: "You can enable or disable notifications at any time in your settings." })] })] }), _jsxs(Label, { htmlFor: "interactive-card", className: "flex cursor-pointer items-start gap-3 rounded-lg border border-input p-4 transition-all hover:bg-accent hover:text-accent-foreground has-aria-checked:border-primary has-aria-checked:bg-primary/10 h-auto", children: [_jsx(Checkbox, { id: "interactive-card", defaultChecked: true }), _jsxs(Box, { className: "grid gap-1.5", children: [_jsx(Text, { size: "sm", weight: "medium", className: "leading-none", children: "Marketing emails" }), _jsx(Text, { size: "sm", className: "text-muted-foreground", children: "Receive emails about new products, features, and updates." })] })] })] })),
|
|
31
35
|
};
|
|
32
36
|
// Multiple Options and Layouts
|
|
33
37
|
export const MultipleOptions = {
|
|
34
|
-
render: () => (_jsxs(
|
|
38
|
+
render: () => (_jsxs(Stack, { gap: 8, children: [_jsxs(Box, { children: [_jsx(Text, { weight: "semibold", size: "sm", className: "mb-3", children: "Vertical Layout" }), _jsxs(Stack, { gap: 3, children: [_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "option1", defaultChecked: true }), _jsx(Label, { htmlFor: "option1", children: "Option 1" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "option2" }), _jsx(Label, { htmlFor: "option2", children: "Option 2" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "option3", defaultChecked: true }), _jsx(Label, { htmlFor: "option3", children: "Option 3" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "option4", disabled: true }), _jsx(Label, { htmlFor: "option4", className: "text-muted-foreground", children: "Disabled option" })] })] })] }), _jsxs(Box, { children: [_jsx(Text, { weight: "semibold", size: "sm", className: "mb-3", children: "Inline Layout" }), _jsxs(Flex, { wrap: "wrap", align: "center", gap: 4, children: [_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "inline1", defaultChecked: true }), _jsx(Label, { htmlFor: "inline1", children: "Option A" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "inline2" }), _jsx(Label, { htmlFor: "inline2", children: "Option B" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "inline3", defaultChecked: true }), _jsx(Label, { htmlFor: "inline3", children: "Option C" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "inline4" }), _jsx(Label, { htmlFor: "inline4", children: "Option D" })] })] })] })] })),
|
|
35
39
|
};
|
|
36
40
|
// Form Examples
|
|
37
41
|
export const FormExamples = {
|
|
38
|
-
render: () => (_jsxs(
|
|
42
|
+
render: () => (_jsxs(Flex, { gap: 6, children: [_jsxs(Box, { className: "w-72 rounded-md border p-4", children: [_jsx(Text, { weight: "semibold", className: "mb-4 text-base", children: "Notification Preferences" }), _jsxs(Stack, { gap: 3, children: [_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "email-pref", defaultChecked: true }), _jsx(Label, { htmlFor: "email-pref", children: "Email notifications" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "push-pref", defaultChecked: true }), _jsx(Label, { htmlFor: "push-pref", children: "Push notifications" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "sms-pref" }), _jsx(Label, { htmlFor: "sms-pref", children: "SMS notifications" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "marketing-pref" }), _jsx(Label, { htmlFor: "marketing-pref", children: "Marketing emails" })] })] })] }), _jsxs(Stack, { gap: 6, className: "w-80", children: [_jsxs(Box, { children: [_jsx(Text, { weight: "semibold", size: "sm", className: "mb-3", children: "Account Settings" }), _jsxs(Stack, { gap: 3, children: [_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "public-profile" }), _jsx(Label, { htmlFor: "public-profile", children: "Make profile public" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "show-email" }), _jsx(Label, { htmlFor: "show-email", children: "Show email address" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "searchable", defaultChecked: true }), _jsx(Label, { htmlFor: "searchable", children: "Searchable by others" })] })] })] }), _jsxs(Box, { children: [_jsx(Text, { weight: "semibold", size: "sm", className: "mb-3", children: "Privacy" }), _jsxs(Stack, { gap: 3, children: [_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "analytics", defaultChecked: true }), _jsx(Label, { htmlFor: "analytics", children: "Analytics cookies" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: "cookies" }), _jsx(Label, { htmlFor: "cookies", children: "Marketing cookies" })] })] })] })] })] })),
|
|
39
43
|
};
|
|
40
44
|
// Select All with Indeterminate (Interactive)
|
|
41
45
|
export const SelectAllInteractive = {
|
|
@@ -55,15 +59,15 @@ export const SelectAllInteractive = {
|
|
|
55
59
|
const handleItemChange = (id) => {
|
|
56
60
|
setItems(items.map((item) => item.id === id ? { ...item, checked: !item.checked } : item));
|
|
57
61
|
};
|
|
58
|
-
return (_jsxs(
|
|
62
|
+
return (_jsxs(Box, { className: "w-80 rounded-md border p-4", children: [_jsxs(Flex, { align: "center", gap: 2, className: "mb-4 border-b pb-3", children: [_jsx(Checkbox, { id: "select-all", checked: allChecked ? true : someChecked ? "indeterminate" : false, onCheckedChange: handleSelectAll, "aria-label": allChecked
|
|
59
63
|
? "Deselect all items"
|
|
60
64
|
: someChecked
|
|
61
65
|
? "Select all items (partial selection)"
|
|
62
|
-
: "Select all items" }), _jsxs(Label, { htmlFor: "select-all", className: "font-semibold", children: ["Select All (", checkedCount, "/", items.length, ")"] })] }), _jsx(
|
|
66
|
+
: "Select all items" }), _jsxs(Label, { htmlFor: "select-all", className: "font-semibold", children: ["Select All (", checkedCount, "/", items.length, ")"] })] }), _jsx(Stack, { gap: 3, children: items.map((item) => (_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Checkbox, { id: `item-${item.id}`, checked: item.checked, onCheckedChange: () => handleItemChange(item.id), "aria-label": `${item.checked ? "Deselect" : "Select"} ${item.label}` }), _jsx(Label, { htmlFor: `item-${item.id}`, children: item.label })] }, item.id))) })] }));
|
|
63
67
|
},
|
|
64
68
|
};
|
|
65
69
|
export const LoadingSkeleton = {
|
|
66
|
-
render: () => (_jsxs(
|
|
70
|
+
render: () => (_jsxs(Stack, { gap: 3, children: [_jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Skeleton, { className: "h-4 w-4 rounded" }), _jsx(Skeleton, { className: "h-4 w-32" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Skeleton, { className: "h-4 w-4 rounded" }), _jsx(Skeleton, { className: "h-4 w-40" })] }), _jsxs(Flex, { align: "center", gap: 2, children: [_jsx(Skeleton, { className: "h-4 w-4 rounded" }), _jsx(Skeleton, { className: "h-4 w-36" })] })] })),
|
|
67
71
|
parameters: {
|
|
68
72
|
docs: {
|
|
69
73
|
description: {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type ActionIconProps } from "../action-icon/action-icon";
|
|
3
|
+
export interface CloseButtonProps extends Omit<ActionIconProps, "children"> {
|
|
4
|
+
iconSize?: number;
|
|
5
|
+
}
|
|
6
|
+
declare const CloseButton: React.ForwardRefExoticComponent<CloseButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
7
|
+
export { CloseButton };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { X } from "lucide-react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { ActionIcon } from "../action-icon/action-icon";
|
|
5
|
+
const CloseButton = React.forwardRef(({ iconSize = 16, ...props }, ref) => {
|
|
6
|
+
return (_jsx(ActionIcon, { ref: ref, ...props, children: _jsx(X, { size: iconSize }) }));
|
|
7
|
+
});
|
|
8
|
+
CloseButton.displayName = "CloseButton";
|
|
9
|
+
export { CloseButton };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { CloseButton } from "./close-button";
|
|
3
|
+
declare const meta: Meta<typeof CloseButton>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof CloseButton>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const Sizes: Story;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CloseButton } from "./close-button";
|
|
3
|
+
const meta = {
|
|
4
|
+
title: "Components/CloseButton",
|
|
5
|
+
component: CloseButton,
|
|
6
|
+
tags: ["autodocs"],
|
|
7
|
+
argTypes: {
|
|
8
|
+
size: {
|
|
9
|
+
control: "select",
|
|
10
|
+
options: ["xs", "sm", "md", "lg", "xl"],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export default meta;
|
|
15
|
+
export const Default = {};
|
|
16
|
+
export const Sizes = {
|
|
17
|
+
render: () => (_jsxs("div", { className: "flex gap-4", children: [_jsx(CloseButton, { size: "xs" }), _jsx(CloseButton, { size: "sm" }), _jsx(CloseButton, { size: "md" }), _jsx(CloseButton, { size: "lg" }), _jsx(CloseButton, { size: "xl" })] })),
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./close-button";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./close-button";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface CodeProps extends React.HTMLAttributes<HTMLElement> {
|
|
3
|
+
/** Whether to render as a block (pre) or inline (code) */
|
|
4
|
+
block?: boolean;
|
|
5
|
+
/** Color scheme (class name for text/bg, e.g. "text-blue-600 bg-blue-50") */
|
|
6
|
+
color?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const Code: React.ForwardRefExoticComponent<CodeProps & React.RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "../../lib/utils";
|
|
4
|
+
export const Code = React.forwardRef(({ className, block = false, color, children, ...props }, ref) => {
|
|
5
|
+
const Comp = block ? "pre" : "code";
|
|
6
|
+
return (_jsx(Comp
|
|
7
|
+
// biome-ignore lint/suspicious/noExplicitAny: polymorphic ref
|
|
8
|
+
, {
|
|
9
|
+
// biome-ignore lint/suspicious/noExplicitAny: polymorphic ref
|
|
10
|
+
ref: ref, className: cn("font-mono text-sm", block
|
|
11
|
+
? "block w-full overflow-x-auto rounded-lg bg-muted p-4"
|
|
12
|
+
: "rounded bg-muted px-1.5 py-0.5", color, className), ...props, children: children }));
|
|
13
|
+
});
|
|
14
|
+
Code.displayName = "Code";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { Code } from "./code";
|
|
3
|
+
declare const meta: Meta<typeof Code>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Code>;
|
|
6
|
+
export declare const Inline: Story;
|
|
7
|
+
export declare const Block: Story;
|
|
8
|
+
export declare const CustomColor: Story;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Code } from "./code";
|
|
2
|
+
const meta = {
|
|
3
|
+
title: "Components/Code",
|
|
4
|
+
component: Code,
|
|
5
|
+
tags: ["autodocs"],
|
|
6
|
+
argTypes: {
|
|
7
|
+
block: { control: "boolean" },
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
export default meta;
|
|
11
|
+
export const Inline = {
|
|
12
|
+
args: {
|
|
13
|
+
children: "npm install @kala-ui/react",
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
export const Block = {
|
|
17
|
+
args: {
|
|
18
|
+
block: true,
|
|
19
|
+
children: `import { Button } from '@kala-ui/react';
|
|
20
|
+
|
|
21
|
+
function App() {
|
|
22
|
+
return <Button>Click me</Button>;
|
|
23
|
+
}`,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export const CustomColor = {
|
|
27
|
+
args: {
|
|
28
|
+
children: "console.log('Hello world')",
|
|
29
|
+
color: "bg-blue-100 text-blue-900 dark:bg-blue-900/30 dark:text-blue-100",
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./code";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./code";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Easing } from "framer-motion";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface CollapseProps {
|
|
4
|
+
/** If true, the content will be visible */
|
|
5
|
+
in: boolean;
|
|
6
|
+
/** The content to be collapsed */
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
/** Transition duration in seconds */
|
|
9
|
+
transitionDuration?: number;
|
|
10
|
+
/** Transition timing function */
|
|
11
|
+
transitionTimingFunction?: Easing | Easing[];
|
|
12
|
+
/** Called when transition starts */
|
|
13
|
+
onTransitionEnd?: () => void;
|
|
14
|
+
/** If true, opacity will be animated */
|
|
15
|
+
animateOpacity?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const Collapse: React.ForwardRefExoticComponent<CollapseProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
export const Collapse = React.forwardRef(({ children, in: opened, transitionDuration = 0.2, transitionTimingFunction = "ease", onTransitionEnd, animateOpacity = true, }, ref) => {
|
|
6
|
+
return (_jsx(AnimatePresence, { initial: false, children: opened && (_jsx(motion.div, { ref: ref, initial: { height: 0, opacity: animateOpacity ? 0 : 1 }, animate: {
|
|
7
|
+
height: "auto",
|
|
8
|
+
opacity: 1,
|
|
9
|
+
transition: {
|
|
10
|
+
height: {
|
|
11
|
+
duration: transitionDuration,
|
|
12
|
+
ease: transitionTimingFunction,
|
|
13
|
+
},
|
|
14
|
+
opacity: {
|
|
15
|
+
duration: transitionDuration,
|
|
16
|
+
ease: transitionTimingFunction,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
}, exit: {
|
|
20
|
+
height: 0,
|
|
21
|
+
opacity: animateOpacity ? 0 : 1,
|
|
22
|
+
transition: {
|
|
23
|
+
height: {
|
|
24
|
+
duration: transitionDuration,
|
|
25
|
+
ease: transitionTimingFunction,
|
|
26
|
+
},
|
|
27
|
+
opacity: {
|
|
28
|
+
duration: transitionDuration,
|
|
29
|
+
ease: transitionTimingFunction,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}, onAnimationComplete: onTransitionEnd, style: { overflow: "hidden" }, children: children })) }));
|
|
33
|
+
});
|
|
34
|
+
Collapse.displayName = "Collapse";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Collapse, type CollapseProps } from "./collapse";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Collapse } from "./collapse";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface ColorInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange"> {
|
|
3
|
+
/**
|
|
4
|
+
* Value for controlled component
|
|
5
|
+
*/
|
|
6
|
+
value?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Default value for uncontrolled component
|
|
9
|
+
*/
|
|
10
|
+
defaultValue?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Callback fired when value changes
|
|
13
|
+
*/
|
|
14
|
+
onChange?: (value: string) => void;
|
|
15
|
+
/**
|
|
16
|
+
* If true, renders with error styles
|
|
17
|
+
*/
|
|
18
|
+
error?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* If true, renders with success styles
|
|
21
|
+
*/
|
|
22
|
+
success?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* If true, hides the color preview swatch
|
|
25
|
+
*/
|
|
26
|
+
withPreview?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare const ColorInput: React.ForwardRefExoticComponent<ColorInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { inputStyles } from "../../config/input";
|
|
4
|
+
import { cn } from "../../lib/utils";
|
|
5
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../popover";
|
|
6
|
+
export const ColorInput = React.forwardRef(({ className, value: valueProp, defaultValue, onChange, error, success, withPreview = true, disabled, ...props }, ref) => {
|
|
7
|
+
const [internalValue, setInternalValue] = React.useState(valueProp ?? defaultValue ?? "");
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
if (valueProp !== undefined) {
|
|
10
|
+
setInternalValue(valueProp);
|
|
11
|
+
}
|
|
12
|
+
}, [valueProp]);
|
|
13
|
+
const handleChange = (e) => {
|
|
14
|
+
const val = e.target.value;
|
|
15
|
+
setInternalValue(val);
|
|
16
|
+
onChange?.(val);
|
|
17
|
+
};
|
|
18
|
+
const handleColorChange = (e) => {
|
|
19
|
+
const val = e.target.value;
|
|
20
|
+
setInternalValue(val);
|
|
21
|
+
onChange?.(val);
|
|
22
|
+
};
|
|
23
|
+
return (_jsxs("div", { className: "relative flex items-center", children: [withPreview && (_jsx("div", { className: "absolute left-3 top-1/2 -translate-y-1/2 z-10", children: _jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsx("button", { type: "button", className: "h-5 w-5 rounded border shadow-sm cursor-pointer overflow-hidden p-0 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", style: { backgroundColor: internalValue || "transparent" }, disabled: disabled, children: _jsx("span", { className: "sr-only", children: "Pick a color" }) }) }), _jsx(PopoverContent, { className: "w-auto p-3", align: "start", children: _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("div", { className: "flex gap-2", children: [
|
|
24
|
+
"#000000",
|
|
25
|
+
"#ffffff",
|
|
26
|
+
"#ef4444",
|
|
27
|
+
"#22c55e",
|
|
28
|
+
"#3b82f6",
|
|
29
|
+
"#f59e0b",
|
|
30
|
+
].map((color) => (_jsx("button", { type: "button", className: "h-6 w-6 rounded border shadow-sm hover:scale-110 transition-transform", style: { backgroundColor: color }, onClick: () => {
|
|
31
|
+
setInternalValue(color);
|
|
32
|
+
onChange?.(color);
|
|
33
|
+
} }, color))) }), _jsx("input", { type: "color", value: internalValue.length === 7 ? internalValue : "#000000", onChange: handleColorChange, className: "h-8 w-full cursor-pointer" })] }) })] }) })), _jsx("input", { type: "text", ref: ref, value: internalValue, onChange: handleChange, disabled: disabled, className: cn(inputStyles.base, error && inputStyles.error, success && inputStyles.success, withPreview && "pl-10", className), placeholder: "#000000", ...props })] }));
|
|
34
|
+
});
|
|
35
|
+
ColorInput.displayName = "ColorInput";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { ColorInput } from "./color-input";
|
|
3
|
+
declare const meta: Meta<typeof ColorInput>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof ColorInput>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithValue: Story;
|
|
8
|
+
export declare const NoPreview: Story;
|
|
9
|
+
export declare const Disabled: Story;
|
|
10
|
+
export declare const WithError: Story;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ColorInput } from "./color-input";
|
|
2
|
+
const meta = {
|
|
3
|
+
title: "Components/ColorInput",
|
|
4
|
+
component: ColorInput,
|
|
5
|
+
tags: ["autodocs"],
|
|
6
|
+
argTypes: {
|
|
7
|
+
error: { control: "boolean" },
|
|
8
|
+
success: { control: "boolean" },
|
|
9
|
+
withPreview: { control: "boolean" },
|
|
10
|
+
disabled: { control: "boolean" },
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
export default meta;
|
|
14
|
+
export const Default = {
|
|
15
|
+
args: {
|
|
16
|
+
placeholder: "Pick a color",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export const WithValue = {
|
|
20
|
+
args: {
|
|
21
|
+
defaultValue: "#3b82f6",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export const NoPreview = {
|
|
25
|
+
args: {
|
|
26
|
+
defaultValue: "#ef4444",
|
|
27
|
+
withPreview: false,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
export const Disabled = {
|
|
31
|
+
args: {
|
|
32
|
+
defaultValue: "#22c55e",
|
|
33
|
+
disabled: true,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
export const WithError = {
|
|
37
|
+
args: {
|
|
38
|
+
defaultValue: "invalid-color",
|
|
39
|
+
error: true,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./color-input";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./color-input";
|
|
@@ -6,7 +6,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
* Supports both single and multi-select appearances.
|
|
7
7
|
*/
|
|
8
8
|
import { cn } from "../../lib/utils";
|
|
9
|
-
import { Skeleton } from "../skeleton
|
|
9
|
+
import { Skeleton } from "../skeleton";
|
|
10
10
|
/**
|
|
11
11
|
* Combobox skeleton component
|
|
12
12
|
*
|
|
@@ -1,25 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useDisclosure } from "@kala-ui/react-hooks";
|
|
3
4
|
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
4
5
|
import { Check, ChevronsUpDown } from "lucide-react";
|
|
5
6
|
import * as React from "react";
|
|
6
7
|
import { cn } from "../../lib/utils";
|
|
7
8
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "../../primitives/command";
|
|
9
|
+
import { Button } from "../button";
|
|
10
|
+
import { Text } from "../text";
|
|
8
11
|
const Combobox = React.forwardRef(({ options, value, onValueChange, placeholder = "Select option...", searchPlaceholder = "Search...", emptyText = "No results found.", disabled = false, className, size = "default", matchTriggerWidth = true, }, ref) => {
|
|
9
|
-
const [open, setOpen] =
|
|
12
|
+
const [open, { set: setOpen }] = useDisclosure(false);
|
|
10
13
|
const [search, setSearch] = React.useState("");
|
|
11
14
|
const selectedOption = options.find((option) => option.value === value);
|
|
12
|
-
return (_jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsxs(
|
|
13
|
-
"h-8 px-2 py-1 text-xs": size === "sm",
|
|
14
|
-
"h-10": size === "default",
|
|
15
|
-
}, className), children: [_jsx("span", { className: cn("truncate", !selectedOption && "text-muted-foreground"), children: selectedOption ? selectedOption.label : placeholder }), _jsx(ChevronsUpDown, { className: "ml-2 size-4 shrink-0 opacity-50", "aria-hidden": "true" })] }) }), _jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Content, { className: "p-0 z-30", align: "start", sideOffset: 4, style: matchTriggerWidth
|
|
15
|
+
return (_jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsxs(Button, { ref: ref, variant: "outline", role: "combobox", "aria-expanded": open, disabled: disabled, className: cn("w-full justify-between font-normal", size === "sm" ? "h-8 px-3 text-xs" : "h-10 px-4", !value && "text-muted-foreground", className), children: [_jsx(Text, { className: cn("truncate", matchTriggerWidth && "flex-1 text-left"), children: selectedOption ? selectedOption.label : placeholder }), _jsx(ChevronsUpDown, { className: "ml-2 size-4 shrink-0 opacity-50" })] }) }), _jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Content, { className: "p-0 z-30", align: "start", sideOffset: 4, style: matchTriggerWidth
|
|
16
16
|
? { width: "var(--radix-popover-trigger-width)" }
|
|
17
|
-
: undefined, children: _jsxs(Command, { className: cn("rounded-lg border bg-popover text-popover-foreground theme-dropdown", matchTriggerWidth ? "w-full" : "min-w-[200px]"),
|
|
17
|
+
: undefined, children: _jsxs(Command, { className: cn("rounded-lg border bg-popover text-popover-foreground theme-dropdown", matchTriggerWidth ? "w-full" : "min-w-[200px]"), filter: (value, search) => {
|
|
18
|
+
const option = options.find((opt) => opt.value === value);
|
|
19
|
+
const label = option?.label ?? "";
|
|
20
|
+
const searchLower = search.toLowerCase();
|
|
21
|
+
if (value.toLowerCase().includes(searchLower) ||
|
|
22
|
+
label.toLowerCase().includes(searchLower)) {
|
|
23
|
+
return 1;
|
|
24
|
+
}
|
|
25
|
+
return 0;
|
|
26
|
+
}, children: [_jsx(CommandInput, { placeholder: searchPlaceholder, value: search, onValueChange: setSearch }), _jsxs(CommandList, { className: "max-h-[300px] overflow-y-auto scrollbar-hide", children: [_jsx(CommandEmpty, { children: emptyText }), _jsx(CommandGroup, { children: options.map((option) => (_jsxs(CommandItem, { value: option.value, disabled: option.disabled ?? false, onSelect: () => {
|
|
18
27
|
const newValue = option.value === value ? "" : option.value;
|
|
19
28
|
onValueChange?.(newValue);
|
|
20
29
|
setOpen(false);
|
|
21
30
|
setSearch("");
|
|
22
|
-
}, children: [_jsx(Check, { className: cn("mr-2 size-4", value === option.value ? "opacity-100" : "opacity-0"), "aria-hidden": "true" }), _jsx(
|
|
31
|
+
}, children: [_jsx(Check, { className: cn("mr-2 size-4", value === option.value ? "opacity-100" : "opacity-0"), "aria-hidden": "true" }), _jsx(Text, { className: cn(!matchTriggerWidth && "truncate", "text-foreground"), children: option.label })] }, option.value))) })] })] }) }) })] }));
|
|
23
32
|
});
|
|
24
33
|
Combobox.displayName = "Combobox";
|
|
25
|
-
export { Combobox
|
|
34
|
+
export { Combobox };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
-
import { Skeleton } from "../skeleton
|
|
3
|
+
import { Skeleton } from "../skeleton";
|
|
4
4
|
import { Combobox } from "./combobox";
|
|
5
5
|
const meta = {
|
|
6
6
|
title: "Forms/Combobox",
|
|
@@ -24,7 +24,7 @@ declare const CommandInput: React.ForwardRefExoticComponent<Omit<Omit<Pick<Pick<
|
|
|
24
24
|
ref?: React.Ref<HTMLInputElement>;
|
|
25
25
|
} & {
|
|
26
26
|
asChild?: boolean;
|
|
27
|
-
}, "key" | "asChild" | keyof React.InputHTMLAttributes<HTMLInputElement>>, "onChange" | "
|
|
27
|
+
}, "key" | "asChild" | keyof React.InputHTMLAttributes<HTMLInputElement>>, "onChange" | "value" | "type"> & {
|
|
28
28
|
value?: string;
|
|
29
29
|
onValueChange?: (search: string) => void;
|
|
30
30
|
} & React.RefAttributes<HTMLInputElement>, "ref"> & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -50,7 +50,7 @@ declare const CommandGroup: React.ForwardRefExoticComponent<Omit<{
|
|
|
50
50
|
ref?: React.Ref<HTMLDivElement>;
|
|
51
51
|
} & {
|
|
52
52
|
asChild?: boolean;
|
|
53
|
-
}, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "asChild">, "
|
|
53
|
+
}, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "asChild">, "value" | "heading"> & {
|
|
54
54
|
heading?: React.ReactNode;
|
|
55
55
|
value?: string;
|
|
56
56
|
forceMount?: boolean;
|