@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
38 lines • 4.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableRow = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const text_1 = require("../../../components/text/text");
const component_1 = require("../../../components/text/types/component");
const type_1 = require("../../button/types/type");
const elementOrIcon_1 = require("../../elementOrIcon/elementOrIcon");
const useContent_1 = require("../hooks/useContent");
const table_styled_1 = require("../table.styled");
const tableDivider_1 = require("./tableDivider");
/**
* @description
* TableRow component is used to display a row in a table.
*/
const TableRow = (props) => {
const { divider, rowHeader, dividerValue, getExpandedAria, getValue, getCellTokenValue, handleShowExpandedContent, hasExpandedContentRow, hasFooter, showExpandedContent, rowVariant, } = (0, useContent_1.useContent)({ ...props });
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(table_styled_1.TableRowBodyStyled, { borderPosition: props.value.rowBorderPosition, "data-testid": `${props.dataTestId}-row-${props.indexRow}`, hasDivider: !!dividerValue(), hasDividerContent: !!props.value.dividerContent, hasFooter: hasFooter, hasSomeDivider: props.hasSomeDivider, hasSomeDividerContent: props.hasSomeDividerContent, hasSomeExpandedContent: props.hasSomeExpandedContent, lineSeparatorLineStyles: props.lineSeparatorLineStyles, numberOfCells: props.headers.length, styles: props.styles.bodyRows?.[rowVariant], children: [(0, jsx_runtime_1.jsx)(tableDivider_1.TableDivider, { divider: dividerValue(), styles: props.styles.divider }), rowHeader && ((0, jsx_runtime_1.jsx)(table_styled_1.TableColumnHeaderStyled, { "aria-hidden": rowHeader.config?.['aria-hidden'], customAlign: rowHeader?.config?.alignHeader?.[props.device] || rowHeader?.config?.alignHeader, customBackgroundColor: rowHeader?.config?.backgroundColor, customWidth: rowHeader?.config?.width, flexWidth: rowHeader?.config?.flexWidth, scope: "row", styles: props.styles.header?.[rowHeader.variant], children: (0, jsx_runtime_1.jsx)(text_1.Text, { component: component_1.TextComponentType.SPAN, customTypography: props.styles.header?.[rowHeader.variant]?.typography, children: rowHeader.label }) })), props.headers
.filter(headerValue => headerValue.id !== divider?.id)
.map((headerValue, indexHeader) => {
const hasExpandedIcon = indexHeader === 0;
return ((0, jsx_runtime_1.jsxs)(table_styled_1.TableColumnBodyStyled, { "aria-hidden": headerValue.config?.['aria-hidden'], customAlign: getCellTokenValue({ headerValue, token: 'align' }) ||
headerValue?.config?.alignValue?.[props.device] ||
headerValue?.config?.alignValue ||
headerValue?.config?.alignHeader?.[props.device] ||
headerValue?.config?.alignHeader, customBackgroundColor: getCellTokenValue({ headerValue, token: 'backgroundColor' }) ??
props.value.backgroundColor, customWidth: headerValue?.config?.width, "data-testid": `${props.dataTestId}-row-${props.indexRow}-content-${indexHeader}`, flexWidth: headerValue?.config?.flexWidth, hasSomeExpandedContent: props.hasSomeExpandedContent && hasExpandedIcon, styles: props.styles.bodyRows?.[rowVariant], children: [hasExpandedIcon &&
props.hasSomeExpandedContent &&
(hasExpandedContentRow ? ((0, jsx_runtime_1.jsx)(table_styled_1.TableExpandedButton, { "aria-label": getExpandedAria(), styles: props.styles.bodyRows?.[rowVariant], type: type_1.ButtonType.BUTTON, onClick: () => {
props.onExpandedContentOpen?.(!showExpandedContent, getValue(headerValue), indexHeader);
handleShowExpandedContent(!showExpandedContent);
}, children: (0, jsx_runtime_1.jsx)(elementOrIcon_1.ElementOrIcon, { customIconStyles: props.styles.bodyRows?.[rowVariant]?.accordionIcon, rotate: showExpandedContent ? '180deg' : '0deg', ...props.accordionIcon }) })) : ((0, jsx_runtime_1.jsx)(table_styled_1.TableEmptyExpandedContentRow, { styles: props.styles.bodyRows?.[rowVariant] }))), getValue(headerValue)] }, indexHeader));
}), props.hasSomeExpandedContent && ((0, jsx_runtime_1.jsx)(table_styled_1.TableExpandedCellStyled, { "data-testid": `${props.dataTestId}-row-${props.indexRow}-expanded-content`, showExpandedContent: showExpandedContent, styles: props.styles.bodyRows?.[rowVariant], children: showExpandedContent && props.value.expandedContent
? props.value.expandedContent[props.device]
: props.expandedContentHelpMessage }))] }) }));
};
exports.TableRow = TableRow;
//# sourceMappingURL=tableRow.js.map