@ecohouse/ui 0.1.52 → 0.1.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +80 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +80 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DatePicker/DatePicker.tsx +104 -15
package/dist/index.cjs
CHANGED
|
@@ -34246,6 +34246,16 @@ var DEFAULT_MONTH_NAMES = [
|
|
|
34246
34246
|
"\u0534\u0565\u056F\u057F\u0565\u0574\u0562\u0565\u0580"
|
|
34247
34247
|
];
|
|
34248
34248
|
var DEFAULT_WEEKDAY_LABELS = ["\u0535\u0550", "\u0535\u0554", "\u0549\u0550", "\u0540\u0546", "\u0548\u0552\u0550", "\u0547\u0532", "\u053F\u0550"];
|
|
34249
|
+
function rangeIncludesUnavailable(start, end, isUnavailable) {
|
|
34250
|
+
const cursor = startOfDay(start);
|
|
34251
|
+
const last = startOfDay(end);
|
|
34252
|
+
const step = isBefore(last, cursor) ? -1 : 1;
|
|
34253
|
+
while (true) {
|
|
34254
|
+
if (isUnavailable(cursor)) return true;
|
|
34255
|
+
if (isSameDay(cursor, last)) return false;
|
|
34256
|
+
cursor.setDate(cursor.getDate() + step);
|
|
34257
|
+
}
|
|
34258
|
+
}
|
|
34249
34259
|
var EMPTY_RANGE = { start: null, end: null };
|
|
34250
34260
|
var DEFAULT_WIDTH = 320;
|
|
34251
34261
|
var DEFAULT_MENU_HEIGHT = 388;
|
|
@@ -34299,6 +34309,9 @@ var DatePicker = react.forwardRef(
|
|
|
34299
34309
|
closeOnSelect = true,
|
|
34300
34310
|
minDate,
|
|
34301
34311
|
maxDate,
|
|
34312
|
+
unavailableDates,
|
|
34313
|
+
unavailableDateLabel = "Booked",
|
|
34314
|
+
blockUnavailableDates = false,
|
|
34302
34315
|
defaultVisibleMonth,
|
|
34303
34316
|
monthNames = DEFAULT_MONTH_NAMES,
|
|
34304
34317
|
weekdayLabels = DEFAULT_WEEKDAY_LABELS,
|
|
@@ -34317,6 +34330,17 @@ var DatePicker = react.forwardRef(
|
|
|
34317
34330
|
onValueChange: _onValueChange,
|
|
34318
34331
|
...rest
|
|
34319
34332
|
} = props;
|
|
34333
|
+
const unavailableDayKeys = react.useMemo(() => {
|
|
34334
|
+
const keys = /* @__PURE__ */ new Set();
|
|
34335
|
+
for (const date of unavailableDates ?? []) {
|
|
34336
|
+
keys.add(startOfDay(date).getTime());
|
|
34337
|
+
}
|
|
34338
|
+
return keys;
|
|
34339
|
+
}, [unavailableDates]);
|
|
34340
|
+
const isUnavailable = react.useCallback(
|
|
34341
|
+
(day) => unavailableDayKeys.has(startOfDay(day).getTime()),
|
|
34342
|
+
[unavailableDayKeys]
|
|
34343
|
+
);
|
|
34320
34344
|
const isRange = props.range === true;
|
|
34321
34345
|
const usesRangeTrigger = isRange && variant !== "default";
|
|
34322
34346
|
const formatValue = formatValueProp ?? (usesRangeTrigger ? (date) => formatDateDayShortMonth(date, monthNames) : formatDate);
|
|
@@ -34419,6 +34443,7 @@ var DatePicker = react.forwardRef(
|
|
|
34419
34443
|
const handleDayPress = react.useCallback(
|
|
34420
34444
|
(day) => {
|
|
34421
34445
|
if (disabled || isDateDisabled(day, minDate, maxDate)) return;
|
|
34446
|
+
if (blockUnavailableDates && isUnavailable(day)) return;
|
|
34422
34447
|
const picked = startOfDay(day);
|
|
34423
34448
|
if (!isRange) {
|
|
34424
34449
|
if (!isValueControlled) setUncontrolledSingle(picked);
|
|
@@ -34429,14 +34454,19 @@ var DatePicker = react.forwardRef(
|
|
|
34429
34454
|
const { start, end } = rangeValue;
|
|
34430
34455
|
const startingNewRange = !start || start && end;
|
|
34431
34456
|
const nextRange = startingNewRange ? { start: picked, end: null } : isBefore(picked, start) ? { start: picked, end: null } : { start, end: picked };
|
|
34457
|
+
if (blockUnavailableDates && nextRange.start && nextRange.end && rangeIncludesUnavailable(nextRange.start, nextRange.end, isUnavailable)) {
|
|
34458
|
+
return;
|
|
34459
|
+
}
|
|
34432
34460
|
if (!isValueControlled) setUncontrolledRange(nextRange);
|
|
34433
34461
|
props.onValueChange?.(nextRange);
|
|
34434
34462
|
if (closeOnSelect && nextRange.start && nextRange.end) setOpen(false);
|
|
34435
34463
|
},
|
|
34436
34464
|
[
|
|
34465
|
+
blockUnavailableDates,
|
|
34437
34466
|
closeOnSelect,
|
|
34438
34467
|
disabled,
|
|
34439
34468
|
isRange,
|
|
34469
|
+
isUnavailable,
|
|
34440
34470
|
isValueControlled,
|
|
34441
34471
|
maxDate,
|
|
34442
34472
|
minDate,
|
|
@@ -34515,7 +34545,8 @@ var DatePicker = react.forwardRef(
|
|
|
34515
34545
|
styles26.menu,
|
|
34516
34546
|
usesRangeTrigger && styles26.rangeMenu,
|
|
34517
34547
|
hideTrigger ? styles26.menuInline : menuAlignEnd ? styles26.menuAlignEnd : styles26.menuAlignStart,
|
|
34518
|
-
calendarStyle
|
|
34548
|
+
calendarStyle,
|
|
34549
|
+
styles26.menuFitContent
|
|
34519
34550
|
],
|
|
34520
34551
|
children: [
|
|
34521
34552
|
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles26.calendarHeader, children: [
|
|
@@ -34547,7 +34578,7 @@ var DatePicker = react.forwardRef(
|
|
|
34547
34578
|
}
|
|
34548
34579
|
)
|
|
34549
34580
|
] }),
|
|
34550
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { children: [
|
|
34581
|
+
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles26.calendarGrid, children: [
|
|
34551
34582
|
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles26.weekdayRow, children: weekdayLabels.map((weekdayLabel, index) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles26.weekdayCell, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles26.weekdayText, children: weekdayLabel }) }, `${weekdayLabel}-${index}`)) }),
|
|
34552
34583
|
weeks.map((week, weekIndex) => {
|
|
34553
34584
|
let rangeHighlightStyle = null;
|
|
@@ -34602,24 +34633,26 @@ var DatePicker = react.forwardRef(
|
|
|
34602
34633
|
const isRangeStart = isRange && isSameDay(day, rangeValue.start);
|
|
34603
34634
|
const isRangeEnd = isRange && isSameDay(day, rangeValue.end);
|
|
34604
34635
|
const isSelectedEndpoint = isSelectedSingle || isRangeStart || isRangeEnd;
|
|
34636
|
+
const dayUnavailable = isUnavailable(day);
|
|
34637
|
+
const dayBlocked = blockUnavailableDates && dayUnavailable;
|
|
34605
34638
|
const dayDisabled = disabled || isDateDisabled(day, minDate, maxDate);
|
|
34606
34639
|
const dayKey = startOfDay(day).getTime();
|
|
34607
|
-
const isHovered = !dayDisabled && !isSelectedEndpoint && hoveredDayKey === dayKey;
|
|
34640
|
+
const isHovered = !dayDisabled && !dayBlocked && !isSelectedEndpoint && hoveredDayKey === dayKey;
|
|
34608
34641
|
const dayTextColor = isSelectedEndpoint ? colors.white : dayDisabled ? colors.grey400 : isToday ? colors.primary : !inCurrentMonth ? colors.grey300 : colors.white;
|
|
34609
34642
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
34610
34643
|
reactNative.Pressable,
|
|
34611
34644
|
{
|
|
34612
34645
|
onPress: () => handleDayPress(day),
|
|
34613
|
-
disabled: dayDisabled,
|
|
34646
|
+
disabled: dayDisabled || dayBlocked,
|
|
34614
34647
|
onHoverIn: () => setHoveredDayKey(dayKey),
|
|
34615
34648
|
onHoverOut: () => setHoveredDayKey((current) => current === dayKey ? null : current),
|
|
34616
34649
|
onPressIn: () => setHoveredDayKey(dayKey),
|
|
34617
34650
|
onPressOut: () => setHoveredDayKey((current) => current === dayKey ? null : current),
|
|
34618
34651
|
style: styles26.dayCellWrap,
|
|
34619
34652
|
accessibilityRole: "button",
|
|
34620
|
-
accessibilityLabel: formatValue(day),
|
|
34653
|
+
accessibilityLabel: dayUnavailable ? `${formatValue(day)}, ${unavailableDateLabel}` : formatValue(day),
|
|
34621
34654
|
accessibilityState: {
|
|
34622
|
-
disabled: dayDisabled,
|
|
34655
|
+
disabled: dayDisabled || dayBlocked,
|
|
34623
34656
|
selected: isSelectedEndpoint
|
|
34624
34657
|
},
|
|
34625
34658
|
children: [
|
|
@@ -34629,9 +34662,20 @@ var DatePicker = react.forwardRef(
|
|
|
34629
34662
|
style: [
|
|
34630
34663
|
styles26.dayCircle,
|
|
34631
34664
|
isSelectedEndpoint && styles26.dayCircleSelected,
|
|
34665
|
+
dayUnavailable && styles26.dayCircleBooked,
|
|
34632
34666
|
isHovered && styles26.dayCircleHovered
|
|
34633
34667
|
],
|
|
34634
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
34668
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
34669
|
+
reactNative.Text,
|
|
34670
|
+
{
|
|
34671
|
+
style: [
|
|
34672
|
+
styles26.dayText,
|
|
34673
|
+
{ color: dayTextColor },
|
|
34674
|
+
dayUnavailable && styles26.dayTextBooked
|
|
34675
|
+
],
|
|
34676
|
+
children: day.getDate()
|
|
34677
|
+
}
|
|
34678
|
+
)
|
|
34635
34679
|
}
|
|
34636
34680
|
),
|
|
34637
34681
|
isToday && !isSelectedEndpoint ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles26.todayDot }) : null
|
|
@@ -34769,7 +34813,7 @@ var styles26 = reactNative.StyleSheet.create({
|
|
|
34769
34813
|
menu: {
|
|
34770
34814
|
position: "absolute",
|
|
34771
34815
|
top: "100%",
|
|
34772
|
-
|
|
34816
|
+
alignSelf: "flex-start",
|
|
34773
34817
|
height: DEFAULT_MENU_HEIGHT,
|
|
34774
34818
|
marginTop: 8,
|
|
34775
34819
|
zIndex: 10,
|
|
@@ -34803,10 +34847,26 @@ var styles26 = reactNative.StyleSheet.create({
|
|
|
34803
34847
|
right: "auto",
|
|
34804
34848
|
marginTop: 0
|
|
34805
34849
|
},
|
|
34806
|
-
rangeMenu: {
|
|
34807
|
-
|
|
34850
|
+
rangeMenu: {},
|
|
34851
|
+
menuFitContent: {
|
|
34852
|
+
width: MENU_CONTENT_WIDTH + MENU_PADDING * 2,
|
|
34853
|
+
maxWidth: MENU_CONTENT_WIDTH + MENU_PADDING * 2,
|
|
34854
|
+
alignSelf: "flex-start",
|
|
34855
|
+
alignItems: "flex-start",
|
|
34856
|
+
...reactNative.Platform.select({
|
|
34857
|
+
web: {
|
|
34858
|
+
width: "fit-content",
|
|
34859
|
+
maxWidth: "fit-content"
|
|
34860
|
+
},
|
|
34861
|
+
default: {}
|
|
34862
|
+
})
|
|
34863
|
+
},
|
|
34864
|
+
calendarGrid: {
|
|
34865
|
+
width: MENU_CONTENT_WIDTH,
|
|
34866
|
+
alignSelf: "flex-start"
|
|
34808
34867
|
},
|
|
34809
34868
|
calendarHeader: {
|
|
34869
|
+
width: MENU_CONTENT_WIDTH,
|
|
34810
34870
|
height: HEADER_HEIGHT3,
|
|
34811
34871
|
paddingTop: 8,
|
|
34812
34872
|
paddingBottom: 8,
|
|
@@ -34840,9 +34900,8 @@ var styles26 = reactNative.StyleSheet.create({
|
|
|
34840
34900
|
weekdayCell: {
|
|
34841
34901
|
width: DAY_CELL_WIDTH,
|
|
34842
34902
|
height: WEEKDAY_ROW_HEIGHT,
|
|
34843
|
-
flexGrow:
|
|
34844
|
-
flexShrink:
|
|
34845
|
-
flexBasis: 0,
|
|
34903
|
+
flexGrow: 0,
|
|
34904
|
+
flexShrink: 0,
|
|
34846
34905
|
alignItems: "center",
|
|
34847
34906
|
justifyContent: "center"
|
|
34848
34907
|
},
|
|
@@ -34870,9 +34929,8 @@ var styles26 = reactNative.StyleSheet.create({
|
|
|
34870
34929
|
dayCellWrap: {
|
|
34871
34930
|
width: DAY_CELL_WIDTH,
|
|
34872
34931
|
height: DAY_CELL_HEIGHT,
|
|
34873
|
-
flexGrow:
|
|
34874
|
-
flexShrink:
|
|
34875
|
-
flexBasis: 0,
|
|
34932
|
+
flexGrow: 0,
|
|
34933
|
+
flexShrink: 0,
|
|
34876
34934
|
alignItems: "center",
|
|
34877
34935
|
justifyContent: "center",
|
|
34878
34936
|
opacity: 1
|
|
@@ -34889,6 +34947,12 @@ var styles26 = reactNative.StyleSheet.create({
|
|
|
34889
34947
|
dayCircleSelected: {
|
|
34890
34948
|
backgroundColor: colors.primary
|
|
34891
34949
|
},
|
|
34950
|
+
dayCircleBooked: {
|
|
34951
|
+
backgroundColor: colors.grey700
|
|
34952
|
+
},
|
|
34953
|
+
dayTextBooked: {
|
|
34954
|
+
textDecorationLine: "line-through"
|
|
34955
|
+
},
|
|
34892
34956
|
dayCircleHovered: {
|
|
34893
34957
|
backgroundColor: colors.grey600
|
|
34894
34958
|
},
|