tw-react-components 0.0.135 → 0.0.138
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/index.cjs.js +537 -199
- package/index.css +101 -0
- package/index.esm.js +431 -100
- package/package.json +5 -2
- package/src/components/Form/controls/custom/date-time/DateSelector.d.ts +2 -2
- package/src/components/Form/controls/custom/date-time/DaysView.d.ts +2 -2
- package/src/components/Form/controls/custom/date-time/MonthsView.d.ts +2 -2
- package/src/components/Form/controls/custom/date-time/TimeSelector.d.ts +2 -2
- package/src/components/Form/controls/custom/date-time/YearsView.d.ts +2 -2
- package/src/components/Form/controls/custom/date-time/index.d.ts +4 -4
- package/src/components/Form/controls/custom/file.d.ts +11 -0
- package/src/components/Form/controls/custom/index.d.ts +1 -0
- package/src/components/Form/controls/custom/select/index.d.ts +1 -1
- package/src/components/Form/controls/primitive/BasicInput.d.ts +2 -3
- package/src/components/Form/controls/primitive/NumberInput.d.ts +7 -2
- package/src/components/Form/controls/with-form.d.ts +6 -1
- package/src/components/Layout/index.d.ts +22 -2
- package/src/components/Navbar/index.d.ts +1 -0
- package/src/components/Separator/index.d.ts +2 -0
- package/src/components/Sheet/index.d.ts +26 -0
- package/src/components/Sidebar/index.d.ts +82 -23
- package/src/components/Skeleton/index.d.ts +2 -0
- package/src/components/index.d.ts +3 -0
- package/src/contexts/LayoutContext.d.ts +0 -3
- package/src/hooks/index.d.ts +1 -0
- package/src/hooks/useIsMobile.d.ts +1 -0
- package/tailwindcss-plugin.cjs +88 -0
- package/src/components/Sidebar/SidebarItem.d.ts +0 -10
package/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var React = require('react');
|
|
5
5
|
var clsx = require('clsx');
|
|
6
6
|
var tailwindMerge = require('tailwind-merge');
|
|
7
7
|
var dayjs = require('dayjs');
|
|
@@ -16,8 +16,10 @@ var core = require('@dnd-kit/core');
|
|
|
16
16
|
var modifiers = require('@dnd-kit/modifiers');
|
|
17
17
|
var sortable = require('@dnd-kit/sortable');
|
|
18
18
|
var utilities = require('@dnd-kit/utilities');
|
|
19
|
-
var Accordion = require('@radix-ui/react-accordion');
|
|
20
19
|
var reactRouterDom = require('react-router-dom');
|
|
20
|
+
var reactSlot = require('@radix-ui/react-slot');
|
|
21
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
22
|
+
var SeparatorPrimitive = require('@radix-ui/react-separator');
|
|
21
23
|
var PopoverPrimitive = require('@radix-ui/react-popover');
|
|
22
24
|
var SwitchPrimitives = require('@radix-ui/react-switch');
|
|
23
25
|
var TabsPrimitive = require('@radix-ui/react-tabs');
|
|
@@ -39,10 +41,11 @@ function _interopNamespaceDefault(e) {
|
|
|
39
41
|
return Object.freeze(n);
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
42
45
|
var TooltipPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(TooltipPrimitive);
|
|
43
46
|
var DropdownMenuPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(DropdownMenuPrimitive);
|
|
44
47
|
var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(DialogPrimitive);
|
|
45
|
-
var
|
|
48
|
+
var SeparatorPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(SeparatorPrimitive);
|
|
46
49
|
var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(PopoverPrimitive);
|
|
47
50
|
var SwitchPrimitives__namespace = /*#__PURE__*/_interopNamespaceDefault(SwitchPrimitives);
|
|
48
51
|
var TabsPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(TabsPrimitive);
|
|
@@ -583,7 +586,7 @@ const sizeClassNames = {
|
|
|
583
586
|
},
|
|
584
587
|
},
|
|
585
588
|
};
|
|
586
|
-
const Button =
|
|
589
|
+
const Button = React.forwardRef((_a, ref) => {
|
|
587
590
|
var { children, className, size = 'medium', color = 'slate', variant = 'filled', rounded, prefixIcon: PrefixIcon, suffixIcon: SuffixIcon } = _a, props = __rest(_a, ["children", "className", "size", "color", "variant", "rounded", "prefixIcon", "suffixIcon"]);
|
|
588
591
|
return (jsxRuntime.jsxs("button", Object.assign({ className: cn('relative flex aspect-square items-center font-medium duration-200', sizeClassNames[size].base, variantClassNames[variant][color].base, rounded ? 'rounded-full' : 'rounded-md', props.disabled
|
|
589
592
|
? 'cursor-not-allowed opacity-50'
|
|
@@ -592,17 +595,17 @@ const Button = react.forwardRef((_a, ref) => {
|
|
|
592
595
|
: 'cursor-default', children ? `${sizeClassNames[size].withChildren} aspect-[initial]` : 'justify-center', className), type: "button" }, props, { ref: ref, children: [PrefixIcon && (jsxRuntime.jsx(PrefixIcon, { className: children ? sizeClassNames[size].icon.withChildren : sizeClassNames[size].icon.base })), children, SuffixIcon && (jsxRuntime.jsx(SuffixIcon, { className: children ? sizeClassNames[size].icon.withChildren : sizeClassNames[size].icon.base }))] })));
|
|
593
596
|
});
|
|
594
597
|
|
|
595
|
-
const Badge =
|
|
598
|
+
const Badge = React.forwardRef((_a, ref) => {
|
|
596
599
|
var { size = 'small' } = _a, props = __rest(_a, ["size"]);
|
|
597
600
|
return jsxRuntime.jsx(Button, Object.assign({ size: size }, props, { ref: ref }));
|
|
598
601
|
});
|
|
599
602
|
|
|
600
|
-
const Block =
|
|
603
|
+
const Block = React.forwardRef((_a, ref) => {
|
|
601
604
|
var { children, className, centered, container, fullWidth, fullHeight } = _a, props = __rest(_a, ["children", "className", "centered", "container", "fullWidth", "fullHeight"]);
|
|
602
605
|
return (jsxRuntime.jsx("div", Object.assign({ className: cn(centered && 'mx-auto', container && 'container', fullWidth && 'w-full', fullHeight && 'h-full', className) }, props, { ref: ref, children: children })));
|
|
603
606
|
});
|
|
604
607
|
|
|
605
|
-
const Card =
|
|
608
|
+
const Card = React.forwardRef((_a, ref) => {
|
|
606
609
|
var { children, className } = _a, blockProps = __rest(_a, ["children", "className"]);
|
|
607
610
|
return (jsxRuntime.jsx(Block, Object.assign({ className: cn('rounded-lg border p-3 dark:border-slate-700 dark:bg-slate-900', className) }, blockProps, { ref: ref, children: children })));
|
|
608
611
|
});
|
|
@@ -628,14 +631,14 @@ const justifyClasses = {
|
|
|
628
631
|
between: 'justify-between',
|
|
629
632
|
end: 'justify-end',
|
|
630
633
|
};
|
|
631
|
-
const Flex =
|
|
634
|
+
const Flex = React.forwardRef((_a, ref) => {
|
|
632
635
|
var { children, className, reverse, wrap, direction = 'row', align = 'start', justify = 'start' } = _a, blockProps = __rest(_a, ["children", "className", "reverse", "wrap", "direction", "align", "justify"]);
|
|
633
636
|
return (jsxRuntime.jsx(Block, Object.assign({ className: cn('flex gap-3', wrap && 'flex-wrap', directionClasses[direction][reverse ? 'reverse' : 'normal'], alignClasses[align], justifyClasses[justify], className) }, blockProps, { ref: ref, children: children })));
|
|
634
637
|
});
|
|
635
638
|
|
|
636
639
|
dayjs.extend(localeData);
|
|
637
640
|
function useDays(locale = 'en') {
|
|
638
|
-
return
|
|
641
|
+
return React.useMemo(() => {
|
|
639
642
|
dayjs.extend(localeData).locale(locale);
|
|
640
643
|
const names = dayjs.weekdays();
|
|
641
644
|
const shortNames = dayjs.weekdaysShort();
|
|
@@ -643,9 +646,24 @@ function useDays(locale = 'en') {
|
|
|
643
646
|
}, [locale]);
|
|
644
647
|
}
|
|
645
648
|
|
|
649
|
+
const MOBILE_BREAKPOINT = 768;
|
|
650
|
+
function useIsMobile() {
|
|
651
|
+
const [isMobile, setIsMobile] = React.useState(undefined);
|
|
652
|
+
React.useEffect(() => {
|
|
653
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
654
|
+
const onChange = () => {
|
|
655
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
656
|
+
};
|
|
657
|
+
mql.addEventListener('change', onChange);
|
|
658
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
659
|
+
return () => mql.removeEventListener('change', onChange);
|
|
660
|
+
}, []);
|
|
661
|
+
return !!isMobile;
|
|
662
|
+
}
|
|
663
|
+
|
|
646
664
|
function useLongPress(callback, ms = 100) {
|
|
647
|
-
const [startLongPress, setStartLongPress] =
|
|
648
|
-
|
|
665
|
+
const [startLongPress, setStartLongPress] = React.useState(false);
|
|
666
|
+
React.useEffect(() => {
|
|
649
667
|
let timerId;
|
|
650
668
|
if (startLongPress) {
|
|
651
669
|
timerId = setTimeout(callback, ms);
|
|
@@ -668,7 +686,7 @@ function useLongPress(callback, ms = 100) {
|
|
|
668
686
|
|
|
669
687
|
dayjs.extend(localeData);
|
|
670
688
|
function useMonths(locale = 'en') {
|
|
671
|
-
return
|
|
689
|
+
return React.useMemo(() => {
|
|
672
690
|
dayjs.extend(localeData).locale(locale);
|
|
673
691
|
const names = dayjs.months();
|
|
674
692
|
const shortNames = dayjs.monthsShort();
|
|
@@ -677,7 +695,7 @@ function useMonths(locale = 'en') {
|
|
|
677
695
|
}
|
|
678
696
|
|
|
679
697
|
function useOnSwipe(element, onSwipe, minSwipeDistance = 50) {
|
|
680
|
-
|
|
698
|
+
React.useEffect(() => {
|
|
681
699
|
if (!element.current)
|
|
682
700
|
return;
|
|
683
701
|
const elem = element.current;
|
|
@@ -718,7 +736,7 @@ function useOnSwipe(element, onSwipe, minSwipeDistance = 50) {
|
|
|
718
736
|
}
|
|
719
737
|
|
|
720
738
|
function useOutsideClick(ref, callback) {
|
|
721
|
-
|
|
739
|
+
React.useEffect(() => {
|
|
722
740
|
const handleClickOutside = (event) => {
|
|
723
741
|
if ((ref === null || ref === void 0 ? void 0 : ref.current) && !ref.current.contains(event.target)) {
|
|
724
742
|
callback();
|
|
@@ -734,7 +752,7 @@ function useOutsideClick(ref, callback) {
|
|
|
734
752
|
}
|
|
735
753
|
|
|
736
754
|
function usePagination(currentIndex, totalPages) {
|
|
737
|
-
return
|
|
755
|
+
return React.useMemo(() => {
|
|
738
756
|
const result = [];
|
|
739
757
|
result.push(currentIndex);
|
|
740
758
|
if (totalPages > 7 && currentIndex > 4) {
|
|
@@ -772,7 +790,7 @@ const Label = ({ children, className, description, required, hasErrors, htmlFor,
|
|
|
772
790
|
return !children ? null : (jsxRuntime.jsxs("label", { className: cn('flex items-center gap-1 font-medium', {
|
|
773
791
|
'text-slate-700 dark:text-slate-100': !hasErrors,
|
|
774
792
|
'text-red-600 dark:text-red-500': hasErrors,
|
|
775
|
-
}, className), htmlFor: htmlFor, children: [
|
|
793
|
+
}, className), htmlFor: htmlFor, children: [children, description && (jsxRuntime.jsx(Tooltip, { content: jsxRuntime.jsx("div", { className: "max-w-xs", children: description }), placement: "top", asChild: true, children: jsxRuntime.jsx(lucideReact.HelpCircle, { className: "h-4 w-4" }) })), required && jsxRuntime.jsx("span", { className: "text-red-600", children: "*" })] }));
|
|
776
794
|
};
|
|
777
795
|
|
|
778
796
|
const inputClasses = {
|
|
@@ -823,10 +841,10 @@ const sizeClasses = {
|
|
|
823
841
|
},
|
|
824
842
|
},
|
|
825
843
|
};
|
|
826
|
-
const BasicInput =
|
|
844
|
+
const BasicInput = React.forwardRef(function BasicInput(_a, ref) {
|
|
827
845
|
var { className, inputClassName, extensionClassName, type = 'text', label, description, size = 'medium', hasErrors, clearable, suffixIcon: SuffixIcon, onClear, onSuffixIconClick } = _a, props = __rest(_a, ["className", "inputClassName", "extensionClassName", "type", "label", "description", "size", "hasErrors", "clearable", "suffixIcon", "onClear", "onSuffixIconClick"]);
|
|
828
|
-
const id =
|
|
829
|
-
const memoLabel =
|
|
846
|
+
const id = React.useId();
|
|
847
|
+
const memoLabel = React.useMemo(() => label && (jsxRuntime.jsx(Label, { className: sizeClasses[size].label, htmlFor: id, description: description, required: props.required, hasErrors: hasErrors, children: label })), [description, hasErrors, id, label, props.required, size]);
|
|
830
848
|
const handleClear = (event) => {
|
|
831
849
|
var _a;
|
|
832
850
|
event.stopPropagation();
|
|
@@ -860,25 +878,30 @@ const BasicInputExtension = ({ children, className, size, hasErrors, disabled, o
|
|
|
860
878
|
'cursor-pointer': onClick,
|
|
861
879
|
}, className), onClick: !disabled ? onClick : undefined, onPointerDown: (event) => event.stopPropagation(), children: children }));
|
|
862
880
|
|
|
863
|
-
const CheckboxInput =
|
|
881
|
+
const CheckboxInput = React.forwardRef((props, ref) => (jsxRuntime.jsx(BasicInput, Object.assign({ type: "checkbox" }, props, { ref: ref }))));
|
|
864
882
|
|
|
865
|
-
const EmailInput =
|
|
883
|
+
const EmailInput = React.forwardRef((props, ref) => (jsxRuntime.jsx(BasicInput, Object.assign({ type: "email" }, props, { suffixIcon: lucideReact.AtSignIcon, ref: ref }))));
|
|
866
884
|
|
|
867
|
-
const NumberInput =
|
|
885
|
+
const NumberInput = React.forwardRef((_a, ref) => {
|
|
886
|
+
var { unit } = _a, props = __rest(_a, ["unit"]);
|
|
887
|
+
return (jsxRuntime.jsx(BasicInput, Object.assign({ type: "number" }, props, { suffixIcon: unit
|
|
888
|
+
? ({ className }) => (jsxRuntime.jsx("div", { className: cn(className, 'flex w-min items-center'), onClick: props.onSuffixIconClick, children: unit }))
|
|
889
|
+
: props.suffixIcon, ref: ref })));
|
|
890
|
+
});
|
|
868
891
|
|
|
869
|
-
const PasswordInput =
|
|
870
|
-
const [type, setType] =
|
|
892
|
+
const PasswordInput = React.forwardRef((props, ref) => {
|
|
893
|
+
const [type, setType] = React.useState('password');
|
|
871
894
|
const toggleType = () => setType((type) => (type === 'text' ? 'password' : 'text'));
|
|
872
895
|
return (jsxRuntime.jsx(BasicInput, Object.assign({ type: type }, props, { suffixIcon: type === 'password' ? lucideReact.EyeIcon : lucideReact.EyeOffIcon, onSuffixIconClick: toggleType, ref: ref })));
|
|
873
896
|
});
|
|
874
897
|
|
|
875
|
-
const TextareaInput =
|
|
898
|
+
const TextareaInput = React.forwardRef((props, ref) => (jsxRuntime.jsx(BasicInput, Object.assign({ type: "textarea" }, props, { ref: ref }))));
|
|
876
899
|
|
|
877
|
-
const TextInput =
|
|
900
|
+
const TextInput = React.forwardRef((props, ref) => (jsxRuntime.jsx(BasicInput, Object.assign({ type: "text" }, props, { ref: ref }))));
|
|
878
901
|
|
|
879
902
|
const DaysView = ({ date, value, month, year, minDate, maxDate, locale, setNewDate, }) => {
|
|
880
903
|
const days = useDays(locale);
|
|
881
|
-
const monthDays =
|
|
904
|
+
const monthDays = React.useMemo(() => {
|
|
882
905
|
const daysInMonth = new Date(year, month + 1, 0).getDate();
|
|
883
906
|
const daysInMonthArr = [];
|
|
884
907
|
for (let i = 1; i <= daysInMonth; i++) {
|
|
@@ -886,7 +909,7 @@ const DaysView = ({ date, value, month, year, minDate, maxDate, locale, setNewDa
|
|
|
886
909
|
}
|
|
887
910
|
return daysInMonthArr;
|
|
888
911
|
}, [month, year]);
|
|
889
|
-
const prefixDays =
|
|
912
|
+
const prefixDays = React.useMemo(() => {
|
|
890
913
|
const firstDay = new Date(year, month);
|
|
891
914
|
const dayOfWeek = firstDay.getDay();
|
|
892
915
|
firstDay.setDate(firstDay.getDate() - 1);
|
|
@@ -897,7 +920,7 @@ const DaysView = ({ date, value, month, year, minDate, maxDate, locale, setNewDa
|
|
|
897
920
|
}
|
|
898
921
|
return prefixDays;
|
|
899
922
|
}, [month, year]);
|
|
900
|
-
const suffixDays =
|
|
923
|
+
const suffixDays = React.useMemo(() => {
|
|
901
924
|
const lastDay = new Date(year, month + 1);
|
|
902
925
|
lastDay.setDate(lastDay.getDate() - 1);
|
|
903
926
|
const dayOfWeek = lastDay.getDay();
|
|
@@ -907,7 +930,7 @@ const DaysView = ({ date, value, month, year, minDate, maxDate, locale, setNewDa
|
|
|
907
930
|
}
|
|
908
931
|
return suffixDays;
|
|
909
932
|
}, [month, year]);
|
|
910
|
-
const setDayNumber =
|
|
933
|
+
const setDayNumber = React.useCallback((newDay, newMonth = month, newYear = year) => () => {
|
|
911
934
|
const newDate = new Date(newYear, newMonth, newDay, date.getHours(), date.getMinutes());
|
|
912
935
|
if (minDate) {
|
|
913
936
|
const _minDate = new Date(minDate);
|
|
@@ -936,11 +959,11 @@ const DaysView = ({ date, value, month, year, minDate, maxDate, locale, setNewDa
|
|
|
936
959
|
return (jsxRuntime.jsxs("div", { className: "gap-1 px-3 py-2", children: [jsxRuntime.jsx("div", { className: "grid grid-cols-7", children: days.map((day, index) => (jsxRuntime.jsx("span", { className: "flex h-8 w-8 items-center justify-center text-xs uppercase text-slate-500 dark:text-slate-400", children: day.shortName }, index))) }), jsxRuntime.jsxs("div", { className: "grid grid-cols-7 gap-1", children: [prefixDays.map((dayNumber, index) => (jsxRuntime.jsx(Day, { value: value, day: dayNumber, month: (month - 1 + 12) % 12, year: month % 12 ? year : year - 1, minDate: minDate, maxDate: maxDate, setDayNumber: setDayNumber }, `${dayNumber}-${index}`))), monthDays.map((dayNumber, index) => (jsxRuntime.jsx(Day, { value: value, day: dayNumber, month: month, year: year, minDate: minDate, maxDate: maxDate, primary: true, setDayNumber: setDayNumber }, `${dayNumber}-${index}`))), suffixDays.map((dayNumber, index) => (jsxRuntime.jsx(Day, { value: value, day: dayNumber, month: (month + 1) % 12, year: (month + 1) % 12 ? year : year + 1, minDate: minDate, maxDate: maxDate, setDayNumber: setDayNumber }, `${dayNumber}-${index}`)))] })] }));
|
|
937
960
|
};
|
|
938
961
|
const Day = ({ value, day, month, year, minDate, maxDate, primary, setDayNumber, }) => {
|
|
939
|
-
const dayDate =
|
|
940
|
-
const isSelectable =
|
|
962
|
+
const dayDate = React.useMemo(() => new Date(year, month, day), [day, month, year]);
|
|
963
|
+
const isSelectable = React.useMemo(() => (!minDate || compareDates(dayDate, new Date(minDate), 'day') >= 0) &&
|
|
941
964
|
(!maxDate || compareDates(dayDate, new Date(maxDate), 'day') <= 0), [minDate, dayDate, maxDate]);
|
|
942
|
-
const isSelected =
|
|
943
|
-
const isEqualToday =
|
|
965
|
+
const isSelected = React.useMemo(() => !!value && !compareDates(dayDate, new Date(value), 'day'), [dayDate, value]);
|
|
966
|
+
const isEqualToday = React.useMemo(() => !compareDates(dayDate, new Date(), 'day'), [dayDate]);
|
|
944
967
|
return (jsxRuntime.jsx("div", { className: cn('mx-auto flex h-8 w-8 items-center justify-center rounded-lg text-sm', {
|
|
945
968
|
'border-2 border-blue-500': isEqualToday,
|
|
946
969
|
'bg-blue-500 text-white': isSelected,
|
|
@@ -955,11 +978,11 @@ const MonthsView = ({ date, value, year, minDate, maxDate, locale, selectMonth,
|
|
|
955
978
|
return (jsxRuntime.jsx("div", { className: "grid grid-cols-4 gap-1 px-3 py-2", children: months.map((month, index) => (jsxRuntime.jsx(Month, { date: date, value: value, shortName: month.shortName, month: index, year: year, minDate: minDate, maxDate: maxDate, selectMonth: selectMonth }, index))) }));
|
|
956
979
|
};
|
|
957
980
|
const Month = ({ date, value, shortName, month, year, minDate, maxDate, selectMonth, }) => {
|
|
958
|
-
const dayDate =
|
|
959
|
-
const isSelectable =
|
|
981
|
+
const dayDate = React.useMemo(() => new Date(year, month, date.getDate(), date.getHours(), date.getMinutes()), [date, month, year]);
|
|
982
|
+
const isSelectable = React.useMemo(() => (!minDate || compareDates(dayDate, new Date(minDate), 'month') >= 0) &&
|
|
960
983
|
(!maxDate || compareDates(dayDate, new Date(maxDate), 'month') <= 0), [dayDate, minDate, maxDate]);
|
|
961
|
-
const isSelected =
|
|
962
|
-
const isEqualThisMonth =
|
|
984
|
+
const isSelected = React.useMemo(() => !!value && !compareDates(dayDate, new Date(value), 'month'), [dayDate, value]);
|
|
985
|
+
const isEqualThisMonth = React.useMemo(() => !compareDates(dayDate, new Date(), 'month'), [dayDate]);
|
|
963
986
|
return (jsxRuntime.jsx("div", { className: cn('mx-auto flex w-14 items-center justify-center rounded border py-3 text-sm', {
|
|
964
987
|
'border-blue-500': isEqualThisMonth,
|
|
965
988
|
'border-transparent': !isEqualThisMonth,
|
|
@@ -972,11 +995,11 @@ const Month = ({ date, value, shortName, month, year, minDate, maxDate, selectMo
|
|
|
972
995
|
|
|
973
996
|
const YearsView = ({ date, value, years, minDate, maxDate, selectYear, }) => (jsxRuntime.jsx("div", { className: "grid grid-cols-4 gap-1 px-3 py-2", children: years.map((year, index) => (jsxRuntime.jsx(Year, { date: date, value: value, year: year, minDate: minDate, maxDate: maxDate, selectYear: selectYear }, index))) }));
|
|
974
997
|
const Year = ({ date, value, year, minDate, maxDate, selectYear }) => {
|
|
975
|
-
const dayDate =
|
|
976
|
-
const isSelectable =
|
|
998
|
+
const dayDate = React.useMemo(() => new Date(year, date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()), [date, year]);
|
|
999
|
+
const isSelectable = React.useMemo(() => (!minDate || compareDates(dayDate, new Date(minDate), 'year') >= 0) &&
|
|
977
1000
|
(!maxDate || compareDates(dayDate, new Date(maxDate), 'year') <= 0), [dayDate, minDate, maxDate]);
|
|
978
|
-
const isSelected =
|
|
979
|
-
const isEqualThisYear =
|
|
1001
|
+
const isSelected = React.useMemo(() => !!value && !compareDates(dayDate, new Date(value), 'year'), [dayDate, value]);
|
|
1002
|
+
const isEqualThisYear = React.useMemo(() => !compareDates(dayDate, new Date(), 'year'), [dayDate]);
|
|
980
1003
|
return (jsxRuntime.jsx("div", { className: cn('mx-auto flex w-14 items-center justify-center rounded border py-3 text-sm', {
|
|
981
1004
|
'border-blue-500': isEqualThisYear,
|
|
982
1005
|
'border-transparent': !isEqualThisYear,
|
|
@@ -989,14 +1012,14 @@ const Year = ({ date, value, year, minDate, maxDate, selectYear }) => {
|
|
|
989
1012
|
|
|
990
1013
|
const DateSelector = ({ date, value, minDate, maxDate, locale, calendarView, setCalendarView, setNewDate, }) => {
|
|
991
1014
|
const months = useMonths(locale);
|
|
992
|
-
const [month, setMonth] =
|
|
993
|
-
const [year, setYear] =
|
|
994
|
-
const [yearOffset, setYearOffset] =
|
|
995
|
-
|
|
1015
|
+
const [month, setMonth] = React.useState(date.getMonth());
|
|
1016
|
+
const [year, setYear] = React.useState(date.getFullYear());
|
|
1017
|
+
const [yearOffset, setYearOffset] = React.useState(0);
|
|
1018
|
+
React.useEffect(() => {
|
|
996
1019
|
setMonth(date.getMonth());
|
|
997
1020
|
setYear(date.getFullYear());
|
|
998
1021
|
}, [date]);
|
|
999
|
-
const yearsRange =
|
|
1022
|
+
const yearsRange = React.useMemo(() => {
|
|
1000
1023
|
const yearsRangeArr = [];
|
|
1001
1024
|
for (let i = year + yearOffset - 6; i < year + yearOffset + 6; i++) {
|
|
1002
1025
|
yearsRangeArr.push(i);
|
|
@@ -1066,21 +1089,21 @@ const TimeSelector = ({ date, step = 1, minDate, maxDate, setNewDate, }) => {
|
|
|
1066
1089
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("label", { className: "text-sm text-slate-700 dark:text-slate-300", children: "Time" }), jsxRuntime.jsxs("div", { className: "flex flex-grow justify-center gap-2", children: [jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center", children: [jsxRuntime.jsx(lucideReact.ChevronUpIcon, Object.assign({ className: "h-4 w-4 rounded hover:bg-slate-100 dark:hover:bg-slate-700", onClick: editDateField('hours', 1) }, increaseHours)), jsxRuntime.jsx(lucideReact.ChevronDownIcon, Object.assign({ className: "h-4 w-4 rounded hover:bg-slate-100 dark:hover:bg-slate-700", onClick: editDateField('hours', -1) }, decreaseHours))] }), jsxRuntime.jsxs("div", { className: "flex items-center rounded-lg border border-slate-100 bg-slate-100 text-right dark:border-slate-700 dark:bg-slate-800", children: [jsxRuntime.jsx("span", { className: "flex px-2", onWheel: onWheel('hours'), children: date.getHours().toString().padStart(2, '0') }), jsxRuntime.jsx("span", { children: ":" }), jsxRuntime.jsx("span", { className: "flex px-2", onWheel: onWheel('minutes'), children: date.getMinutes().toString().padStart(2, '0') })] }), jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center", children: [jsxRuntime.jsx(lucideReact.ChevronUpIcon, Object.assign({ className: "h-4 w-4 rounded hover:bg-slate-100 dark:hover:bg-slate-700", onClick: editDateField('minutes', step) }, increaseMinutes)), jsxRuntime.jsx(lucideReact.ChevronDownIcon, Object.assign({ className: "h-4 w-4 rounded hover:bg-slate-100 dark:hover:bg-slate-700", onClick: editDateField('minutes', -step) }, decreaseMinutes))] })] })] }));
|
|
1067
1090
|
};
|
|
1068
1091
|
|
|
1069
|
-
const DateTimeInput =
|
|
1092
|
+
const DateTimeInput = React.forwardRef((_a, ref) => {
|
|
1070
1093
|
var { className, value, clearable, type = 'datetime-local', step = 1, minDate, maxDate, hasErrors, onChange, onBlur, displayFormat = 'dddd, MMMM Do YYYY, HH:mm:ss', displayLocale = 'en' } = _a, props = __rest(_a, ["className", "value", "clearable", "type", "step", "minDate", "maxDate", "hasErrors", "onChange", "onBlur", "displayFormat", "displayLocale"]);
|
|
1071
|
-
const [isOpen, setIsOpen] =
|
|
1072
|
-
const [calendarView, setCalendarView] =
|
|
1073
|
-
const date =
|
|
1094
|
+
const [isOpen, setIsOpen] = React.useState();
|
|
1095
|
+
const [calendarView, setCalendarView] = React.useState('days');
|
|
1096
|
+
const date = React.useMemo(() => {
|
|
1074
1097
|
const result = value
|
|
1075
1098
|
? new Date(value)
|
|
1076
1099
|
: new Date(Math.min(Math.max(new Date(minDate !== null && minDate !== void 0 ? minDate : Date.now()).getTime(), Date.now()), new Date(maxDate !== null && maxDate !== void 0 ? maxDate : Date.now()).getTime()));
|
|
1077
1100
|
result.setMinutes(result.getMinutes() - ((result.getMinutes() + step) % step));
|
|
1078
1101
|
return result;
|
|
1079
1102
|
}, [step, maxDate, minDate, value]);
|
|
1080
|
-
const displayDate =
|
|
1081
|
-
const calendarRef =
|
|
1103
|
+
const displayDate = React.useMemo(() => value && getDisplayDate(date, displayFormat, displayLocale), [date, value, displayFormat, displayLocale]);
|
|
1104
|
+
const calendarRef = React.useRef(null);
|
|
1082
1105
|
useOutsideClick(calendarRef, () => setIsOpen(false));
|
|
1083
|
-
|
|
1106
|
+
React.useEffect(() => {
|
|
1084
1107
|
if (!isOpen) {
|
|
1085
1108
|
setCalendarView('days');
|
|
1086
1109
|
}
|
|
@@ -1119,10 +1142,10 @@ const DateTimeInput = react.forwardRef((_a, ref) => {
|
|
|
1119
1142
|
setIsOpen(false);
|
|
1120
1143
|
}
|
|
1121
1144
|
};
|
|
1122
|
-
return (jsxRuntime.jsxs("div", { className: cn('relative w-full', className), ref: ref, children: [jsxRuntime.jsx(BasicInput, Object.assign({}, props, { type: "text", readOnly: true, value: displayDate !== null && displayDate !== void 0 ? displayDate : '', hasErrors: hasErrors, onClick: handleOnClick, onKeyUp: handleOnKeyUp, clearable: clearable && !!displayDate, onClear: clearDate, suffixIcon: (type === null || type === void 0 ? void 0 : type.includes('date')) ? lucideReact.CalendarIcon : lucideReact.ClockIcon })), isOpen && (jsxRuntime.jsxs("div", { className: "absolute z-20 mt-2 flex origin-top-left flex-col rounded-md border bg-white shadow duration-200 dark:border-slate-700 dark:bg-slate-900 dark:text-white", tabIndex: 0, onBlur: handleOnBlur, ref: calendarRef, children: [(type === null || type === void 0 ? void 0 : type.includes('date')) && (jsxRuntime.jsx(DateSelector, { date: date, value: value, minDate: minDate, maxDate: maxDate, locale: displayLocale, calendarView: calendarView, setCalendarView: setCalendarView, setNewDate: setNewDate })), calendarView === 'days' && (jsxRuntime.jsxs("div", { className: "flex select-none items-center justify-end gap-2 px-3 py-2", children: [(type === null || type === void 0 ? void 0 : type.includes('time')) && (jsxRuntime.jsx(TimeSelector, { date: date, step: step, minDate: minDate, maxDate: maxDate, setNewDate: setNewDate })), jsxRuntime.jsx("div", { className: "cursor-pointer rounded-lg border border-transparent p-1 text-sm font-bold uppercase text-blue-600 transition duration-100 ease-in-out hover:bg-slate-100 dark:text-blue-500 dark:hover:bg-slate-700", onClick: () => setIsOpen(false), children: "OK" })] }))] }))] }));
|
|
1145
|
+
return (jsxRuntime.jsxs("div", { className: cn('relative w-full', className), ref: ref, children: [jsxRuntime.jsx(BasicInput, Object.assign({}, props, { type: "text", readOnly: true, value: displayDate !== null && displayDate !== void 0 ? displayDate : '', hasErrors: hasErrors, onClick: handleOnClick, onKeyUp: handleOnKeyUp, clearable: clearable && !!displayDate, onClear: clearDate, suffixIcon: (type === null || type === void 0 ? void 0 : type.includes('date')) ? lucideReact.CalendarIcon : lucideReact.ClockIcon, onSuffixIconClick: handleOnClick })), isOpen && (jsxRuntime.jsxs("div", { className: "absolute z-20 mt-2 flex origin-top-left flex-col rounded-md border bg-white shadow duration-200 dark:border-slate-700 dark:bg-slate-900 dark:text-white", tabIndex: 0, onBlur: handleOnBlur, ref: calendarRef, children: [(type === null || type === void 0 ? void 0 : type.includes('date')) && (jsxRuntime.jsx(DateSelector, { date: date, value: value, minDate: minDate, maxDate: maxDate, locale: displayLocale, calendarView: calendarView, setCalendarView: setCalendarView, setNewDate: setNewDate })), calendarView === 'days' && (jsxRuntime.jsxs("div", { className: "flex select-none items-center justify-end gap-2 px-3 py-2", children: [(type === null || type === void 0 ? void 0 : type.includes('time')) && (jsxRuntime.jsx(TimeSelector, { date: date, step: step, minDate: minDate, maxDate: maxDate, setNewDate: setNewDate })), jsxRuntime.jsx("div", { className: "cursor-pointer rounded-lg border border-transparent p-1 text-sm font-bold uppercase text-blue-600 transition duration-100 ease-in-out hover:bg-slate-100 dark:text-blue-500 dark:hover:bg-slate-700", onClick: () => setIsOpen(false), children: "OK" })] }))] }))] }));
|
|
1123
1146
|
});
|
|
1124
1147
|
|
|
1125
|
-
const ListContent =
|
|
1148
|
+
const ListContent = React.forwardRef((_a, ref) => {
|
|
1126
1149
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1127
1150
|
return (jsxRuntime.jsx(Block, Object.assign({ className: cn('z-50 min-w-[8rem] overflow-hidden rounded-md border border-slate-100 bg-white p-1 text-slate-700 shadow-md dark:border-slate-700 dark:bg-slate-900 dark:text-white', className), ref: ref }, props)));
|
|
1128
1151
|
});
|
|
@@ -1130,20 +1153,20 @@ const labelSizeClasses = {
|
|
|
1130
1153
|
small: 'p-1 text-sm',
|
|
1131
1154
|
medium: 'px-2 py-1.5',
|
|
1132
1155
|
};
|
|
1133
|
-
const ListItem =
|
|
1156
|
+
const ListItem = React.forwardRef((_a, ref) => {
|
|
1134
1157
|
var { className, size = 'medium', inset } = _a, props = __rest(_a, ["className", "size", "inset"]);
|
|
1135
1158
|
return (jsxRuntime.jsx(Flex, Object.assign({ className: cn(labelSizeClasses[size], 'relative cursor-default select-none gap-2 rounded-md outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-slate-700', inset && 'pl-8', className), align: "center", ref: ref }, props)));
|
|
1136
1159
|
});
|
|
1137
|
-
const ListLabel =
|
|
1160
|
+
const ListLabel = React.forwardRef((_a, ref) => {
|
|
1138
1161
|
var { className, size = 'medium', inset } = _a, props = __rest(_a, ["className", "size", "inset"]);
|
|
1139
1162
|
return (jsxRuntime.jsx(Block, Object.assign({ className: cn(labelSizeClasses[size], 'font-semibold text-slate-900 dark:text-slate-300', inset && 'pl-8', className), ref: ref }, props)));
|
|
1140
1163
|
});
|
|
1141
|
-
const ListIndicator =
|
|
1164
|
+
const ListIndicator = React.forwardRef((_a, ref) => {
|
|
1142
1165
|
var { className, icon: Icon, iconClassName } = _a, props = __rest(_a, ["className", "icon", "iconClassName"]);
|
|
1143
1166
|
return (jsxRuntime.jsx(Flex, Object.assign({ className: cn('absolute left-2 h-3.5 w-3.5', className), align: "center", justify: "center", ref: ref }, props, { children: jsxRuntime.jsx(Icon, { className: iconClassName }) })));
|
|
1144
1167
|
});
|
|
1145
|
-
const ListIcon =
|
|
1146
|
-
const ListSeparator =
|
|
1168
|
+
const ListIcon = React.forwardRef(({ className, icon: Icon }, ref) => jsxRuntime.jsx(Icon, { className: cn('h-4 w-4', className), ref: ref }));
|
|
1169
|
+
const ListSeparator = React.forwardRef((_a, ref) => {
|
|
1147
1170
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1148
1171
|
return (jsxRuntime.jsx(Block, Object.assign({ className: cn('-mx-1 my-1 h-px bg-slate-100 dark:bg-slate-700', className), ref: ref }, props)));
|
|
1149
1172
|
});
|
|
@@ -1160,42 +1183,42 @@ const DropdownMenuGroup = DropdownMenuPrimitive__namespace.Group;
|
|
|
1160
1183
|
const DropdownMenuPortal = DropdownMenuPrimitive__namespace.Portal;
|
|
1161
1184
|
const DropdownMenuSub = DropdownMenuPrimitive__namespace.Sub;
|
|
1162
1185
|
const DropdownMenuRadioGroup = DropdownMenuPrimitive__namespace.RadioGroup;
|
|
1163
|
-
const DropdownMenuSubTrigger =
|
|
1186
|
+
const DropdownMenuSubTrigger = React.forwardRef((_a, ref) => {
|
|
1164
1187
|
var { className, inset, children } = _a, props = __rest(_a, ["className", "inset", "children"]);
|
|
1165
1188
|
return (jsxRuntime.jsx(DropdownMenuPrimitive__namespace.SubTrigger, Object.assign({ ref: ref }, props, { asChild: true, children: jsxRuntime.jsxs(List.Item, { className: className, inset: inset, children: [children, jsxRuntime.jsx(lucideReact.ChevronRightIcon, { className: "ml-auto h-4 w-4" })] }) })));
|
|
1166
1189
|
});
|
|
1167
1190
|
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive__namespace.SubTrigger.displayName;
|
|
1168
|
-
const DropdownMenuSubContent =
|
|
1191
|
+
const DropdownMenuSubContent = React.forwardRef((_a, ref) => {
|
|
1169
1192
|
var { className, children } = _a, props = __rest(_a, ["className", "children"]);
|
|
1170
1193
|
return (jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Portal, { children: jsxRuntime.jsx(DropdownMenuPrimitive__namespace.SubContent, Object.assign({ ref: ref }, props, { asChild: true, children: jsxRuntime.jsx(List, { className: className, children: children }) })) }));
|
|
1171
1194
|
});
|
|
1172
1195
|
DropdownMenuSubContent.displayName = DropdownMenuPrimitive__namespace.SubContent.displayName;
|
|
1173
|
-
const DropdownMenuContent =
|
|
1196
|
+
const DropdownMenuContent = React.forwardRef((_a, ref) => {
|
|
1174
1197
|
var { className, children, sideOffset = 4 } = _a, props = __rest(_a, ["className", "children", "sideOffset"]);
|
|
1175
1198
|
return (jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Portal, { children: jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Content, Object.assign({ ref: ref, sideOffset: sideOffset }, props, { asChild: true, children: jsxRuntime.jsx(List, { className: className, children: children }) })) }));
|
|
1176
1199
|
});
|
|
1177
1200
|
DropdownMenuContent.displayName = DropdownMenuPrimitive__namespace.Content.displayName;
|
|
1178
|
-
const DropdownMenuItem =
|
|
1201
|
+
const DropdownMenuItem = React.forwardRef((_a, ref) => {
|
|
1179
1202
|
var { className, inset, children } = _a, props = __rest(_a, ["className", "inset", "children"]);
|
|
1180
1203
|
return (jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Item, Object.assign({ ref: ref }, props, { asChild: true, children: jsxRuntime.jsx(List.Item, { inset: inset, className: className, children: children }) })));
|
|
1181
1204
|
});
|
|
1182
1205
|
DropdownMenuItem.displayName = DropdownMenuPrimitive__namespace.Item.displayName;
|
|
1183
|
-
const DropdownMenuCheckboxItem =
|
|
1206
|
+
const DropdownMenuCheckboxItem = React.forwardRef((_a, ref) => {
|
|
1184
1207
|
var { className, children } = _a, props = __rest(_a, ["className", "children"]);
|
|
1185
1208
|
return (jsxRuntime.jsx(DropdownMenuPrimitive__namespace.CheckboxItem, Object.assign({ ref: ref }, props, { asChild: true, children: jsxRuntime.jsxs(List.Item, { inset: true, className: className, children: [jsxRuntime.jsx(DropdownMenuPrimitive__namespace.ItemIndicator, { asChild: true, children: jsxRuntime.jsx(List.Indicator, { icon: lucideReact.CheckIcon, iconClassName: "h-4 w-4" }) }), children] }) })));
|
|
1186
1209
|
});
|
|
1187
1210
|
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive__namespace.CheckboxItem.displayName;
|
|
1188
|
-
const DropdownMenuRadioItem =
|
|
1211
|
+
const DropdownMenuRadioItem = React.forwardRef((_a, ref) => {
|
|
1189
1212
|
var { className, children } = _a, props = __rest(_a, ["className", "children"]);
|
|
1190
1213
|
return (jsxRuntime.jsx(DropdownMenuPrimitive__namespace.RadioItem, Object.assign({ ref: ref }, props, { asChild: true, children: jsxRuntime.jsxs(List.Item, { inset: true, className: className, children: [jsxRuntime.jsx(DropdownMenuPrimitive__namespace.ItemIndicator, { asChild: true, children: jsxRuntime.jsx(List.Indicator, { icon: lucideReact.CircleIcon, iconClassName: "h-2 w-2 fill-current" }) }), children] }) })));
|
|
1191
1214
|
});
|
|
1192
1215
|
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive__namespace.RadioItem.displayName;
|
|
1193
|
-
const DropdownMenuLabel =
|
|
1216
|
+
const DropdownMenuLabel = React.forwardRef((_a, ref) => {
|
|
1194
1217
|
var { className, inset, children } = _a, props = __rest(_a, ["className", "inset", "children"]);
|
|
1195
1218
|
return (jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Label, Object.assign({ ref: ref }, props, { asChild: true, children: jsxRuntime.jsx(List.Label, { className: className, inset: inset, children: children }) })));
|
|
1196
1219
|
});
|
|
1197
1220
|
DropdownMenuLabel.displayName = DropdownMenuPrimitive__namespace.Label.displayName;
|
|
1198
|
-
const DropdownMenuSeparator =
|
|
1221
|
+
const DropdownMenuSeparator = React.forwardRef((_a, ref) => {
|
|
1199
1222
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1200
1223
|
return (jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Separator, Object.assign({ ref: ref }, props, { asChild: true, children: jsxRuntime.jsx(List.Separator, { className: className }) })));
|
|
1201
1224
|
});
|
|
@@ -1223,12 +1246,12 @@ const DropdownMenu = Object.assign(DropdownMenuPrimitive__namespace.Root, {
|
|
|
1223
1246
|
RadioGroup: DropdownMenuRadioGroup,
|
|
1224
1247
|
});
|
|
1225
1248
|
|
|
1226
|
-
const SelectInput =
|
|
1249
|
+
const SelectInput = React.forwardRef((_a, ref) => {
|
|
1227
1250
|
var { className, items, renderItem = (item) => item.label, value, multiple, clearable, allowAddition, onNewItemAdded, search, searchPredicate = (item, searchValue) => item.label.toLowerCase().includes(searchValue.toLowerCase()), selectPredicate = (a, b) => a === b, onChange, readOnly, parentRef } = _a, props = __rest(_a, ["className", "items", "renderItem", "value", "multiple", "clearable", "allowAddition", "onNewItemAdded", "search", "searchPredicate", "selectPredicate", "onChange", "readOnly", "parentRef"]);
|
|
1228
|
-
const [open, setOpen] =
|
|
1229
|
-
const [searchValue, setSearchValue] =
|
|
1230
|
-
const pureItems =
|
|
1231
|
-
const selectedItems =
|
|
1251
|
+
const [open, setOpen] = React.useState(false);
|
|
1252
|
+
const [searchValue, setSearchValue] = React.useState('');
|
|
1253
|
+
const pureItems = React.useMemo(() => items.flatMap((item) => (item.group ? item.items : [item])), [items]);
|
|
1254
|
+
const selectedItems = React.useMemo(() => value
|
|
1232
1255
|
? !multiple
|
|
1233
1256
|
? pureItems.find((item) => selectPredicate(item.value, value))
|
|
1234
1257
|
? [pureItems.find((item) => selectPredicate(item.value, value))]
|
|
@@ -1239,7 +1262,7 @@ const SelectInput = react.forwardRef((_a, ref) => {
|
|
|
1239
1262
|
.filter(Boolean)
|
|
1240
1263
|
: []
|
|
1241
1264
|
: [], [multiple, pureItems, selectPredicate, value]);
|
|
1242
|
-
const filteredItems =
|
|
1265
|
+
const filteredItems = React.useMemo(() => !search || !searchValue
|
|
1243
1266
|
? items
|
|
1244
1267
|
: items.flatMap((item) => item.group
|
|
1245
1268
|
? item.items.some((subItem) => subItem.label.toLowerCase().includes(searchValue.toLowerCase()))
|
|
@@ -1250,13 +1273,13 @@ const SelectInput = react.forwardRef((_a, ref) => {
|
|
|
1250
1273
|
: item.label.toLowerCase().includes(searchValue.toLowerCase())
|
|
1251
1274
|
? [item]
|
|
1252
1275
|
: []), [items, search, searchValue]);
|
|
1253
|
-
const text =
|
|
1276
|
+
const text = React.useMemo(() => selectedItems.length
|
|
1254
1277
|
? !multiple
|
|
1255
1278
|
? selectedItems[0].label
|
|
1256
1279
|
: selectedItems.map((item) => item.label).join(', ')
|
|
1257
1280
|
: undefined, [multiple, selectedItems]);
|
|
1258
|
-
const selectedMap =
|
|
1259
|
-
const handleOnSelect =
|
|
1281
|
+
const selectedMap = React.useMemo(() => selectedItems.reduce((prev, curr) => (Object.assign(Object.assign({}, prev), { [curr.id]: curr.value })), {}), [selectedItems]);
|
|
1282
|
+
const handleOnSelect = React.useCallback((id) => {
|
|
1260
1283
|
var _a, _b, _c;
|
|
1261
1284
|
!multiple && setOpen(false);
|
|
1262
1285
|
if (!multiple) {
|
|
@@ -1292,7 +1315,7 @@ const SelectInput = react.forwardRef((_a, ref) => {
|
|
|
1292
1315
|
};
|
|
1293
1316
|
const GroupComponent = multiple ? DropdownMenu.Group : DropdownMenu.RadioGroup;
|
|
1294
1317
|
const ItemComponent = multiple ? DropdownMenu.CheckboxItem : DropdownMenu.RadioItem;
|
|
1295
|
-
const RenderOption =
|
|
1318
|
+
const RenderOption = React.useCallback((option) => {
|
|
1296
1319
|
return (jsxRuntime.jsx(ItemComponent, { className: cn('w-full cursor-pointer hover:bg-slate-200 dark:hover:bg-slate-700', {
|
|
1297
1320
|
'bg-slate-200 dark:bg-slate-700': selectedMap[option.id],
|
|
1298
1321
|
}), value: String(option.id), checked: !!selectedMap[option.id], onSelect: (event) => {
|
|
@@ -1300,16 +1323,31 @@ const SelectInput = react.forwardRef((_a, ref) => {
|
|
|
1300
1323
|
handleOnSelect(option.id);
|
|
1301
1324
|
}, children: jsxRuntime.jsx("span", { children: renderItem(option, !!selectedMap[option.id]) }) }));
|
|
1302
1325
|
}, [ItemComponent, handleOnSelect, multiple, renderItem, selectedMap]);
|
|
1303
|
-
return (jsxRuntime.jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [jsxRuntime.jsx(DropdownMenu.Trigger, { className: cn('w-full', className), children: jsxRuntime.jsx(TextInput, Object.assign({ className: "[&>div>*]:cursor-pointer", inputClassName: "text-left" }, props, { value: text !== null && text !== void 0 ? text : '', clearable: clearable && !!selectedItems.length, onClear: handleOnClear, suffixIcon: lucideReact.ChevronDownIcon, ref: ref, readOnly: true })) }), jsxRuntime.jsxs(DropdownMenu.Content, { className: "flex max-h-80 w-[calc(var(--radix-popper-anchor-width))] flex-col overflow-hidden", children: [search && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TextInput, { value: searchValue, placeholder: "Search...", size: props.size, onChange: handleOnSearchValueChange, clearable: !!searchValue.length, onClear: clearSearchValue }), jsxRuntime.jsx(DropdownMenu.Separator, { className: "w-full" })] })), filteredItems.length === 0 &&
|
|
1326
|
+
return (jsxRuntime.jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [jsxRuntime.jsx(DropdownMenu.Trigger, { className: cn('w-full', className), children: jsxRuntime.jsx(TextInput, Object.assign({ className: "[&>div>*]:cursor-pointer", inputClassName: "text-left" }, props, { value: text !== null && text !== void 0 ? text : '', clearable: clearable && !!selectedItems.length, onClear: handleOnClear, suffixIcon: lucideReact.ChevronDownIcon, onSuffixIconClick: () => setOpen((open) => !open), ref: ref, readOnly: true })) }), jsxRuntime.jsxs(DropdownMenu.Content, { className: "flex max-h-80 w-[calc(var(--radix-popper-anchor-width))] flex-col overflow-hidden", children: [search && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TextInput, { value: searchValue, placeholder: "Search...", size: props.size, onChange: handleOnSearchValueChange, clearable: !!searchValue.length, onClear: clearSearchValue }), jsxRuntime.jsx(DropdownMenu.Separator, { className: "w-full" })] })), filteredItems.length === 0 &&
|
|
1304
1327
|
(allowAddition && searchValue ? (jsxRuntime.jsxs("button", { className: "rounded bg-slate-100 text-center hover:bg-slate-200 dark:bg-slate-900/30 dark:hover:bg-slate-700/30", onClick: handleOnAddItemClicked, children: ["Add '", searchValue, "'"] })) : (jsxRuntime.jsx("div", { className: "text-center text-slate-500", children: "No items." }))), jsxRuntime.jsx(GroupComponent, { className: "flex flex-col gap-1 overflow-auto", value: !multiple && selectedItems.length ? String(selectedItems[0].id) : undefined, children: filteredItems.map((item, index) => item.group ? (jsxRuntime.jsxs(Flex, { className: "gap-1", direction: "column", fullWidth: true, children: [jsxRuntime.jsx(DropdownMenu.Label, { className: "sticky top-0 z-[51] w-full rounded-md border bg-white py-1 dark:bg-slate-900", children: item.label }), item.items.map((subItem) => (jsxRuntime.jsx(RenderOption, Object.assign({}, subItem), subItem.id))), index < filteredItems.length - 1 && (jsxRuntime.jsx("div", { className: "mb-1 h-px w-full bg-slate-200 dark:bg-slate-700" }))] }, item.id)) : (jsxRuntime.jsx(RenderOption, Object.assign({}, item), item.id))) })] })] }));
|
|
1305
1328
|
});
|
|
1306
1329
|
|
|
1330
|
+
const FileInput = React.forwardRef((_a, ref) => {
|
|
1331
|
+
var { className, value, onChange, onFileChange, accept } = _a, props = __rest(_a, ["className", "value", "onChange", "onFileChange", "accept"]);
|
|
1332
|
+
const fileInputRef = React.useRef(null);
|
|
1333
|
+
const handleFileChange = (_a) => __awaiter(void 0, [_a], void 0, function* ({ target: { files } }) {
|
|
1334
|
+
console.log(files);
|
|
1335
|
+
if (files && files.length > 0) {
|
|
1336
|
+
const file = files[0];
|
|
1337
|
+
console.log(file, file.name, onChange, onFileChange);
|
|
1338
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(file.name);
|
|
1339
|
+
onFileChange === null || onFileChange === void 0 ? void 0 : onFileChange(file);
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TextInput, Object.assign({ className: cn('[&>div>*]:cursor-pointer', className), inputClassName: "text-left" }, props, { value: value !== null && value !== void 0 ? value : '', onClick: () => { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, suffixIcon: lucideReact.CloudUploadIcon, onSuffixIconClick: () => { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, ref: ref, readOnly: true })), jsxRuntime.jsx("input", { ref: (ref) => (fileInputRef.current = ref), type: "file", hidden: true, accept: accept, onChange: handleFileChange })] }));
|
|
1343
|
+
});
|
|
1344
|
+
|
|
1307
1345
|
const FormGroup = ({ className, label, children }) => (jsxRuntime.jsxs(Flex, { className: cn('relative !gap-4 rounded-lg border p-4 dark:border-slate-700', className), direction: "column", fullWidth: true, children: [jsxRuntime.jsx("div", { className: "absolute right-0 top-0 rounded-bl-lg rounded-tr-lg bg-slate-500 px-2 py-1 font-medium text-white dark:bg-slate-900 dark:text-white", children: label }), children] }));
|
|
1308
1346
|
|
|
1309
1347
|
function withForm(Component) {
|
|
1310
|
-
return
|
|
1348
|
+
return React.forwardRef((props, ref) => {
|
|
1311
1349
|
const _a = props, { name, pattern, validate } = _a, restProps = __rest(_a, ["name", "pattern", "validate"]);
|
|
1312
|
-
const { control } = reactHookForm.useFormContext();
|
|
1350
|
+
const { control, formState } = reactHookForm.useFormContext();
|
|
1313
1351
|
return (jsxRuntime.jsx(reactHookForm.Controller, { name: name, control: control, rules: {
|
|
1314
1352
|
required: restProps.required,
|
|
1315
1353
|
min: restProps.min,
|
|
@@ -1320,7 +1358,8 @@ function withForm(Component) {
|
|
|
1320
1358
|
validate,
|
|
1321
1359
|
}, render: ({ field, fieldState }) => {
|
|
1322
1360
|
var _a, _b;
|
|
1323
|
-
return (jsxRuntime.jsx(Component, Object.assign({}, restProps, field, { value: (_a = field.value) !== null && _a !== void 0 ? _a : '', disabled: (_b = field.disabled) !== null && _b !== void 0 ? _b : restProps.disabled
|
|
1361
|
+
return (jsxRuntime.jsx(Component, Object.assign({}, restProps, field, { value: (_a = field.value) !== null && _a !== void 0 ? _a : '', disabled: ((_b = field.disabled) !== null && _b !== void 0 ? _b : restProps.disabled) ||
|
|
1362
|
+
formState.isSubmitting, hasErrors: fieldState.error, ref: mergeRefs([ref, field.ref]) })));
|
|
1324
1363
|
} }));
|
|
1325
1364
|
});
|
|
1326
1365
|
}
|
|
@@ -1333,9 +1372,10 @@ const FormInputs = {
|
|
|
1333
1372
|
Checkbox: withForm(CheckboxInput),
|
|
1334
1373
|
DateTime: withForm(DateTimeInput),
|
|
1335
1374
|
Select: withForm(SelectInput),
|
|
1375
|
+
File: withForm(FileInput),
|
|
1336
1376
|
};
|
|
1337
1377
|
|
|
1338
|
-
const HintRoot =
|
|
1378
|
+
const HintRoot = React.forwardRef(({ children }, ref) => (jsxRuntime.jsx(Block, { className: "relative", ref: ref, children: children })));
|
|
1339
1379
|
HintRoot.displayName = 'HintRoot';
|
|
1340
1380
|
const dotSizeClassNames = {
|
|
1341
1381
|
small: {
|
|
@@ -1377,7 +1417,7 @@ const colorClassNames = {
|
|
|
1377
1417
|
pink: 'bg-pink-500 dark:bg-pink-600',
|
|
1378
1418
|
rose: 'bg-rose-500 dark:bg-rose-600',
|
|
1379
1419
|
};
|
|
1380
|
-
const HintDot =
|
|
1420
|
+
const HintDot = React.forwardRef(({ size = 'medium', placement = 'top-right', color = 'green', ping }, ref) => (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Block, { className: cn('absolute rounded-full', colorClassNames[color], dotSizeClassNames[size].base, {
|
|
1381
1421
|
[`${dotSizeClassNames[size].top} ${dotSizeClassNames[size].left}`]: placement === 'top-left',
|
|
1382
1422
|
[`${dotSizeClassNames[size].top} ${dotSizeClassNames[size].right}`]: placement === 'top-right',
|
|
1383
1423
|
[`${dotSizeClassNames[size].bottom} ${dotSizeClassNames[size].right}`]: placement === 'bottom-right',
|
|
@@ -1395,7 +1435,7 @@ const badgeSizeClassNames = {
|
|
|
1395
1435
|
bottom: 'bottom-0 translate-y-1/2',
|
|
1396
1436
|
left: 'left-2 -translate-x-full',
|
|
1397
1437
|
};
|
|
1398
|
-
const HintBadge =
|
|
1438
|
+
const HintBadge = React.forwardRef((_a, ref) => {
|
|
1399
1439
|
var { className, size = 'small', placement = 'top-right' } = _a, props = __rest(_a, ["className", "size", "placement"]);
|
|
1400
1440
|
return (jsxRuntime.jsx(Badge, Object.assign({ className: cn('absolute px-1', size === 'small' ? 'h-5' : 'h-6', {
|
|
1401
1441
|
[`${badgeSizeClassNames.top} ${badgeSizeClassNames.left}`]: placement === 'top-left',
|
|
@@ -1408,9 +1448,9 @@ HintBadge.displayName = 'HintBadge';
|
|
|
1408
1448
|
const Hint = Object.assign(HintRoot, { Dot: HintDot, Badge: HintBadge });
|
|
1409
1449
|
|
|
1410
1450
|
const Pagination = ({ disabled, pageSize = 10, currentPage, totalItems, setCurrentPage, }) => {
|
|
1411
|
-
const totalPages =
|
|
1451
|
+
const totalPages = React.useMemo(() => Math.ceil(totalItems / pageSize), [pageSize, totalItems]);
|
|
1412
1452
|
const pagination = usePagination(currentPage + 1, totalPages);
|
|
1413
|
-
|
|
1453
|
+
React.useEffect(() => {
|
|
1414
1454
|
setCurrentPage((page) => Math.min(page, Math.max(0, totalPages - 1)));
|
|
1415
1455
|
}, [setCurrentPage, totalPages]);
|
|
1416
1456
|
return (jsxRuntime.jsx(Flex, { justify: "end", children: jsxRuntime.jsxs(Flex, { className: "h-10 gap-0 divide-x rounded-md border border-slate-300 bg-white dark:divide-slate-700 dark:border-slate-700 dark:bg-slate-800", children: [jsxRuntime.jsx(PaginationItem, { title: "First page", onClick: () => setCurrentPage(0), disabled: !currentPage || disabled, children: jsxRuntime.jsx(lucideReact.ChevronsLeftIcon, { className: "h-5 w-5" }) }), jsxRuntime.jsx(PaginationItem, { title: "Previous page", onClick: () => currentPage && setCurrentPage(currentPage - 1), disabled: !currentPage || disabled, children: jsxRuntime.jsx(lucideReact.ChevronLeftIcon, { className: "h-5 w-5" }) }), pagination.map((page, index) => (jsxRuntime.jsx(PaginationItem, { active: page !== '...' && page - 1 === currentPage, title: page !== '...' ? `Page ${page}` : undefined, onClick: page !== '...' ? () => setCurrentPage(page - 1) : undefined, disabled: page === '...' || disabled, children: page }, index))), jsxRuntime.jsx(PaginationItem, { title: "Next page", onClick: () => currentPage + 1 < totalPages && setCurrentPage(currentPage + 1), disabled: currentPage + 1 === totalPages || disabled, children: jsxRuntime.jsx(lucideReact.ChevronRightIcon, { className: "h-5 w-5" }) }), jsxRuntime.jsx(PaginationItem, { title: "Last page", onClick: () => setCurrentPage(Math.floor(totalItems && !(totalItems % pageSize)
|
|
@@ -1474,11 +1514,11 @@ function defaultRender(item, field) {
|
|
|
1474
1514
|
}
|
|
1475
1515
|
function DataTable({ className, columns, rows, sorting, pagination, actions = [], isLoading, rowExtraContent, noDataMessage, onRowClick, rowClassName, }) {
|
|
1476
1516
|
var _a;
|
|
1477
|
-
const footerRef =
|
|
1478
|
-
const [expandedRows, setExpandedRows] =
|
|
1479
|
-
const allRowsExpanded =
|
|
1480
|
-
const _columns =
|
|
1481
|
-
const columnsLength =
|
|
1517
|
+
const footerRef = React.useRef(null);
|
|
1518
|
+
const [expandedRows, setExpandedRows] = React.useState({});
|
|
1519
|
+
const allRowsExpanded = React.useMemo(() => rowExtraContent ? rows.every((row) => expandedRows[rowExtraContent.idGetter(row)]) : false, [expandedRows, rowExtraContent, rows]);
|
|
1520
|
+
const _columns = React.useMemo(() => (Array.isArray(columns) ? columns : Object.values(columns)).filter((column) => !column.hide), [columns]);
|
|
1521
|
+
const columnsLength = React.useMemo(() => (rowExtraContent ? 1 : 0) + _columns.length + Math.min(1, actions.length), [_columns.length, actions.length, rowExtraContent]);
|
|
1482
1522
|
const handleSorting = (field, comparator) => () => {
|
|
1483
1523
|
if (!sorting)
|
|
1484
1524
|
return;
|
|
@@ -1530,7 +1570,7 @@ function DataTable({ className, columns, rows, sorting, pagination, actions = []
|
|
|
1530
1570
|
: undefined, children: [column.header, sorting &&
|
|
1531
1571
|
!column.noSorting &&
|
|
1532
1572
|
(((_b = sorting.sorting) === null || _b === void 0 ? void 0 : _b.field) !== column.field ? (jsxRuntime.jsx(lucideReact.ArrowUpDownIcon, { className: "absolute top-1/2 float-right ml-1 hidden h-4 w-4 -translate-y-1/2 group-hover:inline-block" })) : ((_c = sorting.sorting) === null || _c === void 0 ? void 0 : _c.direction) === 'asc' ? (jsxRuntime.jsx(lucideReact.SortAscIcon, { className: "absolute top-1/2 float-right ml-1 inline-block h-4 w-4 -translate-y-1/2" })) : (jsxRuntime.jsx(lucideReact.SortDescIcon, { className: "absolute top-1/2 float-right ml-1 inline-block h-4 w-4 -translate-y-1/2" })))] }, columnIndex));
|
|
1533
|
-
}), actions.length > 0 && jsxRuntime.jsx(Table.HeadCell, { align: "center", children: "Actions" })] }) }), jsxRuntime.jsxs(Table.Body, { className: "relative", children: [isLoading && (jsxRuntime.jsx(Table.Row, { children: jsxRuntime.jsx(Table.Cell, { className: cn('z-10 h-full w-full p-0', {
|
|
1573
|
+
}), actions.filter((action) => !action.hide).length > 0 && (jsxRuntime.jsx(Table.HeadCell, { align: "center", children: "Actions" }))] }) }), jsxRuntime.jsxs(Table.Body, { className: "relative", children: [isLoading && (jsxRuntime.jsx(Table.Row, { children: jsxRuntime.jsx(Table.Cell, { className: cn('z-10 h-full w-full p-0', {
|
|
1534
1574
|
absolute: rows.length,
|
|
1535
1575
|
}), colSpan: columnsLength, children: jsxRuntime.jsx(Spinner, { className: "bg-white/50 py-4 dark:bg-slate-700/50" }) }) })), !isLoading && !rows.length && (jsxRuntime.jsx(Table.Row, { children: jsxRuntime.jsx(Table.Cell, { colSpan: columnsLength, children: jsxRuntime.jsx(Flex, { className: "text-slate-500", justify: "center", children: noDataMessage !== null && noDataMessage !== void 0 ? noDataMessage : 'No data' }) }) })), rows.map((item, rowIndex) => [
|
|
1536
1576
|
jsxRuntime.jsxs(Table.Row, { className: cn({
|
|
@@ -1538,7 +1578,7 @@ function DataTable({ className, columns, rows, sorting, pagination, actions = []
|
|
|
1538
1578
|
}, rowClassName === null || rowClassName === void 0 ? void 0 : rowClassName(item, rowIndex)), onClick: handleRowClicked(item, rowIndex), children: [rowExtraContent && (jsxRuntime.jsx(Table.Cell, { className: "w-min", align: "center", children: jsxRuntime.jsx(ExpandButton, { folded: !expandedRows[rowExtraContent.idGetter(item)], foldComponent: lucideReact.MinusIcon, unfoldComponent: lucideReact.PlusIcon, onClick: handleExpandRow(rowExtraContent.idGetter(item)) }) })), _columns.map((column, columnIndex) => {
|
|
1539
1579
|
var _a, _b, _c;
|
|
1540
1580
|
return (jsxRuntime.jsx(Table.Cell, { className: column.className, align: (_a = column.align) !== null && _a !== void 0 ? _a : 'left', children: (_c = (_b = column.render) === null || _b === void 0 ? void 0 : _b.call(column, item, rowIndex)) !== null && _c !== void 0 ? _c : defaultRender(item, column.field) }, columnIndex));
|
|
1541
|
-
}), actions.length > 0 && (jsxRuntime.jsx(Table.Cell, { className: "py-3", children: jsxRuntime.jsx(Flex, { align: "center", justify: "center", children: actions
|
|
1581
|
+
}), actions.filter((action) => !action.hide).length > 0 && (jsxRuntime.jsx(Table.Cell, { className: "py-3", children: jsxRuntime.jsx(Flex, { align: "center", justify: "center", children: actions
|
|
1542
1582
|
.filter((action) => { var _a; return typeof action.hide === 'boolean' ? !action.hide : !((_a = action.hide) === null || _a === void 0 ? void 0 : _a.call(action, item)); })
|
|
1543
1583
|
.map((action, actionIndex) => {
|
|
1544
1584
|
var _a;
|
|
@@ -1562,12 +1602,12 @@ const $Dialog = DialogPrimitive__namespace.Root;
|
|
|
1562
1602
|
const DialogTrigger = DialogPrimitive__namespace.Trigger;
|
|
1563
1603
|
const DialogPortal = DialogPrimitive__namespace.Portal;
|
|
1564
1604
|
const DialogClose = DialogPrimitive__namespace.Close;
|
|
1565
|
-
const DialogOverlay =
|
|
1605
|
+
const DialogOverlay = React.forwardRef((_a, ref) => {
|
|
1566
1606
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1567
1607
|
return (jsxRuntime.jsx(DialogPrimitive__namespace.Overlay, Object.assign({ ref: ref, className: cn('data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 backdrop-blur-sm', className) }, props)));
|
|
1568
1608
|
});
|
|
1569
1609
|
DialogOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
|
|
1570
|
-
const DialogContent =
|
|
1610
|
+
const DialogContent = React.forwardRef((_a, ref) => {
|
|
1571
1611
|
var { className, fullScreen, children } = _a, props = __rest(_a, ["className", "fullScreen", "children"]);
|
|
1572
1612
|
return (jsxRuntime.jsxs(DialogPortal, { children: [jsxRuntime.jsx(DialogOverlay, {}), jsxRuntime.jsxs(DialogPrimitive__namespace.Content, Object.assign({ ref: ref, className: cn('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 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]', 'fixed left-[50%] top-[50%] z-50 flex w-full max-w-lg translate-x-[-50%] translate-y-[-50%] flex-col gap-3 rounded-lg border bg-white p-3 shadow-md duration-200 xl:gap-4 xl:p-4 dark:border-slate-700 dark:bg-slate-900 dark:text-white', className, fullScreen && 'h-full max-h-none w-full max-w-none rounded-none') }, props, { children: [children, jsxRuntime.jsx(DialogPrimitive__namespace.Close, { className: "!absolute right-1 top-1 opacity-70 ring-offset-white transition-opacity hover:opacity-100 disabled:pointer-events-none xl:right-2 xl:top-2", asChild: true, children: jsxRuntime.jsx(Button, { prefixIcon: lucideReact.XIcon, size: "small", variant: "text" }) })] }))] }));
|
|
1573
1613
|
});
|
|
@@ -1582,12 +1622,12 @@ const DialogFooter = (_a) => {
|
|
|
1582
1622
|
return (jsxRuntime.jsx("div", Object.assign({ className: cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className) }, props)));
|
|
1583
1623
|
};
|
|
1584
1624
|
DialogFooter.displayName = 'DialogFooter';
|
|
1585
|
-
const DialogTitle =
|
|
1625
|
+
const DialogTitle = React.forwardRef((_a, ref) => {
|
|
1586
1626
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1587
1627
|
return (jsxRuntime.jsx(DialogPrimitive__namespace.Title, Object.assign({ ref: ref, className: cn('text-lg font-semibold leading-none tracking-tight', className) }, props)));
|
|
1588
1628
|
});
|
|
1589
1629
|
DialogTitle.displayName = DialogPrimitive__namespace.Title.displayName;
|
|
1590
|
-
const DialogDescription =
|
|
1630
|
+
const DialogDescription = React.forwardRef((_a, ref) => {
|
|
1591
1631
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1592
1632
|
return (jsxRuntime.jsx(DialogPrimitive__namespace.Description, Object.assign({ ref: ref, className: cn('text-sm text-slate-600 dark:text-slate-400', className) }, props)));
|
|
1593
1633
|
});
|
|
@@ -1607,7 +1647,7 @@ const Dialog = Object.assign($Dialog, {
|
|
|
1607
1647
|
const ConfirmDialog = ({ open, title, children, yesLabel, noLabel, onConfirm, onClose, }) => (jsxRuntime.jsx(Dialog, { open: open, onOpenChange: (value) => !value && onClose(), children: jsxRuntime.jsxs(Dialog.Content, { onPointerDownOutside: (event) => event.preventDefault(), children: [jsxRuntime.jsx(Dialog.Header, { children: jsxRuntime.jsx(Dialog.Title, { children: title }) }), children, jsxRuntime.jsxs(Dialog.Footer, { children: [jsxRuntime.jsx(Dialog.Close, { asChild: true, children: jsxRuntime.jsx(Button, { color: "red", children: noLabel !== null && noLabel !== void 0 ? noLabel : 'No' }) }), jsxRuntime.jsx(Dialog.Close, { asChild: true, children: jsxRuntime.jsx(Button, { color: "green", onClick: onConfirm, children: yesLabel !== null && yesLabel !== void 0 ? yesLabel : 'Yes' }) })] })] }) }));
|
|
1608
1648
|
|
|
1609
1649
|
const FormDialog = ({ className, open, title, form, children, submitLabel = 'Submit', cancelLabel = 'Cancel', extraAction, onSubmit, onInvalid, onClose, }) => {
|
|
1610
|
-
const id =
|
|
1650
|
+
const id = React.useId();
|
|
1611
1651
|
const handleSubmit = (data, event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1612
1652
|
try {
|
|
1613
1653
|
yield onSubmit(data, event);
|
|
@@ -1620,7 +1660,7 @@ const FormDialog = ({ className, open, title, form, children, submitLabel = 'Sub
|
|
|
1620
1660
|
};
|
|
1621
1661
|
|
|
1622
1662
|
function ListSorter({ className, items, idResolver, renderer, onChange, }) {
|
|
1623
|
-
const adaptedItems =
|
|
1663
|
+
const adaptedItems = React.useMemo(() => items.map((value, index) => ({ id: idResolver(value, index), value })), [idResolver, items]);
|
|
1624
1664
|
const sensors = core.useSensors(core.useSensor(core.PointerSensor), core.useSensor(core.KeyboardSensor, { coordinateGetter: sortable.sortableKeyboardCoordinates }));
|
|
1625
1665
|
const onDragEnd = ({ active, over }) => {
|
|
1626
1666
|
if (!over || active.id === over.id)
|
|
@@ -1646,8 +1686,8 @@ function SortableItem({ item, index, renderer, }) {
|
|
|
1646
1686
|
}
|
|
1647
1687
|
|
|
1648
1688
|
function ListSorterDialog({ className, open, title, items, idResolver, renderer, cancelLabel, submitLabel, onSubmit, onClose, }) {
|
|
1649
|
-
const [sortedItems, setSortedItems] =
|
|
1650
|
-
|
|
1689
|
+
const [sortedItems, setSortedItems] = React.useState(structuredClone(items));
|
|
1690
|
+
React.useEffect(() => {
|
|
1651
1691
|
return () => {
|
|
1652
1692
|
setSortedItems(structuredClone(items));
|
|
1653
1693
|
};
|
|
@@ -1661,111 +1701,361 @@ const PdfViewerDialog = ({ open, title, url, data, onClose }) => {
|
|
|
1661
1701
|
return !(url || data) ? null : (jsxRuntime.jsx(Dialog, { open: open, onOpenChange: (value) => !value && onClose(), children: jsxRuntime.jsxs(Dialog.Content, { className: "h-[90dvh] max-w-[90dvw]", children: [jsxRuntime.jsx(Dialog.Header, { children: title }), (url || data) && (jsxRuntime.jsx("embed", { className: "rounded-lg", src: url !== null && url !== void 0 ? url : `data:application/pdf;base64,${data}`, type: "application/pdf", width: "100%", height: "100%" }))] }) }));
|
|
1662
1702
|
};
|
|
1663
1703
|
|
|
1664
|
-
const
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1704
|
+
const Separator = React.forwardRef((_a, ref) => {
|
|
1705
|
+
var { className, orientation = 'horizontal', decorative = true } = _a, props = __rest(_a, ["className", "orientation", "decorative"]);
|
|
1706
|
+
return (jsxRuntime.jsx(SeparatorPrimitive__namespace.Root, Object.assign({ ref: ref, decorative: decorative, orientation: orientation, className: cn('bg-border shrink-0', orientation === 'horizontal' ? 'h-[1px] w-full' : 'h-full w-[1px]', className) }, props)));
|
|
1707
|
+
});
|
|
1708
|
+
Separator.displayName = SeparatorPrimitive__namespace.Root.displayName;
|
|
1709
|
+
|
|
1710
|
+
const $Sheet = DialogPrimitive__namespace.Root;
|
|
1711
|
+
const SheetTrigger = DialogPrimitive__namespace.Trigger;
|
|
1712
|
+
const SheetClose = DialogPrimitive__namespace.Close;
|
|
1713
|
+
const SheetPortal = DialogPrimitive__namespace.Portal;
|
|
1714
|
+
const SheetOverlay = React__namespace.forwardRef((_a, ref) => {
|
|
1715
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1716
|
+
return (jsxRuntime.jsx(DialogPrimitive__namespace.Overlay, Object.assign({ className: cn('data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80', className) }, props, { ref: ref })));
|
|
1717
|
+
});
|
|
1718
|
+
SheetOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
|
|
1719
|
+
const sheetVariants = classVarianceAuthority.cva('fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500', {
|
|
1720
|
+
variants: {
|
|
1721
|
+
side: {
|
|
1722
|
+
top: 'inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top',
|
|
1723
|
+
bottom: 'inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom',
|
|
1724
|
+
left: 'inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm',
|
|
1725
|
+
right: 'inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm',
|
|
1726
|
+
},
|
|
1727
|
+
},
|
|
1728
|
+
defaultVariants: {
|
|
1729
|
+
side: 'right',
|
|
1730
|
+
},
|
|
1731
|
+
});
|
|
1732
|
+
const SheetContent = React__namespace.forwardRef((_a, ref) => {
|
|
1733
|
+
var { side = 'right', className, children } = _a, props = __rest(_a, ["side", "className", "children"]);
|
|
1734
|
+
return (jsxRuntime.jsxs(SheetPortal, { children: [jsxRuntime.jsx(SheetOverlay, {}), jsxRuntime.jsxs(DialogPrimitive__namespace.Content, Object.assign({ ref: ref, className: cn(sheetVariants({ side }), className) }, props, { children: [children, jsxRuntime.jsxs(DialogPrimitive__namespace.Close, { className: "ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none", children: [jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4" }), jsxRuntime.jsx("span", { className: "sr-only", children: "Close" })] })] }))] }));
|
|
1735
|
+
});
|
|
1736
|
+
SheetContent.displayName = DialogPrimitive__namespace.Content.displayName;
|
|
1737
|
+
const SheetHeader = (_a) => {
|
|
1738
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1739
|
+
return (jsxRuntime.jsx("div", Object.assign({ className: cn('flex flex-col space-y-2 text-center sm:text-left', className) }, props)));
|
|
1690
1740
|
};
|
|
1691
|
-
|
|
1692
|
-
|
|
1741
|
+
SheetHeader.displayName = 'SheetHeader';
|
|
1742
|
+
const SheetFooter = (_a) => {
|
|
1743
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1744
|
+
return (jsxRuntime.jsx("div", Object.assign({ className: cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className) }, props)));
|
|
1745
|
+
};
|
|
1746
|
+
SheetFooter.displayName = 'SheetFooter';
|
|
1747
|
+
const SheetTitle = React__namespace.forwardRef((_a, ref) => {
|
|
1748
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1749
|
+
return (jsxRuntime.jsx(DialogPrimitive__namespace.Title, Object.assign({ ref: ref, className: cn('text-foreground text-lg font-semibold', className) }, props)));
|
|
1750
|
+
});
|
|
1751
|
+
SheetTitle.displayName = DialogPrimitive__namespace.Title.displayName;
|
|
1752
|
+
const SheetDescription = React__namespace.forwardRef((_a, ref) => {
|
|
1753
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1754
|
+
return (jsxRuntime.jsx(DialogPrimitive__namespace.Description, Object.assign({ ref: ref, className: cn('text-muted-foreground text-sm', className) }, props)));
|
|
1755
|
+
});
|
|
1756
|
+
SheetDescription.displayName = DialogPrimitive__namespace.Description.displayName;
|
|
1757
|
+
const Sheet = Object.assign($Sheet, {
|
|
1758
|
+
Portal: SheetPortal,
|
|
1759
|
+
Overlay: SheetOverlay,
|
|
1760
|
+
Trigger: SheetTrigger,
|
|
1761
|
+
Close: SheetClose,
|
|
1762
|
+
Content: SheetContent,
|
|
1763
|
+
Header: SheetHeader,
|
|
1764
|
+
Footer: SheetFooter,
|
|
1765
|
+
Title: SheetTitle,
|
|
1766
|
+
Description: SheetDescription,
|
|
1767
|
+
});
|
|
1768
|
+
|
|
1769
|
+
const Skeleton = (_a) => {
|
|
1770
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1771
|
+
return (jsxRuntime.jsx("div", Object.assign({ className: cn('bg-muted animate-pulse rounded-md', className) }, props)));
|
|
1772
|
+
};
|
|
1773
|
+
Skeleton.displayName = 'Skeleton';
|
|
1774
|
+
|
|
1775
|
+
const SIDEBAR_COOKIE_NAME = 'sidebar:state';
|
|
1776
|
+
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
1777
|
+
const SIDEBAR_WIDTH = '16rem';
|
|
1778
|
+
const SIDEBAR_WIDTH_MOBILE = '18rem';
|
|
1779
|
+
const SIDEBAR_WIDTH_ICON = '3rem';
|
|
1780
|
+
const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
|
|
1781
|
+
const SidebarContext = React.createContext(null);
|
|
1782
|
+
function useSidebar() {
|
|
1783
|
+
const context = React.useContext(SidebarContext);
|
|
1693
1784
|
if (!context) {
|
|
1694
|
-
throw new Error('
|
|
1785
|
+
throw new Error('useSidebar must be used within a SidebarProvider.');
|
|
1695
1786
|
}
|
|
1696
1787
|
return context;
|
|
1697
1788
|
}
|
|
1698
|
-
const
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
const
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1789
|
+
const SidebarContextProvider = React.forwardRef((_a, ref) => {
|
|
1790
|
+
var { defaultOpen = true, open: openProp, onOpenChange: setOpenProp, className, style, children } = _a, props = __rest(_a, ["defaultOpen", "open", "onOpenChange", "className", "style", "children"]);
|
|
1791
|
+
const isMobile = useIsMobile();
|
|
1792
|
+
const [openMobile, setOpenMobile] = React.useState(false);
|
|
1793
|
+
const screenRef = React.useRef(document.documentElement);
|
|
1794
|
+
// This is the internal state of the sidebar.
|
|
1795
|
+
// We use openProp and setOpenProp for control from outside the component.
|
|
1796
|
+
const [_open, _setOpen] = React.useState(defaultOpen);
|
|
1797
|
+
const open = openProp !== null && openProp !== void 0 ? openProp : _open;
|
|
1798
|
+
const setOpen = React.useCallback((value) => {
|
|
1799
|
+
if (setOpenProp) {
|
|
1800
|
+
return setOpenProp === null || setOpenProp === void 0 ? void 0 : setOpenProp(typeof value === 'function' ? value(open) : value);
|
|
1801
|
+
}
|
|
1802
|
+
_setOpen(value);
|
|
1803
|
+
// This sets the cookie to keep the sidebar state.
|
|
1804
|
+
document.cookie = `${SIDEBAR_COOKIE_NAME}=${open}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
|
|
1805
|
+
}, [setOpenProp, open]);
|
|
1806
|
+
// Helper to toggle the sidebar.
|
|
1807
|
+
const toggleSidebar = React.useCallback(() => {
|
|
1808
|
+
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open);
|
|
1809
|
+
}, [isMobile, setOpen, setOpenMobile]);
|
|
1810
|
+
// Add swipe gesture support for opening and closing the sidebar.
|
|
1811
|
+
useOnSwipe(screenRef, (direction) => direction === 'right' ? setOpen(true) : direction === 'left' && setOpen(false));
|
|
1812
|
+
// Adds a keyboard shortcut to toggle the sidebar.
|
|
1813
|
+
React.useEffect(() => {
|
|
1814
|
+
const handleKeyDown = (event) => {
|
|
1815
|
+
if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
|
|
1816
|
+
event.preventDefault();
|
|
1817
|
+
toggleSidebar();
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
1821
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
1822
|
+
}, [toggleSidebar]);
|
|
1823
|
+
// We add a state so that we can do data-state="expanded" or "collapsed".
|
|
1824
|
+
// This makes it easier to style the sidebar with Tailwind classes.
|
|
1825
|
+
const state = open ? 'expanded' : 'collapsed';
|
|
1826
|
+
const contextValue = React.useMemo(() => ({
|
|
1827
|
+
state,
|
|
1828
|
+
open,
|
|
1829
|
+
setOpen,
|
|
1830
|
+
isMobile,
|
|
1831
|
+
openMobile,
|
|
1832
|
+
setOpenMobile,
|
|
1833
|
+
toggleSidebar,
|
|
1834
|
+
}), [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]);
|
|
1835
|
+
return (jsxRuntime.jsx(SidebarContext.Provider, { value: contextValue, children: jsxRuntime.jsx("div", Object.assign({ style: Object.assign({ '--sidebar-width': SIDEBAR_WIDTH, '--sidebar-width-icon': SIDEBAR_WIDTH_ICON }, style), className: cn('group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full', className), ref: ref }, props, { children: children })) }));
|
|
1836
|
+
});
|
|
1837
|
+
SidebarContextProvider.displayName = 'SidebarContextProvider';
|
|
1838
|
+
const $Sidebar = React.forwardRef((_a, ref) => {
|
|
1839
|
+
var { side = 'left', variant = 'sidebar', collapsible = 'offcanvas', className, children } = _a, props = __rest(_a, ["side", "variant", "collapsible", "className", "children"]);
|
|
1840
|
+
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
|
1841
|
+
if (collapsible === 'none') {
|
|
1842
|
+
return (jsxRuntime.jsx("div", Object.assign({ className: cn('bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col', className), ref: ref }, props, { children: children })));
|
|
1843
|
+
}
|
|
1844
|
+
if (isMobile) {
|
|
1845
|
+
return (jsxRuntime.jsx(Sheet, Object.assign({ open: openMobile, onOpenChange: setOpenMobile }, props, { children: jsxRuntime.jsx(Sheet.Content, { "data-sidebar": "sidebar", "data-mobile": "true", className: "bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden", style: {
|
|
1846
|
+
'--sidebar-width': SIDEBAR_WIDTH_MOBILE,
|
|
1847
|
+
}, side: side, children: jsxRuntime.jsx("div", { className: "flex h-full w-full flex-col", children: children }) }) })));
|
|
1848
|
+
}
|
|
1849
|
+
return (jsxRuntime.jsxs("div", { ref: ref, className: "text-sidebar-foreground group peer hidden md:block", "data-state": state, "data-collapsible": state === 'collapsed' ? collapsible : '', "data-variant": variant, "data-side": side, children: [jsxRuntime.jsx("div", { className: cn('relative h-svh w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear', 'group-data-[collapsible=offcanvas]:w-0', 'group-data-[side=right]:rotate-180', variant === 'floating' || variant === 'inset'
|
|
1850
|
+
? 'group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]'
|
|
1851
|
+
: 'group-data-[collapsible=icon]:w-[--sidebar-width-icon]') }), jsxRuntime.jsx("div", Object.assign({ className: cn('fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex', side === 'left'
|
|
1852
|
+
? 'left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]'
|
|
1853
|
+
: 'right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]',
|
|
1854
|
+
// Adjust the padding for floating and inset variants.
|
|
1855
|
+
variant === 'floating' || variant === 'inset'
|
|
1856
|
+
? 'p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]'
|
|
1857
|
+
: 'border-sidebar-border group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l', className) }, props, { children: jsxRuntime.jsx("div", { "data-sidebar": "sidebar", className: "bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow", children: children }) }))] }));
|
|
1858
|
+
});
|
|
1859
|
+
$Sidebar.displayName = 'Sidebar';
|
|
1860
|
+
const SidebarTrigger = React.forwardRef((_a, ref) => {
|
|
1861
|
+
var { className, onClick } = _a, props = __rest(_a, ["className", "onClick"]);
|
|
1862
|
+
const { toggleSidebar } = useSidebar();
|
|
1863
|
+
return (jsxRuntime.jsx(Button, Object.assign({ ref: ref, "data-sidebar": "trigger", variant: "text", suffixIcon: lucideReact.PanelLeft, className: cn('h-7 w-7', className), onClick: (event) => {
|
|
1864
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
1865
|
+
toggleSidebar();
|
|
1866
|
+
} }, props)));
|
|
1867
|
+
});
|
|
1868
|
+
SidebarTrigger.displayName = 'SidebarTrigger';
|
|
1869
|
+
const SidebarRail = React.forwardRef((_a, ref) => {
|
|
1870
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1871
|
+
const { toggleSidebar } = useSidebar();
|
|
1872
|
+
return (jsxRuntime.jsx("button", Object.assign({ ref: ref, "data-sidebar": "rail", "aria-label": "Toggle Sidebar", tabIndex: -1, onClick: toggleSidebar, title: "Toggle Sidebar", className: cn('hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex', '[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize', '[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize', 'group-data-[collapsible=offcanvas]:hover:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full', '[[data-side=left][data-collapsible=offcanvas]_&]:-right-2', '[[data-side=right][data-collapsible=offcanvas]_&]:-left-2', className) }, props)));
|
|
1873
|
+
});
|
|
1874
|
+
SidebarRail.displayName = 'SidebarRail';
|
|
1875
|
+
const SidebarInset = React.forwardRef((_a, ref) => {
|
|
1876
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1877
|
+
return (jsxRuntime.jsx("main", Object.assign({ ref: ref, className: cn('bg-background relative flex min-h-svh flex-1 flex-col', 'peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow', className) }, props)));
|
|
1878
|
+
});
|
|
1879
|
+
SidebarInset.displayName = 'SidebarInset';
|
|
1880
|
+
const SidebarInput = React.forwardRef((_a, ref) => {
|
|
1881
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1882
|
+
return (jsxRuntime.jsx(BasicInput, Object.assign({ ref: ref, "data-sidebar": "input", className: cn('focus-visible:ring-sidebar-ring focus-visible:ring-2', className) }, props)));
|
|
1883
|
+
});
|
|
1884
|
+
SidebarInput.displayName = 'SidebarInput';
|
|
1885
|
+
const SidebarHeader = React.forwardRef((_a, ref) => {
|
|
1886
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1887
|
+
return (jsxRuntime.jsx("div", Object.assign({ ref: ref, "data-sidebar": "header", className: cn('flex flex-col gap-2 p-2', className) }, props)));
|
|
1888
|
+
});
|
|
1889
|
+
SidebarHeader.displayName = 'SidebarHeader';
|
|
1890
|
+
const SidebarFooter = React.forwardRef((_a, ref) => {
|
|
1891
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1892
|
+
return (jsxRuntime.jsx("div", Object.assign({ ref: ref, "data-sidebar": "footer", className: cn('flex flex-col gap-2 p-2', className) }, props)));
|
|
1893
|
+
});
|
|
1894
|
+
SidebarFooter.displayName = 'SidebarFooter';
|
|
1895
|
+
const SidebarSeparator = React.forwardRef((_a, ref) => {
|
|
1896
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1897
|
+
return (jsxRuntime.jsx(Separator, Object.assign({ ref: ref, "data-sidebar": "separator", className: cn('bg-sidebar-border mx-2 w-auto', className) }, props)));
|
|
1898
|
+
});
|
|
1899
|
+
SidebarSeparator.displayName = 'SidebarSeparator';
|
|
1900
|
+
const SidebarContent = React.forwardRef((_a, ref) => {
|
|
1901
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1902
|
+
return (jsxRuntime.jsx("div", Object.assign({ ref: ref, "data-sidebar": "content", className: cn('flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden', className) }, props)));
|
|
1903
|
+
});
|
|
1904
|
+
SidebarContent.displayName = 'SidebarContent';
|
|
1905
|
+
const SidebarGroup = React.forwardRef((_a, ref) => {
|
|
1906
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1907
|
+
return (jsxRuntime.jsx("div", Object.assign({ ref: ref, "data-sidebar": "group", className: cn('relative flex w-full min-w-0 flex-col p-2', className) }, props)));
|
|
1908
|
+
});
|
|
1909
|
+
SidebarGroup.displayName = 'SidebarGroup';
|
|
1910
|
+
const SidebarGroupLabel = React.forwardRef((_a, ref) => {
|
|
1911
|
+
var { className, asChild = false } = _a, props = __rest(_a, ["className", "asChild"]);
|
|
1912
|
+
const Comp = asChild ? reactSlot.Slot : 'div';
|
|
1913
|
+
return (jsxRuntime.jsx(Comp, Object.assign({ ref: ref, "data-sidebar": "group-label", className: cn('text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-none transition-[margin,opa] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0', 'group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0', className) }, props)));
|
|
1914
|
+
});
|
|
1915
|
+
SidebarGroupLabel.displayName = 'SidebarGroupLabel';
|
|
1916
|
+
const SidebarGroupAction = React.forwardRef((_a, ref) => {
|
|
1917
|
+
var { className, asChild = false } = _a, props = __rest(_a, ["className", "asChild"]);
|
|
1918
|
+
const Comp = asChild ? reactSlot.Slot : 'button';
|
|
1919
|
+
return (jsxRuntime.jsx(Comp, Object.assign({ ref: ref, "data-sidebar": "group-action", className: cn('text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-none transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
1920
|
+
// Increases the hit area of the button on mobile.
|
|
1921
|
+
'after:absolute after:-inset-2 after:md:hidden', 'group-data-[collapsible=icon]:hidden', className) }, props)));
|
|
1922
|
+
});
|
|
1923
|
+
SidebarGroupAction.displayName = 'SidebarGroupAction';
|
|
1924
|
+
const SidebarGroupContent = React.forwardRef((_a, ref) => {
|
|
1925
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1926
|
+
return (jsxRuntime.jsx("div", Object.assign({ ref: ref, "data-sidebar": "group-content", className: cn('w-full text-sm', className) }, props)));
|
|
1927
|
+
});
|
|
1928
|
+
SidebarGroupContent.displayName = 'SidebarGroupContent';
|
|
1929
|
+
const SidebarMenu = React.forwardRef((_a, ref) => {
|
|
1930
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1931
|
+
return (jsxRuntime.jsx("ul", Object.assign({ ref: ref, "data-sidebar": "menu", className: cn('flex w-full min-w-0 flex-col gap-1', className) }, props)));
|
|
1932
|
+
});
|
|
1933
|
+
SidebarMenu.displayName = 'SidebarMenu';
|
|
1934
|
+
const SidebarMenuItem = React.forwardRef((_a, ref) => {
|
|
1935
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1936
|
+
return (jsxRuntime.jsx("li", Object.assign({ ref: ref, "data-sidebar": "menu-item", className: cn('group/menu-item relative', className) }, props)));
|
|
1937
|
+
});
|
|
1938
|
+
SidebarMenuItem.displayName = 'SidebarMenuItem';
|
|
1939
|
+
const sidebarMenuButtonVariants = classVarianceAuthority.cva('peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0', {
|
|
1940
|
+
variants: {
|
|
1941
|
+
variant: {
|
|
1942
|
+
default: 'hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
|
1943
|
+
outline: 'bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]',
|
|
1944
|
+
},
|
|
1945
|
+
size: {
|
|
1946
|
+
default: 'h-8 text-sm',
|
|
1947
|
+
sm: 'h-7 text-xs',
|
|
1948
|
+
lg: 'h-12 text-sm group-data-[collapsible=icon]:!p-0',
|
|
1949
|
+
},
|
|
1950
|
+
},
|
|
1951
|
+
defaultVariants: {
|
|
1952
|
+
variant: 'default',
|
|
1953
|
+
size: 'default',
|
|
1954
|
+
},
|
|
1955
|
+
});
|
|
1956
|
+
const SidebarMenuButton = React.forwardRef((_a, ref) => {
|
|
1957
|
+
var { asChild = false, isActive = false, variant = 'default', size = 'default', tooltip, className } = _a, props = __rest(_a, ["asChild", "isActive", "variant", "size", "tooltip", "className"]);
|
|
1958
|
+
const Comp = asChild ? reactSlot.Slot : 'button';
|
|
1959
|
+
const { isMobile, state } = useSidebar();
|
|
1960
|
+
const button = (jsxRuntime.jsx(Comp, Object.assign({ ref: ref, "data-sidebar": "menu-button", "data-size": size, "data-active": isActive, className: cn(sidebarMenuButtonVariants({ variant, size }), className) }, props)));
|
|
1961
|
+
if (!tooltip || state !== 'collapsed' || isMobile) {
|
|
1962
|
+
return button;
|
|
1963
|
+
}
|
|
1964
|
+
if (typeof tooltip === 'string') {
|
|
1965
|
+
tooltip = {
|
|
1966
|
+
content: tooltip,
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
return (jsxRuntime.jsx(Tooltip, Object.assign({ asChild: true, placement: "right" }, tooltip, { children: button })));
|
|
1970
|
+
});
|
|
1971
|
+
SidebarMenuButton.displayName = 'SidebarMenuButton';
|
|
1972
|
+
const SidebarMenuAction = React.forwardRef((_a, ref) => {
|
|
1973
|
+
var { className, asChild = false, showOnHover = false } = _a, props = __rest(_a, ["className", "asChild", "showOnHover"]);
|
|
1974
|
+
const Comp = asChild ? reactSlot.Slot : 'button';
|
|
1975
|
+
return (jsxRuntime.jsx(Comp, Object.assign({ ref: ref, "data-sidebar": "menu-action", className: cn('text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-none transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
1976
|
+
// Increases the hit area of the button on mobile.
|
|
1977
|
+
'after:absolute after:-inset-2 after:md:hidden', 'peer-data-[size=sm]/menu-button:top-1', 'peer-data-[size=default]/menu-button:top-1.5', 'peer-data-[size=lg]/menu-button:top-2.5', 'group-data-[collapsible=icon]:hidden', showOnHover &&
|
|
1978
|
+
'peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0', className) }, props)));
|
|
1979
|
+
});
|
|
1980
|
+
SidebarMenuAction.displayName = 'SidebarMenuAction';
|
|
1981
|
+
const SidebarMenuBadge = React.forwardRef((_a, ref) => {
|
|
1982
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1983
|
+
return (jsxRuntime.jsx("div", Object.assign({ ref: ref, "data-sidebar": "menu-badge", className: cn('text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums', 'peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground', 'peer-data-[size=sm]/menu-button:top-1', 'peer-data-[size=default]/menu-button:top-1.5', 'peer-data-[size=lg]/menu-button:top-2.5', 'group-data-[collapsible=icon]:hidden', className) }, props)));
|
|
1984
|
+
});
|
|
1985
|
+
SidebarMenuBadge.displayName = 'SidebarMenuBadge';
|
|
1986
|
+
const SidebarMenuSkeleton = React.forwardRef((_a, ref) => {
|
|
1987
|
+
var { className, showIcon = false } = _a, props = __rest(_a, ["className", "showIcon"]);
|
|
1988
|
+
// Random width between 50 to 90%.
|
|
1989
|
+
const width = React.useMemo(() => {
|
|
1990
|
+
return `${Math.floor(Math.random() * 40) + 50}%`;
|
|
1991
|
+
}, []);
|
|
1992
|
+
return (jsxRuntime.jsxs("div", Object.assign({ ref: ref, "data-sidebar": "menu-skeleton", className: cn('flex h-8 items-center gap-2 rounded-md px-2', className) }, props, { children: [showIcon && jsxRuntime.jsx(Skeleton, { className: "size-4 rounded-md", "data-sidebar": "menu-skeleton-icon" }), jsxRuntime.jsx(Skeleton, { className: "h-4 max-w-[--skeleton-width] flex-1", "data-sidebar": "menu-skeleton-text", style: {
|
|
1993
|
+
'--skeleton-width': width,
|
|
1994
|
+
} })] })));
|
|
1995
|
+
});
|
|
1996
|
+
SidebarMenuSkeleton.displayName = 'SidebarMenuSkeleton';
|
|
1997
|
+
const SidebarMenuSub = React.forwardRef((_a, ref) => {
|
|
1998
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1999
|
+
return (jsxRuntime.jsx("ul", Object.assign({ ref: ref, "data-sidebar": "menu-sub", className: cn('border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5', 'group-data-[collapsible=icon]:hidden', className) }, props)));
|
|
2000
|
+
});
|
|
2001
|
+
SidebarMenuSub.displayName = 'SidebarMenuSub';
|
|
2002
|
+
const SidebarMenuSubItem = React.forwardRef((_a, ref) => {
|
|
2003
|
+
var props = __rest(_a, []);
|
|
2004
|
+
return (jsxRuntime.jsx("li", Object.assign({ ref: ref }, props)));
|
|
2005
|
+
});
|
|
2006
|
+
SidebarMenuSubItem.displayName = 'SidebarMenuSubItem';
|
|
2007
|
+
const SidebarMenuSubButton = React.forwardRef((_a, ref) => {
|
|
2008
|
+
var { asChild = false, size = 'md', isActive, className } = _a, props = __rest(_a, ["asChild", "size", "isActive", "className"]);
|
|
2009
|
+
const Comp = asChild ? reactSlot.Slot : 'a';
|
|
2010
|
+
return (jsxRuntime.jsx(Comp, Object.assign({ ref: ref, "data-sidebar": "menu-sub-button", "data-size": size, "data-active": isActive, className: cn('text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0', 'data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground', size === 'sm' && 'text-xs', size === 'md' && 'text-sm', 'group-data-[collapsible=icon]:hidden', className) }, props)));
|
|
2011
|
+
});
|
|
2012
|
+
SidebarMenuSubButton.displayName = 'SidebarMenuSubButton';
|
|
2013
|
+
const Sidebar = Object.assign($Sidebar, {
|
|
2014
|
+
Content: SidebarContent,
|
|
2015
|
+
Footer: SidebarFooter,
|
|
2016
|
+
Group: SidebarGroup,
|
|
2017
|
+
GroupAction: SidebarGroupAction,
|
|
2018
|
+
GroupContent: SidebarGroupContent,
|
|
2019
|
+
GroupLabel: SidebarGroupLabel,
|
|
2020
|
+
Header: SidebarHeader,
|
|
2021
|
+
Input: SidebarInput,
|
|
2022
|
+
Inset: SidebarInset,
|
|
2023
|
+
Menu: SidebarMenu,
|
|
2024
|
+
MenuAction: SidebarMenuAction,
|
|
2025
|
+
MenuBadge: SidebarMenuBadge,
|
|
2026
|
+
MenuButton: SidebarMenuButton,
|
|
2027
|
+
MenuItem: SidebarMenuItem,
|
|
2028
|
+
MenuSkeleton: SidebarMenuSkeleton,
|
|
2029
|
+
MenuSub: SidebarMenuSub,
|
|
2030
|
+
MenuSubButton: SidebarMenuSubButton,
|
|
2031
|
+
MenuSubItem: SidebarMenuSubItem,
|
|
2032
|
+
Rail: SidebarRail,
|
|
2033
|
+
Separator: SidebarSeparator,
|
|
2034
|
+
Trigger: SidebarTrigger,
|
|
2035
|
+
});
|
|
1710
2036
|
|
|
1711
|
-
const Navbar = ({ leftSlot, rightSlot }) => {
|
|
1712
|
-
const { setSidebarOpen } = useLayoutContext();
|
|
1713
|
-
return (jsxRuntime.jsx(Block, { className: "border-b p-3 dark:border-slate-700", fullWidth: true, children: jsxRuntime.jsxs(Flex, { align: "center", justify: "between", children: [jsxRuntime.jsxs(Flex, { align: "center", children: [jsxRuntime.jsx(Button, { className: "xl:hidden", prefixIcon: lucideReact.MenuIcon, variant: "text", onClick: () => setSidebarOpen(true) }), leftSlot] }), rightSlot] }) }));
|
|
1714
|
-
};
|
|
2037
|
+
const Navbar = ({ className, leftSlot, rightSlot }) => (jsxRuntime.jsx(Block, { className: cn('border-b p-3 dark:border-slate-700', className), fullWidth: true, children: jsxRuntime.jsxs(Flex, { align: "center", justify: "between", children: [jsxRuntime.jsxs(Flex, { align: "center", children: [jsxRuntime.jsx(Sidebar.Trigger, {}), leftSlot] }), rightSlot] }) }));
|
|
1715
2038
|
|
|
1716
|
-
const
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
'bg-slate-100 dark:bg-slate-800': active && !isChild && !items,
|
|
1722
|
-
'bg-slate-200 dark:bg-slate-900': active && (isChild || items),
|
|
1723
|
-
'text-slate-500 dark:text-slate-400': !active,
|
|
1724
|
-
'hover:bg-slate-100 dark:hover:bg-slate-800': !active && !isChild,
|
|
1725
|
-
'hover:bg-slate-200 dark:hover:bg-slate-900': !active && isChild,
|
|
1726
|
-
}), to: [basePath, pathname].join('/').replace(/\/{2,}/g, '/'), onClick: onClick, children: [jsxRuntime.jsx(Icon, { className: "h-5 w-5 min-w-min", size: 16 }), jsxRuntime.jsxs("div", { className: "min-w-max", children: [title, jsxRuntime.jsx("div", { className: "ml-auto flex items-center space-x-2", children: label })] })] }));
|
|
1727
|
-
|
|
1728
|
-
const Sidebar = react.forwardRef(({ className, items, basePath = '/', smallLogo, fullLogo, footer }, ref) => {
|
|
2039
|
+
const Layout = (_a) => {
|
|
2040
|
+
var { children, className } = _a, _b = _a.sidebarProps, { basePath, smallLogo, fullLogo, items } = _b, sidebarProps = __rest(_b, ["basePath", "smallLogo", "fullLogo", "items"]), { navbarProps } = _a;
|
|
2041
|
+
return (jsxRuntime.jsxs(Flex, { className: "h-screen w-screen gap-0 text-black dark:bg-slate-900 dark:text-white", children: [jsxRuntime.jsxs(Sidebar, Object.assign({ collapsible: "icon" }, sidebarProps, { children: [jsxRuntime.jsx(Sidebar.Header, { children: smallLogo && fullLogo && (jsxRuntime.jsx("div", { className: "cursor-pointer overflow-hidden whitespace-nowrap py-2 text-center text-lg", children: jsxRuntime.jsxs(reactRouterDom.Link, { to: "/", children: [jsxRuntime.jsx("span", { className: "group-data-[state=collapsed]:hidden", children: fullLogo }), jsxRuntime.jsx("span", { className: "group-data-[state=expanded]:hidden", children: smallLogo })] }) })) }), jsxRuntime.jsx(Sidebar.Content, { className: "gap-0", children: items.map((item, index) => item.type === 'item' ? (jsxRuntime.jsx(Sidebar.Group, { children: jsxRuntime.jsx(Sidebar.Menu, { children: jsxRuntime.jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, item)) }) }, index)) : (jsxRuntime.jsxs(Sidebar.Group, { children: [item.title && jsxRuntime.jsx(Sidebar.GroupLabel, { children: item.title }), jsxRuntime.jsx(Sidebar.GroupContent, { children: jsxRuntime.jsx(Sidebar.Menu, { children: item.items.map((item, index) => (jsxRuntime.jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, item), index))) }) })] }, index))) }), jsxRuntime.jsx(Sidebar.Rail, {})] })), jsxRuntime.jsxs(Flex, { className: "gap-0 overflow-hidden", direction: "column", fullHeight: true, fullWidth: true, children: [jsxRuntime.jsx(Navbar, Object.assign({}, navbarProps)), jsxRuntime.jsx(Flex, { className: cn('overflow-hidden p-3', className), direction: "column", fullWidth: true, fullHeight: true, children: children })] })] }));
|
|
2042
|
+
};
|
|
2043
|
+
const RenderSideBarItem = ({ basePath = '/', pathname, title, Icon, items, }) => {
|
|
1729
2044
|
const location = reactRouterDom.useLocation();
|
|
1730
|
-
const {
|
|
1731
|
-
const currentPath =
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "absolute left-0 top-0 h-full w-full backdrop-blur-sm transition-opacity data-[open=true]:z-50 data-[open=false]:hidden data-[open=false]:opacity-0 data-[open=true]:opacity-100 xl:hidden", "data-open": sidebarOpen }), jsxRuntime.jsxs("nav", { className: cn('group/navbar fixed left-0 top-0 z-50 flex h-full w-56 shrink-0 flex-col bg-white p-2 transition-all duration-200 ease-in-out xl:relative dark:bg-slate-900', 'border-r data-[open=false]:-translate-x-full xl:data-[open=false]:w-16 xl:data-[open=true]:w-72 xl:data-[open=false]:translate-x-0 xl:data-[open=false]:hover:w-72 dark:border-slate-700', className), "data-open": sidebarOpen, ref: ref, children: [smallLogo && fullLogo && (jsxRuntime.jsx("div", { className: "mb-2 cursor-pointer overflow-hidden whitespace-nowrap p-2 py-3 text-center text-2xl", children: jsxRuntime.jsxs(reactRouterDom.Link, { to: "/", children: [jsxRuntime.jsx("span", { className: cn('group-hover/navbar:block', !sidebarOpen && 'hidden'), children: fullLogo }), jsxRuntime.jsx("span", { className: cn('group-hover/navbar:hidden', sidebarOpen && 'hidden'), children: smallLogo })] }) })), jsxRuntime.jsx(Accordion__namespace.Root, { className: "overflow-hidden", type: "single", value: parentTab, children: items.map((item, index) => {
|
|
1738
|
-
var _a;
|
|
1739
|
-
return !item.hidden &&
|
|
1740
|
-
(item.type === 'separator' ? (!item.title ? (jsxRuntime.jsx(Block, { className: "my-2 h-px bg-slate-300 dark:bg-slate-700" }, index)) : (jsxRuntime.jsx(Block, { className: "mb-2 mt-6 pl-2 text-sm font-bold text-slate-600 group-hover/navbar:block data-[open=false]:hidden dark:text-slate-500", "data-open": sidebarOpen, children: item.title }, index))) : (jsxRuntime.jsxs(Accordion__namespace.Item, { className: cn('flex flex-col rounded-md', {
|
|
1741
|
-
'bg-slate-100 dark:bg-slate-800': item.items && isLinkStartsWithPathname(currentPath, item.pathname),
|
|
1742
|
-
}), value: item.pathname, children: [jsxRuntime.jsx(Accordion__namespace.Header, { children: jsxRuntime.jsxs(Accordion__namespace.Trigger, { className: "relative w-full p-0.5 data-[state=open]:[--rotate-chevron:90deg]", children: [jsxRuntime.jsx(SidebarItemComp, Object.assign({}, item, { active: isLinkStartsWithPathname(currentPath, item.pathname) &&
|
|
1743
|
-
(!item.items ||
|
|
1744
|
-
item.items.every((subItem) => !isLinkStartsWithPathname(currentPath, `${item.pathname}/${subItem.pathname}`))), basePath: basePath, sidebarOpen: sidebarOpen, onClick: ((_a = item.items) === null || _a === void 0 ? void 0 : _a.length) ? undefined : () => setSidebarOpen(false) })), item.items && (jsxRuntime.jsx(lucideReact.ChevronRightIcon, { className: cn('absolute right-2 top-1/2 h-4 w-4 -translate-y-1/2 rotate-[var(--rotate-chevron,0deg)] transition-transform duration-200', !sidebarOpen && 'invisible', 'group-hover/navbar:visible') }))] }) }), item.items && (jsxRuntime.jsx(Accordion__namespace.Content, { className: "overflow-hidden data-[state=closed]:animate-[slideUp_200ms_ease-out] data-[state=open]:animate-[slideDown_200ms_ease-out]", children: jsxRuntime.jsx("div", { className: "flex flex-col gap-1 p-1 pt-0", children: item.items.map((subItem) => {
|
|
1745
|
-
const subPathname = `${item.pathname}/${subItem.pathname}`;
|
|
1746
|
-
return (!subItem.hidden && (jsxRuntime.jsx(SidebarItemComp, Object.assign({}, subItem, { pathname: subPathname, isChild: true, active: isLinkStartsWithPathname(currentPath, subPathname), basePath: basePath, sidebarOpen: sidebarOpen, onClick: () => setSidebarOpen(false) }), subPathname)));
|
|
1747
|
-
}) }) }))] }, item.pathname)));
|
|
1748
|
-
}) }), jsxRuntime.jsxs(Flex, { className: "mt-auto", direction: "column", fullWidth: true, children: [footer, jsxRuntime.jsx(Button, { className: "invisible w-full justify-center xl:visible", variant: "text", prefixIcon: OpenCloseIcon, onClick: () => setSidebarOpen(!sidebarOpen) })] })] })] }));
|
|
1749
|
-
});
|
|
2045
|
+
const { open } = useSidebar();
|
|
2046
|
+
const currentPath = React.useMemo(() => location.pathname.replace(basePath, '').replace(/^\/*/, ''), [basePath, location.pathname]);
|
|
2047
|
+
return (jsxRuntime.jsxs(Sidebar.MenuItem, { children: [jsxRuntime.jsx(Sidebar.MenuButton, { asChild: true, tooltip: title, isActive: isLinkStartsWithPathname(currentPath, pathname) &&
|
|
2048
|
+
(!items ||
|
|
2049
|
+
(!open &&
|
|
2050
|
+
items.some((item) => isLinkStartsWithPathname(currentPath, `${pathname}/${item.pathname}`)))), children: jsxRuntime.jsxs(reactRouterDom.Link, { to: pathname, className: "font-medium", children: [Icon && jsxRuntime.jsx(Icon, {}), title] }) }), items && (jsxRuntime.jsx(Sidebar.MenuSub, { children: items.map((subItem, index) => (jsxRuntime.jsx(Sidebar.MenuSubItem, { children: jsxRuntime.jsx(Sidebar.MenuSubButton, { asChild: true, isActive: isLinkStartsWithPathname(currentPath, `${pathname}/${subItem.pathname}`), children: jsxRuntime.jsx(reactRouterDom.Link, { to: `${pathname}/${subItem.pathname}`, children: subItem.title }) }) }, index))) }))] }));
|
|
2051
|
+
};
|
|
1750
2052
|
function isLinkStartsWithPathname(link, pathname) {
|
|
1751
2053
|
return pathname === '' ? link === pathname : link.startsWith(pathname);
|
|
1752
2054
|
}
|
|
1753
|
-
function isItem(item) {
|
|
1754
|
-
return item.type !== 'separator';
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
const Layout = ({ children, className, sidebarProps, navbarProps, }) => {
|
|
1758
|
-
const { sidebarOpen, setSidebarOpen } = useLayoutContext();
|
|
1759
|
-
const screenRef = react.useRef(null);
|
|
1760
|
-
const sidebarRef = react.useRef(null);
|
|
1761
|
-
useOnSwipe(screenRef, (direction) => direction === 'right' ? setSidebarOpen(true) : direction === 'left' && setSidebarOpen(false));
|
|
1762
|
-
useOutsideClick(sidebarRef, () => sidebarOpen && window.document.documentElement.offsetWidth <= 1024 && setSidebarOpen(false));
|
|
1763
|
-
return (jsxRuntime.jsxs(Flex, { className: "h-screen gap-0 text-black dark:bg-slate-900 dark:text-white", ref: screenRef, children: [jsxRuntime.jsx(Sidebar, Object.assign({}, sidebarProps, { open: sidebarOpen, ref: sidebarRef })), jsxRuntime.jsxs(Flex, { className: "gap-0 overflow-hidden", direction: "column", fullHeight: true, fullWidth: true, children: [jsxRuntime.jsx(Navbar, Object.assign({}, navbarProps)), jsxRuntime.jsx(Flex, { className: cn('overflow-hidden p-3', className), direction: "column", fullWidth: true, fullHeight: true, children: children })] })] }));
|
|
1764
|
-
};
|
|
1765
2055
|
|
|
1766
2056
|
const $Popover = PopoverPrimitive__namespace.Root;
|
|
1767
2057
|
const PopoverTrigger = PopoverPrimitive__namespace.Trigger;
|
|
1768
|
-
const PopoverContent =
|
|
2058
|
+
const PopoverContent = React.forwardRef((_a, ref) => {
|
|
1769
2059
|
var { className, align = 'center', sideOffset = 4, container } = _a, props = __rest(_a, ["className", "align", "sideOffset", "container"]);
|
|
1770
2060
|
return (jsxRuntime.jsx(PopoverPrimitive__namespace.Portal, { container: container, children: jsxRuntime.jsx(PopoverPrimitive__namespace.Content, Object.assign({ ref: ref, align: align, sideOffset: sideOffset, className: cn('z-50 rounded-md border bg-white p-1 shadow-md outline-none dark:border-slate-700 dark:bg-slate-900 dark:text-white', 'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95', 'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2', className) }, props)) }));
|
|
1771
2061
|
});
|
|
@@ -1775,23 +2065,23 @@ const Popover = Object.assign($Popover, {
|
|
|
1775
2065
|
Content: PopoverContent,
|
|
1776
2066
|
});
|
|
1777
2067
|
|
|
1778
|
-
const Switch =
|
|
2068
|
+
const Switch = React.forwardRef((_a, ref) => {
|
|
1779
2069
|
var { className } = _a, _b = _a.thumbProps, _c = _b === void 0 ? {} : _b, { className: thumbClassName } = _c, thumbProps = __rest(_c, ["className"]), props = __rest(_a, ["className", "thumbProps"]);
|
|
1780
2070
|
return (jsxRuntime.jsx(SwitchPrimitives__namespace.Root, Object.assign({ className: cn('peer inline-flex h-[calc(1.5rem+6px)] w-[calc(3rem+6px)] shrink-0 cursor-pointer items-center rounded-full border-[3px] border-transparent', 'transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-600 focus-visible:ring-offset-2', 'focus-visible:ring-offset-white disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-600 data-[state=unchecked]:bg-slate-300', 'dark:focus-visible:ring-slate-200 dark:focus-visible:ring-offset-slate-800 dark:data-[state=checked]:bg-blue-700 dark:data-[state=unchecked]:bg-slate-700', className) }, props, { ref: ref, children: jsxRuntime.jsx(SwitchPrimitives__namespace.Thumb, Object.assign({ className: cn('pointer-events-none block h-6 w-6 rounded-full bg-white shadow-lg ring-0 transition-transform', 'data-[state=checked]:translate-x-6 data-[state=unchecked]:translate-x-0 dark:bg-slate-900', thumbClassName) }, thumbProps)) })));
|
|
1781
2071
|
});
|
|
1782
2072
|
Switch.displayName = SwitchPrimitives__namespace.Root.displayName;
|
|
1783
2073
|
|
|
1784
|
-
const $Tabs =
|
|
2074
|
+
const $Tabs = React.forwardRef((_a, ref) => {
|
|
1785
2075
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1786
2076
|
return (jsxRuntime.jsx(TabsPrimitive__namespace.Root, Object.assign({ ref: ref, className: cn('flex flex-col gap-2', className) }, props)));
|
|
1787
2077
|
});
|
|
1788
2078
|
$Tabs.displayName = TabsPrimitive__namespace.Root.displayName;
|
|
1789
|
-
const TabsList =
|
|
2079
|
+
const TabsList = React.forwardRef((_a, ref) => {
|
|
1790
2080
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1791
2081
|
return (jsxRuntime.jsx(TabsPrimitive__namespace.List, Object.assign({ ref: ref, className: cn('inline-flex w-full items-center justify-center gap-1 rounded-lg border bg-slate-100 p-1 text-slate-400 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-500', className) }, props)));
|
|
1792
2082
|
});
|
|
1793
2083
|
TabsList.displayName = TabsPrimitive__namespace.List.displayName;
|
|
1794
|
-
const TabsTrigger =
|
|
2084
|
+
const TabsTrigger = React.forwardRef((_a, ref) => {
|
|
1795
2085
|
var { className } = _a, props = __rest(_a, ["className"]);
|
|
1796
2086
|
return (jsxRuntime.jsx(TabsPrimitive__namespace.Trigger, Object.assign({ ref: ref, className: cn('inline-flex w-full items-center justify-center whitespace-nowrap rounded-md px-2 py-1.5 font-medium transition-all hover:bg-slate-200 disabled:pointer-events-none disabled:opacity-50 dark:hover:bg-slate-800', 'data-[state=active]:bg-white data-[state=active]:text-black data-[state=active]:shadow dark:data-[state=active]:bg-slate-700 dark:data-[state=active]:text-white', className) }, props)));
|
|
1797
2087
|
});
|
|
@@ -1803,6 +2093,47 @@ const Tabs = Object.assign($Tabs, {
|
|
|
1803
2093
|
Content: TabsContent,
|
|
1804
2094
|
});
|
|
1805
2095
|
|
|
2096
|
+
const LayoutContext = React.createContext(undefined);
|
|
2097
|
+
const LayoutContextProvider = ({ children }) => {
|
|
2098
|
+
const [theme, setTheme] = React.useState(getValueFromLocalStorage(THEME_KEY, 'light'));
|
|
2099
|
+
React.useEffect(() => {
|
|
2100
|
+
if (theme) {
|
|
2101
|
+
if (theme === 'dark') {
|
|
2102
|
+
document.documentElement.classList.add('dark');
|
|
2103
|
+
}
|
|
2104
|
+
else {
|
|
2105
|
+
document.documentElement.classList.remove('dark');
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
}, [theme]);
|
|
2109
|
+
const toggleTheme = () => {
|
|
2110
|
+
setTheme((theme) => {
|
|
2111
|
+
const newValue = theme === 'dark' ? 'light' : 'dark';
|
|
2112
|
+
window.localStorage.setItem(THEME_KEY, newValue);
|
|
2113
|
+
return newValue;
|
|
2114
|
+
});
|
|
2115
|
+
};
|
|
2116
|
+
return jsxRuntime.jsx(LayoutContext.Provider, { value: { theme, toggleTheme }, children: children });
|
|
2117
|
+
};
|
|
2118
|
+
function useLayoutContext() {
|
|
2119
|
+
const context = React.useContext(LayoutContext);
|
|
2120
|
+
if (!context) {
|
|
2121
|
+
throw new Error('Please use LayoutContextProvider!');
|
|
2122
|
+
}
|
|
2123
|
+
return context;
|
|
2124
|
+
}
|
|
2125
|
+
const THEME_KEY = 'tw-react-components__theme';
|
|
2126
|
+
function getValueFromLocalStorage(key, _default) {
|
|
2127
|
+
var _a;
|
|
2128
|
+
const transformers = {
|
|
2129
|
+
string: String,
|
|
2130
|
+
boolean: (value) => value === 'true',
|
|
2131
|
+
};
|
|
2132
|
+
return typeof window !== 'undefined'
|
|
2133
|
+
? transformers[typeof _default]((_a = window.localStorage.getItem(key)) !== null && _a !== void 0 ? _a : _default)
|
|
2134
|
+
: _default;
|
|
2135
|
+
}
|
|
2136
|
+
|
|
1806
2137
|
const ThemeSwitcher = ({ className }) => {
|
|
1807
2138
|
const { theme, toggleTheme } = useLayoutContext();
|
|
1808
2139
|
const darkMode = theme === 'dark';
|
|
@@ -1824,6 +2155,7 @@ exports.DateTimeInput = DateTimeInput;
|
|
|
1824
2155
|
exports.Dialog = Dialog;
|
|
1825
2156
|
exports.DropdownMenu = DropdownMenu;
|
|
1826
2157
|
exports.EmailInput = EmailInput;
|
|
2158
|
+
exports.FileInput = FileInput;
|
|
1827
2159
|
exports.Flex = Flex;
|
|
1828
2160
|
exports.FormDialog = FormDialog;
|
|
1829
2161
|
exports.FormGroup = FormGroup;
|
|
@@ -1842,9 +2174,13 @@ exports.Pagination = Pagination;
|
|
|
1842
2174
|
exports.PasswordInput = PasswordInput;
|
|
1843
2175
|
exports.PdfViewerDialog = PdfViewerDialog;
|
|
1844
2176
|
exports.Popover = Popover;
|
|
1845
|
-
exports.SIDEBAR_KEY = SIDEBAR_KEY;
|
|
1846
2177
|
exports.SelectInput = SelectInput;
|
|
2178
|
+
exports.Separator = Separator;
|
|
2179
|
+
exports.Sheet = Sheet;
|
|
1847
2180
|
exports.Sidebar = Sidebar;
|
|
2181
|
+
exports.SidebarContext = SidebarContext;
|
|
2182
|
+
exports.SidebarContextProvider = SidebarContextProvider;
|
|
2183
|
+
exports.Skeleton = Skeleton;
|
|
1848
2184
|
exports.Spinner = Spinner;
|
|
1849
2185
|
exports.Switch = Switch;
|
|
1850
2186
|
exports.THEME_KEY = THEME_KEY;
|
|
@@ -1862,9 +2198,11 @@ exports.isEmpty = isEmpty;
|
|
|
1862
2198
|
exports.mergeRefs = mergeRefs;
|
|
1863
2199
|
exports.resolveTargetObject = resolveTargetObject;
|
|
1864
2200
|
exports.useDays = useDays;
|
|
2201
|
+
exports.useIsMobile = useIsMobile;
|
|
1865
2202
|
exports.useLayoutContext = useLayoutContext;
|
|
1866
2203
|
exports.useLongPress = useLongPress;
|
|
1867
2204
|
exports.useMonths = useMonths;
|
|
1868
2205
|
exports.useOnSwipe = useOnSwipe;
|
|
1869
2206
|
exports.useOutsideClick = useOutsideClick;
|
|
1870
2207
|
exports.usePagination = usePagination;
|
|
2208
|
+
exports.useSidebar = useSidebar;
|