compote-ui
Version:
An opinionated UI component library for Svelte, built on top of [Ark UI](https://ark-ui.com) with additional components and features not available in the core Ark UI library.
44 lines (43 loc) • 1.27 kB
JavaScript
const TYPE_DEFAULTS = {
number: { align: 'right', size: 120 },
currency: { align: 'right', size: 120 },
percent: { align: 'right', size: 100 },
date: { align: 'center', size: 110 },
time: { align: 'center', size: 80 },
'date-time': { align: 'center', size: 160 },
boolean: { align: 'center', size: 90 },
url: { align: 'center', size: 60, enableSorting: false },
phone: { align: 'left', size: 160 }
};
function applyTypeDefaults(options) {
const defaults = options.type ? TYPE_DEFAULTS[options.type] : undefined;
if (!defaults)
return options;
return { ...defaults, ...options };
}
export function createDataTableColumnHelper() {
return {
accessor(accessorKey, options) {
return {
...applyTypeDefaults(options),
accessorKey
};
},
accessorFn(accessorFn, options) {
return {
...applyTypeDefaults(options),
accessorFn
};
},
group(header, columns, options = {}) {
return {
...options,
header,
columns
};
},
columns(columns) {
return columns;
}
};
}