koval-ui
Version:
React components collection with minimalistic design. Supports theming, layout, and input validation.
1 lines • 7.62 kB
Source Map (JSON)
{"version":3,"file":"types.cjs","sources":["../../../../src/lib/DataTable/types.ts"],"sourcesContent":["import type {\n AccessorFn as AccessorFnTanstack,\n HeaderContext,\n CellContext,\n SortingFn as SortingFnTanstack,\n FilterFnOption,\n} from '@tanstack/react-table';\nimport type {FC} from 'react';\n\nimport type {NumberProps} from '@/lib/Number';\nimport type {DateFormatOptions} from '@/lib/DateTime';\n\nexport enum Roles {\n manager = 'manager',\n developer = 'developer',\n}\n\nexport type Row = {\n firstName: string;\n lastName: string;\n role: keyof typeof Roles;\n age: number;\n email: string;\n address: {\n city: string;\n country: string;\n streetAddress: string;\n postcode: string;\n phoneNumber: string;\n };\n business: {\n iban: string;\n companyName: string;\n };\n};\n\nexport type TableValue = string | number;\n\nexport type TableRow = {[property: string]: TableRow | TableValue};\n// export type TableRow = Record<string, TableValue>;\n\n/**\n * Very liberal table data definition\n */\nexport type TableData = TableRow[];\n\nexport enum RenderModes {\n /**\n * Table renders as a virtualized list containing all cells\n */\n virtual = 'virtual',\n /**\n * Table renders as multiple pages of a certain size\n */\n paginated = 'paginated',\n}\n\nexport enum ProcessingModes {\n /**\n * Data processed by the table. Semi-controlled mode, prop changes overwrite the state\n */\n internal = 'internal',\n /**\n * Data processed by the developer. Full controlled mode\n */\n external = 'external',\n}\n\nexport enum ColumnTypes {\n text = 'text',\n decimal = 'decimal',\n percentage = 'percentage',\n currency = 'currency',\n unit = 'unit',\n date = 'date',\n select = 'select',\n}\n\n/**\n * Record which represents table change requested by the user. Key is equal to row index\n */\nexport type EditState = Record<number, TableRow>;\n\nexport type HeaderCell = FC<\n unknown & {\n title?: string;\n headerContext: HeaderContext<TableData, TableValue | TableRow>;\n }\n>;\n\nexport type CellComponent = FC<\n unknown & {\n value?: TableValue;\n cellContext: CellContext<TableData, TableRow | TableValue>;\n }\n>;\n\nexport type FooterCell = FC<\n unknown & {\n cellContext: HeaderContext<TableData, TableRow | TableValue>;\n }\n>;\n\nexport type FilterInput = FC<\n unknown & {\n value: FilterValue;\n onChange: (value: FilterValue) => void;\n }\n>;\n\nexport enum SortingModes {\n auto = 'auto',\n alphanumeric = 'alphanumeric',\n alphanumericCaseSensitive = 'alphanumericCaseSensitive',\n text = 'text',\n textCaseSensitive = 'textCaseSensitive',\n datetime = 'datetime',\n basic = 'basic',\n}\n\nexport type SortingFn = SortingFnTanstack<TableData>;\n\nexport enum FilterModes {\n auto = 'auto',\n includesString = 'includesString',\n includesStringSensitive = 'includesStringSensitive',\n equalsString = 'equalsString',\n arrIncludes = 'arrIncludes',\n arrIncludesAll = 'arrIncludesAll',\n arrIncludesSome = 'arrIncludesSome',\n equals = 'equals',\n weakEquals = 'weakEquals',\n inNumberRange = 'inNumberRange',\n}\n\nexport type ColumnFormatOptions = NumberProps | DateFormatOptions | Record<string, unknown>;\n\nexport enum CustomFilterFns {\n isInDateRange = 'isInDateRange',\n isInPercentRange = 'isInPercentRange',\n}\n\nexport type AccessorFn = AccessorFnTanstack<TableData, TableRow | TableValue>;\n\n/**\n * Table column config\n */\nexport type Column = {\n /**\n * Provide a unique id for the column\n */\n id: string;\n /**\n * Provide a human-readable title for the column\n */\n name: string;\n /**\n * Define a type of column data\n * @see ColumnTypes\n */\n columnType?: keyof typeof ColumnTypes;\n /**\n * Provide a custom React component to render column cells\n * @see CellComponent\n */\n columnCell?: CellComponent;\n /**\n * Set the width of the columns. Defaults to 166\n */\n size?: number;\n /**\n * Enable to allow user editing of the column\n */\n editable?: boolean;\n /**\n * Enable to allow user filtering of the column\n */\n filterable?: boolean;\n /**\n * Enable to make a column able to sort in ascending or descending order\n */\n sortable?: boolean;\n /**\n * Enable to make a column able to pin the left or right side\n */\n pinnable?: boolean;\n /**\n * Define a type of sorting to be used for the column. Can be one of supported modes or custom function\n * @see SortingModes\n * @see SortingFn\n */\n sortingFn?: keyof typeof SortingModes | SortingFn;\n /**\n * Define a type of filtering to be used for the column. Can be one of supported modes or custom function\n * @see FilterFnOption\n * @see CustomFilterFns\n */\n filterFn?: FilterFnOption<TableData> | keyof typeof CustomFilterFns;\n /**\n * Set props for each table cell. Useful for formatting dates, currencies, etc.\n * @see ColumnFormatOptions\n */\n cellProps?: ColumnFormatOptions;\n /**\n * Provide a custom React component to render the column header\n * @see HeaderCell\n */\n headerCell?: HeaderCell;\n /**\n * Provide a custom React component to render the column footer\n * @see FooterCell\n */\n footerCell?: FooterCell;\n /**\n * Provide a custom React component to render the column filter input\n * @see FilterInput\n */\n filterInput?: FilterInput;\n} & (\n | {\n /**\n * Provide an accessor key to get column cell value from table data\n * @example\n * {\n * accessorKey: \"foo.bar[6].bazz\"\n * }\n */\n accessorKey: string;\n /**\n * Provide an accessor function to get column cell value from table data\n */\n accessorFn?: never;\n }\n | {\n /**\n * Provide an accessor key to get column cell value from table data\n * @example\n * {\n * accessorKey: \"foo.bar[6].bazz\"\n * }\n */\n accessorKey?: never;\n /**\n * Provide an accessor function to get column cell value from table data\n */\n accessorFn: AccessorFn;\n }\n);\n\nexport type DateRangeFilterValue = string[];\nexport type RangeFilterValue = number[];\n\nexport type FilterValue = DateRangeFilterValue | RangeFilterValue | string;\n"],"names":["RenderModes","ProcessingModes","ColumnTypes","SortingModes","FilterModes","CustomFilterFns"],"mappings":"6FA8CY,IAAAA,GAAAA,IAIRA,EAAA,QAAU,UAIVA,EAAA,UAAY,YARJA,IAAAA,GAAA,CAAA,CAAA,EAWAC,GAAAA,IAIRA,EAAA,SAAW,WAIXA,EAAA,SAAW,WARHA,IAAAA,GAAA,CAAA,CAAA,EAWAC,GAAAA,IACRA,EAAA,KAAO,OACPA,EAAA,QAAU,UACVA,EAAA,WAAa,aACbA,EAAA,SAAW,WACXA,EAAA,KAAO,OACPA,EAAA,KAAO,OACPA,EAAA,OAAS,SAPDA,IAAAA,GAAA,CAAA,CAAA,EA0CAC,GAAAA,IACRA,EAAA,KAAO,OACPA,EAAA,aAAe,eACfA,EAAA,0BAA4B,4BAC5BA,EAAA,KAAO,OACPA,EAAA,kBAAoB,oBACpBA,EAAA,SAAW,WACXA,EAAA,MAAQ,QAPAA,IAAAA,GAAA,CAAA,CAAA,EAYAC,GAAAA,IACRA,EAAA,KAAO,OACPA,EAAA,eAAiB,iBACjBA,EAAA,wBAA0B,0BAC1BA,EAAA,aAAe,eACfA,EAAA,YAAc,cACdA,EAAA,eAAiB,iBACjBA,EAAA,gBAAkB,kBAClBA,EAAA,OAAS,SACTA,EAAA,WAAa,aACbA,EAAA,cAAgB,gBAVRA,IAAAA,GAAA,CAAA,CAAA,EAeAC,GAAAA,IACRA,EAAA,cAAgB,gBAChBA,EAAA,iBAAmB,mBAFXA,IAAAA,GAAA,CAAA,CAAA"}