@verifiedinc-public/shared-ui-elements 9.12.0 → 9.13.0

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
- "use strict";import{useMemo as m,useEffect as v}from"react";import f from"lodash/map";import p from"lodash/sortBy";const c=e=>e.map(r=>({name:r.brandName,value:r.brandUuid,_raw:r}));function y({value:e,multiple:r=!1,onChange:a,brands:u,maximumSelectedBrands:t,defaultBrandUuids:o}){const d=m(()=>(u??[]).map(n=>n),[u]),i=m(()=>p(c(d),[n=>!n._raw.isLiveBrand]),[d]);return v(()=>{if(!i.length)return;const n=o?i.filter(l=>o.includes(l.value)):[];if(r&&Array.isArray(e)){if(!e.length&&n.length)return a?.(n.slice(0,t));const l=f(i,"value");!e.every(s=>l.includes(s.value))&&n.length&&a?.(n.slice(0,t))}else{const l=n[0];if(!Array.isArray(e)){if(!e&&l)return a?.(l);const s=f(i,"value");!(e&&s.includes(e.value))&&l&&a?.(l)}}},[i]),{brandOptions:i}}export{c as toOption,y as useBrandFilterInput};
1
+ "use strict";import{useMemo as m,useEffect as v}from"react";import c from"lodash/map";import p from"lodash/sortBy";const f=a=>a.map(s=>({name:s.brandName,value:s.brandUuid,_raw:s}));function b({value:a,multiple:s=!1,onChange:t,brands:u,maximumSelectedBrands:i,defaultBrandUuids:o}){const d=m(()=>(u??[]).map(e=>e),[u]),l=m(()=>{const e=new Set,n=d.filter(r=>e.has(r.brandUuid)?!1:(e.add(r.brandUuid),!0));return p(f(n),[r=>!r._raw.isLiveBrand])},[d]);return v(()=>{if(!l.length)return;const e=o?l.filter(n=>o.includes(n.value)):[];if(s&&Array.isArray(a)){if(!a.length&&e.length)return t?.(e.slice(0,i));const n=c(l,"value");!a.every(r=>n.includes(r.value))&&e.length&&t?.(e.slice(0,i))}else{const n=e[0];if(!Array.isArray(a)){if(!a&&n)return t?.(n);const r=c(l,"value");!(a&&r.includes(a.value))&&n&&t?.(n)}}},[l]),{brandOptions:l}}export{f as toOption,b as useBrandFilterInput};
@@ -22,5 +22,5 @@ interface BrandFilterInputProps {
22
22
  sx?: SxProps;
23
23
  }
24
24
  export declare function BrandFilterInput({ label, multiple, value, onChange, brands, isLoading, maximumSelectedBrands, groupLiveBrand, selectAll, selectLiveBrands, defaultBrandUuids, debounceMs, sx, }: Readonly<BrandFilterInputProps>): import("react").JSX.Element;
25
- export * from './types';
25
+ export type * from './types';
26
26
  export * from './BrandFilterInput.hook';
@@ -1 +1 @@
1
- "use strict";import{Box as C,Autocomplete as K,TextField as N,Checkbox as P,Typography as R}from"@mui/material";import{useSnackbar as U}from"../Snackbar/index.mjs";import{useState as O,useMemo as m,useEffect as z}from"react";import{useBrandFilterInput as T}from"./BrandFilterInput.hook.mjs";import{toOption as D}from"./BrandFilterInput.hook.mjs";import{jsx as d,jsxs as G}from"react/jsx-runtime";function H({label:I,multiple:t=!1,value:c,onChange:v,brands:_,isLoading:k,maximumSelectedBrands:i,groupLiveBrand:F=!1,selectAll:f=!1,selectLiveBrands:h=!1,defaultBrandUuids:Y,debounceMs:A=2e3,sx:q}){const[s,b]=O(c??null),E=m(()=>{if(!t)return v;let e;return r=>{clearTimeout(e),e=setTimeout(()=>{v(r)},A)}},[t,v,A]),B=e=>{if(t&&Array.isArray(e)){const r=e.slice(0,i);b(r),E(r);return}b(e),v(e)};z(()=>{b(c??null)},[c]);const{enqueueSnackbar:g}=U(),{brandOptions:n}=T({value:c,multiple:t,onChange:B,brands:_,maximumSelectedBrands:i,defaultBrandUuids:Y});let p;if(t?p="multiple":c===void 0?p="empty":p="single",(f||h)&&!t)throw new Error("selectAll and selectLiveBrands props can only be used when multiple is true");const y=m(()=>({selectAll:{name:"Select All",value:"select-all",_raw:{}},selectLiveBrands:{name:"Select Live Brands",value:"select-live-brands",_raw:{}}}),[]),M=m(()=>{if(!t)return n;const e=[];return f&&e.push(y.selectAll),h&&e.push(y.selectLiveBrands),e.length>0?[...e,...n]:n},[t,f,h,y,n]),$=m(()=>{if(!t||!Array.isArray(s)||n.length===0)return{areAllSelected:!1,areLiveBrandsSelected:!1};const e=n.filter(l=>l._raw.isLiveBrand),r=s.filter(l=>l.value!=="select-all"&&l.value!=="select-live-brands"),u=r.length===n.length&&n.every(l=>r.some(o=>o.value===l.value)),a=e.length>0&&e.every(l=>r.some(o=>o.value===l.value));return{areAllSelected:u,areLiveBrandsSelected:a}},[t,s,n]),{areAllSelected:L,areLiveBrandsSelected:S}=$,j=e=>{if(!t||!Array.isArray(e))return e;const r=e.some(a=>a.value==="select-all"),u=e.some(a=>a.value==="select-live-brands");if(r)return L?[]:i&&n.length>i?(g(`You can't select more than ${i} brands.`,"error"),Array.isArray(s)?s.filter(a=>a.value!=="select-all"&&a.value!=="select-live-brands"):[]):n;if(u){const a=n.filter(l=>l._raw.isLiveBrand);return S?Array.isArray(s)?s.filter(l=>l.value!=="select-live-brands"&&!a.some(o=>o.value===l.value)):[]:i&&a.length>i?(g(`You can't select more than ${i} brands.`,"error"),Array.isArray(s)?s.filter(l=>l.value!=="select-all"&&l.value!=="select-live-brands"):[]):[...Array.isArray(s)?s.filter(l=>l.value!=="select-all"&&l.value!=="select-live-brands"&&!a.some(o=>o.value===l.value)):[],...a]}return e.filter(a=>a.value!=="select-all"&&a.value!=="select-live-brands")},[x,w]=O(!1);return d(C,{onClick:()=>{x||w(!0)},sx:{position:"relative",cursor:"pointer",...q},children:d(K,{multiple:t,value:t?s||[]:s,limitTags:3,options:M,getOptionKey:e=>e.value,getOptionLabel:e=>e.name,isOptionEqualToValue:(e,r)=>r?e.value===r.value:!1,open:x,onOpen:()=>{},onClose:()=>w(!1),onChange:(e,r)=>{const u=j(r);if(i&&Array.isArray(u)&&u.length>i&&Array.isArray(c)&&u.length>c.length){g(`You can't select more than ${i} brands.`,"error");return}B(u)},clearOnBlur:!0,disableClearable:!t,disabled:k,disableCloseOnSelect:t,...F&&{groupBy:e=>e.value==="select-all"||e.value==="select-live-brands"?"":e._raw.isLiveBrand?"Live Brands":"Not Live Yet"},renderOption:(e,r,{selected:u})=>{const a=r.value==="select-all"?L:r.value==="select-live-brands"?S:u;return d("li",{...e,children:G(C,{display:"flex",alignItems:"center",width:"100%",children:[t&&d(P,{checked:a,sx:{marginRight:1}}),d(R,{children:r.name})]})})},renderInput:e=>d(N,{...e,label:I,placeholder:"Select...",inputProps:{...e.inputProps,flex:1,width:"100%"},sx:{width:"100%"}})},p)})}export{H as BrandFilterInput,D as toOption,T as useBrandFilterInput};
1
+ "use strict";import{Box as S,Autocomplete as P,TextField as K,Button as U,Checkbox as z,Typography as D}from"@mui/material";import{useSnackbar as G}from"../Snackbar/index.mjs";import{useState as k,useMemo as h,useEffect as H}from"react";import{useBrandFilterInput as M}from"./BrandFilterInput.hook.mjs";import{toOption as J}from"./BrandFilterInput.hook.mjs";import{jsx as u,jsxs as Q}from"react/jsx-runtime";function V({label:I,multiple:a=!1,value:d,onChange:m,brands:_,isLoading:F,maximumSelectedBrands:i,groupLiveBrand:N=!1,selectAll:b=!1,selectLiveBrands:g=!1,defaultBrandUuids:R,debounceMs:x=2e3,sx:Y}){const[o,f]=k(d??null),$=h(()=>{if(!a)return m;let e;return l=>{clearTimeout(e),e=setTimeout(()=>{m(l)},x)}},[a,m,x]),L=e=>{if(a&&Array.isArray(e)){const l=e.slice(0,i);f(l),$(l);return}f(e),m(e)};H(()=>{f(d??null)},[d]);const{enqueueSnackbar:A}=G(),{brandOptions:t}=M({value:d,multiple:a,onChange:L,brands:_,maximumSelectedBrands:i,defaultBrandUuids:R});let p;if(a?p="multiple":d===void 0?p="empty":p="single",(b||g)&&!a)throw new Error("selectAll and selectLiveBrands props can only be used when multiple is true");const y=h(()=>({selectAll:{name:"Select All",value:"select-all",_raw:{}},selectLiveBrands:{name:"Select Only Brands Active in Time Range",value:"select-live-brands",_raw:{}}}),[]),j=h(()=>{if(!a)return t;const e=[];return b&&e.push(y.selectAll),g&&e.push(y.selectLiveBrands),e.length>0?[...e,...t]:t},[a,b,g,y,t]),q=h(()=>{if(!a||!Array.isArray(o)||t.length===0)return{areAllSelected:!1,areLiveBrandsSelected:!1,hasNonLiveBrandsSelected:!1};const e=t.filter(s=>s._raw.isLiveBrand),l=o.filter(s=>s.value!=="select-all"&&s.value!=="select-live-brands"),c=l.length===t.length&&t.every(s=>l.some(v=>v.value===s.value)),r=e.length>0&&e.every(s=>l.some(v=>v.value===s.value)),n=l.some(s=>!e.some(v=>v.value===s.value));return{areAllSelected:c,areLiveBrandsSelected:r,hasNonLiveBrandsSelected:n}},[a,o,t]),{areAllSelected:C,areLiveBrandsSelected:B,hasNonLiveBrandsSelected:T}=q,E=e=>{if(!a||!Array.isArray(e))return e;const l=e.some(r=>r.value==="select-all"),c=e.some(r=>r.value==="select-live-brands");if(l)return C?[]:i&&t.length>i?(A(`You can't select more than ${i} brands.`,"error"),Array.isArray(o)?o.filter(r=>r.value!=="select-all"&&r.value!=="select-live-brands"):[]):t;if(c){const r=t.filter(n=>n._raw.isLiveBrand);return B&&!T?Array.isArray(o)?o.filter(n=>n.value!=="select-all"&&n.value!=="select-live-brands"):[]:i&&r.length>i?(A(`You can't select more than ${i} brands.`,"error"),Array.isArray(o)?o.filter(n=>n.value!=="select-all"&&n.value!=="select-live-brands"):[]):r}return e.filter(r=>r.value!=="select-all"&&r.value!=="select-live-brands")},[w,O]=k(!1);return u(S,{onClick:()=>{w||O(!0)},sx:{position:"relative",cursor:"pointer",...Y},children:u(P,{multiple:a,value:a?o||[]:o,limitTags:3,options:j,getOptionKey:e=>e.value,getOptionLabel:e=>e.name,isOptionEqualToValue:(e,l)=>l?e.value===l.value:!1,open:w,onOpen:()=>{},onClose:()=>O(!1),onChange:(e,l)=>{const c=E(l);if(i&&Array.isArray(c)&&c.length>i&&Array.isArray(d)&&c.length>d.length){A(`You can't select more than ${i} brands.`,"error");return}L(c)},clearOnBlur:!0,disableClearable:!a,disabled:F,disableCloseOnSelect:a,...N&&{groupBy:e=>e.value==="select-all"||e.value==="select-live-brands"?"":e._raw.isLiveBrand?"Active in Time Range":"Not Active in Time Range"},renderOption:(e,l,{selected:c})=>{const{key:r,...n}=e,s=l.value==="select-all"?C:l.value==="select-live-brands"?B:c;return a&&l.value==="select-live-brands"?u(S,{component:"li",...n,onClick:void 0,onTouchStart:void 0,onMouseMove:void 0,sx:{backgroundColor:"transparent!important"},children:u(U,{variant:"contained","data-option-index":n["data-option-index"],onClick:n.onClick,onTouchStart:n.onTouchStart,onMouseMove:n.onMouseMove,disabled:B&&!T,sx:{mx:"auto"},children:l.name})},r):u("li",{...n,children:Q(S,{display:"flex",alignItems:"center",width:"100%",children:[a&&u(z,{checked:s,sx:{marginRight:1}}),u(D,{children:l.name})]})},r)},renderInput:e=>u(K,{...e,label:I,placeholder:"Select...",inputProps:{...e.inputProps,flex:1,width:"100%"},sx:{width:"100%"}})},p)})}export{V as BrandFilterInput,J as toOption,M as useBrandFilterInput};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verifiedinc-public/shared-ui-elements",
3
- "version": "9.12.0",
3
+ "version": "9.13.0",
4
4
  "description": "A set of UI components, utilities that is shareable with the core apps.",
5
5
  "private": false,
6
6
  "sideEffects": false,