@neko-os/ui 0.0.7 → 0.0.8

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 (217) hide show
  1. package/dist/NekoUI.js +1 -1
  2. package/dist/abstractions/AnimatedView.js +1 -1
  3. package/dist/abstractions/BlurView.js +1 -0
  4. package/dist/abstractions/BlurView.native.js +1 -0
  5. package/dist/abstractions/GradientView.js +1 -0
  6. package/dist/abstractions/GradientView.native.js +1 -0
  7. package/dist/abstractions/Icon.native.js +1 -1
  8. package/dist/abstractions/ImageBackground.js +1 -0
  9. package/dist/abstractions/ImageBackground.native.js +1 -0
  10. package/dist/abstractions/ImageBackground.web.js +1 -0
  11. package/dist/abstractions/Pressable.js +1 -0
  12. package/dist/abstractions/Pressable.native.js +1 -0
  13. package/dist/abstractions/Pressable.web.js +1 -0
  14. package/dist/abstractions/ScrollView.js +1 -0
  15. package/dist/abstractions/ScrollView.native.js +1 -0
  16. package/dist/abstractions/TextInput.js +1 -1
  17. package/dist/components/actions/Button.js +1 -1
  18. package/dist/components/actions/Dropdown.js +1 -1
  19. package/dist/components/actions/Link.js +1 -1
  20. package/dist/components/actions/Pressable.js +1 -0
  21. package/dist/components/actions/index.js +1 -1
  22. package/dist/components/actions/menu/HorizontalMenu.js +1 -1
  23. package/dist/components/actions/menu/VerticalMenu.js +1 -1
  24. package/dist/components/animations/ReanimatedView.js +1 -0
  25. package/dist/components/calendar/CalendarNav.js +1 -0
  26. package/dist/components/calendar/WeekDaysBar.js +1 -0
  27. package/dist/components/calendar/_helpers/calendarDays.js +1 -1
  28. package/dist/components/calendar/_helpers/dateDisabled.js +1 -0
  29. package/dist/components/calendar/index.js +0 -1
  30. package/dist/components/feedback/alerter.js +1 -0
  31. package/dist/components/feedback/confirmer.js +1 -0
  32. package/dist/components/feedback/index.js +1 -1
  33. package/dist/components/feedback/notifications/Notification.js +1 -1
  34. package/dist/components/feedback/notifications/NotificationsHandler.js +1 -1
  35. package/dist/components/index.js +1 -1
  36. package/dist/components/inputs/DateInput.js +1 -0
  37. package/dist/components/inputs/InputWrapper.js +1 -1
  38. package/dist/components/inputs/LinkInput.js +1 -0
  39. package/dist/components/inputs/MaskInput.js +1 -0
  40. package/dist/components/inputs/TextInput.js +1 -1
  41. package/dist/components/inputs/_DateInput.native.js +1 -0
  42. package/dist/components/inputs/datePicker/DatePicker.js +1 -0
  43. package/dist/components/inputs/datePicker/DayPicker.js +1 -0
  44. package/dist/components/inputs/datePicker/MonthPicker.js +1 -0
  45. package/dist/components/inputs/datePicker/QuarterPicker.js +1 -0
  46. package/dist/components/inputs/datePicker/WeekPicker.js +1 -0
  47. package/dist/components/inputs/datePicker/YearPicker.js +1 -0
  48. package/dist/components/inputs/index.js +1 -1
  49. package/dist/components/list/ScrollView.js +1 -0
  50. package/dist/components/list/index.js +1 -0
  51. package/dist/components/presentation/ImageBackground.js +1 -0
  52. package/dist/components/presentation/Result.js +1 -1
  53. package/dist/components/presentation/index.js +1 -1
  54. package/dist/components/structure/Accordion.js +1 -1
  55. package/dist/components/structure/BlurView.js +1 -0
  56. package/dist/components/structure/GradientView.js +1 -0
  57. package/dist/components/structure/bottomDrawer/index.js +1 -0
  58. package/dist/components/structure/bottomDrawer/index.native.js +1 -0
  59. package/dist/components/structure/bottomDrawer/index.web.js +1 -0
  60. package/dist/components/structure/bottomDrawer/native/BottomDrawer.js +1 -0
  61. package/dist/components/structure/bottomDrawer/native/DrawerContext.js +1 -0
  62. package/dist/components/structure/bottomDrawer/native/DrawerHandle.js +1 -0
  63. package/dist/components/structure/bottomDrawer/native/DrawerScrollView.js +1 -0
  64. package/dist/components/structure/bottomDrawer/native/utils.js +1 -0
  65. package/dist/components/structure/bottomDrawer/web/BottomDrawer.js +1 -0
  66. package/dist/components/structure/drawer/Drawer.js +1 -0
  67. package/dist/components/structure/drawer/Drawer.native.js +1 -0
  68. package/dist/components/structure/drawer/index.js +1 -0
  69. package/dist/components/structure/index.js +1 -1
  70. package/dist/components/structure/modal/Modal.js +1 -0
  71. package/dist/components/structure/modal/Modal.native.js +1 -0
  72. package/dist/components/structure/modal/ModalBackdrop.js +1 -0
  73. package/dist/components/structure/modal/ModalContent.js +1 -0
  74. package/dist/components/structure/modal/ModalFooter.js +1 -0
  75. package/dist/components/structure/modal/ModalHeader.js +1 -0
  76. package/dist/components/structure/modal/handler/ModalsHandler.js +1 -0
  77. package/dist/components/structure/modal/index.js +1 -0
  78. package/dist/components/structure/overlay/OverlayWrapper.js +1 -1
  79. package/dist/components/structure/popover/Popover.js +1 -1
  80. package/dist/components/structure/popover/Popover.native.js +1 -1
  81. package/dist/modifiers/animations/animatedEffects.js +1 -1
  82. package/dist/modifiers/animations/animatedEffects.native.js +1 -1
  83. package/dist/modifiers/animations/fadeEffect.js +1 -1
  84. package/dist/modifiers/animations/scaleEffect.js +1 -0
  85. package/dist/modifiers/animations/scaleEffect.native.js +1 -0
  86. package/dist/modifiers/animations/slideEffect.js +1 -1
  87. package/dist/modifiers/background.js +1 -1
  88. package/dist/modifiers/cursor.js +1 -0
  89. package/dist/modifiers/display.js +1 -1
  90. package/dist/modifiers/hover.js +1 -0
  91. package/dist/modifiers/position.js +1 -1
  92. package/dist/modifiers/size.js +1 -1
  93. package/dist/modifiers/state.js +1 -1
  94. package/dist/responsive/responsiveHooks.js +1 -1
  95. package/dist/theme/default/blackTheme.js +1 -0
  96. package/dist/theme/default/cyberpunkTheme.js +1 -1
  97. package/dist/theme/default/darkTheme.js +1 -1
  98. package/dist/theme/default/deepWoodsTheme.js +1 -1
  99. package/dist/theme/default/forestTheme.js +1 -1
  100. package/dist/theme/default/hackerTheme.js +1 -1
  101. package/dist/theme/default/lightTheme.js +1 -1
  102. package/dist/theme/default/midnightTheme.js +1 -1
  103. package/dist/theme/default/msdosTheme.js +1 -1
  104. package/dist/theme/default/oceanTheme.js +1 -1
  105. package/dist/theme/default/pastelTheme.js +1 -1
  106. package/dist/theme/default/sunsetTheme.js +1 -1
  107. package/dist/theme/default/themes.js +1 -1
  108. package/package.json +8 -3
  109. package/src/NekoUI.js +6 -3
  110. package/src/abstractions/AnimatedView.js +3 -3
  111. package/src/abstractions/BlurView.js +43 -0
  112. package/src/abstractions/BlurView.native.js +39 -0
  113. package/src/abstractions/GradientView.js +5 -0
  114. package/src/abstractions/GradientView.native.js +32 -0
  115. package/src/abstractions/Icon.native.js +4 -2
  116. package/src/abstractions/ImageBackground.js +17 -0
  117. package/src/abstractions/ImageBackground.native.js +27 -0
  118. package/src/abstractions/ImageBackground.web.js +7 -0
  119. package/src/abstractions/Pressable.js +4 -0
  120. package/src/abstractions/Pressable.native.js +3 -0
  121. package/src/abstractions/Pressable.web.js +3 -0
  122. package/src/abstractions/ScrollView.js +3 -0
  123. package/src/abstractions/ScrollView.native.js +5 -0
  124. package/src/abstractions/TextInput.js +2 -2
  125. package/src/components/actions/Button.js +7 -0
  126. package/src/components/actions/Dropdown.js +2 -1
  127. package/src/components/actions/Link.js +16 -2
  128. package/src/components/actions/Pressable.js +38 -0
  129. package/src/components/actions/index.js +1 -0
  130. package/src/components/actions/menu/HorizontalMenu.js +2 -1
  131. package/src/components/actions/menu/VerticalMenu.js +4 -3
  132. package/src/components/animations/ReanimatedView.js +40 -0
  133. package/src/components/calendar/CalendarNav.js +67 -0
  134. package/src/components/calendar/WeekDaysBar.js +18 -0
  135. package/src/components/calendar/_helpers/calendarDays.js +1 -3
  136. package/src/components/calendar/_helpers/dateDisabled.js +24 -0
  137. package/src/components/calendar/index.js +1 -1
  138. package/src/components/feedback/alerter.js +31 -0
  139. package/src/components/feedback/confirmer.js +70 -0
  140. package/src/components/feedback/index.js +2 -0
  141. package/src/components/feedback/notifications/Notification.js +1 -1
  142. package/src/components/feedback/notifications/NotificationsHandler.js +3 -3
  143. package/src/components/index.js +1 -0
  144. package/src/components/inputs/DateInput.js +111 -0
  145. package/src/components/inputs/InputWrapper.js +18 -6
  146. package/src/components/inputs/LinkInput.js +17 -0
  147. package/src/components/inputs/MaskInput.js +67 -0
  148. package/src/components/inputs/TextInput.js +2 -2
  149. package/src/components/inputs/_DateInput.native.js +89 -0
  150. package/src/components/inputs/datePicker/DatePicker.js +24 -0
  151. package/src/components/inputs/datePicker/DayPicker.js +65 -0
  152. package/src/components/inputs/datePicker/MonthPicker.js +62 -0
  153. package/src/components/inputs/datePicker/QuarterPicker.js +65 -0
  154. package/src/components/inputs/datePicker/WeekPicker.js +74 -0
  155. package/src/components/inputs/datePicker/YearPicker.js +67 -0
  156. package/src/components/inputs/index.js +4 -0
  157. package/src/components/list/ScrollView.js +58 -0
  158. package/src/components/list/index.js +1 -0
  159. package/src/components/presentation/ImageBackground.js +38 -0
  160. package/src/components/presentation/Result.js +2 -2
  161. package/src/components/presentation/index.js +1 -0
  162. package/src/components/structure/Accordion.js +1 -1
  163. package/src/components/structure/BlurView.js +58 -0
  164. package/src/components/structure/GradientView.js +42 -0
  165. package/src/components/structure/bottomDrawer/index.js +1 -0
  166. package/src/components/structure/bottomDrawer/index.native.js +4 -0
  167. package/src/components/structure/bottomDrawer/index.web.js +4 -0
  168. package/src/components/structure/bottomDrawer/native/BottomDrawer.js +229 -0
  169. package/src/components/structure/bottomDrawer/native/DrawerContext.js +21 -0
  170. package/src/components/structure/bottomDrawer/native/DrawerHandle.js +12 -0
  171. package/src/components/structure/bottomDrawer/native/DrawerScrollView.js +83 -0
  172. package/src/components/structure/bottomDrawer/native/utils.js +58 -0
  173. package/src/components/structure/bottomDrawer/web/BottomDrawer.js +3 -0
  174. package/src/components/structure/drawer/Drawer.js +5 -0
  175. package/src/components/structure/drawer/Drawer.native.js +3 -0
  176. package/src/components/structure/drawer/index.js +1 -0
  177. package/src/components/structure/index.js +5 -0
  178. package/src/components/structure/modal/Modal.js +84 -0
  179. package/src/components/structure/modal/Modal.native.js +83 -0
  180. package/src/components/structure/modal/ModalBackdrop.js +58 -0
  181. package/src/components/structure/modal/ModalContent.js +28 -0
  182. package/src/components/structure/modal/ModalFooter.js +31 -0
  183. package/src/components/structure/modal/ModalHeader.js +50 -0
  184. package/src/components/structure/modal/handler/ModalsHandler.js +61 -0
  185. package/src/components/structure/modal/index.js +6 -0
  186. package/src/components/structure/overlay/OverlayWrapper.js +1 -1
  187. package/src/components/structure/popover/Popover.js +28 -2
  188. package/src/components/structure/popover/Popover.native.js +44 -15
  189. package/src/modifiers/animations/animatedEffects.js +2 -0
  190. package/src/modifiers/animations/animatedEffects.native.js +3 -1
  191. package/src/modifiers/animations/fadeEffect.js +4 -2
  192. package/src/modifiers/animations/scaleEffect.js +45 -0
  193. package/src/modifiers/animations/scaleEffect.native.js +33 -0
  194. package/src/modifiers/animations/slideEffect.js +3 -1
  195. package/src/modifiers/background.js +16 -4
  196. package/src/modifiers/cursor.js +21 -0
  197. package/src/modifiers/display.js +2 -2
  198. package/src/modifiers/hover.js +28 -0
  199. package/src/modifiers/position.js +24 -3
  200. package/src/modifiers/size.js +2 -1
  201. package/src/modifiers/state.js +1 -1
  202. package/src/responsive/responsiveHooks.js +7 -0
  203. package/src/theme/default/blackTheme.js +32 -0
  204. package/src/theme/default/cyberpunkTheme.js +1 -0
  205. package/src/theme/default/darkTheme.js +1 -0
  206. package/src/theme/default/deepWoodsTheme.js +1 -0
  207. package/src/theme/default/forestTheme.js +1 -0
  208. package/src/theme/default/hackerTheme.js +1 -0
  209. package/src/theme/default/lightTheme.js +1 -0
  210. package/src/theme/default/midnightTheme.js +1 -0
  211. package/src/theme/default/msdosTheme.js +1 -0
  212. package/src/theme/default/oceanTheme.js +1 -0
  213. package/src/theme/default/pastelTheme.js +2 -1
  214. package/src/theme/default/sunsetTheme.js +2 -1
  215. package/src/theme/default/themes.js +2 -0
  216. package/dist/components/calendar/DayPicker.js +0 -1
  217. package/src/components/calendar/DayPicker.js +0 -94
@@ -0,0 +1,111 @@
1
+ import React from 'react'
2
+ import advancedFormat from 'dayjs/esm/plugin/advancedFormat'
3
+ import dayjs from 'dayjs'
4
+ import weekOfYear from 'dayjs/esm/plugin/weekOfYear'
5
+
6
+ import { LinkInput } from './LinkInput'
7
+ import { View } from '../structure/View'
8
+ import { useResponsiveValue } from '../../responsive'
9
+
10
+ dayjs.extend(advancedFormat)
11
+ dayjs.extend(weekOfYear)
12
+
13
+ import { DatePicker } from './datePicker/DatePicker'
14
+ import { MaskInput } from './MaskInput'
15
+ import { Popover } from '../structure/popover/Popover'
16
+ import { isValidDate } from '../calendar/_helpers/dateDisabled'
17
+
18
+ export function getDateInputDefaultFormat(type) {
19
+ switch (type) {
20
+ case 'year':
21
+ return 'YYYY'
22
+ case 'quarter':
23
+ return 'YYYY-Q'
24
+ case 'month':
25
+ return 'YYYY-MM'
26
+ case 'week':
27
+ return 'YYYY-ww'
28
+ default:
29
+ return 'YYYY-MM-DD'
30
+ }
31
+ }
32
+
33
+ export function DateInput({
34
+ value,
35
+ onChange,
36
+ min,
37
+ max,
38
+ onCheckDisabled,
39
+ placement,
40
+ type = 'day',
41
+ format,
42
+ useBottomDrawer = { native: true, sm: true, md: true },
43
+ ...props
44
+ }) {
45
+ useBottomDrawer = useResponsiveValue(useBottomDrawer)
46
+ format = format || getDateInputDefaultFormat(type)
47
+ if (value === '') value = undefined
48
+ const [inputValue, setInputValue] = React.useState('')
49
+ const [localValue, setLocalValue] = React.useState(value)
50
+
51
+ value = value || localValue
52
+
53
+ const validations = { min, max, onCheckDisabled }
54
+
55
+ const handleChange = (v) => {
56
+ if (!isValidDate(v, format, validations)) return
57
+ v = !!v ? dayjs(v) : null
58
+ setLocalValue(v)
59
+ onChange?.(v)
60
+ }
61
+
62
+ const handleChangeInput = (v) => {
63
+ setInputValue(v)
64
+ if (!isValidDate(v, format, validations)) return
65
+ handleChange(v)
66
+ }
67
+
68
+ const onBlur = () => {
69
+ if (isValidDate(inputValue, format, validations)) return
70
+ handleChange(null)
71
+ setInputValue('')
72
+ }
73
+
74
+ React.useEffect(() => {
75
+ setInputValue(!!value ? dayjs(value).format(format) : '')
76
+ }, [value])
77
+
78
+ const Input = useBottomDrawer ? LinkInput : MaskInput
79
+
80
+ return (
81
+ <Popover
82
+ trigger="click"
83
+ placement={placement || 'bottomLeft'}
84
+ snapPoints={[350]}
85
+ useBottomDrawer={useBottomDrawer}
86
+ renderContent={({ onClose }) => (
87
+ <View flex centerH>
88
+ <DatePicker
89
+ value={value}
90
+ onChange={(v) => {
91
+ handleChange(v)
92
+ onClose()
93
+ }}
94
+ {...validations}
95
+ type={type}
96
+ />
97
+ </View>
98
+ )}
99
+ >
100
+ <Input
101
+ value={inputValue}
102
+ onChange={handleChangeInput}
103
+ suffixIcon="calendar-line"
104
+ suffixIconColor="text4"
105
+ onBlur={onBlur}
106
+ mask={format.replace(/[DMYQwW]/gi, '9')}
107
+ {...props}
108
+ />
109
+ </Popover>
110
+ )
111
+ }
@@ -19,10 +19,23 @@ const DEFAULT_PROPS = {
19
19
  gap: 'sm',
20
20
  }
21
21
 
22
- export function InputWrapper({ prefix, suffix, prefixIcon, suffixIcon, loading, error, children, ...rootProps }) {
22
+ export function InputWrapper({
23
+ prefix,
24
+ suffix,
25
+ prefixIcon,
26
+ prefixIconColor,
27
+ suffixIcon,
28
+ suffixIconColor,
29
+ loading,
30
+ error,
31
+ children,
32
+ ref,
33
+ ...rootProps
34
+ }) {
23
35
  const [hover, setHover] = React.useState(false)
24
- const inputRef = React.useRef()
25
- const [{ size, sizeCode, onChange }, props] = pipe(
36
+ const fallbackInputRef = React.useRef()
37
+ const inputRef = ref || fallbackInputRef
38
+ const [{ size, sizeCode }, props] = pipe(
26
39
  useSizeConverter('elementHeights', 'md'),
27
40
  useThemeComponentModifier('InputWrapper'),
28
41
  useDefaultModifier(DEFAULT_PROPS)
@@ -34,8 +47,8 @@ export function InputWrapper({ prefix, suffix, prefixIcon, suffixIcon, loading,
34
47
 
35
48
  if (!!prefix && is(String, prefix)) prefix = <Text>{prefix}</Text>
36
49
  if (!!suffix && is(String, suffix)) suffix = <Text>{suffix}</Text>
37
- if (!prefix && !!prefixIcon) prefix = <Icon name={prefixIcon} size={sizeCode} />
38
- if (!suffix && !!suffixIcon) suffix = <Icon name={suffixIcon} size={sizeCode} />
50
+ if (!prefix && !!prefixIcon) prefix = <Icon name={prefixIcon} size={sizeCode} color={prefixIconColor} />
51
+ if (!suffix && !!suffixIcon) suffix = <Icon name={suffixIcon} size={sizeCode} color={suffixIconColor} />
39
52
  if (!prefix && !!error) suffix = <Icon name="close-circle-fill" size={sizeCode} red />
40
53
  if (!!loading) suffix = <Loading size={sizeCode} />
41
54
 
@@ -46,7 +59,6 @@ export function InputWrapper({ prefix, suffix, prefixIcon, suffixIcon, loading,
46
59
  const childWithProps = React.cloneElement(child, {
47
60
  ...child.props,
48
61
  ref: inputRef,
49
- onChange: child.props.onChange || onChange,
50
62
  })
51
63
 
52
64
  return (
@@ -0,0 +1,17 @@
1
+ import { InputWrapper } from './InputWrapper'
2
+ import { Link } from '../actions/Link'
3
+ import { Text } from '../text/Text'
4
+ import { View } from '../structure/View'
5
+ import { useColors } from '../../theme/ThemeHandler'
6
+
7
+ export function LinkInput({ onPress, onClick, placeholder, value, disabled, ...props }) {
8
+ return (
9
+ <Link onPress={!props.loading ? onPress || onClick : undefined} flex fullW centerV disabled={disabled}>
10
+ <InputWrapper {...props}>
11
+ <View centerV flex fullW>
12
+ <Text color={!!value ? 'text' : 'text_op30'} label={value || placeholder} />
13
+ </View>
14
+ </InputWrapper>
15
+ </Link>
16
+ )
17
+ }
@@ -0,0 +1,67 @@
1
+ import React from 'react'
2
+
3
+ import { TextInput } from './TextInput'
4
+
5
+ function removeMask(value, mask = '') {
6
+ let result = ''
7
+
8
+ for (let i = 0; i < mask.length; i++) {
9
+ const maskChar = mask[i]
10
+ const valueChar = value[i]
11
+
12
+ if (!valueChar) break
13
+
14
+ if (maskChar === 'A' && /[A-Za-z]/.test(valueChar)) {
15
+ result += valueChar
16
+ } else if (maskChar === '9' && /\d/.test(valueChar)) {
17
+ result += valueChar
18
+ }
19
+ }
20
+
21
+ return result
22
+ }
23
+
24
+ function applyMask(value, mask) {
25
+ const clean = value.replace(/[^0-9A-Za-z]/g, '')
26
+ let result = ''
27
+ let index = 0
28
+
29
+ for (let i = 0; i < mask.length; i++) {
30
+ if (index >= clean.length) break
31
+ const char = mask[i]
32
+
33
+ if (char === '9' && /[0-9]/.test(clean[index])) {
34
+ result += clean[index]
35
+ index++
36
+ } else if (char === 'A' && /[A-Za-z]/.test(clean[index])) {
37
+ result += clean[index].toUpperCase()
38
+ index++
39
+ } else if (char === '9' || char === 'A') {
40
+ index++
41
+ i--
42
+ } else {
43
+ result += char
44
+ }
45
+ }
46
+
47
+ return result
48
+ }
49
+
50
+ export function MaskInput({ value = '', onChange, mask = '', useRawValue, ...props }) {
51
+ const [localValue, setLocalValue] = React.useState(applyMask(value, mask))
52
+
53
+ const handleChange = React.useCallback(
54
+ (text) => {
55
+ const masked = applyMask(text, mask)
56
+ onChange?.(useRawValue ? removeMask(masked, mask) : masked)
57
+ setLocalValue(masked)
58
+ },
59
+ [mask, onChange]
60
+ )
61
+
62
+ React.useEffect(() => {
63
+ setLocalValue(applyMask(value, mask))
64
+ }, [value])
65
+
66
+ return <TextInput value={localValue} onChange={handleChange} {...props} />
67
+ }
@@ -2,7 +2,7 @@ import { AbsTextInput } from '../../abstractions/TextInput'
2
2
  import { InputWrapper } from './InputWrapper'
3
3
  import { useColors } from '../../theme/ThemeHandler'
4
4
 
5
- export function TextInput({ value, ...props }) {
5
+ export function TextInput({ onChange, ...props }) {
6
6
  const colors = useColors()
7
7
 
8
8
  const STYLE = {
@@ -16,7 +16,7 @@ export function TextInput({ value, ...props }) {
16
16
 
17
17
  return (
18
18
  <InputWrapper {...props}>
19
- <AbsTextInput style={STYLE} placeholderTextColor={colors.text_op30} {...props} value={value} />
19
+ <AbsTextInput style={STYLE} placeholderTextColor={colors.text_op30} {...props} onChange={onChange} />
20
20
  </InputWrapper>
21
21
  )
22
22
  }
@@ -0,0 +1,89 @@
1
+ import React from 'react'
2
+ import advancedFormat from 'dayjs/esm/plugin/advancedFormat'
3
+ import dayjs from 'dayjs'
4
+ import weekOfYear from 'dayjs/esm/plugin/weekOfYear'
5
+
6
+ dayjs.extend(advancedFormat)
7
+ dayjs.extend(weekOfYear)
8
+
9
+ import { DatePicker } from './datePicker/DatePicker'
10
+ import { MaskInput } from './MaskInput'
11
+ import { Popover } from '../structure/popover/Popover'
12
+ import { isValidDate } from '../calendar/_helpers/dateDisabled'
13
+
14
+ export function getDateInputDefaultFormat(type) {
15
+ switch (type) {
16
+ case 'year':
17
+ return 'YYYY'
18
+ case 'quarter':
19
+ return 'YYYY-Q'
20
+ case 'month':
21
+ return 'YYYY-MM'
22
+ case 'week':
23
+ return 'YYYY-ww'
24
+ default:
25
+ return 'YYYY-MM-DD'
26
+ }
27
+ }
28
+
29
+ export function DateInput({ value, onChange, min, max, onCheckDisabled, placement, type = 'day', format, ...props }) {
30
+ format = format || getDateInputDefaultFormat(type)
31
+ const [inputValue, setInputValue] = React.useState('')
32
+ const [localValue, setLocalValue] = React.useState(value)
33
+
34
+ value = value || localValue
35
+
36
+ const validations = { min, max, onCheckDisabled }
37
+
38
+ const handleChange = (v) => {
39
+ if (!isValidDate(v, format, validations)) return
40
+ v = !!v ? dayjs(v) : null
41
+ setLocalValue(v)
42
+ onChange?.(v)
43
+ }
44
+
45
+ const handleChangeInput = (v) => {
46
+ setInputValue(v)
47
+ if (!isValidDate(v, format, validations)) return
48
+ handleChange(v)
49
+ }
50
+
51
+ const onBlur = () => {
52
+ if (isValidDate(inputValue, format, validations)) return
53
+ handleChange(null)
54
+ setInputValue('')
55
+ }
56
+
57
+ React.useEffect(() => {
58
+ setInputValue(!!value ? dayjs(value).format(format) : '')
59
+ }, [value])
60
+
61
+ return false
62
+ return (
63
+ <Popover
64
+ trigger="click"
65
+ placement={placement || 'bottomLeft'}
66
+ renderContent={({ onClose }) => (
67
+ <DatePicker
68
+ value={value}
69
+ onChange={(v) => {
70
+ handleChange(v)
71
+ onClose()
72
+ }}
73
+ {...validations}
74
+ type={type}
75
+ />
76
+ )}
77
+ >
78
+ <MaskInput
79
+ value={inputValue}
80
+ onChange={handleChangeInput}
81
+ suffixIcon="calendar-line"
82
+ suffixIconColor="text4"
83
+ onBlur={onBlur}
84
+ mask={format.replace(/[DMYQwW]/gi, '9')}
85
+ {...props}
86
+ />
87
+ </Popover>
88
+ )
89
+ }
@@ -0,0 +1,24 @@
1
+ import { DayPicker } from './DayPicker'
2
+ import { MonthPicker } from './MonthPicker'
3
+ import { QuarterPicker } from './QuarterPicker'
4
+ import { WeekPicker } from './WeekPicker'
5
+ import { YearPicker } from './YearPicker'
6
+
7
+ export function DatePicker({ type, ...props }) {
8
+ switch (type) {
9
+ case 'year':
10
+ return <YearPicker {...props} />
11
+
12
+ case 'quarter':
13
+ return <QuarterPicker {...props} />
14
+
15
+ case 'month':
16
+ return <MonthPicker {...props} />
17
+
18
+ case 'week':
19
+ return <WeekPicker {...props} />
20
+
21
+ default:
22
+ return <DayPicker {...props} />
23
+ }
24
+ }
@@ -0,0 +1,65 @@
1
+ import React from 'react'
2
+ import dayjs from 'dayjs'
3
+
4
+ import { CalendarNav } from '../../calendar/CalendarNav'
5
+ import { Col } from '../../structure/Col'
6
+ import { Grid } from '../../structure/Row'
7
+ import { Link } from '../../actions/Link'
8
+ import { Text } from '../../text/Text'
9
+ import { View } from '../../structure/View'
10
+ import { WeekDaysBar } from '../../calendar/WeekDaysBar'
11
+ import { isDateDisabled } from '../../calendar/_helpers/dateDisabled'
12
+ import { useCalendarDays } from '../../calendar/_helpers/calendarDays'
13
+
14
+ export function DayPicker({ value, onChange, min, max, onCheckDisabled, ...props }) {
15
+ if (!!value) value = dayjs(value)
16
+ const [localValue, setLocalValue] = React.useState(value)
17
+
18
+ React.useEffect(() => {
19
+ setLocalValue(value)
20
+ }, [value])
21
+
22
+ value = value === undefined ? localValue : value
23
+
24
+ const handleChange = (v) => {
25
+ setLocalValue(v)
26
+ onChange?.(v)
27
+ }
28
+
29
+ const [currentMonth, setCurrentMonth] = React.useState(() => dayjs(value).startOf('month'))
30
+
31
+ const { cells } = useCalendarDays(currentMonth)
32
+
33
+ return (
34
+ <View className="neko-day-picker" width={275} {...props}>
35
+ <CalendarNav value={currentMonth} onChange={setCurrentMonth} />
36
+ <WeekDaysBar />
37
+
38
+ <Grid className="neko-day-picker-days" colSpan={24 / 7} gap="sm">
39
+ {cells.map((day, i) => {
40
+ const dateVal = currentMonth.date(day)
41
+ const isActive = !!value && !!day && dateVal.isSame(value, 'day')
42
+ const disabled = isDateDisabled(dateVal, { min, max, onCheckDisabled })
43
+
44
+ return (
45
+ <Col key={day ? dateVal.format('YYYYMMDD') : i} className="day-cell" center>
46
+ <Link
47
+ ratio={1}
48
+ fullW
49
+ center
50
+ br="md"
51
+ onPress={() => !!day && handleChange(dateVal)}
52
+ bg={isActive && 'primary'}
53
+ disabled={disabled}
54
+ >
55
+ <Text sm text2 center strong={isActive}>
56
+ {day || ''}
57
+ </Text>
58
+ </Link>
59
+ </Col>
60
+ )
61
+ })}
62
+ </Grid>
63
+ </View>
64
+ )
65
+ }
@@ -0,0 +1,62 @@
1
+ import React from 'react'
2
+ import dayjs from 'dayjs'
3
+
4
+ import { CalendarNav } from '../../calendar/CalendarNav'
5
+ import { Col } from '../../structure/Col'
6
+ import { Divider } from '../../helpers'
7
+ import { Grid } from '../../structure/Row'
8
+ import { Link } from '../../actions/Link'
9
+ import { Text } from '../../text/Text'
10
+ import { View } from '../../structure/View'
11
+ import { isDateDisabled } from '../../calendar/_helpers/dateDisabled'
12
+
13
+ const months = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
14
+
15
+ export function MonthPicker({ value, onChange, min, max, onCheckDisabled, ...props }) {
16
+ const [localValue, setLocalValue] = React.useState(value)
17
+ value = value === undefined ? localValue : value
18
+
19
+ React.useEffect(() => {
20
+ setLocalValue(value)
21
+ }, [value?.month?.(), value?.year?.()])
22
+
23
+ const handleChange = (v) => {
24
+ const newValue = v.startOf('month')
25
+ setLocalValue(newValue)
26
+ onChange?.(newValue)
27
+ }
28
+
29
+ const [currentYear, setCurrentYear] = React.useState(() => dayjs(value).startOf('year'))
30
+
31
+ return (
32
+ <View className="neko-day-picker" width={275} {...props}>
33
+ <CalendarNav value={currentYear} onChange={setCurrentYear} level="year" />
34
+ <Divider />
35
+
36
+ <Grid colSpan={8} gap="xs">
37
+ {months.map((month) => {
38
+ const dateVal = currentYear.month(month)
39
+ const isActive = !!value && dateVal.isSame(value, 'week')
40
+ const disabled = isDateDisabled(dateVal, { min, max, onCheckDisabled })
41
+
42
+ return (
43
+ <Col key={month}>
44
+ <Link
45
+ fullW
46
+ br="md"
47
+ padding="sm"
48
+ onPress={() => handleChange(dateVal)}
49
+ bg={isActive && 'primary'}
50
+ disabled={disabled}
51
+ >
52
+ <Text text2={!isActive} strong={isActive} center>
53
+ {dateVal.format('MMM')}
54
+ </Text>
55
+ </Link>
56
+ </Col>
57
+ )
58
+ })}
59
+ </Grid>
60
+ </View>
61
+ )
62
+ }
@@ -0,0 +1,65 @@
1
+ import React from 'react'
2
+ import dayjs from 'dayjs'
3
+ import quarterOfYear from 'dayjs/esm/plugin/quarterOfYear'
4
+
5
+ import { CalendarNav } from '../../calendar/CalendarNav'
6
+ import { Col } from '../../structure/Col'
7
+ import { Divider } from '../../helpers'
8
+ import { Grid } from '../../structure/Row'
9
+ import { Link } from '../../actions/Link'
10
+ import { Text } from '../../text/Text'
11
+ import { View } from '../../structure/View'
12
+ import { isDateDisabled } from '../../calendar/_helpers/dateDisabled'
13
+
14
+ dayjs.extend(quarterOfYear)
15
+
16
+ const quarters = [1, 2, 3, 4]
17
+
18
+ export function QuarterPicker({ value, onChange, min, max, onCheckDisabled, ...props }) {
19
+ const [localValue, setLocalValue] = React.useState(value)
20
+ value = value === undefined ? localValue : value
21
+
22
+ React.useEffect(() => {
23
+ setLocalValue(value)
24
+ }, [value?.quarter?.(), value?.year?.()])
25
+
26
+ const handleChange = (v) => {
27
+ const newValue = v.startOf('quarter')
28
+ setLocalValue(newValue)
29
+ onChange?.(newValue)
30
+ }
31
+
32
+ const [currentYear, setCurrentYear] = React.useState(() => dayjs(value).startOf('year'))
33
+
34
+ return (
35
+ <View className="neko-day-picker" width={275} {...props}>
36
+ <CalendarNav value={currentYear} onChange={setCurrentYear} level="year" />
37
+ <Divider />
38
+
39
+ <Grid colSpan={6} gap="xs">
40
+ {quarters.map((quarter) => {
41
+ const dateVal = currentYear.quarter(quarter)
42
+ const isActive = !!value && dateVal.isSame(value, 'week')
43
+ const disabled = isDateDisabled(dateVal, { min, max, onCheckDisabled })
44
+
45
+ return (
46
+ <Col key={quarter}>
47
+ <Link
48
+ fullW
49
+ br="md"
50
+ padding="sm"
51
+ onPress={() => handleChange(dateVal)}
52
+ bg={isActive && 'primary'}
53
+ disabled={disabled}
54
+ >
55
+ <Text text2={!isActive} strong={isActive} center>
56
+ Q{dateVal.quarter()}
57
+ </Text>
58
+ </Link>
59
+ </Col>
60
+ )
61
+ })}
62
+ </Grid>
63
+ </View>
64
+ )
65
+ }
@@ -0,0 +1,74 @@
1
+ import { splitEvery, identity } from 'ramda'
2
+ import React from 'react'
3
+ import dayjs from 'dayjs'
4
+
5
+ import { CalendarNav } from '../../calendar/CalendarNav'
6
+ import { Col } from '../../structure/Col'
7
+ import { Link } from '../../actions/Link'
8
+ import { Row } from '../../structure/Row'
9
+ import { Text } from '../../text/Text'
10
+ import { View } from '../../structure/View'
11
+ import { WeekDaysBar } from '../../calendar/WeekDaysBar'
12
+ import { isDateDisabled } from '../../calendar/_helpers/dateDisabled'
13
+ import { useCalendarDays } from '../../calendar/_helpers/calendarDays'
14
+
15
+ export function WeekPicker({ value, onChange, min, max, onCheckDisabled, ...props }) {
16
+ const [localValue, setLocalValue] = React.useState(value)
17
+ value = value === undefined ? localValue : value
18
+
19
+ React.useEffect(() => {
20
+ setLocalValue(value)
21
+ }, [value?.day?.(), value?.month?.(), value?.year?.()])
22
+
23
+ const handleChange = (v) => {
24
+ const newValue = v.startOf('week')
25
+ setLocalValue(newValue)
26
+ onChange?.(newValue)
27
+ }
28
+
29
+ const [currentMonth, setCurrentMonth] = React.useState(() => dayjs(value).startOf('month'))
30
+
31
+ const { cells } = useCalendarDays(currentMonth)
32
+ const weeks = splitEvery(7, cells)
33
+
34
+ return (
35
+ <View className="neko-day-picker" width={275} {...props}>
36
+ <CalendarNav value={currentMonth} onChange={setCurrentMonth} />
37
+ <WeekDaysBar />
38
+
39
+ <View colSpan={24 / 7} gap="sm">
40
+ {weeks.map((week, wi) => {
41
+ const firstDay = week.find(identity)
42
+ const dateVal = currentMonth.date(firstDay)
43
+ const isActive = !!value && !!firstDay && dateVal.isSame(value, 'week')
44
+ const disabled = isDateDisabled(dateVal, { min, max, onCheckDisabled })
45
+
46
+ return (
47
+ <Link
48
+ key={firstDay ? dateVal.format('YYYYMMDD') : wi}
49
+ fullW
50
+ br="md"
51
+ onPress={() => !!firstDay && handleChange(dateVal)}
52
+ bg={isActive && 'primary'}
53
+ disabled={disabled}
54
+ >
55
+ <Row colSpan={24 / 7} gap="sm">
56
+ {week.map((day, i) => {
57
+ const dateVal = currentMonth.date(day)
58
+
59
+ return (
60
+ <Col key={day ? dateVal.format('YYYYMMDD') : i} className="day-cell" center ratio={1}>
61
+ <Text sm text2 center strong={isActive}>
62
+ {day || ''}
63
+ </Text>
64
+ </Col>
65
+ )
66
+ })}
67
+ </Row>
68
+ </Link>
69
+ )
70
+ })}
71
+ </View>
72
+ </View>
73
+ )
74
+ }