UNPKG

@wonderflow/react-components

Version:

UI components from Wonderflow's Wanda design system

34 lines (33 loc) 2.29 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 { Children, cloneElement, forwardRef, isValidElement, } from 'react'; import { useUIDSeed } from 'react-uid'; import { Stack, Text } from '../..'; import * as styles from './input-group.module.css'; export const InputGroup = forwardRef(({ className, input, suffix, prefix, label, dimension = 'regular', ...otherProps }, forwardedRef) => { const seedID = useUIDSeed(); return (_jsxs(Stack, { rowGap: 4, hAlign: "stretch", vAlign: "start", fill: false, children: [label && _jsx(Text, { as: "label", variant: dimension === 'big' ? 'body-1' : 'body-2', htmlFor: seedID('field'), children: label }), _jsxs(Stack, { as: "fieldset", direction: "row", vAlign: "start", hAlign: "start", fill: false, inline: true, ref: forwardedRef, className: clsx(styles.InputGroup, className), "data-input-group-has-end": Boolean(suffix), "data-input-group-has-start": !!prefix, ...otherProps, children: [_jsx("div", { className: styles.Start, children: Children.map(prefix, child => isValidElement(child) && cloneElement(child, { dimension, })) }), _jsx("div", { className: styles.InputField, children: Children.map(input, child => isValidElement(child) && cloneElement(child, { id: seedID('field'), dimension, })) }), _jsx("div", { className: styles.End, children: Children.map(suffix, child => isValidElement(child) && cloneElement(child, { dimension, })) })] })] })); }); InputGroup.displayName = 'InputGroup';