@dooherceg/mrt-date-picker 1.0.0 → 1.0.2

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 CHANGED
@@ -1,75 +1,109 @@
1
- # React + TypeScript + Vite
1
+ # @dooherceg/mrt-date-picker
2
2
 
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
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
- Currently, two official plugins are available:
5
+ ## Features
6
6
 
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
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
- ## React Compiler
13
+ ## Installation
11
14
 
12
- The React Compiler is enabled on this template. See [this documentation](https://react.dev/learn/react-compiler) for more information.
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
- Note: This will impact Vite dev & build performances.
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
- ## Expanding the ESLint configuration
34
+ ## Usage
17
35
 
18
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
36
+ ### Single date / datetime filter
19
37
 
20
- ```js
21
- export default defineConfig([
22
- globalIgnores(['dist']),
38
+ ```tsx
39
+ import { MRT_SingleDateValueEditor } from '@dooherceg/mrt-date-picker';
40
+
41
+ // Inside your MRT column definition:
42
+ const columns = [
23
43
  {
24
- files: ['**/*.{ts,tsx}'],
25
- extends: [
26
- // Other configs...
27
-
28
- // Remove tseslint.configs.recommended and replace with this
29
- tseslint.configs.recommendedTypeChecked,
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
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
54
+ Use `pickerType="datetime"` to render a `DateTimePicker` instead of a `DatePicker`.
55
+
56
+ ### Date range filter
49
57
 
50
- ```js
51
- // eslint.config.js
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
- export default defineConfig([
56
- globalIgnores(['dist']),
61
+ const columns = [
57
62
  {
58
- files: ['**/*.{ts,tsx}'],
59
- extends: [
60
- // Other configs...
61
- // Enable lint rules for React
62
- reactX.configs['recommended-typescript'],
63
- // Enable lint rules for React DOM
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 { }