UNPKG

@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

74 lines 2.82 kB
import React from 'react'; export const useContent = (props) => { const [showExpandedContent, setShowExpandedContent] = React.useState(props.initialExpanded); const divider = props.headers.find(header => header?.config?.hasDivider); const rowVariant = props.value.rowVariant || 'DEFAULT'; const handleShowExpandedContent = (value) => { setShowExpandedContent(value); }; const getValueDividerContent = (value, divider) => { if (value.dividerContent || divider?.value?.dividerContent || divider?.value) { if (divider?.value instanceof Function) { const { dividerContent } = divider.value(value); return dividerContent; } return divider?.value?.dividerContent || value.dividerContent; } return null; }; const getValueDivider = (value, divider) => { if (divider?.value instanceof Function) { return divider?.value(value); } return divider?.value ?? value[divider.id]; }; const dividerValue = () => { if (!divider?.id) { return null; } const hasDividerContent = getValueDividerContent(props.value, divider); const hasDivider = getValueDivider(props.value, divider); return hasDividerContent || hasDivider; }; const hasFooter = !!props.footer; const getExpandedAria = () => showExpandedContent ? (props.value.accordionIconExpandedAriaLabel ?? props.accordionIconExpandedAriaLabel) : (props.value.accordionIconCollapsedAriaLabel ?? props.accordionIconCollapsedAriaLabel); const getValue = (headerValue) => { if (headerValue.value) { return headerValue.value(props.value); } const cellValue = props.value[headerValue.id] ? props.value[headerValue.id] : '-'; if (React.isValidElement(cellValue) || typeof cellValue === 'string') { return cellValue; } return cellValue.value; }; const getCellTokenValue = ({ headerValue, token, }) => { const cellValue = props.value[headerValue.id] ? props.value[headerValue.id] : '-'; if (React.isValidElement(cellValue) || typeof cellValue === 'string') { return; } return cellValue[token]; }; const hasExpandedContentRow = !!Object.getOwnPropertyDescriptor(props.value, 'expandedContent'); const rowHeader = props.value.rowHeader; return { divider, rowHeader, dividerValue, getExpandedAria, getValue, getCellTokenValue, handleShowExpandedContent, hasExpandedContentRow, hasFooter, showExpandedContent, rowVariant, }; }; //# sourceMappingURL=useContent.js.map