@real-system/input
Version:
Real System input component
2 lines (1 loc) • 5.85 kB
JavaScript
"use strict";var X=Object.create;var b=Object.defineProperty,j=Object.defineProperties,Y=Object.getOwnPropertyDescriptor,F=Object.getOwnPropertyDescriptors,G=Object.getOwnPropertyNames,C=Object.getOwnPropertySymbols,J=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var A=(o,e,r)=>e in o?b(o,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[e]=r,i=(o,e)=>{for(var r in e||(e={}))B.call(e,r)&&A(o,r,e[r]);if(C)for(var r of C(e))N.call(e,r)&&A(o,r,e[r]);return o},h=(o,e)=>j(o,F(e));var u=(o,e)=>{var r={};for(var t in o)B.call(o,t)&&e.indexOf(t)<0&&(r[t]=o[t]);if(o!=null&&C)for(var t of C(o))e.indexOf(t)<0&&N.call(o,t)&&(r[t]=o[t]);return r};var K=(o,e)=>{for(var r in e)b(o,r,{get:e[r],enumerable:!0})},W=(o,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of G(e))!B.call(o,n)&&n!==r&&b(o,n,{get:()=>e[n],enumerable:!(t=Y(e,n))||t.enumerable});return o};var R=(o,e,r)=>(r=o!=null?X(J(o)):{},W(e||!o||!o.__esModule?b(r,"default",{value:o,enumerable:!0}):r,o)),Q=o=>W(b({},"__esModule",{value:!0}),o);var oe={};K(oe,{Input:()=>ee,InputBox:()=>S});module.exports=Q(oe);var x=R(require("react"));var f=R(require("react")),M=require("@real-system/elements-primitive"),D=require("@real-system/styled-library"),l=require("@real-system/utils-library");var m=R(require("react")),L=require("@real-system/elements-primitive"),H=require("@real-system/utils-library");var U=(o=!1)=>{let e={borderBottomLeftRadius:4,borderTopLeftRadius:4,borderRight:1};return o&&(e={borderBottomRightRadius:4,borderTopRightRadius:4,borderLeft:1}),e},V=(o=!1)=>{let e={backgroundColor:"gray-50",borderColor:"gray-100"};return o&&(e.backgroundColor="none"),e},T=m.default.forwardRef(function(s,d){var p=s,{children:e,disabled:r,isSuffix:t=!1}=p,n=u(p,["children","disabled","isSuffix"]);let c=(0,m.useMemo)(()=>V(r),[r]),y=(0,m.useMemo)(()=>U(t),[t]);return e==null?null:m.default.createElement(L.real.div,h(i(i(i({"data-testid":(0,H.makeTestId)("input-box-addon"),display:"flex",justifyContent:"center",alignItems:"center",height:"auto",paddingX:4},y),c),n),{ref:d}),e)});var g={display:"flex",width:"100%",height:"control",lineHeight:"control",border:"1px solid",borderRadius:4,transition:"box-shadow 150ms ease-in, border-color 150ms ease-in",bgColor:"white",cursor:"text",outline:"none",boxShadow:"none",boxSizing:"content-box",_hover:{},_focusWithin:{},_active:{boxShadow:"none"}},Z={default:(0,l.merge)(g,{color:"gray-500",borderColor:"gray-200",_hover:{borderColor:"gray-300"},_focusWithin:{borderColor:"gray-400",boxShadow:"focus-outline"},_active:{borderColor:"gray-400"}}),disabled:(0,l.merge)(g,{color:"gray-300",bgColor:"gray-50",borderColor:"gray-200",cursor:"default"}),readonly:(0,l.merge)(g,{color:"gray-400",bgColor:"gray-50",borderColor:"gray-200",_hover:{borderColor:"gray-300"},_focusWithin:{boxShadow:"focus-outline",borderColor:"gray-300"},_active:{borderColor:"gray-300"}}),error:(0,l.merge)(g,{borderColor:"red-500",_hover:{borderColor:"red-600"},_focusWithin:{boxShadow:"focus-outline",borderColor:"red-600"},_active:{borderColor:"red-600"}}),hidden:(0,l.merge)(g,{bgColor:"none",border:0,_hover:{border:0},_focusWithin:{border:0},_active:{border:0}})},S=f.forwardRef((E,y)=>{var v=E,{disabled:o,hasError:e=!1,readonly:r,children:t,type:n,suffix:d,prefix:s,addonProps:p}=v,c=u(v,["disabled","hasError","readonly","children","type","suffix","prefix","addonProps"]);let I=o,w=e,k=r,a="default";return n==="hidden"?a="hidden":I?a="disabled":w?a="error":k&&(a="readonly"),f.createElement(M.real.div,i(h(i({ref:y},Z[a]),{"data-testid":(0,l.makeTestId)("input-box")}),(0,D.preventSpreadingStyleProps)(c,{display:!0,height:!0,width:!0,border:!0,borderRadius:!0,transition:!0,bgColor:!0,backgroundColor:!0,color:!0,borderColor:!0,boxShadow:!0,cursor:!0,_hover:!0,_focusWithin:!0,_active:!0})),s&&f.createElement(T,i({disabled:o},p),s),t,d&&f.createElement(T,h(i({disabled:o},p),{isSuffix:!0}),d))});S.displayName="InputBox";var _=R(require("react")),q=require("@real-system/elements-primitive"),O=require("@real-system/styled-library");var $=({disabled:o,readonly:e,type:r})=>(r==="date"||r==="time")&&!e&&!o?"text":"auto",z=(0,_.forwardRef)(function(e,r){return _.default.createElement(q.real.input,i({appearance:"none",display:"block",width:"100%",height:"control",paddingX:5,paddingY:0,margin:0,fontScale:"input",fontWeight:"input",lineHeight:"control",backgroundColor:"transparent",border:"none",borderRadius:4,boxShadow:"none",color:"inherit",cursor:$(e),outline:"none",resize:"none",ref:r,_placeholder:{color:"gray-200",transition:"150ms all ease-in",fontWeight:"placeholder"},_hover_placeholder:{color:"gray-300"},_focus_placeholder:{color:"gray-300"},_focus:{outline:"none"},_disabled:{cursor:"default"},transition:"0.25s all ease-out","aria-invalid":e["aria-invalid"],"aria-readonly":e.readonly,disabled:e.disabled,id:e.id,name:e.name,placeholder:e.placeholder,readOnly:e.readonly,required:e.required,value:e.value},(0,O.spreadStyleProps)(e,{display:!1,width:!1,height:!1,border:!1,borderRadius:!1,transition:!1,bgColor:!1,backgroundColor:!1,color:!1,borderColor:!1,boxShadow:!1,cursor:!1,_hover:!1,_focusWithin:!1,_active:!1})))});var ee=(0,x.forwardRef)(function(k,w){var a=k,{readonly:e,disabled:r,id:t,required:n,hasError:d,type:s="text",suffix:p,prefix:c,placeholder:y,value:E,name:v}=a,I=u(a,["readonly","disabled","id","required","hasError","type","suffix","prefix","placeholder","value","name"]);let P={type:s};return s==="number"&&(P.type="text",P.inputmode="numeric",P.pattern="[0-9]*"),x.default.createElement(S,i({disabled:r,hasError:d,suffix:p,prefix:c,readonly:e,type:s},I),x.default.createElement(z,i(i({"aria-invalid":d,"aria-readonly":e,disabled:r,id:t,name:v,placeholder:y,readonly:e,required:n,value:E,ref:w},I),P)))});0&&(module.exports={Input,InputBox});