@nild/components 0.0.29 → 0.0.31

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.
@@ -1 +1 @@
1
- import{jsx as r}from"react/jsx-runtime";import{useControllableState as g,useEffectCallback as w}from"@nild/hooks";import{isString as u,cnMerge as M}from"@nild/shared";import{forwardRef as S,Children as V,isValidElement as j,cloneElement as G}from"react";import{useGroupContext as P,CheckboxProvider as R}from"./contexts/index.js";import i from"./Indicator.js";import s from"./Label.js";import{checkboxClassNames as I}from"./style/index.js";const h=S((p,f)=>{const t=[],l=new Map,a=P(),{className:v,children:o,variant:C=a?.variant??"solid",size:n=a?.size??"medium",disabled:c=a?.disabled??!1,checked:b,defaultChecked:k,value:d,onChange:m,...x}=p,[y,N]=g(a?a.value.includes(d):b,k??!1),z=w(()=>{c||N(e=>(a?a.setValue(e?a.value.filter(E=>E!==d):a.value.concat(d)):m?.(!e),!e))});return V.forEach(o,e=>{j(e)?e.type===i?(l.delete(i),l.set(i,e)):e.type===s&&(l.delete(s),l.set(s,e)):u(e)&&(l.has(s)||l.set(s,r(s,{children:e})))}),t.push(...l.values()),l.has(i)||t.unshift(r(i,{})),!l.has(s)&&u(o)&&t.push(r(s,{children:o})),r(R,{value:{variant:C,size:n,checked:y,setChecked:z},children:r("label",{...x,className:M(I({size:n,disabled:c}),v),ref:f,children:t.map(e=>G(e,{key:e.type.displayName,...e.props}))})})});h.displayName="Checkbox";export{h as default};
1
+ import{jsx as t}from"react/jsx-runtime";import{useControllableState as E,useEffectCallback as g}from"@nild/hooks";import{isString as w,cnMerge as M}from"@nild/shared";import{forwardRef as S,Children as V,isValidElement as j,cloneElement as G}from"react";import{useGroupContext as P,CheckboxProvider as R}from"./contexts/index.js";import s from"./Indicator.js";import r from"./Label.js";import{checkboxClassNames as I}from"./style/index.js";const m=S((u,p)=>{const i=[],l=new Map,a=P(),{className:f,children:h,variant:v=a?.variant??"solid",size:d=a?.size??"medium",disabled:n=a?.disabled??!1,checked:C,defaultChecked:b,value:o,onChange:c,...k}=u,[y,x]=E(a?a.value.includes(o):C,b??!1),N=g(()=>{n||x(e=>(a?a.setValue(e?a.value.filter(z=>z!==o):a.value.concat(o)):c?.(!e),!e))});return V.forEach(h,e=>{j(e)?e.type===s?(l.delete(s),l.set(s,e)):e.type===r&&(l.delete(r),l.set(r,e)):w(e)&&(l.has(r)||l.set(r,t(r,{children:e})))}),i.push(...l.values()),l.has(s)||i.unshift(t(s,{})),t(R,{value:{variant:v,size:d,checked:y,setChecked:N},children:t("label",{...k,className:M(I({size:d,disabled:n}),f),ref:p,children:i.map(e=>G(e,{key:e.type.displayName,...e.props}))})})});m.displayName="Checkbox";export{m as default};
@@ -1 +1 @@
1
- import{jsx as i}from"react/jsx-runtime";import{usePopupContext as n,useArrowContext as m}from"./contexts/index.js";import{arrowClassNames as p}from"./style/index.js";const r=()=>{const{arrowed:o,size:s,refs:e}=n(),{style:t,orientation:a}=m();return o?i("div",{className:p({orientation:a,size:s}),style:t,ref:e.arrow}):null};r.displayName="Popup.Arrow";export{r as default};
1
+ import{jsx as i}from"react/jsx-runtime";import{usePopupContext as m,useArrowContext as n}from"./contexts/index.js";import{arrowClassNames as p}from"./style/index.js";const r=()=>{const{arrowed:o,size:s,refs:e}=m(),{style:a,orientation:t}=n();return i("div",{className:p({arrowed:o,size:s,orientation:t}),style:a,ref:e.arrow})};r.displayName="Popup.Arrow";export{r as default};
@@ -1 +1 @@
1
- import{jsxs as V,jsx as a}from"react/jsx-runtime";import{useControllableState as q,useEffectCallback as m,useIsomorphicLayoutEffect as x}from"@nild/hooks";import{makeArray as B,isFunction as D}from"@nild/shared";import{Children as G,isValidElement as H,useMemo as J,useState as K,useRef as N}from"react";import Q from"../transition/Transition.js";import{PopupProvider as W,PortalProvider as X,ArrowProvider as Y}from"./contexts/index.js";import Z from"./hooks/usePopup.js";import _ from"./Portal.js";import P from"./Trigger.js";const T=({children:y,placement:f,offset:p,action:d="click",arrowed:E=!0,size:R="medium",open:S,defaultOpen:h=!1,disabled:g,onOpen:v,onClose:w})=>{let s,b,n;G.forEach(y,e=>{if(H(e))switch(e.type){case P:b=e;break;case _:n=e;break;default:s=e;break}});const i=J(()=>new Set(B(d)),[d]),[o,j]=K(h),[r,z]=q(S,h),t=N(),[{triggerRef:l,portalRef:u,portalContext:A,arrowRef:O,arrowContext:F},{update:k,autoUpdate:I}]=Z({placement:f,offset:p}),c=m(e=>{g||z(U=>{const C=D(e)?e(U):e;return C?v?.():w?.(),C})}),L=m(()=>{i.has("hover")&&(t.current&&clearTimeout(t.current),t.current=setTimeout(()=>{c(!0)},100))}),M=m(()=>{i.has("hover")&&(t.current&&clearTimeout(t.current),t.current=setTimeout(()=>{c(!1)},100))});return x(()=>{r&&!o?j(!0):r&&o&&k()},[r,o]),x(()=>{if(!(!l.current||!u.current||!r))return I(l.current,u.current,k)},[f,p,r]),V(W,{value:{actions:i,arrowed:E,size:R,refs:{trigger:l,portal:u,arrow:O},setOpen:c,enter:L,leave:M},children:[b||s&&a(P,{children:s}),a(X,{value:A,children:a(Y,{value:F,children:n&&a(Q,{visible:r,children:o&&n})})})]})};T.displayName="Popup";export{T as default};
1
+ import{jsxs as B,jsx as s}from"react/jsx-runtime";import{useControllableState as D,useEffectCallback as f,useIsomorphicLayoutEffect as G}from"@nild/hooks";import{isArray as H,makeArray as J,isFunction as K}from"@nild/shared";import{Children as Q,isValidElement as U,useState as W,useMemo as X,useRef as Y}from"react";import Z from"../transition/Transition.js";import{PopupProvider as _,PortalProvider as $,ArrowProvider as ee}from"./contexts/index.js";import re from"./hooks/usePopup.js";import te from"./Portal.js";import C from"./Trigger.js";const k=({children:y,placement:g,offset:x,action:p="click",arrowed:P=!0,size:T="medium",delay:t=100,open:A,defaultOpen:d=!1,disabled:E,onOpen:h,onClose:v})=>{let i,w,n;Q.forEach(y,e=>{if(U(e))switch(e.type){case C:w=e;break;case te:n=e;break;default:i=e;break}});const[a,O]=W(d),[o,R]=D(A,d),[S,j=100]=H(t)?t:[t,t],l=X(()=>new Set(J(p)),[p]),r=Y(),[{triggerRef:u,portalRef:c,portalContext:z,arrowRef:F,arrowContext:I},{update:L,autoUpdate:M}]=re({placement:g,offset:x}),m=f(e=>{E||R(q=>{const b=K(e)?e(q):e;return b?h?.():v?.(),b})}),N=f(()=>{l.has("hover")&&(r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{m(!0)},S))}),V=f(()=>{l.has("hover")&&(r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{m(!1)},j))});return G(()=>{if(o&&!a)O(!0);else if(o&&a&&u.current&&c.current)return M(u.current,c.current,L)},[o,a]),B(_,{value:{actions:l,arrowed:P,size:T,refs:{trigger:u,portal:c,arrow:F},setOpen:m,enter:N,leave:V},children:[w||i&&s(C,{children:i}),s($,{value:z,children:s(ee,{value:I,children:n&&s(Z,{visible:o,children:a&&n})})})]})};k.displayName="Popup";export{k as default};
@@ -1 +1 @@
1
- import{jsxs as C,jsx as N}from"react/jsx-runtime";import{mergeRefs as v,cnMerge as r,getDPR as y}from"@nild/shared";import{forwardRef as P,Children as g,isValidElement as h,cloneElement as E}from"react";import{createPortal as M}from"react-dom";import R from"./Arrow.js";import{usePopupContext as j,usePortalContext as w}from"./contexts/index.js";import{portalContentClassNames as $,portalClassNames as z}from"./style/index.js";const o=P(({className:t,style:l,children:n,container:m=document.body,...i},p)=>{var s;const{size:f,refs:c,enter:d,leave:u}=j(),{coords:a}=w(),e=g.toArray(n).find(x=>h(x));return e?M(C("div",{...i,className:r(z(),t),style:{transform:`translate(${a.x}px, ${a.y}px)`,...y()>=1.5&&{willChange:"transform"},...l},onMouseEnter:d,onMouseLeave:u,ref:v(c.portal,p),children:[E(e,{...e.props,className:r($({size:f}),(s=e?.props)==null?void 0:s.className)}),N(R,{})]}),m):null});o.displayName="Popup.Portal";export{o as default};
1
+ import{jsxs as E,jsx as M}from"react/jsx-runtime";import{useEffectCallback as t}from"@nild/hooks";import{mergeRefs as P,cnMerge as n,getDPR as g}from"@nild/shared";import{forwardRef as h,Children as R,isValidElement as b,cloneElement as j}from"react";import{createPortal as w}from"react-dom";import z from"./Arrow.js";import{usePopupContext as L,usePortalContext as $}from"./contexts/index.js";import{portalContentClassNames as k,portalClassNames as A}from"./style/index.js";const m=h(({className:i,style:p,children:f,container:u=document.body,...a},c)=>{var r;const{size:d,refs:v,enter:x,leave:C}=L(),{coords:l}=$(),s=R.toArray(f).find(o=>b(o)),N=t(o=>{var e;(e=a?.onMouseEnter)==null||e.call(a,o),x()}),y=t(o=>{var e;(e=a?.onMouseLeave)==null||e.call(a,o),C()});return s?w(E("div",{...a,className:n(A(),i),style:{transform:`translate(${l.x}px, ${l.y}px)`,...g()>=1.5&&{willChange:"transform"},...p},onMouseEnter:N,onMouseLeave:y,ref:P(v.portal,c),children:[j(s,{...s.props,className:n(k({size:d}),(r=s?.props)==null?void 0:r.className)}),M(z,{})]}),u):null});m.displayName="Popup.Portal";export{m as default};
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @category Components
3
+ */
1
4
  declare const Popup: import('react').FC<import('./interfaces').PopupProps> & {
2
5
  Trigger: import('react').FC<import('./interfaces').TriggerProps>;
3
6
  Portal: import('react').ForwardRefExoticComponent<import('./interfaces').PortalProps & import('react').RefAttributes<HTMLDivElement>>;
@@ -4,4 +4,4 @@ export declare const portalClassNames: (props?: PortalProps | undefined) => stri
4
4
  export declare const portalContentClassNames: (props?: Pick<PopupProps, "size"> | undefined) => string;
5
5
  export declare const arrowClassNames: (props?: ({
6
6
  orientation: ArrowOrientation;
7
- } & Pick<PopupProps, "size">) | undefined) => string;
7
+ } & Pick<PopupProps, "size" | "arrowed">) | undefined) => string;
@@ -1 +1 @@
1
- import{cva as r}from"@nild/shared";const e=r(["nd-popup-trigger"]),o=r(["nd-popup-portal",["absolute","top-0","left-0"]]),a=r(["bg-container","rounded-md",["outline-solid","outline-1","outline-edge"],"shadow-lg"],{variants:{size:{small:["px-2","py-1"],medium:["px-4","py-3"],large:["px-6","py-5"]}}}),t=r(["nd-popup-arrow","absolute","bg-container",["border-solid","border-edge"]],{variants:{orientation:{up:["transform-[translateY(-50%)_rotate(45deg)]",["rounded-tl-sm","border-l-1","border-t-1"]],down:["transform-[translateY(50%)_rotate(45deg)]",["rounded-br-sm","border-r-1","border-b-1"]],left:["transform-[translateX(-50%)_rotate(45deg)]",["rounded-bl-sm","border-l-1","border-b-1"]],right:["transform-[translateX(50%)_rotate(45deg)]",["rounded-tr-sm","border-r-1","border-t-1"]]},size:{small:["w-1.5","h-1.5"],medium:["w-3","h-3"],large:["w-4.5","h-4.5"]}}});export{t as arrowClassNames,o as portalClassNames,a as portalContentClassNames,e as triggerClassNames};
1
+ import{cva as r}from"@nild/shared";const e=r(["nd-popup-trigger"]),a=r(["nd-popup-portal",["absolute","top-0","left-0"]]),o=r(["bg-container","rounded-md",["outline-solid","outline-1","outline-edge"],"shadow-lg"],{variants:{size:{small:["px-2","py-1"],medium:["px-4","py-3"],large:["px-6","py-5"]}}}),t=r(["nd-popup-arrow","absolute","bg-container",["border-solid","border-edge"]],{variants:{arrowed:{true:"",false:["opacity-0","invisible"]},size:{small:["w-1.5","h-1.5"],medium:["w-3","h-3"],large:["w-4.5","h-4.5"]},orientation:{up:["transform-[translateY(-50%)_rotate(45deg)]",["rounded-tl-sm","border-l-1","border-t-1"]],down:["transform-[translateY(50%)_rotate(45deg)]",["rounded-br-sm","border-r-1","border-b-1"]],left:["transform-[translateX(-50%)_rotate(45deg)]",["rounded-bl-sm","border-l-1","border-b-1"]],right:["transform-[translateX(50%)_rotate(45deg)]",["rounded-tr-sm","border-r-1","border-t-1"]]}}});export{t as arrowClassNames,a as portalClassNames,o as portalContentClassNames,e as triggerClassNames};
@@ -1 +1 @@
1
- import{jsx as i}from"react/jsx-runtime";import{useControllableState as R,useEffectCallback as g}from"@nild/hooks";import{isString as c,cnMerge as w}from"@nild/shared";import{forwardRef as x,Children as M,isValidElement as S,cloneElement as V}from"react";import{useGroupContext as j,RadioProvider as G}from"./contexts/index.js";import r from"./Indicator.js";import l from"./Label.js";import{radioClassNames as P}from"./style/index.js";const u=x((h,f)=>{const t=[],s=new Map,a=j(),{className:v,children:o,variant:C=a?.variant??"solid",size:d=a?.size??"medium",disabled:n=a?.disabled??!1,checked:b,defaultChecked:k,value:m,onChange:p,...y}=h,[N,z]=R(a?a.value===m:b,k??!1),E=g(()=>{n||z(e=>e||(a?a.setValue(m):p?.(!e),!e))});return M.forEach(o,e=>{S(e)?e.type===r?(s.delete(r),s.set(r,e)):e.type===l&&(s.delete(l),s.set(l,e)):c(e)&&(s.has(l)||s.set(l,i(l,{children:e})))}),t.push(...s.values()),s.has(r)||t.unshift(i(r,{})),!s.has(l)&&c(o)&&t.push(i(l,{children:o})),i(G,{value:{variant:C,size:d,checked:N,setChecked:E},children:i("label",{...y,className:w(P({size:d,disabled:n}),v),ref:f,children:t.map(e=>V(e,{key:e.type.displayName,...e.props}))})})});u.displayName="Radio";export{u as default};
1
+ import{jsx as r}from"react/jsx-runtime";import{useControllableState as E,useEffectCallback as R}from"@nild/hooks";import{isString as g,cnMerge as w}from"@nild/shared";import{forwardRef as x,Children as M,isValidElement as S,cloneElement as V}from"react";import{useGroupContext as j,RadioProvider as G}from"./contexts/index.js";import i from"./Indicator.js";import l from"./Label.js";import{radioClassNames as P}from"./style/index.js";const c=x((p,u)=>{const t=[],s=new Map,a=j(),{className:f,children:h,variant:v=a?.variant??"solid",size:o=a?.size??"medium",disabled:d=a?.disabled??!1,checked:C,defaultChecked:b,value:m,onChange:n,...k}=p,[y,N]=E(a?a.value===m:C,b??!1),z=R(()=>{d||N(e=>e||(a?a.setValue(m):n?.(!e),!e))});return M.forEach(h,e=>{S(e)?e.type===i?(s.delete(i),s.set(i,e)):e.type===l&&(s.delete(l),s.set(l,e)):g(e)&&(s.has(l)||s.set(l,r(l,{children:e})))}),t.push(...s.values()),s.has(i)||t.unshift(r(i,{})),r(G,{value:{variant:v,size:o,checked:y,setChecked:z},children:r("label",{...k,className:w(P({size:o,disabled:d}),f),ref:u,children:t.map(e=>V(e,{key:e.type.displayName,...e.props}))})})});c.displayName="Radio";export{c as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nild/components",
3
3
  "private": false,
4
- "version": "0.0.29",
4
+ "version": "0.0.31",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
7
7
  "exports": {
@@ -31,9 +31,9 @@
31
31
  "peerDependencies": {
32
32
  "react": "^18.2.0",
33
33
  "react-dom": "^18.2.0",
34
- "@nild/hooks": "0.0.15",
35
- "@nild/shared": "0.0.13",
36
- "@nild/icons": "0.0.14"
34
+ "@nild/shared": "0.0.14",
35
+ "@nild/icons": "0.0.15",
36
+ "@nild/hooks": "0.0.16"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "vite build --mode PROD",