@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
|
|
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
|
|
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};
|