mertani-web-toolkit 0.1.47 → 0.1.48
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.
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
.date-picker-container {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
width: 100%;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.date-picker-container.date-picker-side {
|
|
8
|
+
flex-direction: row;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: 12px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.date-picker-label {
|
|
14
|
+
font-size: 14px;
|
|
15
|
+
font-weight: 400;
|
|
16
|
+
color: var(--color-text-primary);
|
|
17
|
+
margin-bottom: 4px;
|
|
18
|
+
display: block;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.date-picker-container.date-picker-side .date-picker-label {
|
|
22
|
+
margin-bottom: 0;
|
|
23
|
+
min-width: 120px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.date-picker-label.label-left {
|
|
27
|
+
text-align: left;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.date-picker-label.label-right {
|
|
31
|
+
text-align: right;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.label-required {
|
|
35
|
+
color: var(--color-text-error-ti);
|
|
36
|
+
margin-left: 4px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.label-subLabel {
|
|
40
|
+
font-weight: 400;
|
|
41
|
+
color: var(--color-text-tertiary);
|
|
42
|
+
margin-left: 4px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.date-picker-wrapper {
|
|
46
|
+
position: relative;
|
|
47
|
+
flex: 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.date-picker-trigger {
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: space-between;
|
|
54
|
+
width: 100%;
|
|
55
|
+
text-align: left;
|
|
56
|
+
background: var(--dp-bg);
|
|
57
|
+
border: 1px solid var(--dp-border);
|
|
58
|
+
border-radius: var(--dp-radius);
|
|
59
|
+
color: var(--dp-text);
|
|
60
|
+
box-shadow: var(--dp-shadow);
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
transition:
|
|
63
|
+
border-color 0.2s,
|
|
64
|
+
box-shadow 0.2s;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.date-picker-trigger:disabled {
|
|
68
|
+
cursor: not-allowed;
|
|
69
|
+
background: var(--color-bg-disabled);
|
|
70
|
+
opacity: 0.7;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.date-picker-trigger.is-focused:not(:disabled) {
|
|
74
|
+
border-color: var(--dp-accent);
|
|
75
|
+
box-shadow: 0 0 0 2px color-mix(in srgb, var(--dp-accent) 40%, transparent);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.date-picker-trigger.is-error:not(:disabled) {
|
|
79
|
+
border-color: var(--dp-error);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.date-picker-trigger.is-error.is-focused:not(:disabled) {
|
|
83
|
+
border-color: var(--dp-error);
|
|
84
|
+
box-shadow: 0 0 0 2px color-mix(in srgb, var(--dp-error) 40%, transparent);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.date-picker-trigger .placeholder {
|
|
88
|
+
color: var(--color-text-tertiary);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.date-picker-calendar {
|
|
92
|
+
position: absolute;
|
|
93
|
+
bottom: calc(100% + 4px);
|
|
94
|
+
right: 0;
|
|
95
|
+
z-index: 20;
|
|
96
|
+
background: var(--color-bg-surface);
|
|
97
|
+
border-radius: 8px;
|
|
98
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
|
|
99
|
+
width: 240px;
|
|
100
|
+
overflow: hidden;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.date-picker-calendar.placement-bottom {
|
|
104
|
+
bottom: auto;
|
|
105
|
+
top: calc(100% + 4px);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.calendar-head {
|
|
109
|
+
display: flex;
|
|
110
|
+
justify-content: space-between;
|
|
111
|
+
align-items: center;
|
|
112
|
+
padding: 0 8px;
|
|
113
|
+
height: 40px;
|
|
114
|
+
border-bottom: 1px solid var(--color-border-form);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.calendar-head p {
|
|
118
|
+
font-size: 0.875rem;
|
|
119
|
+
color: var(--color-text-primary);
|
|
120
|
+
font-weight: 500;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.nav-btn {
|
|
124
|
+
display: flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
justify-content: center;
|
|
127
|
+
width: 28px;
|
|
128
|
+
height: 28px;
|
|
129
|
+
border-radius: 4px;
|
|
130
|
+
color: var(--color-text-tertiary);
|
|
131
|
+
cursor: pointer;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.nav-btn:hover {
|
|
135
|
+
background: var(--color-bg-surface-hover, #f6f8fa);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.calendar-body {
|
|
139
|
+
padding: 8px 12px;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.date-grid {
|
|
143
|
+
display: grid;
|
|
144
|
+
grid-template-columns: repeat(7, 1fr);
|
|
145
|
+
gap: 2px;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.day-label {
|
|
149
|
+
font-size: 0.75rem;
|
|
150
|
+
color: var(--color-text-tertiary);
|
|
151
|
+
text-align: center;
|
|
152
|
+
padding: 4px 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.date-cell {
|
|
156
|
+
display: flex;
|
|
157
|
+
align-items: center;
|
|
158
|
+
justify-content: center;
|
|
159
|
+
width: 28px;
|
|
160
|
+
height: 28px;
|
|
161
|
+
font-size: 0.8rem;
|
|
162
|
+
border-radius: 4px;
|
|
163
|
+
color: var(--color-text-tertiary);
|
|
164
|
+
margin: auto;
|
|
165
|
+
cursor: pointer;
|
|
166
|
+
background: transparent;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.date-cell:hover:not(:disabled) {
|
|
170
|
+
background: var(--color-bg-surface-hover, #f6f8fa);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.date-cell.in-range {
|
|
174
|
+
color: var(--color-text-primary);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.date-cell.is-now {
|
|
178
|
+
border: 1px solid var(--dp-accent);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.date-cell.is-selected {
|
|
182
|
+
background: var(--dp-accent);
|
|
183
|
+
color: #fff;
|
|
184
|
+
font-weight: 500;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.date-cell.is-disabled {
|
|
188
|
+
opacity: 0.35;
|
|
189
|
+
cursor: not-allowed;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.goto-today {
|
|
193
|
+
width: 100%;
|
|
194
|
+
text-align: center;
|
|
195
|
+
line-height: 40px;
|
|
196
|
+
border-top: 1px solid var(--color-border-form);
|
|
197
|
+
font-size: 0.875rem;
|
|
198
|
+
font-weight: 500;
|
|
199
|
+
cursor: pointer;
|
|
200
|
+
color: var(--dp-accent);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.goto-today:hover {
|
|
204
|
+
background: var(--color-bg-surface-hover, #f6f8fa);
|
|
205
|
+
}
|
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Icon from '../../Icon/Icon.svelte';
|
|
3
|
+
import './DatePicker.css';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
// ===Styles===
|
|
7
|
+
// Label
|
|
8
|
+
labelColor?: string;
|
|
9
|
+
aligment?: 'side' | 'top';
|
|
10
|
+
position?: 'left' | 'right';
|
|
11
|
+
|
|
12
|
+
// Field
|
|
13
|
+
size?: 48 | 40 | 32;
|
|
14
|
+
backgroundColor?: string;
|
|
15
|
+
borderColor?: string;
|
|
16
|
+
accentColor?: string;
|
|
17
|
+
textColor?: string;
|
|
18
|
+
errorColor?: string;
|
|
19
|
+
borderRadius?: number;
|
|
20
|
+
boxShadow?: string;
|
|
21
|
+
|
|
22
|
+
// ===Properties===
|
|
23
|
+
// Data
|
|
24
|
+
id?: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
subLabel?: string;
|
|
27
|
+
value?: Date | string | null;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
locale?: 'id' | 'en';
|
|
30
|
+
minDate?: Date | string | null;
|
|
31
|
+
maxDate?: Date | string | null;
|
|
32
|
+
placement?: 'top' | 'bottom' | 'auto';
|
|
33
|
+
|
|
34
|
+
// Events
|
|
35
|
+
onSelect?: (value: Date) => void;
|
|
36
|
+
onChange?: (value: Date) => void;
|
|
37
|
+
|
|
38
|
+
// Validation
|
|
39
|
+
isMandatory?: boolean;
|
|
40
|
+
customValidation?: (value: Date | null) => string | null;
|
|
41
|
+
|
|
42
|
+
// Additional Actions
|
|
43
|
+
isLoading?: boolean;
|
|
44
|
+
isShow?: boolean;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
tooltip?: string;
|
|
47
|
+
|
|
48
|
+
// Any
|
|
49
|
+
class?: string;
|
|
50
|
+
style?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let {
|
|
54
|
+
// ===Styles===
|
|
55
|
+
// Label
|
|
56
|
+
labelColor = 'var(--color-text-primary)',
|
|
57
|
+
aligment = 'top',
|
|
58
|
+
position = 'left',
|
|
59
|
+
|
|
60
|
+
// Field
|
|
61
|
+
size = 40,
|
|
62
|
+
backgroundColor = 'var(--color-bg-surface)',
|
|
63
|
+
borderColor = 'var(--color-border-form)',
|
|
64
|
+
accentColor = 'var(--color-bg-act-primary)',
|
|
65
|
+
textColor = 'var(--color-text-primary)',
|
|
66
|
+
errorColor = 'var(--color-text-error-ti)',
|
|
67
|
+
borderRadius,
|
|
68
|
+
boxShadow = '',
|
|
69
|
+
|
|
70
|
+
// ===Properties===
|
|
71
|
+
// Data
|
|
72
|
+
id = '',
|
|
73
|
+
label = '',
|
|
74
|
+
subLabel = '',
|
|
75
|
+
value = $bindable<Date | string | null>(null),
|
|
76
|
+
placeholder = 'Pilih Tanggal',
|
|
77
|
+
locale = 'id',
|
|
78
|
+
minDate,
|
|
79
|
+
maxDate,
|
|
80
|
+
placement = 'auto',
|
|
81
|
+
|
|
82
|
+
// Events
|
|
83
|
+
onSelect,
|
|
84
|
+
onChange,
|
|
85
|
+
|
|
86
|
+
// Validation
|
|
87
|
+
isMandatory = false,
|
|
88
|
+
customValidation,
|
|
89
|
+
|
|
90
|
+
// Additional Actions
|
|
91
|
+
isLoading = false,
|
|
92
|
+
isShow = true,
|
|
93
|
+
disabled = false,
|
|
94
|
+
tooltip = '',
|
|
95
|
+
|
|
96
|
+
class: className = '',
|
|
97
|
+
style: customStyle = ''
|
|
98
|
+
}: Props = $props();
|
|
99
|
+
|
|
100
|
+
// ===== Config =====
|
|
101
|
+
const MONTH_LABELS = {
|
|
102
|
+
id: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des'],
|
|
103
|
+
en: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
104
|
+
};
|
|
105
|
+
const DAY_LABELS = {
|
|
106
|
+
id: ['Min', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
|
|
107
|
+
en: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
108
|
+
};
|
|
109
|
+
const TODAY_LABEL = { id: 'Hari ini', en: 'Today' };
|
|
110
|
+
|
|
111
|
+
// ===== Helpers =====
|
|
112
|
+
function parseValue(val: Date | string | null | undefined): Date | null {
|
|
113
|
+
if (!val) return null;
|
|
114
|
+
if (val instanceof Date) return isNaN(val.getTime()) ? null : val;
|
|
115
|
+
const parts = val.includes('-') ? val.split('-') : [];
|
|
116
|
+
if (parts.length !== 3) return null;
|
|
117
|
+
const isISO = parts[0].length === 4;
|
|
118
|
+
const [d, m, y] = isISO
|
|
119
|
+
? [parseInt(parts[2]), parseInt(parts[1]) - 1, parseInt(parts[0])]
|
|
120
|
+
: [parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2])];
|
|
121
|
+
const date = new Date(y, m, d);
|
|
122
|
+
return isNaN(date.getTime()) ? null : date;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function formatDisplay(date: Date): string {
|
|
126
|
+
const d = date.getDate().toString().padStart(2, '0');
|
|
127
|
+
const m = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
128
|
+
return `${d}-${m}-${date.getFullYear()}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function parseLimit(val?: Date | string | null): Date | null {
|
|
132
|
+
return val ? parseValue(val) : null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function isDateDisabled(date: Date): boolean {
|
|
136
|
+
const min = parseLimit(minDate);
|
|
137
|
+
const max = parseLimit(maxDate);
|
|
138
|
+
const d = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
139
|
+
if (min && d < new Date(min.getFullYear(), min.getMonth(), min.getDate())) return true;
|
|
140
|
+
if (max && d > new Date(max.getFullYear(), max.getMonth(), max.getDate())) return true;
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function validateInput(val: Date | string | null): string {
|
|
145
|
+
const parsed = parseValue(val);
|
|
146
|
+
if (customValidation) {
|
|
147
|
+
const customError = customValidation(parsed);
|
|
148
|
+
if (customError) return customError;
|
|
149
|
+
}
|
|
150
|
+
if (isMandatory && !parsed) return 'Field ini wajib diisi';
|
|
151
|
+
return '';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ===== State =====
|
|
155
|
+
const globalNow = new Date();
|
|
156
|
+
let show = $state(false);
|
|
157
|
+
let calendarDate = $state(new Date());
|
|
158
|
+
let selectedDate = $state<Date | null>(parseValue(value));
|
|
159
|
+
let wrapperEl: HTMLDivElement | null = $state(null);
|
|
160
|
+
let isFocused = $state(false);
|
|
161
|
+
let error = $state('');
|
|
162
|
+
|
|
163
|
+
const month = $derived(calendarDate.getMonth());
|
|
164
|
+
const year = $derived(calendarDate.getFullYear());
|
|
165
|
+
const displayValue = $derived(selectedDate ? formatDisplay(selectedDate) : null);
|
|
166
|
+
|
|
167
|
+
const sizeConfig = $derived(
|
|
168
|
+
{
|
|
169
|
+
48: {
|
|
170
|
+
height: '48px',
|
|
171
|
+
labelFontSize: '16px',
|
|
172
|
+
fontSize: '16px',
|
|
173
|
+
borderRadius: 8,
|
|
174
|
+
padding: '8px 12px'
|
|
175
|
+
},
|
|
176
|
+
40: {
|
|
177
|
+
height: '40px',
|
|
178
|
+
labelFontSize: '14px',
|
|
179
|
+
fontSize: '14px',
|
|
180
|
+
borderRadius: 8,
|
|
181
|
+
padding: '6px 12px'
|
|
182
|
+
},
|
|
183
|
+
32: {
|
|
184
|
+
height: '32px',
|
|
185
|
+
labelFontSize: '14px',
|
|
186
|
+
fontSize: '14px',
|
|
187
|
+
borderRadius: 6,
|
|
188
|
+
padding: '6px 10px'
|
|
189
|
+
}
|
|
190
|
+
}[size] ?? {
|
|
191
|
+
height: '40px',
|
|
192
|
+
labelFontSize: '14px',
|
|
193
|
+
fontSize: '14px',
|
|
194
|
+
borderRadius: 8,
|
|
195
|
+
padding: '6px 12px'
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const labelStyles = $derived(`font-size: ${sizeConfig.labelFontSize}; color: ${labelColor};`);
|
|
200
|
+
|
|
201
|
+
const containerStyles = $derived(
|
|
202
|
+
[
|
|
203
|
+
`--dp-accent: ${accentColor};`,
|
|
204
|
+
`--dp-error: ${errorColor};`,
|
|
205
|
+
`--dp-border: ${borderColor};`,
|
|
206
|
+
`--dp-text: ${textColor};`
|
|
207
|
+
].join(' ')
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const triggerStyles = $derived(() => {
|
|
211
|
+
const radius = borderRadius ?? sizeConfig.borderRadius;
|
|
212
|
+
const bg = disabled || isLoading ? 'var(--color-bg-disabled)' : backgroundColor;
|
|
213
|
+
const shadow = boxShadow ? boxShadow : 'none';
|
|
214
|
+
|
|
215
|
+
return [
|
|
216
|
+
`min-height: ${sizeConfig.height};`,
|
|
217
|
+
`padding: ${sizeConfig.padding};`,
|
|
218
|
+
`font-size: ${sizeConfig.fontSize};`,
|
|
219
|
+
`--dp-bg: ${bg};`,
|
|
220
|
+
`--dp-radius: ${radius}px;`,
|
|
221
|
+
`--dp-shadow: ${shadow};`,
|
|
222
|
+
customStyle
|
|
223
|
+
]
|
|
224
|
+
.filter(Boolean)
|
|
225
|
+
.join(' ');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Resolve placement
|
|
229
|
+
const resolvedPlacement = $derived(() => {
|
|
230
|
+
if (placement !== 'auto') return placement;
|
|
231
|
+
return 'top';
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
interface DateCell {
|
|
235
|
+
date: number;
|
|
236
|
+
month: number;
|
|
237
|
+
year: number;
|
|
238
|
+
isNow: boolean;
|
|
239
|
+
isSelected: boolean;
|
|
240
|
+
inRange: boolean;
|
|
241
|
+
isDisabled: boolean;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const dates = $derived(() => {
|
|
245
|
+
const cells: DateCell[] = [];
|
|
246
|
+
const cur = new Date(calendarDate.getFullYear(), calendarDate.getMonth(), 1);
|
|
247
|
+
if (cur.getDay() > 0) cur.setDate(cur.getDate() - cur.getDay());
|
|
248
|
+
|
|
249
|
+
for (let i = 0; i < 42; i++) {
|
|
250
|
+
cells.push({
|
|
251
|
+
date: cur.getDate(),
|
|
252
|
+
month: cur.getMonth(),
|
|
253
|
+
year: cur.getFullYear(),
|
|
254
|
+
isNow: cur.toDateString() === globalNow.toDateString(),
|
|
255
|
+
isSelected: selectedDate ? cur.toDateString() === selectedDate.toDateString() : false,
|
|
256
|
+
inRange: cur.getMonth() === calendarDate.getMonth(),
|
|
257
|
+
isDisabled: isDateDisabled(cur)
|
|
258
|
+
});
|
|
259
|
+
cur.setDate(cur.getDate() + 1);
|
|
260
|
+
}
|
|
261
|
+
return cells;
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Sync external value changes
|
|
265
|
+
$effect(() => {
|
|
266
|
+
const parsed = parseValue(value);
|
|
267
|
+
if (parsed) {
|
|
268
|
+
selectedDate = parsed;
|
|
269
|
+
calendarDate = new Date(parsed.getFullYear(), parsed.getMonth(), 1);
|
|
270
|
+
}
|
|
271
|
+
error = validateInput(value);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// ===== Actions =====
|
|
275
|
+
function selectDate(cell: DateCell) {
|
|
276
|
+
if (cell.isDisabled) return;
|
|
277
|
+
const newDate = new Date(cell.year, cell.month, cell.date);
|
|
278
|
+
selectedDate = newDate;
|
|
279
|
+
value = newDate;
|
|
280
|
+
onSelect?.(newDate);
|
|
281
|
+
onChange?.(newDate);
|
|
282
|
+
|
|
283
|
+
if (!cell.inRange) {
|
|
284
|
+
calendarDate = new Date(cell.year, cell.month, 1);
|
|
285
|
+
}
|
|
286
|
+
show = false;
|
|
287
|
+
error = validateInput(newDate);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function goToToday() {
|
|
291
|
+
calendarDate = new Date(globalNow.getFullYear(), globalNow.getMonth(), 1);
|
|
292
|
+
selectDate({
|
|
293
|
+
date: globalNow.getDate(),
|
|
294
|
+
month: globalNow.getMonth(),
|
|
295
|
+
year: globalNow.getFullYear(),
|
|
296
|
+
isNow: true,
|
|
297
|
+
isSelected: false,
|
|
298
|
+
inRange: true,
|
|
299
|
+
isDisabled: isDateDisabled(globalNow)
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function prevMonth() {
|
|
304
|
+
calendarDate = new Date(calendarDate.getFullYear(), calendarDate.getMonth() - 1, 1);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function nextMonth() {
|
|
308
|
+
calendarDate = new Date(calendarDate.getFullYear(), calendarDate.getMonth() + 1, 1);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function handleClickOutside(e: MouseEvent) {
|
|
312
|
+
if (wrapperEl && !wrapperEl.contains(e.target as Node)) {
|
|
313
|
+
show = false;
|
|
314
|
+
isFocused = false;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function handleFocus() {
|
|
319
|
+
isFocused = true;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function handleBlur() {
|
|
323
|
+
isFocused = false;
|
|
324
|
+
error = validateInput(value);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
$effect(() => {
|
|
328
|
+
if (show) {
|
|
329
|
+
setTimeout(() => document.addEventListener('click', handleClickOutside), 10);
|
|
330
|
+
} else {
|
|
331
|
+
document.removeEventListener('click', handleClickOutside);
|
|
332
|
+
}
|
|
333
|
+
return () => document.removeEventListener('click', handleClickOutside);
|
|
334
|
+
});
|
|
335
|
+
</script>
|
|
336
|
+
|
|
337
|
+
{#if isShow}
|
|
338
|
+
<div
|
|
339
|
+
class="date-picker-container {aligment === 'side' ? 'date-picker-side' : ''}"
|
|
340
|
+
bind:this={wrapperEl}
|
|
341
|
+
style={containerStyles}
|
|
342
|
+
>
|
|
343
|
+
{#if label}
|
|
344
|
+
<label
|
|
345
|
+
for={id}
|
|
346
|
+
class="date-picker-label"
|
|
347
|
+
class:label-left={position === 'left'}
|
|
348
|
+
class:label-right={position === 'right'}
|
|
349
|
+
style={labelStyles}
|
|
350
|
+
>
|
|
351
|
+
{label}
|
|
352
|
+
{#if subLabel}
|
|
353
|
+
<span class="label-subLabel">{subLabel}</span>
|
|
354
|
+
{/if}
|
|
355
|
+
{#if isMandatory}
|
|
356
|
+
<span class="label-required">*</span>
|
|
357
|
+
{/if}
|
|
358
|
+
</label>
|
|
359
|
+
{/if}
|
|
360
|
+
<div class="date-picker-wrapper">
|
|
361
|
+
<button
|
|
362
|
+
{id}
|
|
363
|
+
type="button"
|
|
364
|
+
class="date-picker-trigger {className} {error ? 'is-error' : ''} {isFocused
|
|
365
|
+
? 'is-focused'
|
|
366
|
+
: ''}"
|
|
367
|
+
style={triggerStyles()}
|
|
368
|
+
onclick={() => !disabled && !isLoading && (show = !show)}
|
|
369
|
+
onfocus={handleFocus}
|
|
370
|
+
onblur={handleBlur}
|
|
371
|
+
disabled={disabled || isLoading}
|
|
372
|
+
title={tooltip || ''}
|
|
373
|
+
>
|
|
374
|
+
<span class:placeholder={!displayValue}>
|
|
375
|
+
{displayValue ?? placeholder}
|
|
376
|
+
</span>
|
|
377
|
+
<Icon name="bs-calendar2-date" />
|
|
378
|
+
</button>
|
|
379
|
+
|
|
380
|
+
{#if show}
|
|
381
|
+
<div class="date-picker-calendar" class:placement-bottom={resolvedPlacement() === 'bottom'}>
|
|
382
|
+
<div class="calendar-head">
|
|
383
|
+
<button class="nav-btn" onclick={prevMonth}>
|
|
384
|
+
<Icon name="bs-chevron-left" />
|
|
385
|
+
</button>
|
|
386
|
+
<p>{MONTH_LABELS[locale][month]} {year}</p>
|
|
387
|
+
<button class="nav-btn" onclick={nextMonth}>
|
|
388
|
+
<Icon name="bs-chevron-right" />
|
|
389
|
+
</button>
|
|
390
|
+
</div>
|
|
391
|
+
|
|
392
|
+
<div class="calendar-body">
|
|
393
|
+
<div class="date-grid">
|
|
394
|
+
{#each DAY_LABELS[locale] as day}
|
|
395
|
+
<p class="day-label">{day}</p>
|
|
396
|
+
{/each}
|
|
397
|
+
{#each dates() as cell (cell.year + '-' + cell.month + '-' + cell.date)}
|
|
398
|
+
<button
|
|
399
|
+
class="date-cell"
|
|
400
|
+
class:is-now={cell.isNow}
|
|
401
|
+
class:is-selected={cell.isSelected}
|
|
402
|
+
class:in-range={cell.inRange}
|
|
403
|
+
class:is-disabled={cell.isDisabled}
|
|
404
|
+
onclick={() => selectDate(cell)}
|
|
405
|
+
disabled={cell.isDisabled}
|
|
406
|
+
>
|
|
407
|
+
{cell.date}
|
|
408
|
+
</button>
|
|
409
|
+
{/each}
|
|
410
|
+
</div>
|
|
411
|
+
</div>
|
|
412
|
+
|
|
413
|
+
<button class="goto-today" onclick={goToToday}>
|
|
414
|
+
{TODAY_LABEL[locale]}
|
|
415
|
+
</button>
|
|
416
|
+
</div>
|
|
417
|
+
{/if}
|
|
418
|
+
</div>
|
|
419
|
+
</div>
|
|
420
|
+
{/if}
|
|
421
|
+
|
|
422
|
+
<style>
|
|
423
|
+
.date-picker-container {
|
|
424
|
+
&.date-picker-side {
|
|
425
|
+
flex-direction: row;
|
|
426
|
+
align-items: center;
|
|
427
|
+
gap: 12px;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
.date-picker-calendar {
|
|
432
|
+
&.placement-bottom {
|
|
433
|
+
bottom: auto;
|
|
434
|
+
top: calc(100% + 4px);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.calendar-head {
|
|
439
|
+
display: flex;
|
|
440
|
+
justify-content: space-between;
|
|
441
|
+
align-items: center;
|
|
442
|
+
padding: 0 8px;
|
|
443
|
+
height: 40px;
|
|
444
|
+
border-bottom: 1px solid var(--color-border-form);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.calendar-head p {
|
|
448
|
+
&.is-selected {
|
|
449
|
+
background: var(--accent, #ffa000);
|
|
450
|
+
color: #fff;
|
|
451
|
+
font-weight: 500;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
&.is-disabled {
|
|
455
|
+
opacity: 0.35;
|
|
456
|
+
cursor: not-allowed;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
.goto-today {
|
|
461
|
+
width: 100%;
|
|
462
|
+
text-align: center;
|
|
463
|
+
line-height: 40px;
|
|
464
|
+
border-top: 1px solid #dee2e6;
|
|
465
|
+
font-size: 0.875rem;
|
|
466
|
+
font-weight: 500;
|
|
467
|
+
cursor: pointer;
|
|
468
|
+
|
|
469
|
+
&:hover {
|
|
470
|
+
background: #f6f8fa;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
</style>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import './DatePicker.css';
|
|
2
|
+
interface Props {
|
|
3
|
+
labelColor?: string;
|
|
4
|
+
aligment?: 'side' | 'top';
|
|
5
|
+
position?: 'left' | 'right';
|
|
6
|
+
size?: 48 | 40 | 32;
|
|
7
|
+
backgroundColor?: string;
|
|
8
|
+
borderColor?: string;
|
|
9
|
+
accentColor?: string;
|
|
10
|
+
textColor?: string;
|
|
11
|
+
errorColor?: string;
|
|
12
|
+
borderRadius?: number;
|
|
13
|
+
boxShadow?: string;
|
|
14
|
+
id?: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
subLabel?: string;
|
|
17
|
+
value?: Date | string | null;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
locale?: 'id' | 'en';
|
|
20
|
+
minDate?: Date | string | null;
|
|
21
|
+
maxDate?: Date | string | null;
|
|
22
|
+
placement?: 'top' | 'bottom' | 'auto';
|
|
23
|
+
onSelect?: (value: Date) => void;
|
|
24
|
+
onChange?: (value: Date) => void;
|
|
25
|
+
isMandatory?: boolean;
|
|
26
|
+
customValidation?: (value: Date | null) => string | null;
|
|
27
|
+
isLoading?: boolean;
|
|
28
|
+
isShow?: boolean;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
tooltip?: string;
|
|
31
|
+
class?: string;
|
|
32
|
+
style?: string;
|
|
33
|
+
}
|
|
34
|
+
declare const DatePicker: import("svelte").Component<Props, {}, "value">;
|
|
35
|
+
type DatePicker = ReturnType<typeof DatePicker>;
|
|
36
|
+
export default DatePicker;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,3 +18,4 @@ export { default as TablePagination } from './components/Table/TablePagination.s
|
|
|
18
18
|
export { default as Illustration } from './components/Illustration/Illustration.svelte';
|
|
19
19
|
export { default as IllustrationLibrary } from './components/Illustration/IllustrationLibrary.svelte';
|
|
20
20
|
export type { Column, DeviceStatus, TableAction } from './components/Table/types.js';
|
|
21
|
+
export { default as DatePicker } from './components/inputs/DatePicker/DatePicker.svelte';
|
package/dist/index.js
CHANGED
|
@@ -18,3 +18,4 @@ export { default as Tabs } from './components/Tabs/Tabs.svelte';
|
|
|
18
18
|
export { default as TablePagination } from './components/Table/TablePagination.svelte';
|
|
19
19
|
export { default as Illustration } from './components/Illustration/Illustration.svelte';
|
|
20
20
|
export { default as IllustrationLibrary } from './components/Illustration/IllustrationLibrary.svelte';
|
|
21
|
+
export { default as DatePicker } from './components/inputs/DatePicker/DatePicker.svelte';
|