@guruhotel/aura-ui
Version:
⚛️ React UI library by GuruHotel
1 lines • 2.08 kB
JavaScript
import t from"react";import{StyledInput as e,StyledInputContainer as n,StyledInputLeftAddon as o,StyledInputLeftElement as r,StyledInputRightAddon as s,StyledInputRightElement as d}from"./input.styles";import{jsx as i}from"react/jsx-runtime";export const Input=t=>{const{isDisabled:n,ref:o,className:r,...s}=t;return i(e,{className:`input ${r}`,ref:o,disabled:!!n,...s})};Input.toString=()=>".input";export const InputLeftElement=({content:t,className:e,...n})=>i(r,{className:`left-element ${e}`,...n,children:t});InputLeftElement.toString=()=>".left-element";export const InputRightElement=({content:t,className:e,...n})=>i(d,{className:`right-element ${e}`,...n,children:t});InputRightElement.toString=()=>".right-element";export const InputLeftAddon=({content:t,className:e,...n})=>i(o,{className:`left-addon ${e}`,...n,children:t});InputLeftAddon.toString=()=>".left-addon";export const InputRightAddon=({content:t,className:e,...n})=>i(s,{className:`right-addon ${e}`,...n,children:t});InputRightAddon.toString=()=>".right-addon";export const InputGroup=({children:e,size:o,colorScheme:r,isDisabled:s,rounded:d,css:p,ref:l,...c})=>{const u=t.Children.toArray(e),a=u.find((t=>t.type===InputLeftElement)),m=u.find((t=>t.type===InputLeftAddon)),f=u.find((t=>t.type===InputRightElement)),h=u.find((t=>t.type===InputRightAddon)),I=t.Children.map(e,(e=>{const n=e;if(n.type===Input)return t.cloneElement(n,{size:o,colorScheme:r,isDisabled:s,rounded:d,ref:l,hasLeftElement:!!a,hasRightElement:!!f,css:{...n.props.css,zIndex:2,borderTopLeftRadius:m?0:void 0,borderBottomLeftRadius:m?0:void 0,borderTopRightRadius:h?0:void 0,borderBottomRightRadius:h?0:void 0},...c});if(n.type===InputLeftAddon||n.type===InputRightAddon)return t.cloneElement(n,{size:o,rounded:d,css:{...n.props.css,zIndex:1}});if(n.type===InputLeftElement||n.type===InputRightElement)return t.cloneElement(n,{size:o,css:{...n.props.css,zIndex:3}});throw new Error("InputGroup only accepts Input, InputLeftAddon and InputRightAddon as children")}));return i(n,{css:p,children:I})};InputGroup.displayName="InputGroup";