@shefing/quickfilter 1.0.11 → 1.0.13
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 +859 -0
- package/dist/FilterField.d.ts.map +1 -1
- package/dist/FilterField.js +18 -9
- package/dist/FilterField.js.map +1 -1
- package/dist/QuickFilter.d.ts.map +1 -1
- package/dist/QuickFilter.js +227 -55
- package/dist/QuickFilter.js.map +1 -1
- package/dist/filters/components/checkbox-filter.d.ts +2 -1
- package/dist/filters/components/checkbox-filter.d.ts.map +1 -1
- package/dist/filters/components/checkbox-filter.js +9 -7
- package/dist/filters/components/checkbox-filter.js.map +1 -1
- package/dist/filters/components/date-filter.d.ts +2 -1
- package/dist/filters/components/date-filter.d.ts.map +1 -1
- package/dist/filters/components/date-filter.js +26 -24
- package/dist/filters/components/date-filter.js.map +1 -1
- package/dist/filters/components/select-filter.d.ts +2 -1
- package/dist/filters/components/select-filter.d.ts.map +1 -1
- package/dist/filters/components/select-filter.js +20 -18
- package/dist/filters/components/select-filter.js.map +1 -1
- package/dist/filters/components/small-select-filter.d.ts +2 -1
- package/dist/filters/components/small-select-filter.d.ts.map +1 -1
- package/dist/filters/components/small-select-filter.js +4 -3
- package/dist/filters/components/small-select-filter.js.map +1 -1
- package/dist/filters/constants/date-filter-options.d.ts +7 -4
- package/dist/filters/constants/date-filter-options.d.ts.map +1 -1
- package/dist/filters/constants/date-filter-options.js +25 -70
- package/dist/filters/constants/date-filter-options.js.map +1 -1
- package/dist/filters/types/filters-type.d.ts.map +1 -1
- package/dist/filters/types/filters-type.js.map +1 -1
- package/dist/filters/utils/date-helpers.d.ts +4 -3
- package/dist/filters/utils/date-helpers.d.ts.map +1 -1
- package/dist/filters/utils/date-helpers.js +14 -11
- package/dist/filters/utils/date-helpers.js.map +1 -1
- package/dist/filters/utils/layout-helpers.d.ts.map +1 -1
- package/dist/filters/utils/layout-helpers.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/labels.d.ts +326 -0
- package/dist/labels.d.ts.map +1 -0
- package/dist/labels.js +192 -0
- package/dist/labels.js.map +1 -0
- package/package.json +1 -1
package/dist/QuickFilter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/QuickFilter.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useConfig, useListQuery, useTranslation } from '@payloadcms/ui';\nimport type { ClientField, FieldAffectingData, OptionObject, SelectField } from 'payload';\nimport { getTranslation } from '@payloadcms/translations';\nimport FilterField from './FilterField';\nimport type {\n CheckboxFilterState,\n DateFilterValue,\n FilterDetaild,\n FilterRow,\n SelectFilterValue,\n} from './filters/types/filters-type';\nimport { groupFiltersByRow, parseColumns } from './filters/utils/layout-helpers';\nimport { ChevronDown, ChevronUp, Filter, X } from 'lucide-react';\n\nimport {\n futureDateFilterOptions,\n pastDateFilterOptions,\n} from './filters/constants/date-filter-options';\nimport { getDateRangeForOption } from './filters/utils/date-helpers';\nimport { Button } from './ui/button';\n\n// Recursive function to find fields by name\nfunction findFieldsByName(fields: ClientField[], fieldNames: string[]): ClientField[] {\n const results: ClientField[] = [];\n function recursiveSearch(currentFields: ClientField[]) {\n const filteredFields = currentFields.filter(\n (field) => 'name' in field && fieldNames.includes(field.name as string),\n );\n results.push(...filteredFields);\n currentFields.forEach((item) => {\n if (\n (item.type === 'array' || item.type === 'row' || item.type === 'collapsible') &&\n 'fields' in item &&\n Array.isArray(item.fields)\n ) {\n recursiveSearch(item.fields);\n } else if (item.type === 'tabs' && Array.isArray(item.tabs)) {\n item.tabs.forEach((tab) => {\n if ('fields' in tab && Array.isArray(tab.fields)) {\n recursiveSearch(tab.fields);\n }\n });\n } else if (item.type === 'blocks' && Array.isArray(item.blocks)) {\n item.blocks.forEach((block) => {\n if ('fields' in block && Array.isArray(block.fields)) {\n recursiveSearch(block.fields);\n }\n });\n }\n });\n }\n recursiveSearch(fields);\n return results;\n}\n\n// Helper function to convert UI state to a where query\nconst buildWhereClause = (\n values: Record<string, any>,\n fieldDefs: FilterDetaild[],\n isHebrew: boolean,\n): Record<string, any> => {\n const where: Record<string, any> = {};\n Object.entries(values).forEach(([fieldName, value]) => {\n if (!value) return;\n const fieldDef = fieldDefs.find((f) => f.name === fieldName);\n if (!fieldDef) return;\n switch (fieldDef.type) {\n case 'date': {\n const dateValue = value as DateFilterValue;\n let from: Date | undefined;\n let to: Date | undefined;\n\n if (dateValue.predefinedValue) {\n const locale = isHebrew ? 'he' : 'en';\n const range = getDateRangeForOption(dateValue.predefinedValue, locale);\n\n from = range.from;\n to = range.to;\n }\n // Fallback for custom date ranges\n else if (dateValue.customRange) {\n if (dateValue.customRange.from) {\n from = new Date(dateValue.customRange.from);\n }\n if (dateValue.customRange.to) {\n to = new Date(dateValue.customRange.to);\n }\n }\n\n // Construct the query\n if (from || to) {\n const dateQuery: any = {};\n if (from) dateQuery.greater_than_equal = from;\n if (to) dateQuery.less_than_equal = to;\n if (Object.keys(dateQuery).length > 0) {\n where[fieldName] = dateQuery;\n }\n }\n break;\n }\n case 'select': {\n const selectValue = value as SelectFilterValue;\n if (selectValue.selectedValues && selectValue.selectedValues.length > 0) {\n if (selectValue.selectedValues.length === 1) {\n where[fieldName] = { equals: selectValue.selectedValues[0] };\n } else {\n where[fieldName] = { in: selectValue.selectedValues };\n }\n }\n break;\n }\n case 'checkbox': {\n const checkboxState = value as CheckboxFilterState;\n if (checkboxState === 'checked') {\n where[fieldName] = { equals: true };\n } else if (checkboxState === 'unchecked') {\n where[fieldName] = { equals: false };\n }\n // 'indeterminate' will not filter\n break;\n }\n }\n });\n return where;\n};\n\nconst QuickFilter = ({\n slug,\n filterList,\n}: {\n slug: string;\n filterList: (string | { name: string; width: string })[][];\n}) => {\n const localStorageKey = useMemo(() => `direct-filter-${slug}`, [slug]);\n\n const [fields, setFields] = useState<FilterDetaild[]>([]);\n const [filterRows, setFilterRows] = useState<FilterRow[]>([]);\n const [showFilters, setShowFilters] = useState(false);\n const { refineListData, query } = useListQuery();\n const { getEntityConfig } = useConfig();\n const { i18n } = useTranslation();\n\n const [filterValues, setFilterValues] = useState<Record<string, any>>(() => {\n if (typeof window == 'undefined') return {};\n try {\n const item = window.localStorage.getItem(localStorageKey);\n if (!item) {\n return {};\n }\n const dateTimeReviver = (key: string, value: any) => {\n const isoDateRegex = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$/;\n if (typeof value === 'string' && isoDateRegex.test(value)) {\n return new Date(value);\n }\n return value;\n };\n return JSON.parse(item, dateTimeReviver);\n } catch (error) {\n console.error('Error reading and parsing filters from localStorage.', error);\n return {};\n }\n });\n\n useEffect(() => {\n const collection = getEntityConfig({ collectionSlug: slug });\n const flattenedFieldConfigs = filterList.flatMap((row, rowIndex) =>\n row.map((field, fieldIndex) => ({\n field,\n rowIndex,\n fieldIndex,\n })),\n );\n const fieldNames = flattenedFieldConfigs.map(({ field }) =>\n typeof field === 'string' ? field : field.name,\n );\n const matchedFields = findFieldsByName(collection?.fields || [], fieldNames);\n const simplifiedFields: FilterDetaild[] = matchedFields.map((field) => {\n const label = (field as FieldAffectingData).label;\n const translatedLabel = getTranslation(label as string, i18n);\n const fieldName = (field as FieldAffectingData).name as string;\n const fieldConfig = flattenedFieldConfigs.find(({ field: f }) =>\n typeof f === 'string' ? f === fieldName : f.name === fieldName,\n );\n return {\n name: fieldName,\n label: translatedLabel as string,\n type: field.type,\n options: (field as SelectField).options as OptionObject[],\n row: fieldConfig ? fieldConfig.rowIndex : 0,\n width:\n typeof fieldConfig?.field === 'object' && 'width' in fieldConfig.field\n ? fieldConfig.field.width\n : undefined,\n };\n });\n const sortedFields = flattenedFieldConfigs\n .map(({ field }) => {\n const fieldName = typeof field === 'string' ? field : field.name;\n return simplifiedFields.find((f) => f.name === fieldName);\n })\n .filter((f): f is FilterDetaild => !!f);\n setFields(sortedFields);\n setFilterRows(groupFiltersByRow(sortedFields));\n }, [slug, filterList, getEntityConfig, i18n]);\n\n useEffect(() => {\n if (fields.length === 0) {\n return;\n }\n const where = buildWhereClause(filterValues, fields, isHebrew);\n try {\n if (Object.keys(filterValues).length > 0) {\n localStorage.setItem(localStorageKey, JSON.stringify(filterValues));\n } else {\n localStorage.removeItem(localStorageKey);\n return;\n }\n } catch (error) {\n console.error('Failed to save filters to localStorage', error);\n }\n\n if (JSON.stringify(where) !== JSON.stringify(query.where)) {\n refineListData({\n columns: parseColumns(query.columns),\n where,\n page: '1',\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [filterValues, fields, localStorageKey]);\n\n const handleFilterChange = useCallback((fieldName: string, value: any) => {\n setFilterValues((prev) => {\n const newValues = { ...prev };\n if (\n value === undefined ||\n value === null ||\n value === 'indeterminate' ||\n (value && value.type === 'none')\n ) {\n delete newValues[fieldName];\n } else {\n newValues[fieldName] = value;\n }\n return newValues;\n });\n }, []);\n\n // This function remains largely the same.\n const getActiveFiltersDetails = () => {\n const activeFilters: string[] = [];\n const isHebrew = i18n.language === 'he';\n\n Object.entries(filterValues).forEach(([fieldName, value]) => {\n const field = fields.find((f) => f.name === fieldName);\n if (!field) return;\n\n switch (field.type) {\n case 'date':\n if (value !== undefined) {\n const dateValue = value as DateFilterValue;\n let dateDescription = '';\n\n if (dateValue.type === 'predefined' && dateValue.predefinedValue) {\n const allOptions = [...pastDateFilterOptions, ...futureDateFilterOptions];\n const option = allOptions.find((opt) => opt.value === dateValue.predefinedValue);\n dateDescription = option ? option.label : isHebrew ? 'מותאם אישית' : 'Custom';\n } else if (dateValue.type === 'custom' || dateValue.customRange) {\n dateDescription = isHebrew ? 'מותאם אישית' : 'Custom';\n }\n\n if (dateDescription) {\n activeFilters.push(`${field.label} (${dateDescription})`);\n }\n }\n break;\n case 'select': {\n const selectValue = value as SelectFilterValue;\n if (selectValue && selectValue.selectedValues && selectValue.selectedValues.length > 0) {\n const count = selectValue.selectedValues.length;\n const totalOptions = field.options?.length || 0;\n if (selectValue.selectedValues.length === totalOptions) {\n activeFilters.push(`${field.label} (${isHebrew ? 'הכל' : 'All'})`);\n } else {\n activeFilters.push(`${field.label} (${count})`);\n }\n }\n break;\n }\n case 'checkbox':\n if (value !== 'indeterminate') {\n const checkboxValue =\n value === 'checked' ? (isHebrew ? 'כן' : 'Yes') : isHebrew ? 'לא' : 'No';\n activeFilters.push(`${field.label} (${checkboxValue})`);\n }\n break;\n }\n });\n\n return activeFilters;\n };\n\n const clearAllFilters = () => {\n refineListData({\n columns: parseColumns(query.columns),\n where: {},\n page: '1',\n });\n setFilterValues({});\n };\n\n const memoizedFilterRows = useMemo(() => {\n return filterRows.map((row) => (\n <div key={row.rowNumber}>\n <div className='flex flex-wrap gap-6 mb-4'>\n {row.filters.map((field) => (\n <FilterField\n key={field.name}\n field={field}\n onFilterChange={handleFilterChange}\n value={filterValues[field.name]}\n />\n ))}\n </div>\n </div>\n ));\n }, [filterRows, handleFilterChange, filterValues]);\n\n const toggleFilters = () => {\n setShowFilters((prev) => !prev);\n };\n\n const activeFiltersDetails = getActiveFiltersDetails();\n const hasActiveFilters = activeFiltersDetails.length > 0;\n const isHebrew = i18n.language === 'he';\n\n if (!fields.length) return null;\n\n return (\n <div className='filter-container useTw'>\n <div style={{ position: 'relative', top: '-24px', height: '0px' }}>\n <Button\n variant='outline'\n size='sm'\n onClick={toggleFilters}\n className={`flex items-center gap-2 bg-background border-muted-muted hover:bg-muted ${\n hasActiveFilters ? 'w-auto min-w-fit' : ''\n }`}\n >\n <Filter className={`h-4 w-4 ${hasActiveFilters ? 'fill-current' : ''}`} />\n\n {hasActiveFilters ? (\n <>\n <span className='text-sm truncate'>\n <strong>\n {isHebrew\n ? `${activeFiltersDetails.length === 1 ? 'סינון פעיל בעמודה' : 'סינון פעיל בעמודות'}: `\n : `${activeFiltersDetails.length === 1 ? 'Active filter on column' : 'Active filters on columns'}: `}\n </strong>{' '}\n {activeFiltersDetails.join(' • ')}\n </span>\n\n <span\n onClick={(e) => {\n e.stopPropagation();\n clearAllFilters();\n }}\n className='ml-1 p-0.5 hover:bg-muted rounded-sm transition-colors flex-shrink-0'\n >\n <X className='h-3 w-3 text-gray-500' />\n </span>\n </>\n ) : (\n <span className='text-sm truncate'>{isHebrew ? 'סינון מהיר' : 'Quick Filters'}</span>\n )}\n\n {showFilters ? <ChevronUp className='h-4 w-4' /> : <ChevronDown className='h-4 w-4' />}\n </Button>\n </div>\n {showFilters && <div className={'p-4 pb-2 bg-muted'}>{memoizedFilterRows}</div>}\n </div>\n );\n};\n\nexport default QuickFilter;\n"],"names":["useCallback","useEffect","useMemo","useState","useConfig","useListQuery","useTranslation","getTranslation","FilterField","groupFiltersByRow","parseColumns","ChevronDown","ChevronUp","Filter","X","futureDateFilterOptions","pastDateFilterOptions","getDateRangeForOption","Button","findFieldsByName","fields","fieldNames","results","recursiveSearch","currentFields","filteredFields","filter","field","includes","name","push","forEach","item","type","Array","isArray","tabs","tab","blocks","block","buildWhereClause","values","fieldDefs","isHebrew","where","Object","entries","fieldName","value","fieldDef","find","f","dateValue","from","to","predefinedValue","locale","range","customRange","Date","dateQuery","greater_than_equal","less_than_equal","keys","length","selectValue","selectedValues","equals","in","checkboxState","QuickFilter","slug","filterList","localStorageKey","setFields","filterRows","setFilterRows","showFilters","setShowFilters","refineListData","query","getEntityConfig","i18n","filterValues","setFilterValues","window","localStorage","getItem","dateTimeReviver","key","isoDateRegex","test","JSON","parse","error","console","collection","collectionSlug","flattenedFieldConfigs","flatMap","row","rowIndex","map","fieldIndex","matchedFields","simplifiedFields","label","translatedLabel","fieldConfig","options","width","undefined","sortedFields","setItem","stringify","removeItem","columns","page","handleFilterChange","prev","newValues","getActiveFiltersDetails","activeFilters","language","dateDescription","allOptions","option","opt","count","totalOptions","checkboxValue","clearAllFilters","memoizedFilterRows","div","className","filters","onFilterChange","rowNumber","toggleFilters","activeFiltersDetails","hasActiveFilters","style","position","top","height","variant","size","onClick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KAAa;IAEjD,MAAMuD,gBAAgB;QACpB5D,eAAe,CAACyC,OAAS,CAACA;IAC5B;IAEA,MAAMoB,uBAAuBlB;IAC7B,MAAMmB,mBAAmBD,qBAAqB3E,MAAM,GAAG;IACvD,MAAMrB,WAAWuC,KAAKyC,QAAQ,KAAK;IAEnC,IAAI,CAACvG,OAAO4C,MAAM,EAAE,OAAO;IAE3B,qBACE,MAACqE;QAAIC,WAAU;;0BACb,KAACD;gBAAIQ,OAAO;oBAAEC,UAAU;oBAAYC,KAAK;oBAASC,QAAQ;gBAAM;0BAC9D,cAAA,MAAC9H;oBACC+H,SAAQ;oBACRC,MAAK;oBACLC,SAAST;oBACTJ,WAAW,CAAC,wEAAwE,EAClFM,mBAAmB,qBAAqB,IACxC;;sCAEF,KAAC/H;4BAAOyH,WAAW,CAAC,QAAQ,EAAEM,mBAAmB,iBAAiB,IAAI;;wBAErEA,iCACC;;8CACE,MAACQ;oCAAKd,WAAU;;sDACd,KAACe;sDACE1G,WACG,GAAGgG,qBAAqB3E,MAAM,KAAK,IAAI,sBAAsB,qBAAqB,EAAE,CAAC,GACrF,GAAG2E,qBAAqB3E,MAAM,KAAK,IAAI,4BAA4B,4BAA4B,EAAE,CAAC;;wCAC9F;wCACT2E,qBAAqBW,IAAI,CAAC;;;8CAG7B,KAACF;oCACCD,SAAS,CAACI;wCACRA,EAAEC,eAAe;wCACjBrB;oCACF;oCACAG,WAAU;8CAEV,cAAA,KAACxH;wCAAEwH,WAAU;;;;2CAIjB,KAACc;4BAAKd,WAAU;sCAAoB3F,WAAW,eAAe;;wBAG/DkC,4BAAc,KAACjE;4BAAU0H,WAAU;2CAAe,KAAC3H;4BAAY2H,WAAU;;;;;YAG7EzD,6BAAe,KAACwD;gBAAIC,WAAW;0BAAsBF;;;;AAG5D;AAEA,eAAe9D,YAAY"}
|
|
1
|
+
{"version":3,"sources":["../src/QuickFilter.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { useConfig, useListQuery, useTranslation } from '@payloadcms/ui';\nimport type { ClientField, FieldAffectingData, OptionObject, SelectField } from 'payload';\nimport { getTranslation } from '@payloadcms/translations';\nimport FilterField from './FilterField';\nimport { getLabel, SupportedLocale } from './labels';\nimport type {\n CheckboxFilterState,\n DateFilterValue,\n FilterDetaild,\n FilterRow,\n SelectFilterValue,\n} from './filters/types/filters-type';\nimport { groupFiltersByRow, parseColumns } from './filters/utils/layout-helpers';\nimport { ChevronDown, ChevronUp, Filter, X } from 'lucide-react';\n\nimport { getDateRangeForOption } from './filters/utils/date-helpers';\nimport { isEqual } from 'lodash';\nimport {\n futureOptionKeys,\n getDateFilterOptions,\n pastOptionKeys,\n} from './filters/constants/date-filter-options';\nimport { Button } from './ui/button';\n\n// Recursive function to find fields by name\nfunction findFieldsByName(fields: ClientField[], fieldNames: string[]): ClientField[] {\n const results: ClientField[] = [];\n function recursiveSearch(currentFields: ClientField[]) {\n const filteredFields = currentFields.filter(\n (field) => 'name' in field && fieldNames.includes(field.name as string),\n );\n results.push(...filteredFields);\n currentFields.forEach((item) => {\n if (\n (item.type === 'array' || item.type === 'row' || item.type === 'collapsible') &&\n 'fields' in item &&\n Array.isArray(item.fields)\n ) {\n recursiveSearch(item.fields);\n } else if (item.type === 'tabs' && Array.isArray(item.tabs)) {\n item.tabs.forEach((tab) => {\n if ('fields' in tab && Array.isArray(tab.fields)) {\n recursiveSearch(tab.fields);\n }\n });\n } else if (item.type === 'blocks' && Array.isArray(item.blocks)) {\n item.blocks.forEach((block) => {\n if ('fields' in block && Array.isArray(block.fields)) {\n recursiveSearch(block.fields);\n }\n });\n }\n });\n }\n recursiveSearch(fields);\n return results;\n}\n\n// Builds an array of condition objects from the quick filter values\nconst buildQuickFilterConditions = (\n values: Record<string, any>,\n fieldDefs: FilterDetaild[],\n locale: SupportedLocale,\n): Record<string, any>[] => {\n const conditions: Record<string, any>[] = [];\n\n Object.entries(values).forEach(([fieldName, value]) => {\n if (!value) return;\n const fieldDef = fieldDefs.find((f) => f.name === fieldName);\n if (!fieldDef) return;\n\n let condition: Record<string, any> | null = null;\n\n switch (fieldDef.type) {\n case 'date': {\n const dateValue = value as DateFilterValue;\n let from: Date | undefined;\n let to: Date | undefined;\n\n if (dateValue.predefinedValue) {\n const range = getDateRangeForOption(dateValue.predefinedValue, locale);\n from = range.from;\n to = range.to;\n } else if (dateValue.customRange) {\n if (dateValue.customRange.from) from = new Date(dateValue.customRange.from);\n if (dateValue.customRange.to) to = new Date(dateValue.customRange.to);\n }\n\n if (from || to) {\n const dateQuery: any = {};\n if (from) dateQuery.greater_than_equal = from;\n if (to) dateQuery.less_than_equal = to;\n if (Object.keys(dateQuery).length > 0) {\n condition = { [fieldName]: dateQuery };\n }\n }\n break;\n }\n case 'select': {\n const selectValue = value as SelectFilterValue;\n if (selectValue.selectedValues && selectValue.selectedValues.length > 0) {\n if (selectValue.selectedValues.length === 1) {\n condition = { [fieldName]: { equals: selectValue.selectedValues[0] } };\n } else {\n condition = { [fieldName]: { in: selectValue.selectedValues } };\n }\n }\n break;\n }\n case 'checkbox': {\n const checkboxState = value as CheckboxFilterState;\n if (checkboxState === 'checked') {\n condition = { [fieldName]: { equals: 'true' } };\n } else if (checkboxState === 'unchecked') {\n condition = { [fieldName]: { equals: 'false' } };\n }\n break;\n }\n }\n if (condition) {\n conditions.push(condition);\n }\n });\n return conditions;\n};\n\n// Helper function to remove quick filter conditions from a 'where' clause\nconst cleanWhereClause = (clause: any, fieldsToClean: Set<string>): any => {\n if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {\n return clause;\n }\n\n const newClause: Record<string, any> = {};\n\n for (const key in clause) {\n if (key === 'and' || key === 'or') {\n const cleanedSubClauses = clause[key]\n .map((subClause: any) => cleanWhereClause(subClause, fieldsToClean))\n .filter(Boolean);\n\n if (cleanedSubClauses.length > 0) {\n newClause[key] = cleanedSubClauses;\n }\n } else if (!fieldsToClean.has(key)) {\n newClause[key] = clause[key];\n }\n }\n\n if (Object.keys(newClause).length === 0) {\n return null;\n }\n\n if (newClause.and?.length === 1 && Object.keys(newClause).length === 1) {\n return newClause.and[0];\n }\n if (newClause.or?.length === 1 && Object.keys(newClause).length === 1) {\n return newClause.or[0];\n }\n\n return newClause;\n};\n\n// Translates URL query conditions to the quick filter's internal state\nconst parseWhereClauseToFilterValues = (\n where: any,\n fields: FilterDetaild[],\n locale: SupportedLocale,\n): Record<string, any> => {\n const values: Record<string, any> = {};\n const fieldNames = new Set(fields.map((f) => f.name));\n\n const recursiveParse = (clause: any) => {\n if (!clause || typeof clause !== 'object') return;\n\n if (clause.and) {\n clause.and.forEach(recursiveParse);\n return;\n }\n if (clause.or) {\n clause.or.forEach(recursiveParse);\n return;\n }\n\n for (const fieldName in clause) {\n if (fieldNames.has(fieldName)) {\n const fieldDef = fields.find((f) => f.name === fieldName);\n const condition = clause[fieldName];\n\n if (fieldDef && condition && typeof condition === 'object') {\n if ('equals' in condition) {\n if (fieldDef.type === 'checkbox') {\n values[fieldName] = condition.equals == 'true' ? 'checked' : 'unchecked';\n } else if (fieldDef.type === 'select') {\n values[fieldName] = { selectedValues: [condition.equals] };\n }\n } else if ('in' in condition && Array.isArray(condition.in)) {\n if (fieldDef.type === 'select') {\n values[fieldName] = { selectedValues: condition.in };\n }\n } else if ('greater_than_equal' in condition || 'less_than_equal' in condition) {\n if (fieldDef.type === 'date') {\n const fromDate = condition.greater_than_equal\n ? new Date(condition.greater_than_equal)\n : null;\n const toDate = condition.less_than_equal ? new Date(condition.less_than_equal) : null;\n const allDateOptions = [...pastOptionKeys, ...futureOptionKeys];\n let matchedOption = null;\n\n for (const option of allDateOptions) {\n const range = getDateRangeForOption(option, locale);\n let isFromMatch;\n if (fromDate) {\n isFromMatch = range.from?.toDateString() === fromDate.toDateString();\n } else if (fromDate == null && range.to == undefined) {\n // all future: fromDate == null & range.to == undefined\n isFromMatch = true;\n }\n let isToMatch;\n if (toDate) {\n isToMatch = range.to?.toDateString() === toDate.toDateString();\n } else if (toDate == null && range.to == undefined) {\n // all future: fromDate == null & range.to == undefined\n isToMatch = true;\n }\n\n if (isFromMatch && isToMatch) {\n matchedOption = option;\n break;\n }\n }\n\n if (matchedOption) {\n values[fieldName] = {\n type: 'predefined',\n predefinedValue: matchedOption,\n };\n } else {\n values[fieldName] = {\n type: 'custom',\n customRange: {\n from: fromDate,\n to: toDate,\n },\n };\n }\n }\n }\n }\n }\n }\n };\n\n recursiveParse(where);\n return values;\n};\n\nconst QuickFilter = ({\n slug,\n filterList,\n}: {\n slug: string;\n filterList: (string | { name: string; width: string })[][];\n}) => {\n const localStorageKey = useMemo(() => `direct-filter-${slug}`, [slug]);\n\n const [fields, setFields] = useState<FilterDetaild[]>([]);\n const [filterRows, setFilterRows] = useState<FilterRow[]>([]);\n const [showFilters, setShowFilters] = useState(false);\n const { refineListData, query } = useListQuery();\n const { getEntityConfig } = useConfig();\n const { i18n } = useTranslation();\n const locale = i18n.language as SupportedLocale;\n const isSyncingFromQuery = useRef(false);\n\n const [filterValues, setFilterValues] = useState<Record<string, any>>(() => {\n if (typeof window == 'undefined') return {};\n try {\n const item = window.localStorage.getItem(localStorageKey);\n if (!item) return {};\n const dateTimeReviver = (key: string, value: any) => {\n const isoDateRegex = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$/;\n if (typeof value === 'string' && isoDateRegex.test(value)) {\n return new Date(value);\n }\n return value;\n };\n return JSON.parse(item, dateTimeReviver);\n } catch (error) {\n console.error('Error reading and parsing filters from localStorage.', error);\n return {};\n }\n });\n\n // Build the list of filter fields from config\n useEffect(() => {\n const collection = getEntityConfig({ collectionSlug: slug });\n const flattenedFieldConfigs = filterList.flatMap((row, rowIndex) =>\n row.map((field, fieldIndex) => ({\n field,\n rowIndex,\n fieldIndex,\n })),\n );\n const fieldNames = flattenedFieldConfigs.map(({ field }) =>\n typeof field === 'string' ? field : field.name,\n );\n const matchedFields = findFieldsByName(collection?.fields || [], fieldNames);\n const simplifiedFields: FilterDetaild[] = matchedFields.map((field) => {\n const label = (field as FieldAffectingData).label;\n const translatedLabel = getTranslation(label as string, i18n);\n const fieldName = (field as FieldAffectingData).name as string;\n const fieldConfig = flattenedFieldConfigs.find(({ field: f }) =>\n typeof f === 'string' ? f === fieldName : f.name === fieldName,\n );\n return {\n name: fieldName,\n label: translatedLabel as string,\n type: field.type,\n options: (field as SelectField).options as OptionObject[],\n row: fieldConfig ? fieldConfig.rowIndex : 0,\n width:\n typeof fieldConfig?.field === 'object' && 'width' in fieldConfig.field\n ? fieldConfig.field.width\n : undefined,\n };\n });\n const sortedFields = flattenedFieldConfigs\n .map(({ field }) => {\n const fieldName = typeof field === 'string' ? field : field.name;\n return simplifiedFields.find((f) => f.name === fieldName);\n })\n .filter((f): f is FilterDetaild => !!f);\n setFields(sortedFields);\n setFilterRows(groupFiltersByRow(sortedFields));\n }, [slug, filterList, getEntityConfig, i18n]);\n // Sync from URL (query.where) into internal state\n useEffect(() => {\n if (fields.length === 0) return;\n\n const valuesFromQuery: Record<string, any> = parseWhereClauseToFilterValues(\n query.where,\n fields,\n locale,\n );\n\n if (!isEqual(valuesFromQuery, filterValues)) {\n // Lock to prevent feedback loop when internal state changes\n isSyncingFromQuery.current = true;\n setFilterValues(valuesFromQuery);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query.where, fields]);\n\n // Sync internal state (filterValues) back into the URL\n useEffect(() => {\n // If the change originated from the first effect, skip to avoid infinite loop\n if (isSyncingFromQuery.current) {\n isSyncingFromQuery.current = false;\n return;\n }\n\n if (fields.length === 0) return;\n\n const quickFilterConditions = buildQuickFilterConditions(filterValues, fields, locale);\n const quickFilterFieldNames = new Set(fields.map((f) => f.name));\n const otherFilters = cleanWhereClause(query.where, quickFilterFieldNames);\n\n const allConditions = [...quickFilterConditions];\n if (otherFilters) {\n if (otherFilters.and && Array.isArray(otherFilters.and)) {\n allConditions.push(...otherFilters.and);\n } else if (Object.keys(otherFilters).length > 0) {\n allConditions.push(otherFilters);\n }\n }\n\n let newWhere: Record<string, any> = {};\n if (allConditions.length > 1) {\n newWhere = { and: allConditions };\n } else if (allConditions.length === 1) {\n newWhere = allConditions[0];\n }\n\n // Only update if the query has actually changed to avoid unnecessary updates\n if (!isEqual(newWhere, query.where)) {\n refineListData({\n columns: parseColumns(query.columns),\n where: newWhere,\n page: '1',\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [filterValues, fields, i18n.language, refineListData]);\n // Effect for persisting to localStorage\n useEffect(() => {\n try {\n if (Object.keys(filterValues).length > 0) {\n localStorage.setItem(localStorageKey, JSON.stringify(filterValues));\n } else {\n localStorage.removeItem(localStorageKey);\n }\n } catch (error) {\n console.error('Failed to save filters to localStorage', error);\n }\n }, [filterValues, localStorageKey]);\n\n // Updates only the internal state\n const handleFilterChange = useCallback((fieldName: string, value: any) => {\n setFilterValues((prev) => {\n const newValues = { ...prev };\n if (\n value === undefined ||\n value === null ||\n value === 'indeterminate' ||\n (value && value.type === 'none')\n ) {\n delete newValues[fieldName];\n } else {\n newValues[fieldName] = value;\n }\n return newValues;\n });\n }, []);\n\n // This function remains largely the same.\n const getActiveFiltersDetails = () => {\n const activeFilters: string[] = [];\n const locale = i18n.language as SupportedLocale;\n Object.entries(filterValues).forEach(([fieldName, value]) => {\n const field = fields.find((f) => f.name === fieldName);\n if (!field) return;\n\n switch (field.type) {\n case 'date':\n if (value !== undefined) {\n const dateValue = value as DateFilterValue;\n let dateDescription = '';\n\n if (dateValue.type === 'predefined' && dateValue.predefinedValue) {\n const { pastOptions, futureOptions } = getDateFilterOptions(locale);\n const allOptions = [...pastOptions, ...futureOptions];\n const option = allOptions.find((opt) => opt.value === dateValue.predefinedValue);\n dateDescription = option ? option.label : getLabel('custom', locale);\n } else if (dateValue.type === 'custom' || dateValue.customRange) {\n dateDescription = getLabel('custom', locale);\n }\n\n if (dateDescription) {\n activeFilters.push(`${field.label} (${dateDescription})`);\n }\n }\n break;\n case 'select': {\n const selectValue = value as SelectFilterValue;\n if (selectValue && selectValue.selectedValues && selectValue.selectedValues.length > 0) {\n const totalOptions = field.options?.length || 0;\n\n if (selectValue.selectedValues.length === totalOptions) {\n activeFilters.push(`${field.label} (${getLabel('all', locale)})`);\n } else if (selectValue.selectedValues.length === 1) {\n // Show the actual option name when only one is selected\n const selectedOption = field.options?.find(\n (opt: any) => opt.value === selectValue.selectedValues[0],\n );\n const optionLabel = selectedOption\n ? selectedOption.label\n : selectValue.selectedValues[0];\n activeFilters.push(`${field.label} (${optionLabel})`);\n } else {\n // Show count for multiple selections\n activeFilters.push(`${field.label} (${selectValue.selectedValues.length})`);\n }\n }\n break;\n }\n case 'checkbox':\n if (value !== 'indeterminate') {\n const checkboxValue =\n value === 'checked' ? getLabel('yes', locale) : getLabel('no', locale);\n activeFilters.push(`${field.label} (${checkboxValue})`);\n }\n break;\n }\n });\n\n return activeFilters;\n };\n\n const clearAllFilters = () => {\n setFilterValues({});\n };\n\n const memoizedFilterRows = useMemo(() => {\n return filterRows.map((row) => (\n <div key={row.rowNumber}>\n <div className='flex flex-wrap gap-6 mb-4'>\n {row.filters.map((field) => (\n <FilterField\n key={field.name}\n field={field}\n onFilterChange={handleFilterChange}\n value={filterValues[field.name]}\n />\n ))}\n </div>\n </div>\n ));\n }, [filterRows, handleFilterChange, filterValues]);\n\n const toggleFilters = () => {\n setShowFilters((prev) => !prev);\n };\n\n const activeFiltersDetails = getActiveFiltersDetails();\n const hasActiveFilters = activeFiltersDetails.length > 0;\n\n if (!fields.length) return null;\n\n return (\n <div className='filter-container useTw'>\n <div style={{ position: 'relative', top: '-24px', height: '0px' }}>\n <Button\n variant='outline'\n size='sm'\n onClick={toggleFilters}\n className={`flex items-center gap-2 bg-background border-muted-muted hover:bg-muted ${\n hasActiveFilters ? 'w-auto min-w-fit' : ''\n }`}\n >\n <Filter className={`h-4 w-4 ${hasActiveFilters ? 'fill-current' : ''}`} />\n\n {hasActiveFilters ? (\n <>\n <span className='text-sm truncate'>\n <strong>\n {`${activeFiltersDetails.length === 1 ? getLabel('activeFilterSingular', locale) : getLabel('activeFilterPlural', locale)}: `}\n </strong>{' '}\n {activeFiltersDetails.join(' • ')}\n </span>\n\n <span\n onClick={(e) => {\n e.stopPropagation();\n clearAllFilters();\n }}\n className='ml-1 p-0.5 hover:bg-muted rounded-sm transition-colors flex-shrink-0'\n >\n <X className='h-3 w-3 text-gray-500' />\n </span>\n </>\n ) : (\n <span className='text-sm truncate'>{getLabel('quickFilters', locale)}</span>\n )}\n\n {showFilters ? <ChevronUp className='h-4 w-4' /> : <ChevronDown className='h-4 w-4' />}\n </Button>\n </div>\n {showFilters && <div className={'p-4 pb-2 bg-muted'}>{memoizedFilterRows}</div>}\n </div>\n );\n};\n\nexport default QuickFilter;\n"],"names":["useCallback","useEffect","useMemo","useRef","useState","useConfig","useListQuery","useTranslation","getTranslation","FilterField","getLabel","groupFiltersByRow","parseColumns","ChevronDown","ChevronUp","Filter","X","getDateRangeForOption","isEqual","futureOptionKeys","getDateFilterOptions","pastOptionKeys","Button","findFieldsByName","fields","fieldNames","results","recursiveSearch","currentFields","filteredFields","filter","field","includes","name","push","forEach","item","type","Array","isArray","tabs","tab","blocks","block","buildQuickFilterConditions","values","fieldDefs","locale","conditions","Object","entries","fieldName","value","fieldDef","find","f","condition","dateValue","from","to","predefinedValue","range","customRange","Date","dateQuery","greater_than_equal","less_than_equal","keys","length","selectValue","selectedValues","equals","in","checkboxState","cleanWhereClause","clause","fieldsToClean","newClause","key","cleanedSubClauses","map","subClause","Boolean","has","and","or","parseWhereClauseToFilterValues","where","Set","recursiveParse","fromDate","toDate","allDateOptions","matchedOption","option","isFromMatch","toDateString","undefined","isToMatch","QuickFilter","slug","filterList","localStorageKey","setFields","filterRows","setFilterRows","showFilters","setShowFilters","refineListData","query","getEntityConfig","i18n","language","isSyncingFromQuery","filterValues","setFilterValues","window","localStorage","getItem","dateTimeReviver","isoDateRegex","test","JSON","parse","error","console","collection","collectionSlug","flattenedFieldConfigs","flatMap","row","rowIndex","fieldIndex","matchedFields","simplifiedFields","label","translatedLabel","fieldConfig","options","width","sortedFields","valuesFromQuery","current","quickFilterConditions","quickFilterFieldNames","otherFilters","allConditions","newWhere","columns","page","setItem","stringify","removeItem","handleFilterChange","prev","newValues","getActiveFiltersDetails","activeFilters","dateDescription","pastOptions","futureOptions","allOptions","opt","totalOptions","selectedOption","optionLabel","checkboxValue","clearAllFilters","memoizedFilterRows","div","className","filters","onFilterChange","rowNumber","toggleFilters","activeFiltersDetails","hasActiveFilters","style","position","top","height","variant","size","onClick","span","strong","join","e","stopPropagation"],"mappings":"AAAA;;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAC1E,SAASC,SAAS,EAAEC,YAAY,EAAEC,cAAc,QAAQ,iBAAiB;AAEzE,SAASC,cAAc,QAAQ,2BAA2B;AAC1D,OAAOC,iBAAiB,gBAAgB;AACxC,SAASC,QAAQ,QAAyB,WAAW;AAQrD,SAASC,iBAAiB,EAAEC,YAAY,QAAQ,iCAAiC;AACjF,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,CAAC,QAAQ,eAAe;AAEjE,SAASC,qBAAqB,QAAQ,+BAA+B;AACrE,SAASC,OAAO,QAAQ,SAAS;AACjC,SACEC,gBAAgB,EAChBC,oBAAoB,EACpBC,cAAc,QACT,0CAA0C;AACjD,SAASC,MAAM,QAAQ,cAAc;AAErC,4CAA4C;AAC5C,SAASC,iBAAiBC,MAAqB,EAAEC,UAAoB;IACnE,MAAMC,UAAyB,EAAE;IACjC,SAASC,gBAAgBC,aAA4B;QACnD,MAAMC,iBAAiBD,cAAcE,MAAM,CACzC,CAACC,QAAU,UAAUA,SAASN,WAAWO,QAAQ,CAACD,MAAME,IAAI;QAE9DP,QAAQQ,IAAI,IAAIL;QAChBD,cAAcO,OAAO,CAAC,CAACC;YACrB,IACE,AAACA,CAAAA,KAAKC,IAAI,KAAK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D,4BAAc,KAAC5F;4BAAU4J,WAAU;2CAAe,KAAC7J;4BAAY6J,WAAU;;;;;YAG7EhE,6BAAe,KAAC+D;gBAAIC,WAAW;0BAAsBF;;;;AAG5D;AAEA,eAAerE,YAAY"}
|
|
@@ -6,7 +6,8 @@ interface CheckboxFilterProps {
|
|
|
6
6
|
onChange: (state: CheckboxFilterState) => void;
|
|
7
7
|
locale?: Locale;
|
|
8
8
|
className?: string;
|
|
9
|
+
style?: React.CSSProperties;
|
|
9
10
|
}
|
|
10
|
-
export declare function CheckboxFilter({ label, checkboxLabel, value, onChange, locale, className, }: CheckboxFilterProps): import("react").JSX.Element;
|
|
11
|
+
export declare function CheckboxFilter({ label, checkboxLabel, value, onChange, locale, className, style }: CheckboxFilterProps): import("react").JSX.Element;
|
|
11
12
|
export {};
|
|
12
13
|
//# sourceMappingURL=checkbox-filter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/components/checkbox-filter.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"checkbox-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/components/checkbox-filter.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAOnE,UAAU,mBAAmB;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,mBAAmB,CAAA;IAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAA;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CAC5B;AAED,wBAAgB,cAAc,CAAC,EAC7B,KAAK,EACL,aAAa,EACb,KAAuB,EACvB,QAAQ,EACR,MAAyC,EACzC,SAAS,EACT,KAAK,EACN,EAAE,mBAAmB,+BA4GrB"}
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
import { X } from 'lucide-react';
|
|
5
|
-
import { Label } from '../../ui/label';
|
|
6
5
|
import { cn } from '../../lib/utils';
|
|
6
|
+
import { Label } from '../../ui/label';
|
|
7
7
|
import { Button } from '../../ui/button';
|
|
8
|
+
import { getLabel } from '../../labels';
|
|
8
9
|
export function CheckboxFilter({ label, checkboxLabel, value = 'indeterminate', onChange, locale = {
|
|
9
10
|
code: 'he',
|
|
10
11
|
direction: 'rtl'
|
|
11
|
-
}, className }) {
|
|
12
|
+
}, className, style }) {
|
|
12
13
|
const [internalState, setInternalState] = useState(value);
|
|
13
|
-
const
|
|
14
|
+
const isRTL = locale.direction === 'rtl';
|
|
14
15
|
// Sync internal state with external value prop
|
|
15
16
|
useEffect(()=>{
|
|
16
17
|
setInternalState(value);
|
|
@@ -27,15 +28,16 @@ export function CheckboxFilter({ label, checkboxLabel, value = 'indeterminate',
|
|
|
27
28
|
};
|
|
28
29
|
const isActive = internalState === 'checked' || internalState === 'unchecked';
|
|
29
30
|
const labels_toggle = {
|
|
30
|
-
yes:
|
|
31
|
-
no:
|
|
31
|
+
yes: getLabel('yes', locale.code),
|
|
32
|
+
no: getLabel('no', locale.code)
|
|
32
33
|
};
|
|
33
34
|
return /*#__PURE__*/ _jsxs("div", {
|
|
34
35
|
className: cn('space-y-1', className),
|
|
35
36
|
dir: locale.direction,
|
|
37
|
+
style: style,
|
|
36
38
|
children: [
|
|
37
39
|
label && /*#__PURE__*/ _jsx(Label, {
|
|
38
|
-
className: cn('useTw text-sm font-medium',
|
|
40
|
+
className: cn('useTw text-sm font-medium', isRTL && 'text-right block'),
|
|
39
41
|
children: label
|
|
40
42
|
}),
|
|
41
43
|
/*#__PURE__*/ _jsxs("div", {
|
|
@@ -64,7 +66,7 @@ export function CheckboxFilter({ label, checkboxLabel, value = 'indeterminate',
|
|
|
64
66
|
})
|
|
65
67
|
}),
|
|
66
68
|
checkboxLabel && /*#__PURE__*/ _jsx(Label, {
|
|
67
|
-
className: cn('useTw cursor-pointer select-none text-sm',
|
|
69
|
+
className: cn('useTw cursor-pointer select-none text-sm', isRTL && 'text-right', locale.direction === 'rtl' && 'order-2'),
|
|
68
70
|
children: checkboxLabel
|
|
69
71
|
}),
|
|
70
72
|
(internalState === 'checked' || internalState === 'unchecked') && /*#__PURE__*/ _jsx(Button, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/filters/components/checkbox-filter.tsx"],"sourcesContent":["'use client'
|
|
1
|
+
{"version":3,"sources":["../../../src/filters/components/checkbox-filter.tsx"],"sourcesContent":["'use client'\n\nimport { useEffect, useState } from 'react'\nimport { X } from 'lucide-react'\nimport { CheckboxFilterState, Locale } from '../types/filters-type'\nimport { cn } from '../../lib/utils'\nimport { Label } from '../../ui/label'\nimport { Button } from '../../ui/button'\nimport { getLabel } from '../../labels'\n\n\ninterface CheckboxFilterProps {\n label?: string\n checkboxLabel: string\n value?: CheckboxFilterState\n onChange: (state: CheckboxFilterState) => void\n locale?: Locale\n className?: string\n style?: React.CSSProperties\n}\n\nexport function CheckboxFilter({\n label,\n checkboxLabel,\n value = 'indeterminate',\n onChange,\n locale = { code: 'he', direction: 'rtl' },\n className,\n style\n}: CheckboxFilterProps) {\n const [internalState, setInternalState] = useState<CheckboxFilterState>(value)\n\n const isRTL = locale.direction === 'rtl'\n\n // Sync internal state with external value prop\n useEffect(() => {\n setInternalState(value)\n }, [value])\n\n const handleToggle = (newState: 'checked' | 'unchecked') => {\n setInternalState(newState)\n onChange(newState)\n }\n\n const handleClear = () => {\n setInternalState('indeterminate')\n onChange('indeterminate')\n }\n\n const isActive = internalState === 'checked' || internalState === 'unchecked'\n\n const labels_toggle = {\n yes: getLabel('yes', locale.code),\n no: getLabel('no', locale.code),\n }\n\n return (\n <div className={cn('space-y-1', className)} dir={locale.direction} style={style}>\n {label && (\n <Label className={cn('useTw text-sm font-medium', isRTL && 'text-right block')}>\n {label}\n </Label>\n )}\n\n <div\n className={cn(\n 'flex items-center gap-3 transition-colors py-px',\n locale.direction === 'rtl' && 'justify-start',\n )}\n >\n <div className={cn('flex items-center', locale.direction === 'rtl' && 'order-first')}>\n {/* Two Button Toggle */}\n <div className=\"flex rounded-md border overflow-hidden\">\n {/* In RTL, YES comes first, in LTR, NO comes first */}\n <Button\n variant={internalState === 'checked' ? 'default' : 'ghost'}\n size=\"sm\"\n className={cn(\n 'useTW px-3 py-1 text-xs rounded-none border-0',\n internalState === 'checked'\n ? 'bg-green-600 text-white hover:bg-green-700'\n : 'bg-background text-muted-foreground hover:bg-muted',\n )}\n onClick={() => handleToggle('checked')}\n >\n {labels_toggle.yes}\n </Button>\n <Button\n variant={internalState === 'unchecked' ? 'default' : 'ghost'}\n size=\"sm\"\n className={cn(\n 'useTw px-3 py-1 text-xs rounded-none border-0 border-l',\n internalState === 'unchecked'\n ? 'bg-red-600 text-white hover:bg-red-700'\n : 'bg-background text-muted-foreground hover:bg-muted',\n )}\n onClick={() => handleToggle('unchecked')}\n >\n {labels_toggle.no}\n </Button>\n </div>\n </div>\n\n {checkboxLabel && (\n <Label\n className={cn(\n 'useTw cursor-pointer select-none text-sm',\n isRTL && 'text-right',\n locale.direction === 'rtl' && 'order-2',\n )}\n >\n {checkboxLabel}\n </Label>\n )}\n\n {(internalState === 'checked' || internalState === 'unchecked') && (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n className={cn(\n 'h-5 w-5 p-0 hover:bg-muted rounded-full -mt-1',\n checkboxLabel\n ? locale.direction === 'rtl'\n ? 'order-last -ml-1'\n : 'order-last -mr-1'\n : locale.direction === 'rtl'\n ? 'ml-[80px] order-last'\n : 'mr-[80px] order-last',\n )}\n onClick={handleClear}\n >\n <X className=\"h-3 w-3\" />\n </Button>\n )}\n </div>\n </div>\n )\n}"],"names":["useEffect","useState","X","cn","Label","Button","getLabel","CheckboxFilter","label","checkboxLabel","value","onChange","locale","code","direction","className","style","internalState","setInternalState","isRTL","handleToggle","newState","handleClear","isActive","labels_toggle","yes","no","div","dir","variant","size","onClick"],"mappings":"AAAA;;AAEA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAC3C,SAASC,CAAC,QAAQ,eAAc;AAEhC,SAASC,EAAE,QAAQ,kBAAiB;AACpC,SAASC,KAAK,QAAQ,iBAAgB;AACtC,SAASC,MAAM,QAAQ,kBAAiB;AACxC,SAASC,QAAQ,QAAQ,eAAc;AAavC,OAAO,SAASC,eAAe,EAC7BC,KAAK,EACLC,aAAa,EACbC,QAAQ,eAAe,EACvBC,QAAQ,EACRC,SAAS;IAAEC,MAAM;IAAMC,WAAW;AAAM,CAAC,EACzCC,SAAS,EACTC,KAAK,EACe;IACpB,MAAM,CAACC,eAAeC,iBAAiB,GAAGjB,SAA8BS;IAExE,MAAMS,QAAQP,OAAOE,SAAS,KAAK;IAEnC,+CAA+C;IAC/Cd,UAAU;QACRkB,iBAAiBR;IACnB,GAAG;QAACA;KAAM;IAEV,MAAMU,eAAe,CAACC;QACpBH,iBAAiBG;QACjBV,SAASU;IACX;IAEA,MAAMC,cAAc;QAClBJ,iBAAiB;QACjBP,SAAS;IACX;IAEA,MAAMY,WAAWN,kBAAkB,aAAaA,kBAAkB;IAElE,MAAMO,gBAAgB;QACpBC,KAAKnB,SAAS,OAAOM,OAAOC,IAAI;QAChCa,IAAIpB,SAAS,MAAMM,OAAOC,IAAI;IAChC;IAEA,qBACE,MAACc;QAAIZ,WAAWZ,GAAG,aAAaY;QAAYa,KAAKhB,OAAOE,SAAS;QAAEE,OAAOA;;YACvER,uBACC,KAACJ;gBAAMW,WAAWZ,GAAG,6BAA6BgB,SAAS;0BACxDX;;0BAIL,MAACmB;gBACCZ,WAAWZ,GACT,mDACAS,OAAOE,SAAS,KAAK,SAAS;;kCAGhC,KAACa;wBAAIZ,WAAWZ,GAAG,qBAAqBS,OAAOE,SAAS,KAAK,SAAS;kCAEpE,cAAA,MAACa;4BAAIZ,WAAU;;8CAEb,KAACV;oCACCwB,SAASZ,kBAAkB,YAAY,YAAY;oCACnDa,MAAK;oCACLf,WAAWZ,GACT,iDACAc,kBAAkB,YACd,+CACA;oCAENc,SAAS,IAAMX,aAAa;8CAE3BI,cAAcC,GAAG;;8CAEpB,KAACpB;oCACCwB,SAASZ,kBAAkB,cAAc,YAAY;oCACrDa,MAAK;oCACLf,WAAWZ,GACT,0DACAc,kBAAkB,cACd,2CACA;oCAENc,SAAS,IAAMX,aAAa;8CAE3BI,cAAcE,EAAE;;;;;oBAKtBjB,+BACC,KAACL;wBACCW,WAAWZ,GACT,4CACAgB,SAAS,cACTP,OAAOE,SAAS,KAAK,SAAS;kCAG/BL;;oBAIHQ,CAAAA,kBAAkB,aAAaA,kBAAkB,WAAU,mBAC3D,KAACZ;wBACCwB,SAAQ;wBACRC,MAAK;wBACLf,WAAWZ,GACT,iDACAM,gBACIG,OAAOE,SAAS,KAAK,QACnB,qBACA,qBACFF,OAAOE,SAAS,KAAK,QACnB,yBACA;wBAERiB,SAAST;kCAET,cAAA,KAACpB;4BAAEa,WAAU;;;;;;;AAMzB"}
|
|
@@ -5,7 +5,8 @@ interface DateFilterProps {
|
|
|
5
5
|
onChange: (value: DateFilterValue) => void;
|
|
6
6
|
locale?: Locale;
|
|
7
7
|
className?: string;
|
|
8
|
+
style?: React.CSSProperties;
|
|
8
9
|
}
|
|
9
|
-
export declare function DateFilter({ label, value, onChange, locale, className, }: DateFilterProps): import("react").JSX.Element;
|
|
10
|
+
export declare function DateFilter({ label, value, onChange, locale, className, style, }: DateFilterProps): import("react").JSX.Element;
|
|
10
11
|
export {};
|
|
11
12
|
//# sourceMappingURL=date-filter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/components/date-filter.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"date-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/components/date-filter.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAa,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAW3E,UAAU,eAAe;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,QAAQ,EACR,MAAyC,EACzC,SAAS,EACT,KAAK,GACN,EAAE,eAAe,+BAiVjB"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
import { CalendarIcon, ChevronDown, X } from 'lucide-react';
|
|
5
|
-
import { futureDateFilterOptions, futureDateFilterOptionsEn, pastDateFilterOptions, pastDateFilterOptionsEn } from '../constants/date-filter-options';
|
|
6
5
|
import { formatDate, getDateRangeForOption } from '../utils/date-helpers';
|
|
7
6
|
import { Button } from '../../ui/button';
|
|
8
7
|
import { cn } from '../../lib/utils';
|
|
@@ -10,10 +9,12 @@ import { Label } from '../../ui/label';
|
|
|
10
9
|
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover';
|
|
11
10
|
import { Separator } from '../../ui/separator';
|
|
12
11
|
import { Calendar } from '../../ui/calendar';
|
|
12
|
+
import { getDateFilterOptions } from '../constants/date-filter-options';
|
|
13
|
+
import { getLabel } from '../../labels';
|
|
13
14
|
export function DateFilter({ label, value, onChange, locale = {
|
|
14
15
|
code: 'he',
|
|
15
16
|
direction: 'rtl'
|
|
16
|
-
}, className }) {
|
|
17
|
+
}, className, style }) {
|
|
17
18
|
const [internalValue, setInternalValue] = useState(value);
|
|
18
19
|
const [customRange, setCustomRange] = useState({
|
|
19
20
|
from: undefined,
|
|
@@ -23,9 +24,9 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
23
24
|
const [isOpen, setIsOpen] = useState(false);
|
|
24
25
|
const [openFromCalendar, setOpenFromCalendar] = useState(false);
|
|
25
26
|
const [openToCalendar, setOpenToCalendar] = useState(false);
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
27
|
+
const isRTL = locale.direction === 'rtl';
|
|
28
|
+
const localeCode = locale.code;
|
|
29
|
+
const { pastOptions, futureOptions } = getDateFilterOptions(localeCode);
|
|
29
30
|
// Sync internal state with external value prop
|
|
30
31
|
useEffect(()=>{
|
|
31
32
|
setInternalValue(value);
|
|
@@ -36,15 +37,15 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
36
37
|
value
|
|
37
38
|
]);
|
|
38
39
|
const labels = {
|
|
39
|
-
selectOption:
|
|
40
|
-
from:
|
|
41
|
-
to:
|
|
42
|
-
selectDate:
|
|
43
|
-
past:
|
|
44
|
-
future:
|
|
45
|
-
custom:
|
|
46
|
-
apply:
|
|
47
|
-
cancel:
|
|
40
|
+
selectOption: getLabel('selectOption', localeCode),
|
|
41
|
+
from: getLabel('from', localeCode),
|
|
42
|
+
to: getLabel('to', localeCode),
|
|
43
|
+
selectDate: getLabel('selectDate', localeCode),
|
|
44
|
+
past: getLabel('past', localeCode),
|
|
45
|
+
future: getLabel('future', localeCode),
|
|
46
|
+
custom: getLabel('customRange', localeCode),
|
|
47
|
+
apply: getLabel('apply', localeCode),
|
|
48
|
+
cancel: getLabel('cancel', localeCode)
|
|
48
49
|
};
|
|
49
50
|
const handlePredefinedSelect = (optionValue)=>{
|
|
50
51
|
setShowCustom(false);
|
|
@@ -122,7 +123,7 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
122
123
|
};
|
|
123
124
|
const formatDateRange = (description)=>{
|
|
124
125
|
// Check if description contains a date range (has " - " in it)
|
|
125
|
-
if (description.includes(' - ') &&
|
|
126
|
+
if (description.includes(' - ') && isRTL) {
|
|
126
127
|
// Split by " - " and reverse the order for RTL
|
|
127
128
|
const parts = description.replace(/[()]/g, '').split(' - ');
|
|
128
129
|
if (parts.length === 2) {
|
|
@@ -136,7 +137,7 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
136
137
|
const formattedDescription = formatDateRange(dateRange.description);
|
|
137
138
|
return /*#__PURE__*/ _jsx(Button, {
|
|
138
139
|
variant: "ghost",
|
|
139
|
-
className: cn(' w-full h-auto py-1 px-2 text-xs leading-tight justify-start',
|
|
140
|
+
className: cn(' w-full h-auto py-1 px-2 text-xs leading-tight justify-start', isRTL ? ' text-right' : ' text-left', internalValue?.predefinedValue === option.value && 'bg-accent'),
|
|
140
141
|
onClick: ()=>handlePredefinedSelect(option.value),
|
|
141
142
|
children: /*#__PURE__*/ _jsxs("div", {
|
|
142
143
|
className: cn('flex flex-col'),
|
|
@@ -157,9 +158,10 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
157
158
|
return /*#__PURE__*/ _jsxs("div", {
|
|
158
159
|
className: cn('useTw space-y-1', className),
|
|
159
160
|
dir: locale.direction,
|
|
161
|
+
style: style,
|
|
160
162
|
children: [
|
|
161
163
|
label && /*#__PURE__*/ _jsx(Label, {
|
|
162
|
-
className: cn('useTw text-sm font-medium',
|
|
164
|
+
className: cn('useTw text-sm font-medium', isRTL && 'text-right block'),
|
|
163
165
|
children: label
|
|
164
166
|
}),
|
|
165
167
|
/*#__PURE__*/ _jsxs("div", {
|
|
@@ -179,7 +181,7 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
179
181
|
className: "useTw w-full justify-between bg-background relative min-w-70",
|
|
180
182
|
children: [
|
|
181
183
|
/*#__PURE__*/ _jsx("span", {
|
|
182
|
-
className: `useTw truncate ${
|
|
184
|
+
className: `useTw truncate ${isRTL && 'text-right'}`,
|
|
183
185
|
children: getDisplayValue()
|
|
184
186
|
}),
|
|
185
187
|
/*#__PURE__*/ _jsx(ChevronDown, {
|
|
@@ -200,7 +202,7 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
200
202
|
className: "space-y-1",
|
|
201
203
|
children: [
|
|
202
204
|
/*#__PURE__*/ _jsx("div", {
|
|
203
|
-
className: cn('text-sm font-semibold text-muted-foreground mb-2',
|
|
205
|
+
className: cn('text-sm font-semibold text-muted-foreground mb-2', isRTL && 'text-right'),
|
|
204
206
|
children: labels.future
|
|
205
207
|
}),
|
|
206
208
|
/*#__PURE__*/ _jsx("div", {
|
|
@@ -215,7 +217,7 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
215
217
|
className: "space-y-1",
|
|
216
218
|
children: [
|
|
217
219
|
/*#__PURE__*/ _jsx("div", {
|
|
218
|
-
className: cn('text-sm font-semibold text-muted-foreground mb-2',
|
|
220
|
+
className: cn('text-sm font-semibold text-muted-foreground mb-2', isRTL && 'text-right'),
|
|
219
221
|
children: labels.past
|
|
220
222
|
}),
|
|
221
223
|
/*#__PURE__*/ _jsx("div", {
|
|
@@ -236,7 +238,7 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
236
238
|
children: [
|
|
237
239
|
/*#__PURE__*/ _jsx(Button, {
|
|
238
240
|
variant: "ghost",
|
|
239
|
-
className: cn('useTw w-full justify-start h-auto py-2 px-2', (showCustom || internalValue?.type === 'custom') && 'bg-accent',
|
|
241
|
+
className: cn('useTw w-full justify-start h-auto py-2 px-2', (showCustom || internalValue?.type === 'custom') && 'bg-accent', isRTL && 'justify-start text-right'),
|
|
240
242
|
onClick: handleCustomSelect,
|
|
241
243
|
children: labels.custom
|
|
242
244
|
}),
|
|
@@ -250,7 +252,7 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
250
252
|
className: cn('flex items-center gap-2'),
|
|
251
253
|
children: [
|
|
252
254
|
/*#__PURE__*/ _jsx(Label, {
|
|
253
|
-
className: cn('useTw text-xs w-[20%]',
|
|
255
|
+
className: cn('useTw text-xs w-[20%]', isRTL && 'text-right'),
|
|
254
256
|
children: labels.from
|
|
255
257
|
}),
|
|
256
258
|
/*#__PURE__*/ _jsxs(Popover, {
|
|
@@ -299,7 +301,7 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
299
301
|
className: cn('flex items-center gap-2'),
|
|
300
302
|
children: [
|
|
301
303
|
/*#__PURE__*/ _jsx(Label, {
|
|
302
|
-
className: cn('useTw
|
|
304
|
+
className: cn('useTw text-xs w-[20%]', isRTL && 'text-right'),
|
|
303
305
|
children: labels.to
|
|
304
306
|
}),
|
|
305
307
|
/*#__PURE__*/ _jsxs(Popover, {
|
|
@@ -373,7 +375,7 @@ export function DateFilter({ label, value, onChange, locale = {
|
|
|
373
375
|
]
|
|
374
376
|
}),
|
|
375
377
|
hasValue() && /*#__PURE__*/ _jsx("button", {
|
|
376
|
-
className: `useTw absolute ${
|
|
378
|
+
className: `useTw absolute ${isRTL ? 'left-8' : 'right-8'} top-1/2 -translate-y-1/2 h-4 w-4 p-0 hover:bg-muted rounded-sm flex items-center justify-center z-10 `,
|
|
377
379
|
onClick: (e)=>{
|
|
378
380
|
e.stopPropagation();
|
|
379
381
|
handleClearAll();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/filters/components/date-filter.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\nimport { CalendarIcon, ChevronDown, X } from 'lucide-react';\n\nimport {\n futureDateFilterOptions,\n futureDateFilterOptionsEn,\n pastDateFilterOptions,\n pastDateFilterOptionsEn,\n} from '../constants/date-filter-options';\nimport { formatDate, getDateRangeForOption } from '../utils/date-helpers';\nimport { DateFilterValue, DateRange, Locale } from '../types/filters-type';\nimport { Button } from '../../ui/button';\nimport { cn } from '../../lib/utils';\nimport { Label } from '../../ui/label';\nimport { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover';\nimport { Separator } from '../../ui/separator';\nimport { Calendar } from '../../ui/calendar';\n\ninterface DateFilterProps {\n label?: string;\n value?: DateFilterValue;\n onChange: (value: DateFilterValue) => void;\n locale?: Locale;\n className?: string;\n}\n\nexport function DateFilter({\n label,\n value,\n onChange,\n locale = { code: 'he', direction: 'rtl' },\n className,\n}: DateFilterProps) {\n const [internalValue, setInternalValue] = useState<DateFilterValue | undefined>(value);\n const [customRange, setCustomRange] = useState<DateRange>({ from: undefined, to: undefined });\n const [showCustom, setShowCustom] = useState(false);\n const [isOpen, setIsOpen] = useState(false);\n const [openFromCalendar, setOpenFromCalendar] = useState(false);\n const [openToCalendar, setOpenToCalendar] = useState(false);\n\n const isHebrew = locale.code === 'he';\n const pastOptions = isHebrew ? pastDateFilterOptions : pastDateFilterOptionsEn;\n const futureOptions = isHebrew ? futureDateFilterOptions : futureDateFilterOptionsEn;\n\n // Sync internal state with external value prop\n useEffect(() => {\n setInternalValue(value);\n if (value?.type === 'custom' && value.customRange) {\n setCustomRange(value.customRange);\n }\n }, [value]);\n\n const labels = {\n selectOption: isHebrew ? 'בחר אפשרות' : 'Select Option',\n from: isHebrew ? 'מתאריך' : 'From',\n to: isHebrew ? 'עד תאריך' : 'To',\n selectDate: isHebrew ? 'בחר תאריך' : 'Select Date',\n past: isHebrew ? 'עבר' : 'Past',\n future: isHebrew ? 'עתיד' : 'Future',\n custom: isHebrew ? 'טווח מותאם אישית' : 'Custom Range',\n apply: isHebrew ? 'החל' : 'Apply',\n cancel: isHebrew ? 'ביטול' : 'Cancel',\n };\n\n const handlePredefinedSelect = (optionValue: string) => {\n setShowCustom(false);\n setIsOpen(false);\n\n const dateRange = getDateRangeForOption(optionValue, locale.code);\n const newValue: DateFilterValue = {\n type: 'predefined',\n predefinedValue: optionValue,\n customRange: { from: dateRange.from, to: dateRange.to },\n };\n\n setInternalValue(newValue);\n onChange(newValue);\n };\n\n const handleCustomSelect = () => {\n setShowCustom(true);\n };\n\n const handleCustomRangeChange = (newRange: DateRange) => {\n setCustomRange(newRange);\n };\n\n const handleApplyCustomRange = () => {\n const newValue: DateFilterValue = {\n type: 'custom',\n customRange,\n };\n\n setInternalValue(newValue);\n onChange(newValue);\n setIsOpen(false);\n setShowCustom(false);\n };\n\n const handleCancelCustomRange = () => {\n setIsOpen(false);\n setShowCustom(false);\n setCustomRange({ from: undefined, to: undefined });\n };\n\n const handleClearAll = () => {\n setInternalValue(undefined);\n setCustomRange({ from: undefined, to: undefined });\n setShowCustom(false);\n onChange({} as DateFilterValue);\n };\n\n const hasValue = () => {\n return (\n internalValue && (internalValue.type === 'predefined' || internalValue.type === 'custom')\n );\n };\n\n const getDisplayValue = () => {\n if (internalValue?.type === 'custom' && internalValue.customRange) {\n const { from, to } = internalValue.customRange;\n if (from && to) {\n return `${formatDate(from, 'dd/MM/yyyy')}-${formatDate(to, 'dd/MM/yyyy')}`;\n } else if (from) {\n return `${labels.from}: ${formatDate(from, 'dd/MM/yyyy')}`;\n } else if (to) {\n return `${labels.to}: ${formatDate(to, 'dd/MM/yyyy')}`;\n }\n return labels.custom;\n }\n\n if (internalValue?.type === 'predefined' && internalValue.predefinedValue) {\n const allOptions = [...pastOptions, ...futureOptions];\n const option = allOptions.find((opt) => opt.value === internalValue.predefinedValue);\n const dateRange = getDateRangeForOption(internalValue.predefinedValue, locale.code);\n return `${option?.label || internalValue.predefinedValue} ${dateRange.description}`;\n }\n\n return labels.selectOption;\n };\n\n const formatDateRange = (description: string) => {\n // Check if description contains a date range (has \" - \" in it)\n if (description.includes(' - ') && isHebrew) {\n // Split by \" - \" and reverse the order for RTL\n const parts = description.replace(/[()]/g, '').split(' - ');\n if (parts.length === 2) {\n return `(${parts[1]}-${parts[0]})`;\n }\n }\n return description;\n };\n\n const renderOptionWithDate = (option: { value: string; label: string }) => {\n const dateRange = getDateRangeForOption(option.value, locale.code);\n const formattedDescription = formatDateRange(dateRange.description);\n\n return (\n <Button\n key={option.value}\n variant='ghost'\n className={cn(\n ' w-full h-auto py-1 px-2 text-xs leading-tight justify-start',\n isHebrew ? ' text-right' : ' text-left',\n internalValue?.predefinedValue === option.value && 'bg-accent',\n )}\n onClick={() => handlePredefinedSelect(option.value)}\n >\n <div className={cn('flex flex-col')}>\n <span className='font-medium'>{option.label}</span>\n <span className='text-[10px] text-muted-foreground' dir={locale.direction}>\n {formattedDescription}\n </span>\n </div>\n </Button>\n );\n };\n\n return (\n <div className={cn('useTw space-y-1', className)} dir={locale.direction}>\n {label && (\n <Label className={cn('useTw text-sm font-medium', isHebrew && 'text-right block')}>\n {label}\n </Label>\n )}\n\n <div className='relative useTw'>\n <Popover open={isOpen} onOpenChange={setIsOpen}>\n <PopoverTrigger asChild className='useTw'>\n <Button\n variant='outline'\n role='combobox'\n aria-expanded={isOpen}\n className='useTw w-full justify-between bg-background relative min-w-70'\n >\n <span className={`useTw truncate ${isHebrew && 'text-right'}`}>\n {getDisplayValue()}\n </span>\n <ChevronDown className='useTw h-4 w-4 shrink-0 opacity-50' />\n </Button>\n </PopoverTrigger>\n <PopoverContent className='useTw w-80 p-0'>\n <div className='p-4'>\n <div className='grid grid-cols-2 gap-4'>\n {/* Future Options - Left column */}\n <div className='space-y-1'>\n <div\n className={cn(\n 'text-sm font-semibold text-muted-foreground mb-2',\n isHebrew && 'text-right',\n )}\n >\n {labels.future}\n </div>\n <div className='space-y-0.5'>\n {futureOptions.map((option) => (\n <div key={option.value}>{renderOptionWithDate(option)}</div>\n ))}\n </div>\n </div>\n\n {/* Past Options - Right column */}\n <div className='space-y-1'>\n <div\n className={cn(\n 'text-sm font-semibold text-muted-foreground mb-2',\n isHebrew && 'text-right',\n )}\n >\n {labels.past}\n </div>\n <div className='space-y-0.5'>\n {pastOptions.map((option) => (\n <div key={option.value}>{renderOptionWithDate(option)}</div>\n ))}\n </div>\n </div>\n </div>\n\n <Separator className='my-4' />\n\n {/* Custom Option */}\n <div className='space-y-3'>\n <Button\n variant='ghost'\n className={cn(\n 'useTw w-full justify-start h-auto py-2 px-2',\n (showCustom || internalValue?.type === 'custom') && 'bg-accent',\n isHebrew && 'justify-start text-right',\n )}\n onClick={handleCustomSelect}\n >\n {labels.custom}\n </Button>\n\n {/* Custom Date Range - appears next to custom label */}\n {showCustom && (\n <div className='space-y-3 pl-2'>\n <div className='grid grid-cols-1 gap-3'>\n {/* From Date */}\n <div className={cn('flex items-center gap-2')}>\n <Label\n className={cn(\n 'useTw text-xs w-[20%]',\n isHebrew && 'text-right text-start',\n )}\n >\n {labels.from}\n </Label>\n <Popover open={openFromCalendar} onOpenChange={setOpenFromCalendar}>\n <PopoverTrigger asChild className='useTw'>\n <Button\n variant='outline'\n className={cn(\n 'useTw w-[60%] justify-start text-left font-normal text-xs h-8 bg-background',\n !customRange.from && 'text-muted-foreground',\n )}\n >\n <CalendarIcon className='useTw mr-1 h-3 w-3' />\n <span dir={locale.direction}>\n {customRange.from\n ? formatDate(customRange.from, 'dd/MM/yyyy')\n : labels.selectDate}\n </span>\n </Button>\n </PopoverTrigger>\n <PopoverContent className='useTw w-auto p-0' align='start'>\n <Calendar\n mode='single'\n selected={customRange.from}\n onSelect={(date) => {\n handleCustomRangeChange({ ...customRange, from: date });\n setOpenFromCalendar(false);\n }}\n initialFocus\n className='useTw'\n />\n </PopoverContent>\n </Popover>\n </div>\n\n {/* To Date */}\n <div className={cn('flex items-center gap-2')}>\n <Label\n className={cn(\n 'useTw useTw text-xs w-[20%]',\n isHebrew && 'text-right text-strat',\n )}\n >\n {labels.to}\n </Label>\n <Popover open={openToCalendar} onOpenChange={setOpenToCalendar}>\n <PopoverTrigger asChild className='useTw'>\n <Button\n variant='outline'\n className={cn(\n 'useTw w-[60%] justify-start text-left font-normal text-xs h-8 bg-background',\n !customRange.to && 'text-muted-foreground',\n )}\n >\n <CalendarIcon className='useTw mr-1 h-3 w-3' />\n <span dir={locale.direction}>\n {customRange.to\n ? formatDate(customRange.to, 'dd/MM/yyyy')\n : labels.selectDate}\n </span>\n </Button>\n </PopoverTrigger>\n <PopoverContent className='useTw w-auto p-0' align='start'>\n <Calendar\n mode='single'\n selected={customRange.to}\n onSelect={(date) => {\n handleCustomRangeChange({ ...customRange, to: date });\n setOpenToCalendar(false);\n }}\n initialFocus\n className='useTw'\n />\n </PopoverContent>\n </Popover>\n </div>\n </div>\n\n {/* Action Buttons */}\n <div className='flex gap-2'>\n <Button\n onClick={handleApplyCustomRange}\n className='useTw flex-1 text-xs h-8'\n disabled={!customRange.from && !customRange.to}\n >\n {labels.apply}\n </Button>\n <Button\n onClick={handleCancelCustomRange}\n variant='outline'\n className='useTw flex-1 text-xs h-8 bg-transparent'\n >\n {labels.cancel}\n </Button>\n </div>\n </div>\n )}\n </div>\n </div>\n </PopoverContent>\n </Popover>\n {hasValue() && (\n <button\n className={`useTw absolute ${isHebrew ? 'left-8' : 'right-8'} top-1/2 -translate-y-1/2 h-4 w-4 p-0 hover:bg-muted rounded-sm flex items-center justify-center z-10 `}\n onClick={(e) => {\n e.stopPropagation();\n handleClearAll();\n }}\n >\n <X className='useTw h-3 w-3' />\n </button>\n )}\n </div>\n </div>\n );\n}\n"],"names":["useEffect","useState","CalendarIcon","ChevronDown","X","futureDateFilterOptions","futureDateFilterOptionsEn","pastDateFilterOptions","pastDateFilterOptionsEn","formatDate","getDateRangeForOption","Button","cn","Label","Popover","PopoverContent","PopoverTrigger","Separator","Calendar","DateFilter","label","value","onChange","locale","code","direction","className","internalValue","setInternalValue","customRange","setCustomRange","from","undefined","to","showCustom","setShowCustom","isOpen","setIsOpen","openFromCalendar","setOpenFromCalendar","openToCalendar","setOpenToCalendar","isHebrew","pastOptions","futureOptions","type","labels","selectOption","selectDate","past","future","custom","apply","cancel","handlePredefinedSelect","optionValue","dateRange","newValue","predefinedValue","handleCustomSelect","handleCustomRangeChange","newRange","handleApplyCustomRange","handleCancelCustomRange","handleClearAll","hasValue","getDisplayValue","allOptions","option","find","opt","description","formatDateRange","includes","parts","replace","split","length","renderOptionWithDate","formattedDescription","variant","onClick","div","span","dir","open","onOpenChange","asChild","role","aria-expanded","map","align","mode","selected","onSelect","date","initialFocus","disabled","button","e","stopPropagation"],"mappings":"AAAA;;AAEA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAC5C,SAASC,YAAY,EAAEC,WAAW,EAAEC,CAAC,QAAQ,eAAe;AAE5D,SACEC,uBAAuB,EACvBC,yBAAyB,EACzBC,qBAAqB,EACrBC,uBAAuB,QAClB,mCAAmC;AAC1C,SAASC,UAAU,EAAEC,qBAAqB,QAAQ,wBAAwB;AAE1E,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,EAAE,QAAQ,kBAAkB;AACrC,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,OAAO,EAAEC,cAAc,EAAEC,cAAc,QAAQ,mBAAmB;AAC3E,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SAASC,QAAQ,QAAQ,oBAAoB;AAU7C,OAAO,SAASC,WAAW,EACzBC,KAAK,EACLC,KAAK,EACLC,QAAQ,EACRC,SAAS;IAAEC,MAAM;IAAMC,WAAW;AAAM,CAAC,EACzCC,SAAS,EACO;IAChB,MAAM,CAACC,eAAeC,iBAAiB,GAAG3B,SAAsCoB;IAChF,MAAM,CAACQ,aAAaC,eAAe,GAAG7B,SAAoB;QAAE8B,MAAMC;QAAWC,IAAID;IAAU;IAC3F,MAAM,CAACE,YAAYC,cAAc,GAAGlC,SAAS;IAC7C,MAAM,CAACmC,QAAQC,UAAU,GAAGpC,SAAS;IACrC,MAAM,CAACqC,kBAAkBC,oBAAoB,GAAGtC,SAAS;IACzD,MAAM,CAACuC,gBAAgBC,kBAAkB,GAAGxC,SAAS;IAErD,MAAMyC,WAAWnB,OAAOC,IAAI,KAAK;IACjC,MAAMmB,cAAcD,WAAWnC,wBAAwBC;IACvD,MAAMoC,gBAAgBF,WAAWrC,0BAA0BC;IAE3D,+C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AAEC,eAAe;4BACjBpC;wBACF;kCAEA,cAAA,KAAC5D;4BAAEsB,WAAU;;;;;;;AAMzB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/filters/components/date-filter.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\nimport { CalendarIcon, ChevronDown, X } from 'lucide-react';\n\nimport { formatDate, getDateRangeForOption } from '../utils/date-helpers';\nimport { DateFilterValue, DateRange, Locale } from '../types/filters-type';\nimport { Button } from '../../ui/button';\nimport { cn } from '../../lib/utils';\nimport { Label } from '../../ui/label';\nimport { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover';\nimport { Separator } from '../../ui/separator';\nimport { Calendar } from '../../ui/calendar';\nimport { getDateFilterOptions } from '../constants/date-filter-options';\nimport { SupportedLocale, getLabel } from '../../labels';\n\n\ninterface DateFilterProps {\n label?: string;\n value?: DateFilterValue;\n onChange: (value: DateFilterValue) => void;\n locale?: Locale;\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport function DateFilter({\n label,\n value,\n onChange,\n locale = { code: 'he', direction: 'rtl' },\n className,\n style,\n}: DateFilterProps) {\n const [internalValue, setInternalValue] = useState<DateFilterValue | undefined>(value);\n const [customRange, setCustomRange] = useState<DateRange>({ from: undefined, to: undefined });\n const [showCustom, setShowCustom] = useState(false);\n const [isOpen, setIsOpen] = useState(false);\n const [openFromCalendar, setOpenFromCalendar] = useState(false);\n const [openToCalendar, setOpenToCalendar] = useState(false);\n\n const isRTL = locale.direction === 'rtl';\n const localeCode = locale.code as SupportedLocale;\n const { pastOptions, futureOptions } = getDateFilterOptions(localeCode);\n\n // Sync internal state with external value prop\n useEffect(() => {\n setInternalValue(value);\n if (value?.type === 'custom' && value.customRange) {\n setCustomRange(value.customRange);\n }\n }, [value]);\n\n const labels = {\n selectOption: getLabel('selectOption', localeCode),\n from: getLabel('from', localeCode),\n to: getLabel('to', localeCode),\n selectDate: getLabel('selectDate', localeCode),\n past: getLabel('past', localeCode),\n future: getLabel('future', localeCode),\n custom: getLabel('customRange', localeCode),\n apply: getLabel('apply', localeCode),\n cancel: getLabel('cancel', localeCode),\n };\n\n const handlePredefinedSelect = (optionValue: string) => {\n setShowCustom(false);\n setIsOpen(false);\n\n const dateRange = getDateRangeForOption(optionValue, locale.code);\n const newValue: DateFilterValue = {\n type: 'predefined',\n predefinedValue: optionValue,\n customRange: { from: dateRange.from, to: dateRange.to },\n };\n\n setInternalValue(newValue);\n onChange(newValue);\n };\n\n const handleCustomSelect = () => {\n setShowCustom(true);\n };\n\n const handleCustomRangeChange = (newRange: DateRange) => {\n setCustomRange(newRange);\n };\n\n const handleApplyCustomRange = () => {\n const newValue: DateFilterValue = {\n type: 'custom',\n customRange,\n };\n\n setInternalValue(newValue);\n onChange(newValue);\n setIsOpen(false);\n setShowCustom(false);\n };\n\n const handleCancelCustomRange = () => {\n setIsOpen(false);\n setShowCustom(false);\n setCustomRange({ from: undefined, to: undefined });\n };\n\n const handleClearAll = () => {\n setInternalValue(undefined);\n setCustomRange({ from: undefined, to: undefined });\n setShowCustom(false);\n onChange({} as DateFilterValue);\n };\n\n const hasValue = () => {\n return (\n internalValue && (internalValue.type === 'predefined' || internalValue.type === 'custom')\n );\n };\n\n const getDisplayValue = () => {\n if (internalValue?.type === 'custom' && internalValue.customRange) {\n const { from, to } = internalValue.customRange;\n if (from && to) {\n return `${formatDate(from, 'dd/MM/yyyy')}-${formatDate(to, 'dd/MM/yyyy')}`;\n } else if (from) {\n return `${labels.from}: ${formatDate(from, 'dd/MM/yyyy')}`;\n } else if (to) {\n return `${labels.to}: ${formatDate(to, 'dd/MM/yyyy')}`;\n }\n return labels.custom;\n }\n\n if (internalValue?.type === 'predefined' && internalValue.predefinedValue) {\n const allOptions = [...pastOptions, ...futureOptions];\n const option = allOptions.find((opt) => opt.value === internalValue.predefinedValue);\n const dateRange = getDateRangeForOption(internalValue.predefinedValue, locale.code);\n return `${option?.label || internalValue.predefinedValue} ${dateRange.description}`;\n }\n\n return labels.selectOption;\n };\n\n const formatDateRange = (description: string) => {\n // Check if description contains a date range (has \" - \" in it)\n if (description.includes(' - ') && isRTL) {\n // Split by \" - \" and reverse the order for RTL\n const parts = description.replace(/[()]/g, '').split(' - ');\n if (parts.length === 2) {\n return `(${parts[1]}-${parts[0]})`;\n }\n }\n return description;\n };\n\n const renderOptionWithDate = (option: { value: string; label: string }) => {\n const dateRange = getDateRangeForOption(option.value, locale.code);\n const formattedDescription = formatDateRange(dateRange.description);\n\n return (\n <Button\n key={option.value}\n variant='ghost'\n className={cn(\n ' w-full h-auto py-1 px-2 text-xs leading-tight justify-start',\n isRTL ? ' text-right' : ' text-left',\n internalValue?.predefinedValue === option.value && 'bg-accent',\n )}\n onClick={() => handlePredefinedSelect(option.value)}\n >\n <div className={cn('flex flex-col')}>\n <span className='font-medium'>{option.label}</span>\n <span className='text-[10px] text-muted-foreground' dir={locale.direction}>\n {formattedDescription}\n </span>\n </div>\n </Button>\n );\n };\n\n return (\n <div className={cn('useTw space-y-1', className)} dir={locale.direction} style={style}>\n {label && (\n <Label className={cn('useTw text-sm font-medium', isRTL && 'text-right block')}>\n {label}\n </Label>\n )}\n\n <div className='relative useTw'>\n <Popover open={isOpen} onOpenChange={setIsOpen}>\n <PopoverTrigger asChild className='useTw'>\n <Button\n variant='outline'\n role='combobox'\n aria-expanded={isOpen}\n className='useTw w-full justify-between bg-background relative min-w-70'\n >\n <span className={`useTw truncate ${isRTL && 'text-right'}`}>{getDisplayValue()}</span>\n <ChevronDown className='useTw h-4 w-4 shrink-0 opacity-50' />\n </Button>\n </PopoverTrigger>\n <PopoverContent className='useTw w-80 p-0'>\n <div className='p-4'>\n <div className='grid grid-cols-2 gap-4'>\n {/* Future Options - Left column */}\n <div className='space-y-1'>\n <div\n className={cn(\n 'text-sm font-semibold text-muted-foreground mb-2',\n isRTL && 'text-right',\n )}\n >\n {labels.future}\n </div>\n <div className='space-y-0.5'>\n {futureOptions.map((option) => (\n <div key={option.value}>{renderOptionWithDate(option)}</div>\n ))}\n </div>\n </div>\n\n {/* Past Options - Right column */}\n <div className='space-y-1'>\n <div\n className={cn(\n 'text-sm font-semibold text-muted-foreground mb-2',\n isRTL && 'text-right',\n )}\n >\n {labels.past}\n </div>\n <div className='space-y-0.5'>\n {pastOptions.map((option) => (\n <div key={option.value}>{renderOptionWithDate(option)}</div>\n ))}\n </div>\n </div>\n </div>\n\n <Separator className='my-4' />\n\n {/* Custom Option */}\n <div className='space-y-3'>\n <Button\n variant='ghost'\n className={cn(\n 'useTw w-full justify-start h-auto py-2 px-2',\n (showCustom || internalValue?.type === 'custom') && 'bg-accent',\n isRTL && 'justify-start text-right',\n )}\n onClick={handleCustomSelect}\n >\n {labels.custom}\n </Button>\n\n {/* Custom Date Range - appears next to custom label */}\n {showCustom && (\n <div className='space-y-3 pl-2'>\n <div className='grid grid-cols-1 gap-3'>\n {/* From Date */}\n <div className={cn('flex items-center gap-2')}>\n <Label className={cn('useTw text-xs w-[20%]', isRTL && 'text-right')}>\n {labels.from}\n </Label>\n <Popover open={openFromCalendar} onOpenChange={setOpenFromCalendar}>\n <PopoverTrigger asChild className='useTw'>\n <Button\n variant='outline'\n className={cn(\n 'useTw w-[60%] justify-start text-left font-normal text-xs h-8 bg-background',\n !customRange.from && 'text-muted-foreground',\n )}\n >\n <CalendarIcon className='useTw mr-1 h-3 w-3' />\n <span dir={locale.direction}>\n {customRange.from\n ? formatDate(customRange.from, 'dd/MM/yyyy')\n : labels.selectDate}\n </span>\n </Button>\n </PopoverTrigger>\n <PopoverContent className='useTw w-auto p-0' align='start'>\n <Calendar\n mode='single'\n selected={customRange.from}\n onSelect={(date) => {\n handleCustomRangeChange({ ...customRange, from: date });\n setOpenFromCalendar(false);\n }}\n initialFocus\n className='useTw'\n />\n </PopoverContent>\n </Popover>\n </div>\n\n {/* To Date */}\n <div className={cn('flex items-center gap-2')}>\n <Label className={cn('useTw text-xs w-[20%]', isRTL && 'text-right')}>\n {labels.to}\n </Label>\n <Popover open={openToCalendar} onOpenChange={setOpenToCalendar}>\n <PopoverTrigger asChild className='useTw'>\n <Button\n variant='outline'\n className={cn(\n 'useTw w-[60%] justify-start text-left font-normal text-xs h-8 bg-background',\n !customRange.to && 'text-muted-foreground',\n )}\n >\n <CalendarIcon className='useTw mr-1 h-3 w-3' />\n <span dir={locale.direction}>\n {customRange.to\n ? formatDate(customRange.to, 'dd/MM/yyyy')\n : labels.selectDate}\n </span>\n </Button>\n </PopoverTrigger>\n <PopoverContent className='useTw w-auto p-0' align='start'>\n <Calendar\n mode='single'\n selected={customRange.to}\n onSelect={(date) => {\n handleCustomRangeChange({ ...customRange, to: date });\n setOpenToCalendar(false);\n }}\n initialFocus\n className='useTw'\n />\n </PopoverContent>\n </Popover>\n </div>\n </div>\n\n {/* Action Buttons */}\n <div className='flex gap-2'>\n <Button\n onClick={handleApplyCustomRange}\n className='useTw flex-1 text-xs h-8'\n disabled={!customRange.from && !customRange.to}\n >\n {labels.apply}\n </Button>\n <Button\n onClick={handleCancelCustomRange}\n variant='outline'\n className='useTw flex-1 text-xs h-8 bg-transparent'\n >\n {labels.cancel}\n </Button>\n </div>\n </div>\n )}\n </div>\n </div>\n </PopoverContent>\n </Popover>\n {hasValue() && (\n <button\n className={`useTw absolute ${isRTL ? 'left-8' : 'right-8'} top-1/2 -translate-y-1/2 h-4 w-4 p-0 hover:bg-muted rounded-sm flex items-center justify-center z-10 `}\n onClick={(e) => {\n e.stopPropagation();\n handleClearAll();\n }}\n >\n <X className='useTw h-3 w-3' />\n </button>\n )}\n </div>\n </div>\n );\n}\n"],"names":["useEffect","useState","CalendarIcon","ChevronDown","X","formatDate","getDateRangeForOption","Button","cn","Label","Popover","PopoverContent","PopoverTrigger","Separator","Calendar","getDateFilterOptions","getLabel","DateFilter","label","value","onChange","locale","code","direction","className","style","internalValue","setInternalValue","customRange","setCustomRange","from","undefined","to","showCustom","setShowCustom","isOpen","setIsOpen","openFromCalendar","setOpenFromCalendar","openToCalendar","setOpenToCalendar","isRTL","localeCode","pastOptions","futureOptions","type","labels","selectOption","selectDate","past","future","custom","apply","cancel","handlePredefinedSelect","optionValue","dateRange","newValue","predefinedValue","handleCustomSelect","handleCustomRangeChange","newRange","handleApplyCustomRange","handleCancelCustomRange","handleClearAll","hasValue","getDisplayValue","allOptions","option","find","opt","description","formatDateRange","includes","parts","replace","split","length","renderOptionWithDate","formattedDescription","variant","onClick","div","span","dir","open","onOpenChange","asChild","role","aria-expanded","map","align","mode","selected","onSelect","date","initialFocus","disabled","button","e","stopPropagation"],"mappings":"AAAA;;AAEA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAC5C,SAASC,YAAY,EAAEC,WAAW,EAAEC,CAAC,QAAQ,eAAe;AAE5D,SAASC,UAAU,EAAEC,qBAAqB,QAAQ,wBAAwB;AAE1E,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,EAAE,QAAQ,kBAAkB;AACrC,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,OAAO,EAAEC,cAAc,EAAEC,cAAc,QAAQ,mBAAmB;AAC3E,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,oBAAoB,QAAQ,mCAAmC;AACxE,SAA0BC,QAAQ,QAAQ,eAAe;AAYzD,OAAO,SAASC,WAAW,EACzBC,KAAK,EACLC,KAAK,EACLC,QAAQ,EACRC,SAAS;IAAEC,MAAM;IAAMC,WAAW;AAAM,CAAC,EACzCC,SAAS,EACTC,KAAK,EACW;IAChB,MAAM,CAACC,eAAeC,iBAAiB,GAAG1B,SAAsCkB;IAChF,MAAM,CAACS,aAAaC,eAAe,GAAG5B,SAAoB;QAAE6B,MAAMC;QAAWC,IAAID;IAAU;IAC3F,MAAM,CAACE,YAAYC,cAAc,GAAGjC,SAAS;IAC7C,MAAM,CAACkC,QAAQC,UAAU,GAAGnC,SAAS;IACrC,MAAM,CAACoC,kBAAkBC,oBAAoB,GAAGrC,SAAS;IACzD,MAAM,CAACs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AYE,IAAI,IAAI,CAACF,YAAYI,EAAE;8EAE7Cc,OAAOM,KAAK;;8EAEf,KAAC7C;oEACC0E,SAASlB;oEACTiB,SAAQ;oEACRxD,WAAU;8EAETsB,OAAOO,MAAM;;;;;;;;;;;;;oBAS7BY,4BACC,KAACiC;wBACC1E,WAAW,CAAC,eAAe,EAAEiB,QAAQ,WAAW,UAAU,sGAAsG,CAAC;wBACjKwC,SAAS,CAACkB;4BACRA,EAAEC,eAAe;4BACjBpC;wBACF;kCAEA,cAAA,KAAC5D;4BAAEoB,WAAU;;;;;;;AAMzB"}
|
|
@@ -8,7 +8,8 @@ interface SelectFilterProps {
|
|
|
8
8
|
locale?: Locale;
|
|
9
9
|
className?: string;
|
|
10
10
|
multiSelect?: boolean;
|
|
11
|
+
style?: React.CSSProperties;
|
|
11
12
|
}
|
|
12
|
-
export declare function SelectFilter({ label, options, value, onChange, placeholder, locale, className, multiSelect, }: SelectFilterProps): import("react").JSX.Element;
|
|
13
|
+
export declare function SelectFilter({ label, options, value, onChange, placeholder, locale, className, multiSelect, style, }: SelectFilterProps): import("react").JSX.Element;
|
|
13
14
|
export {};
|
|
14
15
|
//# sourceMappingURL=select-filter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/components/select-filter.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"select-filter.d.ts","sourceRoot":"","sources":["../../../src/filters/components/select-filter.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAiBtF,UAAU,iBAAiB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,WAAW,EACX,MAAyC,EACzC,SAAS,EACT,WAAkB,EAClB,KAAK,GACN,EAAE,iBAAiB,+BAmMnB"}
|