@travel-match/ui 0.4.0 → 0.5.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.
- package/dist/components/AccountMenu/AccountMenu.cjs +1 -1
- package/dist/components/AccountMenu/AccountMenu.cjs.map +1 -1
- package/dist/components/AccountMenu/AccountMenu.js +1 -1
- package/dist/components/AccountMenu/AccountMenu.js.map +1 -1
- package/dist/components/ConfirmationDialog/ConfirmationDialog.cjs +1 -1
- package/dist/components/ConfirmationDialog/ConfirmationDialog.cjs.map +1 -1
- package/dist/components/ConfirmationDialog/ConfirmationDialog.js +1 -0
- package/dist/components/ConfirmationDialog/ConfirmationDialog.js.map +1 -1
- package/dist/components/CtaRequestFlow/CtaRequestFlow.cjs +1 -1
- package/dist/components/CtaRequestFlow/CtaRequestFlow.cjs.map +1 -1
- package/dist/components/CtaRequestFlow/CtaRequestFlow.js +72 -37
- package/dist/components/CtaRequestFlow/CtaRequestFlow.js.map +1 -1
- package/dist/components/ExampleRequests/ExampleRequests.cjs +1 -1
- package/dist/components/ExampleRequests/ExampleRequests.cjs.map +1 -1
- package/dist/components/ExampleRequests/ExampleRequests.js +18 -17
- package/dist/components/ExampleRequests/ExampleRequests.js.map +1 -1
- package/dist/components/FaqItem/FaqItem.cjs +1 -1
- package/dist/components/FaqItem/FaqItem.cjs.map +1 -1
- package/dist/components/FaqItem/FaqItem.js +79 -34
- package/dist/components/FaqItem/FaqItem.js.map +1 -1
- package/dist/components/Field/Field.cjs +1 -1
- package/dist/components/Field/Field.cjs.map +1 -1
- package/dist/components/Field/Field.js +10 -8
- package/dist/components/Field/Field.js.map +1 -1
- package/dist/components/InlineAlert/InlineAlert.cjs +1 -1
- package/dist/components/InlineAlert/InlineAlert.cjs.map +1 -1
- package/dist/components/InlineAlert/InlineAlert.js +9 -8
- package/dist/components/InlineAlert/InlineAlert.js.map +1 -1
- package/dist/components/NewRequestOverlay/NewRequestOverlay.cjs +1 -1
- package/dist/components/NewRequestOverlay/NewRequestOverlay.cjs.map +1 -1
- package/dist/components/NewRequestOverlay/NewRequestOverlay.js +67 -48
- package/dist/components/NewRequestOverlay/NewRequestOverlay.js.map +1 -1
- package/dist/components/NotificationsDropdown/NotificationsMenu.cjs +1 -1
- package/dist/components/NotificationsDropdown/NotificationsMenu.cjs.map +1 -1
- package/dist/components/NotificationsDropdown/NotificationsMenu.js +1 -1
- package/dist/components/NotificationsDropdown/NotificationsMenu.js.map +1 -1
- package/dist/components/PartnerCarousel/PartnerCarousel.cjs.map +1 -1
- package/dist/components/PartnerCarousel/PartnerCarousel.js.map +1 -1
- package/dist/components/PhoneInput/PhoneInput.cjs +1 -1
- package/dist/components/PhoneInput/PhoneInput.cjs.map +1 -1
- package/dist/components/PhoneInput/PhoneInput.js +8 -5
- package/dist/components/PhoneInput/PhoneInput.js.map +1 -1
- package/dist/components/PopularQuestions/PopularQuestions.cjs +1 -1
- package/dist/components/PopularQuestions/PopularQuestions.cjs.map +1 -1
- package/dist/components/PopularQuestions/PopularQuestions.js +22 -21
- package/dist/components/PopularQuestions/PopularQuestions.js.map +1 -1
- package/dist/components/RegionMap/RegionMap.cjs +2 -0
- package/dist/components/RegionMap/RegionMap.cjs.map +1 -0
- package/dist/components/RegionMap/RegionMap.js +55 -0
- package/dist/components/RegionMap/RegionMap.js.map +1 -0
- package/dist/components/RegionMap/mapPaths.cjs +2 -0
- package/dist/components/RegionMap/mapPaths.cjs.map +1 -0
- package/dist/components/RegionMap/mapPaths.js +86 -0
- package/dist/components/RegionMap/mapPaths.js.map +1 -0
- package/dist/components/RequestSearch/RequestSearch.cjs +2 -0
- package/dist/components/RequestSearch/RequestSearch.cjs.map +1 -0
- package/dist/components/RequestSearch/RequestSearch.js +36 -0
- package/dist/components/RequestSearch/RequestSearch.js.map +1 -0
- package/dist/components/RequestSummary/RequestSummary.cjs +1 -1
- package/dist/components/RequestSummary/RequestSummary.cjs.map +1 -1
- package/dist/components/RequestSummary/RequestSummary.js +31 -32
- package/dist/components/RequestSummary/RequestSummary.js.map +1 -1
- package/dist/components/RequestTypeOption/RequestTypeOption.cjs +2 -0
- package/dist/components/RequestTypeOption/RequestTypeOption.cjs.map +1 -0
- package/dist/components/RequestTypeOption/RequestTypeOption.js +52 -0
- package/dist/components/RequestTypeOption/RequestTypeOption.js.map +1 -0
- package/dist/components/Select/Select.cjs +1 -1
- package/dist/components/Select/Select.cjs.map +1 -1
- package/dist/components/Select/Select.js +127 -121
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/ShowMore/ShowMore.cjs +2 -0
- package/dist/components/ShowMore/ShowMore.cjs.map +1 -0
- package/dist/components/ShowMore/ShowMore.js +34 -0
- package/dist/components/ShowMore/ShowMore.js.map +1 -0
- package/dist/components/SiteHeader/SiteHeader.cjs.map +1 -1
- package/dist/components/SiteHeader/SiteHeader.js.map +1 -1
- package/dist/components/SortSelect/SortSelect.cjs +2 -0
- package/dist/components/SortSelect/SortSelect.cjs.map +1 -0
- package/dist/components/SortSelect/SortSelect.js +18 -0
- package/dist/components/SortSelect/SortSelect.js.map +1 -0
- package/dist/components/StatusFilter/StatusFilter.cjs +2 -0
- package/dist/components/StatusFilter/StatusFilter.cjs.map +1 -0
- package/dist/components/StatusFilter/StatusFilter.js +37 -0
- package/dist/components/StatusFilter/StatusFilter.js.map +1 -0
- package/dist/components/StatusTag/StatusTag.cjs.map +1 -1
- package/dist/components/StatusTag/StatusTag.js.map +1 -1
- package/dist/components/StepCard/StepCard.cjs +1 -1
- package/dist/components/StepCard/StepCard.cjs.map +1 -1
- package/dist/components/StepCard/StepCard.js +9 -6
- package/dist/components/StepCard/StepCard.js.map +1 -1
- package/dist/components/StepProgress/StepProgress.cjs +2 -0
- package/dist/components/StepProgress/StepProgress.cjs.map +1 -0
- package/dist/components/StepProgress/StepProgress.js +43 -0
- package/dist/components/StepProgress/StepProgress.js.map +1 -0
- package/dist/components/TelegramConnect/TelegramConnect.cjs +2 -0
- package/dist/components/TelegramConnect/TelegramConnect.cjs.map +1 -0
- package/dist/components/TelegramConnect/TelegramConnect.js +57 -0
- package/dist/components/TelegramConnect/TelegramConnect.js.map +1 -0
- package/dist/components/TextInput/TextInput.cjs +1 -1
- package/dist/components/TextInput/TextInput.cjs.map +1 -1
- package/dist/components/TextInput/TextInput.js +21 -19
- package/dist/components/TextInput/TextInput.js.map +1 -1
- package/dist/components/Textarea/Textarea.cjs +1 -1
- package/dist/components/Textarea/Textarea.cjs.map +1 -1
- package/dist/components/Textarea/Textarea.js +18 -16
- package/dist/components/Textarea/Textarea.js.map +1 -1
- package/dist/components/Toast/Toast.cjs +2 -0
- package/dist/components/Toast/Toast.cjs.map +1 -0
- package/dist/components/Toast/Toast.js +57 -0
- package/dist/components/Toast/Toast.js.map +1 -0
- package/dist/icons/generated/CheckmarkIcon.cjs +1 -1
- package/dist/icons/generated/CheckmarkIcon.cjs.map +1 -1
- package/dist/icons/generated/CheckmarkIcon.js +19 -2
- package/dist/icons/generated/CheckmarkIcon.js.map +1 -1
- package/dist/icons/generated/InfoIcon.cjs +2 -0
- package/dist/icons/generated/InfoIcon.cjs.map +1 -0
- package/dist/icons/generated/InfoIcon.js +35 -0
- package/dist/icons/generated/InfoIcon.js.map +1 -0
- package/dist/icons/generated/SendIcon.cjs +2 -0
- package/dist/icons/generated/SendIcon.cjs.map +1 -0
- package/dist/icons/generated/SendIcon.js +23 -0
- package/dist/icons/generated/SendIcon.js.map +1 -0
- package/dist/icons/generated/index.cjs +1 -1
- package/dist/icons/generated/index.cjs.map +1 -1
- package/dist/icons/generated/index.js +71 -67
- package/dist/icons/generated/index.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +618 -32
- package/dist/index.d.ts +618 -32
- package/dist/index.js +146 -135
- package/dist/styles.css +1 -1
- package/dist/tailwind.css +0 -6
- package/dist/tokens/generated.cjs +1 -1
- package/dist/tokens/generated.cjs.map +1 -1
- package/dist/tokens/generated.js +1 -7
- package/dist/tokens/generated.js.map +1 -1
- package/dist/tokens.css +0 -12
- package/dist/tokens.d.cts +2 -26
- package/dist/tokens.d.ts +2 -26
- package/dist/tokens.json +1 -7
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationsMenu.cjs","names":["useState","Popover","NotificationsButton","NotificationsDropdown","cn","require_runtime","require_cn","require_NotificationsButton","require_NotificationsDropdown","react","react_jsx_runtime","_radix_ui_react_popover","NotificationsMenu","buttonProps","uncontrolledOpen","setUncontrolledOpen","defaultOpen","isOpen","open","setOpen","next","onOpenChange","closeOnLink","event","portalContainer","panelClassName"],"sources":["../../../src/components/NotificationsDropdown/NotificationsMenu.tsx"],"sourcesContent":["import * as Popover from '@radix-ui/react-popover';\nimport { forwardRef, useState, type MouseEvent } from 'react';\nimport { cn } from '../../utils/cn';\nimport { NotificationsButton, type NotificationsButtonProps } from '../NotificationsButton';\nimport { NotificationsDropdown, type NotificationsDropdownProps } from './NotificationsDropdown';\n\ntype PanelProps = Pick<\n NotificationsDropdownProps,\n 'title' | 'headingLevel' | 'headerAction' | 'children' | 'footer' | 'emptyTitle' | 'emptyMessage' | 'empty' | 'error' | 'retryLabel' | 'onRetry'\n>;\n\nexport interface NotificationsMenuProps extends Omit<NotificationsButtonProps, 'title'>, PanelProps {\n /** Whether the panel is open (controlled). */\n open?: boolean;\n /** Opens the panel initially (uncontrolled). */\n defaultOpen?: boolean;\n /** Called when the panel opens or closes. */\n onOpenChange?: (open: boolean) => void;\n
|
|
1
|
+
{"version":3,"file":"NotificationsMenu.cjs","names":["useState","Popover","NotificationsButton","NotificationsDropdown","cn","require_runtime","require_cn","require_NotificationsButton","require_NotificationsDropdown","react","react_jsx_runtime","_radix_ui_react_popover","NotificationsMenu","buttonProps","uncontrolledOpen","setUncontrolledOpen","defaultOpen","isOpen","open","setOpen","next","onOpenChange","closeOnLink","event","portalContainer","panelClassName"],"sources":["../../../src/components/NotificationsDropdown/NotificationsMenu.tsx"],"sourcesContent":["import * as Popover from '@radix-ui/react-popover';\nimport { forwardRef, useState, type MouseEvent } from 'react';\nimport { cn } from '../../utils/cn';\nimport { NotificationsButton, type NotificationsButtonProps } from '../NotificationsButton';\nimport { NotificationsDropdown, type NotificationsDropdownProps } from './NotificationsDropdown';\n\ntype PanelProps = Pick<\n NotificationsDropdownProps,\n 'title' | 'headingLevel' | 'headerAction' | 'children' | 'footer' | 'emptyTitle' | 'emptyMessage' | 'empty' | 'error' | 'retryLabel' | 'onRetry'\n>;\n\nexport interface NotificationsMenuProps extends Omit<NotificationsButtonProps, 'title'>, PanelProps {\n /** Whether the panel is open (controlled). */\n open?: boolean;\n /** Opens the panel initially (uncontrolled). */\n defaultOpen?: boolean;\n /** Called when the panel opens or closes. */\n onOpenChange?: (open: boolean) => void;\n /**\n * How the panel lines up with the button. Figma centres it under the button (`center`, the default); near the edge of\n * the screen it shifts to stay 8px inside the viewport.\n */\n align?: 'start' | 'center' | 'end';\n /** Element the panel is rendered into (default `document.body`). Set it when the theme is scoped to a container. */\n portalContainer?: HTMLElement | null;\n /** Class for the panel, which is rendered in a portal outside the button. */\n panelClassName?: string;\n}\n\n/**\n * The bell button with its dropdown (Figma \"Notifications / State=Open\"): `NotificationsButton` opening a\n * `NotificationsDropdown` in a popover. Escape and a click outside close it, and so does following a link inside it.\n * The ref and the remaining props go to the button.\n */\nexport const NotificationsMenu = /* @__PURE__ */ forwardRef<HTMLButtonElement, NotificationsMenuProps>(function NotificationsMenu(\n {\n title,\n headingLevel,\n headerAction,\n children,\n footer,\n emptyTitle,\n emptyMessage,\n empty,\n error,\n retryLabel,\n onRetry,\n open,\n defaultOpen = false,\n onOpenChange,\n align = 'center',\n portalContainer,\n panelClassName,\n ...buttonProps\n },\n ref,\n) {\n const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);\n const isOpen = open ?? uncontrolledOpen;\n const setOpen = (next: boolean) => {\n if (open === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n };\n\n // A notification that is a link takes the user to another page: the panel should not stay open over it.\n const closeOnLink = (event: MouseEvent<HTMLElement>) => {\n if (!event.defaultPrevented && (event.target as Element).closest('a[href]')) setOpen(false);\n };\n\n return (\n <Popover.Root open={isOpen} onOpenChange={setOpen}>\n <Popover.Trigger asChild>\n <NotificationsButton ref={ref} {...buttonProps} />\n </Popover.Trigger>\n <Popover.Portal container={portalContainer}>\n <Popover.Content asChild align={align} sideOffset={8} collisionPadding={8}>\n <NotificationsDropdown\n className={cn('tm-notifications-menu__panel', panelClassName)}\n title={title}\n headingLevel={headingLevel}\n headerAction={headerAction}\n footer={footer}\n emptyTitle={emptyTitle}\n emptyMessage={emptyMessage}\n empty={empty}\n error={error}\n retryLabel={retryLabel}\n onRetry={onRetry}\n onClick={closeOnLink}\n >\n {children}\n </NotificationsDropdown>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n );\n});\n"],"mappings":"A,sTAkCA,IAAaY,GAAoC,EAAAH,EAAA,WAAA,CAAsD,SACrG,CACE,QACA,eACA,eACA,WACA,SACA,aACA,eACA,QACA,QACA,aACA,UACA,OACA,cAAc,GACd,eACA,QAAQ,SACR,kBACA,iBACA,GAAGI,GAEL,EACA,CACA,GAAM,CAACC,EAAkBC,IAAA,EAAuBf,EAAAA,SAAAA,CAASgB,CAAW,EAC9DC,EAASC,GAAQJ,EACjBK,EAAW,GAAkB,CAC7BD,IAAS,IAAA,IAAWH,EAAoBK,CAAI,EAChDC,IAAeD,CAAI,CACrB,EAGME,EAAe,GAAmC,CAClD,CAACC,EAAM,kBAAqBA,EAAM,OAAmB,QAAQ,SAAS,GAAGJ,EAAQ,EAAK,CAC5F,EAEA,OACE,EAAAT,EAAA,KAAA,CAACT,EAAQ,KAAT,CAAc,KAAMgB,EAAQ,aAAcE,EAA1C,SAAA,EACE,EAAAT,EAAA,IAAA,CAACT,EAAQ,QAAT,CAAiB,QAAA,GACf,UAAA,EAAAS,EAAA,IAAA,CAACR,EAAAA,oBAAD,CAA0B,MAAK,GAAIW,CAAc,CAAA,CAClC,CAAA,GACjB,EAAAH,EAAA,IAAA,CAACT,EAAQ,OAAT,CAAgB,UAAWuB,EACzB,UAAA,EAAAd,EAAA,IAAA,CAACT,EAAQ,QAAT,CAAiB,QAAA,GAAe,QAAO,WAAY,EAAG,iBAAkB,EACtE,UAAA,EAAAS,EAAA,IAAA,CAACP,EAAAA,sBAAD,CACE,UAAWC,EAAAA,GAAG,+BAAgCqB,CAAc,EACrD,QACO,eACA,eACN,SACI,aACE,eACP,QACA,QACK,aACH,UACT,QAASH,EAER,UACoB,CAAA,CACR,CAAA,CACH,CAAA,CACJ,C,EAElB,CAAC,E"}
|
|
@@ -6,7 +6,7 @@ import { forwardRef as r, useState as i } from "react";
|
|
|
6
6
|
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
7
|
import * as s from "@radix-ui/react-popover";
|
|
8
8
|
// src/components/NotificationsDropdown/NotificationsMenu.tsx
|
|
9
|
-
var c = /* @__PURE__ */ r(function({ title: r, headingLevel: c, headerAction: l, children: u, footer: d, emptyTitle: f, emptyMessage: p, empty: m, error: h, retryLabel: g, onRetry: _, open: v, defaultOpen: y = !1, onOpenChange: b, align: x = "
|
|
9
|
+
var c = /* @__PURE__ */ r(function({ title: r, headingLevel: c, headerAction: l, children: u, footer: d, emptyTitle: f, emptyMessage: p, empty: m, error: h, retryLabel: g, onRetry: _, open: v, defaultOpen: y = !1, onOpenChange: b, align: x = "center", portalContainer: S, panelClassName: C, ...w }, T) {
|
|
10
10
|
let [E, D] = i(y), O = v ?? E, k = (e) => {
|
|
11
11
|
v === void 0 && D(e), b?.(e);
|
|
12
12
|
}, A = (e) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationsMenu.js","names":["Popover","NotificationsMenu","buttonProps","uncontrolledOpen","setUncontrolledOpen","useState","defaultOpen","isOpen","open","setOpen","next","onOpenChange","closeOnLink","event","NotificationsButton","portalContainer","NotificationsDropdown","cn","panelClassName"],"sources":["../../../src/components/NotificationsDropdown/NotificationsMenu.tsx"],"sourcesContent":["import * as Popover from '@radix-ui/react-popover';\nimport { forwardRef, useState, type MouseEvent } from 'react';\nimport { cn } from '../../utils/cn';\nimport { NotificationsButton, type NotificationsButtonProps } from '../NotificationsButton';\nimport { NotificationsDropdown, type NotificationsDropdownProps } from './NotificationsDropdown';\n\ntype PanelProps = Pick<\n NotificationsDropdownProps,\n 'title' | 'headingLevel' | 'headerAction' | 'children' | 'footer' | 'emptyTitle' | 'emptyMessage' | 'empty' | 'error' | 'retryLabel' | 'onRetry'\n>;\n\nexport interface NotificationsMenuProps extends Omit<NotificationsButtonProps, 'title'>, PanelProps {\n /** Whether the panel is open (controlled). */\n open?: boolean;\n /** Opens the panel initially (uncontrolled). */\n defaultOpen?: boolean;\n /** Called when the panel opens or closes. */\n onOpenChange?: (open: boolean) => void;\n
|
|
1
|
+
{"version":3,"file":"NotificationsMenu.js","names":["Popover","NotificationsMenu","buttonProps","uncontrolledOpen","setUncontrolledOpen","useState","defaultOpen","isOpen","open","setOpen","next","onOpenChange","closeOnLink","event","NotificationsButton","portalContainer","NotificationsDropdown","cn","panelClassName"],"sources":["../../../src/components/NotificationsDropdown/NotificationsMenu.tsx"],"sourcesContent":["import * as Popover from '@radix-ui/react-popover';\nimport { forwardRef, useState, type MouseEvent } from 'react';\nimport { cn } from '../../utils/cn';\nimport { NotificationsButton, type NotificationsButtonProps } from '../NotificationsButton';\nimport { NotificationsDropdown, type NotificationsDropdownProps } from './NotificationsDropdown';\n\ntype PanelProps = Pick<\n NotificationsDropdownProps,\n 'title' | 'headingLevel' | 'headerAction' | 'children' | 'footer' | 'emptyTitle' | 'emptyMessage' | 'empty' | 'error' | 'retryLabel' | 'onRetry'\n>;\n\nexport interface NotificationsMenuProps extends Omit<NotificationsButtonProps, 'title'>, PanelProps {\n /** Whether the panel is open (controlled). */\n open?: boolean;\n /** Opens the panel initially (uncontrolled). */\n defaultOpen?: boolean;\n /** Called when the panel opens or closes. */\n onOpenChange?: (open: boolean) => void;\n /**\n * How the panel lines up with the button. Figma centres it under the button (`center`, the default); near the edge of\n * the screen it shifts to stay 8px inside the viewport.\n */\n align?: 'start' | 'center' | 'end';\n /** Element the panel is rendered into (default `document.body`). Set it when the theme is scoped to a container. */\n portalContainer?: HTMLElement | null;\n /** Class for the panel, which is rendered in a portal outside the button. */\n panelClassName?: string;\n}\n\n/**\n * The bell button with its dropdown (Figma \"Notifications / State=Open\"): `NotificationsButton` opening a\n * `NotificationsDropdown` in a popover. Escape and a click outside close it, and so does following a link inside it.\n * The ref and the remaining props go to the button.\n */\nexport const NotificationsMenu = /* @__PURE__ */ forwardRef<HTMLButtonElement, NotificationsMenuProps>(function NotificationsMenu(\n {\n title,\n headingLevel,\n headerAction,\n children,\n footer,\n emptyTitle,\n emptyMessage,\n empty,\n error,\n retryLabel,\n onRetry,\n open,\n defaultOpen = false,\n onOpenChange,\n align = 'center',\n portalContainer,\n panelClassName,\n ...buttonProps\n },\n ref,\n) {\n const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);\n const isOpen = open ?? uncontrolledOpen;\n const setOpen = (next: boolean) => {\n if (open === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n };\n\n // A notification that is a link takes the user to another page: the panel should not stay open over it.\n const closeOnLink = (event: MouseEvent<HTMLElement>) => {\n if (!event.defaultPrevented && (event.target as Element).closest('a[href]')) setOpen(false);\n };\n\n return (\n <Popover.Root open={isOpen} onOpenChange={setOpen}>\n <Popover.Trigger asChild>\n <NotificationsButton ref={ref} {...buttonProps} />\n </Popover.Trigger>\n <Popover.Portal container={portalContainer}>\n <Popover.Content asChild align={align} sideOffset={8} collisionPadding={8}>\n <NotificationsDropdown\n className={cn('tm-notifications-menu__panel', panelClassName)}\n title={title}\n headingLevel={headingLevel}\n headerAction={headerAction}\n footer={footer}\n emptyTitle={emptyTitle}\n emptyMessage={emptyMessage}\n empty={empty}\n error={error}\n retryLabel={retryLabel}\n onRetry={onRetry}\n onClick={closeOnLink}\n >\n {children}\n </NotificationsDropdown>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n );\n});\n"],"mappings":";;;;;;;;AAkCA,IAAaC,IAAoC,kBAAsD,SACrG,EACE,UACA,iBACA,iBACA,aACA,WACA,eACA,iBACA,UACA,UACA,eACA,YACA,SACA,iBAAc,IACd,iBACA,WAAQ,UACR,oBACA,mBACA,GAAGC,KAEL,GACA;CACA,IAAM,CAACC,GAAkBC,KAAuBC,EAASC,CAAW,GAC9DC,IAASC,KAAQL,GACjBM,KAAW,MAAkB;EAEjC,AADID,MAAS,KAAA,KAAWJ,EAAoBM,CAAI,GAChDC,IAAeD,CAAI;CACrB,GAGME,KAAe,MAAmC;EACtD,AAAI,CAACC,EAAM,oBAAqBA,EAAM,OAAmB,QAAQ,SAAS,KAAGJ,EAAQ,EAAK;CAC5F;CAEA,OACE,kBAACT,EAAQ,MAAT;EAAc,MAAMO;EAAQ,cAAcE;EAA1C,UAAA,CACE,kBAACT,EAAQ,SAAT;GAAiB,SAAA;GACf,UAAA,kBAACc,GAAD;IAA0B;IAAK,GAAIZ;GAAc,CAAA;EAClC,CAAA,GACjB,kBAACF,EAAQ,QAAT;GAAgB,WAAWe;GACzB,UAAA,kBAACf,EAAQ,SAAT;IAAiB,SAAA;IAAe;IAAO,YAAY;IAAG,kBAAkB;IACtE,UAAA,kBAACgB,GAAD;KACE,WAAWC,EAAG,gCAAgCC,CAAc;KACrD;KACO;KACA;KACN;KACI;KACE;KACP;KACA;KACK;KACH;KACT,SAASN;KAER;IACoB,CAAA;GACR,CAAA;EACH,CAAA,CACJ;;AAElB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PartnerCarousel.cjs","names":["useEffect","useLayoutEffect","Children","useRef","useIndexState","useState","useCallback","useAutoplay","cn","Pagination","require_cn","require_Pagination","require_autoplay","react","react_jsx_runtime","SLIDE_DURATION","easeInOut","t","useIsomorphicLayoutEffect","defaultSlideLabel","index","count","defaultPageLabel","page","pageCount","setInert","element","PartnerCarousel","props","slides","children","looping","loop","rootRef","viewportRef","setIndex","value","defaultValue","onValueChange","stops","setStops","shown","frame","animating","settleTimer","getStep","items","stopAnimation","settle","viewport","step","position","next","scrollToPosition","from","to","reduced","animate","start","run","now","goTo","options","current","measure","observer","autoPlay","interval","handleScroll","interactionProps","node","ref","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","getSlideLabel","i","slide","controls","paginationLabel"],"sources":["../../../src/components/PartnerCarousel/PartnerCarousel.tsx"],"sourcesContent":["import { Children, forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { useAutoplay, useIndexState } from './autoplay';\nimport './PartnerCarousel.css';\n\n/** Figma prototype: Smart animate, ease in and out, 700ms. */\nconst SLIDE_DURATION = 700;\n/** CSS `ease-in-out` of the prototype, closely approximated (quadratic) for the scripted scroll. */\nconst easeInOut = (t: number) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nexport interface PartnerCarouselProps extends Omit<HTMLAttributes<HTMLElement>, 'onChange' | 'defaultValue'> {\n /** The slides: one element per slide, normally `PartnerCard`s. Any number. */\n children?: ReactNode;\n /** Name of the carousel region, e.g. \"Partner agencies\" — translate it. */\n 'aria-label'?: string;\n /** Index (0-based) of the first slide in view — Figma \"Slide\". Makes the carousel controlled. */\n value?: number;\n /** Slide shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the carousel moves (swipe, dots or autoplay). */\n onValueChange?: (value: number) => void;\n /** Moves one slide at a time by itself, in an endless loop. Holds for hover, keyboard focus, a hidden tab, an off-screen carousel and reduced motion. */\n autoPlay?: boolean;\n /** Time a slide rests before the next move, in ms (Figma: 3000). */\n interval?: number;\n /** Holds the autoplay from outside; it carries on once this is `false` again. */\n paused?: boolean;\n /** After the last slide the first one follows seamlessly, as in the Figma prototype. Needs more than two slides. */\n loop?: boolean;\n /** Shows the dots. */\n controls?: boolean;\n /** Accessible name of a slide — translate it. */\n getSlideLabel?: (index: number, count: number) => string;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n}\n\nconst defaultSlideLabel = (index: number, count: number) => `${index + 1} of ${count}`;\nconst defaultPageLabel = (page: number, pageCount: number) => `Slide ${page} of ${pageCount}`;\nconst setInert = (element: HTMLElement | null) => element?.setAttribute('inert', '');\n\n/**\n * Carousel of partner cards (Figma component set \"Home / Partner carousel\"): a native scroll-snap track — so touch\n * swipe, trackpad and keyboard scrolling work by themselves — with dots, autoplay and a seamless loop.\n * Two slides per view; containers narrower than 768px show one 300px slide with the next one peeking, like\n * \"Mobile / Home / Partner carousel\".\n */\nexport const PartnerCarousel = /* @__PURE__ */ forwardRef<HTMLElement, PartnerCarouselProps>(function PartnerCarousel(\n {\n children,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 3000,\n paused = false,\n loop = true,\n controls = true,\n getSlideLabel = defaultSlideLabel,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Slides',\n className,\n ...props\n },\n ref,\n) {\n const slides = Children.toArray(children);\n const count = slides.length;\n const looping = loop && count > 2;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n // Without the loop the last slides share one view, so there are fewer stops than slides (measured below).\n const [stops, setStops] = useState(count);\n const pageCount = looping ? count : Math.max(1, Math.min(stops, count));\n\n /** The index the track currently shows or is animating to. */\n const shown = useRef(index);\n const frame = useRef(0);\n const animating = useRef(false);\n const settleTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n /** Distance between two neighbouring slides; 0 when there is no layout (tests, hidden). */\n const getStep = useCallback(() => {\n const items = viewportRef.current?.querySelectorAll<HTMLElement>('.tm-partner-carousel__slide');\n if (!items || items.length < 2) return 0;\n return (items[1] as HTMLElement).offsetLeft - (items[0] as HTMLElement).offsetLeft;\n }, []);\n\n const stopAnimation = useCallback(() => {\n if (!animating.current) return;\n cancelAnimationFrame(frame.current);\n animating.current = false;\n if (viewportRef.current) viewportRef.current.style.scrollSnapType = '';\n }, []);\n\n /** After a move: leave the cloned slides for their originals and report where the track rests. */\n const settle = useCallback(() => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0 || animating.current) return;\n let position = Math.round(viewport.scrollLeft / step);\n if (looping && position >= count) {\n position -= count;\n viewport.scrollLeft = position * step;\n }\n const next = Math.max(0, Math.min(position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n }, [count, getStep, looping, pageCount, setIndex]);\n\n /** Scrolls to a track position (slide number, clones included) with the Figma timing. */\n const scrollToPosition = useCallback(\n (position: number, animate: boolean) => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n stopAnimation();\n const from = viewport.scrollLeft;\n const to = Math.min(position * step, viewport.scrollWidth - viewport.clientWidth);\n const reduced = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n if (!animate || reduced || Math.abs(to - from) < 1) {\n viewport.scrollLeft = to;\n settle();\n return;\n }\n // Scroll snapping would fight a scripted scroll, so it is switched off for its duration.\n animating.current = true;\n viewport.style.scrollSnapType = 'none';\n const start = performance.now();\n const run = (now: number) => {\n const t = Math.min(1, (now - start) / SLIDE_DURATION);\n viewport.scrollLeft = from + (to - from) * easeInOut(t);\n if (t < 1) {\n frame.current = requestAnimationFrame(run);\n return;\n }\n animating.current = false;\n viewport.style.scrollSnapType = '';\n settle();\n };\n frame.current = requestAnimationFrame(run);\n },\n [getStep, settle, stopAnimation],\n );\n\n /** Shows a slide. `forward` keeps moving right through the clones, so the loop never rewinds. */\n const goTo = useCallback(\n (next: number, options: { forward?: boolean; animate?: boolean; silent?: boolean } = {}) => {\n const viewport = viewportRef.current;\n const step = getStep();\n let position = next;\n if (options.forward && looping && viewport && step > 0) {\n let current = Math.round(viewport.scrollLeft / step);\n if (current >= count) {\n current -= count;\n viewport.scrollLeft = current * step;\n }\n position = current + 1;\n }\n shown.current = next;\n if (!options.silent) setIndex(next);\n scrollToPosition(position, options.animate ?? true);\n },\n [count, getStep, looping, scrollToPosition, setIndex],\n );\n\n // Start at the requested slide without animating.\n useIsomorphicLayoutEffect(() => {\n if (shown.current > 0) scrollToPosition(shown.current, false);\n return () => {\n cancelAnimationFrame(frame.current);\n clearTimeout(settleTimer.current);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // A controlled `value` (or a shrinking list) that differs from what the track shows moves the track.\n useEffect(() => {\n if (index !== shown.current) goTo(index, { silent: true });\n }, [index, goTo]);\n\n // Count the stops of a carousel that does not loop.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n const measure = () => {\n const step = getStep();\n if (step <= 0) return setStops(count);\n setStops(Math.ceil((viewport.scrollWidth - viewport.clientWidth) / step - 0.05) + 1);\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(viewport);\n return () => observer.disconnect();\n }, [count, getStep, looping]);\n\n const { running, interactionProps } = useAutoplay({\n enabled: autoPlay && pageCount > 1,\n paused,\n delay: interval + SLIDE_DURATION,\n onTick: () => goTo((shown.current + 1) % pageCount, { forward: true }),\n rootRef,\n resetKey: index,\n });\n\n const handleScroll = () => {\n if (animating.current) return;\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n // The dots follow a swipe while it happens…\n const position = Math.round(viewport.scrollLeft / step);\n const next = Math.max(0, Math.min(looping ? position % count : position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n // …and once it rests the track leaves the clones (`scrollend` is not available everywhere).\n clearTimeout(settleTimer.current);\n settleTimer.current = setTimeout(settle, 140);\n };\n\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <section\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-partner-carousel', className)}\n aria-roledescription=\"carousel\"\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus(event);\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div\n ref={viewportRef}\n className=\"tm-partner-carousel__viewport\"\n onScroll={handleScroll}\n // The user takes over: a scripted move must not fight a swipe, the wheel or the keyboard.\n onPointerDown={stopAnimation}\n onTouchStart={stopAnimation}\n onWheel={stopAnimation}\n onKeyDown={(event) => {\n if (event.key.startsWith('Arrow') || event.key === 'Home' || event.key === 'End') stopAnimation();\n }}\n >\n <div className=\"tm-partner-carousel__track\">\n {slides.map((slide, i) => (\n <div key={i} className=\"tm-partner-carousel__slide\" role=\"group\" aria-roledescription=\"slide\" aria-label={getSlideLabel(i, count)}>\n {slide}\n </div>\n ))}\n {/* Copies of the slides that close the loop; assistive technology and the keyboard skip them. */}\n {looping\n ? slides.map((slide, i) => (\n <div key={`clone-${i}`} ref={setInert} className=\"tm-partner-carousel__slide\" data-clone=\"\" aria-hidden=\"true\">\n {slide}\n </div>\n ))\n : null}\n </div>\n </div>\n\n {controls && pageCount > 1 ? (\n <div className=\"tm-partner-carousel__controls\">\n <Pagination page={index + 1} pageCount={pageCount} onPageChange={(page) => goTo(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n </div>\n ) : null}\n </section>\n );\n});\n"],"mappings":"A,oNAOA,IAAMe,EAAiB,IAEjBC,EAAa,GAAeC,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AEb,CAAC,E"}
|
|
1
|
+
{"version":3,"file":"PartnerCarousel.cjs","names":["useEffect","useLayoutEffect","Children","useRef","useIndexState","useState","useCallback","useAutoplay","cn","Pagination","require_cn","require_Pagination","require_autoplay","react","react_jsx_runtime","SLIDE_DURATION","easeInOut","t","useIsomorphicLayoutEffect","defaultSlideLabel","index","count","defaultPageLabel","page","pageCount","setInert","element","PartnerCarousel","props","slides","children","looping","loop","rootRef","viewportRef","setIndex","value","defaultValue","onValueChange","stops","setStops","shown","frame","animating","settleTimer","getStep","items","stopAnimation","settle","viewport","step","position","next","scrollToPosition","from","to","reduced","animate","start","run","now","goTo","options","current","measure","observer","autoPlay","interval","handleScroll","interactionProps","node","ref","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","getSlideLabel","i","slide","controls","paginationLabel"],"sources":["../../../src/components/PartnerCarousel/PartnerCarousel.tsx"],"sourcesContent":["import { Children, forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { useAutoplay, useIndexState } from './autoplay';\nimport './PartnerCarousel.css';\n\n/** Figma prototype: Smart animate, ease in and out, 700ms. */\nconst SLIDE_DURATION = 700;\n/** CSS `ease-in-out` of the prototype, closely approximated (quadratic) for the scripted scroll. */\nconst easeInOut = (t: number) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nexport interface PartnerCarouselProps extends Omit<HTMLAttributes<HTMLElement>, 'onChange' | 'defaultValue'> {\n /** The slides: one element per slide, normally `PartnerCard`s. Any number. */\n children?: ReactNode;\n /** Name of the carousel region, e.g. \"Partner agencies\" — translate it. */\n 'aria-label'?: string;\n /** Index (0-based) of the first slide in view — Figma \"Slide\". Makes the carousel controlled. */\n value?: number;\n /** Slide shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the carousel moves (swipe, dots or autoplay). */\n onValueChange?: (value: number) => void;\n /** Moves one slide at a time by itself, in an endless loop. Holds for hover, keyboard focus, a hidden tab, an off-screen carousel and reduced motion. */\n autoPlay?: boolean;\n /** Time a slide rests before the next move, in ms (Figma: 3000). */\n interval?: number;\n /** Holds the autoplay from outside; it carries on once this is `false` again. */\n paused?: boolean;\n /** After the last slide the first one follows seamlessly, as in the Figma prototype. Needs more than two slides. */\n loop?: boolean;\n /** Shows the dots (wide containers only: Figma mobile, under 768px of container width, has none). */\n controls?: boolean;\n /** Accessible name of a slide — translate it. */\n getSlideLabel?: (index: number, count: number) => string;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n}\n\nconst defaultSlideLabel = (index: number, count: number) => `${index + 1} of ${count}`;\nconst defaultPageLabel = (page: number, pageCount: number) => `Slide ${page} of ${pageCount}`;\nconst setInert = (element: HTMLElement | null) => element?.setAttribute('inert', '');\n\n/**\n * Carousel of partner cards (Figma component set \"Home / Partner carousel\"): a native scroll-snap track — so touch\n * swipe, trackpad and keyboard scrolling work by themselves — with dots, autoplay and a seamless loop.\n * Two slides per view; containers narrower than 768px show one 300px slide with the next one peeking, like\n * \"Mobile / Home / Partner carousel\".\n */\nexport const PartnerCarousel = /* @__PURE__ */ forwardRef<HTMLElement, PartnerCarouselProps>(function PartnerCarousel(\n {\n children,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 3000,\n paused = false,\n loop = true,\n controls = true,\n getSlideLabel = defaultSlideLabel,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Slides',\n className,\n ...props\n },\n ref,\n) {\n const slides = Children.toArray(children);\n const count = slides.length;\n const looping = loop && count > 2;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n // Without the loop the last slides share one view, so there are fewer stops than slides (measured below).\n const [stops, setStops] = useState(count);\n const pageCount = looping ? count : Math.max(1, Math.min(stops, count));\n\n /** The index the track currently shows or is animating to. */\n const shown = useRef(index);\n const frame = useRef(0);\n const animating = useRef(false);\n const settleTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n /** Distance between two neighbouring slides; 0 when there is no layout (tests, hidden). */\n const getStep = useCallback(() => {\n const items = viewportRef.current?.querySelectorAll<HTMLElement>('.tm-partner-carousel__slide');\n if (!items || items.length < 2) return 0;\n return (items[1] as HTMLElement).offsetLeft - (items[0] as HTMLElement).offsetLeft;\n }, []);\n\n const stopAnimation = useCallback(() => {\n if (!animating.current) return;\n cancelAnimationFrame(frame.current);\n animating.current = false;\n if (viewportRef.current) viewportRef.current.style.scrollSnapType = '';\n }, []);\n\n /** After a move: leave the cloned slides for their originals and report where the track rests. */\n const settle = useCallback(() => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0 || animating.current) return;\n let position = Math.round(viewport.scrollLeft / step);\n if (looping && position >= count) {\n position -= count;\n viewport.scrollLeft = position * step;\n }\n const next = Math.max(0, Math.min(position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n }, [count, getStep, looping, pageCount, setIndex]);\n\n /** Scrolls to a track position (slide number, clones included) with the Figma timing. */\n const scrollToPosition = useCallback(\n (position: number, animate: boolean) => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n stopAnimation();\n const from = viewport.scrollLeft;\n const to = Math.min(position * step, viewport.scrollWidth - viewport.clientWidth);\n const reduced = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n if (!animate || reduced || Math.abs(to - from) < 1) {\n viewport.scrollLeft = to;\n settle();\n return;\n }\n // Scroll snapping would fight a scripted scroll, so it is switched off for its duration.\n animating.current = true;\n viewport.style.scrollSnapType = 'none';\n const start = performance.now();\n const run = (now: number) => {\n const t = Math.min(1, (now - start) / SLIDE_DURATION);\n viewport.scrollLeft = from + (to - from) * easeInOut(t);\n if (t < 1) {\n frame.current = requestAnimationFrame(run);\n return;\n }\n animating.current = false;\n viewport.style.scrollSnapType = '';\n settle();\n };\n frame.current = requestAnimationFrame(run);\n },\n [getStep, settle, stopAnimation],\n );\n\n /** Shows a slide. `forward` keeps moving right through the clones, so the loop never rewinds. */\n const goTo = useCallback(\n (next: number, options: { forward?: boolean; animate?: boolean; silent?: boolean } = {}) => {\n const viewport = viewportRef.current;\n const step = getStep();\n let position = next;\n if (options.forward && looping && viewport && step > 0) {\n let current = Math.round(viewport.scrollLeft / step);\n if (current >= count) {\n current -= count;\n viewport.scrollLeft = current * step;\n }\n position = current + 1;\n }\n shown.current = next;\n if (!options.silent) setIndex(next);\n scrollToPosition(position, options.animate ?? true);\n },\n [count, getStep, looping, scrollToPosition, setIndex],\n );\n\n // Start at the requested slide without animating.\n useIsomorphicLayoutEffect(() => {\n if (shown.current > 0) scrollToPosition(shown.current, false);\n return () => {\n cancelAnimationFrame(frame.current);\n clearTimeout(settleTimer.current);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // A controlled `value` (or a shrinking list) that differs from what the track shows moves the track.\n useEffect(() => {\n if (index !== shown.current) goTo(index, { silent: true });\n }, [index, goTo]);\n\n // Count the stops of a carousel that does not loop.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n const measure = () => {\n const step = getStep();\n if (step <= 0) return setStops(count);\n setStops(Math.ceil((viewport.scrollWidth - viewport.clientWidth) / step - 0.05) + 1);\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(viewport);\n return () => observer.disconnect();\n }, [count, getStep, looping]);\n\n const { running, interactionProps } = useAutoplay({\n enabled: autoPlay && pageCount > 1,\n paused,\n delay: interval + SLIDE_DURATION,\n onTick: () => goTo((shown.current + 1) % pageCount, { forward: true }),\n rootRef,\n resetKey: index,\n });\n\n const handleScroll = () => {\n if (animating.current) return;\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n // The dots follow a swipe while it happens…\n const position = Math.round(viewport.scrollLeft / step);\n const next = Math.max(0, Math.min(looping ? position % count : position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n // …and once it rests the track leaves the clones (`scrollend` is not available everywhere).\n clearTimeout(settleTimer.current);\n settleTimer.current = setTimeout(settle, 140);\n };\n\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <section\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-partner-carousel', className)}\n aria-roledescription=\"carousel\"\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus(event);\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div\n ref={viewportRef}\n className=\"tm-partner-carousel__viewport\"\n onScroll={handleScroll}\n // The user takes over: a scripted move must not fight a swipe, the wheel or the keyboard.\n onPointerDown={stopAnimation}\n onTouchStart={stopAnimation}\n onWheel={stopAnimation}\n onKeyDown={(event) => {\n if (event.key.startsWith('Arrow') || event.key === 'Home' || event.key === 'End') stopAnimation();\n }}\n >\n <div className=\"tm-partner-carousel__track\">\n {slides.map((slide, i) => (\n <div key={i} className=\"tm-partner-carousel__slide\" role=\"group\" aria-roledescription=\"slide\" aria-label={getSlideLabel(i, count)}>\n {slide}\n </div>\n ))}\n {/* Copies of the slides that close the loop; assistive technology and the keyboard skip them. */}\n {looping\n ? slides.map((slide, i) => (\n <div key={`clone-${i}`} ref={setInert} className=\"tm-partner-carousel__slide\" data-clone=\"\" aria-hidden=\"true\">\n {slide}\n </div>\n ))\n : null}\n </div>\n </div>\n\n {controls && pageCount > 1 ? (\n <div className=\"tm-partner-carousel__controls\">\n <Pagination page={index + 1} pageCount={pageCount} onPageChange={(page) => goTo(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n </div>\n ) : null}\n </section>\n );\n});\n"],"mappings":"A,oNAOA,IAAMe,EAAiB,IAEjBC,EAAa,GAAeC,EAAI,GAAM,EAAIA,EAAIA,EAAI,GAAK,GAAKA,EAAI,IAAM,EAAI,EAC1EC,EAA4B,OAAO,OAAW,IAAclB,EAAAA,UAAYC,EAAAA,gBA+BxEkB,GAAqB,EAAe,IAAkB,GAAGC,EAAQ,EAAE,MAAMC,IACzEC,GAAoB,EAAc,IAAsB,SAASC,EAAK,MAAMC,IAC5EC,EAAY,GAAgCC,GAAS,aAAa,QAAS,EAAE,EAQtEC,GAAkC,EAAAd,EAAA,WAAA,CAA8C,SAC3F,CACE,WACA,QACA,eAAe,EACf,gBACA,WAAW,GACX,WAAW,IACX,SAAS,GACT,OAAO,GACP,WAAW,GACX,gBAAgBM,EAChB,eAAeG,EACf,kBAAkB,SAClB,YACA,GAAGM,GAEL,EACA,CACA,IAAMC,EAAS3B,EAAAA,SAAS,QAAQ4B,CAAQ,EAClCT,EAAQQ,EAAO,OACfE,EAAUC,GAAQX,EAAQ,EAE1BY,GAAA,EAAU9B,EAAAA,OAAAA,CAA2B,IAAI,EACzC+B,GAAA,EAAc/B,EAAAA,OAAAA,CAA8B,IAAI,EAChD,CAACiB,EAAOe,GAAY/B,EAAAA,cAAcgC,EAAOC,EAAcC,EAAejB,CAAK,EAE3E,CAACkB,EAAOC,IAAA,EAAYnC,EAAAA,SAAAA,CAASgB,CAAK,EAClCG,EAAYO,EAAUV,EAAQ,KAAK,IAAI,EAAG,KAAK,IAAIkB,EAAOlB,CAAK,CAAC,EAGhEoB,GAAA,EAAQtC,EAAAA,OAAAA,CAAOiB,CAAK,EACpBsB,GAAA,EAA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,IACD,C,EACF,CAAA,EAEJE,GAAY1D,EAAY,GACvB,EAAAV,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,gCACb,UAAA,EAAAA,EAAA,IAAA,CAACL,EAAAA,WAAD,CAAY,KAAMW,EAAQ,EAAc,YAAW,aAAe,GAASyC,EAAKtC,EAAO,CAAC,EAAiB,eAAc,aAAY4D,CAAkB,CAAA,CAClJ,CAAA,EACH,IACG,C,EAEb,CAAC,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PartnerCarousel.js","names":["SLIDE_DURATION","easeInOut","t","useIsomorphicLayoutEffect","useEffect","useLayoutEffect","defaultSlideLabel","index","count","defaultPageLabel","page","pageCount","setInert","element","PartnerCarousel","props","slides","Children","children","looping","loop","rootRef","useRef","viewportRef","setIndex","useIndexState","value","defaultValue","onValueChange","stops","setStops","useState","shown","frame","animating","settleTimer","getStep","useCallback","items","stopAnimation","settle","viewport","step","position","next","scrollToPosition","from","to","reduced","animate","start","run","now","goTo","options","current","measure","observer","useAutoplay","autoPlay","interval","handleScroll","interactionProps","node","ref","cn","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","getSlideLabel","i","slide","controls","Pagination","paginationLabel"],"sources":["../../../src/components/PartnerCarousel/PartnerCarousel.tsx"],"sourcesContent":["import { Children, forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { useAutoplay, useIndexState } from './autoplay';\nimport './PartnerCarousel.css';\n\n/** Figma prototype: Smart animate, ease in and out, 700ms. */\nconst SLIDE_DURATION = 700;\n/** CSS `ease-in-out` of the prototype, closely approximated (quadratic) for the scripted scroll. */\nconst easeInOut = (t: number) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nexport interface PartnerCarouselProps extends Omit<HTMLAttributes<HTMLElement>, 'onChange' | 'defaultValue'> {\n /** The slides: one element per slide, normally `PartnerCard`s. Any number. */\n children?: ReactNode;\n /** Name of the carousel region, e.g. \"Partner agencies\" — translate it. */\n 'aria-label'?: string;\n /** Index (0-based) of the first slide in view — Figma \"Slide\". Makes the carousel controlled. */\n value?: number;\n /** Slide shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the carousel moves (swipe, dots or autoplay). */\n onValueChange?: (value: number) => void;\n /** Moves one slide at a time by itself, in an endless loop. Holds for hover, keyboard focus, a hidden tab, an off-screen carousel and reduced motion. */\n autoPlay?: boolean;\n /** Time a slide rests before the next move, in ms (Figma: 3000). */\n interval?: number;\n /** Holds the autoplay from outside; it carries on once this is `false` again. */\n paused?: boolean;\n /** After the last slide the first one follows seamlessly, as in the Figma prototype. Needs more than two slides. */\n loop?: boolean;\n /** Shows the dots. */\n controls?: boolean;\n /** Accessible name of a slide — translate it. */\n getSlideLabel?: (index: number, count: number) => string;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n}\n\nconst defaultSlideLabel = (index: number, count: number) => `${index + 1} of ${count}`;\nconst defaultPageLabel = (page: number, pageCount: number) => `Slide ${page} of ${pageCount}`;\nconst setInert = (element: HTMLElement | null) => element?.setAttribute('inert', '');\n\n/**\n * Carousel of partner cards (Figma component set \"Home / Partner carousel\"): a native scroll-snap track — so touch\n * swipe, trackpad and keyboard scrolling work by themselves — with dots, autoplay and a seamless loop.\n * Two slides per view; containers narrower than 768px show one 300px slide with the next one peeking, like\n * \"Mobile / Home / Partner carousel\".\n */\nexport const PartnerCarousel = /* @__PURE__ */ forwardRef<HTMLElement, PartnerCarouselProps>(function PartnerCarousel(\n {\n children,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 3000,\n paused = false,\n loop = true,\n controls = true,\n getSlideLabel = defaultSlideLabel,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Slides',\n className,\n ...props\n },\n ref,\n) {\n const slides = Children.toArray(children);\n const count = slides.length;\n const looping = loop && count > 2;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n // Without the loop the last slides share one view, so there are fewer stops than slides (measured below).\n const [stops, setStops] = useState(count);\n const pageCount = looping ? count : Math.max(1, Math.min(stops, count));\n\n /** The index the track currently shows or is animating to. */\n const shown = useRef(index);\n const frame = useRef(0);\n const animating = useRef(false);\n const settleTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n /** Distance between two neighbouring slides; 0 when there is no layout (tests, hidden). */\n const getStep = useCallback(() => {\n const items = viewportRef.current?.querySelectorAll<HTMLElement>('.tm-partner-carousel__slide');\n if (!items || items.length < 2) return 0;\n return (items[1] as HTMLElement).offsetLeft - (items[0] as HTMLElement).offsetLeft;\n }, []);\n\n const stopAnimation = useCallback(() => {\n if (!animating.current) return;\n cancelAnimationFrame(frame.current);\n animating.current = false;\n if (viewportRef.current) viewportRef.current.style.scrollSnapType = '';\n }, []);\n\n /** After a move: leave the cloned slides for their originals and report where the track rests. */\n const settle = useCallback(() => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0 || animating.current) return;\n let position = Math.round(viewport.scrollLeft / step);\n if (looping && position >= count) {\n position -= count;\n viewport.scrollLeft = position * step;\n }\n const next = Math.max(0, Math.min(position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n }, [count, getStep, looping, pageCount, setIndex]);\n\n /** Scrolls to a track position (slide number, clones included) with the Figma timing. */\n const scrollToPosition = useCallback(\n (position: number, animate: boolean) => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n stopAnimation();\n const from = viewport.scrollLeft;\n const to = Math.min(position * step, viewport.scrollWidth - viewport.clientWidth);\n const reduced = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n if (!animate || reduced || Math.abs(to - from) < 1) {\n viewport.scrollLeft = to;\n settle();\n return;\n }\n // Scroll snapping would fight a scripted scroll, so it is switched off for its duration.\n animating.current = true;\n viewport.style.scrollSnapType = 'none';\n const start = performance.now();\n const run = (now: number) => {\n const t = Math.min(1, (now - start) / SLIDE_DURATION);\n viewport.scrollLeft = from + (to - from) * easeInOut(t);\n if (t < 1) {\n frame.current = requestAnimationFrame(run);\n return;\n }\n animating.current = false;\n viewport.style.scrollSnapType = '';\n settle();\n };\n frame.current = requestAnimationFrame(run);\n },\n [getStep, settle, stopAnimation],\n );\n\n /** Shows a slide. `forward` keeps moving right through the clones, so the loop never rewinds. */\n const goTo = useCallback(\n (next: number, options: { forward?: boolean; animate?: boolean; silent?: boolean } = {}) => {\n const viewport = viewportRef.current;\n const step = getStep();\n let position = next;\n if (options.forward && looping && viewport && step > 0) {\n let current = Math.round(viewport.scrollLeft / step);\n if (current >= count) {\n current -= count;\n viewport.scrollLeft = current * step;\n }\n position = current + 1;\n }\n shown.current = next;\n if (!options.silent) setIndex(next);\n scrollToPosition(position, options.animate ?? true);\n },\n [count, getStep, looping, scrollToPosition, setIndex],\n );\n\n // Start at the requested slide without animating.\n useIsomorphicLayoutEffect(() => {\n if (shown.current > 0) scrollToPosition(shown.current, false);\n return () => {\n cancelAnimationFrame(frame.current);\n clearTimeout(settleTimer.current);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // A controlled `value` (or a shrinking list) that differs from what the track shows moves the track.\n useEffect(() => {\n if (index !== shown.current) goTo(index, { silent: true });\n }, [index, goTo]);\n\n // Count the stops of a carousel that does not loop.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n const measure = () => {\n const step = getStep();\n if (step <= 0) return setStops(count);\n setStops(Math.ceil((viewport.scrollWidth - viewport.clientWidth) / step - 0.05) + 1);\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(viewport);\n return () => observer.disconnect();\n }, [count, getStep, looping]);\n\n const { running, interactionProps } = useAutoplay({\n enabled: autoPlay && pageCount > 1,\n paused,\n delay: interval + SLIDE_DURATION,\n onTick: () => goTo((shown.current + 1) % pageCount, { forward: true }),\n rootRef,\n resetKey: index,\n });\n\n const handleScroll = () => {\n if (animating.current) return;\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n // The dots follow a swipe while it happens…\n const position = Math.round(viewport.scrollLeft / step);\n const next = Math.max(0, Math.min(looping ? position % count : position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n // …and once it rests the track leaves the clones (`scrollend` is not available everywhere).\n clearTimeout(settleTimer.current);\n settleTimer.current = setTimeout(settle, 140);\n };\n\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <section\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-partner-carousel', className)}\n aria-roledescription=\"carousel\"\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus(event);\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div\n ref={viewportRef}\n className=\"tm-partner-carousel__viewport\"\n onScroll={handleScroll}\n // The user takes over: a scripted move must not fight a swipe, the wheel or the keyboard.\n onPointerDown={stopAnimation}\n onTouchStart={stopAnimation}\n onWheel={stopAnimation}\n onKeyDown={(event) => {\n if (event.key.startsWith('Arrow') || event.key === 'Home' || event.key === 'End') stopAnimation();\n }}\n >\n <div className=\"tm-partner-carousel__track\">\n {slides.map((slide, i) => (\n <div key={i} className=\"tm-partner-carousel__slide\" role=\"group\" aria-roledescription=\"slide\" aria-label={getSlideLabel(i, count)}>\n {slide}\n </div>\n ))}\n {/* Copies of the slides that close the loop; assistive technology and the keyboard skip them. */}\n {looping\n ? slides.map((slide, i) => (\n <div key={`clone-${i}`} ref={setInert} className=\"tm-partner-carousel__slide\" data-clone=\"\" aria-hidden=\"true\">\n {slide}\n </div>\n ))\n : null}\n </div>\n </div>\n\n {controls && pageCount > 1 ? (\n <div className=\"tm-partner-carousel__controls\">\n <Pagination page={index + 1} pageCount={pageCount} onPageChange={(page) => goTo(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n </div>\n ) : null}\n </section>\n );\n});\n"],"mappings":";;;;;;;;AAOA,IAAMA,IAAiB,KAEjBC,KAAa,MAAeC,IAAI,KAAM,IAAIA,IAAIA,IAAI,KAAK,KAAKA,IAAI,MAAM,IAAI,GAC1EC,IAA4B,OAAO,SAAW,MAAcC,IAAYC,GA+BxEC,KAAqB,GAAe,MAAkB,GAAGC,IAAQ,EAAE,MAAMC,KACzEC,KAAoB,GAAc,MAAsB,SAASC,EAAK,MAAMC,KAC5EC,KAAY,MAAgCC,GAAS,aAAa,SAAS,EAAE,GAQtEC,IAAkC,kBAA8C,SAC3F,EACE,aACA,UACA,kBAAe,GACf,kBACA,cAAW,IACX,cAAW,KACX,YAAS,IACT,UAAO,IACP,cAAW,IACX,mBAAgBR,GAChB,kBAAeG,GACf,qBAAkB,UAClB,cACA,GAAGM,KAEL,GACA;CACA,IAAMC,IAASC,EAAS,QAAQC,CAAQ,GAClCV,IAAQQ,EAAO,QACfG,IAAUC,KAAQZ,IAAQ,GAE1Ba,IAAUC,EAA2B,IAAI,GACzCC,IAAcD,EAA8B,IAAI,GAChD,CAACf,GAAOiB,KAAYC,EAAcC,GAAOC,GAAcC,GAAepB,CAAK,GAE3E,CAACqB,GAAOC,KAAYC,EAASvB,CAAK,GAClCG,IAAYQ,IAAUX,IAAQ,KAAK,IAAI,GA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Ae,MAAS8C,EAAK3C,IAAO,CAAC;IAAiB;IAAc,cAAYoE;GAAkB,CAAA;EAClJ,CAAA,IACH,IACG;;AAEb,CAAC"}
|
|
1
|
+
{"version":3,"file":"PartnerCarousel.js","names":["SLIDE_DURATION","easeInOut","t","useIsomorphicLayoutEffect","useEffect","useLayoutEffect","defaultSlideLabel","index","count","defaultPageLabel","page","pageCount","setInert","element","PartnerCarousel","props","slides","Children","children","looping","loop","rootRef","useRef","viewportRef","setIndex","useIndexState","value","defaultValue","onValueChange","stops","setStops","useState","shown","frame","animating","settleTimer","getStep","useCallback","items","stopAnimation","settle","viewport","step","position","next","scrollToPosition","from","to","reduced","animate","start","run","now","goTo","options","current","measure","observer","useAutoplay","autoPlay","interval","handleScroll","interactionProps","node","ref","cn","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","getSlideLabel","i","slide","controls","Pagination","paginationLabel"],"sources":["../../../src/components/PartnerCarousel/PartnerCarousel.tsx"],"sourcesContent":["import { Children, forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { useAutoplay, useIndexState } from './autoplay';\nimport './PartnerCarousel.css';\n\n/** Figma prototype: Smart animate, ease in and out, 700ms. */\nconst SLIDE_DURATION = 700;\n/** CSS `ease-in-out` of the prototype, closely approximated (quadratic) for the scripted scroll. */\nconst easeInOut = (t: number) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nexport interface PartnerCarouselProps extends Omit<HTMLAttributes<HTMLElement>, 'onChange' | 'defaultValue'> {\n /** The slides: one element per slide, normally `PartnerCard`s. Any number. */\n children?: ReactNode;\n /** Name of the carousel region, e.g. \"Partner agencies\" — translate it. */\n 'aria-label'?: string;\n /** Index (0-based) of the first slide in view — Figma \"Slide\". Makes the carousel controlled. */\n value?: number;\n /** Slide shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the carousel moves (swipe, dots or autoplay). */\n onValueChange?: (value: number) => void;\n /** Moves one slide at a time by itself, in an endless loop. Holds for hover, keyboard focus, a hidden tab, an off-screen carousel and reduced motion. */\n autoPlay?: boolean;\n /** Time a slide rests before the next move, in ms (Figma: 3000). */\n interval?: number;\n /** Holds the autoplay from outside; it carries on once this is `false` again. */\n paused?: boolean;\n /** After the last slide the first one follows seamlessly, as in the Figma prototype. Needs more than two slides. */\n loop?: boolean;\n /** Shows the dots (wide containers only: Figma mobile, under 768px of container width, has none). */\n controls?: boolean;\n /** Accessible name of a slide — translate it. */\n getSlideLabel?: (index: number, count: number) => string;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n}\n\nconst defaultSlideLabel = (index: number, count: number) => `${index + 1} of ${count}`;\nconst defaultPageLabel = (page: number, pageCount: number) => `Slide ${page} of ${pageCount}`;\nconst setInert = (element: HTMLElement | null) => element?.setAttribute('inert', '');\n\n/**\n * Carousel of partner cards (Figma component set \"Home / Partner carousel\"): a native scroll-snap track — so touch\n * swipe, trackpad and keyboard scrolling work by themselves — with dots, autoplay and a seamless loop.\n * Two slides per view; containers narrower than 768px show one 300px slide with the next one peeking, like\n * \"Mobile / Home / Partner carousel\".\n */\nexport const PartnerCarousel = /* @__PURE__ */ forwardRef<HTMLElement, PartnerCarouselProps>(function PartnerCarousel(\n {\n children,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 3000,\n paused = false,\n loop = true,\n controls = true,\n getSlideLabel = defaultSlideLabel,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Slides',\n className,\n ...props\n },\n ref,\n) {\n const slides = Children.toArray(children);\n const count = slides.length;\n const looping = loop && count > 2;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n // Without the loop the last slides share one view, so there are fewer stops than slides (measured below).\n const [stops, setStops] = useState(count);\n const pageCount = looping ? count : Math.max(1, Math.min(stops, count));\n\n /** The index the track currently shows or is animating to. */\n const shown = useRef(index);\n const frame = useRef(0);\n const animating = useRef(false);\n const settleTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n /** Distance between two neighbouring slides; 0 when there is no layout (tests, hidden). */\n const getStep = useCallback(() => {\n const items = viewportRef.current?.querySelectorAll<HTMLElement>('.tm-partner-carousel__slide');\n if (!items || items.length < 2) return 0;\n return (items[1] as HTMLElement).offsetLeft - (items[0] as HTMLElement).offsetLeft;\n }, []);\n\n const stopAnimation = useCallback(() => {\n if (!animating.current) return;\n cancelAnimationFrame(frame.current);\n animating.current = false;\n if (viewportRef.current) viewportRef.current.style.scrollSnapType = '';\n }, []);\n\n /** After a move: leave the cloned slides for their originals and report where the track rests. */\n const settle = useCallback(() => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0 || animating.current) return;\n let position = Math.round(viewport.scrollLeft / step);\n if (looping && position >= count) {\n position -= count;\n viewport.scrollLeft = position * step;\n }\n const next = Math.max(0, Math.min(position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n }, [count, getStep, looping, pageCount, setIndex]);\n\n /** Scrolls to a track position (slide number, clones included) with the Figma timing. */\n const scrollToPosition = useCallback(\n (position: number, animate: boolean) => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n stopAnimation();\n const from = viewport.scrollLeft;\n const to = Math.min(position * step, viewport.scrollWidth - viewport.clientWidth);\n const reduced = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n if (!animate || reduced || Math.abs(to - from) < 1) {\n viewport.scrollLeft = to;\n settle();\n return;\n }\n // Scroll snapping would fight a scripted scroll, so it is switched off for its duration.\n animating.current = true;\n viewport.style.scrollSnapType = 'none';\n const start = performance.now();\n const run = (now: number) => {\n const t = Math.min(1, (now - start) / SLIDE_DURATION);\n viewport.scrollLeft = from + (to - from) * easeInOut(t);\n if (t < 1) {\n frame.current = requestAnimationFrame(run);\n return;\n }\n animating.current = false;\n viewport.style.scrollSnapType = '';\n settle();\n };\n frame.current = requestAnimationFrame(run);\n },\n [getStep, settle, stopAnimation],\n );\n\n /** Shows a slide. `forward` keeps moving right through the clones, so the loop never rewinds. */\n const goTo = useCallback(\n (next: number, options: { forward?: boolean; animate?: boolean; silent?: boolean } = {}) => {\n const viewport = viewportRef.current;\n const step = getStep();\n let position = next;\n if (options.forward && looping && viewport && step > 0) {\n let current = Math.round(viewport.scrollLeft / step);\n if (current >= count) {\n current -= count;\n viewport.scrollLeft = current * step;\n }\n position = current + 1;\n }\n shown.current = next;\n if (!options.silent) setIndex(next);\n scrollToPosition(position, options.animate ?? true);\n },\n [count, getStep, looping, scrollToPosition, setIndex],\n );\n\n // Start at the requested slide without animating.\n useIsomorphicLayoutEffect(() => {\n if (shown.current > 0) scrollToPosition(shown.current, false);\n return () => {\n cancelAnimationFrame(frame.current);\n clearTimeout(settleTimer.current);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // A controlled `value` (or a shrinking list) that differs from what the track shows moves the track.\n useEffect(() => {\n if (index !== shown.current) goTo(index, { silent: true });\n }, [index, goTo]);\n\n // Count the stops of a carousel that does not loop.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n const measure = () => {\n const step = getStep();\n if (step <= 0) return setStops(count);\n setStops(Math.ceil((viewport.scrollWidth - viewport.clientWidth) / step - 0.05) + 1);\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(viewport);\n return () => observer.disconnect();\n }, [count, getStep, looping]);\n\n const { running, interactionProps } = useAutoplay({\n enabled: autoPlay && pageCount > 1,\n paused,\n delay: interval + SLIDE_DURATION,\n onTick: () => goTo((shown.current + 1) % pageCount, { forward: true }),\n rootRef,\n resetKey: index,\n });\n\n const handleScroll = () => {\n if (animating.current) return;\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n // The dots follow a swipe while it happens…\n const position = Math.round(viewport.scrollLeft / step);\n const next = Math.max(0, Math.min(looping ? position % count : position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n // …and once it rests the track leaves the clones (`scrollend` is not available everywhere).\n clearTimeout(settleTimer.current);\n settleTimer.current = setTimeout(settle, 140);\n };\n\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <section\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-partner-carousel', className)}\n aria-roledescription=\"carousel\"\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus(event);\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div\n ref={viewportRef}\n className=\"tm-partner-carousel__viewport\"\n onScroll={handleScroll}\n // The user takes over: a scripted move must not fight a swipe, the wheel or the keyboard.\n onPointerDown={stopAnimation}\n onTouchStart={stopAnimation}\n onWheel={stopAnimation}\n onKeyDown={(event) => {\n if (event.key.startsWith('Arrow') || event.key === 'Home' || event.key === 'End') stopAnimation();\n }}\n >\n <div className=\"tm-partner-carousel__track\">\n {slides.map((slide, i) => (\n <div key={i} className=\"tm-partner-carousel__slide\" role=\"group\" aria-roledescription=\"slide\" aria-label={getSlideLabel(i, count)}>\n {slide}\n </div>\n ))}\n {/* Copies of the slides that close the loop; assistive technology and the keyboard skip them. */}\n {looping\n ? slides.map((slide, i) => (\n <div key={`clone-${i}`} ref={setInert} className=\"tm-partner-carousel__slide\" data-clone=\"\" aria-hidden=\"true\">\n {slide}\n </div>\n ))\n : null}\n </div>\n </div>\n\n {controls && pageCount > 1 ? (\n <div className=\"tm-partner-carousel__controls\">\n <Pagination page={index + 1} pageCount={pageCount} onPageChange={(page) => goTo(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n </div>\n ) : null}\n </section>\n );\n});\n"],"mappings":";;;;;;;;AAOA,IAAMA,IAAiB,KAEjBC,KAAa,MAAeC,IAAI,KAAM,IAAIA,IAAIA,IAAI,KAAK,KAAKA,IAAI,MAAM,IAAI,GAC1EC,IAA4B,OAAO,SAAW,MAAcC,IAAYC,GA+BxEC,KAAqB,GAAe,MAAkB,GAAGC,IAAQ,EAAE,MAAMC,KACzEC,KAAoB,GAAc,MAAsB,SAASC,EAAK,MAAMC,KAC5EC,KAAY,MAAgCC,GAAS,aAAa,SAAS,EAAE,GAQtEC,IAAkC,kBAA8C,SAC3F,EACE,aACA,UACA,kBAAe,GACf,kBACA,cAAW,IACX,cAAW,KACX,YAAS,IACT,UAAO,IACP,cAAW,IACX,mBAAgBR,GAChB,kBAAeG,GACf,qBAAkB,UAClB,cACA,GAAGM,KAEL,GACA;CACA,IAAMC,IAASC,EAAS,QAAQC,CAAQ,GAClCV,IAAQQ,EAAO,QACfG,IAAUC,KAAQZ,IAAQ,GAE1Ba,IAAUC,EAA2B,IAAI,GACzCC,IAAcD,EAA8B,IAAI,GAChD,CAACf,GAAOiB,KAAYC,EAAcC,GAAOC,GAAcC,GAAepB,CAAK,GAE3E,CAACqB,GAAOC,KAAYC,EAASvB,CAAK,GAClCG,IAAYQ,IAAUX,IAAQ,KAAK,IAAI,GAAG,KAAK,IAAIqB,GAAOrB,CAAK,CAAC,GAGhEwB,IAAQV,EAAOf,CAAK,GACpB0B,IAAQX,EAAO,CAAC,GAChBY,IAAYZ,EAAO,EAAK,GACxBa,IAAcb,EAAkD,KAAA,CAAS,GAGzEc,IAAU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t=require("../Field/Field.cjs"),n=require("../Field/focusControl.cjs"),r=require("../Select/Select.cjs");;/* empty css */let i=require("react"),a=require("react/jsx-runtime");var o=(0,i.forwardRef)(function({label:o,helperText:s,error:c,required:l,optional:u,size:d=`md`,countries:f,country:p,defaultCountry:m,onCountryChange:h,countryLabel:g=`Country code`,countryListOpen:_,onCountryListOpenChange:v,searchable:y,searchPlaceholder:b
|
|
1
|
+
"use client";const e=require("../../utils/cn.cjs"),t=require("../Field/Field.cjs"),n=require("../Field/focusControl.cjs"),r=require("../Select/Select.cjs");;/* empty css */let i=require("react"),a=require("react/jsx-runtime");var o=(0,i.forwardRef)(function({label:o,helperText:s,error:c,required:l,optional:u,size:d=`md`,countries:f,country:p,defaultCountry:m,onCountryChange:h,countryLabel:g=`Country code`,countryListOpen:_,onCountryListOpenChange:v,searchable:y=!0,searchPlaceholder:b=`Search country or code`,emptyText:x,portalContainer:S,id:C,disabled:w,readOnly:T,className:E,style:D,"aria-describedby":O,"aria-invalid":k,...A},j){let M=t.useFieldIds(C,!!(c||s)),N=(0,i.useRef)(null),[P,F]=(0,i.useState)(m??f[0]?.code),I=!!c,L=p??P;return(0,a.jsx)(t.FormField,{ids:M,label:o,helperText:s,error:c,required:l,optional:u,size:d,className:e.cn(`tm-phone-input`,E),style:D,role:`group`,"aria-labelledby":o?M.labelId:void 0,children:(0,a.jsxs)(`div`,{ref:N,className:`tm-phone-input__row`,children:[f.length>0?(0,a.jsx)(r.Select,{"aria-label":g,className:`tm-phone-input__country`,size:d,fullWidth:!1,options:f.map(e=>({value:e.code,label:e.label,description:e.dialCode,icon:e.flag,textValue:`${e.label} ${e.dialCode}`})),value:L??null,onValueChange:e=>{p===void 0&&F(e);let t=f.find(t=>t.code===e);t&&h?.(e,t)},open:_,onOpenChange:v,renderValue:e=>(0,a.jsxs)(`span`,{className:`tm-phone-input__code`,children:[e.icon,f.find(t=>t.code===e.value)?.dialCode]}),panelAnchor:N,panelClassName:`tm-phone-input__panel`,listSize:`md`,invalid:I,disabled:w,readOnly:T,searchable:y,searchPlaceholder:b,emptyText:x,portalContainer:S}):null,(0,a.jsx)(`div`,{className:`tm-field tm-phone-input__number`,"data-size":d,"data-tm-icon-size":d,"data-invalid":I?``:void 0,"data-disabled":w?``:void 0,"data-readonly":T?``:void 0,onMouseDown:n.focusControlOnMouseDown,children:(0,a.jsx)(`input`,{ref:j,id:M.controlId,type:`tel`,inputMode:`tel`,autoComplete:`tel-national`,className:`tm-field__control`,disabled:w,readOnly:T,required:l,"aria-invalid":k??(I||void 0),"aria-describedby":e.cn(O,M.messageId)||void 0,...A})})]})})});exports.PhoneInput=o;
|
|
2
2
|
//# sourceMappingURL=PhoneInput.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.cjs","names":["useFieldIds","useRef","useState","FormField","cn","Select","focusControlOnMouseDown","require_cn","require_Field","require_focusControl","require_Select","react","react_jsx_runtime","PhoneInput","describedBy","ariaInvalid","props","ids","id","error","helperText","rowRef","internalCountry","setInternalCountry","defaultCountry","countries","invalid","selected","country","className","label","countryLabel","item","code","entry","onCountryChange","countryListOpen","onCountryListOpenChange","option","
|
|
1
|
+
{"version":3,"file":"PhoneInput.cjs","names":["useFieldIds","useRef","useState","FormField","cn","Select","focusControlOnMouseDown","require_cn","require_Field","require_focusControl","require_Select","react","react_jsx_runtime","PhoneInput","describedBy","ariaInvalid","props","ids","id","error","helperText","rowRef","internalCountry","setInternalCountry","defaultCountry","countries","invalid","selected","country","className","label","countryLabel","item","code","entry","onCountryChange","countryListOpen","onCountryListOpenChange","option","size","disabled","readOnly"],"sources":["../../../src/components/PhoneInput/PhoneInput.tsx"],"sourcesContent":["import { forwardRef, useRef, useState, type InputHTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { FormField, useFieldIds, type FieldSize, type FormFieldProps } from '../Field';\nimport { focusControlOnMouseDown } from '../Field/focusControl';\nimport { Select } from '../Select';\nimport './PhoneInput.css';\n\nexport interface PhoneCountry {\n /** Unique key of the entry, normally the ISO country code (`AM`). */\n code: string;\n /** Calling code shown in the field and under the country name in the list, e.g. `+374`. */\n dialCode: string;\n /** Country name, the first line of its row in the list; search matches it and the calling code. */\n label: string;\n /** Flag shown before the calling code, e.g. `<FlagIcon />`. */\n flag?: ReactNode;\n}\n\nexport interface PhoneInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'type'>, FormFieldProps {\n /** Figma \"Size\": `lg` 52px · `md` 46px (default) · `sm` 42px. */\n size?: FieldSize;\n /** The calling codes offered. The package ships no country data — pass the countries the app supports. */\n countries: PhoneCountry[];\n /** `code` of the selected country (controlled). */\n country?: string;\n /** Initially selected country (uncontrolled). Defaults to the first of `countries`. */\n defaultCountry?: string;\n /** Called with the `code` of the chosen country and its entry. */\n onCountryChange?: (code: string, country: PhoneCountry) => void;\n /** Accessible name of the calling-code dropdown. */\n countryLabel?: string;\n /** Whether the country list is open (controlled; Figma \"State=Open\"). */\n countryListOpen?: boolean;\n /** Called when the country list opens or closes. */\n onCountryListOpenChange?: (open: boolean) => void;\n /** Shows the search box at the top of the country list (Figma \"State=Open\"). Default `true`; `false` hides it for short lists. */\n searchable?: boolean;\n /** Placeholder and accessible name of that search box. Default \"Search country or code\". */\n searchPlaceholder?: string;\n /** Shown when the search matches no country. */\n emptyText?: ReactNode;\n /** Element the list is rendered into (default `document.body`). */\n portalContainer?: HTMLElement | null;\n}\n\n/**\n * Figma \"Drop down inputs / Type=Phone\" (\"Inputs / Style=Both-icon-drop-down\"): a calling-code dropdown next to a number input.\n * The country list is Figma \"State=Open\": a 280px menu with a search box and one row per country (flag, name, calling code).\n * The national number is a native `<input type=\"tel\">` (`value` / `onChange` / `name` as usual; the ref and extra props go to it);\n * the calling code is `country` / `onCountryChange`. `className` goes to the root.\n */\nexport const PhoneInput = /* @__PURE__ */ forwardRef<HTMLInputElement, PhoneInputProps>(function PhoneInput(\n {\n label,\n helperText,\n error,\n required,\n optional,\n size = 'md',\n countries,\n country,\n defaultCountry,\n onCountryChange,\n countryLabel = 'Country code',\n countryListOpen,\n onCountryListOpenChange,\n searchable = true,\n searchPlaceholder = 'Search country or code',\n emptyText,\n portalContainer,\n id,\n disabled,\n readOnly,\n className,\n style,\n 'aria-describedby': describedBy,\n 'aria-invalid': ariaInvalid,\n ...props\n },\n ref,\n) {\n const ids = useFieldIds(id, Boolean(error || helperText));\n const rowRef = useRef<HTMLDivElement>(null);\n const [internalCountry, setInternalCountry] = useState(defaultCountry ?? countries[0]?.code);\n const invalid = Boolean(error);\n const selected = country ?? internalCountry;\n\n const handleCountryChange = (code: string) => {\n if (country === undefined) setInternalCountry(code);\n const entry = countries.find((item) => item.code === code);\n if (entry) onCountryChange?.(code, entry);\n };\n\n return (\n <FormField\n ids={ids}\n label={label}\n helperText={helperText}\n error={error}\n required={required}\n optional={optional}\n size={size}\n className={cn('tm-phone-input', className)}\n style={style}\n role=\"group\"\n aria-labelledby={label ? ids.labelId : undefined}\n >\n <div ref={rowRef} className=\"tm-phone-input__row\">\n {countries.length > 0 ? (\n <Select\n aria-label={countryLabel}\n className=\"tm-phone-input__country\"\n size={size}\n fullWidth={false}\n options={countries.map((item) => ({\n value: item.code,\n label: item.label,\n description: item.dialCode,\n icon: item.flag,\n // Type-ahead and search work on the country name first, then on the calling code.\n textValue: `${item.label} ${item.dialCode}`,\n }))}\n value={selected ?? null}\n onValueChange={handleCountryChange}\n open={countryListOpen}\n onOpenChange={onCountryListOpenChange}\n renderValue={(option) => (\n <span className=\"tm-phone-input__code\">\n {option.icon}\n {countries.find((item) => item.code === option.value)?.dialCode}\n </span>\n )}\n // Figma \"State=Open\": the menu starts at the left edge of the whole field and keeps M rows at every size.\n panelAnchor={rowRef}\n panelClassName=\"tm-phone-input__panel\"\n listSize=\"md\"\n invalid={invalid}\n disabled={disabled}\n readOnly={readOnly}\n searchable={searchable}\n searchPlaceholder={searchPlaceholder}\n emptyText={emptyText}\n portalContainer={portalContainer}\n />\n ) : null}\n <div\n className=\"tm-field tm-phone-input__number\"\n data-size={size}\n data-tm-icon-size={size}\n data-invalid={invalid ? '' : undefined}\n data-disabled={disabled ? '' : undefined}\n data-readonly={readOnly ? '' : undefined}\n onMouseDown={focusControlOnMouseDown}\n >\n <input\n ref={ref}\n id={ids.controlId}\n type=\"tel\"\n inputMode=\"tel\"\n autoComplete=\"tel-national\"\n className=\"tm-field__control\"\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n aria-invalid={ariaInvalid ?? (invalid || undefined)}\n aria-describedby={cn(describedBy, ids.messageId) || undefined}\n {...props}\n />\n </div>\n </div>\n </FormField>\n );\n});\n"],"mappings":"A,kPAmDA,IAAaa,GAA6B,EAAAF,EAAA,WAAA,CAA8C,SACtF,CACE,QACA,aACA,QACA,WACA,WACA,OAAO,KACP,YACA,UACA,iBACA,kBACA,eAAe,eACf,kBACA,0BACA,aAAa,GACb,oBAAoB,yBACpB,YACA,kBACA,KACA,WACA,WACA,YACA,QACA,mBAAoBG,EACpB,eAAgBC,EAChB,GAAGC,GAEL,EACA,CACA,IAAMC,EAAMjB,EAAAA,YAAYkB,EAAI,GAAQC,GAASC,EAAW,EAClDC,GAAA,EAASpB,EAAAA,OAAAA,CAAuB,IAAI,EACpC,CAACqB,EAAiBC,IAAA,EAAsBrB,EAAAA,SAAAA,CAASsB,GAAkBC,EAAU,EAAE,EAAE,IAAI,EACrFC,EAAU,EAAQP,EAClBQ,EAAWC,GAAWN,EAQ5B,OACE,EAAAV,EAAA,IAAA,CAACT,EAAAA,UAAD,CACO,MACE,QACK,aACL,QACG,WACA,WACJ,OACN,UAAWC,EAAAA,GAAG,iBAAkByB,CAAS,EAClC,QACP,KAAK,QACL,kBAAiBC,EAAQb,EAAI,QAAU,IAAA,GAEvC,UAAA,EAAAL,EAAA,KAAA,CAAC,MAAD,CAAK,IAAKS,EAAQ,UAAU,sBAA5B,SAAA,CACGI,EAAU,OAAS,GAClB,EAAAb,EAAA,IAAA,CAACP,EAAAA,OAAD,CACE,aAAY0B,EACZ,UAAU,0BACJ,OACN,UAAW,GACX,QAASN,EAAU,IAAK,IAAU,CAChC,MAAOO,EAAK,KACZ,MAAOA,EAAK,MACZ,YAAaA,EAAK,SAClB,KAAMA,EAAK,KAEX,UAAW,GAAGA,EAAK,MAAM,GAAGA,EAAK,UACnC,EAAE,EACF,MAAOL,GAAY,KACnB,cApCmB,GAAiB,CACxCC,IAAY,IAAA,IAAWL,EAAmBU,CAAI,EAClD,IAAMC,EAAQT,EAAU,KAAM,GAASO,EAAK,OAASC,CAAI,EACrDC,GAAOC,IAAkBF,EAAMC,CAAK,CAC1C,EAiCU,KAAME,EACN,aAAcC,EACd,YAAc,IACZ,EAAAzB,EAAA,KAAA,CAAC,OAAD,CAAM,UAAU,uBAAhB,SAAA,CACG0B,EAAO,KACPb,EAAU,KAAM,GAASO,EAAK,OAASM,EAAO,KAAK,CAAC,EAAE,QACnD,C,GAGR,YAAajB,EACb,eAAe,wBACf,SAAS,KACA,UACC,WACA,WACE,aACO,oBACR,YACM,iBAClB,CAAA,EACC,MACJ,EAAAT,EAAA,IAAA,CAAC,MAAD,CACE,UAAU,kCACV,YAAW2B,EACX,oBAAmBA,EACnB,eAAcb,EAAU,GAAK,IAAA,GAC7B,gBAAec,EAAW,GAAK,IAAA,GAC/B,gBAAeC,EAAW,GAAK,IAAA,GAC/B,YAAanC,EAAAA,wBAEb,UAAA,EAAAM,EAAA,IAAA,CAAC,QAAD,CACO,MACL,GAAIK,EAAI,UACR,KAAK,MACL,UAAU,MACV,aAAa,eACb,UAAU,oBACA,WACA,WACA,WACV,eAAcF,IAAgBW,GAAW,IAAA,IACzC,mBAAkBtB,EAAAA,GAAGU,EAAaG,EAAI,SAAS,GAAK,IAAA,GACpD,GAAID,CACL,CAAA,CACE,CAAA,CACF,C,EACI,CAAA,CAEf,CAAC,E"}
|
|
@@ -7,7 +7,7 @@ import { Select as i } from "../Select/Select.js";
|
|
|
7
7
|
import { forwardRef as a, useRef as o, useState as s } from "react";
|
|
8
8
|
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
9
9
|
// src/components/PhoneInput/PhoneInput.tsx
|
|
10
|
-
var u = /* @__PURE__ */ a(function({ label: a, helperText: u, error: d, required: f, optional: p, size: m = "md", countries: h, country: g, defaultCountry: _, onCountryChange: v, countryLabel: y = "Country code", countryListOpen: b, onCountryListOpenChange: x, searchable: S, searchPlaceholder: C, emptyText: w, portalContainer: T, id: E, disabled: D, readOnly: O, className: k, style: A, "aria-describedby": j, "aria-invalid": M, ...N }, P) {
|
|
10
|
+
var u = /* @__PURE__ */ a(function({ label: a, helperText: u, error: d, required: f, optional: p, size: m = "md", countries: h, country: g, defaultCountry: _, onCountryChange: v, countryLabel: y = "Country code", countryListOpen: b, onCountryListOpenChange: x, searchable: S = !0, searchPlaceholder: C = "Search country or code", emptyText: w, portalContainer: T, id: E, disabled: D, readOnly: O, className: k, style: A, "aria-describedby": j, "aria-invalid": M, ...N }, P) {
|
|
11
11
|
let F = n(E, !!(d || u)), I = o(null), [L, R] = s(_ ?? h[0]?.code), z = !!d, B = g ?? L;
|
|
12
12
|
return /* @__PURE__ */ c(t, {
|
|
13
13
|
ids: F,
|
|
@@ -31,8 +31,8 @@ var u = /* @__PURE__ */ a(function({ label: a, helperText: u, error: d, required
|
|
|
31
31
|
fullWidth: !1,
|
|
32
32
|
options: h.map((e) => ({
|
|
33
33
|
value: e.code,
|
|
34
|
-
label: e.
|
|
35
|
-
|
|
34
|
+
label: e.label,
|
|
35
|
+
description: e.dialCode,
|
|
36
36
|
icon: e.flag,
|
|
37
37
|
textValue: `${e.label} ${e.dialCode}`
|
|
38
38
|
})),
|
|
@@ -46,11 +46,14 @@ var u = /* @__PURE__ */ a(function({ label: a, helperText: u, error: d, required
|
|
|
46
46
|
onOpenChange: x,
|
|
47
47
|
renderValue: (e) => /* @__PURE__ */ l("span", {
|
|
48
48
|
className: "tm-phone-input__code",
|
|
49
|
-
children: [e.icon, e.
|
|
49
|
+
children: [e.icon, h.find((t) => t.code === e.value)?.dialCode]
|
|
50
50
|
}),
|
|
51
51
|
panelAnchor: I,
|
|
52
|
+
panelClassName: "tm-phone-input__panel",
|
|
53
|
+
listSize: "md",
|
|
52
54
|
invalid: z,
|
|
53
|
-
disabled: D
|
|
55
|
+
disabled: D,
|
|
56
|
+
readOnly: O,
|
|
54
57
|
searchable: S,
|
|
55
58
|
searchPlaceholder: C,
|
|
56
59
|
emptyText: w,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.js","names":["PhoneInput","describedBy","ariaInvalid","props","ids","useFieldIds","id","error","helperText","rowRef","useRef","internalCountry","setInternalCountry","useState","defaultCountry","countries","invalid","selected","country","FormField","cn","className","label","Select","countryLabel","item","code","entry","onCountryChange","countryListOpen","onCountryListOpenChange","option","
|
|
1
|
+
{"version":3,"file":"PhoneInput.js","names":["PhoneInput","describedBy","ariaInvalid","props","ids","useFieldIds","id","error","helperText","rowRef","useRef","internalCountry","setInternalCountry","useState","defaultCountry","countries","invalid","selected","country","FormField","cn","className","label","Select","countryLabel","item","code","entry","onCountryChange","countryListOpen","onCountryListOpenChange","option","size","disabled","readOnly","focusControlOnMouseDown"],"sources":["../../../src/components/PhoneInput/PhoneInput.tsx"],"sourcesContent":["import { forwardRef, useRef, useState, type InputHTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { FormField, useFieldIds, type FieldSize, type FormFieldProps } from '../Field';\nimport { focusControlOnMouseDown } from '../Field/focusControl';\nimport { Select } from '../Select';\nimport './PhoneInput.css';\n\nexport interface PhoneCountry {\n /** Unique key of the entry, normally the ISO country code (`AM`). */\n code: string;\n /** Calling code shown in the field and under the country name in the list, e.g. `+374`. */\n dialCode: string;\n /** Country name, the first line of its row in the list; search matches it and the calling code. */\n label: string;\n /** Flag shown before the calling code, e.g. `<FlagIcon />`. */\n flag?: ReactNode;\n}\n\nexport interface PhoneInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'type'>, FormFieldProps {\n /** Figma \"Size\": `lg` 52px · `md` 46px (default) · `sm` 42px. */\n size?: FieldSize;\n /** The calling codes offered. The package ships no country data — pass the countries the app supports. */\n countries: PhoneCountry[];\n /** `code` of the selected country (controlled). */\n country?: string;\n /** Initially selected country (uncontrolled). Defaults to the first of `countries`. */\n defaultCountry?: string;\n /** Called with the `code` of the chosen country and its entry. */\n onCountryChange?: (code: string, country: PhoneCountry) => void;\n /** Accessible name of the calling-code dropdown. */\n countryLabel?: string;\n /** Whether the country list is open (controlled; Figma \"State=Open\"). */\n countryListOpen?: boolean;\n /** Called when the country list opens or closes. */\n onCountryListOpenChange?: (open: boolean) => void;\n /** Shows the search box at the top of the country list (Figma \"State=Open\"). Default `true`; `false` hides it for short lists. */\n searchable?: boolean;\n /** Placeholder and accessible name of that search box. Default \"Search country or code\". */\n searchPlaceholder?: string;\n /** Shown when the search matches no country. */\n emptyText?: ReactNode;\n /** Element the list is rendered into (default `document.body`). */\n portalContainer?: HTMLElement | null;\n}\n\n/**\n * Figma \"Drop down inputs / Type=Phone\" (\"Inputs / Style=Both-icon-drop-down\"): a calling-code dropdown next to a number input.\n * The country list is Figma \"State=Open\": a 280px menu with a search box and one row per country (flag, name, calling code).\n * The national number is a native `<input type=\"tel\">` (`value` / `onChange` / `name` as usual; the ref and extra props go to it);\n * the calling code is `country` / `onCountryChange`. `className` goes to the root.\n */\nexport const PhoneInput = /* @__PURE__ */ forwardRef<HTMLInputElement, PhoneInputProps>(function PhoneInput(\n {\n label,\n helperText,\n error,\n required,\n optional,\n size = 'md',\n countries,\n country,\n defaultCountry,\n onCountryChange,\n countryLabel = 'Country code',\n countryListOpen,\n onCountryListOpenChange,\n searchable = true,\n searchPlaceholder = 'Search country or code',\n emptyText,\n portalContainer,\n id,\n disabled,\n readOnly,\n className,\n style,\n 'aria-describedby': describedBy,\n 'aria-invalid': ariaInvalid,\n ...props\n },\n ref,\n) {\n const ids = useFieldIds(id, Boolean(error || helperText));\n const rowRef = useRef<HTMLDivElement>(null);\n const [internalCountry, setInternalCountry] = useState(defaultCountry ?? countries[0]?.code);\n const invalid = Boolean(error);\n const selected = country ?? internalCountry;\n\n const handleCountryChange = (code: string) => {\n if (country === undefined) setInternalCountry(code);\n const entry = countries.find((item) => item.code === code);\n if (entry) onCountryChange?.(code, entry);\n };\n\n return (\n <FormField\n ids={ids}\n label={label}\n helperText={helperText}\n error={error}\n required={required}\n optional={optional}\n size={size}\n className={cn('tm-phone-input', className)}\n style={style}\n role=\"group\"\n aria-labelledby={label ? ids.labelId : undefined}\n >\n <div ref={rowRef} className=\"tm-phone-input__row\">\n {countries.length > 0 ? (\n <Select\n aria-label={countryLabel}\n className=\"tm-phone-input__country\"\n size={size}\n fullWidth={false}\n options={countries.map((item) => ({\n value: item.code,\n label: item.label,\n description: item.dialCode,\n icon: item.flag,\n // Type-ahead and search work on the country name first, then on the calling code.\n textValue: `${item.label} ${item.dialCode}`,\n }))}\n value={selected ?? null}\n onValueChange={handleCountryChange}\n open={countryListOpen}\n onOpenChange={onCountryListOpenChange}\n renderValue={(option) => (\n <span className=\"tm-phone-input__code\">\n {option.icon}\n {countries.find((item) => item.code === option.value)?.dialCode}\n </span>\n )}\n // Figma \"State=Open\": the menu starts at the left edge of the whole field and keeps M rows at every size.\n panelAnchor={rowRef}\n panelClassName=\"tm-phone-input__panel\"\n listSize=\"md\"\n invalid={invalid}\n disabled={disabled}\n readOnly={readOnly}\n searchable={searchable}\n searchPlaceholder={searchPlaceholder}\n emptyText={emptyText}\n portalContainer={portalContainer}\n />\n ) : null}\n <div\n className=\"tm-field tm-phone-input__number\"\n data-size={size}\n data-tm-icon-size={size}\n data-invalid={invalid ? '' : undefined}\n data-disabled={disabled ? '' : undefined}\n data-readonly={readOnly ? '' : undefined}\n onMouseDown={focusControlOnMouseDown}\n >\n <input\n ref={ref}\n id={ids.controlId}\n type=\"tel\"\n inputMode=\"tel\"\n autoComplete=\"tel-national\"\n className=\"tm-field__control\"\n disabled={disabled}\n readOnly={readOnly}\n required={required}\n aria-invalid={ariaInvalid ?? (invalid || undefined)}\n aria-describedby={cn(describedBy, ids.messageId) || undefined}\n {...props}\n />\n </div>\n </div>\n </FormField>\n );\n});\n"],"mappings":";;;;;;;;;AAmDA,IAAaA,IAA6B,kBAA8C,SACtF,EACE,UACA,eACA,UACA,aACA,aACA,UAAO,MACP,cACA,YACA,mBACA,oBACA,kBAAe,gBACf,oBACA,4BACA,gBAAa,IACb,uBAAoB,0BACpB,cACA,oBACA,OACA,aACA,aACA,cACA,UACA,oBAAoBC,GACpB,gBAAgBC,GAChB,GAAGC,KAEL,GACA;CACA,IAAMC,IAAMC,EAAYC,GAAI,GAAQC,KAASC,EAAW,GAClDC,IAASC,EAAuB,IAAI,GACpC,CAACC,GAAiBC,KAAsBC,EAASC,KAAkBC,EAAU,EAAE,EAAE,IAAI,GACrFC,IAAU,EAAQT,GAClBU,IAAWC,KAAWP;CAQ5B,OACE,kBAACQ,GAAD;EACO;EACE;EACK;EACL;EACG;EACA;EACJ;EACN,WAAWC,EAAG,kBAAkBC,CAAS;EAClC;EACP,MAAK;EACL,mBAAiBC,IAAQlB,EAAI,UAAU,KAAA;EAEvC,UAAA,kBAAC,OAAD;GAAK,KAAKK;GAAQ,WAAU;GAA5B,UAAA,CACGM,EAAU,SAAS,IAClB,kBAACQ,GAAD;IACE,cAAYC;IACZ,WAAU;IACJ;IACN,WAAW;IACX,SAAST,EAAU,KAAK,OAAU;KAChC,OAAOU,EAAK;KACZ,OAAOA,EAAK;KACZ,aAAaA,EAAK;KAClB,MAAMA,EAAK;KAEX,WAAW,GAAGA,EAAK,MAAM,GAAGA,EAAK;IACnC,EAAE;IACF,OAAOR,KAAY;IACnB,gBApCmB,MAAiB;KAC5C,AAAIC,MAAY,KAAA,KAAWN,EAAmBc,CAAI;KAClD,IAAMC,IAAQZ,EAAU,MAAM,MAASU,EAAK,SAASC,CAAI;KACzD,AAAIC,KAAOC,IAAkBF,GAAMC,CAAK;IAC1C;IAiCU,MAAME;IACN,cAAcC;IACd,cAAc,MACZ,kBAAC,QAAD;KAAM,WAAU;KAAhB,UAAA,CACGC,EAAO,MACPhB,EAAU,MAAM,MAASU,EAAK,SAASM,EAAO,KAAK,CAAC,EAAE,QACnD;;IAGR,aAAatB;IACb,gBAAe;IACf,UAAS;IACA;IACC;IACA;IACE;IACO;IACR;IACM;GAClB,CAAA,IACC,MACJ,kBAAC,OAAD;IACE,WAAU;IACV,aAAWuB;IACX,qBAAmBA;IACnB,gBAAchB,IAAU,KAAK,KAAA;IAC7B,iBAAeiB,IAAW,KAAK,KAAA;IAC/B,iBAAeC,IAAW,KAAK,KAAA;IAC/B,aAAaC;IAEb,UAAA,kBAAC,SAAD;KACO;KACL,IAAI/B,EAAI;KACR,MAAK;KACL,WAAU;KACV,cAAa;KACb,WAAU;KACA;KACA;KACA;KACV,gBAAcF,MAAgBc,KAAW,KAAA;KACzC,oBAAkBI,EAAGnB,GAAaG,EAAI,SAAS,KAAK,KAAA;KACpD,GAAID;IACL,CAAA;GACE,CAAA,CACF;;CACI,CAAA;AAEf,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../../utils/cn.cjs");;/* empty css */let t=require("react"),n=require("react/jsx-runtime");var r=(0,t.forwardRef)(function({audiences:r=[],value:i,defaultValue:a,onValueChange:o,tabsLabel:s,
|
|
1
|
+
"use client";const e=require("../../utils/cn.cjs");;/* empty css */let t=require("react"),n=require("react/jsx-runtime");var r=(0,t.forwardRef)(function({audiences:r=[],value:i,defaultValue:a,onValueChange:o,tabsLabel:s,compactTabs:c=!1,id:l,className:u,children:d,...f},p){let[m,h]=(0,t.useState)(a),g=i??m,_=r.find(e=>e.value===g)??r[0],v=(0,t.useId)(),y=l??v,b=r.length>1,x=e=>`${y}-tab-${e}`,S=e=>`${y}-panel-${e}`,C=e=>{e!==_&&(i===void 0&&h(e.value),o?.(e.value))},w=e=>{let t=Array.from(e.currentTarget.querySelectorAll(`[role="tab"]`)),n=t.indexOf(document.activeElement);if(n===-1)return;let i=getComputedStyle(e.currentTarget).direction===`rtl`?-1:1,a;if(e.key===`ArrowRight`)a=n+i;else if(e.key===`ArrowLeft`)a=n-i;else if(e.key===`Home`)a=0;else if(e.key===`End`)a=t.length-1;else return;e.preventDefault(),a=(a+t.length)%t.length,t[a].focus(),C(r[a])};return(0,n.jsxs)(`div`,{ref:p,id:l,className:e.cn(`tm-popular-questions`,u),"data-compact-tabs":c?``:void 0,...f,children:[b?(0,n.jsx)(`div`,{className:`tm-popular-questions__tabs`,role:`tablist`,"aria-label":s,onKeyDown:w,children:r.map((e,t)=>{let r=e===_;return(0,n.jsxs)(`button`,{type:`button`,role:`tab`,id:x(t),className:`tm-popular-questions__tab`,"data-tm-icon-size":`sm`,"aria-selected":r,"aria-controls":r||e.questions!==void 0?S(t):void 0,tabIndex:r?0:-1,onClick:()=>C(e),children:[e.icon,e.label]},e.value)})}):null,b?r.map((e,t)=>{let r=e===_;return!r&&e.questions===void 0?null:(0,n.jsx)(`div`,{id:S(t),className:`tm-popular-questions__list`,role:`tabpanel`,"aria-labelledby":x(t),hidden:!r,children:e.questions??d},e.value)}):(0,n.jsx)(`div`,{className:`tm-popular-questions__list`,children:_?.questions??d})]})});exports.PopularQuestions=r;
|
|
2
2
|
//# sourceMappingURL=PopularQuestions.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopularQuestions.cjs","names":["useState","useId","cn","require_cn","react","react_jsx_runtime","PopularQuestions","props","uncontrolled","setUncontrolled","defaultValue","requested","value","active","audiences","audience","autoId","baseId","id","hasTabs","tabId","index","panelId","select","onValueChange","handleKeyDown","tabs","event","forward","next","className","tabsLabel","selected","children"],"sources":["../../../src/components/PopularQuestions/PopularQuestions.tsx"],"sourcesContent":["import { forwardRef, useId, useState, type HTMLAttributes, type KeyboardEvent, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport './PopularQuestions.css';\n\nexport interface PopularQuestionsAudience {\n /** Identifies the audience, e.g. `\"travellers\"`. */\n value: string;\n /** Tab text, e.g. \"Travellers\". */\n label: ReactNode;\n /** Optional 16px icon before the label (Figma: plane · briefcase). */\n icon?: ReactNode;\n /**\n * The question cards of this audience (`HelpQuestionCard`s). Audiences that carry their cards stay in the page\n * while their tab is not selected (hidden), so the block works uncontrolled and from Server Components.\n */\n questions?: ReactNode;\n}\n\nexport interface PopularQuestionsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {\n /** The tabs of the segmented control (Figma \"Audience\": Travellers · Agencies). With fewer than two there is no control. */\n audiences?: PopularQuestionsAudience[];\n /** Controlled value: the `value` of the selected audience. */\n value?: string;\n /** Initial audience of an uncontrolled block. Defaults to the first one. */\n defaultValue?: string;\n /** Called with the `value` of the audience the user switched to. */\n onValueChange?: (value: string) => void;\n /** Accessible name of the tab list, e.g. \"Audience\". */\n tabsLabel?: string;\n /** Question cards of the selected audience, for when the app owns the list (used when the audience has no `questions`). */\n children?: ReactNode;\n}\n\n/**\n * Help-centre block (Figma component set \"Help / Popular questions\"): a segmented control that switches the audience\n * and a two-column grid of question cards, one column on small screens. The control is a tab list\n * (arrow keys, Home and End switch tabs).\n */\nexport const PopularQuestions = /* @__PURE__ */ forwardRef<HTMLDivElement, PopularQuestionsProps>(function PopularQuestions(\n { audiences = [], value, defaultValue, onValueChange, tabsLabel, id, className, children, ...props },\n ref,\n) {\n const [uncontrolled, setUncontrolled] = useState(defaultValue);\n const requested = value ?? uncontrolled;\n // Fall back to the first audience when nothing (or something unknown) is selected.\n const active = audiences.find((audience) => audience.value === requested) ?? audiences[0];\n const autoId = useId();\n const baseId = id ?? autoId;\n const hasTabs = audiences.length > 1;\n const tabId = (index: number) => `${baseId}-tab-${index}`;\n const panelId = (index: number) => `${baseId}-panel-${index}`;\n\n const select = (audience: PopularQuestionsAudience) => {\n if (audience === active) return;\n if (value === undefined) setUncontrolled(audience.value);\n onValueChange?.(audience.value);\n };\n\n // Tabs keyboard model with automatic activation: arrows / Home / End move focus and select.\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const tabs = Array.from(event.currentTarget.querySelectorAll<HTMLButtonElement>('[role=\"tab\"]'));\n const index = tabs.indexOf(document.activeElement as HTMLButtonElement);\n if (index === -1) return;\n const forward = getComputedStyle(event.currentTarget).direction === 'rtl' ? -1 : 1;\n let next: number;\n if (event.key === 'ArrowRight') next = index + forward;\n else if (event.key === 'ArrowLeft') next = index - forward;\n else if (event.key === 'Home') next = 0;\n else if (event.key === 'End') next = tabs.length - 1;\n else return;\n event.preventDefault();\n next = (next + tabs.length) % tabs.length;\n tabs[next].focus();\n select(audiences[next]);\n };\n\n return (\n <div ref={ref} id={id} className={cn('tm-popular-questions', className)} {...props}>\n {hasTabs ? (\n <div className=\"tm-popular-questions__tabs\" role=\"tablist\" aria-label={tabsLabel} onKeyDown={handleKeyDown}>\n {audiences.map((audience, index) => {\n const selected = audience === active;\n return (\n <button\n key={audience.value}\n type=\"button\"\n role=\"tab\"\n id={tabId(index)}\n className=\"tm-popular-questions__tab\"\n data-tm-icon-size=\"sm\"\n aria-selected={selected}\n aria-controls={selected || audience.questions !== undefined ? panelId(index) : undefined}\n tabIndex={selected ? 0 : -1}\n onClick={() => select(audience)}\n >\n {audience.icon}\n {audience.label}\n </button>\n );\n })}\n </div>\n ) : null}\n {hasTabs ? (\n audiences.map((audience, index) => {\n const selected = audience === active;\n if (!selected && audience.questions === undefined) return null;\n return (\n <div key={audience.value} id={panelId(index)} className=\"tm-popular-questions__list\" role=\"tabpanel\" aria-labelledby={tabId(index)} hidden={!selected}>\n {audience.questions ?? children}\n </div>\n );\n })\n ) : (\n <div className=\"tm-popular-questions__list\">{active?.questions ?? children}</div>\n )}\n </div>\n );\n});\n"],"mappings":"A,+
|
|
1
|
+
{"version":3,"file":"PopularQuestions.cjs","names":["useState","useId","cn","require_cn","react","react_jsx_runtime","PopularQuestions","props","uncontrolled","setUncontrolled","defaultValue","requested","value","active","audiences","audience","autoId","baseId","id","hasTabs","tabId","index","panelId","select","onValueChange","handleKeyDown","tabs","event","forward","next","className","compactTabs","tabsLabel","selected","children"],"sources":["../../../src/components/PopularQuestions/PopularQuestions.tsx"],"sourcesContent":["import { forwardRef, useId, useState, type HTMLAttributes, type KeyboardEvent, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport './PopularQuestions.css';\n\nexport interface PopularQuestionsAudience {\n /** Identifies the audience, e.g. `\"travellers\"`. */\n value: string;\n /** Tab text, e.g. \"Travellers\". */\n label: ReactNode;\n /** Optional 16px icon before the label (Figma: plane · briefcase). */\n icon?: ReactNode;\n /**\n * The question cards of this audience (`HelpQuestionCard`s). Audiences that carry their cards stay in the page\n * while their tab is not selected (hidden), so the block works uncontrolled and from Server Components.\n */\n questions?: ReactNode;\n}\n\nexport interface PopularQuestionsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {\n /** The tabs of the segmented control (Figma \"Audience\": Travellers · Agencies). With fewer than two there is no control. */\n audiences?: PopularQuestionsAudience[];\n /** Controlled value: the `value` of the selected audience. */\n value?: string;\n /** Initial audience of an uncontrolled block. Defaults to the first one. */\n defaultValue?: string;\n /** Called with the `value` of the audience the user switched to. */\n onValueChange?: (value: string) => void;\n /** Accessible name of the tab list, e.g. \"Audience\". */\n tabsLabel?: string;\n /**\n * On phones (viewports under 768px, the Mobile mode of the tokens) the tabs shrink to their labels with 12px side\n * padding instead of Figma's 180px / spacing/lg tabs, so longer labels (Armenian, Russian) fit a 370px control\n * without scrolling. Not in the Figma component; wider screens are unchanged.\n */\n compactTabs?: boolean;\n /** Question cards of the selected audience, for when the app owns the list (used when the audience has no `questions`). */\n children?: ReactNode;\n}\n\n/**\n * Help-centre block (Figma component set \"Help / Popular questions\"): a segmented control that switches the audience\n * and a two-column grid of question cards, one column on small screens. The control is a tab list\n * (arrow keys, Home and End switch tabs).\n */\nexport const PopularQuestions = /* @__PURE__ */ forwardRef<HTMLDivElement, PopularQuestionsProps>(function PopularQuestions(\n { audiences = [], value, defaultValue, onValueChange, tabsLabel, compactTabs = false, id, className, children, ...props },\n ref,\n) {\n const [uncontrolled, setUncontrolled] = useState(defaultValue);\n const requested = value ?? uncontrolled;\n // Fall back to the first audience when nothing (or something unknown) is selected.\n const active = audiences.find((audience) => audience.value === requested) ?? audiences[0];\n const autoId = useId();\n const baseId = id ?? autoId;\n const hasTabs = audiences.length > 1;\n const tabId = (index: number) => `${baseId}-tab-${index}`;\n const panelId = (index: number) => `${baseId}-panel-${index}`;\n\n const select = (audience: PopularQuestionsAudience) => {\n if (audience === active) return;\n if (value === undefined) setUncontrolled(audience.value);\n onValueChange?.(audience.value);\n };\n\n // Tabs keyboard model with automatic activation: arrows / Home / End move focus and select.\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const tabs = Array.from(event.currentTarget.querySelectorAll<HTMLButtonElement>('[role=\"tab\"]'));\n const index = tabs.indexOf(document.activeElement as HTMLButtonElement);\n if (index === -1) return;\n const forward = getComputedStyle(event.currentTarget).direction === 'rtl' ? -1 : 1;\n let next: number;\n if (event.key === 'ArrowRight') next = index + forward;\n else if (event.key === 'ArrowLeft') next = index - forward;\n else if (event.key === 'Home') next = 0;\n else if (event.key === 'End') next = tabs.length - 1;\n else return;\n event.preventDefault();\n next = (next + tabs.length) % tabs.length;\n tabs[next].focus();\n select(audiences[next]);\n };\n\n return (\n <div ref={ref} id={id} className={cn('tm-popular-questions', className)} data-compact-tabs={compactTabs ? '' : undefined} {...props}>\n {hasTabs ? (\n <div className=\"tm-popular-questions__tabs\" role=\"tablist\" aria-label={tabsLabel} onKeyDown={handleKeyDown}>\n {audiences.map((audience, index) => {\n const selected = audience === active;\n return (\n <button\n key={audience.value}\n type=\"button\"\n role=\"tab\"\n id={tabId(index)}\n className=\"tm-popular-questions__tab\"\n data-tm-icon-size=\"sm\"\n aria-selected={selected}\n aria-controls={selected || audience.questions !== undefined ? panelId(index) : undefined}\n tabIndex={selected ? 0 : -1}\n onClick={() => select(audience)}\n >\n {audience.icon}\n {audience.label}\n </button>\n );\n })}\n </div>\n ) : null}\n {hasTabs ? (\n audiences.map((audience, index) => {\n const selected = audience === active;\n if (!selected && audience.questions === undefined) return null;\n return (\n <div key={audience.value} id={panelId(index)} className=\"tm-popular-questions__list\" role=\"tabpanel\" aria-labelledby={tabId(index)} hidden={!selected}>\n {audience.questions ?? children}\n </div>\n );\n })\n ) : (\n <div className=\"tm-popular-questions__list\">{active?.questions ?? children}</div>\n )}\n </div>\n );\n});\n"],"mappings":"A,+IA4CA,IAAaM,GAAmC,EAAAF,EAAA,WAAA,CAAkD,SAChG,CAAE,YAAY,CAAC,EAAG,QAAO,eAAc,gBAAe,YAAW,cAAc,GAAO,KAAI,YAAW,WAAU,GAAGG,GAClH,EACA,CACA,GAAM,CAACC,EAAcC,IAAA,EAAmBT,EAAAA,SAAAA,CAASU,CAAY,EACvDC,EAAYC,GAASJ,EAErBK,EAASC,EAAU,KAAM,GAAaC,EAAS,QAAUJ,CAAS,GAAKG,EAAU,GACjFE,GAAA,EAASf,EAAAA,MAAAA,CAAM,EACfgB,EAASC,GAAMF,EACfG,EAAUL,EAAU,OAAS,EAC7BM,EAAS,GAAkB,GAAGH,EAAO,OAAOI,IAC5CC,EAAW,GAAkB,GAAGL,EAAO,SAASI,IAEhDE,EAAU,GAAuC,CACjDR,IAAaF,IACbD,IAAU,IAAA,IAAWH,EAAgBM,EAAS,KAAK,EACvDS,IAAgBT,EAAS,KAAK,EAChC,EAGMU,EAAiB,GAAyC,CAC9D,IAAMC,EAAO,MAAM,KAAKC,EAAM,cAAc,iBAAoC,cAAc,CAAC,EACzFN,EAAQK,EAAK,QAAQ,SAAS,aAAkC,EACtE,GAAIL,IAAU,GAAI,OAClB,IAAMO,EAAU,iBAAiBD,EAAM,aAAa,CAAC,CAAC,YAAc,MAAQ,GAAK,EAC7EE,EACJ,GAAIF,EAAM,MAAQ,aAAc,EAAON,EAAQO,OAC1C,GAAID,EA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KnB,EAAS,KAEd,CAET,CAAC,GAED,EAAAV,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,6BAA8B,SAAAQ,GAAQ,WAAaqB,CAAc,CAAA,CAE/E,C,EAET,CAAC,E"}
|
|
@@ -4,10 +4,10 @@ import { cn as e } from "../../utils/cn.js";
|
|
|
4
4
|
import { forwardRef as t, useId as n, useState as r } from "react";
|
|
5
5
|
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
6
6
|
// src/components/PopularQuestions/PopularQuestions.tsx
|
|
7
|
-
var o = /* @__PURE__ */ t(function({ audiences: t = [], value: o, defaultValue: s, onValueChange: c, tabsLabel: l,
|
|
8
|
-
let [
|
|
9
|
-
e !==
|
|
10
|
-
},
|
|
7
|
+
var o = /* @__PURE__ */ t(function({ audiences: t = [], value: o, defaultValue: s, onValueChange: c, tabsLabel: l, compactTabs: u = !1, id: d, className: f, children: p, ...m }, h) {
|
|
8
|
+
let [g, _] = r(s), v = o ?? g, y = t.find((e) => e.value === v) ?? t[0], b = n(), x = d ?? b, S = t.length > 1, C = (e) => `${x}-tab-${e}`, w = (e) => `${x}-panel-${e}`, T = (e) => {
|
|
9
|
+
e !== y && (o === void 0 && _(e.value), c?.(e.value));
|
|
10
|
+
}, E = (e) => {
|
|
11
11
|
let n = Array.from(e.currentTarget.querySelectorAll("[role=\"tab\"]")), r = n.indexOf(document.activeElement);
|
|
12
12
|
if (r === -1) return;
|
|
13
13
|
let i = getComputedStyle(e.currentTarget).direction === "rtl" ? -1 : 1, a;
|
|
@@ -16,46 +16,47 @@ var o = /* @__PURE__ */ t(function({ audiences: t = [], value: o, defaultValue:
|
|
|
16
16
|
else if (e.key === "Home") a = 0;
|
|
17
17
|
else if (e.key === "End") a = n.length - 1;
|
|
18
18
|
else return;
|
|
19
|
-
e.preventDefault(), a = (a + n.length) % n.length, n[a].focus(),
|
|
19
|
+
e.preventDefault(), a = (a + n.length) % n.length, n[a].focus(), T(t[a]);
|
|
20
20
|
};
|
|
21
21
|
return /* @__PURE__ */ a("div", {
|
|
22
|
-
ref:
|
|
23
|
-
id:
|
|
24
|
-
className: e("tm-popular-questions",
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
ref: h,
|
|
23
|
+
id: d,
|
|
24
|
+
className: e("tm-popular-questions", f),
|
|
25
|
+
"data-compact-tabs": u ? "" : void 0,
|
|
26
|
+
...m,
|
|
27
|
+
children: [S ? /* @__PURE__ */ i("div", {
|
|
27
28
|
className: "tm-popular-questions__tabs",
|
|
28
29
|
role: "tablist",
|
|
29
30
|
"aria-label": l,
|
|
30
|
-
onKeyDown:
|
|
31
|
+
onKeyDown: E,
|
|
31
32
|
children: t.map((e, t) => {
|
|
32
|
-
let n = e ===
|
|
33
|
+
let n = e === y;
|
|
33
34
|
return /* @__PURE__ */ a("button", {
|
|
34
35
|
type: "button",
|
|
35
36
|
role: "tab",
|
|
36
|
-
id:
|
|
37
|
+
id: C(t),
|
|
37
38
|
className: "tm-popular-questions__tab",
|
|
38
39
|
"data-tm-icon-size": "sm",
|
|
39
40
|
"aria-selected": n,
|
|
40
|
-
"aria-controls": n || e.questions !== void 0 ?
|
|
41
|
+
"aria-controls": n || e.questions !== void 0 ? w(t) : void 0,
|
|
41
42
|
tabIndex: n ? 0 : -1,
|
|
42
|
-
onClick: () =>
|
|
43
|
+
onClick: () => T(e),
|
|
43
44
|
children: [e.icon, e.label]
|
|
44
45
|
}, e.value);
|
|
45
46
|
})
|
|
46
|
-
}) : null,
|
|
47
|
-
let n = e ===
|
|
47
|
+
}) : null, S ? t.map((e, t) => {
|
|
48
|
+
let n = e === y;
|
|
48
49
|
return !n && e.questions === void 0 ? null : /* @__PURE__ */ i("div", {
|
|
49
|
-
id:
|
|
50
|
+
id: w(t),
|
|
50
51
|
className: "tm-popular-questions__list",
|
|
51
52
|
role: "tabpanel",
|
|
52
|
-
"aria-labelledby":
|
|
53
|
+
"aria-labelledby": C(t),
|
|
53
54
|
hidden: !n,
|
|
54
|
-
children: e.questions ??
|
|
55
|
+
children: e.questions ?? p
|
|
55
56
|
}, e.value);
|
|
56
57
|
}) : /* @__PURE__ */ i("div", {
|
|
57
58
|
className: "tm-popular-questions__list",
|
|
58
|
-
children:
|
|
59
|
+
children: y?.questions ?? p
|
|
59
60
|
})]
|
|
60
61
|
});
|
|
61
62
|
});
|