UNPKG

@wonderflow/react-components

Version:

UI components from Wonderflow's Wanda design system

29 lines (28 loc) 1.76 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /* * Copyright 2022-2023 Wonderflow Design Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import clsx from 'clsx'; import { forwardRef, useState, } from 'react'; import { ToggleButton, Tooltip } from '../..'; import * as styles from './clamp-text.module.css'; export const ClampText = forwardRef(({ className, children, rows = 1, style, expandable, as: Wrapper = 'div', ...otherProps }, forwardedRef) => { const [isExpanded, setIsExpandend] = useState(false); const dynamicStyle = { '--r': rows, '--padding': expandable && '2rem', }; return (_jsxs(Wrapper, { ref: forwardedRef, className: clsx(styles.ClampText, className), ...otherProps, children: [_jsx("span", { className: styles.Content, "data-clamp-text-expanded": isExpanded, style: { ...dynamicStyle, ...style }, children: children }), expandable && (_jsx(Tooltip, { trigger: (_jsx(ToggleButton, { "data-testid": "ExpandableButton", className: styles.Trigger, pressed: isExpanded, onClick: () => setIsExpandend(state => !state), restingIcon: "plus", pressedIcon: "minus", dimension: "small", kind: "secondary" })), children: `${isExpanded ? 'Collapse' : 'Expand'} text` }))] })); });