@dreamstack-us/kaal 0.0.4 → 0.0.5

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.
@@ -1,11 +1,27 @@
1
1
  /// <reference lib="dom" />
2
2
  import type React from 'react';
3
- import { memo, useCallback, useState } from 'react';
3
+ import { memo, useCallback, useMemo, useState } from 'react';
4
4
  import { Pressable, StyleSheet, Text, View } from 'react-native';
5
+ import { useTimePickerOverrides } from '../../context/ThemeOverrideContext';
5
6
  import { to12Hour, to24Hour } from '../../hooks/useTimePicker';
6
7
  import type { ClockMode, TimePeriod, TimeValue } from '../../types/timepicker';
7
8
  import { ClockFace } from './ClockFace';
8
9
 
10
+ // Default colors (dark theme)
11
+ const DEFAULT_COLORS = {
12
+ containerBackground: '#2C2C2E',
13
+ headerColor: '#8E8E93',
14
+ timeFieldBackground: '#3A3A3C',
15
+ timeFieldActiveBackground: '#007AFF',
16
+ textColor: '#FFFFFF',
17
+ separatorColor: '#FFFFFF',
18
+ borderColor: '#48484A',
19
+ periodActiveBackground: 'rgba(0, 122, 255, 0.2)',
20
+ periodTextColor: '#8E8E93',
21
+ periodTextActiveColor: '#007AFF',
22
+ actionButtonColor: '#007AFF',
23
+ };
24
+
9
25
  interface MaterialTimePickerProps {
10
26
  value: TimeValue;
11
27
  onChange: (time: TimeValue) => void;
@@ -127,6 +143,7 @@ const webStyles = StyleSheet.create({
127
143
 
128
144
  export const MaterialTimePicker: React.FC<MaterialTimePickerProps> = memo(
129
145
  ({ value, onChange, is24Hour = false, onCancel, onConfirm }) => {
146
+ const overrides = useTimePickerOverrides();
130
147
  const [mode, setMode] = useState<ClockMode>('hours');
131
148
  const { hour: hour12, period } = to12Hour(value.hours);
132
149
 
@@ -155,9 +172,95 @@ export const MaterialTimePicker: React.FC<MaterialTimePickerProps> = memo(
155
172
  : hour12.toString().padStart(2, '0');
156
173
  const displayMinute = value.minutes.toString().padStart(2, '0');
157
174
 
175
+ // Build override styles from themeOverrides
176
+ const containerStyle = useMemo(
177
+ () => ({
178
+ backgroundColor:
179
+ overrides?.containerBackground ?? DEFAULT_COLORS.containerBackground,
180
+ }),
181
+ [overrides],
182
+ );
183
+
184
+ const headerStyle = useMemo(
185
+ () => ({
186
+ color: overrides?.headerColor ?? DEFAULT_COLORS.headerColor,
187
+ }),
188
+ [overrides],
189
+ );
190
+
191
+ const timeFieldStyle = useMemo(
192
+ () => ({
193
+ backgroundColor:
194
+ overrides?.timeFieldBackground ?? DEFAULT_COLORS.timeFieldBackground,
195
+ }),
196
+ [overrides],
197
+ );
198
+
199
+ const timeFieldActiveStyle = useMemo(
200
+ () => ({
201
+ backgroundColor:
202
+ overrides?.timeFieldActiveBackground ??
203
+ DEFAULT_COLORS.timeFieldActiveBackground,
204
+ }),
205
+ [overrides],
206
+ );
207
+
208
+ const textStyle = useMemo(
209
+ () => ({
210
+ color: overrides?.textColor ?? DEFAULT_COLORS.textColor,
211
+ }),
212
+ [overrides],
213
+ );
214
+
215
+ const separatorStyle = useMemo(
216
+ () => ({
217
+ color: overrides?.separatorColor ?? DEFAULT_COLORS.separatorColor,
218
+ }),
219
+ [overrides],
220
+ );
221
+
222
+ const periodContainerStyle = useMemo(
223
+ () => ({
224
+ borderColor: overrides?.periodBorderColor ?? DEFAULT_COLORS.borderColor,
225
+ }),
226
+ [overrides],
227
+ );
228
+
229
+ const periodActiveStyle = useMemo(
230
+ () => ({
231
+ backgroundColor:
232
+ overrides?.periodActiveBackground ??
233
+ DEFAULT_COLORS.periodActiveBackground,
234
+ }),
235
+ [overrides],
236
+ );
237
+
238
+ const periodTextStyle = useMemo(
239
+ () => ({
240
+ color: overrides?.periodTextColor ?? DEFAULT_COLORS.periodTextColor,
241
+ }),
242
+ [overrides],
243
+ );
244
+
245
+ const periodTextActiveStyle = useMemo(
246
+ () => ({
247
+ color:
248
+ overrides?.periodTextActiveColor ??
249
+ DEFAULT_COLORS.periodTextActiveColor,
250
+ }),
251
+ [overrides],
252
+ );
253
+
254
+ const actionButtonTextStyle = useMemo(
255
+ () => ({
256
+ color: overrides?.actionButtonColor ?? DEFAULT_COLORS.actionButtonColor,
257
+ }),
258
+ [overrides],
259
+ );
260
+
158
261
  return (
159
- <View style={webStyles.materialContainer}>
160
- <Text style={webStyles.materialHeader}>Select time</Text>
262
+ <View style={[webStyles.materialContainer, containerStyle]}>
263
+ <Text style={[webStyles.materialHeader, headerStyle]}>Select time</Text>
161
264
 
162
265
  <View style={webStyles.timeInputContainer}>
163
266
  <View style={webStyles.timeFieldsContainer}>
@@ -165,12 +268,17 @@ export const MaterialTimePicker: React.FC<MaterialTimePickerProps> = memo(
165
268
  onPress={handleHourPress}
166
269
  style={[
167
270
  webStyles.timeField,
168
- mode === 'hours' && webStyles.timeFieldActive,
271
+ timeFieldStyle,
272
+ mode === 'hours' && [
273
+ webStyles.timeFieldActive,
274
+ timeFieldActiveStyle,
275
+ ],
169
276
  ]}
170
277
  >
171
278
  <Text
172
279
  style={[
173
280
  webStyles.timeFieldText,
281
+ textStyle,
174
282
  mode === 'hours' && webStyles.timeFieldTextActive,
175
283
  ]}
176
284
  >
@@ -178,18 +286,23 @@ export const MaterialTimePicker: React.FC<MaterialTimePickerProps> = memo(
178
286
  </Text>
179
287
  </Pressable>
180
288
 
181
- <Text style={webStyles.timeSeparator}>:</Text>
289
+ <Text style={[webStyles.timeSeparator, separatorStyle]}>:</Text>
182
290
 
183
291
  <Pressable
184
292
  onPress={handleMinutePress}
185
293
  style={[
186
294
  webStyles.timeField,
187
- mode === 'minutes' && webStyles.timeFieldActive,
295
+ timeFieldStyle,
296
+ mode === 'minutes' && [
297
+ webStyles.timeFieldActive,
298
+ timeFieldActiveStyle,
299
+ ],
188
300
  ]}
189
301
  >
190
302
  <Text
191
303
  style={[
192
304
  webStyles.timeFieldText,
305
+ textStyle,
193
306
  mode === 'minutes' && webStyles.timeFieldTextActive,
194
307
  ]}
195
308
  >
@@ -199,19 +312,28 @@ export const MaterialTimePicker: React.FC<MaterialTimePickerProps> = memo(
199
312
  </View>
200
313
 
201
314
  {!is24Hour && (
202
- <View style={webStyles.periodToggleContainer}>
315
+ <View
316
+ style={[webStyles.periodToggleContainer, periodContainerStyle]}
317
+ >
203
318
  <Pressable
204
319
  onPress={() => handlePeriodChange('AM')}
205
320
  style={[
206
321
  webStyles.periodButton,
207
322
  webStyles.periodButtonTop,
208
- period === 'AM' && webStyles.periodButtonActive,
323
+ period === 'AM' && [
324
+ webStyles.periodButtonActive,
325
+ periodActiveStyle,
326
+ ],
209
327
  ]}
210
328
  >
211
329
  <Text
212
330
  style={[
213
331
  webStyles.periodButtonText,
214
- period === 'AM' && webStyles.periodButtonTextActive,
332
+ periodTextStyle,
333
+ period === 'AM' && [
334
+ webStyles.periodButtonTextActive,
335
+ periodTextActiveStyle,
336
+ ],
215
337
  ]}
216
338
  >
217
339
  AM
@@ -221,13 +343,20 @@ export const MaterialTimePicker: React.FC<MaterialTimePickerProps> = memo(
221
343
  onPress={() => handlePeriodChange('PM')}
222
344
  style={[
223
345
  webStyles.periodButton,
224
- period === 'PM' && webStyles.periodButtonActive,
346
+ period === 'PM' && [
347
+ webStyles.periodButtonActive,
348
+ periodActiveStyle,
349
+ ],
225
350
  ]}
226
351
  >
227
352
  <Text
228
353
  style={[
229
354
  webStyles.periodButtonText,
230
- period === 'PM' && webStyles.periodButtonTextActive,
355
+ periodTextStyle,
356
+ period === 'PM' && [
357
+ webStyles.periodButtonTextActive,
358
+ periodTextActiveStyle,
359
+ ],
231
360
  ]}
232
361
  >
233
362
  PM
@@ -253,12 +382,20 @@ export const MaterialTimePicker: React.FC<MaterialTimePickerProps> = memo(
253
382
  <View style={webStyles.actionButtonsContainer}>
254
383
  {onCancel && (
255
384
  <Pressable style={webStyles.actionButton} onPress={onCancel}>
256
- <Text style={webStyles.actionButtonText}>Cancel</Text>
385
+ <Text
386
+ style={[webStyles.actionButtonText, actionButtonTextStyle]}
387
+ >
388
+ Cancel
389
+ </Text>
257
390
  </Pressable>
258
391
  )}
259
392
  {onConfirm && (
260
393
  <Pressable style={webStyles.actionButton} onPress={onConfirm}>
261
- <Text style={webStyles.actionButtonText}>OK</Text>
394
+ <Text
395
+ style={[webStyles.actionButtonText, actionButtonTextStyle]}
396
+ >
397
+ OK
398
+ </Text>
262
399
  </Pressable>
263
400
  )}
264
401
  </View>
package/src/utils/date.ts CHANGED
@@ -186,7 +186,10 @@ export const formatMonth = (
186
186
  locale = 'en-US',
187
187
  style: 'long' | 'short' | 'narrow' = 'long',
188
188
  ): string => {
189
- return new Intl.DateTimeFormat(locale, { month: style }).format(date);
189
+ return new Intl.DateTimeFormat(locale, {
190
+ month: style,
191
+ timeZone: 'UTC',
192
+ }).format(date);
190
193
  };
191
194
 
192
195
  /**
@@ -197,7 +200,10 @@ export const formatWeekday = (
197
200
  locale = 'en-US',
198
201
  style: 'long' | 'short' | 'narrow' = 'short',
199
202
  ): string => {
200
- return new Intl.DateTimeFormat(locale, { weekday: style }).format(date);
203
+ return new Intl.DateTimeFormat(locale, {
204
+ weekday: style,
205
+ timeZone: 'UTC',
206
+ }).format(date);
201
207
  };
202
208
 
203
209
  /**
@@ -207,6 +213,7 @@ export const formatYearMonth = (date: Date, locale = 'en-US'): string => {
207
213
  return new Intl.DateTimeFormat(locale, {
208
214
  month: 'long',
209
215
  year: 'numeric',
216
+ timeZone: 'UTC',
210
217
  }).format(date);
211
218
  };
212
219