UNPKG

@accelint/design-toolkit

Version:

An open-source component library to serve as part of the entire ecosystem of UX for Accelint.

4 lines (3 loc) 2 kB
'use client'; import {jsx,jsxs,Fragment}from'react/jsx-runtime';import'client-only';import V from'@accelint/icons/chevron-down';import {createContext}from'react';import {useContextProps,Select,composeRenderProps,SelectValue,Text,FieldError,Popover,Virtualizer,ListLayout}from'react-aria-components';import {Button}from'../button/index.js';import {Icon}from'../icon/index.js';import {Label}from'../label/index.js';import {Options}from'../options/index.js';import {SelectFieldStyles}from'./styles.js';const {description:k,error:G,trigger:J,label:d,field:K,value:Q}=SelectFieldStyles(),m=createContext(null);function u({children:o,...t}){return jsx(m.Provider,{value:t,children:o})}u.displayName="SelectField.Provider";function P({ref:o,...t}){[t,o]=useContextProps(t,o??null,m);const{size:i="medium",children:S,classNames:r,description:n,errorMessage:f,label:N,layoutOptions:F,isInvalid:y,...g}=t,c=f||null,p=i==="small",b=!p&&!!d;return jsx(Select,{...g,ref:o,className:composeRenderProps(r?.field,s=>K({className:s})),isInvalid:y||(c?true:void 0),"data-size":i,children:composeRenderProps(S,(s,{isRequired:x,isDisabled:C,isInvalid:L})=>jsxs(Fragment,{children:[b&&jsx(Label,{className:d({className:r?.label}),isRequired:x,isDisabled:C,children:N}),jsxs(Button,{className:composeRenderProps(r?.trigger,a=>J({className:a})),variant:"outline",size:i,children:[jsx(SelectValue,{className:Q({className:r?.value})}),jsx(Icon,{children:jsx(V,{className:"transform group-open/select-field:rotate-180"})})]}),!!n&&!(p||L)&&jsx(Text,{className:k({className:r?.description}),slot:"description",children:n}),jsx(FieldError,{className:composeRenderProps(r?.error,a=>G({className:a})),children:c}),jsx(Popover,{className:"min-w-(--trigger-width)",children:jsx(Virtualizer,{layout:ListLayout,layoutOptions:F,children:jsx(Options,{children:s})})})]}))})}P.displayName="SelectField",P.Provider=u;export{P as SelectField,m as SelectFieldContext};//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map