@dooherceg/mrt-date-picker 1.0.0 → 1.0.1
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 +91 -57
- package/dist/index.d.ts +1 -1
- package/dist/mrt-date-picker.cjs +175 -0
- package/dist/mrt-date-picker.js +24589 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,75 +1,109 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dooherceg/mrt-date-picker
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Date and datetime filter editor components for [Material React Table (MRT)](https://www.material-react-table.com/) v3, built on top of [MUI X Date Pickers](https://mui.com/x/react-date-pickers/getting-started/) and [Day.js](https://day.js.org/).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
7
|
+
- **`MRT_SingleDateValueEditor`** – renders a `DatePicker` or `DateTimePicker` for single-value date filter operators
|
|
8
|
+
- **`MRT_RangeDateValueEditor`** – renders a custom popover with two calendars (and optional time clocks) for range-based filter operators
|
|
9
|
+
- Relative date range helpers (`current-week`, `last-7-days`, `last-month`, etc.) via `computeRelativeDateValue`
|
|
10
|
+
- Locale-aware formatting with built-in support for **de**, **fr**, **hr**, **nl**, and **en** (falls back to English for any other language)
|
|
11
|
+
- Filter values are serialised as **Unix millisecond timestamps** so they are safe to send to any API
|
|
9
12
|
|
|
10
|
-
##
|
|
13
|
+
## Installation
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
```bash
|
|
16
|
+
npm install @dooherceg/mrt-date-picker
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Peer dependencies
|
|
20
|
+
|
|
21
|
+
The following packages must already be present in your project:
|
|
13
22
|
|
|
14
|
-
|
|
23
|
+
| Package | Version |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `react` / `react-dom` | ≥ 18 |
|
|
26
|
+
| `material-react-table` | ≥ 3 |
|
|
27
|
+
| `@mui/material` | ≥ 6 |
|
|
28
|
+
| `@mui/icons-material` | ≥ 6 |
|
|
29
|
+
| `@mui/x-date-pickers` | ≥ 7 |
|
|
30
|
+
| `@emotion/react` / `@emotion/styled` | ≥ 11 |
|
|
31
|
+
| `@iconify/react` | ≥ 4 |
|
|
32
|
+
| `dayjs` | ≥ 1 |
|
|
15
33
|
|
|
16
|
-
##
|
|
34
|
+
## Usage
|
|
17
35
|
|
|
18
|
-
|
|
36
|
+
### Single date / datetime filter
|
|
19
37
|
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
```tsx
|
|
39
|
+
import { MRT_SingleDateValueEditor } from '@dooherceg/mrt-date-picker';
|
|
40
|
+
|
|
41
|
+
// Inside your MRT column definition:
|
|
42
|
+
const columns = [
|
|
23
43
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// Alternatively, use this for stricter rules
|
|
31
|
-
tseslint.configs.strictTypeChecked,
|
|
32
|
-
// Optionally, add this for stylistic rules
|
|
33
|
-
tseslint.configs.stylisticTypeChecked,
|
|
34
|
-
|
|
35
|
-
// Other configs...
|
|
36
|
-
],
|
|
37
|
-
languageOptions: {
|
|
38
|
-
parserOptions: {
|
|
39
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
40
|
-
tsconfigRootDir: import.meta.dirname,
|
|
41
|
-
},
|
|
42
|
-
// other options...
|
|
43
|
-
},
|
|
44
|
+
accessorKey: 'createdAt',
|
|
45
|
+
header: 'Created At',
|
|
46
|
+
filterVariant: 'custom',
|
|
47
|
+
Filter: (props) => (
|
|
48
|
+
<MRT_SingleDateValueEditor pickerType="date" {...props} />
|
|
49
|
+
),
|
|
44
50
|
},
|
|
45
|
-
]
|
|
51
|
+
];
|
|
46
52
|
```
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
Use `pickerType="datetime"` to render a `DateTimePicker` instead of a `DatePicker`.
|
|
55
|
+
|
|
56
|
+
### Date range filter
|
|
49
57
|
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
import reactX from 'eslint-plugin-react-x'
|
|
53
|
-
import reactDom from 'eslint-plugin-react-dom'
|
|
58
|
+
```tsx
|
|
59
|
+
import { MRT_RangeDateValueEditor } from '@dooherceg/mrt-date-picker';
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
globalIgnores(['dist']),
|
|
61
|
+
const columns = [
|
|
57
62
|
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
reactDom.configs.recommended,
|
|
65
|
-
],
|
|
66
|
-
languageOptions: {
|
|
67
|
-
parserOptions: {
|
|
68
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
69
|
-
tsconfigRootDir: import.meta.dirname,
|
|
70
|
-
},
|
|
71
|
-
// other options...
|
|
72
|
-
},
|
|
63
|
+
accessorKey: 'createdAt',
|
|
64
|
+
header: 'Created At',
|
|
65
|
+
filterVariant: 'custom',
|
|
66
|
+
Filter: (props) => (
|
|
67
|
+
<MRT_RangeDateValueEditor pickerType="date" {...props} />
|
|
68
|
+
),
|
|
73
69
|
},
|
|
74
|
-
]
|
|
70
|
+
];
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The filter value is stored as `{ from: number | null, to: number | null }` where each endpoint is a Unix ms timestamp.
|
|
74
|
+
|
|
75
|
+
### Relative date ranges
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { computeRelativeDateValue } from '@dooherceg/mrt-date-picker';
|
|
79
|
+
|
|
80
|
+
const value = computeRelativeDateValue('last-7-days');
|
|
81
|
+
// => { from: <timestamp>, to: <timestamp> }
|
|
75
82
|
```
|
|
83
|
+
|
|
84
|
+
Supported operator IDs:
|
|
85
|
+
|
|
86
|
+
| Operator ID | Description |
|
|
87
|
+
|---|---|
|
|
88
|
+
| `current-week` | Start of this week → end of this week |
|
|
89
|
+
| `current-month` | Start of this month → end of this month |
|
|
90
|
+
| `last-7-days` | 6 days ago → today |
|
|
91
|
+
| `last-week` | Previous calendar week |
|
|
92
|
+
| `last-month` | Previous calendar month |
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Install dependencies
|
|
98
|
+
npm install
|
|
99
|
+
|
|
100
|
+
# Build the library
|
|
101
|
+
npm run build
|
|
102
|
+
|
|
103
|
+
# Lint
|
|
104
|
+
npm run lint
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export { }
|