@scripso-homepad/ui 0.4.30 → 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/dist/index.cjs +24 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Calendar.tsx +5 -13
- package/src/components/DatePicker.tsx +14 -5
- package/src/theme/calendar.ts +20 -10
package/package.json
CHANGED
|
@@ -77,27 +77,17 @@ export type CalendarRangeProps = CalendarBaseProps & {
|
|
|
77
77
|
export type CalendarProps = CalendarSingleProps | CalendarRangeProps;
|
|
78
78
|
|
|
79
79
|
function resolveDayCellStyle(day: CalendarDayCell): StyleProp<ViewStyle> {
|
|
80
|
-
if (day.isDisabled) {
|
|
81
|
-
return [calendarDropdownMetrics.dayCell];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
80
|
if (day.isSelected) {
|
|
85
81
|
return [calendarDropdownMetrics.dayCell, calendarDropdownMetrics.dayCellSelected];
|
|
86
82
|
}
|
|
87
83
|
|
|
88
84
|
return [
|
|
89
85
|
calendarDropdownMetrics.dayCell,
|
|
90
|
-
day.
|
|
91
|
-
? calendarDropdownMetrics.dayCellPast
|
|
92
|
-
: null,
|
|
86
|
+
day.isDisabled ? calendarDropdownMetrics.dayCellDisabled : null,
|
|
93
87
|
];
|
|
94
88
|
}
|
|
95
89
|
|
|
96
90
|
function resolveDayLabelStyle(day: CalendarDayCell): StyleProp<TextStyle> {
|
|
97
|
-
if (day.isDisabled) {
|
|
98
|
-
return [calendarDropdownMetrics.dayLabel, calendarDropdownMetrics.dayLabelDisabled];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
91
|
if (day.isSelected) {
|
|
102
92
|
return [calendarDropdownMetrics.dayLabel, calendarDropdownMetrics.dayLabelSelected];
|
|
103
93
|
}
|
|
@@ -110,7 +100,7 @@ function resolveDayLabelStyle(day: CalendarDayCell): StyleProp<TextStyle> {
|
|
|
110
100
|
return [calendarDropdownMetrics.dayLabel, calendarDropdownMetrics.dayLabelToday];
|
|
111
101
|
}
|
|
112
102
|
|
|
113
|
-
if (day.
|
|
103
|
+
if (day.isDisabled) {
|
|
114
104
|
return [calendarDropdownMetrics.dayLabel, calendarDropdownMetrics.dayLabelMuted];
|
|
115
105
|
}
|
|
116
106
|
|
|
@@ -364,7 +354,9 @@ export function Calendar(props: CalendarProps) {
|
|
|
364
354
|
>
|
|
365
355
|
<Text style={resolveDayLabelStyle(day)}>{day.date.getDate()}</Text>
|
|
366
356
|
{day.isToday && day.inCurrentMonth && !day.isSelected ? (
|
|
367
|
-
<View style={calendarDropdownMetrics.
|
|
357
|
+
<View style={calendarDropdownMetrics.todayDotWrap}>
|
|
358
|
+
<View style={calendarDropdownMetrics.todayDot} />
|
|
359
|
+
</View>
|
|
368
360
|
) : null}
|
|
369
361
|
</Pressable>
|
|
370
362
|
))}
|
|
@@ -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
|
|
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;
|
package/src/theme/calendar.ts
CHANGED
|
@@ -35,7 +35,7 @@ export const CALENDAR_NAV_ICON_COLOR = colors.stormGray850;
|
|
|
35
35
|
export const CALENDAR_FIELD_ICON_SIZE = 20;
|
|
36
36
|
export const CALENDAR_FIELD_WIDTH = CALENDAR_PANEL_WIDTH;
|
|
37
37
|
export const CALENDAR_FIELD_HEIGHT = 52;
|
|
38
|
-
export const CALENDAR_FIELD_PADDING =
|
|
38
|
+
export const CALENDAR_FIELD_PADDING = 14;
|
|
39
39
|
export const CALENDAR_FIELD_GAP = spacing.sm;
|
|
40
40
|
export const CALENDAR_FIELD_PLACEHOLDER_COLOR = colors.stormGray200;
|
|
41
41
|
|
|
@@ -182,7 +182,7 @@ export const calendarDropdownMetrics = StyleSheet.create({
|
|
|
182
182
|
} as ViewStyle)
|
|
183
183
|
: null),
|
|
184
184
|
},
|
|
185
|
-
|
|
185
|
+
dayCellDisabled: {
|
|
186
186
|
backgroundColor: colors.stormGray50,
|
|
187
187
|
},
|
|
188
188
|
dayCellSelected: {
|
|
@@ -217,18 +217,19 @@ export const calendarDropdownMetrics = StyleSheet.create({
|
|
|
217
217
|
},
|
|
218
218
|
dayLabelDisabled: {
|
|
219
219
|
color: colors.stormGray300,
|
|
220
|
-
opacity: 0.5,
|
|
221
220
|
},
|
|
222
|
-
|
|
221
|
+
todayDotWrap: {
|
|
223
222
|
position: "absolute",
|
|
224
|
-
bottom:
|
|
225
|
-
left:
|
|
223
|
+
bottom: 4,
|
|
224
|
+
left: 0,
|
|
225
|
+
right: 0,
|
|
226
|
+
alignItems: "center",
|
|
227
|
+
},
|
|
228
|
+
todayDot: {
|
|
226
229
|
width: CALENDAR_DAY_DOT_SIZE,
|
|
227
230
|
height: CALENDAR_DAY_DOT_SIZE,
|
|
228
|
-
borderRadius:
|
|
231
|
+
borderRadius: CALENDAR_DAY_DOT_SIZE / 2,
|
|
229
232
|
backgroundColor: CALENDAR_TODAY_DOT_COLOR,
|
|
230
|
-
marginLeft: -(CALENDAR_DAY_DOT_SIZE / 2),
|
|
231
|
-
zIndex: 1,
|
|
232
233
|
},
|
|
233
234
|
pickerBody: {
|
|
234
235
|
width: CALENDAR_DAY_GRID_WIDTH,
|
|
@@ -320,6 +321,14 @@ export function resolveCalendarDropdownLeft(
|
|
|
320
321
|
return Math.max(0, Math.min(anchor.x, maxLeft));
|
|
321
322
|
}
|
|
322
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
|
+
|
|
323
332
|
export const calendarFieldMetrics = StyleSheet.create({
|
|
324
333
|
container: {
|
|
325
334
|
flexDirection: "row",
|
|
@@ -347,7 +356,8 @@ export const calendarFieldMetrics = StyleSheet.create({
|
|
|
347
356
|
paddingVertical: 0,
|
|
348
357
|
paddingHorizontal: 0,
|
|
349
358
|
margin: 0,
|
|
350
|
-
|
|
359
|
+
includeFontPadding: false,
|
|
360
|
+
...(Platform.OS === "android" ? { textAlignVertical: "center" as const } : null),
|
|
351
361
|
...(Platform.OS === "web"
|
|
352
362
|
? ({
|
|
353
363
|
outlineStyle: "none",
|