@spaced-out/ui-design-system
Version:
Sense UI components library
310 lines • 21.2 kB
TypeScript
export declare const TABLE_DOCS: {
readonly argTypes: {
readonly headers: {
readonly type: {
readonly required: true;
};
readonly description: "Provide an array of objects to render the header, each object should consist of label(*), key(*), sortable, sticky and render function";
readonly control: {
readonly type: "object";
};
readonly table: {
readonly type: {
readonly summary: "{label: React.Node, key: $Keys<T>, className?: string, filterIcon?: React.Node, filtered?: boolean, subtext?: string, sortable?: boolean, headerIconClassName?: string, sticky?: boolean, render?: React.ComponentType<{data: T, extras?: U, className?: string, selected?: boolean,}>, }";
};
};
};
readonly entries: {
readonly type: {
readonly required: true;
};
readonly description: "Provide an array of object. Each object belong on one row in the table. Each object should have id and all the keys with values that is being passed in headers array";
readonly control: {
readonly type: "object";
};
readonly table: {
readonly type: {
readonly summary: "Array<T>";
};
};
};
readonly classNames: {
readonly description: "Provide optional classNames to be applied to the wrapper, table, tableHeader, tableBody, tableRow, or checkbox";
readonly control: {
readonly type: "object";
};
readonly table: {
readonly type: {
readonly summary: "{wrapper?: string, table?: string, tableHeader?: string, tableBody?: string, tableRow?: string, checkbox?: string}";
};
};
};
readonly Row: {
readonly description: "Custom Row component to be passed to table";
readonly table: {
readonly type: {
readonly summary: "TableRow<T, U>";
};
};
};
readonly sortable: {
readonly description: "Sort Icon will appear in right side of column's header with column level true sortable value";
readonly name: "sortable";
readonly options: readonly [false, true];
readonly control: "boolean";
readonly table: {
readonly type: {
readonly summary: "boolean";
};
readonly defaultValue: {
readonly summary: true;
};
};
};
readonly showHeader: {
readonly description: "Show or hide header";
readonly options: readonly [false, true];
readonly control: "boolean";
readonly table: {
readonly type: {
readonly summary: "boolean";
};
readonly defaultValue: {
readonly summary: true;
};
};
};
readonly defaultSortKey: {
readonly description: "key name for which table should be sorted by default. headers array should have sortable true for that key object";
readonly control: {
readonly type: "text";
};
readonly table: {
readonly type: {
readonly summary: "string";
};
};
};
readonly defaultSortDirection: {
readonly description: "default sorting direction for the defaultSortKey column";
readonly control: {
readonly type: "text";
};
readonly table: {
readonly type: {
readonly summary: "'asc' | 'desc' | 'original'";
};
};
};
readonly selectedKeys: {
readonly description: "array of keys which are selected. This prop is also used to decide weather to show checkboxes or not. So, pass an empty array in case no row is selected.";
readonly control: {
readonly type: "object";
};
readonly table: {
readonly type: {
readonly summary: "string[]";
};
};
};
readonly disabledKeys: {
readonly description: "array of keys which are disabled. This prop is used to disable the checkbox and its events for particular rows.";
readonly control: {
readonly type: "object";
};
readonly table: {
readonly type: {
readonly summary: "string[]";
};
};
};
readonly onSelect: {
readonly description: "callback function when any row is selected";
readonly action: "selected";
readonly type: {
readonly summary: "(keys: string[]) => mixed";
};
};
readonly idName: {
readonly description: "name of key in row objects that has to be used as id";
};
readonly onSort: {
readonly description: "callback function when any table is sorted";
readonly action: "sorted";
readonly type: {
readonly summary: "(key: $Keys<T>, direction: SortDirection) => void";
};
};
readonly isLoading: {
readonly description: "to wait for data to populate in table and show loading state when entries array is empty.";
readonly options: readonly [false, true];
readonly control: "boolean";
readonly table: {
readonly type: {
readonly summary: "boolean";
};
readonly defaultValue: {
readonly summary: false;
};
};
};
readonly emptyText: {
readonly description: "Provide component to be shown in case of empty data";
readonly table: {
readonly type: {
readonly summary: "React.Component";
};
};
};
readonly customLoader: {
readonly description: "Provide optional component to be shown in case of loading state. It will override the default loader.";
readonly table: {
readonly type: {
readonly summary: "React.Component";
};
};
};
readonly disabled: {
readonly description: "disable all the checkboxes of each row in the table";
readonly options: readonly [false, true];
readonly control: "boolean";
readonly table: {
readonly type: {
readonly summary: "boolean";
};
readonly defaultValue: {
readonly summary: false;
};
};
};
readonly borderRadius: {
readonly description: "Border Radius of all four corners of the table. Default value is borderRadiusMedium i.e., 12px.";
readonly control: "text";
readonly table: {
readonly type: {
readonly summary: "string";
};
readonly defaultValue: {
readonly summary: "12px";
};
};
};
readonly stickyHeader: {
readonly description: "Sticky header will stick the header to the top of the table when scrolling. This would only work if the table wrapper is scrollable.";
readonly control: "boolean";
readonly table: {
readonly type: {
readonly summary: "boolean";
};
readonly defaultValue: {
readonly summary: false;
};
};
};
readonly enableInternalSorting: {
readonly description: "Enable internal sorting for the table. This would sort the table data internally and not rely on the apis sorting";
readonly control: "boolean";
readonly table: {
readonly type: {
readonly summary: "?boolean";
};
readonly defaultValue: {
readonly summary: true;
};
};
};
readonly rowsCount: {
readonly name: "virtualizationOptions.rowsCount";
readonly description: "Total number of virtual rows.";
readonly control: {
readonly type: "number";
};
readonly table: {
readonly type: {
readonly summary: "number";
};
readonly defaultValue: {
readonly summary: 20;
};
};
};
readonly rowHeight: {
readonly name: "virtualizationOptions.rowHeight";
readonly description: "Row height in CSS units (e.g., \"48px\"). Should be provided correctly, otherwise it will not work as expected.";
readonly control: {
readonly type: "text";
};
readonly table: {
readonly type: {
readonly summary: "string";
};
readonly defaultValue: {
readonly summary: "48px";
};
};
};
readonly isEndLoading: {
readonly name: "virtualizationOptions.isEndLoading";
readonly description: "Whether to show loading spinner at the bottom.";
readonly control: {
readonly type: "boolean";
};
readonly table: {
readonly type: {
readonly summary: "boolean";
};
readonly defaultValue: {
readonly summary: false;
};
};
};
readonly isAllDataFetched: {
readonly name: "virtualizationOptions.isAllDataFetched";
readonly description: "Whether all rows are fetched (disables infinite loading).";
readonly control: {
readonly type: "boolean";
};
readonly table: {
readonly type: {
readonly summary: "boolean";
};
readonly defaultValue: {
readonly summary: false;
};
};
};
readonly onEndReached: {
readonly name: "virtualizationOptions.onEndReached";
readonly description: "Callback triggered when end of list is reached.";
readonly action: "onEndReached";
readonly table: {
readonly type: {
readonly summary: "() => void";
};
};
};
readonly testId: {
readonly description: "Test ID for the component";
readonly control: {
readonly type: "text";
};
readonly table: {
readonly type: {
readonly summary: "string";
};
};
};
};
readonly parameters: {
readonly docs: {
readonly subtitle: "Generates a Table component.";
readonly description: {
readonly component: "\n```js\nimport {\n Table,\n StaticTable,\n DefaultRow,\n BasicSingleCell,\n DateCell,\n DoubleCell,\n SingleCell,\n MonogramCell,\n TableActionBar,\n ButtonCta,\n DropdownCta,\n TableTopBar,\n TableBottomBar\n} from \"@spaced-out/ui-design-system/lib/components/Table\";\n```\nTable component internally uses HTML Table, Thead, Tbody, Tr, Th and Td tags. It accepts entries and headers for showing table.\nThe Table component takes care of lots of things for you but it's not a magical component, it wraps a lot of behavior, so you can have,\nfor instance, a static table with no sorting options.\n\nStaticTables work just like regular tables, except they don't have interactive headers, so you lose sorting.\nBut remember, a regular interactive table uses a static table under the hood,\nso how does it work? You can think of the StaticTable as a kind of controlled table component.\nexcept that traditionally we'd update the entries prop and rerender from that.\nThat would work just fine, but instead we can just pass in the keys we care about. By using StaticTable,\nwe can simplify filtering and sorting outside of the table while the table keeps a stable value reference to all the entities.\n\nTo make any of rows selectable, we can do that by also passing in another property, selectedKeys.\n\nLet's say we want to also make any of the rows selectable, we can do that by also passing in another property, selectedKeys.\n\n### Custom Cells\n\nIt's possible you need to render out a custom cell, not just the default cell.\nThere are two ways to do that. If you only need to modify a single cell,\nyou can simply add a render: `React.ComponentType<{data: T, extras?: U}>`\nkey to any given header item.\n\nThis cell renderer receives the _whole row_ of data, not just the individual cell, it's up to you what to do with it.\n\n### With Table Top, Bottom Bar and Actions\n\nYou can attach a top, bottom and action bar to the table by adding `TableTopBar`, `TableBottomBar` and `TableActionBar` components.\nThere are just semantic components which just provide padding and border standardization. You can add any component inside these components.\nThese also accept **className** prop.\n\n### Best Practices\n* A Data Table should always have a `TableTopBar`\n* Use `stickyHeader` prop to make the header sticky\n* Always assign a height to the table wrapper to make it scrollable\n* Manage the Table's Wrapper height effectively when using `TableActionBar` component\n* Always use local `ButtonCta` and `DropdownCta` for actions in Action bar. These components are\njust CSS Wrappers for Button and SimpleButtonDropdown components\n* Use ButtonCta component to add a button CTA in the `TableActionBar`\n* Use DropdownCta component to add a dropdown CTA button in the `TableActionBar` for screen width less than size1280(1280px)\n\n### Handling Sticky Headers with Virtualization\n* When using **virtualization**, always assign a fixed `min-width` and `max-width` to sticky table headers with **same value**.\nThis ensures a strict, fixed width for header cells. Directly using `width` (non strict for table headers) alone is not sufficient, as\nit can be overridden by content width due to table layout behavior, causing headers to shift.\n* If the cell content may exceed the defined width, or if you're unsure of its maximum width, also use `white-space: normal;` and `word-break: break-word;`\nto ensure the content wraps within the cell instead of overflowing or causing layout shifts.\n\nThis helps maintain consistent column alignment and improves readability across varying data lengths.\n\n```jsx\n<Table\n headers={TABLE_HEADERS}\n entries={TABLE_DATA}\n stickyHeader={true}\n classNames={{\n wrapper: classify(css.tableWrapper, {\n [css.withActionBar]: getNumberOfEntriesSelected() > 0,\n })\n }}\n/>\n```\n\n```css\n.tableWrapper {\n height: calc(sizeFullViewportHeight - size160);\n}\n\n.tableWrapper.withActionBar {\n height: calc((sizeFullViewportHeight - size160) - actionBarHeight);\n}\n```\n\n### Usage\n\n```jsx\nconst TABLE_HEADERS = [\n { label: \"Name\", key: \"name\", sortable: true, className: css.mediumColumn },\n { label: \"Tel\", key: \"phone\", sortable: true, className: css.mediumColumn },\n];\n\nconst TABLE_DATA = [\n {\n id: \"1\",\n name: \"Alice\",\n phone: \"123-456-7890\",\n },\n {\n id: \"2\",\n name: \"Bob\",\n phone: \"987-654-3210\",\n },\n];\n\nexport const _TableExample = (): React.Node => {\n return (\n <div className={css.container}>\n {/* Top Bar with Filters */}\n <TableTopBar>\n <div className={css.left}>\n <SubTitleMedium className={css.title}>Basic Data Table</SubTitleMedium>\n <SearchInput />\n </div>\n </TableTopBar>\n\n {/* Table */}\n <Table\n headers={TABLE_HEADERS}\n entries={TABLE_DATA}\n isLoading={isLoading}\n stickyHeader={true}\n borderRadius={'0'}\n selectedKeys={staticTableKeysAcrossPages[currPage] || []}\n onSelect={(keys) => {\n setSelectAllEntries(false);\n setStaticTableKeysAcrossPages({\n ...staticTableKeysAcrossPages,\n [currPage]: keys,\n });\n }}\n classNames={{\n wrapper: classify(css.tableWrapper, {\n [css.withActionBar]: getNumberOfEntriesSelected() > 0,\n })\n }}\n />\n\n {/* Table Actions */}\n {getNumberOfEntriesSelected() > 0 && (\n <TableActionBar className={css.actionBar}>\n <div className={css.leftActionSlot}>\n <ButtonCta\n onClick={() => {\n setSelectAllEntries(true);\n setStaticTableKeysAcrossPages({\n ...staticTableKeysAcrossPages,\n [currPage]: tableEntries.map((entry) => entry.id),\n });\n }}\n >\n Select all items\n </ButtonCta>\n {getNumberOfEntriesSelected() > 0 && (\n <BodySmall color=\"inversePrimary\">\n {getNumberOfEntriesSelected() entries selected}\n </BodySmall>\n )}\n </div>\n <div className={classify(css.middleActionSlot, css.fullTable)}>\n <ButtonCta size=\"small\" iconLeftName=\"folder-plus\">\n Add to group\n </ButtonCta>\n </div>\n <div className={classify(css.middleActionSlot, css.smallTable)}>\n <ButtonCta size=\"small\" iconLeftName=\"folder-plus\">\n Add to group\n </ButtonCta>\n <DropdownCta\n ariaLabel=\"Icon Button Dropdown\"\n iconLeftName=\"ellipsis\"\n options={[\n {\n iconLeft: 'layer-plus',\n key: '1',\n label: 'Create group',\n },\n ]}\n selectedKeys={selectedKeys}\n onOptionSelect={() => setSelectedKeys([])}\n size=\"small\"\n />\n </div>\n <div className={css.rightActionSlot}>\n <ButtonCta\n iconLeftName=\"close\"\n onClick={() => {\n setSelectAllEntries(false);\n setStaticTableKeysAcrossPages({});\n }}\n >\n Close\n </ButtonCta>\n </div>\n </TableActionBar>\n )}\n\n {/* Bottom Bar with Pagination */}\n <TableBottomBar>\n <Pagination\n currentPage={currPage}\n totalPages={totalPages}\n onChange={(page) => {\n onMove(page || 1);\n }}\n >\n <SubTitleExtraSmall color=\"secondary\">\n Showing page {currPage} of {totalPages}\n </SubTitleExtraSmall>\n </Pagination>\n </TableBottomBar>\n </div>\n );\n};\n```\n\n```css\n@value actionBarHeight: size50;\n\n.container {\n width: sizeFluid;\n}\n\n.left {\n display: flex;\n align-items: center;\n}\n\n.title {\n margin-right: spaceMedium;\n}\n\n.mediumColumn {\n width: calc(sizeFluid / 5);\n}\n\n.tableWrapper {\n height: calc(sizeFullViewportHeight - size160);\n}\n\n.actionBar {\n display: flex;\n align-items: center;\n gap: spaceXSmall;\n}\n\n.tableWrapper.withActionBar {\n height: calc((sizeFullViewportHeight - size160) - actionBarHeight);\n}\n\n.leftActionSlot,\n.rightActionSlot,\n.middleActionSlot {\n display: flex;\n gap: spaceSmall;\n align-items: center;\n}\n\n.leftActionSlot,\n.rightActionSlot {\n width: calc(sizeFluid / 4);\n}\n\n.leftActionSlot {\n justify-content: flex-start;\n}\n\n.middleActionSlot {\n width: calc(sizeFluid / 2);\n justify-content: center;\n gap: spaceXXSmall;\n}\n\n.rightActionSlot {\n justify-content: flex-end;\n}\n\n.smallTable {\n display: none;\n}\n\n@media only screen and (max-width: size1280) {\n .fullTable {\n display: none;\n }\n\n .smallTable {\n display: flex;\n }\n}\n\n.dangerText {\n color: colorTextDanger;\n}\n\n.dangerText:hover,\n.dangerText:active,\n.dangerText:focus {\n color: colorTextDanger;\n}\n\n```\n ";
};
};
readonly storySource: {
readonly componentPath: "/src/components/Table/Table";
};
};
};
//# sourceMappingURL=Table.docs.d.ts.map