@economic/taco 1.31.1 → 1.32.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Header/Header.d.ts +1 -1
- package/dist/components/Header/components/AgreementSelector.d.ts +1 -1
- package/dist/esm/packages/taco/src/components/Header/Header.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Header/components/AgreementSelector.js +1 -1
- package/dist/esm/packages/taco/src/components/Header/components/AgreementSelector.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Collection/components/Root.js +3 -2
- package/dist/esm/packages/taco/src/primitives/Collection/components/Root.js.map +1 -1
- package/dist/taco.cjs.development.js +4 -3
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/package.json +2 -2
- package/types.json +3 -2
@@ -6,6 +6,7 @@ import { PrimaryNavigation } from './components/PrimaryNavigation';
|
|
6
6
|
import { SecondaryNavigation } from './components/SecondaryNavigation';
|
7
7
|
import { MenuButton } from './components/MenuButton';
|
8
8
|
import { AgreementSelector, AgreementDisplay } from './components/AgreementSelector';
|
9
|
+
export * from './components/Agreement/types';
|
9
10
|
export declare type HeaderTexts = {
|
10
11
|
addAgreement: string;
|
11
12
|
logout: string;
|
@@ -26,4 +27,3 @@ export declare type ForwardedHeaderWithStatics = React.ForwardRefExoticComponent
|
|
26
27
|
MenuButton: typeof MenuButton;
|
27
28
|
};
|
28
29
|
export declare const Header: ForwardedHeaderWithStatics;
|
29
|
-
export {};
|
@@ -5,7 +5,7 @@ export declare type AgreementSelectorProps = {
|
|
5
5
|
currentAgreement: Agreement;
|
6
6
|
fallbackImageSrc: string;
|
7
7
|
filterAgreement: (agreement: Agreement, filter: (agreement: Agreement) => boolean) => void;
|
8
|
-
filterClientAgreement: (agreement: Agreement, filter: (agreement: Agreement) => boolean) => void;
|
8
|
+
filterClientAgreement: (agreement: Agreement, searchValue: string, filter: (agreement: Agreement) => boolean) => void;
|
9
9
|
onAddAgreement?: () => void;
|
10
10
|
onChangeAgreement: (agreement: Agreement) => void;
|
11
11
|
onLogout: () => void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Header.js","sources":["../../../../../../../src/components/Header/Header.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Button } from './components/Button';\nimport { Link } from './components/Link';\nimport { Logo, LogoLegacy } from './components/Logo';\nimport { PrimaryNavigation } from './components/PrimaryNavigation';\nimport { SecondaryNavigation } from './components/SecondaryNavigation';\nimport { MenuButton } from './components/MenuButton';\nimport { AgreementSelector, AgreementDisplay } from './components/AgreementSelector';\n\nexport type HeaderTexts = {\n addAgreement: string;\n logout: string;\n more: string;\n new: string;\n search: string;\n};\n\ntype HeaderProps = React.HTMLAttributes<HTMLElement>;\n\nexport type ForwardedHeaderWithStatics = React.ForwardRefExoticComponent<HeaderProps & React.RefAttributes<HTMLDivElement>> & {\n AgreementDisplay: typeof AgreementDisplay;\n AgreementSelector: typeof AgreementSelector;\n Button: typeof Button;\n Link: typeof Link;\n Logo: typeof Logo;\n LogoLegacy: typeof LogoLegacy;\n PrimaryNavigation: typeof PrimaryNavigation;\n SecondaryNavigation: typeof SecondaryNavigation;\n MenuButton: typeof MenuButton;\n};\n\nexport const Header = React.forwardRef<HTMLDivElement, HeaderProps>(function Header(props, ref) {\n const className = cn(\n 'bg-blue-900 flex h-16 w-full shrink-0 items-center gap-2 pl-4',\n '[&>*:focus-visible]:yt-focus-dark [&>*]:rounded', // styles for logo wrapped inside an anchor\n props.className\n );\n\n return <header {...props} className={className} ref={ref} />;\n}) as ForwardedHeaderWithStatics;\n\nHeader.AgreementDisplay = AgreementDisplay;\nHeader.AgreementSelector = AgreementSelector;\nHeader.Button = Button;\nHeader.Link = Link;\nHeader.Logo = Logo;\nHeader.LogoLegacy = LogoLegacy;\nHeader.PrimaryNavigation = PrimaryNavigation;\nHeader.SecondaryNavigation = SecondaryNavigation;\nHeader.MenuButton = MenuButton;\n"],"names":["Header","React","forwardRef","props","ref","className","cn","AgreementDisplay","AgreementSelector","Button","Link","Logo","LogoLegacy","PrimaryNavigation","SecondaryNavigation","MenuButton"],"mappings":";;;;;;;;;;
|
1
|
+
{"version":3,"file":"Header.js","sources":["../../../../../../../src/components/Header/Header.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { Button } from './components/Button';\nimport { Link } from './components/Link';\nimport { Logo, LogoLegacy } from './components/Logo';\nimport { PrimaryNavigation } from './components/PrimaryNavigation';\nimport { SecondaryNavigation } from './components/SecondaryNavigation';\nimport { MenuButton } from './components/MenuButton';\nimport { AgreementSelector, AgreementDisplay } from './components/AgreementSelector';\n\nexport * from './components/Agreement/types';\n\nexport type HeaderTexts = {\n addAgreement: string;\n logout: string;\n more: string;\n new: string;\n search: string;\n};\n\ntype HeaderProps = React.HTMLAttributes<HTMLElement>;\n\nexport type ForwardedHeaderWithStatics = React.ForwardRefExoticComponent<HeaderProps & React.RefAttributes<HTMLDivElement>> & {\n AgreementDisplay: typeof AgreementDisplay;\n AgreementSelector: typeof AgreementSelector;\n Button: typeof Button;\n Link: typeof Link;\n Logo: typeof Logo;\n LogoLegacy: typeof LogoLegacy;\n PrimaryNavigation: typeof PrimaryNavigation;\n SecondaryNavigation: typeof SecondaryNavigation;\n MenuButton: typeof MenuButton;\n};\n\nexport const Header = React.forwardRef<HTMLDivElement, HeaderProps>(function Header(props, ref) {\n const className = cn(\n 'bg-blue-900 flex h-16 w-full shrink-0 items-center gap-2 pl-4',\n '[&>*:focus-visible]:yt-focus-dark [&>*]:rounded', // styles for logo wrapped inside an anchor\n props.className\n );\n\n return <header {...props} className={className} ref={ref} />;\n}) as ForwardedHeaderWithStatics;\n\nHeader.AgreementDisplay = AgreementDisplay;\nHeader.AgreementSelector = AgreementSelector;\nHeader.Button = Button;\nHeader.Link = Link;\nHeader.Logo = Logo;\nHeader.LogoLegacy = LogoLegacy;\nHeader.PrimaryNavigation = PrimaryNavigation;\nHeader.SecondaryNavigation = SecondaryNavigation;\nHeader.MenuButton = MenuButton;\n"],"names":["Header","React","forwardRef","props","ref","className","cn","AgreementDisplay","AgreementSelector","Button","Link","Logo","LogoLegacy","PrimaryNavigation","SecondaryNavigation","MenuButton"],"mappings":";;;;;;;;;;MAkCaA,MAAM,gBAAGC,cAAK,CAACC,UAAU,CAA8B,SAASF,MAAM,CAACG,KAAK,EAAEC,GAAG;EAC1F,MAAMC,SAAS,GAAGC,EAAE,CAChB,+DAA+D,EAC/D,iDAAiD;;EACjDH,KAAK,CAACE,SAAS,CAClB;EAED,oBAAOJ,yDAAYE,KAAK;IAAEE,SAAS,EAAEA,SAAS;IAAED,GAAG,EAAEA;KAAO;AAChE,CAAC;AAEDJ,MAAM,CAACO,gBAAgB,GAAGA,gBAAgB;AAC1CP,MAAM,CAACQ,iBAAiB,GAAGA,iBAAiB;AAC5CR,MAAM,CAACS,MAAM,GAAGA,MAAM;AACtBT,MAAM,CAACU,IAAI,GAAGA,IAAI;AAClBV,MAAM,CAACW,IAAI,GAAGA,IAAI;AAClBX,MAAM,CAACY,UAAU,GAAGA,UAAU;AAC9BZ,MAAM,CAACa,iBAAiB,GAAGA,iBAAiB;AAC5Cb,MAAM,CAACc,mBAAmB,GAAGA,mBAAmB;AAChDd,MAAM,CAACe,UAAU,GAAGA,UAAU;;;;"}
|
@@ -85,7 +85,7 @@ function AgreementSelector(props) {
|
|
85
85
|
return /*#__PURE__*/React__default.createElement("span", {
|
86
86
|
className: "flex flex-col gap-px [&>*:first-child>span]:!rounded-t [&>*:last-child>span]:!rounded-b [&>*>span]:!rounded-none",
|
87
87
|
key: `${agreement.number}_${agreement.userId}_clients`
|
88
|
-
}, filterBySearchValue(search)(agreement) ? button : null, agreement.clients.filter(agreement => filterClientAgreement(agreement, filterBySearchValue(search))).map(clientAgreement => createAgreementButton(clientAgreement, fallbackImageSrc, handleChangeAgreement, isCurrentAgreement(clientAgreement, currentAgreement))));
|
88
|
+
}, filterBySearchValue(search)(agreement) ? button : null, agreement.clients.filter(agreement => filterClientAgreement(agreement, search, filterBySearchValue(search))).map(clientAgreement => createAgreementButton(clientAgreement, fallbackImageSrc, handleChangeAgreement, isCurrentAgreement(clientAgreement, currentAgreement))));
|
89
89
|
}
|
90
90
|
return button;
|
91
91
|
})), handleAddAgreement ? /*#__PURE__*/React__default.createElement(Button, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AgreementSelector.js","sources":["../../../../../../../../src/components/Header/components/AgreementSelector.tsx"],"sourcesContent":["import React from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport * as CollectionPrimitive from '../../../primitives/Collection/Collection';\nimport { AgreementItem } from './Agreement/Item';\nimport { createCustomKeyboardEvent } from '../../../utils/input';\nimport { Icon } from '../../Icon/Icon';\nimport { SearchInput } from '../../SearchInput/SearchInput';\nimport { Button } from '../../Button/Button';\nimport { useLocalization } from '../../Provider/Localization';\nimport { Agreement } from './Agreement/types';\nimport { AgreementDisplay as Display } from './Agreement/Display';\n\nconst Container = props => {\n return (\n <div\n className=\"-ml-2 flex flex-shrink-0 flex-grow-0 items-center gap-2 pr-2 xl:ml-auto xl:w-64\"\n data-taco=\"header-agreements\">\n <span className=\"hidden h-8 w-px flex-shrink-0 flex-grow-0 bg-white/[0.3] xl:flex\" />\n {props.children}\n </div>\n );\n};\n\nexport type AgreementSelectorProps = {\n agreements: Agreement[];\n currentAgreement: Agreement;\n fallbackImageSrc: string;\n filterAgreement: (agreement: Agreement, filter: (agreement: Agreement) => boolean) => void;\n filterClientAgreement: (agreement: Agreement, filter: (agreement: Agreement) => boolean) => void;\n onAddAgreement?: () => void;\n onChangeAgreement: (agreement: Agreement) => void;\n onLogout: () => void;\n open?: boolean;\n setOpen?: (open: boolean) => void;\n};\n\nexport function AgreementSelector(props: AgreementSelectorProps) {\n const {\n agreements,\n currentAgreement,\n fallbackImageSrc,\n filterAgreement = () => true,\n filterClientAgreement = () => true,\n onAddAgreement: handleAddAgreement,\n onChangeAgreement,\n onLogout: handleLogout,\n open: prop,\n setOpen: onChange,\n } = props;\n const { texts } = useLocalization();\n const collectionRef = React.useRef<CollectionPrimitive.CollectionRef | null>(null);\n const [open, setOpen] = useControllableState<boolean>({\n onChange,\n prop,\n });\n const [search, setSearch] = React.useState('');\n\n React.useEffect(() => {\n setSearch('');\n }, [open]);\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {\n event.preventDefault();\n collectionRef.current?.dispatchEvent(createCustomKeyboardEvent(event as React.KeyboardEvent<HTMLInputElement>));\n }\n };\n\n const handleChangeAgreement = (agreement: Agreement) => {\n onChangeAgreement(agreement);\n setOpen(false);\n };\n\n return (\n <Container>\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <PopoverPrimitive.Trigger className=\"xl:focus-visible:yt-focus-dark [&:focus-visible_img]:yt-focus-dark w-full rounded outline-none xl:[&:focus-visible_img]:shadow-none\">\n <Display currentAgreement={currentAgreement} fallbackImageSrc={fallbackImageSrc}>\n {agreements ? (\n <Icon\n className=\"ml-auto hidden flex-shrink-0 flex-grow-0 text-white xl:flex\"\n name={open ? 'chevron-up' : 'chevron-down'}\n />\n ) : null}\n </Display>\n </PopoverPrimitive.Trigger>\n <PopoverPrimitive.Content className=\"z-[996] mt-2 flex h-[calc(100vh_-_theme(spacing.16))] w-64 flex-col gap-1 bg-blue-900\">\n <SearchInput\n autoFocus\n className=\"focus-visible:!yt-focus-dark mx-2 !border-transparent !bg-white/[0.08] !text-white hover:!bg-white/[0.16] hover:!shadow-none focus:!bg-white/[0.16] active:!bg-white/[0.16] [&+div>button]:!text-white\"\n onChange={event => setSearch(event.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={texts.header.search}\n />\n <CollectionPrimitive.Root\n querySelector=\"button\"\n className=\"-my-1 flex w-full flex-grow flex-col gap-1 overflow-auto px-2 py-1 outline-none\"\n ref={collectionRef}\n tabIndex={-1}>\n {agreements\n ?.filter(agreement => filterAgreement(agreement, filterBySearchValue(search)))\n .map(agreement => {\n const button = createAgreementButton(\n agreement,\n fallbackImageSrc,\n handleChangeAgreement,\n isCurrentAgreement(agreement, currentAgreement)\n );\n\n if (agreement.clients) {\n return (\n <span\n className=\"flex flex-col gap-px [&>*:first-child>span]:!rounded-t [&>*:last-child>span]:!rounded-b [&>*>span]:!rounded-none\"\n key={`${agreement.number}_${agreement.userId}_clients`}>\n {filterBySearchValue(search)(agreement) ? button : null}\n {agreement.clients\n .filter(agreement =>\n filterClientAgreement(agreement, filterBySearchValue(search))\n )\n .map(clientAgreement =>\n createAgreementButton(\n clientAgreement,\n fallbackImageSrc,\n handleChangeAgreement,\n isCurrentAgreement(clientAgreement, currentAgreement)\n )\n )}\n </span>\n );\n }\n\n return button;\n })}\n </CollectionPrimitive.Root>\n {handleAddAgreement ? (\n <Button\n className=\"focus-visible:!yt-focus-dark my-1 mx-2 !h-9 shrink-0 !bg-white/[0.08] !text-white hover:!bg-white/[0.16]\"\n onClick={handleAddAgreement}>\n {texts.header.addAgreement}\n </Button>\n ) : null}\n <hr className=\"my-0 h-px w-full bg-white/[0.08]\" />\n <a\n className=\"focus-visible:yt-focus-dark mx-2 mb-2 flex h-8 shrink-0 items-center justify-center rounded text-white hover:cursor-pointer hover:text-white hover:underline focus-visible:outline-none\"\n onClick={handleLogout}\n tabIndex={0}>\n {texts.header.logout}\n </a>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Root>\n </Container>\n );\n}\n\nconst filterBySearchValue = (search: string) => (agreement: Agreement) => {\n if (!search || !search.length) {\n return true;\n }\n\n const matchesAgreementNumber = String(agreement.number).indexOf(search) > -1;\n const matchesCompanyName = agreement.name.toLowerCase().indexOf(search.toLowerCase()) > -1;\n\n return matchesAgreementNumber || matchesCompanyName;\n};\n\nconst isCurrentAgreement = (agreement: Agreement, currentAgreement: Agreement) => {\n return agreement.number === currentAgreement.number && agreement.userId === currentAgreement.userId;\n};\n\nconst createAgreementButton = (\n agreement: Agreement,\n fallbackImageSrc: string,\n onChangeAgreement: (agreement: Agreement) => void,\n isCurrentAgreement = false\n) => {\n const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === 'Enter') {\n onChangeAgreement(agreement);\n }\n };\n\n return (\n <button\n aria-current={isCurrentAgreement ? 'true' : undefined}\n className=\"focus:yt-focus-dark w-full rounded outline-none\"\n data-taco=\"header-agreements-agreement\"\n key={`${agreement.number}_${agreement.userId}`}\n onClick={() => onChangeAgreement(agreement)}\n onKeyDown={handleKeyDown}\n tabIndex={0}>\n <AgreementItem\n {...agreement}\n className=\"h-14 bg-white/[0.08] xl:hover:bg-white/[0.16] [[aria-current='true']>&]:bg-white/[0.16]\"\n fallbackImageSrc={fallbackImageSrc}\n />\n </button>\n );\n};\n\nexport type AgreementDisplayProps = React.HTMLAttributes<HTMLDivElement> & {\n currentAgreement: Agreement;\n fallbackImageSrc: string;\n};\n\nexport function AgreementDisplay(props: AgreementDisplayProps) {\n const { currentAgreement, fallbackImageSrc } = props;\n\n return (\n <Container>\n <Display currentAgreement={currentAgreement} fallbackImageSrc={fallbackImageSrc} />\n </Container>\n );\n}\n"],"names":["Container","props","React","className","children","AgreementSelector","agreements","currentAgreement","fallbackImageSrc","filterAgreement","filterClientAgreement","onAddAgreement","handleAddAgreement","onChangeAgreement","onLogout","handleLogout","open","prop","setOpen","onChange","texts","useLocalization","collectionRef","useRef","useControllableState","search","setSearch","useState","useEffect","handleKeyDown","event","key","preventDefault","current","dispatchEvent","createCustomKeyboardEvent","handleChangeAgreement","agreement","PopoverPrimitive","onOpenChange","Display","Icon","name","SearchInput","autoFocus","target","value","onKeyDown","placeholder","header","CollectionPrimitive","querySelector","ref","tabIndex","filter","filterBySearchValue","map","button","createAgreementButton","isCurrentAgreement","clients","number","userId","clientAgreement","Button","onClick","addAgreement","logout","length","matchesAgreementNumber","String","indexOf","matchesCompanyName","toLowerCase","undefined","AgreementItem","AgreementDisplay"],"mapp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AMb,kBAAkB,GAAG,CAACtB,SAAoB,EAAE9B,gBAA2B;EACzE,OAAO8B,SAAS,CAACwB,MAAM,KAAKtD,gBAAgB,CAACsD,MAAM,IAAIxB,SAAS,CAACyB,MAAM,KAAKvD,gBAAgB,CAACuD,MAAM;AACvG,CAAC;AAED,MAAMJ,qBAAqB,GAAG,CAC1BrB,SAAoB,EACpB7B,gBAAwB,EACxBK,iBAAiD,EACjD8C,kBAAkB,GAAG,KAAK;EAE1B,MAAM9B,aAAa,GAAIC,KAA6C;IAChE,IAAIA,KAAK,CAACC,GAAG,KAAK,OAAO,EAAE;MACvBlB,iBAAiB,CAACwB,SAAS,CAAC;;GAEnC;EAED,oBACInC;oBACkByD,kBAAkB,GAAG,MAAM,GAAGe,SAAS;IACrDvE,SAAS,EAAC,iDAAiD;iBACjD,6BAA6B;IACvC4B,GAAG,KAAKM,SAAS,CAACwB,UAAUxB,SAAS,CAACyB,QAAQ;IAC9CG,OAAO,EAAE,MAAMpD,iBAAiB,CAACwB,SAAS,CAAC;IAC3CU,SAAS,EAAElB,aAAa;IACxBwB,QAAQ,EAAE;kBACVnD,6BAACyE,aAAa,oBACNtC,SAAS;IACblC,SAAS,EAAC,yFAAyF;IACnGK,gBAAgB,EAAEA;KACpB,CACG;AAEjB,CAAC;SAOeoE,gBAAgB,CAAC3E,KAA4B;EACzD,MAAM;IAAEM,gBAAgB;IAAEC;GAAkB,GAAGP,KAAK;EAEpD,oBACIC,6BAACF,SAAS,qBACNE,6BAACsC,kBAAO;IAACjC,gBAAgB,EAAEA,gBAAgB;IAAEC,gBAAgB,EAAEA;IAAoB,CAC3E;AAEpB;;;;"}
|
1
|
+
{"version":3,"file":"AgreementSelector.js","sources":["../../../../../../../../src/components/Header/components/AgreementSelector.tsx"],"sourcesContent":["import React from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport * as CollectionPrimitive from '../../../primitives/Collection/Collection';\nimport { AgreementItem } from './Agreement/Item';\nimport { createCustomKeyboardEvent } from '../../../utils/input';\nimport { Icon } from '../../Icon/Icon';\nimport { SearchInput } from '../../SearchInput/SearchInput';\nimport { Button } from '../../Button/Button';\nimport { useLocalization } from '../../Provider/Localization';\nimport { Agreement } from './Agreement/types';\nimport { AgreementDisplay as Display } from './Agreement/Display';\n\nconst Container = props => {\n return (\n <div\n className=\"-ml-2 flex flex-shrink-0 flex-grow-0 items-center gap-2 pr-2 xl:ml-auto xl:w-64\"\n data-taco=\"header-agreements\">\n <span className=\"hidden h-8 w-px flex-shrink-0 flex-grow-0 bg-white/[0.3] xl:flex\" />\n {props.children}\n </div>\n );\n};\n\nexport type AgreementSelectorProps = {\n agreements: Agreement[];\n currentAgreement: Agreement;\n fallbackImageSrc: string;\n filterAgreement: (agreement: Agreement, filter: (agreement: Agreement) => boolean) => void;\n filterClientAgreement: (agreement: Agreement, searchValue: string, filter: (agreement: Agreement) => boolean) => void;\n onAddAgreement?: () => void;\n onChangeAgreement: (agreement: Agreement) => void;\n onLogout: () => void;\n open?: boolean;\n setOpen?: (open: boolean) => void;\n};\n\nexport function AgreementSelector(props: AgreementSelectorProps) {\n const {\n agreements,\n currentAgreement,\n fallbackImageSrc,\n filterAgreement = () => true,\n filterClientAgreement = () => true,\n onAddAgreement: handleAddAgreement,\n onChangeAgreement,\n onLogout: handleLogout,\n open: prop,\n setOpen: onChange,\n } = props;\n const { texts } = useLocalization();\n const collectionRef = React.useRef<CollectionPrimitive.CollectionRef | null>(null);\n const [open, setOpen] = useControllableState<boolean>({\n onChange,\n prop,\n });\n const [search, setSearch] = React.useState('');\n\n React.useEffect(() => {\n setSearch('');\n }, [open]);\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {\n event.preventDefault();\n collectionRef.current?.dispatchEvent(createCustomKeyboardEvent(event as React.KeyboardEvent<HTMLInputElement>));\n }\n };\n\n const handleChangeAgreement = (agreement: Agreement) => {\n onChangeAgreement(agreement);\n setOpen(false);\n };\n\n return (\n <Container>\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n <PopoverPrimitive.Trigger className=\"xl:focus-visible:yt-focus-dark [&:focus-visible_img]:yt-focus-dark w-full rounded outline-none xl:[&:focus-visible_img]:shadow-none\">\n <Display currentAgreement={currentAgreement} fallbackImageSrc={fallbackImageSrc}>\n {agreements ? (\n <Icon\n className=\"ml-auto hidden flex-shrink-0 flex-grow-0 text-white xl:flex\"\n name={open ? 'chevron-up' : 'chevron-down'}\n />\n ) : null}\n </Display>\n </PopoverPrimitive.Trigger>\n <PopoverPrimitive.Content className=\"z-[996] mt-2 flex h-[calc(100vh_-_theme(spacing.16))] w-64 flex-col gap-1 bg-blue-900\">\n <SearchInput\n autoFocus\n className=\"focus-visible:!yt-focus-dark mx-2 !border-transparent !bg-white/[0.08] !text-white hover:!bg-white/[0.16] hover:!shadow-none focus:!bg-white/[0.16] active:!bg-white/[0.16] [&+div>button]:!text-white\"\n onChange={event => setSearch(event.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={texts.header.search}\n />\n <CollectionPrimitive.Root\n querySelector=\"button\"\n className=\"-my-1 flex w-full flex-grow flex-col gap-1 overflow-auto px-2 py-1 outline-none\"\n ref={collectionRef}\n tabIndex={-1}>\n {agreements\n ?.filter(agreement => filterAgreement(agreement, filterBySearchValue(search)))\n .map(agreement => {\n const button = createAgreementButton(\n agreement,\n fallbackImageSrc,\n handleChangeAgreement,\n isCurrentAgreement(agreement, currentAgreement)\n );\n\n if (agreement.clients) {\n return (\n <span\n className=\"flex flex-col gap-px [&>*:first-child>span]:!rounded-t [&>*:last-child>span]:!rounded-b [&>*>span]:!rounded-none\"\n key={`${agreement.number}_${agreement.userId}_clients`}>\n {filterBySearchValue(search)(agreement) ? button : null}\n {agreement.clients\n .filter(agreement =>\n filterClientAgreement(agreement, search, filterBySearchValue(search))\n )\n .map(clientAgreement =>\n createAgreementButton(\n clientAgreement,\n fallbackImageSrc,\n handleChangeAgreement,\n isCurrentAgreement(clientAgreement, currentAgreement)\n )\n )}\n </span>\n );\n }\n\n return button;\n })}\n </CollectionPrimitive.Root>\n {handleAddAgreement ? (\n <Button\n className=\"focus-visible:!yt-focus-dark my-1 mx-2 !h-9 shrink-0 !bg-white/[0.08] !text-white hover:!bg-white/[0.16]\"\n onClick={handleAddAgreement}>\n {texts.header.addAgreement}\n </Button>\n ) : null}\n <hr className=\"my-0 h-px w-full bg-white/[0.08]\" />\n <a\n className=\"focus-visible:yt-focus-dark mx-2 mb-2 flex h-8 shrink-0 items-center justify-center rounded text-white hover:cursor-pointer hover:text-white hover:underline focus-visible:outline-none\"\n onClick={handleLogout}\n tabIndex={0}>\n {texts.header.logout}\n </a>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Root>\n </Container>\n );\n}\n\nconst filterBySearchValue = (search: string) => (agreement: Agreement) => {\n if (!search || !search.length) {\n return true;\n }\n\n const matchesAgreementNumber = String(agreement.number).indexOf(search) > -1;\n const matchesCompanyName = agreement.name.toLowerCase().indexOf(search.toLowerCase()) > -1;\n\n return matchesAgreementNumber || matchesCompanyName;\n};\n\nconst isCurrentAgreement = (agreement: Agreement, currentAgreement: Agreement) => {\n return agreement.number === currentAgreement.number && agreement.userId === currentAgreement.userId;\n};\n\nconst createAgreementButton = (\n agreement: Agreement,\n fallbackImageSrc: string,\n onChangeAgreement: (agreement: Agreement) => void,\n isCurrentAgreement = false\n) => {\n const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === 'Enter') {\n onChangeAgreement(agreement);\n }\n };\n\n return (\n <button\n aria-current={isCurrentAgreement ? 'true' : undefined}\n className=\"focus:yt-focus-dark w-full rounded outline-none\"\n data-taco=\"header-agreements-agreement\"\n key={`${agreement.number}_${agreement.userId}`}\n onClick={() => onChangeAgreement(agreement)}\n onKeyDown={handleKeyDown}\n tabIndex={0}>\n <AgreementItem\n {...agreement}\n className=\"h-14 bg-white/[0.08] xl:hover:bg-white/[0.16] [[aria-current='true']>&]:bg-white/[0.16]\"\n fallbackImageSrc={fallbackImageSrc}\n />\n </button>\n );\n};\n\nexport type AgreementDisplayProps = React.HTMLAttributes<HTMLDivElement> & {\n currentAgreement: Agreement;\n fallbackImageSrc: string;\n};\n\nexport function AgreementDisplay(props: AgreementDisplayProps) {\n const { currentAgreement, fallbackImageSrc } = props;\n\n return (\n <Container>\n <Display currentAgreement={currentAgreement} fallbackImageSrc={fallbackImageSrc} />\n </Container>\n );\n}\n"],"names":["Container","props","React","className","children","AgreementSelector","agreements","currentAgreement","fallbackImageSrc","filterAgreement","filterClientAgreement","onAddAgreement","handleAddAgreement","onChangeAgreement","onLogout","handleLogout","open","prop","setOpen","onChange","texts","useLocalization","collectionRef","useRef","useControllableState","search","setSearch","useState","useEffect","handleKeyDown","event","key","preventDefault","current","dispatchEvent","createCustomKeyboardEvent","handleChangeAgreement","agreement","PopoverPrimitive","onOpenChange","Display","Icon","name","SearchInput","autoFocus","target","value","onKeyDown","placeholder","header","CollectionPrimitive","querySelector","ref","tabIndex","filter","filterBySearchValue","map","button","createAgreementButton","isCurrentAgreement","clients","number","userId","clientAgreement","Button","onClick","addAgreement","logout","length","matchesAgreementNumber","String","indexOf","matchesCompanyName","toLowerCase","undefined","AgreementItem","AgreementDisplay"],"mappings":";;;;;;;;;;;;;AAaA,MAAMA,SAAS,GAAGC,KAAK;EACnB,oBACIC;IACIC,SAAS,EAAC,iFAAiF;iBACjF;kBACVD;IAAMC,SAAS,EAAC;IAAqE,EACpFF,KAAK,CAACG,QAAQ,CACb;AAEd,CAAC;SAeeC,iBAAiB,CAACJ,KAA6B;EAC3D,MAAM;IACFK,UAAU;IACVC,gBAAgB;IAChBC,gBAAgB;IAChBC,eAAe,GAAG,MAAM,IAAI;IAC5BC,qBAAqB,GAAG,MAAM,IAAI;IAClCC,cAAc,EAAEC,kBAAkB;IAClCC,iBAAiB;IACjBC,QAAQ,EAAEC,YAAY;IACtBC,I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CAACwB,SAAS,CAAC;;GAEnC;EAED,oBACInC;oBACkByD,kBAAkB,GAAG,MAAM,GAAGe,SAAS;IACrDvE,SAAS,EAAC,iDAAiD;iBACjD,6BAA6B;IACvC4B,GAAG,KAAKM,SAAS,CAACwB,UAAUxB,SAAS,CAACyB,QAAQ;IAC9CG,OAAO,EAAE,MAAMpD,iBAAiB,CAACwB,SAAS,CAAC;IAC3CU,SAAS,EAAElB,aAAa;IACxBwB,QAAQ,EAAE;kBACVnD,6BAACyE,aAAa,oBACNtC,SAAS;IACblC,SAAS,EAAC,yFAAyF;IACnGK,gBAAgB,EAAEA;KACpB,CACG;AAEjB,CAAC;SAOeoE,gBAAgB,CAAC3E,KAA4B;EACzD,MAAM;IAAEM,gBAAgB;IAAEC;GAAkB,GAAGP,KAAK;EAEpD,oBACIC,6BAACF,SAAS,qBACNE,6BAACsC,kBAAO;IAACjC,gBAAgB,EAAEA,gBAAgB;IAAEC,gBAAgB,EAAEA;IAAoB,CAC3E;AAEpB;;;;"}
|
@@ -95,9 +95,10 @@ const Root = /*#__PURE__*/React__default.forwardRef(function CollectionRoot(prop
|
|
95
95
|
if (nextActiveIndex !== undefined && nextActiveIndex !== activeIndex) {
|
96
96
|
setActiveOption(nextActiveIndex, event.currentTarget, options.item(nextActiveIndex));
|
97
97
|
}
|
98
|
-
} else if (activeIndex !== undefined) {
|
98
|
+
} else if (activeIndex !== undefined && !!options.item(activeIndex)) {
|
99
|
+
var _options$item;
|
99
100
|
// forward events onto the underlying option - this lets consumers place onKeyDown handlers on their own components
|
100
|
-
options.item(activeIndex).dispatchEvent(createCustomKeyboardEvent(event));
|
101
|
+
(_options$item = options.item(activeIndex)) === null || _options$item === void 0 ? void 0 : _options$item.dispatchEvent(createCustomKeyboardEvent(event));
|
101
102
|
}
|
102
103
|
}
|
103
104
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Root.js","sources":["../../../../../../../../src/primitives/Collection/components/Root.tsx"],"sourcesContent":["import React from 'react';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { isAriaDirectionKey } from '../../../utils/aria';\nimport { createCustomKeyboardEvent } from '../../../utils/input';\n\n/* This component provides a keyboard navigable collection primitive for use in lists\n * It is unlikely you need to edit this component\n */\n\nexport type CollectionProps = React.HTMLAttributes<HTMLDivElement> & {\n querySelector: string;\n};\n\nexport type CollectionRef = HTMLDivElement & {\n setActiveIndex: (option: HTMLDivElement) => void;\n};\n\nconst getOptionsFromCollection = (collection: HTMLDivElement, selector: string): NodeListOf<Element> =>\n collection.querySelectorAll(selector);\n\n// we use javascript to set attributes (rather than cloning children and adding them)\n// so that we can support nesting (e.g. groups) - child elements that aren't options.\n// without doing this we would have to unwrap and flatten all groups\nexport const Root = React.forwardRef<CollectionRef, CollectionProps>(function CollectionRoot(props, ref) {\n const { querySelector, tabIndex = 0, ...otherProps } = props;\n const internalRef = useMergedRef<CollectionRef>(ref);\n const [activeIndex, setActiveIndex] = React.useState<number | undefined>();\n const lastLengthRef = React.useRef(0);\n\n const setActiveOption = (index: number, collection: HTMLDivElement, option: Element) => {\n collection.querySelector(`[aria-current]`)?.removeAttribute('aria-current');\n option.setAttribute('aria-current', 'true');\n option.scrollIntoView({ block: 'nearest' });\n setActiveIndex(index);\n };\n\n const setActiveIndexByElement = React.useCallback(\n (option: HTMLDivElement) => {\n if (internalRef.current) {\n if (option.matches(querySelector)) {\n const options = getOptionsFromCollection(internalRef.current, querySelector);\n const nextActiveIndex = Array.from(options).indexOf(option);\n\n if (nextActiveIndex > -1) {\n setActiveOption(nextActiveIndex, internalRef.current, option);\n }\n }\n }\n },\n [internalRef.current, querySelector]\n );\n\n React.useEffect(() => {\n if (internalRef.current) {\n internalRef.current.setActiveIndex = setActiveIndexByElement;\n }\n }, [internalRef.current]);\n\n React.useEffect(() => {\n if (internalRef.current) {\n const options = getOptionsFromCollection(internalRef.current, querySelector);\n\n if (options.length && options.length !== lastLengthRef.current) {\n let selected = internalRef.current.querySelectorAll(`[aria-current=\"true\"]`);\n\n if (selected.length === 0) {\n selected = internalRef.current.querySelectorAll(`[aria-selected]`);\n }\n\n if (selected.length === 1) {\n if (options) {\n const firstSelected = selected.item(0);\n const selectedIndex = Array.from(options).indexOf(firstSelected);\n\n if (selectedIndex > -1) {\n setActiveOption(selectedIndex, internalRef.current, firstSelected);\n }\n }\n } else {\n // multiple selected or none selected should go to 0\n setActiveOption(0, internalRef.current, options.item(0));\n }\n }\n\n lastLengthRef.current = options.length;\n }\n }, [props.children]);\n\n const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const option = event.target as HTMLElement;\n\n if (option.matches(querySelector)) {\n const options = getOptionsFromCollection(event.currentTarget, querySelector);\n const nextActiveIndex = Array.from(options).indexOf(option);\n\n if (nextActiveIndex > -1) {\n setActiveOption(nextActiveIndex, event.currentTarget, option);\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n // this stops the event dispatched to the option rebounding back and starting an infinite loop\n if (event.target !== event.currentTarget) {\n return;\n }\n\n if (otherProps.onKeyDown) {\n otherProps.onKeyDown(event);\n }\n\n if (event.isDefaultPrevented()) {\n return;\n }\n\n const options = getOptionsFromCollection(event.currentTarget, querySelector);\n\n if (options) {\n if (isAriaDirectionKey(event)) {\n event.preventDefault();\n event.stopPropagation();\n const nextActiveIndex = getNextEnabledItem(event, options, activeIndex);\n\n if (nextActiveIndex !== undefined && nextActiveIndex !== activeIndex) {\n setActiveOption(nextActiveIndex, event.currentTarget, options.item(nextActiveIndex));\n }\n } else if (activeIndex !== undefined) {\n // forward events onto the underlying option - this lets consumers place onKeyDown handlers on their own components\n options\n .item(activeIndex)\n .dispatchEvent(createCustomKeyboardEvent(event as React.KeyboardEvent<HTMLInputElement>));\n }\n }\n };\n\n return <div {...otherProps} onClick={handleClick} onKeyDown={handleKeyDown} ref={internalRef} tabIndex={tabIndex} />;\n});\n\nexport const getNextIndexFromKeycode = (\n event: React.KeyboardEvent,\n length: number,\n activeIndex: number | undefined\n): number | undefined => {\n switch (event.key) {\n case 'ArrowUp':\n return activeIndex === undefined ? length - 1 : activeIndex > 0 ? activeIndex - 1 : activeIndex;\n\n case 'ArrowDown':\n return activeIndex === undefined ? 0 : activeIndex < length - 1 ? activeIndex + 1 : activeIndex;\n\n case 'Home':\n return 0;\n\n case 'End':\n return length - 1;\n\n default:\n return;\n }\n};\n\nexport const getNextEnabledItem = (\n event: React.KeyboardEvent<HTMLElement>,\n options: NodeListOf<Element>,\n activeIndex: number | undefined,\n recurse = true\n): number | undefined => {\n const nextIndex = getNextIndexFromKeycode(event, options.length, activeIndex);\n\n if (nextIndex !== undefined) {\n if (nextIndex === activeIndex) {\n return activeIndex;\n } else if (options.item(nextIndex) && isSkippableItem(options.item(nextIndex))) {\n // check in the other direction if the first or last item is disabled,\n // but prevent infinite loops if all elements are disabled by disabling recursion\n if (recurse) {\n if (nextIndex === 0) {\n return getNextEnabledItem(\n new KeyboardEvent(event.type, { ...(event as any), key: 'ArrowDown' }) as any,\n options,\n nextIndex,\n false\n );\n } else if (nextIndex === options.length - 1) {\n return getNextEnabledItem(\n new KeyboardEvent(event.type, { ...(event as any), key: 'ArrowUp' }) as any,\n options,\n nextIndex,\n false\n );\n }\n }\n\n return getNextEnabledItem(event, options, nextIndex, recurse);\n }\n }\n\n return nextIndex;\n};\n\nconst isSkippableItem = (element: Element) => {\n return (\n element.getAttribute('role') === 'presentation' ||\n !!element.hasAttribute('disabled') ||\n !!element.getAttribute('aria-disabled') ||\n !!element.getAttribute('aria-hidden')\n );\n};\n"],"names":["getOptionsFromCollection","collection","selector","querySelectorAll","Root","React","forwardRef","CollectionRoot","props","ref","querySelector","tabIndex","otherProps","internalRef","useMergedRef","activeIndex","setActiveIndex","useState","lastLengthRef","useRef","setActiveOption","index","option","removeAttribute","setAttribute","scrollIntoView","block","setActiveIndexByElement","useCallback","current","matches","options","nextActiveIndex","Array","from","indexOf","useEffect","length","selected","firstSelected","item","selectedIndex","children","handleClick","event","target","currentTarget","handleKeyDown","onKeyDown","isDefaultPrevented","isAriaDirectionKey","preventDefault","stopPropagation","getNextEnabledItem","undefined","dispatchEvent","createCustomKeyboardEvent","onClick","getNextIndexFromKeycode","key","recurse","nextIndex","isSkippableItem","KeyboardEvent","type","element","getAttribute","hasAttribute"],"mappings":";;;;;AAiBA,MAAMA,wBAAwB,GAAG,CAACC,UAA0B,EAAEC,QAAgB,KAC1ED,UAAU,CAACE,gBAAgB,CAACD,QAAQ,CAAC;AAEzC;AACA;AACA;MACaE,IAAI,gBAAGC,cAAK,CAACC,UAAU,CAAiC,SAASC,cAAc,CAACC,KAAK,EAAEC,GAAG;EACnG,MAAM;IAAEC,aAAa;IAAEC,QAAQ,GAAG,CAAC;IAAE,GAAGC;GAAY,GAAGJ,KAAK;EAC5D,MAAMK,WAAW,GAAGC,YAAY,CAAgBL,GAAG,CAAC;EACpD,MAAM,CAACM,WAAW,EAAEC,cAAc,CAAC,GAAGX,cAAK,CAACY,QAAQ,EAAsB;EAC1E,MAAMC,aAAa,GAAGb,cAAK,CAACc,MAAM,CAAC,CAAC,CAAC;EAErC,MAAMC,eAAe,GAAG,CAACC,KAAa,EAAEpB,UAA0B,EAAEqB,MAAe;;IAC/E,yBAAArB,UAAU,CAACS,aAAa,iBAAiB,CAAC,0DAA1C,sBAA4Ca,eAAe,CAAC,cAAc,CAAC;IAC3ED,MAAM,CAACE,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC;IAC3CF,MAAM,CAACG,cAAc,CAAC;MAAEC,KAAK,EAAE;KAAW,CAAC;IAC3CV,cAAc,CAACK,KAAK,CAAC;GACxB;EAED,MAAMM,uBAAuB,GAAGtB,cAAK,CAACuB,WAAW,CAC5CN,MAAsB;IACnB,IAAIT,WAAW,CAACgB,OAAO,EAAE;MACrB,IAAIP,MAAM,CAACQ,OAAO,CAACpB,aAAa,CAAC,EAAE;QAC/B,MAAMqB,OAAO,GAAG/B,wBAAwB,CAACa,WAAW,CAACgB,OAAO,EAAEnB,aAAa,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KP,SAAS,EAAE;IACzB,IAAIO,SAAS,KAAK9C,WAAW,EAAE;MAC3B,OAAOA,WAAW;KACrB,MAAM,IAAIgB,OAAO,CAACS,IAAI,CAACqB,SAAS,CAAC,IAAIC,eAAe,CAAC/B,OAAO,CAACS,IAAI,CAACqB,SAAS,CAAC,CAAC,EAAE;;;MAG5E,IAAID,OAAO,EAAE;QACT,IAAIC,SAAS,KAAK,CAAC,EAAE;UACjB,OAAOR,kBAAkB,CACrB,IAAIU,aAAa,CAACnB,KAAK,CAACoB,IAAI,EAAE;YAAE,GAAIpB,KAAa;YAAEe,GAAG,EAAE;WAAa,CAAQ,EAC7E5B,OAAO,EACP8B,SAAS,EACT,KAAK,CACR;SACJ,MAAM,IAAIA,SAAS,KAAK9B,OAAO,CAACM,MAAM,GAAG,CAAC,EAAE;UACzC,OAAOgB,kBAAkB,CACrB,IAAIU,aAAa,CAACnB,KAAK,CAACoB,IAAI,EAAE;YAAE,GAAIpB,KAAa;YAAEe,GAAG,EAAE;WAAW,CAAQ,EAC3E5B,OAAO,EACP8B,SAAS,EACT,KAAK,CACR;;;MAIT,OAAOR,kBAAkB,CAACT,KAAK,EAAEb,OAAO,EAAE8B,SAAS,EAAED,OAAO,CAAC;;;EAIrE,OAAOC,SAAS;AACpB;AAEA,MAAMC,eAAe,GAAIG,OAAgB;EACrC,OACIA,OAAO,CAACC,YAAY,CAAC,MAAM,CAAC,KAAK,cAAc,IAC/C,CAAC,CAACD,OAAO,CAACE,YAAY,CAAC,UAAU,CAAC,IAClC,CAAC,CAACF,OAAO,CAACC,YAAY,CAAC,eAAe,CAAC,IACvC,CAAC,CAACD,OAAO,CAACC,YAAY,CAAC,aAAa,CAAC;AAE7C,CAAC;;;;"}
|
1
|
+
{"version":3,"file":"Root.js","sources":["../../../../../../../../src/primitives/Collection/components/Root.tsx"],"sourcesContent":["import React from 'react';\nimport { useMergedRef } from '../../../hooks/useMergedRef';\nimport { isAriaDirectionKey } from '../../../utils/aria';\nimport { createCustomKeyboardEvent } from '../../../utils/input';\n\n/* This component provides a keyboard navigable collection primitive for use in lists\n * It is unlikely you need to edit this component\n */\n\nexport type CollectionProps = React.HTMLAttributes<HTMLDivElement> & {\n querySelector: string;\n};\n\nexport type CollectionRef = HTMLDivElement & {\n setActiveIndex: (option: HTMLDivElement) => void;\n};\n\nconst getOptionsFromCollection = (collection: HTMLDivElement, selector: string): NodeListOf<Element> =>\n collection.querySelectorAll(selector);\n\n// we use javascript to set attributes (rather than cloning children and adding them)\n// so that we can support nesting (e.g. groups) - child elements that aren't options.\n// without doing this we would have to unwrap and flatten all groups\nexport const Root = React.forwardRef<CollectionRef, CollectionProps>(function CollectionRoot(props, ref) {\n const { querySelector, tabIndex = 0, ...otherProps } = props;\n const internalRef = useMergedRef<CollectionRef>(ref);\n const [activeIndex, setActiveIndex] = React.useState<number | undefined>();\n const lastLengthRef = React.useRef(0);\n\n const setActiveOption = (index: number, collection: HTMLDivElement, option: Element) => {\n collection.querySelector(`[aria-current]`)?.removeAttribute('aria-current');\n option.setAttribute('aria-current', 'true');\n option.scrollIntoView({ block: 'nearest' });\n setActiveIndex(index);\n };\n\n const setActiveIndexByElement = React.useCallback(\n (option: HTMLDivElement) => {\n if (internalRef.current) {\n if (option.matches(querySelector)) {\n const options = getOptionsFromCollection(internalRef.current, querySelector);\n const nextActiveIndex = Array.from(options).indexOf(option);\n\n if (nextActiveIndex > -1) {\n setActiveOption(nextActiveIndex, internalRef.current, option);\n }\n }\n }\n },\n [internalRef.current, querySelector]\n );\n\n React.useEffect(() => {\n if (internalRef.current) {\n internalRef.current.setActiveIndex = setActiveIndexByElement;\n }\n }, [internalRef.current]);\n\n React.useEffect(() => {\n if (internalRef.current) {\n const options = getOptionsFromCollection(internalRef.current, querySelector);\n\n if (options.length && options.length !== lastLengthRef.current) {\n let selected = internalRef.current.querySelectorAll(`[aria-current=\"true\"]`);\n\n if (selected.length === 0) {\n selected = internalRef.current.querySelectorAll(`[aria-selected]`);\n }\n\n if (selected.length === 1) {\n if (options) {\n const firstSelected = selected.item(0);\n const selectedIndex = Array.from(options).indexOf(firstSelected);\n\n if (selectedIndex > -1) {\n setActiveOption(selectedIndex, internalRef.current, firstSelected);\n }\n }\n } else {\n // multiple selected or none selected should go to 0\n setActiveOption(0, internalRef.current, options.item(0));\n }\n }\n\n lastLengthRef.current = options.length;\n }\n }, [props.children]);\n\n const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const option = event.target as HTMLElement;\n\n if (option.matches(querySelector)) {\n const options = getOptionsFromCollection(event.currentTarget, querySelector);\n const nextActiveIndex = Array.from(options).indexOf(option);\n\n if (nextActiveIndex > -1) {\n setActiveOption(nextActiveIndex, event.currentTarget, option);\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n // this stops the event dispatched to the option rebounding back and starting an infinite loop\n if (event.target !== event.currentTarget) {\n return;\n }\n\n if (otherProps.onKeyDown) {\n otherProps.onKeyDown(event);\n }\n\n if (event.isDefaultPrevented()) {\n return;\n }\n\n const options = getOptionsFromCollection(event.currentTarget, querySelector);\n\n if (options) {\n if (isAriaDirectionKey(event)) {\n event.preventDefault();\n event.stopPropagation();\n const nextActiveIndex = getNextEnabledItem(event, options, activeIndex);\n\n if (nextActiveIndex !== undefined && nextActiveIndex !== activeIndex) {\n setActiveOption(nextActiveIndex, event.currentTarget, options.item(nextActiveIndex));\n }\n } else if (activeIndex !== undefined && !!options.item(activeIndex)) {\n // forward events onto the underlying option - this lets consumers place onKeyDown handlers on their own components\n options\n .item(activeIndex)\n ?.dispatchEvent(createCustomKeyboardEvent(event as React.KeyboardEvent<HTMLInputElement>));\n }\n }\n };\n\n return <div {...otherProps} onClick={handleClick} onKeyDown={handleKeyDown} ref={internalRef} tabIndex={tabIndex} />;\n});\n\nexport const getNextIndexFromKeycode = (\n event: React.KeyboardEvent,\n length: number,\n activeIndex: number | undefined\n): number | undefined => {\n switch (event.key) {\n case 'ArrowUp':\n return activeIndex === undefined ? length - 1 : activeIndex > 0 ? activeIndex - 1 : activeIndex;\n\n case 'ArrowDown':\n return activeIndex === undefined ? 0 : activeIndex < length - 1 ? activeIndex + 1 : activeIndex;\n\n case 'Home':\n return 0;\n\n case 'End':\n return length - 1;\n\n default:\n return;\n }\n};\n\nexport const getNextEnabledItem = (\n event: React.KeyboardEvent<HTMLElement>,\n options: NodeListOf<Element>,\n activeIndex: number | undefined,\n recurse = true\n): number | undefined => {\n const nextIndex = getNextIndexFromKeycode(event, options.length, activeIndex);\n\n if (nextIndex !== undefined) {\n if (nextIndex === activeIndex) {\n return activeIndex;\n } else if (options.item(nextIndex) && isSkippableItem(options.item(nextIndex))) {\n // check in the other direction if the first or last item is disabled,\n // but prevent infinite loops if all elements are disabled by disabling recursion\n if (recurse) {\n if (nextIndex === 0) {\n return getNextEnabledItem(\n new KeyboardEvent(event.type, { ...(event as any), key: 'ArrowDown' }) as any,\n options,\n nextIndex,\n false\n );\n } else if (nextIndex === options.length - 1) {\n return getNextEnabledItem(\n new KeyboardEvent(event.type, { ...(event as any), key: 'ArrowUp' }) as any,\n options,\n nextIndex,\n false\n );\n }\n }\n\n return getNextEnabledItem(event, options, nextIndex, recurse);\n }\n }\n\n return nextIndex;\n};\n\nconst isSkippableItem = (element: Element) => {\n return (\n element.getAttribute('role') === 'presentation' ||\n !!element.hasAttribute('disabled') ||\n !!element.getAttribute('aria-disabled') ||\n !!element.getAttribute('aria-hidden')\n );\n};\n"],"names":["getOptionsFromCollection","collection","selector","querySelectorAll","Root","React","forwardRef","CollectionRoot","props","ref","querySelector","tabIndex","otherProps","internalRef","useMergedRef","activeIndex","setActiveIndex","useState","lastLengthRef","useRef","setActiveOption","index","option","removeAttribute","setAttribute","scrollIntoView","block","setActiveIndexByElement","useCallback","current","matches","options","nextActiveIndex","Array","from","indexOf","useEffect","length","selected","firstSelected","item","selectedIndex","children","handleClick","event","target","currentTarget","handleKeyDown","onKeyDown","isDefaultPrevented","isAriaDirectionKey","preventDefault","stopPropagation","getNextEnabledItem","undefined","dispatchEvent","createCustomKeyboardEvent","onClick","getNextIndexFromKeycode","key","recurse","nextIndex","isSkippableItem","KeyboardEvent","type","element","getAttribute","hasAttribute"],"mappings":";;;;;AAiBA,MAAMA,wBAAwB,GAAG,CAACC,UAA0B,EAAEC,QAAgB,KAC1ED,UAAU,CAACE,gBAAgB,CAACD,QAAQ,CAAC;AAEzC;AACA;AACA;MACaE,IAAI,gBAAGC,cAAK,CAACC,UAAU,CAAiC,SAASC,cAAc,CAACC,KAAK,EAAEC,GAAG;EACnG,MAAM;IAAEC,aAAa;IAAEC,QAAQ,GAAG,CAAC;IAAE,GAAGC;GAAY,GAAGJ,KAAK;EAC5D,MAAMK,WAAW,GAAGC,YAAY,CAAgBL,GAAG,CAAC;EACpD,MAAM,CAACM,WAAW,EAAEC,cAAc,CAAC,GAAGX,cAAK,CAACY,QAAQ,EAAsB;EAC1E,MAAMC,aAAa,GAAGb,cAAK,CAACc,MAAM,CAAC,CAAC,CAAC;EAErC,MAAMC,eAAe,GAAG,CAACC,KAAa,EAAEpB,UAA0B,EAAEqB,MAAe;;IAC/E,yBAAArB,UAAU,CAACS,aAAa,iBAAiB,CAAC,0DAA1C,sBAA4Ca,eAAe,CAAC,cAAc,CAAC;IAC3ED,MAAM,CAACE,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC;IAC3CF,MAAM,CAACG,cAAc,CAAC;MAAEC,KAAK,EAAE;KAAW,CAAC;IAC3CV,cAAc,CAACK,KAAK,CAAC;GACxB;EAED,MAAMM,uBAAuB,GAAGtB,cAAK,CAACuB,WAAW,CAC5CN,MAAsB;IACnB,IAAIT,WAAW,CAACgB,OAAO,EAAE;MACrB,IAAIP,MAAM,CAACQ,OAAO,CAACpB,aAAa,CAAC,EAAE;QAC/B,MAAMqB,OAAO,GAAG/B,wBAAwB,CAACa,WAAW,CAACgB,OAAO,EAAEnB,aAAa,CAAC;QAC5E,MAAMsB,eAAe,GAAGC,KAAK,CAACC,IAAI,CAACH,OAA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AI8C,SAAS,KAAKP,SAAS,EAAE;IACzB,IAAIO,SAAS,KAAK9C,WAAW,EAAE;MAC3B,OAAOA,WAAW;KACrB,MAAM,IAAIgB,OAAO,CAACS,IAAI,CAACqB,SAAS,CAAC,IAAIC,eAAe,CAAC/B,OAAO,CAACS,IAAI,CAACqB,SAAS,CAAC,CAAC,EAAE;;;MAG5E,IAAID,OAAO,EAAE;QACT,IAAIC,SAAS,KAAK,CAAC,EAAE;UACjB,OAAOR,kBAAkB,CACrB,IAAIU,aAAa,CAACnB,KAAK,CAACoB,IAAI,EAAE;YAAE,GAAIpB,KAAa;YAAEe,GAAG,EAAE;WAAa,CAAQ,EAC7E5B,OAAO,EACP8B,SAAS,EACT,KAAK,CACR;SACJ,MAAM,IAAIA,SAAS,KAAK9B,OAAO,CAACM,MAAM,GAAG,CAAC,EAAE;UACzC,OAAOgB,kBAAkB,CACrB,IAAIU,aAAa,CAACnB,KAAK,CAACoB,IAAI,EAAE;YAAE,GAAIpB,KAAa;YAAEe,GAAG,EAAE;WAAW,CAAQ,EAC3E5B,OAAO,EACP8B,SAAS,EACT,KAAK,CACR;;;MAIT,OAAOR,kBAAkB,CAACT,KAAK,EAAEb,OAAO,EAAE8B,SAAS,EAAED,OAAO,CAAC;;;EAIrE,OAAOC,SAAS;AACpB;AAEA,MAAMC,eAAe,GAAIG,OAAgB;EACrC,OACIA,OAAO,CAACC,YAAY,CAAC,MAAM,CAAC,KAAK,cAAc,IAC/C,CAAC,CAACD,OAAO,CAACE,YAAY,CAAC,UAAU,CAAC,IAClC,CAAC,CAACF,OAAO,CAACC,YAAY,CAAC,eAAe,CAAC,IACvC,CAAC,CAACD,OAAO,CAACC,YAAY,CAAC,aAAa,CAAC;AAE7C,CAAC;;;;"}
|
@@ -8608,9 +8608,10 @@ const Root = /*#__PURE__*/React__default.forwardRef(function CollectionRoot(prop
|
|
8608
8608
|
if (nextActiveIndex !== undefined && nextActiveIndex !== activeIndex) {
|
8609
8609
|
setActiveOption(nextActiveIndex, event.currentTarget, options.item(nextActiveIndex));
|
8610
8610
|
}
|
8611
|
-
} else if (activeIndex !== undefined) {
|
8611
|
+
} else if (activeIndex !== undefined && !!options.item(activeIndex)) {
|
8612
|
+
var _options$item;
|
8612
8613
|
// forward events onto the underlying option - this lets consumers place onKeyDown handlers on their own components
|
8613
|
-
options.item(activeIndex).dispatchEvent(createCustomKeyboardEvent(event));
|
8614
|
+
(_options$item = options.item(activeIndex)) === null || _options$item === void 0 ? void 0 : _options$item.dispatchEvent(createCustomKeyboardEvent(event));
|
8614
8615
|
}
|
8615
8616
|
}
|
8616
8617
|
};
|
@@ -15659,7 +15660,7 @@ function AgreementSelector(props) {
|
|
15659
15660
|
return /*#__PURE__*/React__default.createElement("span", {
|
15660
15661
|
className: "flex flex-col gap-px [&>*:first-child>span]:!rounded-t [&>*:last-child>span]:!rounded-b [&>*>span]:!rounded-none",
|
15661
15662
|
key: `${agreement.number}_${agreement.userId}_clients`
|
15662
|
-
}, filterBySearchValue(search)(agreement) ? button : null, agreement.clients.filter(agreement => filterClientAgreement(agreement, filterBySearchValue(search))).map(clientAgreement => createAgreementButton(clientAgreement, fallbackImageSrc, handleChangeAgreement, isCurrentAgreement(clientAgreement, currentAgreement))));
|
15663
|
+
}, filterBySearchValue(search)(agreement) ? button : null, agreement.clients.filter(agreement => filterClientAgreement(agreement, search, filterBySearchValue(search))).map(clientAgreement => createAgreementButton(clientAgreement, fallbackImageSrc, handleChangeAgreement, isCurrentAgreement(clientAgreement, currentAgreement))));
|
15663
15664
|
}
|
15664
15665
|
return button;
|
15665
15666
|
})), handleAddAgreement ? /*#__PURE__*/React__default.createElement(Button$1, {
|