@lifesg/react-design-system 1.0.0-alpha.20 → 1.0.0-alpha.21
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/animations/index.d.ts +1 -0
- package/animations/index.js +6 -3
- package/animations/index.js.map +1 -1
- package/animations/loading-dots-spinner/loading-dots-spinner.d.ts +2 -0
- package/animations/loading-dots-spinner/lottie-animation.d.ts +2 -0
- package/calendar/calendar-day.d.ts +11 -0
- package/calendar/calendar-day.style.d.ts +23 -0
- package/calendar/calendar-month.d.ts +12 -0
- package/calendar/calendar-month.style.d.ts +12 -0
- package/calendar/calendar-year.d.ts +12 -0
- package/calendar/calendar-year.style.d.ts +12 -0
- package/calendar/calendar.d.ts +4 -0
- package/calendar/calendar.style.d.ts +35 -0
- package/calendar/index.d.ts +2 -0
- package/calendar/index.js +381 -0
- package/calendar/index.js.map +1 -0
- package/calendar/package.json +7 -0
- package/calendar/types.d.ts +15 -0
- package/cjs/index.js +426 -221
- package/cjs/index.js.map +1 -1
- package/date-input/index.js +115 -115
- package/date-input/index.js.map +1 -1
- package/error-display/index.js +1 -0
- package/error-display/index.js.map +1 -1
- package/form/index.js +440 -471
- package/form/index.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +461 -256
- package/index.js.map +1 -1
- package/input/index.js +71 -70
- package/input/index.js.map +1 -1
- package/input/input.style.d.ts +3 -7
- package/input-group/index.js +375 -363
- package/input-group/index.js.map +1 -1
- package/input-group/input-group-list-addon.d.ts +1 -1
- package/input-group/input-group-list-addon.style.d.ts +9 -1
- package/input-group/input-group.style.d.ts +4 -7
- package/input-group/types.d.ts +3 -2
- package/input-select/index.js +10 -4
- package/input-select/index.js.map +1 -1
- package/otp-input/index.d.ts +2 -0
- package/otp-input/index.js +600 -0
- package/otp-input/index.js.map +1 -0
- package/otp-input/otp-input.d.ts +3 -0
- package/otp-input/otp-input.styles.d.ts +5 -0
- package/otp-input/package.json +7 -0
- package/otp-input/types.d.ts +22 -0
- package/package.json +1 -1
- package/phone-number-input/index.d.ts +1 -0
- package/phone-number-input/index.js +375 -365
- package/phone-number-input/index.js.map +1 -1
- package/phone-number-input/phone-number-input-helper.d.ts +2 -2
- package/phone-number-input/phone-number-input.d.ts +1 -1
- package/phone-number-input/types.d.ts +9 -0
- package/shared/dropdown-list/dropdown-list.d.ts +1 -1
- package/shared/dropdown-list/types.d.ts +1 -0
- package/shared/input-wrapper/input-wrapper.d.ts +8 -0
- package/unit-number/index.js +256 -302
- package/unit-number/index.js.map +1 -1
- package/unit-number/unit-number-input.style.d.ts +7 -12
- package/util/calendar-helper.d.ts +10 -0
- package/util/index.d.ts +1 -0
- package/phone-number-input/phone-number-input.styles.d.ts +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { InputGroupProps } from "./types";
|
|
3
|
-
export declare const InputGroupListAddon: <T, V>({ addon, error, onChange, ...otherProps }: InputGroupProps<T, V>) => JSX.Element;
|
|
3
|
+
export declare const InputGroupListAddon: <T, V>({ addon, error, onChange, readOnly, className, onBlur, ...otherProps }: InputGroupProps<T, V>) => JSX.Element;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { InputGroupAddonPosition } from "./types";
|
|
2
3
|
interface StyleProps {
|
|
3
4
|
disabled?: boolean;
|
|
5
|
+
$readOnly?: boolean;
|
|
4
6
|
$expanded?: boolean;
|
|
7
|
+
$position?: InputGroupAddonPosition;
|
|
8
|
+
}
|
|
9
|
+
interface DividerStyleProps {
|
|
10
|
+
$readOnly?: boolean;
|
|
11
|
+
$position?: InputGroupAddonPosition;
|
|
5
12
|
}
|
|
6
13
|
export declare const Wrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
7
14
|
export declare const ElementBoundary: import("styled-components").StyledComponent<"div", any, import("../input-select/input-select.styles").InputSelectStyleProps, never>;
|
|
8
15
|
export declare const DisplayContainer: import("styled-components").StyledComponent<"div", any, StyleProps, never>;
|
|
9
16
|
export declare const Selector: import("styled-components").StyledComponent<"button", any, {}, never>;
|
|
17
|
+
export declare const SelectorReadOnly: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
10
18
|
export declare const IconContainer: import("styled-components").StyledComponent<"div", any, StyleProps, never>;
|
|
11
19
|
export declare const StyledChevronIcon: import("styled-components").StyledComponent<{
|
|
12
20
|
(props: import("react").SVGProps<SVGSVGElement>): JSX.Element;
|
|
@@ -15,5 +23,5 @@ export declare const StyledChevronIcon: import("styled-components").StyledCompon
|
|
|
15
23
|
export declare const LabelContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
16
24
|
export declare const ValueLabel: import("styled-components").StyledComponent<"p", any, import("..").TextProps, never>;
|
|
17
25
|
export declare const PlaceholderLabel: import("styled-components").StyledComponent<"p", any, import("..").TextProps, never>;
|
|
18
|
-
export declare const Divider: import("styled-components").StyledComponent<"div", any,
|
|
26
|
+
export declare const Divider: import("styled-components").StyledComponent<"div", any, DividerStyleProps, never>;
|
|
19
27
|
export {};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
2
|
+
import { InputGroupAddonPosition } from "./types";
|
|
3
|
+
export interface AddonStyleProps {
|
|
3
4
|
disabled?: boolean;
|
|
4
5
|
$error?: boolean;
|
|
5
6
|
$readOnly?: boolean;
|
|
6
|
-
$position?:
|
|
7
|
-
}
|
|
8
|
-
interface MainInputStyleProps {
|
|
9
|
-
$position?: "left" | "right" | undefined;
|
|
7
|
+
$position?: InputGroupAddonPosition;
|
|
10
8
|
}
|
|
11
9
|
export declare const Container: import("styled-components").StyledComponent<"div", any, AddonStyleProps, never>;
|
|
12
|
-
export declare const MainInput: import("styled-components").StyledComponent<(props: import("..").InputProps & import("react").RefAttributes<HTMLInputElement>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>, any,
|
|
10
|
+
export declare const MainInput: import("styled-components").StyledComponent<(props: import("..").InputProps & import("react").RefAttributes<HTMLInputElement>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>, any, {}, never>;
|
|
13
11
|
export declare const AddOnContainer: import("styled-components").StyledComponent<"div", any, AddonStyleProps, never>;
|
|
14
|
-
export {};
|
package/input-group/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { InputProps } from "../input/types";
|
|
3
3
|
import { DropdownDisplayProps, DropdownSearchProps, ItemsLoadStateType, TruncateType } from "../shared/dropdown-list/types";
|
|
4
4
|
export declare type InputGroupAddonType = "label" | "list" | "custom";
|
|
5
|
+
export declare type InputGroupAddonPosition = "left" | "right" | undefined;
|
|
5
6
|
export interface CustomAddon {
|
|
6
7
|
children?: JSX.Element | undefined;
|
|
7
8
|
}
|
|
@@ -9,7 +10,6 @@ export interface LabelAddon {
|
|
|
9
10
|
value?: string | undefined;
|
|
10
11
|
}
|
|
11
12
|
export interface ListAddon<T, V> extends DropdownDisplayProps<T, V>, DropdownSearchProps<T> {
|
|
12
|
-
value?: T | undefined;
|
|
13
13
|
placeholder?: string | undefined;
|
|
14
14
|
displayValueExtractor?: ((item: T) => string) | undefined;
|
|
15
15
|
"data-selector-testid"?: string | undefined;
|
|
@@ -30,10 +30,11 @@ export interface ListAddon<T, V> extends DropdownDisplayProps<T, V>, DropdownSea
|
|
|
30
30
|
export interface AddonProps<T, V> {
|
|
31
31
|
type?: InputGroupAddonType | undefined;
|
|
32
32
|
attributes: ListAddon<T, V> | LabelAddon | CustomAddon;
|
|
33
|
-
position?:
|
|
33
|
+
position?: InputGroupAddonPosition;
|
|
34
34
|
}
|
|
35
35
|
export interface InputGroupProps<T, V> extends InputProps {
|
|
36
36
|
addon?: AddonProps<T, V> | undefined;
|
|
37
|
+
onBlur?: (() => void) | undefined;
|
|
37
38
|
}
|
|
38
39
|
/** To be exposed for Form component inheritance */
|
|
39
40
|
export declare type InputGroupPartialProps<T, V> = Omit<InputGroupProps<T, V>, "error">;
|
package/input-select/index.js
CHANGED
|
@@ -465,6 +465,7 @@ import e,{jsxs as t,jsx as n,Fragment as r}from"react/jsx-runtime";import*as i f
|
|
|
465
465
|
background: transparent;
|
|
466
466
|
flex: 1;
|
|
467
467
|
padding: 0 0.5rem 0 0;
|
|
468
|
+
width: 100%;
|
|
468
469
|
|
|
469
470
|
:focus,
|
|
470
471
|
:active {
|
|
@@ -489,14 +490,14 @@ import e,{jsxs as t,jsx as n,Fragment as r}from"react/jsx-runtime";import*as i f
|
|
|
489
490
|
height: 1.375rem;
|
|
490
491
|
width: 1.375rem;
|
|
491
492
|
color: ${Hl.Neutral[3]};
|
|
492
|
-
`,eu=u(((e,r)=>{const{onClear:i,...o}=e;return t(Gc,{children:[n(Kc,{}),n(Xc,{ref:r,...o}),o.value&&n(Yc,{"aria-label":"Clear search",focusOutline:"browser",onClick:i,children:n(Jc,{})})]},"search")})),tu=({listItems:e,listExtractor:i,valueExtractor:o,onSelectItem:s,listStyleWidth:u,visible:d,enableSearch:h,searchPlaceholder:p="Search",onSearch:f,searchFunction:g,onDismiss:m,multiSelect:y,selectedItems:v,onSelectAll:b,onRetry:w,itemsLoadState:_="success",itemTruncationType:S="end",renderListItem:x
|
|
493
|
+
`,eu=u(((e,r)=>{const{onClear:i,...o}=e;return t(Gc,{children:[n(Kc,{}),n(Xc,{ref:r,...o}),o.value&&n(Yc,{"aria-label":"Clear search",focusOutline:"browser",onClick:i,children:n(Jc,{})})]},"search")})),tu=({listItems:e,listExtractor:i,valueExtractor:o,onSelectItem:s,listStyleWidth:u,visible:d,enableSearch:h,searchPlaceholder:p="Search",onSearch:f,searchFunction:g,onDismiss:m,multiSelect:y,selectedItems:v,onSelectAll:b,onRetry:w,itemsLoadState:_="success",itemTruncationType:S="end",renderListItem:x,onBlur:$,...C})=>{const[k,F]=l(0),[j,O]=l(""),[B,A]=l(e),[I,P]=l(0),z=function(e,t){const n=ho.fun(e),[[r],i]=ll(1,n?e:[e],n?t||[]:t);return n||2==arguments.length?[r,i]:r}({height:I}),D=c(),E=c(),H=c([]),M=c(),N=c(k),T=c(B),L=e=>{N.current=e,F(e)},V=e=>{T.current=e,A(e)};a((()=>(document.addEventListener("keydown",Z),()=>{document.removeEventListener("keydown",Z)})),[]),a((()=>{U(j)}),[j]),a((()=>{O(""),d?(P(Q()),M&&M.current?(M.current.focus(),L(-1)):H.current[k]&&H.current[k].focus()):P(0)}),[d]),a((()=>{if(d){const e=Q();P(e)}}),[B]),a((()=>{V(e),O(""),L(0)}),[e]);const R=e=>i?i(e):e.toString(),W=e=>{const t=i?i(e):e.toString();let n=0;return E&&E.current&&(n=E.current.getBoundingClientRect().width-100),hc.shouldTruncateToTwoLines("string"==typeof t?t:t.title,n)},q=e=>qi(v,e)>-1,U=t=>{if(""===t)V(e);else if(g){const e=g(t);V(e)}else{const n=e.filter((e=>{const n=R(e),r="object"==typeof n?n.title.toLowerCase():n.toLowerCase();return"object"==typeof n&&n.secondaryLabel?r.includes(t.trim().toLowerCase())||n.secondaryLabel.includes(t.trim().toLowerCase()):r.includes(t.trim().toLowerCase())}));V(n)}},Q=()=>E&&E.current?E.current.getBoundingClientRect().height:0,Z=e=>{if(D&&D.current.contains(e.target))switch(e.code){case"ArrowDown":if(N.current<T.current.length-1){const e=N.current+1;H.current[e].focus(),L(e)}break;case"ArrowUp":if(N.current>0){const e=N.current-1;H.current[e].focus(),L(N.current-1)}break;case"Escape":m&&m()}},G=(e,t)=>{e.preventDefault(),s&&s(t,(e=>o?o(e):e)(t))},X=e=>{const t=e.target.value;O(t),f&&f()},K=()=>{O(""),f&&f()},Y=()=>{w&&w()},J=()=>{$&&$()},ee=e=>{const r=R(e),i="string"==typeof r?r:r.title;return t(Bc,{"data-testid":"truncate-middle-container",children:[n(Ac,{children:i}),t(Ic,{children:[" ",i]})]})},te=e=>{const i=R(e);return"string"==typeof i?n(r,{children:i}):t(r,{children:[i.title,i.secondaryLabel&&n(Oc,{children:i.secondaryLabel})]})},ne=()=>{if(!w||w&&"success"===_)return B.map(((e,r)=>n(kc,{checked:q(e)&&!y,children:t(Fc,{onClick:t=>{G(t,e)},ref:e=>H.current[r]=e,"data-testid":"list-item",type:"button",tabIndex:d?0:-1,multiSelect:y,onBlur:J,children:[y&&n(Pc,{checked:q(e),displaySize:"small"}),x?x(e,{selected:q(e)}):n(jc,{truncateType:S,children:"middle"===S&&W(e)?ee(e):te(e)})]})},((e,t)=>`item_${t}__${o?o(e):e}`)(e,r))))},re=()=>{if(y&&B.length>0&&!j&&"success"===_)return n(zc,{children:n(Dc,{onClick:b,children:0===v.length?"Select all":"Unselect all"})},"selectAll")},ie=()=>{if(j&&0===B.length)return t(Ec,{"data-testid":"list-no-results",children:[n(Mc,{"data-testid":"no-result-icon"}),n(Hc,{children:"No results found."})]},"noResults")},oe=()=>{if(w&&"loading"===_)return t(Ec,{"data-testid":"list-loading",children:[n(dc,{$buttonStyle:"secondary",size:24}),n(Hc,{children:"Loading..."})]},"loading")},ae=()=>{if(w&&"fail"===_)return t(Ec,{"data-testid":"list-fail",children:[n(Mc,{"data-testid":"load-error-icon"}),n(Hc,{children:"Failed to load."}),n(Dc,{onClick:Y,children:"Try again."})]},"noResults")};return n($c,{style:z,"data-testid":d?"dropdown-container":"dropdown-container-hidden",ref:D,children:(()=>{if(d)return t(Cc,{ref:E,"data-testid":"dropdown-list",width:u,role:"list",...C,children:[(h||g)&&"success"===_?n(eu,{ref:M,onChange:X,value:j,placeholder:p,"data-testid":"search-input","aria-label":"search-input",tabIndex:d?0:-1,onClear:K}):null,re(),ie(),oe(),ae(),ne()]})})()})};var nu,ru={};Object.defineProperty(ru,"__esModule",{value:!0});var iu=e;const ou=e=>iu.jsx("svg",{width:"1em",height:"1em",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:iu.jsx("path",{d:"M2.62611 5.81312C2.84811 5.59112 3.10478 5.48012 3.39611 5.48012C3.68811 5.48012 3.94511 5.59112 4.16711 5.81312L10.1881 11.8341L16.2301 5.79212C16.4381 5.58412 16.6881 5.48012 16.9801 5.48012C17.2714 5.48012 17.5281 5.59112 17.7501 5.81312C17.9588 6.02179 18.0631 6.27545 18.0631 6.57412C18.0631 6.87279 17.9588 7.12612 17.7501 7.33412L10.8131 14.2721C10.7158 14.3688 10.6151 14.4381 10.5111 14.4801C10.4071 14.5215 10.2994 14.5421 10.1881 14.5421C10.0768 14.5421 9.96911 14.5215 9.86511 14.4801C9.76111 14.4381 9.66044 14.3688 9.56311 14.2721L2.60511 7.31312C2.38244 7.09112 2.27811 6.83779 2.29211 6.55312C2.30611 6.26845 2.41744 6.02179 2.62611 5.81312Z",fill:"currentColor"})});ou.displayName="ChevronDownIcon",nu=ru.ChevronDownIcon=ou;const au={collections:{base:{InputBoxShadow:y`
|
|
493
494
|
inset 0 0 6px 1px ${Hl.Shadow.Accent}
|
|
494
495
|
`,InputErrorBoxShadow:y`
|
|
495
496
|
inset 0 0 6px 1px ${Hl.Shadow.Red}
|
|
496
497
|
`}},defaultValue:"base"},su=e=>t=>{const n=t.theme,r=Pl(au,n[zl.designTokenScheme]);return n.options?.designToken?Il(r,e,n.options.designToken):Il(r,e)},lu=su("InputBoxShadow"),cu=su("InputErrorBoxShadow"),uu="all 300ms cubic-bezier(0.21, 0.79, 0.53, 1)",du=g.div`
|
|
497
498
|
position: relative;
|
|
498
499
|
min-height: 3rem;
|
|
499
|
-
height: 3rem;
|
|
500
|
+
height: 3rem; // Need this to persist the height when expanding or collapsing list
|
|
500
501
|
width: 100%;
|
|
501
502
|
|
|
502
503
|
${Tl.tablet} {
|
|
@@ -507,7 +508,8 @@ import e,{jsxs as t,jsx as n,Fragment as r}from"react/jsx-runtime";import*as i f
|
|
|
507
508
|
position: relative;
|
|
508
509
|
align-items: center;
|
|
509
510
|
justify-content: space-between;
|
|
510
|
-
padding: 0
|
|
511
|
+
padding: 0 1rem;
|
|
512
|
+
height: 3rem;
|
|
511
513
|
width: 100%;
|
|
512
514
|
border-radius: ${"4px"};
|
|
513
515
|
cursor: pointer;
|
|
@@ -518,6 +520,10 @@ import e,{jsxs as t,jsx as n,Fragment as r}from"react/jsx-runtime";import*as i f
|
|
|
518
520
|
:active {
|
|
519
521
|
outline: none;
|
|
520
522
|
}
|
|
523
|
+
|
|
524
|
+
:focus-visible {
|
|
525
|
+
outline: 2px solid ${Hl.Accent.Light[3]};
|
|
526
|
+
}
|
|
521
527
|
`,pu=m`
|
|
522
528
|
from {
|
|
523
529
|
position: absolute;
|
|
@@ -609,5 +615,5 @@ import e,{jsxs as t,jsx as n,Fragment as r}from"react/jsx-runtime";import*as i f
|
|
|
609
615
|
overflow: hidden;
|
|
610
616
|
`,wu=g(bu)`
|
|
611
617
|
color: ${Hl.Neutral[3]};
|
|
612
|
-
`,_u=({children:e,show:t,error:r,disabled:i,testId:o,onBlur:s,readOnly:l})=>{const u=c(),d=c(t);a((()=>(document.addEventListener("mousedown",h),()=>{document.removeEventListener("mousedown",h)})),[]),a((()=>{d.current=t}),[t]);const h=e=>{if(!i){if(u&&u.current.contains(e.target))return;d.current&&s()}};return n(du,{children:n(fu,{ref:u,error:r&&!t,disabled:i,$readOnly:l,expanded:t,"data-testid":o,children:e})})},Su=({selectedOption:e,placeholder:i="Select",options:o,disabled:s,error:u,"data-testid":d,id:h,enableSearch:p=!1,searchFunction:f,searchPlaceholder:g,valueExtractor:m,valueToStringFunction:y,listExtractor:v,displayValueExtractor:b,onSelectOption:w,listStyleWidth:_,onShowOptions:S,onHideOptions:x,onRetry:$,optionsLoadState:C="success",optionTruncationType:k="end",renderCustomSelectedOption:F,renderListItem:j,...O})=>{const[B,A]=l(e),[I,P]=l(!1),z=c(),D=c();a((()=>{A(e)}),[e]);const E=(e,t)=>{A(e),P(!1),N(!1),z&&z.current.focus(),w&&w(e,t)},H=()=>{I&&(P(!1),N(!1)),z&&z.current.focus()},M=e=>{if("middle"===k){let t=0;return D&&D.current&&(t=D.current.getBoundingClientRect().width),hc.truncateOneLine((e=>"string"==typeof e?e:y(e)||e.toString())(e),t,120,8)}return e},N=e=>{!e&&x&&x(),e&&S&&S()};return t(_u,{show:I,error:u&&!I,disabled:s,readOnly:O.readOnly,testId:d,onBlur:()=>{P(!1),N(!1)},children:[n(hu,{ref:z,type:"button","data-testid":h||"selector",onClick:e=>{e.preventDefault(),s||O.readOnly||(P(!I),N(!I))},...O,children:t(r,{children:[n(vu,{ref:D,children:B?F?F(B):n(bu,{truncateType:k,children:M(b?b(B):m?m(B):B.toString())}):n(wu,{truncateType:k,children:i})}),!O.readOnly&&n(gu,{expanded:I,children:n(mu,{})})]})}),I&&n(yu,{}),o&&o.length>0?n(tu,{listItems:o,onSelectItem:E,onDismiss:H,valueExtractor:m,listExtractor:v,listStyleWidth:_,visible:I,enableSearch:p,searchPlaceholder:g,searchFunction:f,"data-testid":"dropdown-list",selectedItems:B?[B]:[],onRetry:$,itemsLoadState:C,itemTruncationType:k,renderListItem:j}):null]})},xu=({selectedOptions:e,placeholder:i="Select",options:o,disabled:s,error:u,"data-testid":d,enableSearch:h=!1,searchFunction:p,searchPlaceholder:f,valueExtractor:g,listExtractor:m,onSelectOptions:y,listStyleWidth:v,onShowOptions:b,onHideOptions:w,onRetry:_,optionsLoadState:S="success",optionTruncationType:x="end",...$})=>{const[C,k]=l(e||[]),[F,j]=l(!1),O=c();a((()=>{k(e||[])}),[e]);const B=(e,t)=>{const n=[...C],r=qi(C,(e=>(g?g(e):e)===t));r>-1?n.splice(r,1):n.push(e),k(n),P(!1),O&&O.current.focus(),y&&y(n)},A=()=>{F&&(j(!1),P(!1)),O&&O.current.focus()},I=()=>{C&&C.length>0?(k([]),y([])):(k(o),y(o))},P=e=>{!e&&w&&w(),e&&b&&b()};return t(_u,{show:F,error:u&&!F,disabled:s,testId:d,onBlur:()=>{j(!1),P(!1)},children:[n(hu,{ref:O,type:"button","data-testid":"selector",onClick:e=>{e.preventDefault(),s||(j(!F),P(!F))},...$,children:t(r,{children:[n(vu,{children:C&&0!==C.length?n(bu,{children:C&&0!=C.length?`${C.length} selected`:i}):n(wu,{truncateType:x,children:i})}),n(gu,{expanded:F,children:n(mu,{})})]})}),F&&n(yu,{}),o&&o.length>0||_?n(tu,{listItems:o,onSelectItem:B,onDismiss:A,valueExtractor:g,listExtractor:m,listStyleWidth:v,visible:F,enableSearch:h,searchFunction:p,searchPlaceholder:f,"data-testid":"dropdown-list",multiSelect:!0,selectedItems:C,onSelectAll:I,onRetry:_,itemsLoadState:S,itemTruncationType:x}):null]})};export{xu as InputMultiSelect,Su as InputSelect};
|
|
618
|
+
`,_u=({children:e,show:t,error:r,disabled:i,testId:o,onBlur:s,readOnly:l})=>{const u=c(),d=c(t);a((()=>(document.addEventListener("mousedown",h),()=>{document.removeEventListener("mousedown",h)})),[]),a((()=>{d.current=t}),[t]);const h=e=>{if(!i){if(u&&u.current.contains(e.target))return;d.current&&s()}};return n(du,{children:n(fu,{ref:u,error:r&&!t,disabled:i,$readOnly:l,expanded:t,"data-testid":o,children:e})})},Su=({selectedOption:e,placeholder:i="Select",options:o,disabled:s,error:u,"data-testid":d,id:h,enableSearch:p=!1,searchFunction:f,searchPlaceholder:g,valueExtractor:m,valueToStringFunction:y,listExtractor:v,displayValueExtractor:b,onSelectOption:w,listStyleWidth:_,onShowOptions:S,onHideOptions:x,onRetry:$,optionsLoadState:C="success",optionTruncationType:k="end",renderCustomSelectedOption:F,renderListItem:j,...O})=>{const[B,A]=l(e),[I,P]=l(!1),z=c(),D=c();a((()=>{A(e)}),[e]);const E=(e,t)=>{A(e),P(!1),N(!1),z&&z.current.focus(),w&&w(e,t)},H=()=>{I&&(P(!1),N(!1)),z&&z.current.focus()},M=e=>{if("middle"===k){let t=0;return D&&D.current&&(t=D.current.getBoundingClientRect().width),hc.truncateOneLine((e=>"string"==typeof e?e:y(e)||e.toString())(e),t,120,8)}return e},N=e=>{!e&&x&&x(),e&&S&&S()};return t(_u,{show:I,error:u&&!I,disabled:s,readOnly:O.readOnly,testId:d,onBlur:()=>{P(!1),N(!1)},children:[n(hu,{ref:z,type:"button","data-testid":h||"selector",disabled:s,onClick:e=>{e.preventDefault(),s||O.readOnly||(P(!I),N(!I))},...O,children:t(r,{children:[n(vu,{ref:D,children:B?F?F(B):n(bu,{truncateType:k,children:M(b?b(B):m?m(B):B.toString())}):n(wu,{truncateType:k,children:i})}),!O.readOnly&&n(gu,{expanded:I,children:n(mu,{})})]})}),I&&n(yu,{}),o&&o.length>0?n(tu,{listItems:o,onSelectItem:E,onDismiss:H,valueExtractor:m,listExtractor:v,listStyleWidth:_,visible:I,enableSearch:p,searchPlaceholder:g,searchFunction:f,"data-testid":"dropdown-list",selectedItems:B?[B]:[],onRetry:$,itemsLoadState:C,itemTruncationType:k,renderListItem:j}):null]})},xu=({selectedOptions:e,placeholder:i="Select",options:o,disabled:s,error:u,"data-testid":d,enableSearch:h=!1,searchFunction:p,searchPlaceholder:f,valueExtractor:g,listExtractor:m,onSelectOptions:y,listStyleWidth:v,onShowOptions:b,onHideOptions:w,onRetry:_,optionsLoadState:S="success",optionTruncationType:x="end",...$})=>{const[C,k]=l(e||[]),[F,j]=l(!1),O=c();a((()=>{k(e||[])}),[e]);const B=(e,t)=>{const n=[...C],r=qi(C,(e=>(g?g(e):e)===t));r>-1?n.splice(r,1):n.push(e),k(n),P(!1),O&&O.current.focus(),y&&y(n)},A=()=>{F&&(j(!1),P(!1)),O&&O.current.focus()},I=()=>{C&&C.length>0?(k([]),y([])):(k(o),y(o))},P=e=>{!e&&w&&w(),e&&b&&b()};return t(_u,{show:F,error:u&&!F,disabled:s,testId:d,onBlur:()=>{j(!1),P(!1)},children:[n(hu,{ref:O,type:"button","data-testid":"selector",onClick:e=>{e.preventDefault(),s||(j(!F),P(!F))},...$,children:t(r,{children:[n(vu,{children:C&&0!==C.length?n(bu,{children:C&&0!=C.length?`${C.length} selected`:i}):n(wu,{truncateType:x,children:i})}),n(gu,{expanded:F,children:n(mu,{})})]})}),F&&n(yu,{}),o&&o.length>0||_?n(tu,{listItems:o,onSelectItem:B,onDismiss:A,valueExtractor:g,listExtractor:m,listStyleWidth:v,visible:F,enableSearch:h,searchFunction:p,searchPlaceholder:f,"data-testid":"dropdown-list",multiSelect:!0,selectedItems:C,onSelectAll:I,onRetry:_,itemsLoadState:S,itemTruncationType:x}):null]})};export{xu as InputMultiSelect,Su as InputSelect};
|
|
613
619
|
//# sourceMappingURL=index.js.map
|