@datability/8ui 1.0.0 → 1.1.0
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/.prettierrc +8 -0
- package/.vscode/extensions.json +6 -0
- package/README.md +1 -3
- package/declaration.d.ts +10 -0
- package/docker-compose.yml +20 -0
- package/eslint.config.js +23 -0
- package/{dist/index.html → index.html} +1 -2
- package/package.json +13 -14
- package/src/App.tsx +370 -0
- package/src/components/assets/closed.svg +4 -0
- package/src/components/assets/expand-arrow.svg +3 -0
- package/src/components/assets/visibility-off.svg +5 -0
- package/src/components/assets/visibility.svg +5 -0
- package/src/components/blackdrop/index.scss +16 -0
- package/src/components/blackdrop/index.tsx +18 -0
- package/src/components/blackdrop/index.type.ts +7 -0
- package/src/components/button/index.scss +40 -0
- package/src/components/button/index.tsx +44 -0
- package/src/components/button/index.type.ts +13 -0
- package/src/components/chip/index.scss +32 -0
- package/src/components/chip/index.tsx +39 -0
- package/src/components/chip/index.type.ts +12 -0
- package/src/components/context.tsx +26 -0
- package/src/components/divider/index.scss +4 -0
- package/src/components/divider/index.tsx +13 -0
- package/src/components/index.ts +62 -0
- package/src/components/input/extend.scss +19 -0
- package/src/components/input/input-auto-complete/index.scss +53 -0
- package/src/components/input/input-auto-complete/index.tsx +140 -0
- package/src/components/input/input-auto-complete/index.type.tsx +13 -0
- package/src/components/input/input-base/index.scss +14 -0
- package/src/components/input/input-base/index.tsx +39 -0
- package/src/components/input/input-base/index.type.tsx +13 -0
- package/src/components/input/input-basic/index.scss +9 -0
- package/src/components/input/input-basic/index.tsx +47 -0
- package/src/components/input/input-basic/index.type.tsx +8 -0
- package/src/components/input/input-checkbox/index.scss +30 -0
- package/src/components/input/input-checkbox/index.tsx +69 -0
- package/src/components/input/input-checkbox/index.type.tsx +11 -0
- package/src/components/input/input-date/index.scss +102 -0
- package/src/components/input/input-date/index.tsx +354 -0
- package/src/components/input/input-date/index.type.tsx +11 -0
- package/src/components/input/input-date-range/index.scss +101 -0
- package/src/components/input/input-date-range/index.tsx +284 -0
- package/src/components/input/input-date-range/index.type.tsx +11 -0
- package/src/components/input/input-date-time/index.scss +179 -0
- package/src/components/input/input-date-time/index.tsx +367 -0
- package/src/components/input/input-date-time/index.type.tsx +11 -0
- package/src/components/input/input-number/index.scss +9 -0
- package/src/components/input/input-number/index.tsx +118 -0
- package/src/components/input/input-number/index.type.tsx +11 -0
- package/src/components/input/input-password/index.scss +22 -0
- package/src/components/input/input-password/index.tsx +60 -0
- package/src/components/input/input-password/index.type.tsx +8 -0
- package/src/components/input/input-radio/index.scss +35 -0
- package/src/components/input/input-radio/index.tsx +72 -0
- package/src/components/input/input-radio/index.type.tsx +12 -0
- package/src/components/input/input-select/index.scss +81 -0
- package/src/components/input/input-select/index.tsx +113 -0
- package/src/components/input/input-select/index.type.tsx +15 -0
- package/src/components/input/input-switch/index.scss +84 -0
- package/src/components/input/input-switch/index.tsx +44 -0
- package/src/components/input/input-switch/index.type.tsx +4 -0
- package/src/components/input/input-textarea/index.scss +10 -0
- package/src/components/input/input-textarea/index.tsx +48 -0
- package/src/components/input/input-textarea/index.type.tsx +10 -0
- package/src/components/menu/index.scss +30 -0
- package/src/components/menu/index.tsx +136 -0
- package/src/components/menu/index.type.ts +8 -0
- package/src/components/modal/index.scss +33 -0
- package/src/components/modal/index.tsx +99 -0
- package/src/components/modal/index.type.tsx +8 -0
- package/src/index.scss +44 -0
- package/src/index.ts +62 -0
- package/src/logoDownload.svg +3 -0
- package/src/main.tsx +9 -0
- package/tsconfig.app.json +28 -0
- package/tsconfig.json +42 -0
- package/tsconfig.node.json +29 -0
- package/vite.config.d.ts +2 -0
- package/vite.config.ts +35 -0
- package/dist/assets/index-BYmsRLQS.js +0 -48
- package/dist/assets/index-QxCDX2bt.css +0 -1
- /package/{dist → public}/vite.svg +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Lib
|
|
2
|
+
import React from "react"
|
|
3
|
+
import { Controller, useFormContext } from "react-hook-form"
|
|
4
|
+
|
|
5
|
+
// Include in project
|
|
6
|
+
import "./index.scss"
|
|
7
|
+
import InputBase from "../input-base"
|
|
8
|
+
import type { PropsInputCheckbox } from "./index.type"
|
|
9
|
+
|
|
10
|
+
const InputCheckbox: React.FC<PropsInputCheckbox> = ({
|
|
11
|
+
name,
|
|
12
|
+
label,
|
|
13
|
+
disabled = false,
|
|
14
|
+
require = false,
|
|
15
|
+
fullWidth = false,
|
|
16
|
+
options,
|
|
17
|
+
}) => {
|
|
18
|
+
const { control } = useFormContext()
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Controller
|
|
22
|
+
name={name}
|
|
23
|
+
control={control}
|
|
24
|
+
render={({ field, fieldState }) => {
|
|
25
|
+
const value: (string | number)[] = field.value ?? []
|
|
26
|
+
const { onChange } = field
|
|
27
|
+
const { error, invalid } = fieldState
|
|
28
|
+
|
|
29
|
+
const toggleValue = (checkedValue: string | number) => {
|
|
30
|
+
if (value.includes(checkedValue)) {
|
|
31
|
+
onChange(value.filter((v) => v !== checkedValue))
|
|
32
|
+
} else {
|
|
33
|
+
onChange([...value, checkedValue])
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<InputBase
|
|
39
|
+
name={name}
|
|
40
|
+
label={label}
|
|
41
|
+
require={require}
|
|
42
|
+
fullWidth={fullWidth}
|
|
43
|
+
isInvalid={invalid}
|
|
44
|
+
errorMessage={error?.message}
|
|
45
|
+
>
|
|
46
|
+
<div className="DBui-wrapInputCheckboxList">
|
|
47
|
+
{options.map((data, index) => (
|
|
48
|
+
<div key={index} className="DBui-wrapInputCheckbox">
|
|
49
|
+
<input
|
|
50
|
+
className="DBui-inputCheckbox"
|
|
51
|
+
type="checkbox"
|
|
52
|
+
disabled={disabled}
|
|
53
|
+
checked={value.includes(data.value)}
|
|
54
|
+
onChange={() => toggleValue(data.value)}
|
|
55
|
+
/>
|
|
56
|
+
<p className="DBui-labelCheckbox" data-invalid={invalid}>
|
|
57
|
+
<small>{data.label}</small>
|
|
58
|
+
</p>
|
|
59
|
+
</div>
|
|
60
|
+
))}
|
|
61
|
+
</div>
|
|
62
|
+
</InputBase>
|
|
63
|
+
)
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default InputCheckbox
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
@import '../extend.scss';
|
|
2
|
+
|
|
3
|
+
.DBui-inputDate {
|
|
4
|
+
@extend .DBui-input;
|
|
5
|
+
height: 35px;
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
|
|
10
|
+
&[data-disabled='true'] {
|
|
11
|
+
@extend .DBui-disabled;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.DBui-clearIconInputDate {
|
|
15
|
+
width: 20px;
|
|
16
|
+
|
|
17
|
+
&[data-hidden='true'] {
|
|
18
|
+
display: none !important;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&:hover {
|
|
22
|
+
opacity: 0.8;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.DBui-inputDateWrapperCalendar {
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
gap: 0.3em;
|
|
31
|
+
padding: 2em 0;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
align-items: center;
|
|
34
|
+
|
|
35
|
+
.DBui-inputDateRowMonthYear,
|
|
36
|
+
.DBui-inputDateRowHeaderDay,
|
|
37
|
+
.DBui-inputDateRowDay {
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: row;
|
|
40
|
+
gap: 0.8em;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.DBui-inputDateRowMonthYear {
|
|
44
|
+
gap: 0.5em;
|
|
45
|
+
margin-left: 0.5em;
|
|
46
|
+
align-items: center;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.DBui-inputDateRowHeaderDay,
|
|
50
|
+
.DBui-inputDateRowDay {
|
|
51
|
+
|
|
52
|
+
.DBui-inputDateHeader,
|
|
53
|
+
.DBui-inputDateDay {
|
|
54
|
+
width: 30px;
|
|
55
|
+
height: 30px;
|
|
56
|
+
text-align: center;
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
justify-content: center;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.DBui-inputDateDay {
|
|
63
|
+
cursor: not-allowed;
|
|
64
|
+
|
|
65
|
+
&[data-hidden-hover='false'] {
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
|
|
68
|
+
&:hover {
|
|
69
|
+
background-color: #03287E;
|
|
70
|
+
border-radius: 100%;
|
|
71
|
+
color: #FFFFFF;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&[data-checked='true'] {
|
|
76
|
+
background-color: #03287E;
|
|
77
|
+
color: #FFFFFF;
|
|
78
|
+
border-radius: 100%;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.DBui-inputDateRowMonthYearSelected {
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
text-align: center;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.DBui-inputDateRowMonthYearOption {
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
padding: 0.5em 1em;
|
|
92
|
+
|
|
93
|
+
&:hover {
|
|
94
|
+
background-color: #03287E;
|
|
95
|
+
color: #FFFFFF;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&[data-checked='true'] {
|
|
99
|
+
background-color: #03287E;
|
|
100
|
+
color: #FFFFFF;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/* eslint-disable react-refresh/only-export-components */
|
|
2
|
+
// Lib
|
|
3
|
+
import React, { useEffect, useState } from "react"
|
|
4
|
+
import { Controller, useFormContext } from "react-hook-form"
|
|
5
|
+
|
|
6
|
+
// Images
|
|
7
|
+
import expandArrowSVG from "../../assets/expand-arrow.svg"
|
|
8
|
+
import closedSVG from "../../assets/closed.svg"
|
|
9
|
+
|
|
10
|
+
// Include in project
|
|
11
|
+
import "./index.scss"
|
|
12
|
+
import InputBase from "../input-base"
|
|
13
|
+
import type { PropsInputDate } from "./index.type"
|
|
14
|
+
import Menu from "../../menu"
|
|
15
|
+
import Modal from "../../modal"
|
|
16
|
+
import { createPortal } from "react-dom"
|
|
17
|
+
|
|
18
|
+
// 2025-09-01
|
|
19
|
+
const InputDate: React.FC<PropsInputDate> = ({
|
|
20
|
+
name,
|
|
21
|
+
label,
|
|
22
|
+
placeholder,
|
|
23
|
+
disabled = false,
|
|
24
|
+
require = false,
|
|
25
|
+
fullWidth = false,
|
|
26
|
+
isHideClearIcon = true,
|
|
27
|
+
minYear,
|
|
28
|
+
maxYear,
|
|
29
|
+
}) => {
|
|
30
|
+
const { control } = useFormContext()
|
|
31
|
+
|
|
32
|
+
const [showDay, setShowDay] = useState(getDateNow())
|
|
33
|
+
const [isOpenModal, setIsOpenModal] = useState(false)
|
|
34
|
+
|
|
35
|
+
const [mounted, setMounted] = useState(false)
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
setMounted(true)
|
|
38
|
+
return () => setMounted(false)
|
|
39
|
+
}, [])
|
|
40
|
+
|
|
41
|
+
const yearOption = generateYearOptions(minYear, maxYear)
|
|
42
|
+
const monthOption = generateMonthOptions()
|
|
43
|
+
|
|
44
|
+
const portalRoot =
|
|
45
|
+
(document.getElementById("root") as HTMLElement) ||
|
|
46
|
+
(document.getElementById("__next") as HTMLElement) ||
|
|
47
|
+
document.body
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Controller
|
|
51
|
+
name={name}
|
|
52
|
+
control={control}
|
|
53
|
+
render={({ field, fieldState }) => {
|
|
54
|
+
const value: string = field.value || ""
|
|
55
|
+
const { onChange } = field
|
|
56
|
+
const { invalid, error } = fieldState
|
|
57
|
+
|
|
58
|
+
// sync showDay เมื่อเปิด modal หรือค่าเปลี่ยน
|
|
59
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!isOpenModal) return
|
|
62
|
+
setShowDay(value || getDateNow())
|
|
63
|
+
}, [isOpenModal])
|
|
64
|
+
|
|
65
|
+
function CalendarRow({ year, month }: { year: number; month: string }) {
|
|
66
|
+
const days = getDaysInMonthWithWeekday(year, month)
|
|
67
|
+
|
|
68
|
+
const mapToThaiWeek = (dayIndex: number) => dayIndex % 7
|
|
69
|
+
const firstDayThaiIndex = mapToThaiWeek(new Date(`${year}-${month}-01`).getDay())
|
|
70
|
+
const emptyStartDays = Array(firstDayThaiIndex).fill(null)
|
|
71
|
+
|
|
72
|
+
const allDays = [...emptyStartDays, ...days.map((d) => d.date.split("-")[2])]
|
|
73
|
+
|
|
74
|
+
while (allDays.length < 42) allDays.push(null)
|
|
75
|
+
|
|
76
|
+
const weeks: Array<Array<string | null>> = []
|
|
77
|
+
for (let i = 0; i < allDays.length; i += 7) weeks.push(allDays.slice(i, i + 7))
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<>
|
|
81
|
+
{weeks.map((week, rowIndex) => (
|
|
82
|
+
<div key={rowIndex} className="DBui-inputDateRowDay">
|
|
83
|
+
{week.map((day, i) => (
|
|
84
|
+
<p
|
|
85
|
+
key={i}
|
|
86
|
+
className="DBui-inputDateDay"
|
|
87
|
+
onClick={() => {
|
|
88
|
+
if (!day) return
|
|
89
|
+
const next = `${getYearInDateString(showDay)}-${getMonthInDateString(showDay)}-${day}`
|
|
90
|
+
onChange(next)
|
|
91
|
+
setIsOpenModal(false)
|
|
92
|
+
}}
|
|
93
|
+
data-checked={
|
|
94
|
+
`${getYearInDateString(value || showDay)}-${getMonthInDateString(value || showDay)}-${getDayInDateString(
|
|
95
|
+
value || showDay,
|
|
96
|
+
)}` === `${getYearInDateString(showDay)}-${getMonthInDateString(showDay)}-${day}`
|
|
97
|
+
}
|
|
98
|
+
data-hidden-hover={!day}
|
|
99
|
+
>
|
|
100
|
+
{day || ""}
|
|
101
|
+
</p>
|
|
102
|
+
))}
|
|
103
|
+
</div>
|
|
104
|
+
))}
|
|
105
|
+
</>
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const handleClear = (e: React.MouseEvent<HTMLImageElement>) => {
|
|
110
|
+
e.stopPropagation()
|
|
111
|
+
onChange("")
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<InputBase
|
|
116
|
+
name={name}
|
|
117
|
+
label={label}
|
|
118
|
+
require={require}
|
|
119
|
+
fullWidth={fullWidth}
|
|
120
|
+
isInvalid={invalid}
|
|
121
|
+
errorMessage={error?.message}
|
|
122
|
+
>
|
|
123
|
+
<>
|
|
124
|
+
<div
|
|
125
|
+
className="DBui-inputDate"
|
|
126
|
+
onClick={() => (disabled ? null : setIsOpenModal(true))}
|
|
127
|
+
data-invalid={invalid}
|
|
128
|
+
data-disabled={disabled}
|
|
129
|
+
>
|
|
130
|
+
<p>{value ? value : placeholder}</p>
|
|
131
|
+
|
|
132
|
+
<img
|
|
133
|
+
src={closedSVG}
|
|
134
|
+
className="DBui-clearIconInputDate"
|
|
135
|
+
onClick={handleClear}
|
|
136
|
+
data-hidden={value === "" || disabled || isHideClearIcon}
|
|
137
|
+
/>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
{mounted &&
|
|
141
|
+
createPortal(
|
|
142
|
+
<Modal id="modalInputDate" open={isOpenModal} onClose={() => setIsOpenModal(false)}>
|
|
143
|
+
<div className="DBui-inputDateWrapperCalendar">
|
|
144
|
+
<div className="DBui-inputDateRowMonthYear">
|
|
145
|
+
<img
|
|
146
|
+
src={expandArrowSVG}
|
|
147
|
+
className="DBui-inputDateRowMonthYearSelected"
|
|
148
|
+
style={{ transform: "rotate(90deg)" }}
|
|
149
|
+
onClick={() => {
|
|
150
|
+
setShowDay(
|
|
151
|
+
updateMonthInDateString(
|
|
152
|
+
showDay,
|
|
153
|
+
String(Number(showDay.split("-")[1]) - 1).padStart(2, "0"),
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
}}
|
|
157
|
+
/>
|
|
158
|
+
|
|
159
|
+
<Menu
|
|
160
|
+
isInModal
|
|
161
|
+
trigger={() => <h4 className="DBui-inputDateRowMonthYearSelected">{showDay.slice(0, 4)}</h4>}
|
|
162
|
+
>
|
|
163
|
+
{({ close }) =>
|
|
164
|
+
yearOption.map((y, index) => (
|
|
165
|
+
<p
|
|
166
|
+
key={index}
|
|
167
|
+
className="DBui-inputDateRowMonthYearOption"
|
|
168
|
+
onClick={() => {
|
|
169
|
+
setShowDay(updateYearInDateString(showDay, y.value))
|
|
170
|
+
close()
|
|
171
|
+
}}
|
|
172
|
+
data-checked={getYearInDateString(showDay) === y.value}
|
|
173
|
+
>
|
|
174
|
+
{y.label}
|
|
175
|
+
</p>
|
|
176
|
+
))
|
|
177
|
+
}
|
|
178
|
+
</Menu>
|
|
179
|
+
|
|
180
|
+
<Menu
|
|
181
|
+
isInModal
|
|
182
|
+
trigger={() => (
|
|
183
|
+
<h4 className="DBui-inputDateRowMonthYearSelected" style={{ width: "7rem" }}>
|
|
184
|
+
{monthOption.find((e) => e.value === showDay.slice(5, 7))?.label}
|
|
185
|
+
</h4>
|
|
186
|
+
)}
|
|
187
|
+
>
|
|
188
|
+
{({ close }) =>
|
|
189
|
+
monthOption.map((m, index) => (
|
|
190
|
+
<p
|
|
191
|
+
key={index}
|
|
192
|
+
className="DBui-inputDateRowMonthYearOption"
|
|
193
|
+
onClick={() => {
|
|
194
|
+
setShowDay(updateMonthInDateString(showDay, m.value))
|
|
195
|
+
close()
|
|
196
|
+
}}
|
|
197
|
+
data-checked={getMonthInDateString(showDay) === m.value}
|
|
198
|
+
>
|
|
199
|
+
{m.label}
|
|
200
|
+
</p>
|
|
201
|
+
))
|
|
202
|
+
}
|
|
203
|
+
</Menu>
|
|
204
|
+
|
|
205
|
+
<img
|
|
206
|
+
src={expandArrowSVG}
|
|
207
|
+
className="DBui-inputDateRowMonthYearSelected"
|
|
208
|
+
style={{ transform: "rotate(-90deg)" }}
|
|
209
|
+
onClick={() => {
|
|
210
|
+
setShowDay(
|
|
211
|
+
updateMonthInDateString(
|
|
212
|
+
showDay,
|
|
213
|
+
String(Number(showDay.split("-")[1]) + 1).padStart(2, "0"),
|
|
214
|
+
),
|
|
215
|
+
)
|
|
216
|
+
}}
|
|
217
|
+
/>
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
<div>
|
|
221
|
+
<div className="DBui-inputDateRowHeaderDay">
|
|
222
|
+
<p className="DBui-inputDateHeader">Sun</p>
|
|
223
|
+
<p className="DBui-inputDateHeader">Mon</p>
|
|
224
|
+
<p className="DBui-inputDateHeader">Tue</p>
|
|
225
|
+
<p className="DBui-inputDateHeader">Wed</p>
|
|
226
|
+
<p className="DBui-inputDateHeader">Thu</p>
|
|
227
|
+
<p className="DBui-inputDateHeader">Fri</p>
|
|
228
|
+
<p className="DBui-inputDateHeader">Sat</p>
|
|
229
|
+
</div>
|
|
230
|
+
|
|
231
|
+
<CalendarRow year={getYearInDateString(showDay)} month={getMonthInDateString(showDay)} />
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
</Modal>,
|
|
235
|
+
portalRoot,
|
|
236
|
+
)}
|
|
237
|
+
{!mounted && (
|
|
238
|
+
<Modal id="modalInputDate" open={isOpenModal} onClose={() => setIsOpenModal(false)}>
|
|
239
|
+
<div className="DBui-inputDateWrapperCalendar"></div>
|
|
240
|
+
</Modal>
|
|
241
|
+
)}
|
|
242
|
+
</>
|
|
243
|
+
</InputBase>
|
|
244
|
+
)
|
|
245
|
+
}}
|
|
246
|
+
/>
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export default InputDate
|
|
251
|
+
|
|
252
|
+
export function generateYearOptions(minYear?: number, maxYear?: number): { label: string; value: number }[] {
|
|
253
|
+
const currentYear = new Date().getFullYear()
|
|
254
|
+
|
|
255
|
+
// Default values ถ้าไม่ส่งมา
|
|
256
|
+
const finalMax = maxYear ?? currentYear
|
|
257
|
+
const finalMin = minYear ?? currentYear - 100
|
|
258
|
+
|
|
259
|
+
const years = []
|
|
260
|
+
|
|
261
|
+
// ไล่ปีแบบมาก -> น้อย
|
|
262
|
+
for (let year = finalMax; year >= finalMin; year--) {
|
|
263
|
+
years.push({ label: String(year), value: year })
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return years
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function generateMonthOptions(): { label: string; value: string }[] {
|
|
270
|
+
const monthNames = [
|
|
271
|
+
"January",
|
|
272
|
+
"February",
|
|
273
|
+
"March",
|
|
274
|
+
"April",
|
|
275
|
+
"May",
|
|
276
|
+
"June",
|
|
277
|
+
"July",
|
|
278
|
+
"August",
|
|
279
|
+
"September",
|
|
280
|
+
"October",
|
|
281
|
+
"November",
|
|
282
|
+
"December",
|
|
283
|
+
]
|
|
284
|
+
|
|
285
|
+
return monthNames.map((name, index) => ({
|
|
286
|
+
label: name,
|
|
287
|
+
value: String(index + 1).padStart(2, "0"),
|
|
288
|
+
}))
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function updateYearInDateString(dateStr: string, newYear: number): string {
|
|
292
|
+
const newDateStr = dateStr ? dateStr : new Date().toISOString().split("T")[0]
|
|
293
|
+
const [, month, day] = newDateStr.split("-")
|
|
294
|
+
|
|
295
|
+
return `${newYear}-${month}-${day}`
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export function updateMonthInDateString(dateStr: string, newMonth: string): string {
|
|
299
|
+
const newDateStr = dateStr || new Date().toISOString().split("T")[0]
|
|
300
|
+
const [yearStr, , dayStr] = newDateStr.split("-")
|
|
301
|
+
|
|
302
|
+
let year = parseInt(yearStr, 10)
|
|
303
|
+
let month = parseInt(newMonth, 10)
|
|
304
|
+
|
|
305
|
+
// Handle overflow/underflow
|
|
306
|
+
year += Math.floor((month - 1) / 12)
|
|
307
|
+
month = ((((month - 1) % 12) + 12) % 12) + 1 // Wrap to 1–12
|
|
308
|
+
|
|
309
|
+
const monthStr = String(month).padStart(2, "0")
|
|
310
|
+
return `${year}-${monthStr}-${dayStr}`
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export function getYearInDateString(dateStr: string): number {
|
|
314
|
+
const [year] = dateStr.split("-")
|
|
315
|
+
return Number(year)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export function getMonthInDateString(dateStr: string): string {
|
|
319
|
+
const [, month] = dateStr.split("-")
|
|
320
|
+
return month
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export function getDayInDateString(dateStr: string): string {
|
|
324
|
+
const [, , day] = dateStr.split("-")
|
|
325
|
+
return day
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function getDaysInMonthWithWeekday(year: number, month: string): { date: string; weekday: string }[] {
|
|
329
|
+
const days: { date: string; weekday: string }[] = []
|
|
330
|
+
const monthIndex = parseInt(month, 10) - 1 // JavaScript months are 0-based
|
|
331
|
+
|
|
332
|
+
const date = new Date(year, monthIndex, 1)
|
|
333
|
+
const weekdayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
|
|
334
|
+
|
|
335
|
+
while (date.getMonth() === monthIndex) {
|
|
336
|
+
const day = String(date.getDate()).padStart(2, "0")
|
|
337
|
+
const weekday = weekdayNames[date.getDay()]
|
|
338
|
+
const formattedDate = `${year}-${month}-${day}`
|
|
339
|
+
|
|
340
|
+
days.push({ date: formattedDate, weekday })
|
|
341
|
+
date.setDate(date.getDate() + 1)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return days
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function getDateNow(): string {
|
|
348
|
+
const dateNow = new Date()
|
|
349
|
+
|
|
350
|
+
const year = dateNow.getFullYear()
|
|
351
|
+
const month = `${dateNow.getMonth() + 1}`.padStart(2, "0")
|
|
352
|
+
const date = `${dateNow.getDate()}`.padStart(2, "0")
|
|
353
|
+
return `${year}-${month}-${date}`
|
|
354
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
@import '../extend.scss';
|
|
2
|
+
|
|
3
|
+
.DBui-inputDateRange {
|
|
4
|
+
@extend .DBui-input;
|
|
5
|
+
height: 35px;
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
|
|
10
|
+
&[data-disabled='true'] {
|
|
11
|
+
@extend .DBui-disabled;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.DBui-clearIconInputDateRange {
|
|
15
|
+
width: 20px;
|
|
16
|
+
|
|
17
|
+
&[data-hidden='true'] {
|
|
18
|
+
display: none !important;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&:hover {
|
|
22
|
+
opacity: 0.8;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.DBui-inputDateRangeWrapperCalendar {
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
gap: 0.3em;
|
|
31
|
+
padding: 2em 0;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
align-items: center;
|
|
34
|
+
|
|
35
|
+
.DBui-inputDateRangeRowMonthYear,
|
|
36
|
+
.DBui-inputDateRangeRowHeaderDay,
|
|
37
|
+
.DBui-inputDateRangeRowDay {
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: row;
|
|
40
|
+
gap: 0.8em;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.DBui-inputDateRangeRowMonthYear {
|
|
44
|
+
gap: 0.5em;
|
|
45
|
+
margin-left: 0.5em;
|
|
46
|
+
align-items: center;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.DBui-inputDateRangeRowHeaderDay,
|
|
50
|
+
.DBui-inputDateRangeRowDay {
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
|
|
53
|
+
.DBui-inputDateRangeHeader,
|
|
54
|
+
.DBui-inputDateRangeDay {
|
|
55
|
+
width: 30px;
|
|
56
|
+
height: 30px;
|
|
57
|
+
text-align: center;
|
|
58
|
+
display: flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.DBui-inputDateRangeDay {
|
|
64
|
+
|
|
65
|
+
&[data-hidden-hover='false'] {
|
|
66
|
+
|
|
67
|
+
&:hover {
|
|
68
|
+
background-color: #03287E;
|
|
69
|
+
border-radius: 100%;
|
|
70
|
+
color: #FFFFFF;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&[data-checked='true'] {
|
|
75
|
+
background-color: #03287E;
|
|
76
|
+
color: #FFFFFF;
|
|
77
|
+
border-radius: 100%;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.DBui-inputDateRangeRowMonthYearSelected {
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
text-align: center;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.DBui-inputDateRangeRowMonthYearOption {
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
padding: 0.5em 1em;
|
|
91
|
+
|
|
92
|
+
&:hover {
|
|
93
|
+
background-color: #03287E;
|
|
94
|
+
color: #FFFFFF;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&[data-checked='true'] {
|
|
98
|
+
background-color: #03287E;
|
|
99
|
+
color: #FFFFFF;
|
|
100
|
+
}
|
|
101
|
+
}
|