@keenmate/web-daterangepicker 1.0.0-rc01
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/README.md +197 -0
- package/dist/date-range-picker.js +1768 -0
- package/dist/date-range-picker.umd.js +26 -0
- package/dist/style.css +1 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Date Range Picker Web Component
|
|
2
|
+
|
|
3
|
+
A lightweight, accessible date picker web component with excellent keyboard navigation and range selection support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 **Input Masking** - Auto-format dates as you type with separator insertion
|
|
8
|
+
- ⌨️ **Keyboard Navigation** - Full keyboard support (arrows, Enter, Esc, PageUp/Down, Home/End)
|
|
9
|
+
- 📅 **Rolling Selector** - Innovative scrollable year/month picker
|
|
10
|
+
- 📊 **Multi-Month Display** - Show 1-3+ months side by side with independent navigation
|
|
11
|
+
- 🎨 **Themeable** - All styles use CSS custom properties (`--drp-*`)
|
|
12
|
+
- 🖱️ **Drag-to-Adjust** - Drag range endpoints to adjust selection (range mode)
|
|
13
|
+
- 🌐 **Multiple Formats** - YYYY-MM-DD, DD.MM.YYYY, MM/DD/YYYY, etc.
|
|
14
|
+
- ✨ **Modern** - Web Component with Shadow DOM, TypeScript, bundled with Vite
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @keenmate/web-daterangepicker
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Basic HTML
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<!-- Single date picker -->
|
|
28
|
+
<date-range-picker
|
|
29
|
+
mode="single"
|
|
30
|
+
format="YYYY-MM-DD"
|
|
31
|
+
placeholder="Select date"
|
|
32
|
+
></date-range-picker>
|
|
33
|
+
|
|
34
|
+
<!-- Date range picker -->
|
|
35
|
+
<date-range-picker
|
|
36
|
+
mode="range"
|
|
37
|
+
format="YYYY-MM-DD"
|
|
38
|
+
months-to-show="2"
|
|
39
|
+
placeholder="Select date range"
|
|
40
|
+
></date-range-picker>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### With JavaScript/TypeScript
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// Import the component (includes styles)
|
|
47
|
+
import '@keenmate/web-daterangepicker';
|
|
48
|
+
|
|
49
|
+
// Or import styles separately if needed
|
|
50
|
+
import '@keenmate/web-daterangepicker/style.css';
|
|
51
|
+
|
|
52
|
+
const picker = document.querySelector('date-range-picker');
|
|
53
|
+
|
|
54
|
+
// Listen for date selection
|
|
55
|
+
picker.addEventListener('date-select', (e) => {
|
|
56
|
+
console.log('Selected:', e.detail.formattedValue);
|
|
57
|
+
console.log('Date object:', e.detail.date);
|
|
58
|
+
console.log('Range:', e.detail.dateRange);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Programmatic API
|
|
62
|
+
picker.show(); // Show calendar
|
|
63
|
+
picker.hide(); // Hide calendar
|
|
64
|
+
picker.toggle(); // Toggle calendar
|
|
65
|
+
picker.clear(); // Clear selection
|
|
66
|
+
picker.getValue(); // Get current value
|
|
67
|
+
picker.setValue('2025-11-15'); // Set value
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Attributes
|
|
71
|
+
|
|
72
|
+
| Attribute | Type | Default | Description |
|
|
73
|
+
|-----------|------|---------|-------------|
|
|
74
|
+
| `mode` | `'single' \| 'range'` | `'single'` | Single date or date range selection |
|
|
75
|
+
| `format` | `string` | `'YYYY-MM-DD'` | Date format (YYYY-MM-DD, DD.MM.YYYY, MM/DD/YYYY, etc.) |
|
|
76
|
+
| `months-to-show` | `number` | `1` (single), `2` (range) | Number of months to display |
|
|
77
|
+
| `trigger` | `'auto' \| 'button'` | `'auto'` | How to open calendar (auto = click/focus, button = button only) |
|
|
78
|
+
| `value` | `string` | - | Current value |
|
|
79
|
+
| `placeholder` | `string` | - | Input placeholder text |
|
|
80
|
+
| `disabled` | `boolean` | `false` | Disable the picker |
|
|
81
|
+
|
|
82
|
+
## Properties
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// Get/set properties
|
|
86
|
+
picker.mode = 'range';
|
|
87
|
+
picker.format = 'DD.MM.YYYY';
|
|
88
|
+
picker.value = '2025-11-15';
|
|
89
|
+
picker.disabled = true;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Methods
|
|
93
|
+
|
|
94
|
+
| Method | Description |
|
|
95
|
+
|--------|-------------|
|
|
96
|
+
| `show()` | Show the calendar |
|
|
97
|
+
| `hide()` | Hide the calendar |
|
|
98
|
+
| `toggle()` | Toggle calendar visibility |
|
|
99
|
+
| `clear()` | Clear the current selection |
|
|
100
|
+
| `getValue()` | Get the current value as a string |
|
|
101
|
+
| `setValue(value: string)` | Set the value |
|
|
102
|
+
|
|
103
|
+
## Events
|
|
104
|
+
|
|
105
|
+
| Event | Detail | Description |
|
|
106
|
+
|-------|--------|-------------|
|
|
107
|
+
| `date-select` | `{ date?, dateRange?, formattedValue }` | Fired when a date is selected |
|
|
108
|
+
| `change` | `{ date?, dateRange?, formattedValue }` | Fired when selection changes |
|
|
109
|
+
|
|
110
|
+
## Keyboard Shortcuts
|
|
111
|
+
|
|
112
|
+
- **↑ ↓** - Navigate up/down by week
|
|
113
|
+
- **← →** - Navigate left/right by day
|
|
114
|
+
- **Ctrl+← / Ctrl+→** - Previous / next month (maintains day position)
|
|
115
|
+
- **PageUp / PageDown** - Previous / next month (maintains day position)
|
|
116
|
+
- **Home** - First day of current month (repeat to cycle backwards through months)
|
|
117
|
+
- **End** - Last day of current month (repeat to cycle forwards through months)
|
|
118
|
+
- **Ctrl+Home** - January 1st of current year (repeat for previous year)
|
|
119
|
+
- **Ctrl+End** - December 31st of current year (repeat for next year)
|
|
120
|
+
- **Enter** - Select focused day
|
|
121
|
+
- **Escape** - Close calendar
|
|
122
|
+
- **Tab / Shift+Tab** - Switch between month columns (multi-month mode)
|
|
123
|
+
- **T** - Jump to today
|
|
124
|
+
|
|
125
|
+
## Theming
|
|
126
|
+
|
|
127
|
+
Customize the appearance using CSS custom properties:
|
|
128
|
+
|
|
129
|
+
```css
|
|
130
|
+
:root {
|
|
131
|
+
/* Colors */
|
|
132
|
+
--drp-card-bg: #ffffff;
|
|
133
|
+
--drp-border-color: #e5e7eb;
|
|
134
|
+
--drp-primary-bg: #f3f4f6;
|
|
135
|
+
--drp-primary-bg-hover: #e5e7eb;
|
|
136
|
+
--drp-accent-color: #3b82f6;
|
|
137
|
+
--drp-accent-color-hover: #2563eb;
|
|
138
|
+
--drp-text-primary: #111827;
|
|
139
|
+
--drp-text-secondary: #6b7280;
|
|
140
|
+
|
|
141
|
+
/* Spacing */
|
|
142
|
+
--drp-spacing-xs: 0.25rem;
|
|
143
|
+
--drp-spacing-sm: 0.5rem;
|
|
144
|
+
--drp-spacing-md: 1rem;
|
|
145
|
+
--drp-spacing-lg: 1.5rem;
|
|
146
|
+
--drp-spacing-xl: 2rem;
|
|
147
|
+
|
|
148
|
+
/* Typography */
|
|
149
|
+
--drp-font-size-xs: 0.75rem;
|
|
150
|
+
--drp-font-size-sm: 0.875rem;
|
|
151
|
+
--drp-font-size-base: 1rem;
|
|
152
|
+
--drp-font-weight-medium: 500;
|
|
153
|
+
--drp-font-weight-semibold: 600;
|
|
154
|
+
|
|
155
|
+
/* Borders */
|
|
156
|
+
--drp-border-width-base: 1px;
|
|
157
|
+
--drp-border-radius: 0.375rem;
|
|
158
|
+
|
|
159
|
+
/* Shadows */
|
|
160
|
+
--drp-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
|
|
161
|
+
|
|
162
|
+
/* Transitions */
|
|
163
|
+
--drp-transition-fast: 150ms;
|
|
164
|
+
--drp-easing-snappy: cubic-bezier(0.4, 0.0, 0.2, 1);
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Install dependencies
|
|
172
|
+
npm install
|
|
173
|
+
|
|
174
|
+
# Start dev server
|
|
175
|
+
npm run dev
|
|
176
|
+
|
|
177
|
+
# Build for production
|
|
178
|
+
npm run build
|
|
179
|
+
|
|
180
|
+
# Preview production build
|
|
181
|
+
npm run preview
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Browser Support
|
|
185
|
+
|
|
186
|
+
- Modern browsers with Web Components support
|
|
187
|
+
- Chrome/Edge 54+
|
|
188
|
+
- Firefox 63+
|
|
189
|
+
- Safari 10.1+
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT
|
|
194
|
+
|
|
195
|
+
## Credits
|
|
196
|
+
|
|
197
|
+
Extracted from the [Pure Admin](https://github.com/keenmate/pure-admin) design system.
|