UNPKG

@wonderflow/react-components

Version:

UI components from Wonderflow's Wanda design system

32 lines (31 loc) 2.48 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, } from 'react'; import { useUIDSeed } from 'react-uid'; import { Stack, Symbol, Text, } from '../..'; import * as styles from './select.module.css'; export const Select = forwardRef(({ children, className, invalid = false, disabled = false, icon = 'chevron-down', label, message, kind = 'single', dimension = 'regular', onChange, ...otherProps }, forwardedRef) => { const seedID = useUIDSeed(); const iconSizes = { small: 12, regular: 16, big: 24, }; return (_jsxs(Stack, { as: "fieldset", rowGap: 4, className: clsx(styles.Select, className), "data-select-is-multiple": kind === 'multiple', "data-select-has-label": Boolean(label), "data-select-dimension": dimension, "data-select-invalid": invalid && !disabled, "aria-disabled": disabled, "aria-invalid": invalid && !disabled, hAlign: "start", vAlign: "start", inline: true, tabIndex: disabled ? 0 : undefined, children: [label && _jsx(Text, { as: "label", "aria-disabled": disabled, className: styles.Label, variant: dimension === 'big' ? 'body-1' : 'body-2', htmlFor: seedID('select'), children: label }), _jsxs("div", { className: styles.FieldContainer, children: [_jsx("select", { disabled: disabled, "aria-invalid": invalid && !disabled, className: styles.Field, id: seedID('select'), multiple: kind === 'multiple', onChange: onChange, ref: forwardedRef, ...otherProps, children: children }), kind === 'single' && (_jsx(Symbol, { className: styles.Icon, source: icon, dimension: iconSizes[dimension] }))] }), message && _jsx(Text, { as: "label", "aria-disabled": disabled, color: (invalid && !disabled) ? 'danger' : undefined, className: styles.Label, variant: dimension === 'big' ? 'body-2' : 'body-3', children: message })] })); }); Select.displayName = 'Select';