@nori-ui/core 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.cjs CHANGED
@@ -6611,6 +6611,334 @@ var Checkbox = /* @__PURE__ */ __name(({
6611
6611
  }
6612
6612
  );
6613
6613
  }, "Checkbox");
6614
+ function formatDate(date$1, locale) {
6615
+ try {
6616
+ return new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(date$1.toDate(date.getLocalTimeZone()));
6617
+ } catch {
6618
+ return `${date$1.year}-${String(date$1.month).padStart(2, "0")}-${String(date$1.day).padStart(2, "0")}`;
6619
+ }
6620
+ }
6621
+ __name(formatDate, "formatDate");
6622
+ function CalendarIcon({ size = 16, color = "currentColor" }) {
6623
+ const colors = useThemeColors();
6624
+ if (reactNative.Platform.OS === "web") {
6625
+ return /* @__PURE__ */ jsxRuntime.jsx(
6626
+ "svg",
6627
+ {
6628
+ width: size,
6629
+ height: size,
6630
+ viewBox: "0 0 24 24",
6631
+ fill: "none",
6632
+ stroke: color,
6633
+ strokeWidth: "2",
6634
+ strokeLinecap: "round",
6635
+ strokeLinejoin: "round",
6636
+ "aria-hidden": "true",
6637
+ children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8 2v4M16 2v4M3 10h18M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z" })
6638
+ }
6639
+ );
6640
+ }
6641
+ const resolvedColor = color === "currentColor" ? colors.semantic.text.muted : color;
6642
+ return /* @__PURE__ */ jsxRuntime.jsx(
6643
+ reactNative.Text,
6644
+ {
6645
+ accessibilityElementsHidden: true,
6646
+ importantForAccessibility: "no-hide-descendants",
6647
+ style: { fontSize: size, lineHeight: size, color: resolvedColor },
6648
+ children: "\u{1F4C5}"
6649
+ }
6650
+ );
6651
+ }
6652
+ __name(CalendarIcon, "CalendarIcon");
6653
+ function buildCalendarOptional(minValue, maxValue, isDateUnavailable, firstDayOfWeek) {
6654
+ const out = {};
6655
+ if (minValue !== void 0) {
6656
+ out.minValue = minValue;
6657
+ }
6658
+ if (maxValue !== void 0) {
6659
+ out.maxValue = maxValue;
6660
+ }
6661
+ if (isDateUnavailable !== void 0) {
6662
+ out.isDateUnavailable = isDateUnavailable;
6663
+ }
6664
+ if (firstDayOfWeek !== void 0) {
6665
+ out.firstDayOfWeek = firstDayOfWeek;
6666
+ }
6667
+ return out;
6668
+ }
6669
+ __name(buildCalendarOptional, "buildCalendarOptional");
6670
+ function buildTriggerAriaProps(ariaProps) {
6671
+ const out = {};
6672
+ if (ariaProps["aria-labelledby"] !== void 0) {
6673
+ out["aria-labelledby"] = ariaProps["aria-labelledby"];
6674
+ }
6675
+ if (ariaProps["aria-describedby"] !== void 0) {
6676
+ out["aria-describedby"] = ariaProps["aria-describedby"];
6677
+ }
6678
+ if (ariaProps["aria-invalid"] !== void 0) {
6679
+ out["aria-invalid"] = ariaProps["aria-invalid"];
6680
+ }
6681
+ if (ariaProps["aria-required"] !== void 0) {
6682
+ out["aria-required"] = ariaProps["aria-required"];
6683
+ }
6684
+ return out;
6685
+ }
6686
+ __name(buildTriggerAriaProps, "buildTriggerAriaProps");
6687
+ var DatePickerRoot = /* @__PURE__ */ __name(({
6688
+ value,
6689
+ defaultValue: defaultValue2,
6690
+ onChange,
6691
+ locale: localeProp,
6692
+ minValue,
6693
+ maxValue,
6694
+ isDateUnavailable,
6695
+ firstDayOfWeek,
6696
+ placeholder,
6697
+ disabled = false,
6698
+ id,
6699
+ name: _name,
6700
+ className,
6701
+ testID,
6702
+ ...ariaProps
6703
+ }) => {
6704
+ const providerLocale = useLocale();
6705
+ const locale = localeProp ?? providerLocale;
6706
+ const [open, setOpen] = React.useState(false);
6707
+ const isControlled = value !== void 0;
6708
+ const [inner, setInner] = React.useState(defaultValue2 ?? null);
6709
+ const current = isControlled ? value ?? null : inner;
6710
+ const handleChange = React.useCallback(
6711
+ (date) => {
6712
+ if (!isControlled) {
6713
+ setInner(date);
6714
+ }
6715
+ onChange?.(date);
6716
+ setOpen(false);
6717
+ },
6718
+ [isControlled, onChange]
6719
+ );
6720
+ const handleOpenChange = React.useCallback(
6721
+ (next) => {
6722
+ if (!disabled) {
6723
+ setOpen(next);
6724
+ }
6725
+ },
6726
+ [disabled]
6727
+ );
6728
+ const displayValue = current ? formatDate(current, locale) : null;
6729
+ const calendarOptional = buildCalendarOptional(minValue, maxValue, isDateUnavailable, firstDayOfWeek);
6730
+ const triggerAriaProps = buildTriggerAriaProps(ariaProps);
6731
+ const colors = useThemeColors();
6732
+ const hasError = ariaProps["aria-invalid"] === true || ariaProps["aria-invalid"] === "true";
6733
+ const pressableStyle = {
6734
+ flexDirection: "row",
6735
+ alignItems: "center",
6736
+ borderWidth: 1,
6737
+ borderRadius: px(colors.radius.md),
6738
+ paddingHorizontal: px(colors.spacing["3"]),
6739
+ paddingVertical: px(colors.spacing["2"]),
6740
+ backgroundColor: colors.semantic.background.elevated,
6741
+ borderColor: hasError ? colors.color.danger : colors.semantic.border.default,
6742
+ opacity: disabled ? 0.6 : 1
6743
+ };
6744
+ const textStyle = {
6745
+ flex: 1,
6746
+ fontFamily: colors.fontFamily.body,
6747
+ fontSize: px(colors.fontSize.md),
6748
+ color: displayValue ? colors.semantic.text.default : colors.semantic.text.muted
6749
+ };
6750
+ const triggerExtraProps = {
6751
+ role: "combobox",
6752
+ accessibilityRole: "button",
6753
+ "aria-haspopup": "dialog",
6754
+ "aria-expanded": open,
6755
+ ...triggerAriaProps
6756
+ };
6757
+ if (id !== void 0) {
6758
+ triggerExtraProps.id = id;
6759
+ triggerExtraProps.nativeID = id;
6760
+ }
6761
+ if (testID !== void 0) {
6762
+ triggerExtraProps.testID = testID;
6763
+ }
6764
+ if (hasError) {
6765
+ triggerExtraProps["aria-invalid"] = true;
6766
+ }
6767
+ if (ariaProps["aria-required"]) {
6768
+ triggerExtraProps["aria-required"] = true;
6769
+ }
6770
+ if (disabled) {
6771
+ triggerExtraProps["aria-disabled"] = true;
6772
+ }
6773
+ return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
6774
+ /* @__PURE__ */ jsxRuntime.jsx(Popover.Trigger, { asChild: false, className: cn(className), children: /* @__PURE__ */ jsxRuntime.jsxs(
6775
+ reactNative.Pressable,
6776
+ {
6777
+ onPress: disabled ? void 0 : () => setOpen(!open),
6778
+ disabled,
6779
+ className: cn(
6780
+ "flex-row items-center rounded-md border px-3 py-2",
6781
+ hasError ? "border-semantic-interactive-destructive" : "border-semantic-border-default",
6782
+ disabled ? "opacity-60" : void 0,
6783
+ className
6784
+ ),
6785
+ style: pressableStyle,
6786
+ ...triggerExtraProps,
6787
+ children: [
6788
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: textStyle, numberOfLines: 1, children: displayValue ?? placeholder ?? "" }),
6789
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: { marginLeft: px(colors.spacing["2"]) }, children: /* @__PURE__ */ jsxRuntime.jsx(CalendarIcon, { size: 16, color: colors.semantic.text.muted }) })
6790
+ ]
6791
+ }
6792
+ ) }),
6793
+ /* @__PURE__ */ jsxRuntime.jsx(Popover.Content, { "aria-label": "Date picker", side: "bottom", align: "start", children: /* @__PURE__ */ jsxRuntime.jsx(
6794
+ Calendar,
6795
+ {
6796
+ mode: "single",
6797
+ value: current,
6798
+ onChange: (date) => {
6799
+ handleChange(date);
6800
+ },
6801
+ locale,
6802
+ ...calendarOptional
6803
+ }
6804
+ ) })
6805
+ ] });
6806
+ }, "DatePickerRoot");
6807
+ var DatePickerRange = /* @__PURE__ */ __name(({
6808
+ value,
6809
+ defaultValue: defaultValue2,
6810
+ onChange,
6811
+ locale: localeProp,
6812
+ minValue,
6813
+ maxValue,
6814
+ isDateUnavailable,
6815
+ firstDayOfWeek,
6816
+ placeholder,
6817
+ disabled = false,
6818
+ id,
6819
+ name: _name,
6820
+ className,
6821
+ testID,
6822
+ ...ariaProps
6823
+ }) => {
6824
+ const providerLocale = useLocale();
6825
+ const locale = localeProp ?? providerLocale;
6826
+ const [open, setOpen] = React.useState(false);
6827
+ const isControlled = value !== void 0;
6828
+ const [inner, setInner] = React.useState(defaultValue2 ?? { start: null, end: null });
6829
+ const current = isControlled ? value ?? { start: null, end: null } : inner;
6830
+ const calendarValue = current.start !== null ? { start: current.start, end: current.end } : null;
6831
+ const handleChange = React.useCallback(
6832
+ (calRange) => {
6833
+ const next = {
6834
+ start: calRange?.start ?? null,
6835
+ end: calRange?.end ?? null
6836
+ };
6837
+ if (!isControlled) {
6838
+ setInner(next);
6839
+ }
6840
+ onChange?.(next);
6841
+ if (next.start !== null && next.end !== null) {
6842
+ setOpen(false);
6843
+ }
6844
+ },
6845
+ [isControlled, onChange]
6846
+ );
6847
+ const handleOpenChange = React.useCallback(
6848
+ (next) => {
6849
+ if (!disabled) {
6850
+ setOpen(next);
6851
+ }
6852
+ },
6853
+ [disabled]
6854
+ );
6855
+ let displayValue = null;
6856
+ if (current.start !== null) {
6857
+ const startStr = formatDate(current.start, locale);
6858
+ const endStr = current.end !== null ? formatDate(current.end, locale) : "";
6859
+ displayValue = `${startStr} \u2013 ${endStr}`;
6860
+ }
6861
+ const calendarOptional = buildCalendarOptional(minValue, maxValue, isDateUnavailable, firstDayOfWeek);
6862
+ const triggerAriaProps = buildTriggerAriaProps(ariaProps);
6863
+ const colors = useThemeColors();
6864
+ const hasError = ariaProps["aria-invalid"] === true || ariaProps["aria-invalid"] === "true";
6865
+ const pressableStyle = {
6866
+ flexDirection: "row",
6867
+ alignItems: "center",
6868
+ borderWidth: 1,
6869
+ borderRadius: px(colors.radius.md),
6870
+ paddingHorizontal: px(colors.spacing["3"]),
6871
+ paddingVertical: px(colors.spacing["2"]),
6872
+ backgroundColor: colors.semantic.background.elevated,
6873
+ borderColor: hasError ? colors.color.danger : colors.semantic.border.default,
6874
+ opacity: disabled ? 0.6 : 1
6875
+ };
6876
+ const textStyle = {
6877
+ flex: 1,
6878
+ fontFamily: colors.fontFamily.body,
6879
+ fontSize: px(colors.fontSize.md),
6880
+ color: displayValue ? colors.semantic.text.default : colors.semantic.text.muted
6881
+ };
6882
+ const triggerExtraProps = {
6883
+ role: "combobox",
6884
+ accessibilityRole: "button",
6885
+ "aria-haspopup": "dialog",
6886
+ "aria-expanded": open,
6887
+ ...triggerAriaProps
6888
+ };
6889
+ if (id !== void 0) {
6890
+ triggerExtraProps.id = id;
6891
+ triggerExtraProps.nativeID = id;
6892
+ }
6893
+ if (testID !== void 0) {
6894
+ triggerExtraProps.testID = testID;
6895
+ }
6896
+ if (hasError) {
6897
+ triggerExtraProps["aria-invalid"] = true;
6898
+ }
6899
+ if (ariaProps["aria-required"]) {
6900
+ triggerExtraProps["aria-required"] = true;
6901
+ }
6902
+ if (disabled) {
6903
+ triggerExtraProps["aria-disabled"] = true;
6904
+ }
6905
+ return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
6906
+ /* @__PURE__ */ jsxRuntime.jsx(Popover.Trigger, { asChild: false, className: cn(className), children: /* @__PURE__ */ jsxRuntime.jsxs(
6907
+ reactNative.Pressable,
6908
+ {
6909
+ onPress: disabled ? void 0 : () => setOpen(!open),
6910
+ disabled,
6911
+ className: cn(
6912
+ "flex-row items-center rounded-md border px-3 py-2",
6913
+ hasError ? "border-semantic-interactive-destructive" : "border-semantic-border-default",
6914
+ disabled ? "opacity-60" : void 0,
6915
+ className
6916
+ ),
6917
+ style: pressableStyle,
6918
+ ...triggerExtraProps,
6919
+ children: [
6920
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: textStyle, numberOfLines: 1, children: displayValue ?? placeholder ?? "" }),
6921
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: { marginLeft: px(colors.spacing["2"]) }, children: /* @__PURE__ */ jsxRuntime.jsx(CalendarIcon, { size: 16, color: colors.semantic.text.muted }) })
6922
+ ]
6923
+ }
6924
+ ) }),
6925
+ /* @__PURE__ */ jsxRuntime.jsx(Popover.Content, { "aria-label": "Date range picker", side: "bottom", align: "start", children: /* @__PURE__ */ jsxRuntime.jsx(
6926
+ Calendar,
6927
+ {
6928
+ mode: "range",
6929
+ value: calendarValue,
6930
+ onChange: (range2) => {
6931
+ handleChange(range2);
6932
+ },
6933
+ locale,
6934
+ ...calendarOptional
6935
+ }
6936
+ ) })
6937
+ ] });
6938
+ }, "DatePickerRange");
6939
+ var DatePicker = Object.assign(DatePickerRoot, {
6940
+ Range: DatePickerRange
6941
+ });
6614
6942
  var DialogContext = React.createContext(null);
6615
6943
  var useDialogContext = /* @__PURE__ */ __name((label) => {
6616
6944
  const ctx = React.useContext(DialogContext);
@@ -12291,6 +12619,7 @@ exports.Button = Button;
12291
12619
  exports.Calendar = Calendar;
12292
12620
  exports.Card = Card;
12293
12621
  exports.Checkbox = Checkbox;
12622
+ exports.DatePicker = DatePicker;
12294
12623
  exports.Dialog = Dialog;
12295
12624
  exports.Field = Field;
12296
12625
  exports.FloatButton = FloatButton;