@allxsmith/bestax-bulma 5.53.0 → 5.54.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/esm/components/Avatars.js +7 -2
- package/dist/esm/components/Avatars.js.map +1 -1
- package/dist/esm/components/Badge.js +7 -2
- package/dist/esm/components/Badge.js.map +1 -1
- package/dist/esm/components/Command.js +19 -9
- package/dist/esm/components/Command.js.map +1 -1
- package/dist/esm/components/Pagination.js +9 -1
- package/dist/esm/components/Pagination.js.map +1 -1
- package/dist/esm/components/Steps.js +5 -1
- package/dist/esm/components/Steps.js.map +1 -1
- package/dist/esm/elements/RingProgress.js +6 -1
- package/dist/esm/elements/RingProgress.js.map +1 -1
- package/dist/esm/form/Autocomplete.js +4 -0
- package/dist/esm/form/Autocomplete.js.map +1 -1
- package/dist/esm/form/Combobox.js +7 -2
- package/dist/esm/form/Combobox.js.map +1 -1
- package/dist/esm/form/File.js +4 -1
- package/dist/esm/form/File.js.map +1 -1
- package/dist/esm/form/Rate.js +9 -1
- package/dist/esm/form/Rate.js.map +1 -1
- package/dist/esm/form/Slider.js +7 -4
- package/dist/esm/form/Slider.js.map +1 -1
- package/dist/esm/form/Taginput.js +9 -3
- package/dist/esm/form/Taginput.js.map +1 -1
- package/dist/esm/helpers/LocaleProvider.js +9 -6
- package/dist/esm/helpers/LocaleProvider.js.map +1 -1
- package/dist/esm/helpers/localeFormat.js +108 -0
- package/dist/esm/helpers/localeFormat.js.map +1 -0
- package/dist/index.cjs +435 -276
- package/dist/index.cjs.map +1 -1
- package/dist/types/components/Avatars.d.ts +1 -1
- package/dist/types/components/Badge.d.ts +1 -1
- package/dist/types/components/Command.d.ts +4 -2
- package/dist/types/components/Pagination.d.ts +3 -0
- package/dist/types/components/Steps.d.ts +4 -1
- package/dist/types/elements/RingProgress.d.ts +3 -2
- package/dist/types/form/Autocomplete.d.ts +6 -1
- package/dist/types/form/Combobox.d.ts +3 -2
- package/dist/types/form/File.d.ts +2 -1
- package/dist/types/form/Rate.d.ts +4 -1
- package/dist/types/form/Slider.d.ts +9 -2
- package/dist/types/form/Taginput.d.ts +8 -2
- package/dist/types/helpers/LocaleProvider.d.ts +9 -6
- package/dist/types/helpers/localeFormat.d.ts +26 -0
- package/dist/types-cjs/components/Avatars.d.ts +1 -1
- package/dist/types-cjs/components/Badge.d.ts +1 -1
- package/dist/types-cjs/components/Command.d.ts +4 -2
- package/dist/types-cjs/components/Pagination.d.ts +3 -0
- package/dist/types-cjs/components/Steps.d.ts +4 -1
- package/dist/types-cjs/elements/RingProgress.d.ts +3 -2
- package/dist/types-cjs/form/Autocomplete.d.ts +6 -1
- package/dist/types-cjs/form/Combobox.d.ts +3 -2
- package/dist/types-cjs/form/File.d.ts +2 -1
- package/dist/types-cjs/form/Rate.d.ts +4 -1
- package/dist/types-cjs/form/Slider.d.ts +9 -2
- package/dist/types-cjs/form/Taginput.d.ts +8 -2
- package/dist/types-cjs/helpers/LocaleProvider.d.ts +9 -6
- package/dist/types-cjs/helpers/localeFormat.d.ts +26 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.js","sources":["../../../src/components/Pagination.tsx"],"sourcesContent":["import React from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport {\n useBulmaClasses,\n BulmaClassesProps,\n validColors,\n} from '../helpers/useBulmaClasses';\nimport { warnDeprecatedColorProp } from '../helpers/colorDeprecations';\n\n/**\n * Props for the Pagination component.\n */\nexport interface PaginationProps\n extends\n React.HTMLAttributes<HTMLElement>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /**\n * Color modifier for the pagination (renders `is-<color>`).\n *\n * Bulma ships no pagination color CSS, so this prop has never had a visual\n * effect for any value. Passing it logs a console warning in development.\n * Use `textColor` / `bgColor` instead.\n * @deprecated No `.pagination.is-<color>` CSS exists; the prop renders\n * unstyled and will be removed in the next major version.\n */\n color?:\n | 'primary'\n | 'link'\n | 'info'\n | 'success'\n | 'warning'\n | 'danger'\n | 'black'\n | 'dark'\n | 'light'\n | 'white';\n /** Text color helper. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Background color helper. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Size modifier for the pagination. */\n size?: 'small' | 'medium' | 'large';\n /** Alignment for the pagination. */\n align?: 'centered' | 'right';\n /** Renders pagination with rounded corners. */\n rounded?: boolean;\n /**\n * The number of pages. Given `total` and no children, `Pagination` renders\n * the whole control itself: Previous, Next and a link for each page it\n * shows, with an ellipsis where it skips some. Given children, it renders\n * those as they are, and `total` and the other page props do nothing.\n */\n total?: number;\n /**\n * The page shown as current, counting from 1, when rendering from `total`.\n * Leave it out and `Pagination` keeps the page itself, starting at 1.\n */\n current?: number;\n /**\n * Called with the page chosen, when rendering from `total`. Choosing the\n * page already current doesn't call it.\n */\n onPageChange?: (page: number) => void;\n /** How many pages to show on each side of the current one, when rendering from `total`. */\n siblingCount?: number;\n /** How many pages to always show at the start and at the end, when rendering from `total`. */\n boundaryCount?: number;\n /** The Previous link's content, when rendering from `total`. */\n previousLabel?: React.ReactNode;\n /** The Next link's content, when rendering from `total`. */\n nextLabel?: React.ReactNode;\n /** Disables every link, when rendering from `total`. */\n disabled?: boolean;\n /**\n * The `href` for a page's link, when rendering from `total`, making each\n * one a real link (`page => '?page=' + page`). A click then calls\n * `onPageChange` and the browser follows the link too. Without it the\n * links have no `href`, act as buttons, and Enter or Space chooses a page.\n */\n getPageHref?: (page: number) => string;\n /**\n * The accessible name of a page's link, when rendering from `total`, since\n * its content is only the number (`page => 'Page ' + page` by default).\n */\n getPageLabel?: (page: number) => string;\n /** Additional CSS classes. */\n className?: string;\n /** Custom pagination content (usually subcomponents). */\n children?: React.ReactNode;\n}\n\n/** A page's number, or a run of pages left out. */\ntype PageItem = number | 'start-gap' | 'end-gap';\n\n/** A count read as a whole number from zero, or `fallback` when it's no number. */\nfunction whole(count: number, fallback: number): number {\n return Number.isFinite(count) ? Math.max(Math.floor(count), 0) : fallback;\n}\n\nfunction range(from: number, to: number): number[] {\n return Array.from({ length: Math.max(to - from + 1, 0) }, (_, i) => from + i);\n}\n\n/**\n * The pages to show for `current` of `total`: the first and last\n * `boundaries`, `siblings` on each side of the current one, and a gap for\n * each run left out. A gap of a single page shows that page instead, and the\n * window around the current page slides inward near either end, so the row\n * keeps its length as the page moves.\n */\nfunction pageItems(\n total: number,\n current: number,\n siblings: number,\n boundaries: number\n): PageItem[] {\n const windowSize = siblings * 2 + 1;\n // Every page fits in the room the boundary pages, the window and two gaps take.\n if (total <= boundaries * 2 + windowSize + 2) return range(1, total);\n const lowest = boundaries + 2;\n const highest = total - boundaries - 1;\n const start = Math.min(\n Math.max(current - siblings, lowest),\n highest - windowSize + 1\n );\n const end = start + windowSize - 1;\n const gap = (from: number, to: number, name: PageItem): PageItem[] =>\n to === from ? [from] : [name];\n return [\n ...range(1, boundaries),\n ...gap(boundaries + 1, start - 1, 'start-gap'),\n ...range(start, end),\n ...gap(end + 1, total - boundaries, 'end-gap'),\n ...range(total - boundaries + 1, total),\n ];\n}\n\n/**\n * Props for PaginationPrevious and PaginationNext components.\n */\nexport interface PaginationPreviousNextProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n /** Additional CSS classes. */\n className?: string;\n /** Whether previous/next is disabled. */\n disabled?: boolean;\n /** Button content. */\n children?: React.ReactNode;\n}\n\n/**\n * \"Previous\" navigation button.\n *\n * @function\n * @param {PaginationPreviousNextProps} props - Props for the PaginationPrevious component.\n * @returns {JSX.Element} The rendered previous button.\n */\nexport const PaginationPrevious: React.FC<PaginationPreviousNextProps> = ({\n className,\n disabled,\n children,\n ...props\n}) => (\n <a\n className={classNames(\n usePrefixedClassNames('pagination-previous', {\n 'is-disabled': disabled,\n }),\n className\n )}\n aria-disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n {...props}\n onClick={\n disabled\n ? e => {\n e.preventDefault();\n e.stopPropagation();\n }\n : props.onClick\n }\n >\n {children}\n </a>\n);\n\n/**\n * \"Next\" navigation button.\n *\n * @function\n * @param {PaginationPreviousNextProps} props - Props for the PaginationNext component.\n * @returns {JSX.Element} The rendered next button.\n */\nexport const PaginationNext: React.FC<PaginationPreviousNextProps> = ({\n className,\n disabled,\n children,\n ...props\n}) => (\n <a\n className={classNames(\n usePrefixedClassNames('pagination-next', { 'is-disabled': disabled }),\n className\n )}\n aria-disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n {...props}\n onClick={\n disabled\n ? e => {\n e.preventDefault();\n e.stopPropagation();\n }\n : props.onClick\n }\n >\n {children}\n </a>\n);\n\n/**\n * The `Pagination` component provides a flexible, composable Bulma pagination navigation for your Bulma React UI.\n *\n * @function\n * @param {PaginationProps} props - Props for the Pagination component.\n * @returns {JSX.Element} The rendered pagination.\n * @see {@link https://bulma.io/documentation/components/pagination/ | Bulma Pagination documentation}\n */\nconst PaginationComponent: React.FC<PaginationProps> = ({\n color,\n textColor,\n bgColor,\n size,\n align,\n rounded,\n total,\n current,\n onPageChange,\n siblingCount = 1,\n boundaryCount = 1,\n previousLabel = 'Previous',\n nextLabel = 'Next',\n disabled,\n getPageHref,\n getPageLabel,\n className,\n children,\n ...props\n}) => {\n const [kept, setKept] = React.useState(1);\n warnDeprecatedColorProp(\n 'Pagination',\n color,\n 'Use the textColor / bgColor helper props instead.'\n );\n\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor,\n backgroundColor: bgColor,\n ...props,\n });\n\n // Generate Bulma classes with prefix\n const bulmaClasses = usePrefixedClassNames('pagination', {\n [`is-${color}`]: color,\n [`is-${size}`]: size,\n [`is-${align}`]: align,\n 'is-rounded': rounded,\n });\n\n const paginationClasses = classNames(\n bulmaClasses,\n bulmaHelperClasses,\n className\n );\n\n // A child that renders nothing (`{show && …}` when false) is no children.\n const fromTotal =\n total !== undefined && React.Children.toArray(children).length === 0;\n let content: React.ReactNode = children;\n if (fromTotal) {\n const pages = Number.isFinite(total) ? Math.max(Math.floor(total), 0) : 0;\n // A current page that's no number reads as the first.\n const page = Math.min(\n Math.max(whole(current ?? kept, 1), 1),\n Math.max(pages, 1)\n );\n const choose = (next: number) => {\n if (next === page) return;\n if (current === undefined) setKept(next);\n onPageChange?.(next);\n };\n /**\n * What a link to `target` is given, beside what it renders. With no\n * `getPageHref` it's a button; a link that's `off` goes nowhere.\n */\n const linkTo = (target: number, off: boolean) => ({\n href: off || !getPageHref ? undefined : getPageHref(target),\n role: getPageHref ? undefined : 'button',\n // A link that's off is disabled too, and the parts drop its clicks.\n onClick: () => choose(target),\n onKeyDown: getPageHref\n ? undefined\n : (e: React.KeyboardEvent<HTMLAnchorElement>) => {\n if (off || (e.key !== 'Enter' && e.key !== ' ')) return;\n e.preventDefault();\n choose(target);\n },\n });\n const atStart = disabled || page <= 1;\n const atEnd = disabled || page >= pages;\n content = (\n <>\n <PaginationPrevious disabled={atStart} {...linkTo(page - 1, atStart)}>\n {previousLabel}\n </PaginationPrevious>\n <PaginationNext disabled={atEnd} {...linkTo(page + 1, atEnd)}>\n {nextLabel}\n </PaginationNext>\n <PaginationList>\n {pageItems(\n pages,\n page,\n whole(siblingCount, 1),\n whole(boundaryCount, 1)\n ).map(item =>\n typeof item === 'number' ? (\n <PaginationLink\n key={item}\n aria-label={getPageLabel ? getPageLabel(item) : `Page ${item}`}\n active={item === page}\n disabled={disabled}\n {...linkTo(item, Boolean(disabled))}\n >\n {item}\n </PaginationLink>\n ) : (\n <PaginationEllipsis key={item} />\n )\n )}\n </PaginationList>\n </>\n );\n }\n\n return (\n <nav\n className={paginationClasses}\n role=\"navigation\"\n aria-label=\"pagination\"\n {...rest}\n >\n {content}\n </nav>\n );\n};\n\n/**\n * Props for the PaginationList component.\n */\nexport interface PaginationListProps\n extends\n React.HTMLAttributes<HTMLUListElement>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Additional CSS classes. */\n className?: string;\n /** Text color for the list. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Bulma color modifier for the list. */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Background color for the list. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** List items. */\n children?: React.ReactNode;\n}\n\n/**\n * Container for page links and ellipsis.\n *\n * @function\n * @param {PaginationListProps} props - Props for the PaginationList component.\n * @returns {JSX.Element} The rendered pagination list.\n */\nexport const PaginationList: React.FC<PaginationListProps> = ({\n className,\n textColor,\n bgColor,\n children,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor,\n backgroundColor: bgColor,\n ...props,\n });\n return (\n <ul\n className={classNames(\n usePrefixedClassNames('pagination-list'),\n bulmaHelperClasses,\n className\n )}\n {...rest}\n >\n {children}\n </ul>\n );\n};\n\n/**\n * Props for the PaginationLink component.\n */\nexport interface PaginationLinkProps\n extends\n React.AnchorHTMLAttributes<HTMLAnchorElement>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Additional CSS classes. */\n className?: string;\n /** Bulma color modifier. */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Text color. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Background color. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Whether the link is for the current page. */\n active?: boolean;\n /** Whether the link is disabled. */\n disabled?: boolean;\n /** Link content. */\n children?: React.ReactNode;\n}\n\n/**\n * Page number or navigation link.\n *\n * @function\n * @param {PaginationLinkProps} props - Props for the PaginationLink component.\n * @returns {JSX.Element} The rendered pagination link.\n */\nexport const PaginationLink: React.FC<PaginationLinkProps> = ({\n className,\n textColor,\n bgColor,\n active,\n disabled,\n onClick,\n children,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor,\n backgroundColor: bgColor,\n ...props,\n });\n\n const handleClick = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {\n if (disabled) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n if (onClick) {\n onClick(e);\n }\n };\n\n return (\n <li>\n <a\n className={classNames(\n usePrefixedClassNames('pagination-link', {\n 'is-current': active,\n 'is-disabled': disabled,\n }),\n bulmaHelperClasses,\n className\n )}\n aria-current={active ? 'page' : undefined}\n aria-disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n onClick={handleClick}\n {...rest}\n >\n {children}\n </a>\n </li>\n );\n};\n\n/**\n * Ellipsis separator.\n *\n * @function\n * @param {React.LiHTMLAttributes<HTMLLIElement>} props - Standard li props.\n * @returns {JSX.Element} The rendered ellipsis.\n */\nexport const PaginationEllipsis: React.FC<\n React.LiHTMLAttributes<HTMLLIElement>\n> = props => (\n <li>\n <span className={usePrefixedClassNames('pagination-ellipsis')} {...props}>\n …\n </span>\n </li>\n);\n\nexport const Pagination = withSubComponents(\n PaginationComponent,\n {\n Link: PaginationLink,\n List: PaginationList,\n Ellipsis: PaginationEllipsis,\n Previous: PaginationPrevious,\n Next: PaginationNext,\n },\n 'Pagination'\n);\n\nexport default Pagination;\n"],"names":["_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;;AA+FA;AACA,SAAS,KAAK,CAAC,KAAa,EAAE,QAAgB,EAAA;IAC5C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ;AAC3E;AAEA,SAAS,KAAK,CAAC,IAAY,EAAE,EAAU,EAAA;AACrC,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;AAC/E;AAEA;;;;;;AAMG;AACH,SAAS,S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,EACnB;AACE,IAAA,IAAI,EAAE,cAAc;AACpB,IAAA,IAAI,EAAE,cAAc;AACpB,IAAA,QAAQ,EAAE,kBAAkB;AAC5B,IAAA,QAAQ,EAAE,kBAAkB;AAC5B,IAAA,IAAI,EAAE,cAAc;CACrB,EACD,YAAY;;"}
|
|
1
|
+
{"version":3,"file":"Pagination.js","sources":["../../../src/components/Pagination.tsx"],"sourcesContent":["import React from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport {\n useBulmaClasses,\n BulmaClassesProps,\n validColors,\n} from '../helpers/useBulmaClasses';\nimport { warnDeprecatedColorProp } from '../helpers/colorDeprecations';\nimport { useNumberFormat } from '../helpers/localeFormat';\n\n/**\n * Props for the Pagination component.\n */\nexport interface PaginationProps\n extends\n React.HTMLAttributes<HTMLElement>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /**\n * Color modifier for the pagination (renders `is-<color>`).\n *\n * Bulma ships no pagination color CSS, so this prop has never had a visual\n * effect for any value. Passing it logs a console warning in development.\n * Use `textColor` / `bgColor` instead.\n * @deprecated No `.pagination.is-<color>` CSS exists; the prop renders\n * unstyled and will be removed in the next major version.\n */\n color?:\n | 'primary'\n | 'link'\n | 'info'\n | 'success'\n | 'warning'\n | 'danger'\n | 'black'\n | 'dark'\n | 'light'\n | 'white';\n /** Text color helper. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Background color helper. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Size modifier for the pagination. */\n size?: 'small' | 'medium' | 'large';\n /** Alignment for the pagination. */\n align?: 'centered' | 'right';\n /** Renders pagination with rounded corners. */\n rounded?: boolean;\n /**\n * The number of pages. Given `total` and no children, `Pagination` renders\n * the whole control itself: Previous, Next and a link for each page it\n * shows, with an ellipsis where it skips some. Given children, it renders\n * those as they are, and `total` and the other page props do nothing.\n */\n total?: number;\n /**\n * The page shown as current, counting from 1, when rendering from `total`.\n * Leave it out and `Pagination` keeps the page itself, starting at 1.\n */\n current?: number;\n /**\n * Called with the page chosen, when rendering from `total`. Choosing the\n * page already current doesn't call it.\n */\n onPageChange?: (page: number) => void;\n /** How many pages to show on each side of the current one, when rendering from `total`. */\n siblingCount?: number;\n /** How many pages to always show at the start and at the end, when rendering from `total`. */\n boundaryCount?: number;\n /** The Previous link's content, when rendering from `total`. */\n previousLabel?: React.ReactNode;\n /** The Next link's content, when rendering from `total`. */\n nextLabel?: React.ReactNode;\n /** Disables every link, when rendering from `total`. */\n disabled?: boolean;\n /**\n * The `href` for a page's link, when rendering from `total`, making each\n * one a real link (`page => '?page=' + page`). A click then calls\n * `onPageChange` and the browser follows the link too. Without it the\n * links have no `href`, act as buttons, and Enter or Space chooses a page.\n */\n getPageHref?: (page: number) => string;\n /**\n * The accessible name of a page's link, when rendering from `total`, since\n * its content is only the number (`page => 'Page ' + page` by default).\n * Inside a `LocaleProvider` with a `locale`, the number on the link, and\n * in the default name, is written the way that locale writes numbers, so\n * the name still holds the text on screen.\n */\n getPageLabel?: (page: number) => string;\n /** Additional CSS classes. */\n className?: string;\n /** Custom pagination content (usually subcomponents). */\n children?: React.ReactNode;\n}\n\n/** A page's number, or a run of pages left out. */\ntype PageItem = number | 'start-gap' | 'end-gap';\n\n/** A count read as a whole number from zero, or `fallback` when it's no number. */\nfunction whole(count: number, fallback: number): number {\n return Number.isFinite(count) ? Math.max(Math.floor(count), 0) : fallback;\n}\n\nfunction range(from: number, to: number): number[] {\n return Array.from({ length: Math.max(to - from + 1, 0) }, (_, i) => from + i);\n}\n\n/**\n * The pages to show for `current` of `total`: the first and last\n * `boundaries`, `siblings` on each side of the current one, and a gap for\n * each run left out. A gap of a single page shows that page instead, and the\n * window around the current page slides inward near either end, so the row\n * keeps its length as the page moves.\n */\nfunction pageItems(\n total: number,\n current: number,\n siblings: number,\n boundaries: number\n): PageItem[] {\n const windowSize = siblings * 2 + 1;\n // Every page fits in the room the boundary pages, the window and two gaps take.\n if (total <= boundaries * 2 + windowSize + 2) return range(1, total);\n const lowest = boundaries + 2;\n const highest = total - boundaries - 1;\n const start = Math.min(\n Math.max(current - siblings, lowest),\n highest - windowSize + 1\n );\n const end = start + windowSize - 1;\n const gap = (from: number, to: number, name: PageItem): PageItem[] =>\n to === from ? [from] : [name];\n return [\n ...range(1, boundaries),\n ...gap(boundaries + 1, start - 1, 'start-gap'),\n ...range(start, end),\n ...gap(end + 1, total - boundaries, 'end-gap'),\n ...range(total - boundaries + 1, total),\n ];\n}\n\n/**\n * Props for PaginationPrevious and PaginationNext components.\n */\nexport interface PaginationPreviousNextProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n /** Additional CSS classes. */\n className?: string;\n /** Whether previous/next is disabled. */\n disabled?: boolean;\n /** Button content. */\n children?: React.ReactNode;\n}\n\n/**\n * \"Previous\" navigation button.\n *\n * @function\n * @param {PaginationPreviousNextProps} props - Props for the PaginationPrevious component.\n * @returns {JSX.Element} The rendered previous button.\n */\nexport const PaginationPrevious: React.FC<PaginationPreviousNextProps> = ({\n className,\n disabled,\n children,\n ...props\n}) => (\n <a\n className={classNames(\n usePrefixedClassNames('pagination-previous', {\n 'is-disabled': disabled,\n }),\n className\n )}\n aria-disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n {...props}\n onClick={\n disabled\n ? e => {\n e.preventDefault();\n e.stopPropagation();\n }\n : props.onClick\n }\n >\n {children}\n </a>\n);\n\n/**\n * \"Next\" navigation button.\n *\n * @function\n * @param {PaginationPreviousNextProps} props - Props for the PaginationNext component.\n * @returns {JSX.Element} The rendered next button.\n */\nexport const PaginationNext: React.FC<PaginationPreviousNextProps> = ({\n className,\n disabled,\n children,\n ...props\n}) => (\n <a\n className={classNames(\n usePrefixedClassNames('pagination-next', { 'is-disabled': disabled }),\n className\n )}\n aria-disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n {...props}\n onClick={\n disabled\n ? e => {\n e.preventDefault();\n e.stopPropagation();\n }\n : props.onClick\n }\n >\n {children}\n </a>\n);\n\n/**\n * The `Pagination` component provides a flexible, composable Bulma pagination navigation for your Bulma React UI.\n *\n * @function\n * @param {PaginationProps} props - Props for the Pagination component.\n * @returns {JSX.Element} The rendered pagination.\n * @see {@link https://bulma.io/documentation/components/pagination/ | Bulma Pagination documentation}\n */\nconst PaginationComponent: React.FC<PaginationProps> = ({\n color,\n textColor,\n bgColor,\n size,\n align,\n rounded,\n total,\n current,\n onPageChange,\n siblingCount = 1,\n boundaryCount = 1,\n previousLabel = 'Previous',\n nextLabel = 'Next',\n disabled,\n getPageHref,\n getPageLabel,\n className,\n children,\n ...props\n}) => {\n const [kept, setKept] = React.useState(1);\n warnDeprecatedColorProp(\n 'Pagination',\n color,\n 'Use the textColor / bgColor helper props instead.'\n );\n\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor,\n backgroundColor: bgColor,\n ...props,\n });\n const formatNumber = useNumberFormat();\n\n // Generate Bulma classes with prefix\n const bulmaClasses = usePrefixedClassNames('pagination', {\n [`is-${color}`]: color,\n [`is-${size}`]: size,\n [`is-${align}`]: align,\n 'is-rounded': rounded,\n });\n\n const paginationClasses = classNames(\n bulmaClasses,\n bulmaHelperClasses,\n className\n );\n\n // A child that renders nothing (`{show && …}` when false) is no children.\n const fromTotal =\n total !== undefined && React.Children.toArray(children).length === 0;\n let content: React.ReactNode = children;\n if (fromTotal) {\n const pages = Number.isFinite(total) ? Math.max(Math.floor(total), 0) : 0;\n // A current page that's no number reads as the first.\n const page = Math.min(\n Math.max(whole(current ?? kept, 1), 1),\n Math.max(pages, 1)\n );\n const choose = (next: number) => {\n if (next === page) return;\n if (current === undefined) setKept(next);\n onPageChange?.(next);\n };\n /**\n * What a link to `target` is given, beside what it renders. With no\n * `getPageHref` it's a button; a link that's `off` goes nowhere.\n */\n const linkTo = (target: number, off: boolean) => ({\n href: off || !getPageHref ? undefined : getPageHref(target),\n role: getPageHref ? undefined : 'button',\n // A link that's off is disabled too, and the parts drop its clicks.\n onClick: () => choose(target),\n onKeyDown: getPageHref\n ? undefined\n : (e: React.KeyboardEvent<HTMLAnchorElement>) => {\n if (off || (e.key !== 'Enter' && e.key !== ' ')) return;\n e.preventDefault();\n choose(target);\n },\n });\n const atStart = disabled || page <= 1;\n const atEnd = disabled || page >= pages;\n content = (\n <>\n <PaginationPrevious disabled={atStart} {...linkTo(page - 1, atStart)}>\n {previousLabel}\n </PaginationPrevious>\n <PaginationNext disabled={atEnd} {...linkTo(page + 1, atEnd)}>\n {nextLabel}\n </PaginationNext>\n <PaginationList>\n {pageItems(\n pages,\n page,\n whole(siblingCount, 1),\n whole(boundaryCount, 1)\n ).map(item => {\n if (typeof item !== 'number') {\n return <PaginationEllipsis key={item} />;\n }\n const shown = formatNumber ? formatNumber(item) : item;\n return (\n <PaginationLink\n key={item}\n aria-label={getPageLabel ? getPageLabel(item) : `Page ${shown}`}\n active={item === page}\n disabled={disabled}\n {...linkTo(item, Boolean(disabled))}\n >\n {shown}\n </PaginationLink>\n );\n })}\n </PaginationList>\n </>\n );\n }\n\n return (\n <nav\n className={paginationClasses}\n role=\"navigation\"\n aria-label=\"pagination\"\n {...rest}\n >\n {content}\n </nav>\n );\n};\n\n/**\n * Props for the PaginationList component.\n */\nexport interface PaginationListProps\n extends\n React.HTMLAttributes<HTMLUListElement>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Additional CSS classes. */\n className?: string;\n /** Text color for the list. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Bulma color modifier for the list. */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Background color for the list. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** List items. */\n children?: React.ReactNode;\n}\n\n/**\n * Container for page links and ellipsis.\n *\n * @function\n * @param {PaginationListProps} props - Props for the PaginationList component.\n * @returns {JSX.Element} The rendered pagination list.\n */\nexport const PaginationList: React.FC<PaginationListProps> = ({\n className,\n textColor,\n bgColor,\n children,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor,\n backgroundColor: bgColor,\n ...props,\n });\n return (\n <ul\n className={classNames(\n usePrefixedClassNames('pagination-list'),\n bulmaHelperClasses,\n className\n )}\n {...rest}\n >\n {children}\n </ul>\n );\n};\n\n/**\n * Props for the PaginationLink component.\n */\nexport interface PaginationLinkProps\n extends\n React.AnchorHTMLAttributes<HTMLAnchorElement>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Additional CSS classes. */\n className?: string;\n /** Bulma color modifier. */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Text color. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Background color. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Whether the link is for the current page. */\n active?: boolean;\n /** Whether the link is disabled. */\n disabled?: boolean;\n /** Link content. */\n children?: React.ReactNode;\n}\n\n/**\n * Page number or navigation link.\n *\n * @function\n * @param {PaginationLinkProps} props - Props for the PaginationLink component.\n * @returns {JSX.Element} The rendered pagination link.\n */\nexport const PaginationLink: React.FC<PaginationLinkProps> = ({\n className,\n textColor,\n bgColor,\n active,\n disabled,\n onClick,\n children,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor,\n backgroundColor: bgColor,\n ...props,\n });\n\n const handleClick = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {\n if (disabled) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n if (onClick) {\n onClick(e);\n }\n };\n\n return (\n <li>\n <a\n className={classNames(\n usePrefixedClassNames('pagination-link', {\n 'is-current': active,\n 'is-disabled': disabled,\n }),\n bulmaHelperClasses,\n className\n )}\n aria-current={active ? 'page' : undefined}\n aria-disabled={disabled}\n tabIndex={disabled ? -1 : 0}\n onClick={handleClick}\n {...rest}\n >\n {children}\n </a>\n </li>\n );\n};\n\n/**\n * Ellipsis separator.\n *\n * @function\n * @param {React.LiHTMLAttributes<HTMLLIElement>} props - Standard li props.\n * @returns {JSX.Element} The rendered ellipsis.\n */\nexport const PaginationEllipsis: React.FC<\n React.LiHTMLAttributes<HTMLLIElement>\n> = props => (\n <li>\n <span className={usePrefixedClassNames('pagination-ellipsis')} {...props}>\n …\n </span>\n </li>\n);\n\nexport const Pagination = withSubComponents(\n PaginationComponent,\n {\n Link: PaginationLink,\n List: PaginationList,\n Ellipsis: PaginationEllipsis,\n Previous: PaginationPrevious,\n Next: PaginationNext,\n },\n 'Pagination'\n);\n\nexport default Pagination;\n"],"names":["_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;;;AAmGA;AACA,SAAS,KAAK,CAAC,KAAa,EAAE,QAAgB,EAAA;IAC5C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ;AAC3E;AAEA,SAAS,KAAK,CAAC,IAAY,EAAE,EAAU,EAAA;AACrC,IAAA,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;AAC/E;AAEA;;;;;;AAMG;AACH,SAAS,SAAS,CAChB,KAAa,EACb,OAAe,EACf,QAAgB,EAChB,UAAkB,EAAA;AAElB,IAAA,MAAM,UAAU,GAAG,QAAQ,GAAG,CAAC,GAAG,CAAC;;IAEnC,IAAI,KAAK,IAAI,UAAU,GAAG,CAAC,GAAG,UAAU,GAAG,CAAC;AAAE,QAAA,OAAO,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;AACpE,IAAA,MAAM,MAAM,GAAG,UAAU,GAAG,CAAC;AAC7B,IAAA,MAAM,OAAO,GAAG,KAAK,GAAG,UAAU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B,EACD,YAAY;;"}
|
|
@@ -4,6 +4,7 @@ import React from 'react';
|
|
|
4
4
|
import { classNames, usePrefixedClassNames } from '../helpers/classNames.js';
|
|
5
5
|
import { withSubComponents } from '../helpers/withSubComponents.js';
|
|
6
6
|
import { useBulmaClasses } from '../helpers/useBulmaClasses.js';
|
|
7
|
+
import { useNumberFormat } from '../helpers/localeFormat.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Individual Step component for use inside Steps.
|
|
@@ -14,6 +15,7 @@ import { useBulmaClasses } from '../helpers/useBulmaClasses.js';
|
|
|
14
15
|
*/
|
|
15
16
|
const Step = ({ isActive = false, isCompleted = false, label, icon, clickable = false, onClick, stepNumber, completedIcon, className, children, ...props }) => {
|
|
16
17
|
const { bulmaHelperClasses, rest } = useBulmaClasses(props);
|
|
18
|
+
const formatNumber = useNumberFormat();
|
|
17
19
|
const stepClasses = classNames(usePrefixedClassNames('steps-segment', {
|
|
18
20
|
'is-active': isActive,
|
|
19
21
|
'is-completed': isCompleted,
|
|
@@ -26,7 +28,9 @@ const Step = ({ isActive = false, isCompleted = false, label, icon, clickable =
|
|
|
26
28
|
const markerContent = icon ||
|
|
27
29
|
(isCompleted && resolvedCompletedIcon
|
|
28
30
|
? resolvedCompletedIcon
|
|
29
|
-
:
|
|
31
|
+
: stepNumber == null || !formatNumber
|
|
32
|
+
? (stepNumber ?? null)
|
|
33
|
+
: formatNumber(stepNumber));
|
|
30
34
|
const title = label || children;
|
|
31
35
|
const current = isActive ? 'step' : undefined;
|
|
32
36
|
// The step stays a list item, and a real button inside it does the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Steps.js","sources":["../../../src/components/Steps.tsx"],"sourcesContent":["import React from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\n\n/** Available size modifiers for the Steps component. */\nexport type StepsSize = 'small' | 'medium' | 'large';\n/** Available color variants for the Steps component. */\nexport type StepsColor =\n 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n\n/**\n * Props for individual Step items.\n */\nexport interface StepItemProps {\n /**\n * Step label/title. On a `clickable` step it's rendered inside the step's\n * `<button>`, so it has to be phrasing content, like text, a `<span>` or an\n * icon, with no link, button or other control in it.\n */\n label?: React.ReactNode;\n /** Icon for the step marker */\n icon?: React.ReactNode;\n /**\n * Icon shown when the step is completed.\n * @defaultValue '✓'\n */\n completedIcon?: React.ReactNode;\n /**\n * Whether this step is clickable. A clickable step puts its marker and\n * label in a `<button type=\"button\">` inside its list item, which calls\n * `onStepClick`, and the current step's `aria-current` goes on that button.\n */\n clickable?: boolean;\n /** Additional CSS classes. */\n className?: string;\n}\n\n/**\n * Props for the Steps component.\n * @extraProp {React.ReactNode} [children] - Step children (alternative to items).\n * @extraProp {string} [className] - Additional CSS classes.\n */\nexport interface StepsProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, 'color'>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor' | 'size'> {\n /** Current active step (0-indexed). */\n value?: number;\n /** Array of step items. */\n items?: StepItemProps[];\n /** Size of the steps. */\n size?: StepsSize;\n /** Color variant. */\n color?: StepsColor;\n /** Show step markers. Default: true. */\n hasMarker?: boolean;\n /** Enable animations. Default: true. */\n animated?: boolean;\n /** Use rounded markers. Default: true. */\n rounded?: boolean;\n /** Vertical layout. */\n vertical?: boolean;\n /**\n * Position of labels. `right` and `left` mean the end and the start of the\n * line, so in a right-to-left page `right` puts each label to the left of\n * its marker, and `left` to the right.\n */\n labelPosition?: 'bottom' | 'right' | 'left';\n /** Mobile display mode. */\n mobileMode?: 'minimal' | 'compact' | 'right';\n /** Displays step numbers in the markers. */\n showStepNumbers?: boolean;\n /**\n * Shows previous/next navigation buttons. They render `type=\"button\"`, so a\n * multi-step form wrapped around the steps is not submitted by moving\n * between them.\n */\n hasNavigation?: boolean;\n /** Label for the previous button. */\n prevLabel?: string;\n /** Label for the next button. */\n nextLabel?: string;\n /** Callback when previous button is clicked. */\n onPrev?: () => void;\n /** Callback when next button is clicked. */\n onNext?: () => void;\n /** Callback when a step is clicked. */\n onStepClick?: (step: number) => void;\n}\n\n/**\n * Props for the Step subcomponent.\n */\nexport interface StepProps\n extends\n Omit<React.LiHTMLAttributes<HTMLLIElement>, 'color'>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Whether this step is active */\n isActive?: boolean;\n /** Whether this step is completed */\n isCompleted?: boolean;\n /**\n * Step label/title, or pass it as `children`. On a `clickable` step it's\n * rendered inside the step's `<button>`, so it has to be phrasing content,\n * like text, a `<span>` or an icon, with no link, button or other control\n * in it.\n */\n label?: React.ReactNode;\n /** Icon for the step marker */\n icon?: React.ReactNode;\n /**\n * Whether this step is clickable. A clickable step puts its marker and\n * label in a `<button type=\"button\">` inside the `<li>`, which calls\n * `onClick`, and `aria-current` goes on that button. The `<li>` keeps the\n * rest of the props.\n */\n clickable?: boolean;\n /** Click handler */\n onClick?: () => void;\n /** Step number to display in marker (1-indexed) */\n stepNumber?: number;\n /**\n * Icon shown when the step is completed.\n * @defaultValue '✓'\n */\n completedIcon?: React.ReactNode;\n}\n\n/**\n * Individual Step component for use inside Steps.\n *\n * @function\n * @param {StepProps} props - Props for the Step component.\n * @returns {JSX.Element} The rendered step segment.\n */\nexport const Step: React.FC<StepProps> = ({\n isActive = false,\n isCompleted = false,\n label,\n icon,\n clickable = false,\n onClick,\n stepNumber,\n completedIcon,\n className,\n children,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n\n const stepClasses = classNames(\n usePrefixedClassNames('steps-segment', {\n 'is-active': isActive,\n 'is-completed': isCompleted,\n }),\n bulmaHelperClasses,\n className\n );\n const stepsLinkClass = usePrefixedClassNames('steps-link');\n const stepsMarkerClass = usePrefixedClassNames('steps-marker');\n const stepsContentClass = usePrefixedClassNames('steps-content');\n const stepsTitleClass = usePrefixedClassNames('steps-title');\n\n const resolvedCompletedIcon =\n completedIcon === undefined ? '\\u2713' : completedIcon;\n const markerContent =\n icon ||\n (isCompleted && resolvedCompletedIcon\n ? resolvedCompletedIcon\n : (stepNumber ?? null));\n const title = label || children;\n const current = isActive ? 'step' : undefined;\n\n // The step stays a list item, and a real button inside it does the\n // clicking, so the list keeps its items and the button brings Enter, Space\n // and focus with it. A button holds only phrasing content, so its parts\n // are spans.\n if (clickable) {\n return (\n <li className={stepClasses} {...rest}>\n <button\n type=\"button\"\n className={stepsLinkClass}\n onClick={() => onClick?.()}\n aria-current={current}\n >\n <span className={stepsMarkerClass}>{markerContent}</span>\n {title && (\n <span className={stepsContentClass}>\n <span className={stepsTitleClass}>{title}</span>\n </span>\n )}\n </button>\n </li>\n );\n }\n\n return (\n <li className={stepClasses} aria-current={current} {...rest}>\n <div className={stepsLinkClass}>\n <span className={stepsMarkerClass}>{markerContent}</span>\n {title && (\n <div className={stepsContentClass}>\n <p className={stepsTitleClass}>{title}</p>\n </div>\n )}\n </div>\n </li>\n );\n};\n\n/**\n * The `Steps` component provides a multi-step progress indicator for wizard flows, checkout processes, or any multi-step workflow.\n *\n * @function\n * @param {StepsProps} props - Props for the Steps component.\n * @returns {JSX.Element} The rendered steps component.\n *\n * @example\n * // Basic steps with items\n * <Steps\n * value={1}\n * items={[\n * { label: 'Account' },\n * { label: 'Profile' },\n * { label: 'Complete' },\n * ]}\n * />\n *\n * @example\n * // Clickable steps with navigation\n * <Steps\n * value={currentStep}\n * onStepClick={(step) => setCurrentStep(step)}\n * hasNavigation\n * items={[\n * { label: 'Step 1', clickable: true },\n * { label: 'Step 2', clickable: true },\n * { label: 'Step 3', clickable: true },\n * ]}\n * />\n */\nconst StepsComponent: React.FC<StepsProps> = ({\n value = 0,\n items,\n size,\n color,\n hasMarker = true,\n animated = true,\n rounded = true,\n vertical = false,\n labelPosition = 'bottom',\n mobileMode,\n showStepNumbers = true,\n hasNavigation = false,\n prevLabel,\n nextLabel,\n onPrev,\n onNext,\n onStepClick,\n className,\n children,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n\n // Generate classes for the wrapper div\n const stepsClasses = usePrefixedClassNames('steps', {\n [`is-${size}`]: size,\n [`is-${color}`]: color,\n 'has-marker': hasMarker,\n 'is-animated': animated,\n 'is-rounded': rounded,\n 'is-vertical': vertical,\n [`has-label-${labelPosition}`]:\n labelPosition && (labelPosition !== 'bottom' || vertical),\n [`is-${mobileMode}`]: mobileMode,\n });\n\n const combinedClasses = classNames(\n stepsClasses,\n bulmaHelperClasses,\n className\n );\n\n // Generate classes for the ul (list)\n const listClasses = usePrefixedClassNames('steps-list', {\n 'is-vertical': vertical,\n });\n const stepsNavigationClass = usePrefixedClassNames('steps-navigation');\n const prevButtonClass = usePrefixedClassNames('button');\n const nextButtonClass = usePrefixedClassNames('button', {\n 'is-primary': true,\n });\n\n // Count total steps for navigation\n const totalSteps = items ? items.length : React.Children.count(children);\n\n // Render items if provided\n const renderSteps = () => {\n if (items && items.length > 0) {\n return items.map((item, index) => (\n <Step\n key={index}\n isActive={index === value}\n isCompleted={index < value}\n label={item.label}\n icon={item.icon}\n completedIcon={item.completedIcon}\n clickable={item.clickable}\n stepNumber={showStepNumbers ? index + 1 : undefined}\n onClick={\n item.clickable && onStepClick ? () => onStepClick(index) : undefined\n }\n className={item.className}\n />\n ));\n }\n\n // If children are provided, clone them with active/completed states\n if (children) {\n return React.Children.map(children, (child, index) => {\n if (React.isValidElement<StepProps>(child)) {\n return React.cloneElement(child, {\n isActive: index === value,\n isCompleted: index < value,\n stepNumber: showStepNumbers ? index + 1 : undefined,\n onClick:\n child.props.clickable && onStepClick\n ? () => onStepClick(index)\n : child.props.onClick,\n });\n }\n return child;\n });\n }\n\n return null;\n };\n\n // role=\"list\" restates the <ul>'s own role, for Safari: WebKit stops\n // exposing a list as one once its markers are hidden, as they are here,\n // unless the role is set explicitly.\n return (\n <div className={combinedClasses} {...rest}>\n <ul className={listClasses} role=\"list\">\n {renderSteps()}\n </ul>\n {hasNavigation && (\n <div className={stepsNavigationClass}>\n <button\n type=\"button\"\n className={prevButtonClass}\n disabled={value === 0}\n onClick={onPrev ?? (() => onStepClick?.(value - 1))}\n >\n {prevLabel ?? 'Previous'}\n </button>\n <button\n type=\"button\"\n className={nextButtonClass}\n disabled={value === totalSteps - 1}\n onClick={onNext ?? (() => onStepClick?.(value + 1))}\n >\n {nextLabel ?? 'Next'}\n </button>\n </div>\n )}\n </div>\n );\n};\n\n// Attach Step as static property\nexport const Steps = withSubComponents(StepsComponent, { Step }, 'Steps');\n\nexport default Steps;\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;AAiIA;;;;;;AAMG;AACI,MAAM,IAAI,GAAwB,CAAC,EACxC,QAAQ,GAAG,KAAK,EAChB,WAAW,GAAG,KAAK,EACnB,KAAK,EACL,IAAI,EACJ,SAAS,GAAG,KAAK,EACjB,OAAO,EACP,UAAU,EACV,aAAa,EACb,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,KAAI;IACH,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC;AAE3D,IAAA,MAAM,WAAW,GAAG,UAAU,CAC5B,qBAAqB,CAAC,eAAe,EAAE;AACrC,QAAA,WAAW,EAAE,QAAQ;AACrB,QAAA,cAAc,EAAE,WAAW;AAC5B,KAAA,CAAC,EACF,kBAAkB,EAClB,SAAS,CACV;AACD,IAAA,MAAM,cAAc,GAAG,qBAAqB,CAAC,YAAY,CAAC;AAC1D,IAAA,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,cAAc,CAAC;AAC9D,IAAA,MAAM,iBAAiB,GAAG,qBAAqB,CAAC,eAAe,CAAC;AAChE,IAAA,MAAM,eAAe,GAAG,qBAAqB,CAAC,aAAa,CAAC;AAE5D,IAAA,MAAM,qBAAqB,GACzB,aAAa,KAAK,SAAS,GAAG,QAAQ,GAAG,aAAa;IACxD,MAAM,aAAa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"}
|
|
1
|
+
{"version":3,"file":"Steps.js","sources":["../../../src/components/Steps.tsx"],"sourcesContent":["import React from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { useNumberFormat } from '../helpers/localeFormat';\n\n/** Available size modifiers for the Steps component. */\nexport type StepsSize = 'small' | 'medium' | 'large';\n/** Available color variants for the Steps component. */\nexport type StepsColor =\n 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n\n/**\n * Props for individual Step items.\n */\nexport interface StepItemProps {\n /**\n * Step label/title. On a `clickable` step it's rendered inside the step's\n * `<button>`, so it has to be phrasing content, like text, a `<span>` or an\n * icon, with no link, button or other control in it.\n */\n label?: React.ReactNode;\n /** Icon for the step marker */\n icon?: React.ReactNode;\n /**\n * Icon shown when the step is completed.\n * @defaultValue '✓'\n */\n completedIcon?: React.ReactNode;\n /**\n * Whether this step is clickable. A clickable step puts its marker and\n * label in a `<button type=\"button\">` inside its list item, which calls\n * `onStepClick`, and the current step's `aria-current` goes on that button.\n */\n clickable?: boolean;\n /** Additional CSS classes. */\n className?: string;\n}\n\n/**\n * Props for the Steps component.\n * @extraProp {React.ReactNode} [children] - Step children (alternative to items).\n * @extraProp {string} [className] - Additional CSS classes.\n */\nexport interface StepsProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, 'color'>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor' | 'size'> {\n /** Current active step (0-indexed). */\n value?: number;\n /** Array of step items. */\n items?: StepItemProps[];\n /** Size of the steps. */\n size?: StepsSize;\n /** Color variant. */\n color?: StepsColor;\n /** Show step markers. Default: true. */\n hasMarker?: boolean;\n /** Enable animations. Default: true. */\n animated?: boolean;\n /** Use rounded markers. Default: true. */\n rounded?: boolean;\n /** Vertical layout. */\n vertical?: boolean;\n /**\n * Position of labels. `right` and `left` mean the end and the start of the\n * line, so in a right-to-left page `right` puts each label to the left of\n * its marker, and `left` to the right.\n */\n labelPosition?: 'bottom' | 'right' | 'left';\n /** Mobile display mode. */\n mobileMode?: 'minimal' | 'compact' | 'right';\n /** Displays step numbers in the markers. */\n showStepNumbers?: boolean;\n /**\n * Shows previous/next navigation buttons. They render `type=\"button\"`, so a\n * multi-step form wrapped around the steps is not submitted by moving\n * between them.\n */\n hasNavigation?: boolean;\n /** Label for the previous button. */\n prevLabel?: string;\n /** Label for the next button. */\n nextLabel?: string;\n /** Callback when previous button is clicked. */\n onPrev?: () => void;\n /** Callback when next button is clicked. */\n onNext?: () => void;\n /** Callback when a step is clicked. */\n onStepClick?: (step: number) => void;\n}\n\n/**\n * Props for the Step subcomponent.\n */\nexport interface StepProps\n extends\n Omit<React.LiHTMLAttributes<HTMLLIElement>, 'color'>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Whether this step is active */\n isActive?: boolean;\n /** Whether this step is completed */\n isCompleted?: boolean;\n /**\n * Step label/title, or pass it as `children`. On a `clickable` step it's\n * rendered inside the step's `<button>`, so it has to be phrasing content,\n * like text, a `<span>` or an icon, with no link, button or other control\n * in it.\n */\n label?: React.ReactNode;\n /** Icon for the step marker */\n icon?: React.ReactNode;\n /**\n * Whether this step is clickable. A clickable step puts its marker and\n * label in a `<button type=\"button\">` inside the `<li>`, which calls\n * `onClick`, and `aria-current` goes on that button. The `<li>` keeps the\n * rest of the props.\n */\n clickable?: boolean;\n /** Click handler */\n onClick?: () => void;\n /**\n * Step number to display in marker (1-indexed), written the way the\n * `locale` of a `LocaleProvider` around it writes numbers.\n */\n stepNumber?: number;\n /**\n * Icon shown when the step is completed.\n * @defaultValue '✓'\n */\n completedIcon?: React.ReactNode;\n}\n\n/**\n * Individual Step component for use inside Steps.\n *\n * @function\n * @param {StepProps} props - Props for the Step component.\n * @returns {JSX.Element} The rendered step segment.\n */\nexport const Step: React.FC<StepProps> = ({\n isActive = false,\n isCompleted = false,\n label,\n icon,\n clickable = false,\n onClick,\n stepNumber,\n completedIcon,\n className,\n children,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const formatNumber = useNumberFormat();\n\n const stepClasses = classNames(\n usePrefixedClassNames('steps-segment', {\n 'is-active': isActive,\n 'is-completed': isCompleted,\n }),\n bulmaHelperClasses,\n className\n );\n const stepsLinkClass = usePrefixedClassNames('steps-link');\n const stepsMarkerClass = usePrefixedClassNames('steps-marker');\n const stepsContentClass = usePrefixedClassNames('steps-content');\n const stepsTitleClass = usePrefixedClassNames('steps-title');\n\n const resolvedCompletedIcon =\n completedIcon === undefined ? '\\u2713' : completedIcon;\n const markerContent =\n icon ||\n (isCompleted && resolvedCompletedIcon\n ? resolvedCompletedIcon\n : stepNumber == null || !formatNumber\n ? (stepNumber ?? null)\n : formatNumber(stepNumber));\n const title = label || children;\n const current = isActive ? 'step' : undefined;\n\n // The step stays a list item, and a real button inside it does the\n // clicking, so the list keeps its items and the button brings Enter, Space\n // and focus with it. A button holds only phrasing content, so its parts\n // are spans.\n if (clickable) {\n return (\n <li className={stepClasses} {...rest}>\n <button\n type=\"button\"\n className={stepsLinkClass}\n onClick={() => onClick?.()}\n aria-current={current}\n >\n <span className={stepsMarkerClass}>{markerContent}</span>\n {title && (\n <span className={stepsContentClass}>\n <span className={stepsTitleClass}>{title}</span>\n </span>\n )}\n </button>\n </li>\n );\n }\n\n return (\n <li className={stepClasses} aria-current={current} {...rest}>\n <div className={stepsLinkClass}>\n <span className={stepsMarkerClass}>{markerContent}</span>\n {title && (\n <div className={stepsContentClass}>\n <p className={stepsTitleClass}>{title}</p>\n </div>\n )}\n </div>\n </li>\n );\n};\n\n/**\n * The `Steps` component provides a multi-step progress indicator for wizard flows, checkout processes, or any multi-step workflow.\n *\n * @function\n * @param {StepsProps} props - Props for the Steps component.\n * @returns {JSX.Element} The rendered steps component.\n *\n * @example\n * // Basic steps with items\n * <Steps\n * value={1}\n * items={[\n * { label: 'Account' },\n * { label: 'Profile' },\n * { label: 'Complete' },\n * ]}\n * />\n *\n * @example\n * // Clickable steps with navigation\n * <Steps\n * value={currentStep}\n * onStepClick={(step) => setCurrentStep(step)}\n * hasNavigation\n * items={[\n * { label: 'Step 1', clickable: true },\n * { label: 'Step 2', clickable: true },\n * { label: 'Step 3', clickable: true },\n * ]}\n * />\n */\nconst StepsComponent: React.FC<StepsProps> = ({\n value = 0,\n items,\n size,\n color,\n hasMarker = true,\n animated = true,\n rounded = true,\n vertical = false,\n labelPosition = 'bottom',\n mobileMode,\n showStepNumbers = true,\n hasNavigation = false,\n prevLabel,\n nextLabel,\n onPrev,\n onNext,\n onStepClick,\n className,\n children,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n\n // Generate classes for the wrapper div\n const stepsClasses = usePrefixedClassNames('steps', {\n [`is-${size}`]: size,\n [`is-${color}`]: color,\n 'has-marker': hasMarker,\n 'is-animated': animated,\n 'is-rounded': rounded,\n 'is-vertical': vertical,\n [`has-label-${labelPosition}`]:\n labelPosition && (labelPosition !== 'bottom' || vertical),\n [`is-${mobileMode}`]: mobileMode,\n });\n\n const combinedClasses = classNames(\n stepsClasses,\n bulmaHelperClasses,\n className\n );\n\n // Generate classes for the ul (list)\n const listClasses = usePrefixedClassNames('steps-list', {\n 'is-vertical': vertical,\n });\n const stepsNavigationClass = usePrefixedClassNames('steps-navigation');\n const prevButtonClass = usePrefixedClassNames('button');\n const nextButtonClass = usePrefixedClassNames('button', {\n 'is-primary': true,\n });\n\n // Count total steps for navigation\n const totalSteps = items ? items.length : React.Children.count(children);\n\n // Render items if provided\n const renderSteps = () => {\n if (items && items.length > 0) {\n return items.map((item, index) => (\n <Step\n key={index}\n isActive={index === value}\n isCompleted={index < value}\n label={item.label}\n icon={item.icon}\n completedIcon={item.completedIcon}\n clickable={item.clickable}\n stepNumber={showStepNumbers ? index + 1 : undefined}\n onClick={\n item.clickable && onStepClick ? () => onStepClick(index) : undefined\n }\n className={item.className}\n />\n ));\n }\n\n // If children are provided, clone them with active/completed states\n if (children) {\n return React.Children.map(children, (child, index) => {\n if (React.isValidElement<StepProps>(child)) {\n return React.cloneElement(child, {\n isActive: index === value,\n isCompleted: index < value,\n stepNumber: showStepNumbers ? index + 1 : undefined,\n onClick:\n child.props.clickable && onStepClick\n ? () => onStepClick(index)\n : child.props.onClick,\n });\n }\n return child;\n });\n }\n\n return null;\n };\n\n // role=\"list\" restates the <ul>'s own role, for Safari: WebKit stops\n // exposing a list as one once its markers are hidden, as they are here,\n // unless the role is set explicitly.\n return (\n <div className={combinedClasses} {...rest}>\n <ul className={listClasses} role=\"list\">\n {renderSteps()}\n </ul>\n {hasNavigation && (\n <div className={stepsNavigationClass}>\n <button\n type=\"button\"\n className={prevButtonClass}\n disabled={value === 0}\n onClick={onPrev ?? (() => onStepClick?.(value - 1))}\n >\n {prevLabel ?? 'Previous'}\n </button>\n <button\n type=\"button\"\n className={nextButtonClass}\n disabled={value === totalSteps - 1}\n onClick={onNext ?? (() => onStepClick?.(value + 1))}\n >\n {nextLabel ?? 'Next'}\n </button>\n </div>\n )}\n </div>\n );\n};\n\n// Attach Step as static property\nexport const Steps = withSubComponents(StepsComponent, { Step }, 'Steps');\n\nexport default Steps;\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;AAqIA;;;;;;AAMG;AACI,MAAM,IAAI,GAAwB,CAAC,EACxC,QAAQ,GAAG,KAAK,EAChB,WAAW,GAAG,KAAK,EACnB,KAAK,EACL,IAAI,EACJ,SAAS,GAAG,KAAK,EACjB,OAAO,EACP,UAAU,EACV,aAAa,EACb,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,KAAI;IACH,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC;AAC3D,IAAA,MAAM,YAAY,GAAG,eAAe,EAAE;AAEtC,IAAA,MAAM,WAAW,GAAG,UAAU,CAC5B,qBAAqB,CAAC,eAAe,EAAE;AACrC,QAAA,WAAW,EAAE,QA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AAK,MAAM,WAAW,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,EAAA,QAAA,EAElD,SAAS,IAAI,UAAU,EAAA,CACjB,EACTA,GAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,KAAK,KAAK,UAAU,GAAG,CAAC,EAClC,OAAO,EAAE,MAAM,KAAK,MAAM,WAAW,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,EAAA,QAAA,EAElD,SAAS,IAAI,MAAM,GACb,CAAA,EAAA,CACL,CACP,CAAA,EAAA,CACG;AAEV,CAAC;AAED;AACO,MAAM,KAAK,GAAG,iBAAiB,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,EAAE,OAAO;;"}
|
|
@@ -3,6 +3,7 @@ import { jsxs, jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
import { forwardRef, useEffect } from 'react';
|
|
4
4
|
import { usePrefixedClassNames, classNames, prefixedClassNames } from '../helpers/classNames.js';
|
|
5
5
|
import { useClassPrefix } from '../helpers/Config.js';
|
|
6
|
+
import { useNumberFormat } from '../helpers/localeFormat.js';
|
|
6
7
|
import { useBulmaClasses } from '../helpers/useBulmaClasses.js';
|
|
7
8
|
import { warnOnce } from '../helpers/devWarnings.js';
|
|
8
9
|
|
|
@@ -85,13 +86,17 @@ const RingProgress = forwardRef(({ className, textColor, bgColor, value, max = 1
|
|
|
85
86
|
const labelClass = usePrefixedClassNames('ring-progress-label');
|
|
86
87
|
// A section's color class, prefixed like the rest.
|
|
87
88
|
const classPrefix = useClassPrefix();
|
|
89
|
+
const formatNumber = useNumberFormat();
|
|
90
|
+
const writeShare = (share) => formatNumber
|
|
91
|
+
? formatNumber(share / 100, { style: 'percent' })
|
|
92
|
+
: `${share}%`;
|
|
88
93
|
const roleProps = sections
|
|
89
94
|
? {
|
|
90
95
|
role: 'img',
|
|
91
96
|
'aria-label': [
|
|
92
97
|
label || rest['aria-label'],
|
|
93
98
|
sections
|
|
94
|
-
.map((section, i) => `${section.label} ${Math.round(arcs[i].length)}
|
|
99
|
+
.map((section, i) => `${section.label} ${writeShare(Math.round(arcs[i].length))}`)
|
|
95
100
|
.join(', '),
|
|
96
101
|
]
|
|
97
102
|
.filter(Boolean)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RingProgress.js","sources":["../../../src/elements/RingProgress.tsx"],"sourcesContent":["import React, { forwardRef, useEffect } from 'react';\nimport {\n classNames,\n prefixedClassNames,\n usePrefixedClassNames,\n} from '../helpers/classNames';\nimport { useClassPrefix } from '../helpers/Config';\nimport {\n useBulmaClasses,\n BulmaClassesProps,\n validColors,\n} from '../helpers/useBulmaClasses';\nimport { warnOnce } from '../helpers/devWarnings';\n\nconst validRingProgressColors = [\n 'primary',\n 'link',\n 'info',\n 'success',\n 'warning',\n 'danger',\n 'black',\n 'dark',\n 'light',\n 'white',\n] as const;\n/** The Bulma colors an arc takes, the ones `Progress` takes. */\nexport type RingProgressColor = (typeof validRingProgressColors)[number];\n\nconst validRingProgressSizes = ['small', 'medium', 'large'] as const;\n\n/** One colored part of a ring drawn in sections. */\nexport interface RingProgressSection {\n /** Its size, in the same units as the ring's `max`. */\n value: number;\n /** Its color. Without one, it takes the ring's. */\n color?: RingProgressColor;\n /** What it is, such as \"Photos\", read in the ring's name with its share. */\n label: string;\n}\n\n/**\n * Props for the RingProgress component. The helper props, the other\n * attributes and the `ref` land on its root `<div>`.\n *\n * @extraProp {React.Ref<HTMLDivElement>} [ref] - Ref forwarded to the root `<div>`.\n * @extraProp {string} [aria-labelledby] - The id of a visible heading that names the ring, in place of `label`. With `sections`, use `label`, since a name from here replaces the one that lists the values.\n * @extraProp {string} [aria-valuetext] - What a screen reader says for the value, such as \"7 of 10 tasks\". Without it, the value is read as a percentage.\n */\nexport interface RingProgressProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, 'color' | 'role'>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Additional CSS classes to apply. */\n className?: string;\n /**\n * How far along it is, from 0 to `max`. Values outside that range are\n * drawn, and read, at the nearest end. Ignored with `sections`.\n */\n value?: number;\n /** The value that fills the ring. */\n max?: number;\n /**\n * Several values around one ring, in order clockwise from the top, each\n * with its own color and label. The ring is then an image whose name\n * writes them out, such as \"Storage: Documents 40%, Photos 15%\", since a\n * screen reader can't take several values from one element. A total over\n * `max` fills the ring and stops.\n */\n sections?: RingProgressSection[];\n /**\n * What it shows, such as \"Upload\" or \"Storage\". It names the ring, so it's\n * read with the value. A development build warns when the ring has no\n * name.\n */\n label?: string;\n /**\n * A level within a range, such as storage used or a score, rather than a\n * task moving toward done: `role=\"meter\"` in place of `role=\"progressbar\"`.\n * Ignored with `sections`.\n */\n isMeter?: boolean;\n /** The arc's color, and the color of sections without one. */\n color?: RingProgressColor;\n /** The ring's size. */\n size?: (typeof validRingProgressSizes)[number];\n /** Rounds the ends of the arc. */\n isRounded?: boolean;\n /**\n * What sits in the middle of the ring, such as the value as text. It's\n * hidden from assistive tech, which reads the value from the ring itself,\n * so the value isn't heard twice. Say anything more, such as \"7 of 10\n * tasks\", in `aria-valuetext`.\n */\n children?: React.ReactNode;\n /** Text color helper. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Background color helper. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n}\n\n/** An arc's place on the ring, in percent of the way round. */\ninterface Arc {\n start: number;\n length: number;\n color?: RingProgressColor;\n}\n\nconst clamp = (value: number, low: number, high: number) =>\n Math.min(Math.max(value, low), high);\n\n/**\n * The `RingProgress` component draws a value as a ring that fills as it grows, with anything you pass shown in the middle.\n *\n * It's a `progressbar` for a task moving toward done, or a `meter` with\n * `isMeter` for a level within a range, named by `label`. With `sections`\n * it draws several values around one ring and is an image whose name lists\n * them. It has no state for work with no value: that's `Loader`.\n *\n * @function\n * @param {RingProgressProps} props - Props for the RingProgress component.\n * @param {React.Ref<HTMLDivElement>} ref - Forwarded ref to the root `<div>`.\n * @returns {JSX.Element} The rendered ring.\n *\n * @example\n * <RingProgress value={72} label=\"Upload\" color=\"success\">\n * 72%\n * </RingProgress>\n */\nexport const RingProgress = forwardRef<HTMLDivElement, RingProgressProps>(\n (\n {\n className,\n textColor,\n bgColor,\n value,\n max = 100,\n sections,\n label,\n isMeter,\n color,\n size,\n isRounded,\n children,\n ...props\n },\n ref\n ) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor,\n backgroundColor: bgColor,\n ...props,\n });\n\n const named = Boolean(\n label || rest['aria-label'] || rest['aria-labelledby']\n );\n const mixed = sections !== undefined && value !== undefined;\n useEffect(() => {\n if (!named) {\n warnOnce(\n 'RingProgress:unnamed',\n '[bestax-bulma] <RingProgress> has no accessible name. Pass ' +\n 'label, so a screen reader can say what the ring shows.'\n );\n }\n if (mixed) {\n warnOnce(\n 'RingProgress:value-and-sections',\n '[bestax-bulma] <RingProgress> was given both value and sections. ' +\n 'It draws the sections and ignores value.'\n );\n }\n }, [named, mixed]);\n\n const total = max > 0 ? max : 100;\n const share = (part: number) => (clamp(part, 0, total) / total) * 100;\n\n // Each arc starts where the one before ended, and the last stops at the\n // top, so a total over max fills the ring and no more.\n const arcs: Arc[] = [];\n if (sections) {\n let start = 0;\n for (const section of sections) {\n const length = Math.min(share(section.value), 100 - start);\n arcs.push({ start, length, color: section.color });\n start += length;\n }\n } else {\n arcs.push({ start: 0, length: share(value ?? 0) });\n }\n\n const rootClass = usePrefixedClassNames('ring-progress', {\n [`is-${size}`]:\n !!size && (validRingProgressSizes as readonly string[]).includes(size),\n [`is-${color}`]:\n !!color &&\n (validRingProgressColors as readonly string[]).includes(color),\n 'is-rounded': !!isRounded,\n 'has-sections': !!sections,\n });\n const ringClass = usePrefixedClassNames('ring-progress-ring');\n const trackClass = usePrefixedClassNames('ring-progress-track');\n const arcClass = usePrefixedClassNames('ring-progress-arc');\n const labelClass = usePrefixedClassNames('ring-progress-label');\n // A section's color class, prefixed like the rest.\n const classPrefix = useClassPrefix();\n\n const roleProps = sections\n ? {\n role: 'img',\n 'aria-label': [\n label || rest['aria-label'],\n sections\n .map(\n (section, i) =>\n `${section.label} ${Math.round(arcs[i].length)}%`\n )\n .join(', '),\n ]\n .filter(Boolean)\n .join(': '),\n }\n : {\n role: isMeter ? 'meter' : 'progressbar',\n 'aria-valuenow': clamp(value ?? 0, 0, total),\n 'aria-valuemin': 0,\n 'aria-valuemax': total,\n 'aria-label': label || rest['aria-label'],\n };\n\n return (\n <div\n ref={ref}\n className={classNames(rootClass, bulmaHelperClasses, className)}\n {...rest}\n {...roleProps}\n >\n <svg className={ringClass} viewBox=\"0 0 100 100\" aria-hidden=\"true\">\n <circle className={trackClass} cx=\"50\" cy=\"50\" r=\"42\" />\n {arcs.map(\n (arc, i) =>\n arc.length > 0 && (\n <circle\n key={i}\n className={classNames(\n arcClass,\n arc.color &&\n (validRingProgressColors as readonly string[]).includes(\n arc.color\n ) &&\n prefixedClassNames(classPrefix, `is-${arc.color}`)\n )}\n cx=\"50\"\n cy=\"50\"\n r=\"42\"\n pathLength={100}\n style={\n {\n '--ring-progress-length': arc.length,\n '--ring-progress-start': arc.start,\n } as React.CSSProperties\n }\n />\n )\n )}\n </svg>\n {children !== undefined && children !== null && (\n // The ring's value is already read from its role, and not every\n // browser keeps a meter's content out of the tree, so the middle\n // is for the eye only.\n <div className={labelClass} aria-hidden=\"true\">\n {children}\n </div>\n )}\n </div>\n );\n }\n);\n\nRingProgress.displayName = 'RingProgress';\n\nexport default RingProgress;\n"],"names":["clamp","_jsxs","_jsx"],"mappings":";;;;;;;;AAcA,MAAM,uBAAuB,GAAG;IAC9B,SAAS;IACT,MAAM;IACN,MAAM;IACN,SAAS;IACT,SAAS;IACT,QAAQ;IACR,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;CACC;AAIV,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAU;AA+EpE,MAAMA,OAAK,GAAG,CA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AG,CAAC,KAAK;AACN,4BAAA,uBAA6C,CAAC,QAAQ,CACrD,GAAG,CAAC,KAAK,CACV;AACD,4BAAA,kBAAkB,CAAC,WAAW,EAAE,CAAA,GAAA,EAAM,GAAG,CAAC,KAAK,CAAA,CAAE,CAAC,CACrD,EACD,EAAE,EAAC,IAAI,EACP,EAAE,EAAC,IAAI,EACP,CAAC,EAAC,IAAI,EACN,UAAU,EAAE,GAAG,EACf,KAAK,EACH;4BACE,wBAAwB,EAAE,GAAG,CAAC,MAAM;4BACpC,uBAAuB,EAAE,GAAG,CAAC,KAAK;yBACZ,EAAA,EAjBrB,CAAC,CAmBN,CACH,CACJ,CAAA,EAAA,CACG,EACL,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,KAI1CA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,UAAU,EAAA,aAAA,EAAc,MAAM,EAAA,QAAA,EAC3C,QAAQ,EAAA,CACL,CACP,CAAA,EAAA,CACG;AAEV,CAAC;AAGH,YAAY,CAAC,WAAW,GAAG,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"RingProgress.js","sources":["../../../src/elements/RingProgress.tsx"],"sourcesContent":["import React, { forwardRef, useEffect } from 'react';\nimport {\n classNames,\n prefixedClassNames,\n usePrefixedClassNames,\n} from '../helpers/classNames';\nimport { useClassPrefix } from '../helpers/Config';\nimport { useNumberFormat } from '../helpers/localeFormat';\nimport {\n useBulmaClasses,\n BulmaClassesProps,\n validColors,\n} from '../helpers/useBulmaClasses';\nimport { warnOnce } from '../helpers/devWarnings';\n\nconst validRingProgressColors = [\n 'primary',\n 'link',\n 'info',\n 'success',\n 'warning',\n 'danger',\n 'black',\n 'dark',\n 'light',\n 'white',\n] as const;\n/** The Bulma colors an arc takes, the ones `Progress` takes. */\nexport type RingProgressColor = (typeof validRingProgressColors)[number];\n\nconst validRingProgressSizes = ['small', 'medium', 'large'] as const;\n\n/** One colored part of a ring drawn in sections. */\nexport interface RingProgressSection {\n /** Its size, in the same units as the ring's `max`. */\n value: number;\n /** Its color. Without one, it takes the ring's. */\n color?: RingProgressColor;\n /** What it is, such as \"Photos\", read in the ring's name with its share. */\n label: string;\n}\n\n/**\n * Props for the RingProgress component. The helper props, the other\n * attributes and the `ref` land on its root `<div>`.\n *\n * @extraProp {React.Ref<HTMLDivElement>} [ref] - Ref forwarded to the root `<div>`.\n * @extraProp {string} [aria-labelledby] - The id of a visible heading that names the ring, in place of `label`. With `sections`, use `label`, since a name from here replaces the one that lists the values.\n * @extraProp {string} [aria-valuetext] - What a screen reader says for the value, such as \"7 of 10 tasks\". Without it, the value is read as a percentage.\n */\nexport interface RingProgressProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, 'color' | 'role'>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Additional CSS classes to apply. */\n className?: string;\n /**\n * How far along it is, from 0 to `max`. Values outside that range are\n * drawn, and read, at the nearest end. Ignored with `sections`.\n */\n value?: number;\n /** The value that fills the ring. */\n max?: number;\n /**\n * Several values around one ring, in order clockwise from the top, each\n * with its own color and label. The ring is then an image whose name\n * writes them out, such as \"Storage: Documents 40%, Photos 15%\", since a\n * screen reader can't take several values from one element. Inside a\n * `LocaleProvider` with a `locale`, the shares are written as that locale\n * writes a percentage. A total over `max` fills the ring and stops.\n */\n sections?: RingProgressSection[];\n /**\n * What it shows, such as \"Upload\" or \"Storage\". It names the ring, so it's\n * read with the value. A development build warns when the ring has no\n * name.\n */\n label?: string;\n /**\n * A level within a range, such as storage used or a score, rather than a\n * task moving toward done: `role=\"meter\"` in place of `role=\"progressbar\"`.\n * Ignored with `sections`.\n */\n isMeter?: boolean;\n /** The arc's color, and the color of sections without one. */\n color?: RingProgressColor;\n /** The ring's size. */\n size?: (typeof validRingProgressSizes)[number];\n /** Rounds the ends of the arc. */\n isRounded?: boolean;\n /**\n * What sits in the middle of the ring, such as the value as text. It's\n * hidden from assistive tech, which reads the value from the ring itself,\n * so the value isn't heard twice. Say anything more, such as \"7 of 10\n * tasks\", in `aria-valuetext`.\n */\n children?: React.ReactNode;\n /** Text color helper. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Background color helper. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n}\n\n/** An arc's place on the ring, in percent of the way round. */\ninterface Arc {\n start: number;\n length: number;\n color?: RingProgressColor;\n}\n\nconst clamp = (value: number, low: number, high: number) =>\n Math.min(Math.max(value, low), high);\n\n/**\n * The `RingProgress` component draws a value as a ring that fills as it grows, with anything you pass shown in the middle.\n *\n * It's a `progressbar` for a task moving toward done, or a `meter` with\n * `isMeter` for a level within a range, named by `label`. With `sections`\n * it draws several values around one ring and is an image whose name lists\n * them. It has no state for work with no value: that's `Loader`.\n *\n * @function\n * @param {RingProgressProps} props - Props for the RingProgress component.\n * @param {React.Ref<HTMLDivElement>} ref - Forwarded ref to the root `<div>`.\n * @returns {JSX.Element} The rendered ring.\n *\n * @example\n * <RingProgress value={72} label=\"Upload\" color=\"success\">\n * 72%\n * </RingProgress>\n */\nexport const RingProgress = forwardRef<HTMLDivElement, RingProgressProps>(\n (\n {\n className,\n textColor,\n bgColor,\n value,\n max = 100,\n sections,\n label,\n isMeter,\n color,\n size,\n isRounded,\n children,\n ...props\n },\n ref\n ) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor,\n backgroundColor: bgColor,\n ...props,\n });\n\n const named = Boolean(\n label || rest['aria-label'] || rest['aria-labelledby']\n );\n const mixed = sections !== undefined && value !== undefined;\n useEffect(() => {\n if (!named) {\n warnOnce(\n 'RingProgress:unnamed',\n '[bestax-bulma] <RingProgress> has no accessible name. Pass ' +\n 'label, so a screen reader can say what the ring shows.'\n );\n }\n if (mixed) {\n warnOnce(\n 'RingProgress:value-and-sections',\n '[bestax-bulma] <RingProgress> was given both value and sections. ' +\n 'It draws the sections and ignores value.'\n );\n }\n }, [named, mixed]);\n\n const total = max > 0 ? max : 100;\n const share = (part: number) => (clamp(part, 0, total) / total) * 100;\n\n // Each arc starts where the one before ended, and the last stops at the\n // top, so a total over max fills the ring and no more.\n const arcs: Arc[] = [];\n if (sections) {\n let start = 0;\n for (const section of sections) {\n const length = Math.min(share(section.value), 100 - start);\n arcs.push({ start, length, color: section.color });\n start += length;\n }\n } else {\n arcs.push({ start: 0, length: share(value ?? 0) });\n }\n\n const rootClass = usePrefixedClassNames('ring-progress', {\n [`is-${size}`]:\n !!size && (validRingProgressSizes as readonly string[]).includes(size),\n [`is-${color}`]:\n !!color &&\n (validRingProgressColors as readonly string[]).includes(color),\n 'is-rounded': !!isRounded,\n 'has-sections': !!sections,\n });\n const ringClass = usePrefixedClassNames('ring-progress-ring');\n const trackClass = usePrefixedClassNames('ring-progress-track');\n const arcClass = usePrefixedClassNames('ring-progress-arc');\n const labelClass = usePrefixedClassNames('ring-progress-label');\n // A section's color class, prefixed like the rest.\n const classPrefix = useClassPrefix();\n const formatNumber = useNumberFormat();\n const writeShare = (share: number) =>\n formatNumber\n ? formatNumber(share / 100, { style: 'percent' })\n : `${share}%`;\n\n const roleProps = sections\n ? {\n role: 'img',\n 'aria-label': [\n label || rest['aria-label'],\n sections\n .map(\n (section, i) =>\n `${section.label} ${writeShare(Math.round(arcs[i].length))}`\n )\n .join(', '),\n ]\n .filter(Boolean)\n .join(': '),\n }\n : {\n role: isMeter ? 'meter' : 'progressbar',\n 'aria-valuenow': clamp(value ?? 0, 0, total),\n 'aria-valuemin': 0,\n 'aria-valuemax': total,\n 'aria-label': label || rest['aria-label'],\n };\n\n return (\n <div\n ref={ref}\n className={classNames(rootClass, bulmaHelperClasses, className)}\n {...rest}\n {...roleProps}\n >\n <svg className={ringClass} viewBox=\"0 0 100 100\" aria-hidden=\"true\">\n <circle className={trackClass} cx=\"50\" cy=\"50\" r=\"42\" />\n {arcs.map(\n (arc, i) =>\n arc.length > 0 && (\n <circle\n key={i}\n className={classNames(\n arcClass,\n arc.color &&\n (validRingProgressColors as readonly string[]).includes(\n arc.color\n ) &&\n prefixedClassNames(classPrefix, `is-${arc.color}`)\n )}\n cx=\"50\"\n cy=\"50\"\n r=\"42\"\n pathLength={100}\n style={\n {\n '--ring-progress-length': arc.length,\n '--ring-progress-start': arc.start,\n } as React.CSSProperties\n }\n />\n )\n )}\n </svg>\n {children !== undefined && children !== null && (\n // The ring's value is already read from its role, and not every\n // browser keeps a meter's content out of the tree, so the middle\n // is for the eye only.\n <div className={labelClass} aria-hidden=\"true\">\n {children}\n </div>\n )}\n </div>\n );\n }\n);\n\nRingProgress.displayName = 'RingProgress';\n\nexport default RingProgress;\n"],"names":["clamp","_jsxs","_jsx"],"mappings":";;;;;;;;;AAeA,MAAM,uBAAuB,GAAG;IAC9B,SAAS;IACT,MAAM;IACN,MAAM;IACN,SAAS;IACT,SAAS;IACT,QAAQ;IACR,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;CACC;AAIV,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAU;AAgFpE,MAAMA,OAAK,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,IAAY,KACrD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC;AAEtC;;;;;;;;;;;;;;;;;AAiBG;AACI,MAAM,YAAY,GAAG,UAAU,CACpC,CACE,EACE,SAAS,EACT,SAAS,EACT,OAAO,EACP,KAAK,EACL,GAAG,GAAG,GAAG,EACT,QAAQ,EACR,KAAK,EACL,OAAO,EACP,KAAK,EACL,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EACD,GAAG,KACD;AACF,IAAA,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC;AACnD,QAAA,KAAK,EAAE,SAAS;AAChB,QAAA,eAAe,EAAE,OAAO;AACxB,QAAA,GAAG,KAAK;AACT,KAAA,CAAC;AAEF,IAAA,MAAM,KAAK,GAAG,OAAO,C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AAG,CAAC,KAAK;yBACZ,EAAA,EAjBrB,CAAC,CAmBN,CACH,CACJ,CAAA,EAAA,CACG,EACL,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,KAI1CA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,UAAU,EAAA,aAAA,EAAc,MAAM,EAAA,QAAA,EAC3C,QAAQ,EAAA,CACL,CACP,CAAA,EAAA,CACG;AAEV,CAAC;AAGH,YAAY,CAAC,WAAW,GAAG,cAAc;;"}
|
|
@@ -10,6 +10,7 @@ import { useAutoLabelId } from './useAutoLabelId.js';
|
|
|
10
10
|
import { useControlLoading } from './controlLoading.js';
|
|
11
11
|
import { spokenText, StatusRegion } from '../helpers/statusRegion.js';
|
|
12
12
|
import { useLatestRef } from '../helpers/useLatestRef.js';
|
|
13
|
+
import { useLocaleMatcher } from '../helpers/localeFormat.js';
|
|
13
14
|
|
|
14
15
|
// What the status region announces: the `empty` content, as the one item
|
|
15
16
|
// it's handed while that content is on screen because of the user's typing.
|
|
@@ -71,6 +72,7 @@ label, labelSize, labelProps, horizontal, message, messageColor, fieldClassName,
|
|
|
71
72
|
needsLabelId: true,
|
|
72
73
|
});
|
|
73
74
|
const { bulmaHelperClasses, rest } = useBulmaClasses(props);
|
|
75
|
+
const matchText = useLocaleMatcher();
|
|
74
76
|
const { classPrefix } = useConfig();
|
|
75
77
|
const containerRef = useRef(null);
|
|
76
78
|
const inputRef = useRef(null);
|
|
@@ -100,6 +102,8 @@ label, labelSize, labelProps, horizontal, message, messageColor, fieldClassName,
|
|
|
100
102
|
// Filter data based on input
|
|
101
103
|
const filteredData = data.filter(item => {
|
|
102
104
|
const displayValue = getDisplayValue(item);
|
|
105
|
+
if (matchText)
|
|
106
|
+
return matchText(displayValue, inputValue);
|
|
103
107
|
return displayValue.toLowerCase().includes(inputValue.toLowerCase());
|
|
104
108
|
});
|
|
105
109
|
// The dropdown shows the options or, when nothing matches, the `empty`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autocomplete.js","sources":["../../../src/form/Autocomplete.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useState,\n useRef,\n useEffect,\n useCallback,\n useId,\n} from 'react';\nimport {\n classNames,\n usePrefixedClassNames,\n prefixedClassNames,\n} from '../helpers/classNames';\nimport { useConfig } from '../helpers/Config';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { useFieldsetDisabled, useInsideField } from './FormContext';\nimport { Field } from './Field';\nimport { FormFieldProps } from './fieldProps';\nimport { useAutoLabelId } from './useAutoLabelId';\nimport { useControlLoading } from './controlLoading';\nimport { StatusRegion, spokenText } from '../helpers/statusRegion';\nimport { useLatestRef } from '../helpers/useLatestRef';\n\n/**\n * An item in the Autocomplete dropdown list.\n */\nexport interface AutocompleteItem {\n /** The value used for filtering and selection. */\n value: string;\n /** Display label (optional). */\n label?: string;\n /** Whether the item is disabled and unselectable. */\n disabled?: boolean;\n [key: string]: unknown;\n}\n\n// What the status region announces: the `empty` content, as the one item\n// it's handed while that content is on screen because of the user's typing.\nconst typedNoMatches = [{ id: 'empty' }];\nconst nothingToAnnounce: Array<{ id: string }> = [];\n\n// A press on an option would take focus from the field, since an option\n// can't hold it, and nothing would put it back. Cancelling the press keeps\n// it there, as the ARIA Authoring Practices' combobox does, and the click\n// still picks the option.\nconst keepFocus = (e: React.MouseEvent) => e.preventDefault();\n\n// An IME that's composing owns every key: Enter confirms what it composed,\n// and the arrows move through its candidates. Safari can say so with\n// `keyCode` 229 rather than `isComposing`.\nconst isComposing = (e: React.KeyboardEvent): boolean =>\n e.nativeEvent.isComposing || e.nativeEvent.keyCode === 229;\n\n// Whether an option can be picked. The arrows still reach a disabled one, so\n// a screen reader user finds it.\nconst isEnabled = (item: AutocompleteItem | string): boolean =>\n typeof item === 'string' || !item.disabled;\n\n/**\n * Props for the Autocomplete component.\n * @extraProp {string} [className] - Additional CSS classes.\n * @extraProp {React.Ref<HTMLInputElement>} [ref] - Ref forwarded to the input element.\n */\nexport interface AutocompleteProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, 'onSelect' | 'onInput'>,\n Omit<BulmaClassesProps, 'color'>,\n FormFieldProps {\n /** Field label, associated with the text input via `htmlFor`: through your `id` when provided, otherwise a generated one. Dropped inside an outer `Field`, whose label names the input instead when it points at it. The `Field` points its label there itself when the Autocomplete has no `id` and no inner `Field` sits between them (and the `Field` is not `grouped` or `hasAddons`); a label you wire by hand with `labelProps.htmlFor` points at the input with that `id`. The label naming the input also names the open suggestion list, through `aria-labelledby`, when it has an id: this label always does, and an outer `Field`'s does unless you wired it by hand without an `id` in its `labelProps`. Otherwise the list is named \"Suggestions\". */\n label?: React.ReactNode;\n /** Props for the label element. An explicit `htmlFor` here overrides the automatic association (the input then gets no generated id). While the label names the input, the suggestion list's `aria-labelledby` points at it, through an `id` here when you give one and a generated one otherwise. */\n labelProps?: React.LabelHTMLAttributes<HTMLLabelElement> & {\n [key: string]: unknown;\n };\n /** Applied to the inner text input (the labellable control), not the wrapper div. */\n id?: string;\n /** The options data to display (required). */\n data: AutocompleteItem[] | string[];\n /** The current input value (controlled). */\n value?: string;\n /**\n * Does nothing: Autocomplete doesn't read it.\n *\n * @deprecated Nothing reads it, and `onSelect` is what reports a pick. It\n * will be removed in the next major version.\n */\n selected?: AutocompleteItem | string | null;\n /** Placeholder text for the input. */\n placeholder?: string;\n /** Object property to use as the display field. */\n field?: string;\n /**\n * Whether to show a clear button while the input holds a value.\n * It hides while the input is disabled, and gives way to a loading\n * spinner at the same right edge: the one `loading` draws, or that of a\n * `Control` with `isLoading` around the Autocomplete.\n */\n clearable?: boolean;\n /** Open dropdown when input is focused. */\n openOnFocus?: boolean;\n /**\n * Keep the first option highlighted whenever the list opens, Up Arrow and\n * Alt+Down Arrow included, and whenever the text in the field changes.\n * While the list is open on a highlighted option that isn't disabled, Enter\n * picks it rather than submitting a form around the field.\n */\n keepFirst?: boolean;\n /** Keep dropdown open after selection. */\n keepOpen?: boolean;\n /** Select highlighted item on click outside. */\n selectOnClickOutside?: boolean;\n /** Maximum dropdown height in pixels. */\n maxHeight?: number;\n /**\n * Does nothing: Autocomplete doesn't read it, and always shows its\n * suggestions in a dropdown.\n *\n * @deprecated It will be removed in the next major version, with nothing\n * in its place.\n */\n dropdown?: boolean;\n /**\n * Show a loading spinner in the input.\n * Under `prefers-reduced-motion: reduce` the spinner stops and stays\n * drawn (with bestax's CSS loaded).\n */\n loading?: boolean;\n /** Whether the input is disabled. */\n disabled?: boolean;\n /** Enables infinite scroll detection in the dropdown. */\n checkInfiniteScroll?: boolean;\n /** Distance in pixels from the bottom to trigger `onInfiniteScroll`. */\n infiniteScrollDistance?: number;\n /** Input color variant. */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Size variant. */\n size?: 'small' | 'medium' | 'large';\n /** Form field name. Forwarded to the inner `<input>`. */\n name?: string;\n /** Optional id of the form the input belongs to. */\n form?: string;\n /** Marks the field as required for native HTML form validation. */\n required?: boolean;\n /** Callback when input value changes. */\n onInput?: (value: string) => void;\n /** Callback when item is selected. */\n onSelect?: (item: AutocompleteItem | string | null) => void;\n /** Callback when dropdown active state changes. */\n onActiveChange?: (active: boolean) => void;\n /** Callback when scrolled to bottom (infinite scroll). */\n onInfiniteScroll?: () => void;\n /** Custom render for items. */\n itemTemplate?: (item: AutocompleteItem | string) => React.ReactNode;\n /** Custom header at the top of the dropdown. It sits above the list of options rather than in it, so assistive technology doesn't count it as one. */\n header?: React.ReactNode;\n /** Custom footer at the bottom of the dropdown. It sits below the list of options rather than in it, so assistive technology doesn't count it as one. */\n footer?: React.ReactNode;\n /**\n * A message the dropdown shows in place of the options when nothing\n * matches. Keep it to text: `Tab` closes the list, so a keyboard user\n * can't reach a link or button in it. It sits beside the list of options\n * rather than in it, so the input's `aria-expanded` stays false while it\n * shows. When the user's typing leaves nothing that matches, a polite\n * status region announces its text: once each time the matches run out.\n * The text is read when they first run out, and isn't read again as it\n * changes while they stay out, so a message that names the query is heard\n * for that first query only. Keep it static.\n * Opening the list without typing, or emptying the field, announces\n * nothing. While `loading`, or a `Control` with `isLoading` around the\n * Autocomplete, is on, it waits, and it's announced once loading ends\n * with nothing matching. Without `empty`, the dropdown closes when nothing\n * matches and nothing is announced.\n */\n empty?: React.ReactNode;\n}\n\n/**\n * The `Autocomplete` component provides an input field with dropdown suggestions that filter based on user input.\n *\n * @function\n * @param {AutocompleteProps} props - Props for the Autocomplete component.\n * @param {React.Ref<HTMLInputElement>} ref - Forwarded ref to the input element.\n * @returns {JSX.Element} The rendered autocomplete component.\n *\n * @example\n * // Basic usage with string array\n * <Autocomplete\n * data={['Apple', 'Banana', 'Cherry']}\n * placeholder=\"Search fruit...\"\n * onSelect={(item) => console.log(item)}\n * />\n *\n * @example\n * // With object data\n * <Autocomplete\n * data={[{ value: '1', label: 'Option 1' }, { value: '2', label: 'Option 2' }]}\n * field=\"label\"\n * onSelect={(item) => console.log(item)}\n * />\n */\nexport const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(\n (\n {\n data = [],\n value: controlledValue,\n placeholder,\n field = 'label',\n clearable = false,\n openOnFocus = false,\n keepFirst = false,\n keepOpen = false,\n selectOnClickOutside = false,\n maxHeight = 200,\n loading = false,\n disabled: disabledProp,\n checkInfiniteScroll = false,\n infiniteScrollDistance = 50,\n color,\n size,\n onInput,\n onSelect,\n onActiveChange,\n onInfiniteScroll,\n itemTemplate,\n header,\n footer,\n empty,\n name,\n form,\n required,\n id,\n // Deprecated no-ops, taken here so they stay off the wrapper.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- deprecated no-op\n selected,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- deprecated no-op\n dropdown,\n // Field props\n label,\n labelSize,\n labelProps,\n horizontal,\n message,\n messageColor,\n fieldClassName,\n className,\n ...props\n },\n ref\n ) => {\n const disabled = useFieldsetDisabled(disabledProp);\n const insideField = useInsideField();\n // The suggestion list points `aria-labelledby` at the label that names\n // the input, so it needs that label's id.\n const {\n controlId,\n fieldLabelProps,\n labelId: listLabelId,\n } = useAutoLabelId({\n label,\n id,\n labelProps,\n rendersLabel: !insideField,\n needsLabelId: true,\n });\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const { classPrefix } = useConfig();\n const containerRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const dropdownRef = useRef<HTMLDivElement>(null);\n\n const [internalValue, setInternalValue] = useState('');\n const [isActive, setIsActive] = useState(false);\n // Whether the user has typed since the list opened, since only typing\n // gets the `empty` content announced. Closing the list resets it (during\n // render, React's pattern for adjusting state when other state changes),\n // so opening the list again without typing stays quiet.\n const [typed, setTyped] = useState(false);\n if (typed && !isActive) setTyped(false);\n const [highlightedIndex, setHighlightedIndex] = useState(-1);\n const listboxId = `${useId()}-listbox`;\n\n // Use controlled or internal value\n const inputValue =\n controlledValue !== undefined ? controlledValue : internalValue;\n\n // Get display value from item\n const getDisplayValue = (item: AutocompleteItem | string): string => {\n if (typeof item === 'string') return item;\n const fieldValue = item[field];\n if (typeof fieldValue === 'string') return fieldValue;\n return item.value || '';\n };\n\n // Filter data based on input\n const filteredData = data.filter(item => {\n const displayValue = getDisplayValue(item);\n return displayValue.toLowerCase().includes(inputValue.toLowerCase());\n });\n\n // The dropdown shows the options or, when nothing matches, the `empty`\n // content. The listbox holds only options, so it's on screen only while\n // there are some.\n const menuOpen = isActive && (filteredData.length > 0 || !!empty);\n const listOpen = isActive && filteredData.length > 0;\n\n // Handle input change\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = e.target.value;\n if (controlledValue === undefined) {\n setInternalValue(newValue);\n }\n onInput?.(newValue);\n setTyped(true);\n if (!isActive && newValue) {\n setIsActive(true);\n }\n },\n [controlledValue, isActive, onInput]\n );\n\n // Handle item selection\n const handleSelect = useCallback(\n (item: AutocompleteItem | string) => {\n if (typeof item !== 'string' && item.disabled) return;\n\n const displayValue = getDisplayValue(item);\n if (controlledValue === undefined) {\n setInternalValue(displayValue);\n }\n onInput?.(displayValue);\n onSelect?.(item);\n\n if (!keepOpen) {\n setIsActive(false);\n }\n setHighlightedIndex(-1);\n },\n [controlledValue, field, keepOpen, onInput, onSelect]\n );\n\n // Handle clear\n const handleClear = useCallback(() => {\n if (controlledValue === undefined) {\n setInternalValue('');\n }\n onInput?.('');\n onSelect?.(null);\n inputRef.current?.focus();\n }, [controlledValue, onInput, onSelect]);\n\n // Handle focus\n const handleFocus = useCallback(() => {\n if (openOnFocus && !disabled) {\n setIsActive(true);\n }\n }, [openOnFocus, disabled]);\n\n // Read when a click lands outside, so the listener stays put while the\n // list is open. What it selects changes as the user types and arrows\n // through suggestions, the filtered list is new on every render, and an\n // inline `onInput` or `onSelect` changes on every render of the parent.\n // Typing leaves the highlight where it was, so a list that narrowed can\n // leave it past the last suggestion, with nothing there to select.\n const selectHighlightedRef = useLatestRef(() => {\n if (\n selectOnClickOutside &&\n highlightedIndex >= 0 &&\n highlightedIndex < filteredData.length\n ) {\n handleSelect(filteredData[highlightedIndex]);\n }\n });\n\n // Handle blur (click outside)\n useEffect(() => {\n if (!isActive) return undefined;\n\n const handleClickOutside = (e: MouseEvent) => {\n if (!containerRef.current) return;\n\n // Use composedPath() to correctly detect clicks inside Shadow DOM\n const path = e.composedPath();\n const isInside = path.includes(containerRef.current);\n\n if (!isInside) {\n selectHighlightedRef.current();\n setIsActive(false);\n }\n };\n\n document.addEventListener('mousedown', handleClickOutside);\n return () =>\n document.removeEventListener('mousedown', handleClickOutside);\n }, [isActive, selectHighlightedRef]);\n\n // Read when the dropdown opens or closes, so an inline `onActiveChange`,\n // new on every render of the parent, isn't told again about a state that\n // didn't change.\n const onActiveChangeRef = useLatestRef(onActiveChange);\n\n // Notify active state change\n useEffect(() => {\n onActiveChangeRef.current?.(isActive);\n }, [isActive, onActiveChangeRef]);\n\n // Keep first highlighted\n useEffect(() => {\n if (keepFirst && isActive && filteredData.length > 0) {\n setHighlightedIndex(0);\n }\n }, [keepFirst, isActive, filteredData.length, inputValue]);\n\n // Handle keyboard navigation\n const handleKeyDown = useCallback(\n (e: React.KeyboardEvent) => {\n if (disabled || isComposing(e)) return;\n\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!isActive) {\n // A closed list opens on its first enabled option, as the ARIA\n // Authoring Practices' combobox does. Alt+Down Arrow opens it\n // without a highlight.\n setIsActive(true);\n setHighlightedIndex(\n e.altKey ? -1 : filteredData.map(isEnabled).indexOf(true)\n );\n } else {\n setHighlightedIndex(prev =>\n prev < filteredData.length - 1 ? prev + 1 : prev\n );\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n if (!isActive) {\n // And Up Arrow opens it on its last enabled option.\n setIsActive(true);\n setHighlightedIndex(\n filteredData.map(isEnabled).lastIndexOf(true)\n );\n } else {\n setHighlightedIndex(prev => (prev > 0 ? prev - 1 : prev));\n }\n break;\n case 'Enter':\n // With the list open on a highlighted option it can pick, Enter\n // is that option's. Otherwise it closes the list and goes on, so\n // a form around the field submits, as it would from any text\n // field.\n if (\n isActive &&\n highlightedIndex >= 0 &&\n filteredData[highlightedIndex] &&\n isEnabled(filteredData[highlightedIndex])\n ) {\n e.preventDefault();\n handleSelect(filteredData[highlightedIndex]);\n } else {\n setIsActive(false);\n }\n break;\n case 'Escape':\n // Only closing the dropdown claims the key. With it closed, the\n // key goes on to a Modal around the field.\n if (menuOpen) e.preventDefault();\n setIsActive(false);\n setHighlightedIndex(-1);\n break;\n case 'Tab':\n if (\n isActive &&\n highlightedIndex >= 0 &&\n filteredData[highlightedIndex]\n ) {\n handleSelect(filteredData[highlightedIndex]);\n }\n setIsActive(false);\n break;\n }\n },\n [\n disabled,\n isActive,\n menuOpen,\n highlightedIndex,\n filteredData,\n handleSelect,\n ]\n );\n\n // Handle dropdown scroll for infinite scroll\n const handleDropdownScroll = useCallback(() => {\n if (!checkInfiniteScroll || !dropdownRef.current) return;\n\n const { scrollTop, scrollHeight, clientHeight } = dropdownRef.current;\n if (scrollHeight - scrollTop - clientHeight <= infiniteScrollDistance) {\n onInfiniteScroll?.();\n }\n }, [checkInfiniteScroll, infiniteScrollDistance, onInfiniteScroll]);\n\n // Scroll highlighted item into view\n useEffect(() => {\n if (highlightedIndex >= 0 && dropdownRef.current) {\n const highlightedEl = dropdownRef.current.querySelector(\n `[data-index=\"${highlightedIndex}\"]`\n );\n if (\n highlightedEl &&\n typeof highlightedEl.scrollIntoView === 'function'\n ) {\n highlightedEl.scrollIntoView({ block: 'nearest' });\n }\n }\n }, [highlightedIndex]);\n\n // Combined ref\n const combinedRef = useCallback(\n (node: HTMLInputElement | null) => {\n (inputRef as React.MutableRefObject<HTMLInputElement | null>).current =\n node;\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) {\n (ref as React.MutableRefObject<HTMLInputElement | null>).current =\n node;\n }\n },\n [ref]\n );\n\n // Generate classes\n const autocompleteClasses = usePrefixedClassNames('autocomplete', {\n 'is-active': isActive,\n [`is-${size}`]: !!size,\n });\n\n const inputClasses = usePrefixedClassNames('input', {\n [`is-${color}`]: !!color,\n [`is-${size}`]: !!size,\n 'is-loading': loading,\n });\n\n const controlClasses = usePrefixedClassNames(\n 'control',\n 'is-expanded',\n 'has-icons-right'\n );\n\n const dropdownMenuClasses = usePrefixedClassNames('dropdown-menu', {\n 'is-active': menuOpen,\n });\n\n const dropdownContentClass = usePrefixedClassNames('dropdown-content');\n const dropdownHeaderClass = usePrefixedClassNames('dropdown-header');\n const dropdownFooterClass = usePrefixedClassNames('dropdown-footer');\n const emptyItemClasses = usePrefixedClassNames(\n 'dropdown-item',\n 'has-text-grey'\n );\n\n const iconRightClickableClass = usePrefixedClassNames(\n 'icon',\n 'is-right',\n 'is-clickable'\n );\n const iconRightClass = usePrefixedClassNames('icon', 'is-right');\n const loaderClass = usePrefixedClassNames('loader', 'is-loading');\n\n const combinedClasses = classNames(\n autocompleteClasses,\n bulmaHelperClasses,\n className\n );\n\n const helpClass = usePrefixedClassNames('help', {\n [`is-${messageColor}`]: !!messageColor,\n });\n const messageEl = message ? <p className={helpClass}>{message}</p> : null;\n\n // The clear button gives way to a spinner at its spot: the `loading` one,\n // or that of a loading Control this sits in.\n const controlLoading = useControlLoading();\n const showClear =\n clearable && !!inputValue && !disabled && !loading && !controlLoading;\n\n // The combobox controls its listbox and points at the highlighted option.\n // The listbox takes its name from the label that names the combobox, the\n // one this renders or a surrounding Field's, so the two say the same\n // thing. When no label names the combobox, or the one that does has no\n // id to point at, the list keeps a fallback name. While the dropdown\n // shows only the `empty` content there's no listbox, so the combobox is\n // collapsed and points at nothing.\n const activeOptionId =\n listOpen &&\n highlightedIndex >= 0 &&\n highlightedIndex < filteredData.length\n ? `${listboxId}-${highlightedIndex}`\n : undefined;\n\n // A polite status region, in the page from the start so it's there\n // before anything is written into it, announces the `empty` content\n // when the user's typing leaves nothing that matches what's in the\n // field. It follows what's on screen, so results that come in after the\n // typing count too. It's said once each time that happens, not again on\n // each keystroke while nothing matches. An empty field isn't a search,\n // so it stays quiet then, even with no data. While `loading`, or a\n // loading Control around it, says results are on their way, it waits,\n // and it's said once loading ends with nothing matching.\n const emptyItems =\n typed &&\n menuOpen &&\n !listOpen &&\n !!inputValue &&\n !loading &&\n !controlLoading\n ? typedNoMatches\n : nothingToAnnounce;\n // The region reads the text on screen, whatever `empty` renders.\n const emptyRef = useRef<HTMLDivElement>(null);\n const describeEmpty = useCallback(() => {\n const node = emptyRef.current;\n /* istanbul ignore if: it's only announced while it's on screen */\n if (!node) return null;\n return spokenText(node);\n }, []);\n\n const autocompleteElement = (\n <div ref={containerRef} className={combinedClasses} {...rest}>\n <div className={controlClasses}>\n <input\n ref={combinedRef}\n type=\"text\"\n className={inputClasses}\n id={controlId}\n value={inputValue}\n placeholder={placeholder}\n disabled={disabled}\n name={name}\n form={form}\n required={required}\n onChange={handleInputChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n role=\"combobox\"\n aria-expanded={listOpen}\n aria-controls={listOpen ? listboxId : undefined}\n aria-activedescendant={activeOptionId}\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n autoComplete=\"off\"\n />\n {showClear && (\n <button\n type=\"button\"\n className={iconRightClickableClass}\n onClick={handleClear}\n aria-label=\"Clear\"\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n width=\"16\"\n height=\"16\"\n aria-hidden=\"true\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" />\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" />\n </svg>\n </button>\n )}\n {loading && (\n <span className={iconRightClass}>\n <span className={loaderClass} />\n </span>\n )}\n </div>\n\n {menuOpen && (\n <div className={dropdownMenuClasses}>\n <div\n ref={dropdownRef}\n className={dropdownContentClass}\n style={{ maxHeight: `${maxHeight}px`, overflowY: 'auto' }}\n onScroll={handleDropdownScroll}\n >\n {header && <div className={dropdownHeaderClass}>{header}</div>}\n\n {listOpen ? (\n <div\n id={listboxId}\n role=\"listbox\"\n aria-labelledby={listLabelId}\n aria-label={listLabelId ? undefined : 'Suggestions'}\n onMouseDown={keepFocus}\n >\n {filteredData.map((item, index) => {\n const isDisabled =\n typeof item !== 'string' && item.disabled;\n const isHighlighted = index === highlightedIndex;\n\n const itemClasses = prefixedClassNames(\n classPrefix,\n 'dropdown-item',\n {\n 'is-active': isHighlighted,\n 'is-disabled': isDisabled,\n }\n );\n\n return (\n <a\n key={index}\n id={`${listboxId}-${index}`}\n data-index={index}\n className={itemClasses}\n onClick={() => !isDisabled && handleSelect(item)}\n onMouseEnter={() =>\n !isDisabled && setHighlightedIndex(index)\n }\n role=\"option\"\n aria-selected={isHighlighted && !isDisabled}\n aria-disabled={isDisabled}\n >\n {itemTemplate\n ? itemTemplate(item)\n : getDisplayValue(item)}\n </a>\n );\n })}\n </div>\n ) : (\n <div\n ref={emptyRef}\n className={emptyItemClasses}\n onMouseDown={keepFocus}\n >\n {empty}\n </div>\n )}\n\n {footer && <div className={dropdownFooterClass}>{footer}</div>}\n </div>\n </div>\n )}\n\n <StatusRegion items={emptyItems} describe={describeEmpty} />\n </div>\n );\n\n if (!insideField) {\n return (\n <Field\n label={label}\n labelSize={labelSize}\n labelProps={fieldLabelProps}\n horizontal={horizontal}\n className={fieldClassName}\n >\n {autocompleteElement}\n {messageEl}\n </Field>\n );\n }\n\n return (\n <>\n {autocompleteElement}\n {messageEl}\n </>\n );\n }\n);\n\nAutocomplete.displayName = 'Autocomplete';\n\nexport default Autocomplete;\n"],"names":["typedNoMatches","nothingToAnnounce","isComposing","_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;;;;;;;AAoCA;AACA;AACA,MAAMA,gBAAc,GAAG,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;AACxC,MAAMC,mBAAiB,GAA0B,EAAE;AAEnD;AACA;AACA;AACA;AACA,MAAM,SAAS,GAAG,CAAC,CAAmB,KAAK,CAAC,CAAC,cAAc,EAAE;AAE7D;AACA;AACA;AACA,MAAMC,aAAW,GAAG,CAAC,CAAsB,KACzC,CAAC,CAAC,WAAW,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,CAAC,OAAO,KAAK,GAAG;AAE5D;AACA;AACA,MAAM,SAAS,GAAG,CAAC,IAA+B,KAChD,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ;AAwH5C;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACI,MAAM,YAAY,GAAG,UAAU,CACpC,CACE,EACE,IAAI,GAAG,EAAE,EACT,KAAK,EAAE,eAAe,EACtB,WAAW,EACX,KAAK,GAAG,OAAO,EACf,SAAS,GAAG,KAAK,EACjB,WAAW,GAAG,KAAK,EACnB,SAAS,GAAG,KAAK,EACjB,QAAQ,GAAG,KAAK,EAChB,oBAAoB,GAAG,KAAK,EAC5B,SAAS,GAAG,GAAG,EACf,OAAO,GAAG,KA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A,CAAC,KAAK,EAAA,EACJ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,eAAe,EAC3B,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,cAAc,EAAA,QAAA,EAAA,CAExB,mBAAmB,EACnB,SAAS,CAAA,EAAA,CACJ;IAEZ;AAEA,IAAA,QACEA,IAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,CACG,mBAAmB,EACnB,SAAS,CAAA,EAAA,CACT;AAEP,CAAC;AAGH,YAAY,CAAC,WAAW,GAAG,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"Autocomplete.js","sources":["../../../src/form/Autocomplete.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useState,\n useRef,\n useEffect,\n useCallback,\n useId,\n} from 'react';\nimport {\n classNames,\n usePrefixedClassNames,\n prefixedClassNames,\n} from '../helpers/classNames';\nimport { useConfig } from '../helpers/Config';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { useFieldsetDisabled, useInsideField } from './FormContext';\nimport { Field } from './Field';\nimport { FormFieldProps } from './fieldProps';\nimport { useAutoLabelId } from './useAutoLabelId';\nimport { useControlLoading } from './controlLoading';\nimport { StatusRegion, spokenText } from '../helpers/statusRegion';\nimport { useLatestRef } from '../helpers/useLatestRef';\nimport { useLocaleMatcher } from '../helpers/localeFormat';\n\n/**\n * An item in the Autocomplete dropdown list.\n */\nexport interface AutocompleteItem {\n /** The value used for filtering and selection. */\n value: string;\n /** Display label (optional). */\n label?: string;\n /** Whether the item is disabled and unselectable. */\n disabled?: boolean;\n [key: string]: unknown;\n}\n\n// What the status region announces: the `empty` content, as the one item\n// it's handed while that content is on screen because of the user's typing.\nconst typedNoMatches = [{ id: 'empty' }];\nconst nothingToAnnounce: Array<{ id: string }> = [];\n\n// A press on an option would take focus from the field, since an option\n// can't hold it, and nothing would put it back. Cancelling the press keeps\n// it there, as the ARIA Authoring Practices' combobox does, and the click\n// still picks the option.\nconst keepFocus = (e: React.MouseEvent) => e.preventDefault();\n\n// An IME that's composing owns every key: Enter confirms what it composed,\n// and the arrows move through its candidates. Safari can say so with\n// `keyCode` 229 rather than `isComposing`.\nconst isComposing = (e: React.KeyboardEvent): boolean =>\n e.nativeEvent.isComposing || e.nativeEvent.keyCode === 229;\n\n// Whether an option can be picked. The arrows still reach a disabled one, so\n// a screen reader user finds it.\nconst isEnabled = (item: AutocompleteItem | string): boolean =>\n typeof item === 'string' || !item.disabled;\n\n/**\n * Props for the Autocomplete component.\n * @extraProp {string} [className] - Additional CSS classes.\n * @extraProp {React.Ref<HTMLInputElement>} [ref] - Ref forwarded to the input element.\n */\nexport interface AutocompleteProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, 'onSelect' | 'onInput'>,\n Omit<BulmaClassesProps, 'color'>,\n FormFieldProps {\n /** Field label, associated with the text input via `htmlFor`: through your `id` when provided, otherwise a generated one. Dropped inside an outer `Field`, whose label names the input instead when it points at it. The `Field` points its label there itself when the Autocomplete has no `id` and no inner `Field` sits between them (and the `Field` is not `grouped` or `hasAddons`); a label you wire by hand with `labelProps.htmlFor` points at the input with that `id`. The label naming the input also names the open suggestion list, through `aria-labelledby`, when it has an id: this label always does, and an outer `Field`'s does unless you wired it by hand without an `id` in its `labelProps`. Otherwise the list is named \"Suggestions\". */\n label?: React.ReactNode;\n /** Props for the label element. An explicit `htmlFor` here overrides the automatic association (the input then gets no generated id). While the label names the input, the suggestion list's `aria-labelledby` points at it, through an `id` here when you give one and a generated one otherwise. */\n labelProps?: React.LabelHTMLAttributes<HTMLLabelElement> & {\n [key: string]: unknown;\n };\n /** Applied to the inner text input (the labellable control), not the wrapper div. */\n id?: string;\n /**\n * The options data to display (required). The list shows the options that\n * contain what's typed, ignoring case, and inside a `LocaleProvider` with a\n * `locale`, ignoring accents too where that language does, so \"cafe\" finds\n * \"Café\".\n */\n data: AutocompleteItem[] | string[];\n /** The current input value (controlled). */\n value?: string;\n /**\n * Does nothing: Autocomplete doesn't read it.\n *\n * @deprecated Nothing reads it, and `onSelect` is what reports a pick. It\n * will be removed in the next major version.\n */\n selected?: AutocompleteItem | string | null;\n /** Placeholder text for the input. */\n placeholder?: string;\n /** Object property to use as the display field. */\n field?: string;\n /**\n * Whether to show a clear button while the input holds a value.\n * It hides while the input is disabled, and gives way to a loading\n * spinner at the same right edge: the one `loading` draws, or that of a\n * `Control` with `isLoading` around the Autocomplete.\n */\n clearable?: boolean;\n /** Open dropdown when input is focused. */\n openOnFocus?: boolean;\n /**\n * Keep the first option highlighted whenever the list opens, Up Arrow and\n * Alt+Down Arrow included, and whenever the text in the field changes.\n * While the list is open on a highlighted option that isn't disabled, Enter\n * picks it rather than submitting a form around the field.\n */\n keepFirst?: boolean;\n /** Keep dropdown open after selection. */\n keepOpen?: boolean;\n /** Select highlighted item on click outside. */\n selectOnClickOutside?: boolean;\n /** Maximum dropdown height in pixels. */\n maxHeight?: number;\n /**\n * Does nothing: Autocomplete doesn't read it, and always shows its\n * suggestions in a dropdown.\n *\n * @deprecated It will be removed in the next major version, with nothing\n * in its place.\n */\n dropdown?: boolean;\n /**\n * Show a loading spinner in the input.\n * Under `prefers-reduced-motion: reduce` the spinner stops and stays\n * drawn (with bestax's CSS loaded).\n */\n loading?: boolean;\n /** Whether the input is disabled. */\n disabled?: boolean;\n /** Enables infinite scroll detection in the dropdown. */\n checkInfiniteScroll?: boolean;\n /** Distance in pixels from the bottom to trigger `onInfiniteScroll`. */\n infiniteScrollDistance?: number;\n /** Input color variant. */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Size variant. */\n size?: 'small' | 'medium' | 'large';\n /** Form field name. Forwarded to the inner `<input>`. */\n name?: string;\n /** Optional id of the form the input belongs to. */\n form?: string;\n /** Marks the field as required for native HTML form validation. */\n required?: boolean;\n /** Callback when input value changes. */\n onInput?: (value: string) => void;\n /** Callback when item is selected. */\n onSelect?: (item: AutocompleteItem | string | null) => void;\n /** Callback when dropdown active state changes. */\n onActiveChange?: (active: boolean) => void;\n /** Callback when scrolled to bottom (infinite scroll). */\n onInfiniteScroll?: () => void;\n /** Custom render for items. */\n itemTemplate?: (item: AutocompleteItem | string) => React.ReactNode;\n /** Custom header at the top of the dropdown. It sits above the list of options rather than in it, so assistive technology doesn't count it as one. */\n header?: React.ReactNode;\n /** Custom footer at the bottom of the dropdown. It sits below the list of options rather than in it, so assistive technology doesn't count it as one. */\n footer?: React.ReactNode;\n /**\n * A message the dropdown shows in place of the options when nothing\n * matches. Keep it to text: `Tab` closes the list, so a keyboard user\n * can't reach a link or button in it. It sits beside the list of options\n * rather than in it, so the input's `aria-expanded` stays false while it\n * shows. When the user's typing leaves nothing that matches, a polite\n * status region announces its text: once each time the matches run out.\n * The text is read when they first run out, and isn't read again as it\n * changes while they stay out, so a message that names the query is heard\n * for that first query only. Keep it static.\n * Opening the list without typing, or emptying the field, announces\n * nothing. While `loading`, or a `Control` with `isLoading` around the\n * Autocomplete, is on, it waits, and it's announced once loading ends\n * with nothing matching. Without `empty`, the dropdown closes when nothing\n * matches and nothing is announced.\n */\n empty?: React.ReactNode;\n}\n\n/**\n * The `Autocomplete` component provides an input field with dropdown suggestions that filter based on user input.\n *\n * @function\n * @param {AutocompleteProps} props - Props for the Autocomplete component.\n * @param {React.Ref<HTMLInputElement>} ref - Forwarded ref to the input element.\n * @returns {JSX.Element} The rendered autocomplete component.\n *\n * @example\n * // Basic usage with string array\n * <Autocomplete\n * data={['Apple', 'Banana', 'Cherry']}\n * placeholder=\"Search fruit...\"\n * onSelect={(item) => console.log(item)}\n * />\n *\n * @example\n * // With object data\n * <Autocomplete\n * data={[{ value: '1', label: 'Option 1' }, { value: '2', label: 'Option 2' }]}\n * field=\"label\"\n * onSelect={(item) => console.log(item)}\n * />\n */\nexport const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(\n (\n {\n data = [],\n value: controlledValue,\n placeholder,\n field = 'label',\n clearable = false,\n openOnFocus = false,\n keepFirst = false,\n keepOpen = false,\n selectOnClickOutside = false,\n maxHeight = 200,\n loading = false,\n disabled: disabledProp,\n checkInfiniteScroll = false,\n infiniteScrollDistance = 50,\n color,\n size,\n onInput,\n onSelect,\n onActiveChange,\n onInfiniteScroll,\n itemTemplate,\n header,\n footer,\n empty,\n name,\n form,\n required,\n id,\n // Deprecated no-ops, taken here so they stay off the wrapper.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- deprecated no-op\n selected,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- deprecated no-op\n dropdown,\n // Field props\n label,\n labelSize,\n labelProps,\n horizontal,\n message,\n messageColor,\n fieldClassName,\n className,\n ...props\n },\n ref\n ) => {\n const disabled = useFieldsetDisabled(disabledProp);\n const insideField = useInsideField();\n // The suggestion list points `aria-labelledby` at the label that names\n // the input, so it needs that label's id.\n const {\n controlId,\n fieldLabelProps,\n labelId: listLabelId,\n } = useAutoLabelId({\n label,\n id,\n labelProps,\n rendersLabel: !insideField,\n needsLabelId: true,\n });\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const matchText = useLocaleMatcher();\n const { classPrefix } = useConfig();\n const containerRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const dropdownRef = useRef<HTMLDivElement>(null);\n\n const [internalValue, setInternalValue] = useState('');\n const [isActive, setIsActive] = useState(false);\n // Whether the user has typed since the list opened, since only typing\n // gets the `empty` content announced. Closing the list resets it (during\n // render, React's pattern for adjusting state when other state changes),\n // so opening the list again without typing stays quiet.\n const [typed, setTyped] = useState(false);\n if (typed && !isActive) setTyped(false);\n const [highlightedIndex, setHighlightedIndex] = useState(-1);\n const listboxId = `${useId()}-listbox`;\n\n // Use controlled or internal value\n const inputValue =\n controlledValue !== undefined ? controlledValue : internalValue;\n\n // Get display value from item\n const getDisplayValue = (item: AutocompleteItem | string): string => {\n if (typeof item === 'string') return item;\n const fieldValue = item[field];\n if (typeof fieldValue === 'string') return fieldValue;\n return item.value || '';\n };\n\n // Filter data based on input\n const filteredData = data.filter(item => {\n const displayValue = getDisplayValue(item);\n if (matchText) return matchText(displayValue, inputValue);\n return displayValue.toLowerCase().includes(inputValue.toLowerCase());\n });\n\n // The dropdown shows the options or, when nothing matches, the `empty`\n // content. The listbox holds only options, so it's on screen only while\n // there are some.\n const menuOpen = isActive && (filteredData.length > 0 || !!empty);\n const listOpen = isActive && filteredData.length > 0;\n\n // Handle input change\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = e.target.value;\n if (controlledValue === undefined) {\n setInternalValue(newValue);\n }\n onInput?.(newValue);\n setTyped(true);\n if (!isActive && newValue) {\n setIsActive(true);\n }\n },\n [controlledValue, isActive, onInput]\n );\n\n // Handle item selection\n const handleSelect = useCallback(\n (item: AutocompleteItem | string) => {\n if (typeof item !== 'string' && item.disabled) return;\n\n const displayValue = getDisplayValue(item);\n if (controlledValue === undefined) {\n setInternalValue(displayValue);\n }\n onInput?.(displayValue);\n onSelect?.(item);\n\n if (!keepOpen) {\n setIsActive(false);\n }\n setHighlightedIndex(-1);\n },\n [controlledValue, field, keepOpen, onInput, onSelect]\n );\n\n // Handle clear\n const handleClear = useCallback(() => {\n if (controlledValue === undefined) {\n setInternalValue('');\n }\n onInput?.('');\n onSelect?.(null);\n inputRef.current?.focus();\n }, [controlledValue, onInput, onSelect]);\n\n // Handle focus\n const handleFocus = useCallback(() => {\n if (openOnFocus && !disabled) {\n setIsActive(true);\n }\n }, [openOnFocus, disabled]);\n\n // Read when a click lands outside, so the listener stays put while the\n // list is open. What it selects changes as the user types and arrows\n // through suggestions, the filtered list is new on every render, and an\n // inline `onInput` or `onSelect` changes on every render of the parent.\n // Typing leaves the highlight where it was, so a list that narrowed can\n // leave it past the last suggestion, with nothing there to select.\n const selectHighlightedRef = useLatestRef(() => {\n if (\n selectOnClickOutside &&\n highlightedIndex >= 0 &&\n highlightedIndex < filteredData.length\n ) {\n handleSelect(filteredData[highlightedIndex]);\n }\n });\n\n // Handle blur (click outside)\n useEffect(() => {\n if (!isActive) return undefined;\n\n const handleClickOutside = (e: MouseEvent) => {\n if (!containerRef.current) return;\n\n // Use composedPath() to correctly detect clicks inside Shadow DOM\n const path = e.composedPath();\n const isInside = path.includes(containerRef.current);\n\n if (!isInside) {\n selectHighlightedRef.current();\n setIsActive(false);\n }\n };\n\n document.addEventListener('mousedown', handleClickOutside);\n return () =>\n document.removeEventListener('mousedown', handleClickOutside);\n }, [isActive, selectHighlightedRef]);\n\n // Read when the dropdown opens or closes, so an inline `onActiveChange`,\n // new on every render of the parent, isn't told again about a state that\n // didn't change.\n const onActiveChangeRef = useLatestRef(onActiveChange);\n\n // Notify active state change\n useEffect(() => {\n onActiveChangeRef.current?.(isActive);\n }, [isActive, onActiveChangeRef]);\n\n // Keep first highlighted\n useEffect(() => {\n if (keepFirst && isActive && filteredData.length > 0) {\n setHighlightedIndex(0);\n }\n }, [keepFirst, isActive, filteredData.length, inputValue]);\n\n // Handle keyboard navigation\n const handleKeyDown = useCallback(\n (e: React.KeyboardEvent) => {\n if (disabled || isComposing(e)) return;\n\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!isActive) {\n // A closed list opens on its first enabled option, as the ARIA\n // Authoring Practices' combobox does. Alt+Down Arrow opens it\n // without a highlight.\n setIsActive(true);\n setHighlightedIndex(\n e.altKey ? -1 : filteredData.map(isEnabled).indexOf(true)\n );\n } else {\n setHighlightedIndex(prev =>\n prev < filteredData.length - 1 ? prev + 1 : prev\n );\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n if (!isActive) {\n // And Up Arrow opens it on its last enabled option.\n setIsActive(true);\n setHighlightedIndex(\n filteredData.map(isEnabled).lastIndexOf(true)\n );\n } else {\n setHighlightedIndex(prev => (prev > 0 ? prev - 1 : prev));\n }\n break;\n case 'Enter':\n // With the list open on a highlighted option it can pick, Enter\n // is that option's. Otherwise it closes the list and goes on, so\n // a form around the field submits, as it would from any text\n // field.\n if (\n isActive &&\n highlightedIndex >= 0 &&\n filteredData[highlightedIndex] &&\n isEnabled(filteredData[highlightedIndex])\n ) {\n e.preventDefault();\n handleSelect(filteredData[highlightedIndex]);\n } else {\n setIsActive(false);\n }\n break;\n case 'Escape':\n // Only closing the dropdown claims the key. With it closed, the\n // key goes on to a Modal around the field.\n if (menuOpen) e.preventDefault();\n setIsActive(false);\n setHighlightedIndex(-1);\n break;\n case 'Tab':\n if (\n isActive &&\n highlightedIndex >= 0 &&\n filteredData[highlightedIndex]\n ) {\n handleSelect(filteredData[highlightedIndex]);\n }\n setIsActive(false);\n break;\n }\n },\n [\n disabled,\n isActive,\n menuOpen,\n highlightedIndex,\n filteredData,\n handleSelect,\n ]\n );\n\n // Handle dropdown scroll for infinite scroll\n const handleDropdownScroll = useCallback(() => {\n if (!checkInfiniteScroll || !dropdownRef.current) return;\n\n const { scrollTop, scrollHeight, clientHeight } = dropdownRef.current;\n if (scrollHeight - scrollTop - clientHeight <= infiniteScrollDistance) {\n onInfiniteScroll?.();\n }\n }, [checkInfiniteScroll, infiniteScrollDistance, onInfiniteScroll]);\n\n // Scroll highlighted item into view\n useEffect(() => {\n if (highlightedIndex >= 0 && dropdownRef.current) {\n const highlightedEl = dropdownRef.current.querySelector(\n `[data-index=\"${highlightedIndex}\"]`\n );\n if (\n highlightedEl &&\n typeof highlightedEl.scrollIntoView === 'function'\n ) {\n highlightedEl.scrollIntoView({ block: 'nearest' });\n }\n }\n }, [highlightedIndex]);\n\n // Combined ref\n const combinedRef = useCallback(\n (node: HTMLInputElement | null) => {\n (inputRef as React.MutableRefObject<HTMLInputElement | null>).current =\n node;\n if (typeof ref === 'function') {\n ref(node);\n } else if (ref) {\n (ref as React.MutableRefObject<HTMLInputElement | null>).current =\n node;\n }\n },\n [ref]\n );\n\n // Generate classes\n const autocompleteClasses = usePrefixedClassNames('autocomplete', {\n 'is-active': isActive,\n [`is-${size}`]: !!size,\n });\n\n const inputClasses = usePrefixedClassNames('input', {\n [`is-${color}`]: !!color,\n [`is-${size}`]: !!size,\n 'is-loading': loading,\n });\n\n const controlClasses = usePrefixedClassNames(\n 'control',\n 'is-expanded',\n 'has-icons-right'\n );\n\n const dropdownMenuClasses = usePrefixedClassNames('dropdown-menu', {\n 'is-active': menuOpen,\n });\n\n const dropdownContentClass = usePrefixedClassNames('dropdown-content');\n const dropdownHeaderClass = usePrefixedClassNames('dropdown-header');\n const dropdownFooterClass = usePrefixedClassNames('dropdown-footer');\n const emptyItemClasses = usePrefixedClassNames(\n 'dropdown-item',\n 'has-text-grey'\n );\n\n const iconRightClickableClass = usePrefixedClassNames(\n 'icon',\n 'is-right',\n 'is-clickable'\n );\n const iconRightClass = usePrefixedClassNames('icon', 'is-right');\n const loaderClass = usePrefixedClassNames('loader', 'is-loading');\n\n const combinedClasses = classNames(\n autocompleteClasses,\n bulmaHelperClasses,\n className\n );\n\n const helpClass = usePrefixedClassNames('help', {\n [`is-${messageColor}`]: !!messageColor,\n });\n const messageEl = message ? <p className={helpClass}>{message}</p> : null;\n\n // The clear button gives way to a spinner at its spot: the `loading` one,\n // or that of a loading Control this sits in.\n const controlLoading = useControlLoading();\n const showClear =\n clearable && !!inputValue && !disabled && !loading && !controlLoading;\n\n // The combobox controls its listbox and points at the highlighted option.\n // The listbox takes its name from the label that names the combobox, the\n // one this renders or a surrounding Field's, so the two say the same\n // thing. When no label names the combobox, or the one that does has no\n // id to point at, the list keeps a fallback name. While the dropdown\n // shows only the `empty` content there's no listbox, so the combobox is\n // collapsed and points at nothing.\n const activeOptionId =\n listOpen &&\n highlightedIndex >= 0 &&\n highlightedIndex < filteredData.length\n ? `${listboxId}-${highlightedIndex}`\n : undefined;\n\n // A polite status region, in the page from the start so it's there\n // before anything is written into it, announces the `empty` content\n // when the user's typing leaves nothing that matches what's in the\n // field. It follows what's on screen, so results that come in after the\n // typing count too. It's said once each time that happens, not again on\n // each keystroke while nothing matches. An empty field isn't a search,\n // so it stays quiet then, even with no data. While `loading`, or a\n // loading Control around it, says results are on their way, it waits,\n // and it's said once loading ends with nothing matching.\n const emptyItems =\n typed &&\n menuOpen &&\n !listOpen &&\n !!inputValue &&\n !loading &&\n !controlLoading\n ? typedNoMatches\n : nothingToAnnounce;\n // The region reads the text on screen, whatever `empty` renders.\n const emptyRef = useRef<HTMLDivElement>(null);\n const describeEmpty = useCallback(() => {\n const node = emptyRef.current;\n /* istanbul ignore if: it's only announced while it's on screen */\n if (!node) return null;\n return spokenText(node);\n }, []);\n\n const autocompleteElement = (\n <div ref={containerRef} className={combinedClasses} {...rest}>\n <div className={controlClasses}>\n <input\n ref={combinedRef}\n type=\"text\"\n className={inputClasses}\n id={controlId}\n value={inputValue}\n placeholder={placeholder}\n disabled={disabled}\n name={name}\n form={form}\n required={required}\n onChange={handleInputChange}\n onFocus={handleFocus}\n onKeyDown={handleKeyDown}\n role=\"combobox\"\n aria-expanded={listOpen}\n aria-controls={listOpen ? listboxId : undefined}\n aria-activedescendant={activeOptionId}\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n autoComplete=\"off\"\n />\n {showClear && (\n <button\n type=\"button\"\n className={iconRightClickableClass}\n onClick={handleClear}\n aria-label=\"Clear\"\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n width=\"16\"\n height=\"16\"\n aria-hidden=\"true\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\" />\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\" />\n </svg>\n </button>\n )}\n {loading && (\n <span className={iconRightClass}>\n <span className={loaderClass} />\n </span>\n )}\n </div>\n\n {menuOpen && (\n <div className={dropdownMenuClasses}>\n <div\n ref={dropdownRef}\n className={dropdownContentClass}\n style={{ maxHeight: `${maxHeight}px`, overflowY: 'auto' }}\n onScroll={handleDropdownScroll}\n >\n {header && <div className={dropdownHeaderClass}>{header}</div>}\n\n {listOpen ? (\n <div\n id={listboxId}\n role=\"listbox\"\n aria-labelledby={listLabelId}\n aria-label={listLabelId ? undefined : 'Suggestions'}\n onMouseDown={keepFocus}\n >\n {filteredData.map((item, index) => {\n const isDisabled =\n typeof item !== 'string' && item.disabled;\n const isHighlighted = index === highlightedIndex;\n\n const itemClasses = prefixedClassNames(\n classPrefix,\n 'dropdown-item',\n {\n 'is-active': isHighlighted,\n 'is-disabled': isDisabled,\n }\n );\n\n return (\n <a\n key={index}\n id={`${listboxId}-${index}`}\n data-index={index}\n className={itemClasses}\n onClick={() => !isDisabled && handleSelect(item)}\n onMouseEnter={() =>\n !isDisabled && setHighlightedIndex(index)\n }\n role=\"option\"\n aria-selected={isHighlighted && !isDisabled}\n aria-disabled={isDisabled}\n >\n {itemTemplate\n ? itemTemplate(item)\n : getDisplayValue(item)}\n </a>\n );\n })}\n </div>\n ) : (\n <div\n ref={emptyRef}\n className={emptyItemClasses}\n onMouseDown={keepFocus}\n >\n {empty}\n </div>\n )}\n\n {footer && <div className={dropdownFooterClass}>{footer}</div>}\n </div>\n </div>\n )}\n\n <StatusRegion items={emptyItems} describe={describeEmpty} />\n </div>\n );\n\n if (!insideField) {\n return (\n <Field\n label={label}\n labelSize={labelSize}\n labelProps={fieldLabelProps}\n horizontal={horizontal}\n className={fieldClassName}\n >\n {autocompleteElement}\n {messageEl}\n </Field>\n );\n }\n\n return (\n <>\n {autocompleteElement}\n {messageEl}\n </>\n );\n }\n);\n\nAutocomplete.displayName = 'Autocomplete';\n\nexport default Autocomplete;\n"],"names":["typedNoMatches","nothingToAnnounce","isComposing","_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;;;;;;;;AAqCA;AACA;AACA,MAAMA,gBAAc,GAAG,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;AACxC,MAAMC,mBAAiB,GAA0B,EAAE;AAEnD;AACA;AACA;AACA;AACA,MAAM,SAAS,GAAG,CAAC,CAAmB,KAAK,CAAC,CAAC,cAAc,EAAE;AAE7D;AACA;AACA;AACA,MAAMC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C,EAE3C,IAAI,EAAC,QAAQ,EAAA,eAAA,EACE,aAAa,IAAI,CAAC,UAAU,EAAA,eAAA,EAC5B,UAAU,EAAA,QAAA,EAExB;AACC,0CAAE,YAAY,CAAC,IAAI;0CACjB,eAAe,CAAC,IAAI,CAAC,EAAA,EAdpB,KAAK,CAeR;4BAER,CAAC,CAAC,GACE,KAENA,GAAA,CAAA,KAAA,EAAA,EACE,GAAG,EAAE,QAAQ,EACb,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,SAAS,EAAA,QAAA,EAErB,KAAK,EAAA,CACF,CACP,EAEA,MAAM,IAAIA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,mBAAmB,EAAA,QAAA,EAAG,MAAM,EAAA,CAAO,CAAA,EAAA,CAC1D,EAAA,CACF,CACP,EAEDA,GAAA,CAAC,YAAY,EAAA,EAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAA,CAAI,CAAA,EAAA,CACxD,CACP;IAED,IAAI,CAAC,WAAW,EAAE;AAChB,QAAA,QACEC,IAAA,CAAC,KAAK,EAAA,EACJ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,eAAe,EAC3B,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,cAAc,EAAA,QAAA,EAAA,CAExB,mBAAmB,EACnB,SAAS,CAAA,EAAA,CACJ;IAEZ;AAEA,IAAA,QACEA,IAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,CACG,mBAAmB,EACnB,SAAS,CAAA,EAAA,CACT;AAEP,CAAC;AAGH,YAAY,CAAC,WAAW,GAAG,cAAc;;"}
|
|
@@ -9,6 +9,7 @@ import { useIsHydrated } from '../helpers/useIsHydrated.js';
|
|
|
9
9
|
import { useClientLayoutEffect } from '../helpers/useClientLayoutEffect.js';
|
|
10
10
|
import { flattenChildren } from '../helpers/flattenChildren.js';
|
|
11
11
|
import { warnOnce } from '../helpers/devWarnings.js';
|
|
12
|
+
import { useLocaleMatcher } from '../helpers/localeFormat.js';
|
|
12
13
|
import { useAnchoredPosition, marginGap } from '../helpers/useAnchoredPosition.js';
|
|
13
14
|
import { spokenText, StatusRegion } from '../helpers/statusRegion.js';
|
|
14
15
|
import { useComboboxEngine } from '../helpers/useComboboxEngine.js';
|
|
@@ -446,6 +447,7 @@ const ComboboxFromData = forwardRef((props, ref) => {
|
|
|
446
447
|
};
|
|
447
448
|
const controlled = value !== undefined;
|
|
448
449
|
const [ownValue, setOwnValue] = useState(() => asList(defaultValue));
|
|
450
|
+
const matchText = useLocaleMatcher();
|
|
449
451
|
const picked = controlled ? asList(value) : ownValue;
|
|
450
452
|
const change = (next) => {
|
|
451
453
|
if (!controlled)
|
|
@@ -473,8 +475,11 @@ const ComboboxFromData = forwardRef((props, ref) => {
|
|
|
473
475
|
}
|
|
474
476
|
setQuery(null);
|
|
475
477
|
};
|
|
476
|
-
const
|
|
477
|
-
const
|
|
478
|
+
const typed = (query ?? '').trim();
|
|
479
|
+
const term = typed.toLowerCase();
|
|
480
|
+
const shown = items.filter(item => matchText
|
|
481
|
+
? matchText(labelOf(item), typed)
|
|
482
|
+
: labelOf(item).toLowerCase().includes(term));
|
|
478
483
|
const inputRef = useRef(null);
|
|
479
484
|
const select = (pick) => {
|
|
480
485
|
onSelect?.(pick);
|