@ticatec/uniface-element 0.2.3 → 0.3.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/dist/accordion/README.md +169 -0
- package/dist/accordion/README_CN.md +176 -0
- package/dist/action-bar/README.md +275 -0
- package/dist/action-bar/README_CN.md +285 -0
- package/dist/app-layout/README.md +374 -0
- package/dist/app-layout/README_CN.md +381 -0
- package/dist/app-top-bar/README.md +357 -0
- package/dist/app-top-bar/README_CN.md +365 -0
- package/dist/attachment-files/AttachmentFilesField.svelte +67 -1
- package/dist/attachment-files/AttachmentFilesField.svelte.d.ts +8 -1
- package/dist/base-calendar/CalendarBase.svelte +0 -3
- package/dist/box/README.md +385 -0
- package/dist/box/README_CN.md +393 -0
- package/dist/breadcrumbs/README.md +442 -0
- package/dist/breadcrumbs/README_CN.md +442 -0
- package/dist/button/Button.svelte +27 -7
- package/dist/button/Button.svelte.d.ts +3 -1
- package/dist/button/IconButton.svelte +26 -6
- package/dist/button/IconButton.svelte.d.ts +3 -1
- package/dist/button/IconButton_README.md +513 -0
- package/dist/button/IconButton_README_CN.md +513 -0
- package/dist/button/README.md +428 -0
- package/dist/button/README_CN.md +428 -0
- package/dist/button/TextButton.svelte +26 -6
- package/dist/button/TextButton.svelte.d.ts +3 -1
- package/dist/button/TextButton_README.md +571 -0
- package/dist/button/TextButton_README_CN.md +571 -0
- package/dist/card/README.md +666 -0
- package/dist/card/README_CN.md +666 -0
- package/dist/cascade-options-select/CascadeOptionSelect.svelte +43 -7
- package/dist/cascade-options-select/CascadeOptionSelect.svelte.d.ts +3 -4
- package/dist/cascade-options-select/README.md +663 -2
- package/dist/cascade-options-select/README_CN.md +664 -0
- package/dist/checkbox/CheckBox.svelte +20 -6
- package/dist/checkbox/CheckBox.svelte.d.ts +4 -2
- package/dist/checkbox/README.md +562 -0
- package/dist/checkbox/README_CN.md +727 -0
- package/dist/common-editor/NumberInput.svelte +39 -26
- package/dist/common-editor/NumberInput.svelte.d.ts +5 -1
- package/dist/concise-data-table/ConciseListTable.svelte +133 -36
- package/dist/concise-data-table/ConciseListTable.svelte.d.ts +8 -1
- package/dist/concise-data-table/DataCell.svelte +5 -6
- package/dist/concise-data-table/DataRow.svelte +22 -2
- package/dist/concise-data-table/DataRow.svelte.d.ts +1 -0
- package/dist/concise-data-table/README.md +606 -0
- package/dist/concise-data-table/README_CN.md +611 -0
- package/dist/context-menu/ContextMenu.svelte +138 -21
- package/dist/context-menu/ContextMenu.svelte.d.ts +5 -0
- package/dist/context-menu/ContextMenuItem.d.ts +20 -4
- package/dist/context-menu/README.md +551 -0
- package/dist/context-menu/README_CN.md +551 -0
- package/dist/criteria-field/CriteriaField.svelte +3 -5
- package/dist/criteria-field/README.md +532 -0
- package/dist/criteria-field/README_CN.md +532 -0
- package/dist/data-table/README.md +712 -0
- package/dist/data-table/README_CN.md +712 -0
- package/dist/date-picker/DatePicker.svelte +44 -7
- package/dist/date-picker/DatePicker.svelte.d.ts +3 -4
- package/dist/date-picker/DateTimePicker.svelte +32 -8
- package/dist/date-picker/DateTimePicker.svelte.d.ts +3 -4
- package/dist/date-picker/README.md +326 -0
- package/dist/date-picker/README_CN.md +316 -0
- package/dist/date-picker/ScrollBar.svelte +18 -8
- package/dist/date-picker/ScrollBar.svelte.d.ts +1 -1
- package/dist/date-picker/TimePanel.svelte +5 -5
- package/dist/date-picker/TimePanel.svelte.d.ts +1 -1
- package/dist/date-range/README.md +374 -0
- package/dist/date-range/README_CN.md +374 -0
- package/dist/dialog/DialogBoard.svelte +1 -1
- package/dist/dialog/README.md +596 -0
- package/dist/dialog/README_CN.md +596 -0
- package/dist/drawer/README.md +679 -1
- package/dist/drawer/README_CN.md +679 -0
- package/dist/group-box/group-check-box/GroupCheckBox.svelte +62 -5
- package/dist/group-box/group-check-box/GroupCheckBox.svelte.d.ts +7 -2
- package/dist/group-box/group-check-box/README.md +749 -0
- package/dist/group-box/group-check-box/README_CN.md +750 -0
- package/dist/group-box/group-radio-box/GroupRadioBox.svelte +69 -4
- package/dist/group-box/group-radio-box/GroupRadioBox.svelte.d.ts +8 -2
- package/dist/group-box/group-radio-box/README.md +920 -0
- package/dist/group-box/group-radio-box/README_CN.md +920 -0
- package/dist/image-files/README.md +1346 -0
- package/dist/image-files/README_CN.md +1346 -0
- package/dist/input-options-select/InputOptionsSelect.svelte +161 -65
- package/dist/input-options-select/InputOptionsSelect.svelte.d.ts +4 -1
- package/dist/lib/forwardAllEvents.d.ts +3 -0
- package/dist/lib/forwardAllEvents.js +24 -0
- package/dist/list-box/README.md +579 -0
- package/dist/list-box/README_CN.md +682 -0
- package/dist/lookup-editor/LookupEditor.svelte +15 -3
- package/dist/lookup-editor/LookupEditor.svelte.d.ts +3 -4
- package/dist/lookup-editor/README.md +684 -0
- package/dist/lookup-editor/README_CN.md +684 -0
- package/dist/memo-editor/MemoEditor.svelte +77 -27
- package/dist/memo-editor/MemoEditor.svelte.d.ts +6 -3
- package/dist/memo-editor/README.md +819 -0
- package/dist/memo-editor/README_CN.md +819 -0
- package/dist/message-box/README.md +398 -0
- package/dist/message-box/README_CN.md +398 -0
- package/dist/number-editor/NumberEditor.svelte +2 -2
- package/dist/number-editor/NumberEditor.svelte.d.ts +1 -1
- package/dist/number-editor/README.md +353 -22
- package/dist/number-editor/README_CN.md +357 -0
- package/dist/number-range/README.md +443 -0
- package/dist/number-range/README_CN.md +443 -0
- package/dist/options-multi-select/OptionsMultiSelect.svelte +87 -12
- package/dist/options-multi-select/OptionsMultiSelect.svelte.d.ts +3 -1
- package/dist/options-multi-select/README.md +480 -0
- package/dist/options-multi-select/README_CN.md +480 -0
- package/dist/options-select/OptionsSelect.svelte +36 -5
- package/dist/options-select/OptionsSelect.svelte.d.ts +3 -4
- package/dist/options-select/README.md +632 -0
- package/dist/options-select/README_CN.md +632 -0
- package/dist/page/README.md +605 -0
- package/dist/page/README_CN.md +605 -0
- package/dist/pagination/README.md +946 -0
- package/dist/pagination/README_CN.md +946 -0
- package/dist/pagination-panel/README.md +1075 -0
- package/dist/pagination-panel/README_CN.md +1075 -0
- package/dist/popup-hint/README.md +841 -0
- package/dist/popup-hint/README_CN.md +840 -0
- package/dist/progress-bar/README.md +242 -0
- package/dist/progress-bar/README_CN.md +242 -0
- package/dist/progress-step-bar/README.md +316 -0
- package/dist/progress-step-bar/README_CN.md +316 -0
- package/dist/prompts-text-editor/PromptsTextEditor.svelte +6 -3
- package/dist/prompts-text-editor/PromptsTextEditor.svelte.d.ts +3 -1
- package/dist/prompts-text-editor/README.md +329 -0
- package/dist/prompts-text-editor/README_CN.md +329 -0
- package/dist/property-editor/README.md +969 -0
- package/dist/property-editor/README_CN.md +969 -0
- package/dist/radio-button/README.md +372 -0
- package/dist/radio-button/README_CN.md +372 -0
- package/dist/radio-button/RadioButton.svelte +32 -3
- package/dist/radio-button/RadioButton.svelte.d.ts +12 -1
- package/dist/search-box/README.md +425 -0
- package/dist/search-box/README_CN.md +424 -0
- package/dist/search-box/SearchBox.svelte +22 -6
- package/dist/search-box/SearchBox.svelte.d.ts +4 -1
- package/dist/tabs/README.md +919 -0
- package/dist/tabs/README_CN.md +920 -0
- package/dist/tag/README.md +922 -0
- package/dist/tag/README_CN.md +922 -0
- package/dist/text-editor/PasswordEditor.svelte +17 -2
- package/dist/text-editor/PasswordEditor.svelte.d.ts +3 -3
- package/dist/text-editor/PasswordEditor_README.md +551 -0
- package/dist/text-editor/PasswordEditor_README_CN.md +551 -0
- package/dist/text-editor/README.md +466 -0
- package/dist/text-editor/README_CN.md +466 -0
- package/dist/text-editor/TextEditor.svelte +51 -19
- package/dist/text-editor/TextEditor.svelte.d.ts +0 -1
- package/dist/ticatec-uniface-web.css +1 -0
- package/dist/time-editor/README.md +498 -24
- package/dist/time-editor/README_CN.md +498 -0
- package/dist/time-editor/TimeEditor.svelte +7 -3
- package/dist/time-editor/TimeEditor.svelte.d.ts +3 -1
- package/dist/toast/README.md +667 -0
- package/dist/toast/README_CN.md +667 -0
- package/dist/transfer/README.md +795 -0
- package/dist/transfer/Transfer.svelte +6 -4
- package/dist/transfer/Transfer.svelte.d.ts +3 -1
- package/dist/tree-view/README.md +761 -0
- package/dist/tree-view/README_CN.md +761 -0
- package/dist/tree-view/TreeView.svelte +5 -3
- package/dist/tree-view/TreeView.svelte.d.ts +3 -1
- package/dist/unit-number-editor/README.md +546 -20
- package/dist/unit-number-editor/README_CN.md +525 -0
- package/dist/unit-number-editor/UnitNumberEditor.svelte +62 -8
- package/dist/unit-number-editor/UnitNumberEditor.svelte.d.ts +5 -1
- package/docs/form-field/cn/README_CN.md +364 -0
- package/docs/form-field/en/README.md +364 -0
- package/docs/form-panel/flex-form/cn/README_CN.md +586 -0
- package/docs/form-panel/flex-form/en/README.md +586 -0
- package/docs/form-panel/flex-row-form/cn/README_CN.md +787 -0
- package/docs/form-panel/flex-row-form/en/README.md +787 -0
- package/docs/form-panel/grid-form/en/README.md +744 -0
- package/package.json +1 -1
- package/dist/drawer/README-CN.md +0 -1
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
# DateRangeEditor Component
|
|
2
|
+
|
|
3
|
+
A comprehensive date range selection component built with Svelte, providing an intuitive interface for selecting start and end dates with dual calendar popups.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Dual Calendar Interface**: Side-by-side calendars for from/to date selection
|
|
8
|
+
- **Smart Date Constraints**: Automatic min/max validation between start and end dates
|
|
9
|
+
- **Multiple Visual Variants**: Support for plain, outlined, filled, and compact styles
|
|
10
|
+
- **Readonly Input Fields**: Prevents manual text input, ensuring data integrity
|
|
11
|
+
- **Flexible Date Formatting**: Customizable date display format
|
|
12
|
+
- **Clear Functionality**: Easy range clearing with integrated clear button
|
|
13
|
+
- **Popup Management**: Click-outside-to-close behavior
|
|
14
|
+
- **Responsive Design**: Automatically sized popup container
|
|
15
|
+
- **Integration Ready**: Works seamlessly with form layouts
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @ticatec/uniface-element
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import DateRangeEditor from '@ticatec/uniface-element/DateRange';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or if using within the same project:
|
|
28
|
+
```typescript
|
|
29
|
+
import DateRangeEditor from '$lib/date-range';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Basic Usage
|
|
33
|
+
|
|
34
|
+
```svelte
|
|
35
|
+
<script>
|
|
36
|
+
import DateRangeEditor from '$lib/date-range';
|
|
37
|
+
|
|
38
|
+
let fromDate = null;
|
|
39
|
+
let toDate = null;
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<DateRangeEditor
|
|
43
|
+
bind:fromValue={fromDate}
|
|
44
|
+
bind:toValue={toDate}
|
|
45
|
+
placeholder="Select date range"
|
|
46
|
+
/>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Props
|
|
50
|
+
|
|
51
|
+
| Prop | Type | Default | Description |
|
|
52
|
+
|------|------|---------|-------------|
|
|
53
|
+
| `fromValue` | `UniDate` | `null` | Start date of the range |
|
|
54
|
+
| `toValue` | `UniDate` | `null` | End date of the range |
|
|
55
|
+
| `variant` | `'' \| 'plain' \| 'outlined' \| 'filled'` | `''` | Visual style variant |
|
|
56
|
+
| `compact` | `boolean` | `false` | Compact display mode |
|
|
57
|
+
| `style` | `string` | `''` | Custom CSS styles |
|
|
58
|
+
| `class` | `string` | `''` | Additional CSS classes |
|
|
59
|
+
| `format` | `string` | `'YYYY-MM-DD'` | Date display format |
|
|
60
|
+
| `min` | `string \| Date \| null` | `null` | Minimum selectable date |
|
|
61
|
+
| `max` | `string \| Date \| null` | `null` | Maximum selectable date |
|
|
62
|
+
|
|
63
|
+
## Examples
|
|
64
|
+
|
|
65
|
+
### Basic Date Range Selector
|
|
66
|
+
|
|
67
|
+
```svelte
|
|
68
|
+
<script>
|
|
69
|
+
import DateRangeEditor from '$lib/date-range';
|
|
70
|
+
|
|
71
|
+
let startDate = null;
|
|
72
|
+
let endDate = null;
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<DateRangeEditor
|
|
76
|
+
bind:fromValue={startDate}
|
|
77
|
+
bind:toValue={endDate}
|
|
78
|
+
/>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Outlined Date Range with Custom Format
|
|
82
|
+
|
|
83
|
+
```svelte
|
|
84
|
+
<DateRangeEditor
|
|
85
|
+
variant="outlined"
|
|
86
|
+
bind:fromValue={projectStart}
|
|
87
|
+
bind:toValue={projectEnd}
|
|
88
|
+
format="DD/MM/YYYY"
|
|
89
|
+
/>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Filled Compact Date Range
|
|
93
|
+
|
|
94
|
+
```svelte
|
|
95
|
+
<DateRangeEditor
|
|
96
|
+
variant="filled"
|
|
97
|
+
compact
|
|
98
|
+
bind:fromValue={reportFrom}
|
|
99
|
+
bind:toValue={reportTo}
|
|
100
|
+
/>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Date Range with Min/Max Constraints
|
|
104
|
+
|
|
105
|
+
```svelte
|
|
106
|
+
<script>
|
|
107
|
+
// Only allow dates within the current year
|
|
108
|
+
const currentYear = new Date().getFullYear();
|
|
109
|
+
const yearStart = new Date(currentYear, 0, 1);
|
|
110
|
+
const yearEnd = new Date(currentYear, 11, 31);
|
|
111
|
+
</script>
|
|
112
|
+
|
|
113
|
+
<DateRangeEditor
|
|
114
|
+
variant="outlined"
|
|
115
|
+
bind:fromValue={periodStart}
|
|
116
|
+
bind:toValue={periodEnd}
|
|
117
|
+
min={yearStart}
|
|
118
|
+
max={yearEnd}
|
|
119
|
+
/>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Custom Styled Date Range
|
|
123
|
+
|
|
124
|
+
```svelte
|
|
125
|
+
<DateRangeEditor
|
|
126
|
+
variant="filled"
|
|
127
|
+
style="width: 300px; margin: 10px;"
|
|
128
|
+
class="custom-date-range"
|
|
129
|
+
bind:fromValue={eventStart}
|
|
130
|
+
bind:toValue={eventEnd}
|
|
131
|
+
format="MMM DD, YYYY"
|
|
132
|
+
/>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Smart Date Validation
|
|
136
|
+
|
|
137
|
+
The component automatically enforces logical date constraints:
|
|
138
|
+
|
|
139
|
+
- **From Date Maximum**: Cannot exceed the selected "to" date or global `max` value
|
|
140
|
+
- **To Date Minimum**: Cannot be before the selected "from" date or global `min` value
|
|
141
|
+
- **Global Constraints**: Both dates respect the `min` and `max` props
|
|
142
|
+
|
|
143
|
+
```svelte
|
|
144
|
+
<script>
|
|
145
|
+
let checkIn = new Date('2024-01-15');
|
|
146
|
+
let checkOut = null; // Will be constrained to dates after checkIn
|
|
147
|
+
</script>
|
|
148
|
+
|
|
149
|
+
<DateRangeEditor
|
|
150
|
+
bind:fromValue={checkIn}
|
|
151
|
+
bind:toValue={checkOut}
|
|
152
|
+
min={new Date()} // No past dates allowed
|
|
153
|
+
/>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Date Formats
|
|
157
|
+
|
|
158
|
+
The `format` prop supports Day.js formatting tokens:
|
|
159
|
+
|
|
160
|
+
| Format | Example | Description |
|
|
161
|
+
|--------|---------|-------------|
|
|
162
|
+
| `YYYY-MM-DD` | 2024-03-15 | ISO format (default) |
|
|
163
|
+
| `DD/MM/YYYY` | 15/03/2024 | European format |
|
|
164
|
+
| `MM/DD/YYYY` | 03/15/2024 | US format |
|
|
165
|
+
| `MMM DD, YYYY` | Mar 15, 2024 | Long month name |
|
|
166
|
+
| `DD MMM YYYY` | 15 Mar 2024 | Day-month-year |
|
|
167
|
+
|
|
168
|
+
```svelte
|
|
169
|
+
<!-- Different format examples -->
|
|
170
|
+
<DateRangeEditor format="DD/MM/YYYY" bind:fromValue={start} bind:toValue={end} />
|
|
171
|
+
<DateRangeEditor format="MMM DD, YYYY" bind:fromValue={start} bind:toValue={end} />
|
|
172
|
+
<DateRangeEditor format="DD MMM YYYY" bind:fromValue={start} bind:toValue={end} />
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Calendar Interaction
|
|
176
|
+
|
|
177
|
+
### Dual Calendar Layout
|
|
178
|
+
|
|
179
|
+
The popup displays two side-by-side calendars:
|
|
180
|
+
- **Left Calendar**: For selecting the "from" date
|
|
181
|
+
- **Right Calendar**: For selecting the "to" date
|
|
182
|
+
- **Smart Constraints**: Each calendar respects the constraints based on the other's selection
|
|
183
|
+
|
|
184
|
+
### Selection Workflow
|
|
185
|
+
|
|
186
|
+
1. Click anywhere on the component to open the popup
|
|
187
|
+
2. Select start date from the left calendar
|
|
188
|
+
3. Select end date from the right calendar (automatically closes popup)
|
|
189
|
+
4. Use the clear button (×) to reset both dates
|
|
190
|
+
|
|
191
|
+
## Variants
|
|
192
|
+
|
|
193
|
+
### Default (`''`)
|
|
194
|
+
Basic styling with standard borders and backgrounds.
|
|
195
|
+
|
|
196
|
+
```svelte
|
|
197
|
+
<DateRangeEditor bind:fromValue={start} bind:toValue={end} />
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Plain (`'plain'`)
|
|
201
|
+
Minimal styling with reduced visual elements.
|
|
202
|
+
|
|
203
|
+
```svelte
|
|
204
|
+
<DateRangeEditor variant="plain" bind:fromValue={start} bind:toValue={end} />
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Outlined (`'outlined'`)
|
|
208
|
+
Prominent border styling for emphasis.
|
|
209
|
+
|
|
210
|
+
```svelte
|
|
211
|
+
<DateRangeEditor variant="outlined" bind:fromValue={start} bind:toValue={end} />
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Filled (`'filled'`)
|
|
215
|
+
Background-filled styling for better visual hierarchy.
|
|
216
|
+
|
|
217
|
+
```svelte
|
|
218
|
+
<DateRangeEditor variant="filled" bind:fromValue={start} bind:toValue={end} />
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Integration with Forms
|
|
222
|
+
|
|
223
|
+
The DateRangeEditor works seamlessly with form layouts and FormField components:
|
|
224
|
+
|
|
225
|
+
```svelte
|
|
226
|
+
<script>
|
|
227
|
+
import FormField from '$lib/form-field';
|
|
228
|
+
import DateRangeEditor from '$lib/date-range';
|
|
229
|
+
</script>
|
|
230
|
+
|
|
231
|
+
<FormField label="Project Duration">
|
|
232
|
+
<DateRangeEditor
|
|
233
|
+
variant="outlined"
|
|
234
|
+
bind:fromValue={projectStart}
|
|
235
|
+
bind:toValue={projectEnd}
|
|
236
|
+
/>
|
|
237
|
+
</FormField>
|
|
238
|
+
|
|
239
|
+
<FormField label="Reporting Period">
|
|
240
|
+
<DateRangeEditor
|
|
241
|
+
variant="filled"
|
|
242
|
+
format="MMM DD, YYYY"
|
|
243
|
+
bind:fromValue={reportStart}
|
|
244
|
+
bind:toValue={reportEnd}
|
|
245
|
+
/>
|
|
246
|
+
</FormField>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Styling
|
|
250
|
+
|
|
251
|
+
The component inherits styling from the Uniface design system and can be customized:
|
|
252
|
+
|
|
253
|
+
```css
|
|
254
|
+
.custom-date-range {
|
|
255
|
+
--uniface-inside-border-color: #e0e0e0;
|
|
256
|
+
--uniface-primary-color: #1976d2;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.uniface-range-editor {
|
|
260
|
+
/* Custom styling for the range editor */
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.date-popover {
|
|
264
|
+
/* Custom styling for the popup */
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Accessibility
|
|
269
|
+
|
|
270
|
+
- **Keyboard Navigation**: Tab through input fields and use Enter/Space to open popup
|
|
271
|
+
- **ARIA Support**: Proper labeling and descriptions for screen readers
|
|
272
|
+
- **Focus Management**: Logical focus flow and clear visual indicators
|
|
273
|
+
- **Readonly Inputs**: Prevents invalid manual input while maintaining accessibility
|
|
274
|
+
|
|
275
|
+
## Event Handling
|
|
276
|
+
|
|
277
|
+
```svelte
|
|
278
|
+
<script>
|
|
279
|
+
import DateRangeEditor from '$lib/date-range';
|
|
280
|
+
|
|
281
|
+
let fromDate = null;
|
|
282
|
+
let toDate = null;
|
|
283
|
+
|
|
284
|
+
// React to changes
|
|
285
|
+
$: if (fromDate && toDate) {
|
|
286
|
+
console.log('Date range selected:', fromDate, 'to', toDate);
|
|
287
|
+
calculateDateDifference();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function calculateDateDifference() {
|
|
291
|
+
if (fromDate && toDate) {
|
|
292
|
+
const diffTime = Math.abs(toDate - fromDate);
|
|
293
|
+
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
294
|
+
console.log(`Duration: ${diffDays} days`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
</script>
|
|
298
|
+
|
|
299
|
+
<DateRangeEditor
|
|
300
|
+
bind:fromValue={fromDate}
|
|
301
|
+
bind:toValue={toDate}
|
|
302
|
+
on:blur={() => console.log('Range editor lost focus')}
|
|
303
|
+
/>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Type Definitions
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
type UniDate = Date | dayjs.Dayjs | string | null;
|
|
310
|
+
|
|
311
|
+
interface DateRangeEditorProps {
|
|
312
|
+
fromValue: UniDate;
|
|
313
|
+
toValue: UniDate;
|
|
314
|
+
variant?: '' | 'plain' | 'outlined' | 'filled';
|
|
315
|
+
compact?: boolean;
|
|
316
|
+
style?: string;
|
|
317
|
+
class?: string;
|
|
318
|
+
format?: string;
|
|
319
|
+
min?: string | Date | null;
|
|
320
|
+
max?: string | Date | null;
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Common Use Cases
|
|
325
|
+
|
|
326
|
+
### Project Timeline Selection
|
|
327
|
+
```svelte
|
|
328
|
+
<DateRangeEditor
|
|
329
|
+
variant="outlined"
|
|
330
|
+
bind:fromValue={projectStart}
|
|
331
|
+
bind:toValue={projectEnd}
|
|
332
|
+
format="MMM DD, YYYY"
|
|
333
|
+
/>
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Booking Date Range
|
|
337
|
+
```svelte
|
|
338
|
+
<DateRangeEditor
|
|
339
|
+
variant="filled"
|
|
340
|
+
bind:fromValue={checkIn}
|
|
341
|
+
bind:toValue={checkOut}
|
|
342
|
+
min={new Date()} // No past dates
|
|
343
|
+
/>
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Report Period Filter
|
|
347
|
+
```svelte
|
|
348
|
+
<DateRangeEditor
|
|
349
|
+
compact
|
|
350
|
+
bind:fromValue={reportFrom}
|
|
351
|
+
bind:toValue={reportTo}
|
|
352
|
+
format="DD/MM/YYYY"
|
|
353
|
+
/>
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Event Duration
|
|
357
|
+
```svelte
|
|
358
|
+
<DateRangeEditor
|
|
359
|
+
variant="outlined"
|
|
360
|
+
bind:fromValue={eventStart}
|
|
361
|
+
bind:toValue={eventEnd}
|
|
362
|
+
min={new Date()}
|
|
363
|
+
max={new Date(Date.now() + 365 * 24 * 60 * 60 * 1000)} // Max 1 year ahead
|
|
364
|
+
/>
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Notes
|
|
368
|
+
|
|
369
|
+
- The component uses Day.js internally for date manipulation and formatting
|
|
370
|
+
- Input fields are readonly to prevent invalid manual entry
|
|
371
|
+
- Popup automatically positions itself to fit within the viewport
|
|
372
|
+
- Clear functionality is only shown when at least one date is selected
|
|
373
|
+
- Date constraints are enforced in real-time as selections are made
|
|
374
|
+
- The component maintains internal state for popup visibility and constraints
|