-
-
-
-
-
- –
-
-
-
-
+ ranges?: DataGridPredefinedDateRange[]
+}) => {
+ const id = useId()
+ return (
+
+
+ {label}
+
+
+
+ {ranges?.length > 0 &&
+ {ranges.map(({ start, end, label }) => (
+
+ ))}
+
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-)
+
+
+ )
+}
+
+export type DataGridPredefinedDateRange = { start: string, end: string, label: ReactNode }
+const DataGridRangeFilter = ({ start, end, label }: DataGridPredefinedDateRange) => {
+ const name = useDataViewFilterName()
+ const [filter, setFilter] = useDataViewFilter
(name)
+ const isActive = filter?.start === start && filter?.end === end
+ return (
+
+ )
+}
diff --git a/packages/playground/admin/lib/dict.ts b/packages/playground/admin/lib/dict.ts
index 82f7e21f3..e4ef67d6d 100644
--- a/packages/playground/admin/lib/dict.ts
+++ b/packages/playground/admin/lib/dict.ts
@@ -27,8 +27,9 @@ export const dict = {
},
datagrid: {
na: 'N/A',
- dateStart: 'Start',
- dateEnd: 'End',
+ dateStart: 'From',
+ today: 'Today',
+ dateEnd: 'To',
numberFrom: 'From',
numberTo: 'To',
textReset: 'Reset filter',
diff --git a/packages/react-dataview/src/components/filtering/date/DataViewDateFilterResetTrigger.tsx b/packages/react-dataview/src/components/filtering/date/DataViewDateFilterResetTrigger.tsx
index 2618bea0e..63c2e1314 100644
--- a/packages/react-dataview/src/components/filtering/date/DataViewDateFilterResetTrigger.tsx
+++ b/packages/react-dataview/src/components/filtering/date/DataViewDateFilterResetTrigger.tsx
@@ -8,21 +8,26 @@ import { useDataViewFilterName } from '../../../contexts'
export type DataViewDateFilterResetTriggerProps = {
name?: string
children: ReactElement
+ type?: 'start' | 'end'
}
-export const DataViewDateFilterResetTrigger = ({ name, ...props }: DataViewDateFilterResetTriggerProps) => {
+export const DataViewDateFilterResetTrigger = ({ name, type, ...props }: DataViewDateFilterResetTriggerProps) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
name ??= useDataViewFilterName()
const [state, setFilter] = useDataViewFilter(name)
const cb = useCallback(() => {
setFilter(it => ({
...it,
- start: undefined,
- end: undefined,
+ start: !type || type === 'start' ? undefined : it?.start,
+ end: !type || type === 'end' ? undefined : it?.end,
}))
- }, [setFilter])
-
- if (state?.start === undefined && state?.end === undefined) {
+ }, [setFilter, type])
+ const hasStart = state?.start !== undefined
+ const hasEnd = state?.end !== undefined
+ if (!hasStart && !hasEnd) {
+ return null
+ }
+ if (type === 'start' && !hasStart || type === 'end' && !hasEnd) {
return null
}