import { defineComponent } from "vue"; import type { PropType, VNode } from "vue"; import type { Text } from "@darwin-studio/vue-ui/src/types/text"; import type { DLoaderProps } from "@darwin-studio/vue-ui/src/components/atoms/d-loader/types"; import { DLoaderAsync as DLoader } from "@darwin-studio/vue-ui/src/components/atoms/d-loader/async"; import generateProp from "@darwin-studio/vue-ui/src/utils/generate-prop"; import generateClass from "@darwin-studio/vue-ui/src/utils/generate-class"; import config from "./config"; /** * Simply renders table element with passed head and body rows. */ export default defineComponent({ name: config.name, props: { /** * Two-dimensional array of head cells content */ headRows: { type: Array as PropType<(Text | VNode)[][]>, }, /** * You can pass own class name to the thead element. */ // TODO: options headClass: String, /** * You can pass own class name to the tr elements inside thead. */ // TODO: options headRowClass: String, /** * You can pass own class name to the th elements inside thead. */ // TODO: options headCellClass: String, /** * Pass any attrs to the tr elements inside thead. */ // TODO: options headRowAttrs: { type: Function as PropType<(rowIndex: number) => Record>, }, /** * Pass any attrs to the th elements inside thead. */ // TODO: options headCellAttrs: { type: Function as PropType< (rowIndex: number, colIndex: number) => Record >, }, /** * Two-dimensional array of body cells content */ bodyRows: { type: Array as PropType<(Text | VNode)[][]>, }, /** * You can pass own class name to the tbody element. */ // TODO: options bodyClass: String, /** * You can pass own class name to the tr elements inside tbody. */ // TODO: options bodyRowClass: String, /** * You can pass own class name to the td elements inside tbody. */ // TODO: options bodyCellClass: String, /** * Pass any attrs to the tr elements inside tbody. */ // TODO: options bodyRowAttrs: { type: Function as PropType<(rowIndex: number) => Record>, }, /** * Pass any attrs to the td elements inside tbody. */ // TODO: options bodyCellAttrs: { type: Function as PropType< (rowIndex: number, colIndex: number) => Record >, }, /** * Defines padding type of the component, use 'equal' if the component contains only an icon */ padding: generateProp.padding(), /** * Defines size of the component */ size: generateProp.size(), /** * Defines transition type of the component */ transition: generateProp.transition(), /** * Defines if DLoader element should be displayed. */ loading: Boolean, /** * Pass any DLoader.props to customize it, f.e. { class: "someClass" } */ loaderOptions: generateProp.options(config.loaderOptions), }, computed: { commonRowClasses(): (string | undefined)[] { return [ generateClass.font(this.size), generateClass.transition(this.transition), ]; }, commonCellClasses(): (string | undefined)[] { return [ ...generateClass.padding(this.padding, this.size), generateClass.size(this.size), ]; }, // TODO: warn if number of header and item cells a different renderHead(): VNode { const rowClasses = [ ...this.commonRowClasses, config.rowClass, this.headRowClass, ]; const cellClasses = [...this.commonCellClasses, this.headCellClass]; /* TODO: slot */ return ( {/* TODO: keys */} {this.headRows?.map((row, rowIndex) => ( {/* TODO: keys */} {row?.map((cell, colIndex) => ( {cell} ))} ))} ); }, renderBody(): VNode { const rowClasses = [ ...this.commonRowClasses, config.rowClass, this.bodyRowClass, ]; const cellClasses = [...this.commonCellClasses, this.bodyCellClass]; /* TODO: slot */ return ( {/* TODO: keys */} {this.bodyRows?.map((row, rowIndex) => ( {/* TODO: keys */} {row?.map((cell, colIndex) => ( {cell} ))} ))} ); }, }, render(): VNode { return ( {this.loading && ( )} {this.renderHead} {this.renderBody}
); }, });