@moondreamsdev/dreamer-ui 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/components.cjs.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),x=require("./join-yP8AS-6v.cjs"),b=require("react");function I(){const[a,r]=b.useState(0);return b.useEffect(()=>{const e=setInterval(()=>{r(s=>(s+1)%3)},500);return()=>clearInterval(e)},[]),i.jsx("div",{className:"absolute inset-0 inline-flex items-center justify-center gap-x-2 align-middle",children:[0,1,2].map(e=>i.jsx("div",{className:x.join("rounded-full transition-all duration-500 ease-in-out size-[0.35em] bg-current",a===e&&"transform -translate-y-1")},e))})}const L={base:"",primary:"bg-primary text-primary-foreground hover:bg-primary/85 disabled:bg-muted disabled:text-muted-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/85 disabled:bg-muted/80 disabled:text-muted-foreground/80",tertiary:"text-primary hover:text-primary-foreground disabled:text-muted",outline:"border border-primary text-primary hover:border-primary-foreground hover:text-primary-foreground disabled:border-muted disabled:text-muted",link:"underline-offset-4 hover:underline disabled:underline disabled:text-muted",danger:"bg-danger text-danger-foreground hover:bg-danger/85 disabled:bg-muted disabled:text-muted-foreground"},S={stripped:"",fitted:"size-fit",sm:"px-2 py-1 text-sm",md:"px-4 py-2 text-base",lg:"px-6 py-3 text-lg",icon:"p-1 w-fit aspect-square",full:"p-2 w-full"},R={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",full:"rounded-full"},N={variant:"primary",size:"md",rounded:"md"};function z({variant:a=N.variant,size:r,rounded:e=N.rounded,loading:s,linkTo:t,linkProps:n,type:d="button",className:u,...l}){let m;a==="link"&&!r?m="fitted":m=r||N.size;const o=x.join("appearance-none focus:outline-none focus:ring not-disabled:hover:cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed transition-all",L[a],S[m],R[e],s&&"relative pointer-events-none",t&&"relative",u);return i.jsxs("button",{...l,role:t?"link":l.role,"aria-label":l["aria-label"]||(n==null?void 0:n["aria-label"]),"aria-description":l["aria-description"]||(n==null?void 0:n["aria-description"]),"aria-disabled":l.disabled||s,"aria-busy":s,type:d,className:o,children:[s&&i.jsx(I,{}),i.jsx("span",{className:x.join(s&&"invisible"),children:l.children}),t&&!l.disabled&&i.jsx("a",{...n,"aria-hidden":!0,href:t,target:(n==null?void 0:n.target)||"_blank",rel:(n==null?void 0:n.rel)||"noreferrer",className:"absolute inset-0"})]})}function B({size:a=15,color:r="currentColor"}){return i.jsx("svg",{width:a,height:a,className:"inline",viewBox:"0 0 15 15",xmlns:"http://www.w3.org/2000/svg",children:i.jsx("path",{d:"M11.4669 3.72684C11.7558 3.91574 11.8369 4.30308 11.648 4.59198L7.39799 11.092C7.29783 11.2452 7.13556 11.3467 6.95402 11.3699C6.77247 11.3931 6.58989 11.3355 6.45446 11.2124L3.70446 8.71241C3.44905 8.48022 3.43023 8.08494 3.66242 7.82953C3.89461 7.57412 4.28989 7.55529 4.5453 7.78749L6.75292 9.79441L10.6018 3.90792C10.7907 3.61902 11.178 3.53795 11.4669 3.72684Z",fill:r,fillRule:"evenodd",clipRule:"evenodd"})})}function q(a){const[r,e]=b.useState(""),s=b.useCallback(t=>{let n=t,d="";for(;n&&!d;){const u=window.getComputedStyle(n).backgroundColor;u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)"&&(d=u),n=n.parentElement}return d||"transparent"},[]);return b.useEffect(()=>{const t=document.getElementById(a);if(t){const n=s(t.parentElement);e(n)}},[a,s]),r}function F({ref:a,id:r,size:e=20,color:s,filled:t=!1,rounded:n=!0,checked:d=!1,onCheckedChange:u,disabled:l,className:m="",...v}){const o=b.useId(),g=b.useMemo(()=>r||`checkbox-${o}`,[r,o]),f=q(g),[c,h]=b.useState(d);b.useEffect(()=>{h(d)},[d]);const w=()=>{l||(h(!c),u==null||u(!c))},p=C=>{C.key===" "&&(C.preventDefault(),w())},j=x.join("flex items-center justify-center border outline outline-transparent focus:outline-current focus:outline-offset-2",n&&"rounded",l&&"opacity-40 cursor-not-allowed",!l&&"cursor-pointer",m);return i.jsx("button",{id:g,type:"button",ref:a,tabIndex:0,role:"checkbox",onClick:w,"aria-checked":c,"aria-disabled":l,onKeyDownCapture:p,style:{width:e,height:e,color:s,backgroundColor:c&&t?"currentcolor":"transparent"},className:j,...v,children:c&&i.jsx(B,{size:e,color:t?f:void 0})})}const G={base:"",default:"ring ring-transparent focus:ring-primary-foreground not-disabled:data-error:ring-danger not-disabled:data-success:ring-success",underline:"border-b border-border focus:border-primary-foreground disabled:border-muted/30 not-disabled:data-error:border-danger not-disabled:data-success:border-success",outline:"border border-border focus:border-primary-foreground disabled:border-muted/30 not-disabled:data-error:border-danger not-disabled:data-success:border-success"},V={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",full:"px-3 rounded-full"},A={variant:"default",rounded:"none"};function E({elementId:a,type:r,message:e}){return b.useEffect(()=>{const s=document.getElementById(a);if(s){if(!e&&r==="error"){s.removeAttribute("data-error");return}if(!e&&r==="success"){s.removeAttribute("data-success");return}return s.setAttribute("aria-describedby",`${a}-${r}-message`),s.setAttribute("aria-invalid",r==="error"?"true":"false"),r==="error"&&s.setAttribute("data-error","true"),r==="success"&&s.setAttribute("data-success","true"),()=>{s.removeAttribute("aria-describedby"),s.removeAttribute("aria-invalid"),s.removeAttribute("data-error"),s.removeAttribute("data-success")}}},[a,r,e]),e?i.jsxs("small",{className:x.join("mt-0.5 text-sm inline-flex items-center gap-1 w-full justify-start",r==="error"&&"text-danger",r==="success"&&"text-success"),role:"status",children:[r==="error"?i.jsx(x.ExclamationTriangle,{}):i.jsx(x.CheckCircled,{}),i.jsx("span",{id:`${a}-${r}-message`,children:e})]}):null}function H({variant:a=A.variant,rounded:r,displayOnlyMode:e=!1,errorMessage:s,successMessage:t,type:n="text",className:d,...u}){const l=b.useId(),[m,v]=b.useState(!1);let o=r;a==="outline"&&!r&&(o="md"),o=o||A.rounded;const c=x.join("appearance-none w-full focus:outline-none disabled:opacity-50 disabled:cursor-not-allowed placeholder:text-muted/70 hide-number-input-arrows transition-all","file:mr-2 file:border-0 file:rounded-md file:px-1.5 file:py-1 file:bg-primary hover:file:bg-primary/85 file:text-sm file:font-medium file:text-foreground file:transition-colors",!e&&G[a],!e&&V[o],n==="password"&&"pr-10",!e&&"px-2 py-1",e&&"pointer-events-none",d);return i.jsxs("div",{className:x.join(e&&"cursor-text"),style:{height:u.height,width:u.width},children:[i.jsxs("div",{className:x.join(n==="password"&&"relative"),children:[i.jsx("input",{...u,id:l,type:n==="password"&&m?"text":n,"aria-disabled":u.disabled,readOnly:e,"aria-readonly":e||u["aria-readonly"],"data-error":s?!0:void 0,"data-success":t?!0:void 0,className:c}),n==="password"&&i.jsx("button",{onClick:()=>v(!m),className:"absolute inset-y-0 right-0 px-2 hover:cursor-pointer","aria-label":"Toggle password visibility","data-state":m?"visible":"hidden",children:m?i.jsx(x.EyeClosed$1,{size:20}):i.jsx(x.EyeClosed,{size:20})})]}),!e&&i.jsx(E,{elementId:l,type:"error",message:s}),!e&&i.jsx(E,{elementId:l,type:"success",message:t})]})}function K({display:a="inline",width:r="fit-content",className:e="",required:s,helpMessage:t,suffix:n,htmlFor:d,children:u,...l}){const m=b.useId(),v=x.join("font-medium",a,e),o=t?`${d??m}-help`:void 0;return i.jsxs("div",{style:{display:a==="inline"?"inline-flex":"flex",width:r},className:"relative",children:[i.jsxs("label",{className:v,htmlFor:d,...l,children:[u,s&&i.jsx("span",{className:"text-red-500 font-medium ml-1","aria-label":"required",children:"*"})]}),t&&i.jsx("span",{className:"text-gray-500 ml-1 size-fit -translate-y-1/3","aria-describedby":o,"aria-label":"Help information",title:t,children:i.jsx(x.QuestionMarkCircled,{})}),t&&i.jsx("div",{id:o,className:"sr-only",children:t}),n&&i.jsx("span",{className:"ml-1",children:n})]})}function k({itemId:a,checked:r,onChange:e,name:s,disabled:t=!1,className:n=""}){const d="relative inline-flex items-center justify-center rounded-full",u=()=>{t||e()},l=x.join(d,!r&&"hover:border-current/60",!t&&"border-current cursor-pointer",t&&"border-muted/60 cursor-not-allowed",n);return i.jsx("div",{id:a,role:"radio",tabIndex:-1,"aria-checked":r,"aria-disabled":t,"aria-description":`Radio button for ${s}`,"aria-labelledby":`${a}-label`,onClick:u,className:l,style:{width:"1em",height:"1em",padding:"0.1em",borderWidth:"0.06em"},children:r&&i.jsx("div",{className:x.join("size-full aspect-square rounded-full",t&&"bg-muted/60",!t&&"bg-current")})})}function y({value:a,children:r,className:e="",isSelected:s=!1,onChange:t,disabled:n=!1,hideInput:d=!1,description:u,name:l}){const v=`radio-${b.useId()}-${a}`,o=()=>{n||t==null||t(a)};return i.jsxs("div",{title:u,className:x.join("relative flex items-center",e,d&&`p-2 border-2 focus-within:border-dashed focus-within:${n?"border-current/50":"border-current/80"}`,d&&!s&&`border-transparent ${n?"":"not-focus-within:hover:border-border/60"}`,d&&s&&"border-border",n&&"opacity-60 cursor-not-allowed"),style:{gap:"0.5em"},children:[!d&&i.jsx(k,{itemId:v,name:l||"",checked:s,onChange:o,disabled:n,className:x.join(d&&"")}),i.jsx("div",{id:d?v:void 0,tabIndex:d?-1:void 0,role:d?"radio":void 0,onClick:d?o:void 0,"aria-checked":d?s?"true":"false":void 0,"aria-disabled":d?n:void 0,"aria-description":d?u||`Radio button for ${l}`:void 0,"aria-labelledby":d?`${v}-label`:void 0,className:x.join(d&&"size-full",typeof r=="object"&&"grow focus:outline-none"),children:i.jsx("label",{id:`${v}-label`,onClick:d?void 0:o,className:x.join(n&&"cursor-not-allowed",!n&&"cursor-pointer"),children:r})})]})}function T(a,r){const[e,s]=b.useState(r),[t,n]=b.useState(-1),[d,u]=b.useState(!1),l=b.useCallback((f,c)=>{var p;const h=f[c];h.hasAttribute("disabled")||h.getAttribute("aria-disabled")==="true"||((p=f[c])==null||p.click(),n(c))},[]),m=b.useCallback((f,c)=>{var w;if(f.preventDefault(),d||!c.length)return;const h=r!==-1?r:0;(w=c[h])==null||w.focus(),s(h),r!==-1&&l(c,h)},[r,d,l]),v=b.useCallback(f=>{var p;if(!f.shiftKey)return;f.preventDefault();const c=Array.from(document.querySelectorAll('a, button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])')).filter(j=>!j.hasAttribute("disabled")&&j.tabIndex>=0),h=c.findIndex(j=>j.id===a),w=h>0?h-1:c.length-1;(p=c[w])==null||p.focus()},[a]),o=b.useCallback((f,c)=>{var C;if(!c.length)return;const h=f.target;if(!c.some(D=>D.id===h.id))return;const p=e!==-1?e:0;let j=p;switch(f.key){case"ArrowUp":case"ArrowLeft":f.preventDefault(),j=p>0?p-1:c.length-1;break;case"ArrowDown":case"ArrowRight":f.preventDefault(),j=(p+1)%c.length;break;case" ":f.preventDefault(),l(c,p);return;case"Tab":v(f);return;default:return}(C=c[j])==null||C.focus(),s(j),t!==-1&&l(c,j)},[e,t,v,l]),g=b.useCallback(()=>{const f=document.querySelector(`[id="${a}"][role="radiogroup"]`);return f?Array.from(f.querySelectorAll('[role="radio"]')):[]},[a]);b.useEffect(()=>{const f=document.querySelector(`[id="${a}"][role="radiogroup"]`);if(!f)return;const c=g(),h=C=>m(C,c),w=C=>o(C,c),p=()=>u(!0),j=()=>u(!1);return document.addEventListener("keydown",w),f.addEventListener("focus",h),f.addEventListener("mousedown",p),document.addEventListener("mouseup",j),()=>{document.removeEventListener("keydown",w),f.removeEventListener("focus",h),f.removeEventListener("mousedown",p),document.removeEventListener("mouseup",j)}},[a,g,m,o])}function U({options:a=[],value:r,onChange:e,name:s,children:t,className:n="",childrenClassName:d="",hideInputs:u=!1}){const l=b.useId(),m=s||`radio-group-${l}`;T(m,a.findIndex(o=>o===r));const v=b.useMemo(()=>a.reduce((o,g)=>(typeof g=="string"?o.some(f=>f.value===g)||o.push({label:g,value:g}):o.push(g),o),[]),[a]);return i.jsxs("div",{id:m,role:"radiogroup",tabIndex:0,className:x.join(n,"focus:outline-none"),children:[v.length>0&&v.map((o,g)=>i.jsx(y,{value:o.value,isSelected:r===o.value,onChange:e,name:m,disabled:o.disabled,description:o.description,hideInput:u,className:d,children:o.label},`${o.value}-${g}`)),v.length===0&&t&&b.Children.map(t,o=>b.isValidElement(o)&&o.type===y?i.jsx(y,{...o.props,className:x.join(d,o.props.className),hideInput:o.props.hideInput||u,isSelected:r===o.props.value,onChange:e,name:m,children:o.props.children}):null)]})}function Q(a,r){b.useEffect(()=>{const e=document.getElementById(a);if(!e)return;if(!r){e.style.height="auto";return}const s=()=>{e.style.height="auto",e.style.height=`${e.scrollHeight}px`};return s(),e.addEventListener("input",s),e.addEventListener("resize",s),window.addEventListener("resize",s),()=>{e.removeEventListener("input",s),e.removeEventListener("resize",s),window.removeEventListener("resize",s)}},[a,r])}const W={base:"","left-line":"border-l border-border focus:border-primary-foreground disabled:border-muted/30 not-disabled:data-error:border-danger not-disabled:data-success:border-success",outline:"border border-border focus:border-primary-foreground disabled:border-muted/30 not-disabled:data-error:border-danger not-disabled:data-success:border-success"},Z={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",full:"px-3 rounded-full"},$={variant:"outline",rounded:"none"};function _({elementId:a,maxLength:r}){const[e,s]=b.useState(0);return b.useEffect(()=>{const t=document.getElementById(a);if(!t)return;const n=()=>{const d=t.value.length;s(d);const u=d>=r;t.setAttribute("aria-describedby",`${a}-character-count`),t.setAttribute("aria-invalid",u?"true":"false"),u?t.setAttribute("data-error","true"):t.removeAttribute("data-error")};return n(),t.addEventListener("input",n),t.setAttribute("maxlength",String(r)),()=>{t.removeEventListener("input",n),t.removeAttribute("maxlength"),t.removeAttribute("aria-describedby"),t.removeAttribute("aria-invalid"),t.removeAttribute("data-error")}},[a,r]),i.jsx("small",{className:x.join("mt-0.5 text-sm inline-flex items-center gap-1 w-full justify-end",e>=r&&"text-danger",e<r&&"text-current"),role:"status",children:i.jsxs("span",{id:`${a}-character-count`,children:[e," / ",r," characters"]})})}function J({variant:a=$.variant,rounded:r,displayOnlyMode:e=!1,errorMessage:s,successMessage:t,hideResizeHandle:n=!1,autoExpand:d=!1,characterLimit:u=0,className:l,...m}){const v=b.useId();Q(v,d||e);let o=r;a==="outline"&&!r&&(o="md"),o=o||$.rounded;let g=n;(e||a==="left-line"&&!n)&&(g=!0);const c=x.join("appearance-none w-full focus:outline-none disabled:opacity-50 disabled:cursor-not-allowed placeholder:text-muted/70 hide-number-input-arrows transition-all",!e&&W[a],!e&&Z[o],!e&&"px-2 py-1",e&&"pointer-events-none",g&&"no-resize-handle",l);return i.jsxs("div",{className:x.join("-space-y-1.5",e&&"cursor-text"),children:[i.jsx("textarea",{...m,id:v,"aria-disabled":m.disabled,readOnly:e,"aria-readonly":e||m["aria-readonly"],style:{resize:d?"none":void 0},className:c}),u>0&&i.jsx(_,{elementId:v,maxLength:u}),!e&&i.jsx(E,{elementId:v,type:"error",message:s}),!e&&i.jsx(E,{elementId:v,type:"success",message:t})]})}exports.Button=z;exports.ButtonLoadingDots=I;exports.Checkbox=F;exports.Input=H;exports.Label=K;exports.RadioGroup=U;exports.RadioGroupItem=y;exports.RadioInput=k;exports.Textarea=J;
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("./join-yP8AS-6v.cjs"),i=require("react/jsx-runtime"),b=require("react");function I(){const[a,r]=b.useState(0);return b.useEffect(()=>{const e=setInterval(()=>{r(s=>(s+1)%3)},500);return()=>clearInterval(e)},[]),i.jsx("div",{className:"absolute inset-0 inline-flex items-center justify-center gap-x-2 align-middle",children:[0,1,2].map(e=>i.jsx("div",{className:x.join("rounded-full transition-all duration-500 ease-in-out size-[0.35em] bg-current",a===e&&"transform -translate-y-1")},e))})}const L={base:"",primary:"bg-primary text-primary-foreground hover:bg-primary/85 disabled:bg-muted disabled:text-muted-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/85 disabled:bg-muted/80 disabled:text-muted-foreground/80",tertiary:"text-primary hover:text-primary-foreground disabled:text-muted",outline:"border border-primary text-primary hover:border-primary-foreground hover:text-primary-foreground disabled:border-muted disabled:text-muted",link:"underline-offset-4 hover:underline disabled:underline disabled:text-muted",danger:"bg-danger text-danger-foreground hover:bg-danger/85 disabled:bg-muted disabled:text-muted-foreground"},S={stripped:"",fitted:"size-fit",sm:"px-2 py-1 text-sm",md:"px-4 py-2 text-base",lg:"px-6 py-3 text-lg",icon:"p-1 w-fit aspect-square",full:"p-2 w-full"},R={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",full:"rounded-full"},N={variant:"primary",size:"md",rounded:"md"};function z({variant:a=N.variant,size:r,rounded:e=N.rounded,loading:s,linkTo:t,linkProps:n,type:d="button",className:u,...l}){let m;a==="link"&&!r?m="fitted":m=r||N.size;const o=x.join("appearance-none focus:outline-none focus:ring not-disabled:hover:cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed transition-all",L[a],S[m],R[e],s&&"relative pointer-events-none",t&&"relative",u);return i.jsxs("button",{...l,role:t?"link":l.role,"aria-label":l["aria-label"]||(n==null?void 0:n["aria-label"]),"aria-description":l["aria-description"]||(n==null?void 0:n["aria-description"]),"aria-disabled":l.disabled||s,"aria-busy":s,type:d,className:o,children:[s&&i.jsx(I,{}),i.jsx("span",{className:x.join(s&&"invisible"),children:l.children}),t&&!l.disabled&&i.jsx("a",{...n,"aria-hidden":!0,href:t,target:(n==null?void 0:n.target)||"_blank",rel:(n==null?void 0:n.rel)||"noreferrer",className:"absolute inset-0"})]})}function B({size:a=15,color:r="currentColor"}){return i.jsx("svg",{width:a,height:a,className:"inline",viewBox:"0 0 15 15",xmlns:"http://www.w3.org/2000/svg",children:i.jsx("path",{d:"M11.4669 3.72684C11.7558 3.91574 11.8369 4.30308 11.648 4.59198L7.39799 11.092C7.29783 11.2452 7.13556 11.3467 6.95402 11.3699C6.77247 11.3931 6.58989 11.3355 6.45446 11.2124L3.70446 8.71241C3.44905 8.48022 3.43023 8.08494 3.66242 7.82953C3.89461 7.57412 4.28989 7.55529 4.5453 7.78749L6.75292 9.79441L10.6018 3.90792C10.7907 3.61902 11.178 3.53795 11.4669 3.72684Z",fill:r,fillRule:"evenodd",clipRule:"evenodd"})})}function q(a){const[r,e]=b.useState(""),s=b.useCallback(t=>{let n=t,d="";for(;n&&!d;){const u=window.getComputedStyle(n).backgroundColor;u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)"&&(d=u),n=n.parentElement}return d||"transparent"},[]);return b.useEffect(()=>{const t=document.getElementById(a);if(t){const n=s(t.parentElement);e(n)}},[a,s]),r}function F({ref:a,id:r,size:e=20,color:s,filled:t=!1,rounded:n=!0,checked:d=!1,onCheckedChange:u,disabled:l,className:m="",...v}){const o=b.useId(),g=b.useMemo(()=>r||`checkbox-${o}`,[r,o]),f=q(g),[c,h]=b.useState(d);b.useEffect(()=>{h(d)},[d]);const w=()=>{l||(h(!c),u==null||u(!c))},p=C=>{C.key===" "&&(C.preventDefault(),w())},j=x.join("flex items-center justify-center border outline outline-transparent focus:outline-current focus:outline-offset-2",n&&"rounded",l&&"opacity-40 cursor-not-allowed",!l&&"cursor-pointer",m);return i.jsx("button",{id:g,type:"button",ref:a,tabIndex:0,role:"checkbox",onClick:w,"aria-checked":c,"aria-disabled":l,onKeyDownCapture:p,style:{width:e,height:e,color:s,backgroundColor:c&&t?"currentcolor":"transparent"},className:j,...v,children:c&&i.jsx(B,{size:e,color:t?f:void 0})})}const G={base:"",default:"ring ring-transparent focus:ring-primary-foreground not-disabled:data-error:ring-danger not-disabled:data-success:ring-success",underline:"border-b border-border focus:border-primary-foreground disabled:border-muted/30 not-disabled:data-error:border-danger not-disabled:data-success:border-success",outline:"border border-border focus:border-primary-foreground disabled:border-muted/30 not-disabled:data-error:border-danger not-disabled:data-success:border-success"},V={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",full:"px-3 rounded-full"},A={variant:"default",rounded:"none"};function E({elementId:a,type:r,message:e}){return b.useEffect(()=>{const s=document.getElementById(a);if(s){if(!e&&r==="error"){s.removeAttribute("data-error");return}if(!e&&r==="success"){s.removeAttribute("data-success");return}return s.setAttribute("aria-describedby",`${a}-${r}-message`),s.setAttribute("aria-invalid",r==="error"?"true":"false"),r==="error"&&s.setAttribute("data-error","true"),r==="success"&&s.setAttribute("data-success","true"),()=>{s.removeAttribute("aria-describedby"),s.removeAttribute("aria-invalid"),s.removeAttribute("data-error"),s.removeAttribute("data-success")}}},[a,r,e]),e?i.jsxs("small",{className:x.join("mt-0.5 text-sm inline-flex items-center gap-1 w-full justify-start",r==="error"&&"text-danger",r==="success"&&"text-success"),role:"status",children:[r==="error"?i.jsx(x.ExclamationTriangle,{}):i.jsx(x.CheckCircled,{}),i.jsx("span",{id:`${a}-${r}-message`,children:e})]}):null}function H({variant:a=A.variant,rounded:r,displayOnlyMode:e=!1,errorMessage:s,successMessage:t,type:n="text",className:d,...u}){const l=b.useId(),[m,v]=b.useState(!1);let o=r;a==="outline"&&!r&&(o="md"),o=o||A.rounded;const c=x.join("appearance-none w-full focus:outline-none disabled:opacity-50 disabled:cursor-not-allowed placeholder:text-muted/70 hide-number-input-arrows transition-all","file:mr-2 file:border-0 file:rounded-md file:px-1.5 file:py-1 file:bg-primary hover:file:bg-primary/85 file:text-sm file:font-medium file:text-foreground file:transition-colors",!e&&G[a],!e&&V[o],n==="password"&&"pr-10",!e&&"px-2 py-1",e&&"pointer-events-none",d);return i.jsxs("div",{className:x.join(e&&"cursor-text"),style:{height:u.height,width:u.width},children:[i.jsxs("div",{className:x.join(n==="password"&&"relative"),children:[i.jsx("input",{...u,id:l,type:n==="password"&&m?"text":n,"aria-disabled":u.disabled,readOnly:e,"aria-readonly":e||u["aria-readonly"],"data-error":s?!0:void 0,"data-success":t?!0:void 0,className:c}),n==="password"&&i.jsx("button",{onClick:()=>v(!m),className:"absolute inset-y-0 right-0 px-2 hover:cursor-pointer","aria-label":"Toggle password visibility","data-state":m?"visible":"hidden",children:m?i.jsx(x.EyeClosed$1,{size:20}):i.jsx(x.EyeClosed,{size:20})})]}),!e&&i.jsx(E,{elementId:l,type:"error",message:s}),!e&&i.jsx(E,{elementId:l,type:"success",message:t})]})}function K({display:a="inline",width:r="fit-content",className:e="",required:s,helpMessage:t,suffix:n,htmlFor:d,children:u,...l}){const m=b.useId(),v=x.join("font-medium",a,e),o=t?`${d??m}-help`:void 0;return i.jsxs("div",{style:{display:a==="inline"?"inline-flex":"flex",width:r},className:"relative",children:[i.jsxs("label",{className:v,htmlFor:d,...l,children:[u,s&&i.jsx("span",{className:"text-red-500 font-medium ml-1","aria-label":"required",children:"*"})]}),t&&i.jsx("span",{className:"text-gray-500 ml-1 size-fit -translate-y-1/3","aria-describedby":o,"aria-label":"Help information",title:t,children:i.jsx(x.QuestionMarkCircled,{})}),t&&i.jsx("div",{id:o,className:"sr-only",children:t}),n&&i.jsx("span",{className:"ml-1",children:n})]})}function k({itemId:a,checked:r,onChange:e,name:s,disabled:t=!1,className:n=""}){const d="relative inline-flex items-center justify-center rounded-full",u=()=>{t||e()},l=x.join(d,!r&&"hover:border-current/60",!t&&"border-current cursor-pointer",t&&"border-muted/60 cursor-not-allowed",n);return i.jsx("div",{id:a,role:"radio",tabIndex:-1,"aria-checked":r,"aria-disabled":t,"aria-description":`Radio button for ${s}`,"aria-labelledby":`${a}-label`,onClick:u,className:l,style:{width:"1em",height:"1em",padding:"0.1em",borderWidth:"0.06em"},children:r&&i.jsx("div",{className:x.join("size-full aspect-square rounded-full",t&&"bg-muted/60",!t&&"bg-current")})})}function y({value:a,children:r,className:e="",isSelected:s=!1,onChange:t,disabled:n=!1,hideInput:d=!1,description:u,name:l}){const v=`radio-${b.useId()}-${a}`,o=()=>{n||t==null||t(a)};return i.jsxs("div",{title:u,className:x.join("relative flex items-center",e,d&&`p-2 border-2 focus-within:border-dashed focus-within:${n?"border-current/50":"border-current/80"}`,d&&!s&&`border-transparent ${n?"":"not-focus-within:hover:border-border/60"}`,d&&s&&"border-border",n&&"opacity-60 cursor-not-allowed"),style:{gap:"0.5em"},children:[!d&&i.jsx(k,{itemId:v,name:l||"",checked:s,onChange:o,disabled:n,className:x.join(d&&"")}),i.jsx("div",{id:d?v:void 0,tabIndex:d?-1:void 0,role:d?"radio":void 0,onClick:d?o:void 0,"aria-checked":d?s?"true":"false":void 0,"aria-disabled":d?n:void 0,"aria-description":d?u||`Radio button for ${l}`:void 0,"aria-labelledby":d?`${v}-label`:void 0,className:x.join(d&&"size-full",typeof r=="object"&&"grow focus:outline-none"),children:i.jsx("label",{id:`${v}-label`,onClick:d?void 0:o,className:x.join(n&&"cursor-not-allowed",!n&&"cursor-pointer"),children:r})})]})}function T(a,r){const[e,s]=b.useState(r),[t,n]=b.useState(-1),[d,u]=b.useState(!1),l=b.useCallback((f,c)=>{var p;const h=f[c];h.hasAttribute("disabled")||h.getAttribute("aria-disabled")==="true"||((p=f[c])==null||p.click(),n(c))},[]),m=b.useCallback((f,c)=>{var w;if(f.preventDefault(),d||!c.length)return;const h=r!==-1?r:0;(w=c[h])==null||w.focus(),s(h),r!==-1&&l(c,h)},[r,d,l]),v=b.useCallback(f=>{var p;if(!f.shiftKey)return;f.preventDefault();const c=Array.from(document.querySelectorAll('a, button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])')).filter(j=>!j.hasAttribute("disabled")&&j.tabIndex>=0),h=c.findIndex(j=>j.id===a),w=h>0?h-1:c.length-1;(p=c[w])==null||p.focus()},[a]),o=b.useCallback((f,c)=>{var C;if(!c.length)return;const h=f.target;if(!c.some(D=>D.id===h.id))return;const p=e!==-1?e:0;let j=p;switch(f.key){case"ArrowUp":case"ArrowLeft":f.preventDefault(),j=p>0?p-1:c.length-1;break;case"ArrowDown":case"ArrowRight":f.preventDefault(),j=(p+1)%c.length;break;case" ":f.preventDefault(),l(c,p);return;case"Tab":v(f);return;default:return}(C=c[j])==null||C.focus(),s(j),t!==-1&&l(c,j)},[e,t,v,l]),g=b.useCallback(()=>{const f=document.querySelector(`[id="${a}"][role="radiogroup"]`);return f?Array.from(f.querySelectorAll('[role="radio"]')):[]},[a]);b.useEffect(()=>{const f=document.querySelector(`[id="${a}"][role="radiogroup"]`);if(!f)return;const c=g(),h=C=>m(C,c),w=C=>o(C,c),p=()=>u(!0),j=()=>u(!1);return document.addEventListener("keydown",w),f.addEventListener("focus",h),f.addEventListener("mousedown",p),document.addEventListener("mouseup",j),()=>{document.removeEventListener("keydown",w),f.removeEventListener("focus",h),f.removeEventListener("mousedown",p),document.removeEventListener("mouseup",j)}},[a,g,m,o])}function U({options:a=[],value:r,onChange:e,name:s,children:t,className:n="",childrenClassName:d="",hideInputs:u=!1}){const l=b.useId(),m=s||`radio-group-${l}`;T(m,a.findIndex(o=>o===r));const v=b.useMemo(()=>a.reduce((o,g)=>(typeof g=="string"?o.some(f=>f.value===g)||o.push({label:g,value:g}):o.push(g),o),[]),[a]);return i.jsxs("div",{id:m,role:"radiogroup",tabIndex:0,className:x.join(n,"focus:outline-none"),children:[v.length>0&&v.map((o,g)=>i.jsx(y,{value:o.value,isSelected:r===o.value,onChange:e,name:m,disabled:o.disabled,description:o.description,hideInput:u,className:d,children:o.label},`${o.value}-${g}`)),v.length===0&&t&&b.Children.map(t,o=>b.isValidElement(o)&&o.type===y?i.jsx(y,{...o.props,className:x.join(d,o.props.className),hideInput:o.props.hideInput||u,isSelected:r===o.props.value,onChange:e,name:m,children:o.props.children}):null)]})}function Q(a,r){b.useEffect(()=>{const e=document.getElementById(a);if(!e)return;if(!r){e.style.height="auto";return}const s=()=>{e.style.height="auto",e.style.height=`${e.scrollHeight}px`};return s(),e.addEventListener("input",s),e.addEventListener("resize",s),window.addEventListener("resize",s),()=>{e.removeEventListener("input",s),e.removeEventListener("resize",s),window.removeEventListener("resize",s)}},[a,r])}const W={base:"","left-line":"border-l border-border focus:border-primary-foreground disabled:border-muted/30 not-disabled:data-error:border-danger not-disabled:data-success:border-success",outline:"border border-border focus:border-primary-foreground disabled:border-muted/30 not-disabled:data-error:border-danger not-disabled:data-success:border-success"},Z={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",lg:"rounded-lg",full:"px-3 rounded-full"},$={variant:"outline",rounded:"none"};function _({elementId:a,maxLength:r}){const[e,s]=b.useState(0);return b.useEffect(()=>{const t=document.getElementById(a);if(!t)return;const n=()=>{const d=t.value.length;s(d);const u=d>=r;t.setAttribute("aria-describedby",`${a}-character-count`),t.setAttribute("aria-invalid",u?"true":"false"),u?t.setAttribute("data-error","true"):t.removeAttribute("data-error")};return n(),t.addEventListener("input",n),t.setAttribute("maxlength",String(r)),()=>{t.removeEventListener("input",n),t.removeAttribute("maxlength"),t.removeAttribute("aria-describedby"),t.removeAttribute("aria-invalid"),t.removeAttribute("data-error")}},[a,r]),i.jsx("small",{className:x.join("mt-0.5 text-sm inline-flex items-center gap-1 w-full justify-end",e>=r&&"text-danger",e<r&&"text-current"),role:"status",children:i.jsxs("span",{id:`${a}-character-count`,children:[e," / ",r," characters"]})})}function J({variant:a=$.variant,rounded:r,displayOnlyMode:e=!1,errorMessage:s,successMessage:t,hideResizeHandle:n=!1,autoExpand:d=!1,characterLimit:u=0,className:l,...m}){const v=b.useId();Q(v,d||e);let o=r;a==="outline"&&!r&&(o="md"),o=o||$.rounded;let g=n;(e||a==="left-line"&&!n)&&(g=!0);const c=x.join("appearance-none w-full focus:outline-none disabled:opacity-50 disabled:cursor-not-allowed placeholder:text-muted/70 hide-number-input-arrows transition-all",!e&&W[a],!e&&Z[o],!e&&"px-2 py-1",e&&"pointer-events-none",g&&"no-resize-handle",l);return i.jsxs("div",{className:x.join("-space-y-1.5",e&&"cursor-text"),children:[i.jsx("textarea",{...m,id:v,"aria-disabled":m.disabled,readOnly:e,"aria-readonly":e||m["aria-readonly"],style:{resize:d?"none":void 0},className:c}),u>0&&i.jsx(_,{elementId:v,maxLength:u}),!e&&i.jsx(E,{elementId:v,type:"error",message:s}),!e&&i.jsx(E,{elementId:v,type:"success",message:t})]})}exports.Button=z;exports.ButtonLoadingDots=I;exports.Checkbox=F;exports.Input=H;exports.Label=K;exports.RadioGroup=U;exports.RadioGroupItem=y;exports.RadioInput=k;exports.Textarea=J;
|
2
2
|
//# sourceMappingURL=components.cjs.js.map
|
package/dist/components.esm.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { jsx as u, jsxs as C } from "react/jsx-runtime";
|
2
1
|
import { j as v, E as S, C as F, b as V, a as q, Q as G } from "./join-DATGxH1G.js";
|
2
|
+
import { jsx as u, jsxs as C } from "react/jsx-runtime";
|
3
3
|
import j, { useState as N, useEffect as A, useCallback as E, useId as $, useMemo as R } from "react";
|
4
4
|
function H() {
|
5
5
|
const [o, r] = N(0);
|
package/dist/components.lib.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "@moondreamsdev/dreamer-ui",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.1",
|
4
4
|
"type": "module",
|
5
5
|
"description": "A collection of Tailwind CSS components for React",
|
6
6
|
"main": "dist/index.js",
|
7
7
|
"module": "dist/index.esm.js",
|
8
|
-
"types": "dist/index.d.ts",
|
8
|
+
"types": "dist/index.lib.d.ts",
|
9
9
|
"files": [
|
10
10
|
"dist",
|
11
11
|
"README.md"
|
12
12
|
],
|
13
13
|
"exports": {
|
14
14
|
".": {
|
15
|
-
"types": "./dist/index.d.ts",
|
15
|
+
"types": "./dist/index.lib.d.ts",
|
16
16
|
"import": "./dist/index.esm.js",
|
17
17
|
"require": "./dist/index.js"
|
18
18
|
},
|
File without changes
|