@neko-os/ui 0.5.0 → 0.5.2

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.
Files changed (41) hide show
  1. package/dist/NekoUI.js +4 -1
  2. package/dist/abstractions/index.js +1 -0
  3. package/dist/components/actions/Dropdown.js +5 -3
  4. package/dist/components/calendar/PeriodNavBar.js +176 -0
  5. package/dist/components/calendar/WeekDaysBar.js +8 -4
  6. package/dist/components/calendar/_helpers/calendarDays.js +5 -1
  7. package/dist/components/calendar/index.js +1 -0
  8. package/dist/components/carousel/CarouselSlider.native.js +12 -1
  9. package/dist/components/filter/DateFilter.js +1 -1
  10. package/dist/components/inputs/Select.js +56 -52
  11. package/dist/components/inputs/datePicker/DayPicker.js +15 -9
  12. package/dist/components/inputs/datePicker/MonthPicker.js +15 -10
  13. package/dist/components/inputs/datePicker/QuarterPicker.js +15 -10
  14. package/dist/components/inputs/datePicker/WeekPicker.js +15 -9
  15. package/dist/components/inputs/datePicker/YearPicker.js +15 -10
  16. package/dist/helpers/index.js +2 -0
  17. package/dist/helpers/weekStart.js +25 -0
  18. package/dist/helpers/weekStartSetup.js +11 -0
  19. package/dist/helpers/weekStartSetup.native.js +11 -0
  20. package/dist/index.js +1 -0
  21. package/package.json +1 -1
  22. package/src/NekoUI.js +3 -0
  23. package/src/abstractions/index.js +1 -0
  24. package/src/components/actions/Dropdown.js +2 -0
  25. package/src/components/calendar/PeriodNavBar.js +176 -0
  26. package/src/components/calendar/WeekDaysBar.js +6 -2
  27. package/src/components/calendar/_helpers/calendarDays.js +5 -1
  28. package/src/components/calendar/index.js +1 -1
  29. package/src/components/carousel/CarouselSlider.native.js +12 -1
  30. package/src/components/filter/DateFilter.js +1 -1
  31. package/src/components/inputs/Select.js +19 -15
  32. package/src/components/inputs/datePicker/DayPicker.js +14 -8
  33. package/src/components/inputs/datePicker/MonthPicker.js +14 -9
  34. package/src/components/inputs/datePicker/QuarterPicker.js +14 -9
  35. package/src/components/inputs/datePicker/WeekPicker.js +14 -8
  36. package/src/components/inputs/datePicker/YearPicker.js +14 -9
  37. package/src/helpers/index.js +2 -0
  38. package/src/helpers/weekStart.js +25 -0
  39. package/src/helpers/weekStartSetup.js +11 -0
  40. package/src/helpers/weekStartSetup.native.js +11 -0
  41. package/src/index.js +1 -0
@@ -17,14 +17,15 @@ dayjs.extend(quarterOfYear)
17
17
 
18
18
  const quarters = [1, 2, 3, 4]
19
19
 
20
- function QuarterGrid({ year, selectedValue, onSelect, min, max, onCheckDisabled }) {
20
+ const QuarterGrid = React.memo(function QuarterGrid({ year, selectedKey, onSelect, min, max, onCheckDisabled }) {
21
21
  const yearDate = dayjs().year(year).startOf('year')
22
+ const selectedValue = selectedKey ? dayjs(selectedKey) : null
22
23
 
23
24
  return (
24
25
  <Grid colSpan={6} gap="xs">
25
26
  {quarters.map((quarter) => {
26
27
  const dateVal = yearDate.quarter(quarter)
27
- const isActive = !!selectedValue && dateVal.isSame(selectedValue, 'week')
28
+ const isActive = !!selectedValue && dateVal.isSame(selectedValue, 'quarter')
28
29
  const disabled = isDateDisabled(dateVal, { min, max, onCheckDisabled })
29
30
 
30
31
  return (
@@ -46,7 +47,7 @@ function QuarterGrid({ year, selectedValue, onSelect, min, max, onCheckDisabled
46
47
  })}
47
48
  </Grid>
48
49
  )
49
- }
50
+ })
50
51
 
51
52
  export function QuarterPicker({ value, onChange, min, max, onCheckDisabled, allowClear, ...props }) {
52
53
  const [localValue, setLocalValue] = React.useState(value)
@@ -58,18 +59,22 @@ export function QuarterPicker({ value, onChange, min, max, onCheckDisabled, allo
58
59
  if (value?.isValid?.()) setCurrentYear(value.startOf('year'))
59
60
  }, [value?.quarter?.(), value?.year?.()])
60
61
 
61
- const handleChange = (v) => {
62
- const newValue = v.startOf('quarter')
63
- setLocalValue(newValue)
64
- onChange?.(newValue)
65
- }
62
+ const handleChange = React.useCallback(
63
+ (v) => {
64
+ const newValue = v.startOf('quarter')
65
+ setLocalValue(newValue)
66
+ onChange?.(newValue)
67
+ },
68
+ [onChange]
69
+ )
66
70
 
67
71
  const yearValue = currentYear.year()
68
72
  const minYear = min ? dayjs(min).year() : undefined
69
73
  const maxYear = max ? dayjs(max).year() : undefined
74
+ const selectedKey = value?.valueOf?.()
70
75
 
71
76
  const renderSlide = (v) => (
72
- <QuarterGrid year={v} selectedValue={value} onSelect={handleChange} min={min} max={max} onCheckDisabled={onCheckDisabled} />
77
+ <QuarterGrid year={v} selectedKey={selectedKey} onSelect={handleChange} min={min} max={max} onCheckDisabled={onCheckDisabled} />
73
78
  )
74
79
 
75
80
  return (
@@ -25,7 +25,9 @@ function fromMonthValue(v) {
25
25
  .startOf('month')
26
26
  }
27
27
 
28
- function MonthWeeks({ month, selectedValue, onSelect, min, max, onCheckDisabled }) {
28
+ const MonthWeeks = React.memo(function MonthWeeks({ monthValue, selectedKey, onSelect, min, max, onCheckDisabled }) {
29
+ const month = fromMonthValue(monthValue)
30
+ const selectedValue = selectedKey ? dayjs(selectedKey) : null
29
31
  const { cells } = useCalendarDays(month)
30
32
  const weeks = splitEvery(7, cells)
31
33
 
@@ -67,7 +69,7 @@ function MonthWeeks({ month, selectedValue, onSelect, min, max, onCheckDisabled
67
69
  </View>
68
70
  </View>
69
71
  )
70
- }
72
+ })
71
73
 
72
74
  export function WeekPicker({ value, onChange, min, max, onCheckDisabled, allowClear, ...props }) {
73
75
  const [localValue, setLocalValue] = React.useState(value)
@@ -79,18 +81,22 @@ export function WeekPicker({ value, onChange, min, max, onCheckDisabled, allowCl
79
81
  if (value?.isValid?.()) setCurrentMonth(value.startOf('month'))
80
82
  }, [value?.day?.(), value?.month?.(), value?.year?.()])
81
83
 
82
- const handleChange = (v) => {
83
- const newValue = v.startOf('week')
84
- setLocalValue(newValue)
85
- onChange?.(newValue)
86
- }
84
+ const handleChange = React.useCallback(
85
+ (v) => {
86
+ const newValue = v.startOf('week')
87
+ setLocalValue(newValue)
88
+ onChange?.(newValue)
89
+ },
90
+ [onChange]
91
+ )
87
92
 
88
93
  const monthValue = toMonthValue(currentMonth)
89
94
  const minMonth = min ? toMonthValue(dayjs(min).startOf('month')) : undefined
90
95
  const maxMonth = max ? toMonthValue(dayjs(max).startOf('month')) : undefined
96
+ const selectedKey = value?.valueOf?.()
91
97
 
92
98
  const renderSlide = (v) => (
93
- <MonthWeeks month={fromMonthValue(v)} selectedValue={value} onSelect={handleChange} min={min} max={max} onCheckDisabled={onCheckDisabled} />
99
+ <MonthWeeks monthValue={v} selectedKey={selectedKey} onSelect={handleChange} min={min} max={max} onCheckDisabled={onCheckDisabled} />
94
100
  )
95
101
 
96
102
  return (
@@ -21,15 +21,16 @@ function decadeFromIndex(i) {
21
21
  return dayjs().year(i * 10).startOf('year')
22
22
  }
23
23
 
24
- function DecadeGrid({ decadeIndex, selectedValue, onSelect, min, max, onCheckDisabled }) {
24
+ const DecadeGrid = React.memo(function DecadeGrid({ decadeIndex, selectedKey, onSelect, min, max, onCheckDisabled }) {
25
25
  const decadeStart = decadeFromIndex(decadeIndex)
26
+ const selectedValue = selectedKey ? dayjs(selectedKey) : null
26
27
  const years = range(decadeStart.year(), decadeStart.year() + 10)
27
28
 
28
29
  return (
29
30
  <Grid colSpan={12} gap="xs">
30
31
  {years.map((year) => {
31
32
  const dateVal = decadeStart.year(year)
32
- const isActive = !!selectedValue && dateVal.isSame(selectedValue, 'week')
33
+ const isActive = !!selectedValue && dateVal.isSame(selectedValue, 'year')
33
34
  const disabled = isDateDisabled(dateVal, { min, max, onCheckDisabled })
34
35
 
35
36
  return (
@@ -51,7 +52,7 @@ function DecadeGrid({ decadeIndex, selectedValue, onSelect, min, max, onCheckDis
51
52
  })}
52
53
  </Grid>
53
54
  )
54
- }
55
+ })
55
56
 
56
57
  export function YearPicker({ value, onChange, min, max, onCheckDisabled, allowClear, ...props }) {
57
58
  const [localValue, setLocalValue] = React.useState(value)
@@ -64,17 +65,21 @@ export function YearPicker({ value, onChange, min, max, onCheckDisabled, allowCl
64
65
  if (value?.isValid?.()) setCurrentDecade(getDecadeIndex(value))
65
66
  }, [value?.year?.()])
66
67
 
67
- const handleChange = (v) => {
68
- const newValue = v.startOf('year')
69
- setLocalValue(newValue)
70
- onChange?.(newValue)
71
- }
68
+ const handleChange = React.useCallback(
69
+ (v) => {
70
+ const newValue = v.startOf('year')
71
+ setLocalValue(newValue)
72
+ onChange?.(newValue)
73
+ },
74
+ [onChange]
75
+ )
72
76
 
73
77
  const minDecade = min ? getDecadeIndex(min) : undefined
74
78
  const maxDecade = max ? getDecadeIndex(max) : undefined
79
+ const selectedKey = value?.valueOf?.()
75
80
 
76
81
  const renderSlide = (v) => (
77
- <DecadeGrid decadeIndex={v} selectedValue={value} onSelect={handleChange} min={min} max={max} onCheckDisabled={onCheckDisabled} />
82
+ <DecadeGrid decadeIndex={v} selectedKey={selectedKey} onSelect={handleChange} min={min} max={max} onCheckDisabled={onCheckDisabled} />
78
83
  )
79
84
 
80
85
  return (
@@ -2,4 +2,6 @@ export * from './debounce'
2
2
  export * from './string'
3
3
  export * from './random'
4
4
  export * from './storage'
5
+ export * from './weekStart'
6
+ export * from './weekStartSetup'
5
7
  export * from './../abstractions/helpers/useSafeAreaInsets'
@@ -0,0 +1,25 @@
1
+ import dayjs from 'dayjs'
2
+ import updateLocale from 'dayjs/esm/plugin/updateLocale'
3
+
4
+ dayjs.extend(updateLocale)
5
+
6
+ let _override = null
7
+
8
+ export function getFirstDayOfWeek() {
9
+ if (_override !== null) return _override
10
+ return dayjs().$locale().weekStart || 0
11
+ }
12
+
13
+ export function setFirstDayOfWeek(day) {
14
+ _override = day
15
+ dayjs.updateLocale(dayjs().$locale().name || 'en', { weekStart: day })
16
+ }
17
+
18
+ export function getOrderedWeekdays() {
19
+ const first = getFirstDayOfWeek()
20
+ return Array.from({ length: 7 }, (_, i) => (first + i) % 7)
21
+ }
22
+
23
+ export function getWeekdayOffset(dayIndex) {
24
+ return (dayIndex - getFirstDayOfWeek() + 7) % 7
25
+ }
@@ -0,0 +1,11 @@
1
+ import { setFirstDayOfWeek } from './weekStart'
2
+
3
+ export function initFirstDayOfWeek() {
4
+ try {
5
+ const locale = new Intl.Locale(navigator.language)
6
+ const weekInfo = locale.weekInfo ?? locale.getWeekInfo?.()
7
+ if (weekInfo?.firstDay != null) {
8
+ setFirstDayOfWeek(weekInfo.firstDay === 7 ? 0 : weekInfo.firstDay)
9
+ }
10
+ } catch {}
11
+ }
@@ -0,0 +1,11 @@
1
+ import { setFirstDayOfWeek } from './weekStart'
2
+
3
+ export function initFirstDayOfWeek() {
4
+ try {
5
+ const Localization = require('expo-localization')
6
+ const cal = Localization.getCalendars()[0]
7
+ if (cal?.firstWeekday != null) {
8
+ setFirstDayOfWeek((cal.firstWeekday - 1) % 7)
9
+ }
10
+ } catch {}
11
+ }
package/src/index.js CHANGED
@@ -4,5 +4,6 @@ export * from './theme'
4
4
  export * from './responsive'
5
5
  export * from './i18n'
6
6
  export * from './NekoUI'
7
+ export * from './abstractions'
7
8
 
8
9
  export const version = 41