@kodezen/kz-react-datepicker 1.0.0-beta.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/README.md +147 -0
- package/dist/index.cjs.css +2 -0
- package/dist/index.cjs.css.map +1 -0
- package/dist/index.cjs.js +1796 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.css.map +1 -0
- package/dist/index.esm.css +2 -0
- package/dist/index.esm.css.map +1 -0
- package/dist/index.esm.js +1794 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# @kodezen/kz-react-datepicker
|
|
2
|
+
|
|
3
|
+
A fully custom React date picker component built from scratch — no external date libraries. Supports range selection, single date, dark/light/auto themes, dynamic placements, shortcuts, and full customization via CSS variables.
|
|
4
|
+
|
|
5
|
+
*Inspired by [react-advance-datepicker](https://github.com/danish1717/react-advance-datepicker).*
|
|
6
|
+
|
|
7
|
+
## Preview
|
|
8
|
+
|
|
9
|
+
| Light Mode | Dark Mode |
|
|
10
|
+
|:---:|:---:|
|
|
11
|
+
|  |  |
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
| Dependency | Version |
|
|
16
|
+
|---|---|
|
|
17
|
+
| Node.js | `>= 14.x` (recommended `>= 18.x`) |
|
|
18
|
+
| React | `^16.8.0 \|\| ^17.0.0 \|\| ^18.0.0` |
|
|
19
|
+
| react-dom | `^16.8.0 \|\| ^17.0.0 \|\| ^18.0.0` |
|
|
20
|
+
|
|
21
|
+
> **Note:** React and react-dom are **peer dependencies** and must be installed in your project separately.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @kodezen/kz-react-datepicker
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Basic Usage
|
|
30
|
+
|
|
31
|
+
```jsx
|
|
32
|
+
import React, { useState } from 'react';
|
|
33
|
+
import DatePicker from '@kodezen/kz-react-datepicker';
|
|
34
|
+
import '@kodezen/kz-react-datepicker/dist/index.css';
|
|
35
|
+
|
|
36
|
+
const App = () => {
|
|
37
|
+
const [date, setDate] = useState(null);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<DatePicker
|
|
41
|
+
value={date}
|
|
42
|
+
onChange={(newDate) => setDate(newDate)}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default App;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Props
|
|
51
|
+
|
|
52
|
+
| Prop | Type | Default | Description |
|
|
53
|
+
|---|---|---|---|
|
|
54
|
+
| `value` | `{ startDate, endDate } \| null` | `null` | The selected date value. Each date can be a `Date` object or date string. |
|
|
55
|
+
| `onChange` | `(value, e?) => void` | — | **Required.** Callback fired when the user selects a date. |
|
|
56
|
+
| `asSingle` | `boolean` | `false` | If `true`, only allows picking a single date instead of a range. |
|
|
57
|
+
| `useRange` | `boolean` | `true` | If `false`, hides the second calendar and disables range selection. |
|
|
58
|
+
| `placeholder` | `string` | — | Input placeholder text. |
|
|
59
|
+
| `displayFormat` | `string` | `"YYYY-MM-DD"` | Format string for how dates are displayed in the input. |
|
|
60
|
+
| `separator` | `string` | `"~"` | String used to separate start and end dates in the input. |
|
|
61
|
+
| `startFrom` | `Date \| string \| null` | `null` | The date the calendar should open to initially. |
|
|
62
|
+
| `minDate` | `Date \| string \| null` | `null` | Minimum selectable date. |
|
|
63
|
+
| `maxDate` | `Date \| string \| null` | `null` | Maximum selectable date. |
|
|
64
|
+
| `disabledDates` | `Array<{ start, end }> \| null` | `null` | Array of date ranges to disable. |
|
|
65
|
+
| `disabled` | `boolean` | `false` | Disables the entire input. |
|
|
66
|
+
| `readOnly` | `boolean` | `false` | Makes the text input read-only (calendar still opens). |
|
|
67
|
+
| `theme` | `"auto" \| "light" \| "dark"` | `"auto"` | Color theme. `"auto"` follows the OS system preference. |
|
|
68
|
+
| `placement` | `"bottom" \| "top" \| "left" \| "right" \| "auto"` | `"bottom"` | Where the calendar popup opens relative to the input. `"auto"` picks the best position based on available screen space. |
|
|
69
|
+
| `showShortcuts` | `boolean` | `false` | Show quick date shortcut buttons (e.g., Today, Last 7 days). |
|
|
70
|
+
| `showFooter` | `boolean` | `false` | Show Apply/Cancel footer buttons. |
|
|
71
|
+
| `shortcutText` | `string \| null` | `null` | Prefix label shown inside the input on the left side. |
|
|
72
|
+
| `primaryColor` | `string` | `"blue"` | Primary accent color for the datepicker. |
|
|
73
|
+
| `i18n` | `string` | `"en"` | Locale string for internationalization. |
|
|
74
|
+
| `startWeekOn` | `"sun" \| "mon"` | `"sun"` | Day the week starts on. |
|
|
75
|
+
| `dateLooking` | `"forward" \| "backward" \| "middle"` | `"forward"` | Controls how incomplete ranges are displayed. |
|
|
76
|
+
| `inputId` | `string` | — | `id` attribute for the input element. |
|
|
77
|
+
| `inputName` | `string` | — | `name` attribute for the input element. |
|
|
78
|
+
| `inputClassName` | `string \| (cls: string) => string` | — | Custom class(es) for the input element. |
|
|
79
|
+
| `containerClassName` | `string \| (cls: string) => string` | — | Custom class(es) for the outer container. |
|
|
80
|
+
| `toggleClassName` | `string \| (cls: string) => string` | — | Custom class(es) for the calendar toggle button. |
|
|
81
|
+
| `toggleIcon` | `(open: boolean) => ReactNode` | — | Custom icon component for the toggle button. |
|
|
82
|
+
| `classNames` | `Object` | — | Fine-grained class overrides for sub-components. |
|
|
83
|
+
| `configs` | `Object` | — | Advanced configuration options for shortcuts. |
|
|
84
|
+
| `suffix` | `string` | `""` | Suffix appended to all internal CSS class names (useful for multiple instances). |
|
|
85
|
+
| `popoverDirection` | `string` | — | Legacy popover direction override. Prefer `placement` instead. |
|
|
86
|
+
|
|
87
|
+
## Styling & Customization
|
|
88
|
+
|
|
89
|
+
The datepicker uses CSS Custom Properties (variables) for theming — no `!important` needed.
|
|
90
|
+
|
|
91
|
+
### CSS Variables
|
|
92
|
+
|
|
93
|
+
Override these in your `:root` or a parent selector:
|
|
94
|
+
|
|
95
|
+
```css
|
|
96
|
+
:root {
|
|
97
|
+
--kz-datepicker-primary: #3b82f6; /* Accent / primary color */
|
|
98
|
+
--kz-datepicker-bg: #ffffff; /* Background color */
|
|
99
|
+
--kz-datepicker-text: #374151; /* Text color */
|
|
100
|
+
--kz-datepicker-border: #d1d5db; /* Border color */
|
|
101
|
+
--kz-datepicker-border-radius: 4px; /* Border radius */
|
|
102
|
+
--kz-datepicker-font-family: inherit; /* Font family */
|
|
103
|
+
--kz-datepicker-hover-bg: #f3f4f6; /* Hover background */
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Class Prop Overrides
|
|
108
|
+
|
|
109
|
+
Use these props to inject custom classes into different parts:
|
|
110
|
+
|
|
111
|
+
| Prop | Targets |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `containerClassName` | Outer wrapper `<div>` |
|
|
114
|
+
| `inputClassName` | The text `<input>` |
|
|
115
|
+
| `toggleClassName` | Calendar toggle `<button>` |
|
|
116
|
+
| `dayClassName` *(via classNames)* | Individual day cells |
|
|
117
|
+
| `calendarClassName` *(via classNames)* | Calendar popover container |
|
|
118
|
+
|
|
119
|
+
## Theme Examples
|
|
120
|
+
|
|
121
|
+
```jsx
|
|
122
|
+
// Follow OS preference (default)
|
|
123
|
+
<DatePicker value={date} onChange={setDate} theme="auto" />
|
|
124
|
+
|
|
125
|
+
// Always light
|
|
126
|
+
<DatePicker value={date} onChange={setDate} theme="light" />
|
|
127
|
+
|
|
128
|
+
// Always dark
|
|
129
|
+
<DatePicker value={date} onChange={setDate} theme="dark" />
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Placement Examples
|
|
133
|
+
|
|
134
|
+
```jsx
|
|
135
|
+
// Opens below (default)
|
|
136
|
+
<DatePicker value={date} onChange={setDate} placement="bottom" />
|
|
137
|
+
|
|
138
|
+
// Opens above
|
|
139
|
+
<DatePicker value={date} onChange={setDate} placement="top" />
|
|
140
|
+
|
|
141
|
+
// Auto-detect based on available viewport space
|
|
142
|
+
<DatePicker value={date} onChange={setDate} placement="auto" />
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
ISC
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
:root{--kz-datepicker-primary:#007bff;--kz-datepicker-bg:#fff;--kz-datepicker-text:#333;--kz-datepicker-border:#ccc;--kz-datepicker-border-radius:4px;--kz-datepicker-font-family:inherit;--kz-datepicker-hover-bg:#f0f0f0}.kz-datepicker{color:var(--kz-datepicker-text);display:inline-block;font-family:var(--kz-datepicker-font-family);position:relative}.kz-datepicker-input{background-color:var(--kz-datepicker-bg);border:1px solid var(--kz-datepicker-border);border-radius:var(--kz-datepicker-border-radius);color:inherit;cursor:pointer;font-family:inherit;outline:none;padding:8px 12px}.kz-datepicker-input:focus{border-color:var(--kz-datepicker-primary);box-shadow:0 0 0 2px rgba(0,123,255,.25)}.kz-datepicker-calendar{background-color:var(--kz-datepicker-bg);border:1px solid var(--kz-datepicker-border);border-radius:var(--kz-datepicker-border-radius);box-shadow:0 4px 6px rgba(0,0,0,.1);left:0;padding:16px;position:absolute;top:calc(100% + 4px);z-index:1000}
|
|
2
|
+
/*# sourceMappingURL=index.cjs.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.scss"],"names":[],"mappings":"AAAA,MACE,+BAAgC,CAChC,uBAA2B,CAC3B,yBAA6B,CAC7B,2BAA+B,CAC/B,iCAAkC,CAClC,mCAAoC,CACpC,gCACF,CAEA,eAIE,+BAAgC,CADhC,oBAAqB,CAFrB,4CAA6C,CAC7C,iBAGF,CACA,qBAIE,wCAAyC,CAFzC,4CAA6C,CAC7C,gDAAiD,CAEjD,aAAc,CAEd,cAAe,CADf,mBAAoB,CAEpB,YAAa,CAPb,gBAQF,CACA,2BACE,yCAA0C,CAC1C,wCACF,CACA,wBAKE,wCAAyC,CACzC,4CAA6C,CAC7C,gDAAiD,CAEjD,mCAAwC,CANxC,MAAO,CAKP,YAAa,CAPb,iBAAkB,CAClB,oBAAqB,CAErB,YAMF","file":"index.cjs.css","sourcesContent":[":root {\n --kz-datepicker-primary: #007bff;\n --kz-datepicker-bg: #ffffff;\n --kz-datepicker-text: #333333;\n --kz-datepicker-border: #cccccc;\n --kz-datepicker-border-radius: 4px;\n --kz-datepicker-font-family: inherit;\n --kz-datepicker-hover-bg: #f0f0f0;\n}\n\n.kz-datepicker {\n font-family: var(--kz-datepicker-font-family);\n position: relative;\n display: inline-block;\n color: var(--kz-datepicker-text);\n}\n.kz-datepicker-input {\n padding: 8px 12px;\n border: 1px solid var(--kz-datepicker-border);\n border-radius: var(--kz-datepicker-border-radius);\n background-color: var(--kz-datepicker-bg);\n color: inherit;\n font-family: inherit;\n cursor: pointer;\n outline: none;\n}\n.kz-datepicker-input:focus {\n border-color: var(--kz-datepicker-primary);\n box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);\n}\n.kz-datepicker-calendar {\n position: absolute;\n top: calc(100% + 4px);\n left: 0;\n z-index: 1000;\n background-color: var(--kz-datepicker-bg);\n border: 1px solid var(--kz-datepicker-border);\n border-radius: var(--kz-datepicker-border-radius);\n padding: 16px;\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n}"]}
|