UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

48 lines 1.61 kB
import React, { useCallback } from 'react'; import Button from "../button/Button.js"; import { chevron_down, chevron_up } from "../../icons/index.js"; import { useSharedState } from "../../shared/helpers/useSharedState.js"; import useTranslation from "../../shared/useTranslation.js"; import { jsx as _jsx } from "react/jsx-runtime"; function ListShowMoreButton(props) { var _data$expanded; const { id, showMore, showLess, ...rest } = props; const { List: { showMore: showMoreTranslation, showLess: showLessTranslation } = {} } = useTranslation(); const resolvedShowMore = showMore !== null && showMore !== void 0 ? showMore : showMoreTranslation; const resolvedShowLess = showLess !== null && showLess !== void 0 ? showLess : showLessTranslation; const { data, update } = useSharedState(id, { expanded: false }); const expanded = (_data$expanded = data === null || data === void 0 ? void 0 : data.expanded) !== null && _data$expanded !== void 0 ? _data$expanded : false; const handleClick = useCallback(() => { update({ expanded: !expanded }); }, [expanded, update]); return _jsx(Button, { variant: "tertiary", text: expanded ? resolvedShowLess : resolvedShowMore, icon: expanded ? chevron_up : chevron_down, iconPosition: "right", onClick: handleClick, "aria-expanded": expanded, "aria-controls": typeof id === 'string' ? id : undefined, ...rest }); } ListShowMoreButton._supportsSpacingProps = true; export default ListShowMoreButton; //# sourceMappingURL=ListShowMoreButton.js.map