@dimaan/ui 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,34 @@
1
- import { createContext, forwardRef, Children, isValidElement, cloneElement, useRef, useImperativeHandle, useLayoutEffect, useId, useContext, useState, useCallback, useMemo, useEffect } from 'react';
1
+ import { DirectionProvider } from '@radix-ui/react-direction';
2
+ import { createContext, forwardRef, Children, isValidElement, cloneElement, useRef, useImperativeHandle, useLayoutEffect, useId, useCallback, useState, useEffect, useContext, useMemo } from 'react';
2
3
  import { clsx } from 'clsx';
3
4
  import { twMerge } from 'tailwind-merge';
4
5
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
5
- import { Loader2, Check, Minus, ChevronLeft, Menu, ChevronDown, ChevronsUpDown, ChevronUp, ChevronRight } from 'lucide-react';
6
+ import { Loader2, Check, Minus, ChevronDown, ChevronUp, ChevronLeft, Menu, ChevronsUpDown, ChevronRight } from 'lucide-react';
6
7
  import { useFormContext, Controller } from 'react-hook-form';
8
+ import * as RadixSelect from '@radix-ui/react-select';
9
+ import * as RadixSwitch from '@radix-ui/react-switch';
7
10
 
8
- // src/components/dashboard-layout/context.ts
11
+ // src/components/app-shell/AppShell.tsx
12
+ function readDocumentDirection() {
13
+ if (typeof document === "undefined") return "ltr";
14
+ const dir = document.documentElement.getAttribute("dir");
15
+ return dir === "rtl" ? "rtl" : "ltr";
16
+ }
17
+ function useDirection() {
18
+ const [dir, setDir] = useState(() => readDocumentDirection());
19
+ useEffect(() => {
20
+ setDir(readDocumentDirection());
21
+ const observer = new MutationObserver(() => {
22
+ setDir(readDocumentDirection());
23
+ });
24
+ observer.observe(document.documentElement, {
25
+ attributes: true,
26
+ attributeFilter: ["dir"]
27
+ });
28
+ return () => observer.disconnect();
29
+ }, []);
30
+ return dir;
31
+ }
9
32
  var DashboardLayoutContext = createContext(null);
10
33
  function useDashboardLayout() {
11
34
  const ctx = useContext(DashboardLayoutContext);
@@ -599,7 +622,8 @@ function AppShell({
599
622
  onCollapsedChange,
600
623
  children
601
624
  }) {
602
- return /* @__PURE__ */ jsxs(
625
+ const dir = useDirection();
626
+ return /* @__PURE__ */ jsx(DirectionProvider, { dir, children: /* @__PURE__ */ jsxs(
603
627
  DashboardLayout,
604
628
  {
605
629
  defaultCollapsed,
@@ -644,7 +668,7 @@ function AppShell({
644
668
  ] })
645
669
  ]
646
670
  }
647
- );
671
+ ) });
648
672
  }
649
673
  var sizeClass = {
650
674
  sm: "h-7 w-7 text-xs",
@@ -780,6 +804,7 @@ function FieldShell({
780
804
  required = false,
781
805
  disabled = false,
782
806
  fullWidth = true,
807
+ orientation = "vertical",
783
808
  className,
784
809
  children
785
810
  }) {
@@ -802,39 +827,47 @@ function FieldShell({
802
827
  disabled: childProps.disabled ?? disabled,
803
828
  required: childProps.required ?? required
804
829
  });
830
+ const labelEl = label !== void 0 && label !== null ? /* @__PURE__ */ jsxs(
831
+ "label",
832
+ {
833
+ htmlFor: id,
834
+ className: cn(
835
+ "text-sm font-medium select-none text-foreground",
836
+ disabled && "opacity-50",
837
+ invalid && "text-destructive"
838
+ ),
839
+ children: [
840
+ label,
841
+ required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "ms-0.5 text-destructive", children: "*" })
842
+ ]
843
+ }
844
+ ) : null;
845
+ const messageEl = showError ? /* @__PURE__ */ jsx(
846
+ "p",
847
+ {
848
+ id: errorId,
849
+ role: "alert",
850
+ "aria-live": "polite",
851
+ className: "text-xs font-medium text-destructive",
852
+ children: error
853
+ }
854
+ ) : showDescription ? /* @__PURE__ */ jsx("p", { id: descriptionId, className: "text-xs text-muted-foreground", children: description }) : null;
805
855
  return /* @__PURE__ */ jsxs(
806
856
  "div",
807
857
  {
808
858
  "data-invalid": invalid || void 0,
809
859
  "data-disabled": disabled || void 0,
860
+ "data-orientation": orientation,
810
861
  className: cn("flex flex-col gap-1.5", fullWidth && "w-full", className),
811
862
  children: [
812
- label !== void 0 && label !== null && /* @__PURE__ */ jsxs(
813
- "label",
814
- {
815
- htmlFor: id,
816
- className: cn(
817
- "text-sm font-medium select-none text-foreground",
818
- disabled && "opacity-50",
819
- invalid && "text-destructive"
820
- ),
821
- children: [
822
- label,
823
- required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "ms-0.5 text-destructive", children: "*" })
824
- ]
825
- }
826
- ),
827
- enhancedChild,
828
- showError ? /* @__PURE__ */ jsx(
829
- "p",
830
- {
831
- id: errorId,
832
- role: "alert",
833
- "aria-live": "polite",
834
- className: "text-xs font-medium text-destructive",
835
- children: error
836
- }
837
- ) : showDescription ? /* @__PURE__ */ jsx("p", { id: descriptionId, className: "text-xs text-muted-foreground", children: description }) : null
863
+ orientation === "horizontal" ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
864
+ labelEl,
865
+ enhancedChild
866
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
867
+ labelEl,
868
+ enhancedChild
869
+ ] }),
870
+ messageEl
838
871
  ]
839
872
  }
840
873
  );
@@ -996,26 +1029,207 @@ function LanguageSwitcher({
996
1029
  }
997
1030
  );
998
1031
  }
999
- function readDocumentDirection() {
1000
- if (typeof document === "undefined") return "ltr";
1001
- const dir = document.documentElement.getAttribute("dir");
1002
- return dir === "rtl" ? "rtl" : "ltr";
1032
+
1033
+ // src/components/select/selectVariants.ts
1034
+ var selectVariantClass = {
1035
+ default: "border border-input bg-background hover:border-ring",
1036
+ filled: "border border-transparent bg-muted hover:bg-muted/80",
1037
+ ghost: "border border-transparent bg-transparent hover:bg-accent"
1038
+ };
1039
+ var selectSizeClass = {
1040
+ sm: "h-8 rounded-md ps-2.5 pe-8 text-sm",
1041
+ md: "h-9 rounded-md ps-3 pe-9 text-sm",
1042
+ lg: "h-11 rounded-md ps-4 pe-10 text-base"
1043
+ };
1044
+ var selectBaseClass = "group/select relative inline-flex w-full items-center text-foreground outline-none transition-[background-color,border-color,box-shadow] focus:ring-2 focus:ring-ring/40 focus:ring-offset-1 focus:ring-offset-background aria-[invalid=true]:border-destructive aria-[invalid=true]:focus:ring-destructive/40 disabled:pointer-events-none disabled:opacity-50 cursor-pointer data-[placeholder]:text-muted-foreground";
1045
+ var selectContentClass = "z-50 max-h-(--radix-select-content-available-height) min-w-(--radix-select-trigger-width) overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95";
1046
+ var selectViewportClass = "p-1";
1047
+ var selectItemClass = "relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 ps-8 pe-2 text-sm outline-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50";
1048
+ var selectItemIndicatorClass = "absolute start-2 inline-flex h-3.5 w-3.5 items-center justify-center [&_svg]:h-3.5 [&_svg]:w-3.5";
1049
+ var selectGroupLabelClass = "px-2 py-1.5 text-xs font-semibold text-muted-foreground";
1050
+ var selectSeparatorClass = "-mx-1 my-1 h-px bg-border";
1051
+ function isGroupedOptions(options) {
1052
+ const first = options[0];
1053
+ return first !== void 0 && "options" in first;
1003
1054
  }
1004
- function useDirection() {
1005
- const [dir, setDir] = useState(() => readDocumentDirection());
1006
- useEffect(() => {
1007
- setDir(readDocumentDirection());
1008
- const observer = new MutationObserver(() => {
1009
- setDir(readDocumentDirection());
1010
- });
1011
- observer.observe(document.documentElement, {
1012
- attributes: true,
1013
- attributeFilter: ["dir"]
1014
- });
1015
- return () => observer.disconnect();
1016
- }, []);
1017
- return dir;
1055
+ var Select = forwardRef(function Select2({
1056
+ variant = "default",
1057
+ selectSize = "md",
1058
+ options,
1059
+ placeholder,
1060
+ value,
1061
+ defaultValue,
1062
+ onValueChange,
1063
+ onChange,
1064
+ onBlur,
1065
+ name,
1066
+ disabled,
1067
+ required,
1068
+ id,
1069
+ className,
1070
+ "aria-invalid": ariaInvalid,
1071
+ "aria-describedby": ariaDescribedBy,
1072
+ "aria-label": ariaLabel,
1073
+ children
1074
+ }, ref) {
1075
+ const generatedId = useId();
1076
+ const triggerId = id ?? generatedId;
1077
+ const handleValueChange = useCallback(
1078
+ (next) => {
1079
+ onValueChange?.(next);
1080
+ if (onChange) {
1081
+ const synthetic = {
1082
+ target: { value: next, name },
1083
+ currentTarget: { value: next, name },
1084
+ type: "change"
1085
+ };
1086
+ onChange(synthetic);
1087
+ }
1088
+ },
1089
+ [onValueChange, onChange, name]
1090
+ );
1091
+ return /* @__PURE__ */ jsxs(
1092
+ RadixSelect.Root,
1093
+ {
1094
+ value,
1095
+ defaultValue,
1096
+ onValueChange: handleValueChange,
1097
+ disabled,
1098
+ required,
1099
+ name,
1100
+ children: [
1101
+ /* @__PURE__ */ jsxs(
1102
+ RadixSelect.Trigger,
1103
+ {
1104
+ ref,
1105
+ id: triggerId,
1106
+ "aria-label": ariaLabel,
1107
+ "aria-invalid": ariaInvalid,
1108
+ "aria-describedby": ariaDescribedBy,
1109
+ onBlur,
1110
+ "data-slot": "select-trigger",
1111
+ className: cn(
1112
+ selectBaseClass,
1113
+ selectVariantClass[variant],
1114
+ selectSizeClass[selectSize],
1115
+ className
1116
+ ),
1117
+ children: [
1118
+ /* @__PURE__ */ jsx(RadixSelect.Value, { placeholder }),
1119
+ /* @__PURE__ */ jsx(RadixSelect.Icon, { asChild: true, children: /* @__PURE__ */ jsx(ChevronDown, { className: "pointer-events-none absolute end-3 top-1/2 size-4 shrink-0 -translate-y-1/2 text-muted-foreground" }) })
1120
+ ]
1121
+ }
1122
+ ),
1123
+ /* @__PURE__ */ jsx(RadixSelect.Portal, { children: /* @__PURE__ */ jsxs(
1124
+ RadixSelect.Content,
1125
+ {
1126
+ position: "popper",
1127
+ sideOffset: 4,
1128
+ "data-slot": "select-content",
1129
+ className: selectContentClass,
1130
+ children: [
1131
+ /* @__PURE__ */ jsx(RadixSelect.ScrollUpButton, { className: "flex h-6 cursor-default items-center justify-center bg-popover text-muted-foreground", children: /* @__PURE__ */ jsx(ChevronUp, { className: "size-4" }) }),
1132
+ /* @__PURE__ */ jsx(RadixSelect.Viewport, { className: selectViewportClass, children: children ?? (options ? renderOptions(options) : null) }),
1133
+ /* @__PURE__ */ jsx(RadixSelect.ScrollDownButton, { className: "flex h-6 cursor-default items-center justify-center bg-popover text-muted-foreground", children: /* @__PURE__ */ jsx(ChevronDown, { className: "size-4" }) })
1134
+ ]
1135
+ }
1136
+ ) })
1137
+ ]
1138
+ }
1139
+ );
1140
+ });
1141
+ function renderOptions(options) {
1142
+ if (isGroupedOptions(options)) {
1143
+ const lastIndex = options.length - 1;
1144
+ return options.map((group, idx) => /* @__PURE__ */ jsxs(RadixSelect.Group, { children: [
1145
+ /* @__PURE__ */ jsx(RadixSelect.Label, { className: selectGroupLabelClass, children: group.label }),
1146
+ group.options.map((opt) => /* @__PURE__ */ jsx(SelectItem, { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value)),
1147
+ idx < lastIndex && /* @__PURE__ */ jsx(RadixSelect.Separator, { className: selectSeparatorClass })
1148
+ ] }, group.label));
1149
+ }
1150
+ return options.map((opt) => /* @__PURE__ */ jsx(SelectItem, { value: opt.value, disabled: opt.disabled, children: opt.label }, opt.value));
1018
1151
  }
1152
+ var SelectItem = forwardRef(function SelectItem2({ className, children, ...props }, ref) {
1153
+ return /* @__PURE__ */ jsxs(RadixSelect.Item, { ref, className: cn(selectItemClass, className), ...props, children: [
1154
+ /* @__PURE__ */ jsx(RadixSelect.ItemIndicator, { className: selectItemIndicatorClass, children: /* @__PURE__ */ jsx(Check, {}) }),
1155
+ /* @__PURE__ */ jsx(RadixSelect.ItemText, { children })
1156
+ ] });
1157
+ });
1158
+
1159
+ // src/components/switch/switchVariants.ts
1160
+ var switchTrackClass = {
1161
+ sm: "h-4 w-7",
1162
+ md: "h-5 w-9",
1163
+ lg: "h-6 w-11"
1164
+ };
1165
+ var switchThumbClass = {
1166
+ sm: "size-3 data-[state=checked]:translate-x-3 data-[state=checked]:rtl:-translate-x-3",
1167
+ md: "size-4 data-[state=checked]:translate-x-4 data-[state=checked]:rtl:-translate-x-4",
1168
+ lg: "size-5 data-[state=checked]:translate-x-5 data-[state=checked]:rtl:-translate-x-5"
1169
+ };
1170
+ var switchTrackBaseClass = "relative inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent bg-input transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary aria-[invalid=true]:ring-2 aria-[invalid=true]:ring-destructive/40";
1171
+ var switchThumbBaseClass = "pointer-events-none block rounded-full bg-background shadow-sm ring-0 transition-transform";
1172
+ var Switch = forwardRef(function Switch2({
1173
+ switchSize = "md",
1174
+ checked,
1175
+ defaultChecked,
1176
+ onCheckedChange,
1177
+ value,
1178
+ onChange,
1179
+ onBlur,
1180
+ name,
1181
+ disabled,
1182
+ required,
1183
+ id,
1184
+ className,
1185
+ "aria-label": ariaLabel,
1186
+ "aria-describedby": ariaDescribedBy,
1187
+ "aria-invalid": ariaInvalid
1188
+ }, ref) {
1189
+ const generatedId = useId();
1190
+ const switchId = id ?? generatedId;
1191
+ const resolvedChecked = checked ?? (value === void 0 ? void 0 : Boolean(value));
1192
+ const handleCheckedChange = useCallback(
1193
+ (next) => {
1194
+ onCheckedChange?.(next);
1195
+ if (onChange) {
1196
+ const synthetic = {
1197
+ target: { checked: next, value: next, name },
1198
+ currentTarget: { checked: next, value: next, name },
1199
+ type: "change"
1200
+ };
1201
+ onChange(synthetic);
1202
+ }
1203
+ },
1204
+ [onCheckedChange, onChange, name]
1205
+ );
1206
+ return /* @__PURE__ */ jsx(
1207
+ RadixSwitch.Root,
1208
+ {
1209
+ ref,
1210
+ id: switchId,
1211
+ checked: resolvedChecked,
1212
+ defaultChecked,
1213
+ onCheckedChange: handleCheckedChange,
1214
+ onBlur,
1215
+ disabled,
1216
+ required,
1217
+ name,
1218
+ "aria-label": ariaLabel,
1219
+ "aria-invalid": ariaInvalid,
1220
+ "aria-describedby": ariaDescribedBy,
1221
+ "data-slot": "switch-track",
1222
+ className: cn(switchTrackBaseClass, switchTrackClass[switchSize], className),
1223
+ children: /* @__PURE__ */ jsx(
1224
+ RadixSwitch.Thumb,
1225
+ {
1226
+ "data-slot": "switch-thumb",
1227
+ className: cn(switchThumbBaseClass, switchThumbClass[switchSize])
1228
+ }
1229
+ )
1230
+ }
1231
+ );
1232
+ });
1019
1233
  function Pagination({
1020
1234
  pageIndex,
1021
1235
  pageSize,
@@ -1589,6 +1803,6 @@ var Textarea = forwardRef(function Textarea2({
1589
1803
  ] });
1590
1804
  });
1591
1805
 
1592
- export { AppShell, Avatar, Button, Checkbox, DashboardContent, DashboardHeader, DashboardLayout, DashboardMain, Field, HeaderActions, HeaderCollapseTrigger, HeaderMobileTrigger, HeaderSearch, HeaderTitle, Input, LanguageSwitcher, Sidebar, SidebarFooter, SidebarGroup, SidebarHeader, SidebarNav, SidebarNavGroup, SidebarNavItem, Table, Textarea, buttonBaseClass, buttonSizeClass, buttonVariantClass, cn, inputBaseClass, inputSizeClass, inputVariantClass, alignClass as tableAlignClass, tableBaseClass, selectedRowClass as tableSelectedRowClass, tableSizeClass, sortIconClass as tableSortIconClass, textareaBaseClass, textareaResizeClass, textareaSizeClass, textareaVariantClass, useDashboardLayout, useDirection };
1806
+ export { AppShell, Avatar, Button, Checkbox, DashboardContent, DashboardHeader, DashboardLayout, DashboardMain, Field, HeaderActions, HeaderCollapseTrigger, HeaderMobileTrigger, HeaderSearch, HeaderTitle, Input, LanguageSwitcher, Select, Sidebar, SidebarFooter, SidebarGroup, SidebarHeader, SidebarNav, SidebarNavGroup, SidebarNavItem, Switch, Table, Textarea, buttonBaseClass, buttonSizeClass, buttonVariantClass, cn, inputBaseClass, inputSizeClass, inputVariantClass, selectBaseClass, selectSizeClass, selectVariantClass, switchThumbBaseClass, switchThumbClass, switchTrackBaseClass, switchTrackClass, alignClass as tableAlignClass, tableBaseClass, selectedRowClass as tableSelectedRowClass, tableSizeClass, sortIconClass as tableSortIconClass, textareaBaseClass, textareaResizeClass, textareaSizeClass, textareaVariantClass, useDashboardLayout, useDirection };
1593
1807
  //# sourceMappingURL=index.js.map
1594
1808
  //# sourceMappingURL=index.js.map