@scripso-homepad/ui 0.4.31 → 0.4.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scripso-homepad/ui",
3
- "version": "0.4.31",
3
+ "version": "0.4.33",
4
4
  "type": "module",
5
5
  "description": "Cross-platform UI components for Homepad (React Web + React Native)",
6
6
  "license": "MIT",
@@ -81,12 +81,9 @@ function resolveDayCellStyle(day: CalendarDayCell): StyleProp<ViewStyle> {
81
81
  return [calendarDropdownMetrics.dayCell, calendarDropdownMetrics.dayCellSelected];
82
82
  }
83
83
 
84
- const useMutedBackground =
85
- day.inCurrentMonth && !day.isToday && (day.isPast || day.isDisabled);
86
-
87
84
  return [
88
85
  calendarDropdownMetrics.dayCell,
89
- useMutedBackground ? calendarDropdownMetrics.dayCellPast : null,
86
+ day.isDisabled ? calendarDropdownMetrics.dayCellDisabled : null,
90
87
  ];
91
88
  }
92
89
 
@@ -103,7 +100,7 @@ function resolveDayLabelStyle(day: CalendarDayCell): StyleProp<TextStyle> {
103
100
  return [calendarDropdownMetrics.dayLabel, calendarDropdownMetrics.dayLabelToday];
104
101
  }
105
102
 
106
- if (day.isPast || day.isDisabled) {
103
+ if (day.isDisabled) {
107
104
  return [calendarDropdownMetrics.dayLabel, calendarDropdownMetrics.dayLabelMuted];
108
105
  }
109
106
 
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useRef, useState, type ComponentRef } from "react";
2
2
  import {
3
3
  Modal,
4
+ Platform,
4
5
  Pressable,
5
6
  StyleSheet,
6
7
  Text,
@@ -19,6 +20,7 @@ import {
19
20
  calendarFieldTypography,
20
21
  calendarLabelTypography,
21
22
  resolveCalendarDropdownLeft,
23
+ resolveCalendarDropdownLeftCentered,
22
24
  resolveCalendarDropdownTop,
23
25
  } from "../theme/calendar";
24
26
  import { getSelectFieldStyles, resolveInputVisualState, SELECT_LABEL_GAP } from "../theme/select";
@@ -78,6 +80,8 @@ export type DatePickerRangeProps = Omit<CalendarRangeProps, "style" | "className
78
80
 
79
81
  export type DatePickerProps = DatePickerSingleProps | DatePickerRangeProps;
80
82
 
83
+ const isDesktopCalendar = Platform.OS === "web";
84
+
81
85
  export function DatePicker(props: DatePickerProps) {
82
86
  const {
83
87
  label,
@@ -184,12 +188,12 @@ export function DatePicker(props: DatePickerProps) {
184
188
  };
185
189
  const helperMessage = error ?? hint;
186
190
  const panelWidth = CALENDAR_PANEL_WIDTH;
187
- const panelLeft = anchor ? resolveCalendarDropdownLeft(anchor, panelWidth) : 0;
191
+ const panelLeft = anchor
192
+ ? isDesktopCalendar
193
+ ? resolveCalendarDropdownLeft(anchor, panelWidth)
194
+ : resolveCalendarDropdownLeftCentered(panelWidth)
195
+ : 0;
188
196
  const dropdownTop = anchor ? resolveCalendarDropdownTop(anchor) : 0;
189
- const resolvedDefaultViewDate =
190
- defaultViewDate ??
191
- (props.mode === "range" ? props.value?.start : props.value) ??
192
- today;
193
197
 
194
198
  function closePicker() {
195
199
  setOpen(false);
@@ -207,6 +211,11 @@ export function DatePicker(props: DatePickerProps) {
207
211
  });
208
212
  }
209
213
 
214
+ const resolvedDefaultViewDate =
215
+ defaultViewDate ??
216
+ (props.mode === "range" ? props.value?.start : props.value) ??
217
+ today;
218
+
210
219
  function handleSingleSelect(date: Date | undefined) {
211
220
  if (props.mode === "range") {
212
221
  return;
@@ -182,7 +182,7 @@ export const calendarDropdownMetrics = StyleSheet.create({
182
182
  } as ViewStyle)
183
183
  : null),
184
184
  },
185
- dayCellPast: {
185
+ dayCellDisabled: {
186
186
  backgroundColor: colors.stormGray50,
187
187
  },
188
188
  dayCellSelected: {
@@ -321,6 +321,14 @@ export function resolveCalendarDropdownLeft(
321
321
  return Math.max(0, Math.min(anchor.x, maxLeft));
322
322
  }
323
323
 
324
+ export function resolveCalendarDropdownLeftCentered(
325
+ panelWidth: number = CALENDAR_PANEL_WIDTH,
326
+ ): number {
327
+ const windowWidth = Dimensions.get("window").width;
328
+
329
+ return Math.max(0, (windowWidth - panelWidth) / 2);
330
+ }
331
+
324
332
  export const calendarFieldMetrics = StyleSheet.create({
325
333
  container: {
326
334
  flexDirection: "row",