@empathyco/x-components 9.2.0 → 9.3.1
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/CHANGELOG.md +14 -0
- package/core/index.js +2 -0
- package/core/index.js.map +1 -1
- package/docs/API-reference/api/x-components.accessibility_key.md +11 -0
- package/docs/API-reference/api/x-components.aicarousel.md +4 -0
- package/docs/API-reference/api/x-components.arialabels.aicarousel.md +14 -0
- package/docs/API-reference/api/x-components.arialabels.basecolumnpickerdropdown.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.basecolumnpickerlist.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.basedropdown.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.baseeventsmodalclose.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.baseeventsmodalopen.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.basemodal.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.clearhistoryqueries.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.editablenumberrangefilter.md +14 -0
- package/docs/API-reference/api/x-components.arialabels.facets.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.filterssearch.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.historyqueriesswitch.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.historyquery.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.md +419 -0
- package/docs/API-reference/api/x-components.arialabels.pageloaderbutton.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.pageselector.md +16 -0
- package/docs/API-reference/api/x-components.arialabels.removehistoryquery.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.scrolltotop.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.searchinput.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.sliderfilter.md +14 -0
- package/docs/API-reference/api/x-components.arialabels.sortdropdown.md +13 -0
- package/docs/API-reference/api/x-components.basecolumnpickerdropdown.md +3 -0
- package/docs/API-reference/api/x-components.basecolumnpickerlist.md +3 -0
- package/docs/API-reference/api/x-components.basedropdown.md +3 -2
- package/docs/API-reference/api/x-components.baseeventsmodalclose.md +3 -0
- package/docs/API-reference/api/x-components.baseeventsmodalopen.md +3 -0
- package/docs/API-reference/api/x-components.basemodal.md +3 -0
- package/docs/API-reference/api/x-components.clearhistoryqueries.md +3 -0
- package/docs/API-reference/api/x-components.editablenumberrangefilter.md +4 -2
- package/docs/API-reference/api/x-components.facets.md +3 -0
- package/docs/API-reference/api/x-components.filterssearch.md +3 -0
- package/docs/API-reference/api/x-components.historyqueriesswitch.md +3 -0
- package/docs/API-reference/api/x-components.historyquery.md +3 -0
- package/docs/API-reference/api/x-components.md +20 -0
- package/docs/API-reference/api/x-components.pageloaderbutton.md +3 -0
- package/docs/API-reference/api/x-components.pageselector.md +6 -0
- package/docs/API-reference/api/x-components.removehistoryquery.md +3 -0
- package/docs/API-reference/api/x-components.scrolltotop.md +3 -0
- package/docs/API-reference/api/x-components.searchinput.md +3 -0
- package/docs/API-reference/api/x-components.sliderfilter.md +4 -0
- package/docs/API-reference/api/x-components.sortdropdown.md +3 -0
- package/docs/API-reference/components/common/x-components.base-dropdown.md +0 -1
- package/js/components/base-dropdown.vue.js +1 -1
- package/js/components/base-dropdown.vue.js.map +1 -1
- package/js/components/base-dropdown.vue2.js +4 -3
- package/js/components/base-dropdown.vue2.js.map +1 -1
- package/js/components/column-picker/base-column-picker-dropdown.vue.js +2 -2
- package/js/components/column-picker/base-column-picker-dropdown.vue.js.map +1 -1
- package/js/components/column-picker/base-column-picker-dropdown.vue2.js +4 -1
- package/js/components/column-picker/base-column-picker-dropdown.vue2.js.map +1 -1
- package/js/components/column-picker/base-column-picker-list.vue.js +1 -1
- package/js/components/column-picker/base-column-picker-list.vue.js.map +1 -1
- package/js/components/column-picker/base-column-picker-list.vue2.js +4 -2
- package/js/components/column-picker/base-column-picker-list.vue2.js.map +1 -1
- package/js/components/modals/base-events-modal-close.vue.js +2 -2
- package/js/components/modals/base-events-modal-close.vue.js.map +1 -1
- package/js/components/modals/base-events-modal-close.vue2.js +4 -1
- package/js/components/modals/base-events-modal-close.vue2.js.map +1 -1
- package/js/components/modals/base-events-modal-open.vue.js +2 -2
- package/js/components/modals/base-events-modal-open.vue.js.map +1 -1
- package/js/components/modals/base-events-modal-open.vue2.js +4 -1
- package/js/components/modals/base-events-modal-open.vue2.js.map +1 -1
- package/js/components/modals/base-modal.vue.js +11 -16
- package/js/components/modals/base-modal.vue.js.map +1 -1
- package/js/components/modals/base-modal.vue2.js +4 -1
- package/js/components/modals/base-modal.vue2.js.map +1 -1
- package/js/components/page-loader-button.vue.js +2 -2
- package/js/components/page-loader-button.vue.js.map +1 -1
- package/js/components/page-loader-button.vue2.js +4 -1
- package/js/components/page-loader-button.vue2.js.map +1 -1
- package/js/components/page-selector.vue.js +12 -12
- package/js/components/page-selector.vue.js.map +1 -1
- package/js/components/page-selector.vue2.js +4 -1
- package/js/components/page-selector.vue2.js.map +1 -1
- package/js/components/sort/sort-dropdown.vue.js +2 -2
- package/js/components/sort/sort-dropdown.vue.js.map +1 -1
- package/js/components/sort/sort-dropdown.vue2.js +4 -1
- package/js/components/sort/sort-dropdown.vue2.js.map +1 -1
- package/js/index.js +2 -0
- package/js/index.js.map +1 -1
- package/js/types/accessibility.js +4 -0
- package/js/types/accessibility.js.map +1 -0
- package/js/utils/accessibility.js +55 -0
- package/js/utils/accessibility.js.map +1 -0
- package/js/x-installer/x-installer.js +4 -0
- package/js/x-installer/x-installer.js.map +1 -1
- package/js/x-modules/ai/components/ai-carousel.vue.js +8 -3
- package/js/x-modules/ai/components/ai-carousel.vue.js.map +1 -1
- package/js/x-modules/ai/components/ai-carousel.vue2.js +4 -1
- package/js/x-modules/ai/components/ai-carousel.vue2.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue.js +57 -51
- package/js/x-modules/facets/components/facets/facets.vue.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue2.js +4 -1
- package/js/x-modules/facets/components/facets/facets.vue2.js.map +1 -1
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue.js +2 -2
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue2.js +4 -5
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue2.js.map +1 -1
- package/js/x-modules/facets/components/filters/slider-filter.vue.js +4 -4
- package/js/x-modules/facets/components/filters/slider-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/slider-filter.vue2.js +4 -1
- package/js/x-modules/facets/components/filters/slider-filter.vue2.js.map +1 -1
- package/js/x-modules/facets/components/lists/filters-search.vue.js +2 -2
- package/js/x-modules/facets/components/lists/filters-search.vue.js.map +1 -1
- package/js/x-modules/facets/components/lists/filters-search.vue2.js +4 -1
- package/js/x-modules/facets/components/lists/filters-search.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/clear-history-queries.vue.js +2 -2
- package/js/x-modules/history-queries/components/clear-history-queries.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/clear-history-queries.vue2.js +4 -1
- package/js/x-modules/history-queries/components/clear-history-queries.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/history-queries-switch.vue.js +2 -2
- package/js/x-modules/history-queries/components/history-queries-switch.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/history-queries-switch.vue2.js +4 -1
- package/js/x-modules/history-queries/components/history-queries-switch.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/history-query.vue.js +2 -1
- package/js/x-modules/history-queries/components/history-query.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/history-query.vue2.js +4 -1
- package/js/x-modules/history-queries/components/history-query.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/remove-history-query.vue.js +2 -2
- package/js/x-modules/history-queries/components/remove-history-query.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/remove-history-query.vue2.js +4 -1
- package/js/x-modules/history-queries/components/remove-history-query.vue2.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue.js +2 -2
- package/js/x-modules/scroll/components/scroll-to-top.vue.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue2.js +4 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue2.js.map +1 -1
- package/js/x-modules/search-box/components/search-input.vue.js +2 -2
- package/js/x-modules/search-box/components/search-input.vue.js.map +1 -1
- package/js/x-modules/search-box/components/search-input.vue2.js +4 -1
- package/js/x-modules/search-box/components/search-input.vue2.js.map +1 -1
- package/package.json +2 -2
- package/report/x-components.api.json +618 -41
- package/report/x-components.api.md +173 -11
- package/types/src/components/base-dropdown.vue.d.ts +3 -4
- package/types/src/components/base-dropdown.vue.d.ts.map +1 -1
- package/types/src/components/column-picker/base-column-picker-dropdown.vue.d.ts +3 -0
- package/types/src/components/column-picker/base-column-picker-dropdown.vue.d.ts.map +1 -1
- package/types/src/components/column-picker/base-column-picker-list.vue.d.ts +3 -0
- package/types/src/components/column-picker/base-column-picker-list.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-events-modal-close.vue.d.ts +3 -0
- package/types/src/components/modals/base-events-modal-close.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-events-modal-open.vue.d.ts +3 -0
- package/types/src/components/modals/base-events-modal-open.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-modal.vue.d.ts +3 -0
- package/types/src/components/modals/base-modal.vue.d.ts.map +1 -1
- package/types/src/components/page-loader-button.vue.d.ts +3 -0
- package/types/src/components/page-loader-button.vue.d.ts.map +1 -1
- package/types/src/components/page-selector.vue.d.ts +6 -0
- package/types/src/components/page-selector.vue.d.ts.map +1 -1
- package/types/src/components/sort/sort-dropdown.vue.d.ts +3 -0
- package/types/src/components/sort/sort-dropdown.vue.d.ts.map +1 -1
- package/types/src/types/accessibility.d.ts +79 -0
- package/types/src/types/accessibility.d.ts.map +1 -0
- package/types/src/types/index.d.ts +1 -0
- package/types/src/types/index.d.ts.map +1 -1
- package/types/src/utils/accessibility.d.ts +20 -0
- package/types/src/utils/accessibility.d.ts.map +1 -0
- package/types/src/utils/index.d.ts +1 -0
- package/types/src/utils/index.d.ts.map +1 -1
- package/types/src/x-installer/x-installer.d.ts.map +1 -1
- package/types/src/x-modules/ai/components/ai-carousel.vue.d.ts +4 -0
- package/types/src/x-modules/ai/components/ai-carousel.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/facets/facets.vue.d.ts +3 -0
- package/types/src/x-modules/facets/components/facets/facets.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/filters/editable-number-range-filter.vue.d.ts +4 -2
- package/types/src/x-modules/facets/components/filters/editable-number-range-filter.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/filters/slider-filter.vue.d.ts +4 -0
- package/types/src/x-modules/facets/components/filters/slider-filter.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/lists/filters-search.vue.d.ts +3 -0
- package/types/src/x-modules/facets/components/lists/filters-search.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/clear-history-queries.vue.d.ts +3 -0
- package/types/src/x-modules/history-queries/components/clear-history-queries.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/history-queries-switch.vue.d.ts +3 -0
- package/types/src/x-modules/history-queries/components/history-queries-switch.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/history-query.vue.d.ts +3 -0
- package/types/src/x-modules/history-queries/components/history-query.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/remove-history-query.vue.d.ts +3 -0
- package/types/src/x-modules/history-queries/components/remove-history-query.vue.d.ts.map +1 -1
- package/types/src/x-modules/scroll/components/scroll-to-top.vue.d.ts +3 -0
- package/types/src/x-modules/scroll/components/scroll-to-top.vue.d.ts.map +1 -1
- package/types/src/x-modules/search-box/components/search-input.vue.d.ts +3 -0
- package/types/src/x-modules/search-box/components/search-input.vue.d.ts.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-modal.vue2.js","sources":["../../../../src/components/modals/base-modal.vue"],"sourcesContent":["<template>\n <div v-show=\"isWaitingForLeave || open\" ref=\"modalRef\" class=\"x-modal\" data-test=\"modal\">\n <component\n :is=\"animation\"\n @before-leave=\"isWaitingForLeave = true\"\n @after-leave=\"isWaitingForLeave = false\"\n >\n <div\n v-if=\"open\"\n ref=\"modalContentRef\"\n class=\"x-modal__content\"\n data-test=\"modal-content\"\n role=\"dialog\"\n :class=\"contentClass\"\n aria-label=\"Base modal content\"\n >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { useDebounce } from '../../composables'\nimport { AnimationProp } from '../../types'\nimport { FOCUSABLE_SELECTORS, getTargetElement } from '../../utils'\nimport { Fade, NoAnimation } from '../animations'\n\n/**\n * Base component with no XPlugin dependencies that serves as a utility for constructing more\n * complex modals.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseModal',\n props: {\n /** Determines if the modal is open or not. */\n open: {\n type: Boolean,\n required: true,\n },\n /**\n * Determines if the focused element changes to one inside the modal when it opens. Either the\n * first element with a positive tabindex or just the first focusable element.\n */\n focusOnOpen: {\n type: Boolean,\n default: true,\n },\n /**\n * The reference selector of a DOM element to use as reference to position the modal.\n * This selector can be an ID or a class, if it is a class, it will use the first\n * element that matches.\n */\n referenceSelector: String,\n /** Animation to use for opening/closing the modal.This animation only affects the content. */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /**\n * Animation to use for the overlay (backdrop) part of the modal. By default, it uses\n * a fade transition.\n */\n overlayAnimation: {\n type: AnimationProp,\n default: () => Fade,\n },\n /** Class inherited by content element. */\n contentClass: String,\n /** Class inherited by overlay element. */\n overlayClass: String,\n },\n emits: ['click:overlay', 'focusin:body'],\n setup(props, { emit }) {\n /** Reference to the modal element in the DOM. */\n const modalRef = ref<HTMLDivElement>()\n /** Reference to the modal content element in the DOM. */\n const modalContentRef = ref<HTMLDivElement>()\n\n /** The previous value of the body overflow style. */\n const previousBodyOverflow = ref('')\n /** The previous value of the HTML element overflow style. */\n const previousHTMLOverflow = ref('')\n /** Boolean to delay the leave animation until it has completed. */\n const isWaitingForLeave = ref(false)\n /** The reference element to use to find the modal's position. */\n let referenceElement: HTMLElement | undefined\n\n /** Disables the scroll of both the body and the window. */\n function disableScroll() {\n previousBodyOverflow.value = document.body.style.overflow\n previousHTMLOverflow.value = document.documentElement.style.overflow\n document.body.style.overflow = document.documentElement.style.overflow = 'hidden'\n }\n\n /** Restores the scroll of both the body and the window. */\n function enableScroll() {\n document.body.style.overflow = previousBodyOverflow.value\n document.documentElement.style.overflow = previousHTMLOverflow.value\n }\n\n /**\n * Emits the `click:overlay` event if the click has been triggered in the overlay layer.\n *\n * @param event - The click event.\n */\n function emitOverlayClicked(event: Event) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('click:overlay', event)\n }\n\n /**\n * Emits the `focusin:body` event if a focus event has been triggered outside the modal.\n *\n * @param event - The focusin event.\n */\n function emitFocusInBody(event: FocusEvent) {\n if (!modalContentRef.value?.contains(getTargetElement(event))) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('focusin:body', event)\n }\n }\n\n /**\n * Adds listeners to the body element ot detect if the modal should be closed.\n *\n * @remarks TODO find a better solution and remove the timeout\n * To avoid emit the focusin on opening X that provokes closing it immediately.\n * This is because this event was emitted after the open of main modal when the user clicks\n * on the customer website search box (focus event). This way we avoid add the listener before\n * the open and the avoid the event that provokes the close.\n */\n function addBodyListeners() {\n setTimeout(() => {\n document.body.addEventListener('focusin', emitFocusInBody)\n })\n }\n\n /** Removes the body listeners. */\n function removeBodyListeners() {\n document.body.removeEventListener('focusin', emitFocusInBody)\n }\n\n /**\n * Sets the focused element to the first element either the first element with a positive\n * tabindex or, if there isn't any, the first focusable element inside the modal.\n */\n function setFocus() {\n const candidates: HTMLElement[] = Array.from(\n modalContentRef.value?.querySelectorAll(FOCUSABLE_SELECTORS) ?? [],\n )\n const element = candidates.find(element => element.tabIndex) ?? candidates[0]\n element?.focus()\n }\n\n /**\n * Syncs the body to the open state of the modal, adding or removing styles and listeners.\n *\n * @remarks nextTick() to wait for `modalContentRef` to be updated to look for focusable\n * candidates inside.\n *\n * @param isOpen - True when the modal is opened.\n */\n async function syncBody(isOpen: boolean) {\n if (isOpen) {\n disableScroll()\n addBodyListeners()\n if (props.focusOnOpen) {\n await nextTick()\n setFocus()\n }\n } else {\n enableScroll()\n removeBodyListeners()\n }\n }\n\n /**\n * Updates the position of the modal setting the top of the element depending\n * on the selector. The modal will be placed under this selector.\n */\n const debouncedUpdatePosition = useDebounce(\n () => {\n const { height, y } = referenceElement?.getBoundingClientRect() ?? { height: 0, y: 0 }\n modalRef.value!.style.top = `${height + y}px`\n modalRef.value!.style.bottom = '0'\n modalRef.value!.style.height = 'auto'\n },\n 100,\n { leading: true },\n )\n\n let resizeObserver: ResizeObserver\n\n onMounted(() => {\n watch(() => props.open, syncBody)\n if (props.open) {\n syncBody(true)\n }\n\n resizeObserver = new ResizeObserver(debouncedUpdatePosition)\n\n watch(\n () => props.referenceSelector,\n () => {\n resizeObserver.disconnect()\n\n if (props.referenceSelector) {\n const element = document.querySelector(props.referenceSelector) as HTMLElement\n if (element) {\n referenceElement = element\n resizeObserver.observe(element)\n }\n } else {\n referenceElement = undefined\n debouncedUpdatePosition()\n }\n },\n { immediate: true },\n )\n })\n\n onBeforeUnmount(() => {\n if (props.open) {\n removeBodyListeners()\n enableScroll()\n }\n resizeObserver.disconnect()\n })\n\n return {\n emitOverlayClicked,\n isWaitingForLeave,\n modalContentRef,\n modalRef,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-modal {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: flex-start;\n justify-content: flex-start;\n width: 100%;\n height: 100%;\n z-index: 1;\n}\n\n.x-modal__content {\n display: flex;\n flex-flow: column nowrap;\n z-index: 1;\n}\n\n.x-modal__overlay {\n width: 100%;\n height: 100%;\n position: absolute;\n background-color: rgb(0, 0, 0);\n opacity: 0.3;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThe `BaseModal` is a simple component that serves to create complex modals. Its open state has to be\npassed via prop. There is a prop, `referenceSelector`, used to place the modal under some element\ninstead of set the top of the element directly. It also accepts an animation to use for opening &\nclosing.\n\nIt emits a `click:overlay` event when any part out of the content is clicked, but only if the modal\nis open.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n### Customized usage\n\n#### Customizing the content with classes\n\nThe `contentClass` prop can be used to add classes to the modal content.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n contentClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n#### Customizing the overlay with classes\n\nThe `overlayClass` prop can be used to add classes to the modal overlay.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n overlayClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n## Vue Events\n\nA list of events that the component will emit:\n\n- `click:overlay`: the event is emitted after the user clicks any part out of the content but only\n if the modal is open. The event payload is the mouse event that triggers it.\n- `focusin:body`: the event is emitted after the user focus in any part out of the content but only\n if the modal is open. The event payload is the focus event that triggers it.\n</docs>\n"],"names":["NoAnimation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;AAKE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,KAAK,EAAE;;AAEL,QAAA,IAAI,EAAE;AACJ,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;AAGE;AACF,QAAA,WAAW,EAAE;AACX,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;;;AAIE;AACF,QAAA,iBAAiB,EAAE,MAAM;;AAEzB,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAMA,WAAW;AAC3B,SAAA;AACD;;;AAGE;AACF,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAM,IAAI;AACpB,SAAA;;AAED,QAAA,YAAY,EAAE,MAAM;;AAEpB,QAAA,YAAY,EAAE,MAAM;AACrB,KAAA;AACD,IAAA,K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AAK,CAAC,MAAK,GAAI,GAAE;YACjC,QAAQ,CAAC,KAAM,CAAC,KAAK,CAAC,MAAK,GAAI,MAAK;QACtC,CAAC,EACD,GAAG,EACH,EAAE,OAAO,EAAE,IAAG,EAAG,CACnB;AAEA,QAAA,IAAI,cAA6B;QAEjC,SAAS,CAAC,MAAI;YACZ,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAA;AAChC,YAAA,IAAI,KAAK,CAAC,IAAI,EAAE;gBACd,QAAQ,CAAC,IAAI,CAAA;YACf;AAEA,YAAA,iBAAiB,IAAI,cAAc,CAAC,uBAAuB,CAAA;YAE3D,KAAK,CACH,MAAM,KAAK,CAAC,iBAAiB,EAC7B,MAAI;gBACF,cAAc,CAAC,UAAU,EAAC;AAE1B,gBAAA,IAAI,KAAK,CAAC,iBAAiB,EAAE;oBAC3B,MAAM,OAAM,GAAI,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,iBAAiB,CAAe;oBAC7E,IAAI,OAAO,EAAE;wBACX,gBAAe,GAAI,OAAM;AACzB,wBAAA,cAAc,CAAC,OAAO,CAAC,OAAO,CAAA;oBAChC;gBACF;qBAAO;oBACL,gBAAe,GAAI,SAAQ;AAC3B,oBAAA,uBAAuB,EAAC;gBAC1B;AACF,YAAA,CAAC,EACD,EAAE,SAAS,EAAE,MAAM,CACrB;AACF,QAAA,CAAC,CAAA;QAED,eAAe,CAAC,MAAI;AAClB,YAAA,IAAI,KAAK,CAAC,IAAI,EAAE;AACd,gBAAA,mBAAmB,EAAC;AACpB,gBAAA,YAAY,EAAC;YACf;YACA,cAAc,CAAC,UAAU,EAAC;AAC5B,QAAA,CAAC,CAAA;QAED,OAAO;YACL,kBAAkB;YAClB,iBAAiB;YACjB,eAAe;YACf,QAAQ;SACV;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"base-modal.vue2.js","sources":["../../../../src/components/modals/base-modal.vue"],"sourcesContent":["<template>\n <div v-show=\"isWaitingForLeave || open\" ref=\"modalRef\" class=\"x-modal\" data-test=\"modal\">\n <component\n :is=\"animation\"\n @before-leave=\"isWaitingForLeave = true\"\n @after-leave=\"isWaitingForLeave = false\"\n >\n <div\n v-if=\"open\"\n ref=\"modalContentRef\"\n class=\"x-modal__content\"\n data-test=\"modal-content\"\n role=\"dialog\"\n :class=\"contentClass\"\n :aria-label=\"ariaLabels?.modal\"\n >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { AriaLabels } from '../../types'\nimport { defineComponent, inject, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { useDebounce } from '../../composables'\nimport { ACCESSIBILITY_KEY, AnimationProp } from '../../types'\nimport { FOCUSABLE_SELECTORS, getTargetElement } from '../../utils'\nimport { Fade, NoAnimation } from '../animations'\n\n/**\n * Base component with no XPlugin dependencies that serves as a utility for constructing more\n * complex modals.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseModal',\n props: {\n /** Determines if the modal is open or not. */\n open: {\n type: Boolean,\n required: true,\n },\n /**\n * Determines if the focused element changes to one inside the modal when it opens. Either the\n * first element with a positive tabindex or just the first focusable element.\n */\n focusOnOpen: {\n type: Boolean,\n default: true,\n },\n /**\n * The reference selector of a DOM element to use as reference to position the modal.\n * This selector can be an ID or a class, if it is a class, it will use the first\n * element that matches.\n */\n referenceSelector: String,\n /** Animation to use for opening/closing the modal.This animation only affects the content. */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /**\n * Animation to use for the overlay (backdrop) part of the modal. By default, it uses\n * a fade transition.\n */\n overlayAnimation: {\n type: AnimationProp,\n default: () => Fade,\n },\n /** Class inherited by content element. */\n contentClass: String,\n /** Class inherited by overlay element. */\n overlayClass: String,\n },\n emits: ['click:overlay', 'focusin:body'],\n setup(props, { emit }) {\n const { baseModal: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n /** Reference to the modal element in the DOM. */\n const modalRef = ref<HTMLDivElement>()\n /** Reference to the modal content element in the DOM. */\n const modalContentRef = ref<HTMLDivElement>()\n\n /** The previous value of the body overflow style. */\n const previousBodyOverflow = ref('')\n /** The previous value of the HTML element overflow style. */\n const previousHTMLOverflow = ref('')\n /** Boolean to delay the leave animation until it has completed. */\n const isWaitingForLeave = ref(false)\n /** The reference element to use to find the modal's position. */\n let referenceElement: HTMLElement | undefined\n\n /** Disables the scroll of both the body and the window. */\n function disableScroll() {\n previousBodyOverflow.value = document.body.style.overflow\n previousHTMLOverflow.value = document.documentElement.style.overflow\n document.body.style.overflow = document.documentElement.style.overflow = 'hidden'\n }\n\n /** Restores the scroll of both the body and the window. */\n function enableScroll() {\n document.body.style.overflow = previousBodyOverflow.value\n document.documentElement.style.overflow = previousHTMLOverflow.value\n }\n\n /**\n * Emits the `click:overlay` event if the click has been triggered in the overlay layer.\n *\n * @param event - The click event.\n */\n function emitOverlayClicked(event: Event) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('click:overlay', event)\n }\n\n /**\n * Emits the `focusin:body` event if a focus event has been triggered outside the modal.\n *\n * @param event - The focusin event.\n */\n function emitFocusInBody(event: FocusEvent) {\n if (!modalContentRef.value?.contains(getTargetElement(event))) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('focusin:body', event)\n }\n }\n\n /**\n * Adds listeners to the body element ot detect if the modal should be closed.\n *\n * @remarks TODO find a better solution and remove the timeout\n * To avoid emit the focusin on opening X that provokes closing it immediately.\n * This is because this event was emitted after the open of main modal when the user clicks\n * on the customer website search box (focus event). This way we avoid add the listener before\n * the open and the avoid the event that provokes the close.\n */\n function addBodyListeners() {\n setTimeout(() => {\n document.body.addEventListener('focusin', emitFocusInBody)\n })\n }\n\n /** Removes the body listeners. */\n function removeBodyListeners() {\n document.body.removeEventListener('focusin', emitFocusInBody)\n }\n\n /**\n * Sets the focused element to the first element either the first element with a positive\n * tabindex or, if there isn't any, the first focusable element inside the modal.\n */\n function setFocus() {\n const candidates: HTMLElement[] = Array.from(\n modalContentRef.value?.querySelectorAll(FOCUSABLE_SELECTORS) ?? [],\n )\n const element = candidates.find(element => element.tabIndex) ?? candidates[0]\n element?.focus()\n }\n\n /**\n * Syncs the body to the open state of the modal, adding or removing styles and listeners.\n *\n * @remarks nextTick() to wait for `modalContentRef` to be updated to look for focusable\n * candidates inside.\n *\n * @param isOpen - True when the modal is opened.\n */\n async function syncBody(isOpen: boolean) {\n if (isOpen) {\n disableScroll()\n addBodyListeners()\n if (props.focusOnOpen) {\n await nextTick()\n setFocus()\n }\n } else {\n enableScroll()\n removeBodyListeners()\n }\n }\n\n /**\n * Updates the position of the modal setting the top of the element depending\n * on the selector. The modal will be placed under this selector.\n */\n const debouncedUpdatePosition = useDebounce(\n () => {\n const { height, y } = referenceElement?.getBoundingClientRect() ?? { height: 0, y: 0 }\n modalRef.value!.style.top = `${height + y}px`\n modalRef.value!.style.bottom = '0'\n modalRef.value!.style.height = 'auto'\n },\n 100,\n { leading: true },\n )\n\n let resizeObserver: ResizeObserver\n\n onMounted(() => {\n watch(() => props.open, syncBody)\n if (props.open) {\n syncBody(true)\n }\n\n resizeObserver = new ResizeObserver(debouncedUpdatePosition)\n\n watch(\n () => props.referenceSelector,\n () => {\n resizeObserver.disconnect()\n\n if (props.referenceSelector) {\n const element = document.querySelector(props.referenceSelector) as HTMLElement\n if (element) {\n referenceElement = element\n resizeObserver.observe(element)\n }\n } else {\n referenceElement = undefined\n debouncedUpdatePosition()\n }\n },\n { immediate: true },\n )\n })\n\n onBeforeUnmount(() => {\n if (props.open) {\n removeBodyListeners()\n enableScroll()\n }\n resizeObserver.disconnect()\n })\n\n return {\n ariaLabels,\n emitOverlayClicked,\n isWaitingForLeave,\n modalContentRef,\n modalRef,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-modal {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: flex-start;\n justify-content: flex-start;\n width: 100%;\n height: 100%;\n z-index: 1;\n}\n\n.x-modal__content {\n display: flex;\n flex-flow: column nowrap;\n z-index: 1;\n}\n\n.x-modal__overlay {\n width: 100%;\n height: 100%;\n position: absolute;\n background-color: rgb(0, 0, 0);\n opacity: 0.3;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThe `BaseModal` is a simple component that serves to create complex modals. Its open state has to be\npassed via prop. There is a prop, `referenceSelector`, used to place the modal under some element\ninstead of set the top of the element directly. It also accepts an animation to use for opening &\nclosing.\n\nIt emits a `click:overlay` event when any part out of the content is clicked, but only if the modal\nis open.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n### Customized usage\n\n#### Customizing the content with classes\n\nThe `contentClass` prop can be used to add classes to the modal content.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n contentClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n#### Customizing the overlay with classes\n\nThe `overlayClass` prop can be used to add classes to the modal overlay.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n overlayClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n## Vue Events\n\nA list of events that the component will emit:\n\n- `click:overlay`: the event is emitted after the user clicks any part out of the content but only\n if the modal is open. The event payload is the mouse event that triggers it.\n- `focusin:body`: the event is emitted after the user focus in any part out of the content but only\n if the modal is open. The event payload is the focus event that triggers it.\n</docs>\n"],"names":["NoAnimation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA;;;;;AAKE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,KAAK,EAAE;;AAEL,QAAA,IAAI,EAAE;AACJ,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;AAGE;AACF,QAAA,WAAW,EAAE;AACX,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;;;AAIE;AACF,QAAA,iBAAiB,EAAE,MAAM;;AAEzB,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAMA,WAAW;AAC3B,SAAA;AACD;;;AAGE;AACF,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAM,IAAI;AACpB,SAAA;;AAED,QAAA,YA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,iBAAiB;YACjB,eAAe;YACf,QAAQ;SACV;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
@@ -31,7 +31,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
31
31
|
class: normalizeClass(["xds:button", _ctx.buttonClasses]),
|
|
32
32
|
events: _ctx.events,
|
|
33
33
|
"data-test": "load-content",
|
|
34
|
-
"aria-label":
|
|
34
|
+
"aria-label": _ctx.ariaLabels?.button
|
|
35
35
|
}, {
|
|
36
36
|
default: withCtx(() => [
|
|
37
37
|
renderSlot(_ctx.$slots, "buttonContent", {}, () => [
|
|
@@ -44,7 +44,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
44
44
|
]),
|
|
45
45
|
_: 3
|
|
46
46
|
/* FORWARDED */
|
|
47
|
-
}, 8, ["class", "events"])
|
|
47
|
+
}, 8, ["class", "events", "aria-label"])
|
|
48
48
|
], true)
|
|
49
49
|
]);
|
|
50
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-loader-button.vue.js","sources":["../../../src/components/page-loader-button.vue"],"sourcesContent":["<template>\n <div class=\"x-page-loader\" data-test=\"page-loader\">\n <!--\n @slot default\n @binding {number} resultsLength - The search result's length\n @binding {number} totalResults - The totalResults of a searched query\n -->\n <slot v-bind=\"{ resultsLength, totalResults }\">\n <!-- @slot Rendered count with a text and the number of results displayed & remaining. -->\n <slot name=\"textContent\" :results-length=\"resultsLength\" :total-results=\"totalResults\">\n <p class=\"x-page-loader__text-content\" data-test=\"text-content\">\n You are seeing {{ resultsLength }} of {{ totalResults }} results\n </p>\n </slot>\n <BaseEventButton\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :events=\"events\"\n data-test=\"load-content\"\n aria-label=\"
|
|
1
|
+
{"version":3,"file":"page-loader-button.vue.js","sources":["../../../src/components/page-loader-button.vue"],"sourcesContent":["<template>\n <div class=\"x-page-loader\" data-test=\"page-loader\">\n <!--\n @slot default\n @binding {number} resultsLength - The search result's length\n @binding {number} totalResults - The totalResults of a searched query\n -->\n <slot v-bind=\"{ resultsLength, totalResults }\">\n <!-- @slot Rendered count with a text and the number of results displayed & remaining. -->\n <slot name=\"textContent\" :results-length=\"resultsLength\" :total-results=\"totalResults\">\n <p class=\"x-page-loader__text-content\" data-test=\"text-content\">\n You are seeing {{ resultsLength }} of {{ totalResults }} results\n </p>\n </slot>\n <BaseEventButton\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :events=\"events\"\n data-test=\"load-content\"\n :aria-label=\"ariaLabels?.button\"\n >\n <!-- @slot Button content with a text, an icon or both -->\n <slot name=\"buttonContent\">Load</slot>\n </BaseEventButton>\n </slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport type { AriaLabels } from '../types'\nimport type { VueCSSClasses } from '../utils/types'\nimport type { XEventsTypes } from '../wiring'\nimport { computed, defineComponent, inject } from 'vue'\nimport { use$x } from '../composables'\nimport { ACCESSIBILITY_KEY } from '../types'\nimport BaseEventButton from './base-event-button.vue'\n\n/**\n * Component that renders a text with the number of rendered results and\n * the remaining ones and a `<BaseEventButton>` with the logic of emitting\n * the event \"UserReachedResultsListEnd\" to load more results on click.\n *\n * @public\n */\nexport default defineComponent({\n name: 'PageLoaderButton',\n components: { BaseEventButton },\n props: {\n /**\n * CSS classes to customize the loader button.\n *\n * @internal\n */\n buttonClasses: {\n type: String as PropType<VueCSSClasses>,\n default: '',\n },\n /**\n * Events to customize what will be emitted by the loader button.\n *\n * @internal\n */\n buttonEvents: {\n type: Object as PropType<Partial<XEventsTypes>>,\n },\n },\n setup(props) {\n const { pageLoaderButton: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n const $x = use$x()\n const resultsLength = computed(() => $x.results.length)\n const totalResults = computed(() => $x.totalResults)\n\n /**\n * The events that will be emitted when clicking on the loader button.\n *\n * @returns The {@link XEvent} to emit.\n * @public\n */\n const events = computed<Partial<XEventsTypes>>(() => {\n return { UserReachedResultsListEnd: undefined, ...props.buttonEvents }\n })\n\n return {\n ariaLabels,\n resultsLength,\n totalResults,\n events,\n }\n },\n})\n</script>\n\n<style scoped>\n.x-page-loader {\n display: flex;\n flex-direction: column;\n align-items: center;\n padding: 32px 0;\n}\n\n.x-page-loader__text-content {\n padding: 16px 0;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the \"UserReachedResultsListEnd\" event by default. This can be changed using the\nbuttonEvents prop:\n\n```vue live\n<template>\n <PageLoaderButton :buttonEvents=\"{ UserClickedCloseX: undefined }\" />\n</template>\n\n<script>\nimport { PageLoaderButton } from '@empathyco/x-components'\n\nexport default {\n name: 'PageLoaderButtonDemo',\n components: {\n PageLoaderButton,\n },\n}\n</script>\n```\n\n## See it in action\n\nHere you have a basic example of how the page loader component is rendered.\n\n```vue live\n<template>\n <PageLoaderButton />\n</template>\n\n<script>\nimport { PageLoaderButton } from '@empathyco/x-components'\n\nexport default {\n name: 'PageLoaderButtonDemo',\n components: {\n PageLoaderButton,\n },\n}\n</script>\n```\n\n### Customise the default layout\n\nThis component has a default slot which allows to customise the entire layout.\n\n```vue live\n<template>\n <PageLoaderButton>\n <template #default=\"{ resultsLength, totalResults }\">\n <div class=\"x-flex x-flex-col\">\n <div class=\"x-flex x-gap-4 x-text\">\n <span class=\"x-text-accent-50 x-font-bold\">{{ resultsLength }}</span>\n <span>of</span>\n <span class=\"x-text-accent-50\">{{ totalResults }}</span>\n </div>\n <button\n @click=\"$x.emit('UserReachedResultsListEnd', undefined)\"\n class=\"x-button x-button-ghost\"\n >\n Load more\n </button>\n </div>\n </template>\n </PageLoaderButton>\n</template>\n\n<script>\nimport { PageLoaderButton } from '@empathyco/x-components'\n\nexport default {\n name: 'PageLoaderButtonDemo',\n components: {\n PageLoaderButton,\n },\n}\n</script>\n```\n\n### Customise the slots\n\nThis component allows to customise both the textContent and the buttonContent slots. The\ntextContent's slot layout can be replaced entirely, while the buttonContent's slot enables wrapping\ncontent inside and customizing its style using the buttonClasses prop.\n\n```vue live\n<template>\n <PageLoaderButton :buttonClasses=\"buttonClasses\">\n <template #textContent=\"{ resultsLength, totalResults }\">\n <div class=\"x-flex x-gap-4 x-text\">\n <span class=\"x-text-accent-50 x-font-bold\">{{ resultsLength }}</span>\n <span>of</span>\n <span class=\"x-text-accent-50\">{{ totalResults }}</span>\n </div>\n </template>\n <template #buttonContent>Load more results</template>\n </PageLoaderButton>\n</template>\n\n<script>\nimport { PageLoaderButton } from '@empathyco/x-components'\n\nexport default {\n name: 'PageLoaderButtonDemo',\n components: {\n PageLoaderButton,\n },\n data() {\n return {\n buttonClasses: 'x-rounded-full',\n }\n },\n}\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_renderSlot","_normalizeProps","_guardReactiveProps","_createElementVNode","_toDisplayString","_createVNode","_normalizeClass","_createTextVNode"],"mappings":";;;;;;EACO,KAAA,EAAM,eAAA;AAAA,EAAgB,WAAA,EAAU;;;EAS5B,KAAA,EAAM,6BAAA;AAAA,EAA8B,WAAA,EAAU;;;;AATvD,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA,CAwBM,OAxBN,UAAA,EAwBM;AAAA,IAlBJC,WAiBO,IAAA,CAAA,MAAA,EAAA,SAAA,EAAAC,cAAA,CAAAC,kBAAA,CAAA,EAAA,aAAA,EAjBS,IAAA,CAAA,aAAA,EAAa,YAAA,EAAE,IAAA,CAAA,YAAA,MAA/B,MAiBO;AAAA,MAfLF,UAAA,CAIO,IAAA,CAAA,MAAA,EAAA,aAAA,EAAA;AAAA,QAJmB,aAAA,EAAgB,IAAA,CAAA,aAAA;AAAA,QAAgB,YAAA,EAAe,IAAA,CAAA;AAAA,OAAA,EAAzE,MAIO;AAAA,QAHLG,kBAAA;AAAA,UAEI,GAAA;AAAA,UAFJ,UAAA;AAAA,UAAgE,qBAC/CC,eAAA,CAAG,IAAA,CAAA,aAAa,IAAG,MAAA,GAAIA,eAAA,CAAG,iBAAY,CAAA,GAAG,WAAA;AAAA,UAC1D;AAAA;AAAA;AAAA,OAAA,EAAA,IAAA,CAAA;MAEFC,WAAA,CASkB,0BAAA,EAAA;AAAA,QARhB,KAAA,EAAKC,cAAA,CAAA,CAAC,YAAA,EACE,IAAA,CAAA,aAAa,CAAA,CAAA;AAAA,QACpB,MAAA,EAAQ,IAAA,CAAA,MAAA;AAAA,QACT,WAAA,EAAU,cAAA;AAAA,QACT,cAAY,IAAA,CAAA,UAAA,EAAY;AAAA,OAAA,EAAA;yBAGzB,MAAsC;AAAA,UAAtCN,UAAA,CAAsC,kCAAtC,MAAsC;AAAA,YAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAO,eAAA;AAAX,cAAA,MAAA;AAAA,cAAI;AAAA;AAAA,aAAA;AAAA,WAAA,EAAA,IAAA;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, computed } from 'vue';
|
|
1
|
+
import { defineComponent, inject, computed } from 'vue';
|
|
2
2
|
import '../composables/create-use-device.js';
|
|
3
3
|
import { use$x } from '../composables/use-_x.js';
|
|
4
4
|
import 'vuex';
|
|
@@ -7,6 +7,7 @@ import '@empathyco/x-utils';
|
|
|
7
7
|
import '../plugins/x-plugin.js';
|
|
8
8
|
import '@vueuse/core';
|
|
9
9
|
import 'rxjs';
|
|
10
|
+
import { ACCESSIBILITY_KEY } from '../types/accessibility.js';
|
|
10
11
|
import BaseEventButton from './base-event-button.vue.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -39,6 +40,7 @@ var _sfc_main = defineComponent({
|
|
|
39
40
|
},
|
|
40
41
|
},
|
|
41
42
|
setup(props) {
|
|
43
|
+
const { pageLoaderButton: ariaLabels } = inject(ACCESSIBILITY_KEY);
|
|
42
44
|
const $x = use$x();
|
|
43
45
|
const resultsLength = computed(() => $x.results.length);
|
|
44
46
|
const totalResults = computed(() => $x.totalResults);
|
|
@@ -52,6 +54,7 @@ var _sfc_main = defineComponent({
|
|
|
52
54
|
return { UserReachedResultsListEnd: undefined, ...props.buttonEvents };
|
|
53
55
|
});
|
|
54
56
|
return {
|
|
57
|
+
ariaLabels,
|
|
55
58
|
resultsLength,
|
|
56
59
|
totalResults,
|
|
57
60
|
events,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-loader-button.vue2.js","sources":["../../../src/components/page-loader-button.vue"],"sourcesContent":["<template>\n <div class=\"x-page-loader\" data-test=\"page-loader\">\n <!--\n @slot default\n @binding {number} resultsLength - The search result's length\n @binding {number} totalResults - The totalResults of a searched query\n -->\n <slot v-bind=\"{ resultsLength, totalResults }\">\n <!-- @slot Rendered count with a text and the number of results displayed & remaining. -->\n <slot name=\"textContent\" :results-length=\"resultsLength\" :total-results=\"totalResults\">\n <p class=\"x-page-loader__text-content\" data-test=\"text-content\">\n You are seeing {{ resultsLength }} of {{ totalResults }} results\n </p>\n </slot>\n <BaseEventButton\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :events=\"events\"\n data-test=\"load-content\"\n aria-label=\"
|
|
1
|
+
{"version":3,"file":"page-loader-button.vue2.js","sources":["../../../src/components/page-loader-button.vue"],"sourcesContent":["<template>\n <div class=\"x-page-loader\" data-test=\"page-loader\">\n <!--\n @slot default\n @binding {number} resultsLength - The search result's length\n @binding {number} totalResults - The totalResults of a searched query\n -->\n <slot v-bind=\"{ resultsLength, totalResults }\">\n <!-- @slot Rendered count with a text and the number of results displayed & remaining. -->\n <slot name=\"textContent\" :results-length=\"resultsLength\" :total-results=\"totalResults\">\n <p class=\"x-page-loader__text-content\" data-test=\"text-content\">\n You are seeing {{ resultsLength }} of {{ totalResults }} results\n </p>\n </slot>\n <BaseEventButton\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :events=\"events\"\n data-test=\"load-content\"\n :aria-label=\"ariaLabels?.button\"\n >\n <!-- @slot Button content with a text, an icon or both -->\n <slot name=\"buttonContent\">Load</slot>\n </BaseEventButton>\n </slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport type { AriaLabels } from '../types'\nimport type { VueCSSClasses } from '../utils/types'\nimport type { XEventsTypes } from '../wiring'\nimport { computed, defineComponent, inject } from 'vue'\nimport { use$x } from '../composables'\nimport { ACCESSIBILITY_KEY } from '../types'\nimport BaseEventButton from './base-event-button.vue'\n\n/**\n * Component that renders a text with the number of rendered results and\n * the remaining ones and a `<BaseEventButton>` with the logic of emitting\n * the event \"UserReachedResultsListEnd\" to load more results on click.\n *\n * @public\n */\nexport default defineComponent({\n name: 'PageLoaderButton',\n components: { BaseEventButton },\n props: {\n /**\n * CSS classes to customize the loader button.\n *\n * @internal\n */\n buttonClasses: {\n type: String as PropType<VueCSSClasses>,\n default: '',\n },\n /**\n * Events to customize what will be emitted by the loader button.\n *\n * @internal\n */\n buttonEvents: {\n type: Object as PropType<Partial<XEventsTypes>>,\n },\n },\n setup(props) {\n const { pageLoaderButton: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n const $x = use$x()\n const resultsLength = computed(() => $x.results.length)\n const totalResults = computed(() => $x.totalResults)\n\n /**\n * The events that will be emitted when clicking on the loader button.\n *\n * @returns The {@link XEvent} to emit.\n * @public\n */\n const events = computed<Partial<XEventsTypes>>(() => {\n return { UserReachedResultsListEnd: undefined, ...props.buttonEvents }\n })\n\n return {\n ariaLabels,\n resultsLength,\n totalResults,\n events,\n }\n },\n})\n</script>\n\n<style scoped>\n.x-page-loader {\n display: flex;\n flex-direction: column;\n align-items: center;\n padding: 32px 0;\n}\n\n.x-page-loader__text-content {\n padding: 16px 0;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the \"UserReachedResultsListEnd\" event by default. This can be changed using the\nbuttonEvents prop:\n\n```vue live\n<template>\n <PageLoaderButton :buttonEvents=\"{ UserClickedCloseX: undefined }\" />\n</template>\n\n<script>\nimport { PageLoaderButton } from '@empathyco/x-components'\n\nexport default {\n name: 'PageLoaderButtonDemo',\n components: {\n PageLoaderButton,\n },\n}\n</script>\n```\n\n## See it in action\n\nHere you have a basic example of how the page loader component is rendered.\n\n```vue live\n<template>\n <PageLoaderButton />\n</template>\n\n<script>\nimport { PageLoaderButton } from '@empathyco/x-components'\n\nexport default {\n name: 'PageLoaderButtonDemo',\n components: {\n PageLoaderButton,\n },\n}\n</script>\n```\n\n### Customise the default layout\n\nThis component has a default slot which allows to customise the entire layout.\n\n```vue live\n<template>\n <PageLoaderButton>\n <template #default=\"{ resultsLength, totalResults }\">\n <div class=\"x-flex x-flex-col\">\n <div class=\"x-flex x-gap-4 x-text\">\n <span class=\"x-text-accent-50 x-font-bold\">{{ resultsLength }}</span>\n <span>of</span>\n <span class=\"x-text-accent-50\">{{ totalResults }}</span>\n </div>\n <button\n @click=\"$x.emit('UserReachedResultsListEnd', undefined)\"\n class=\"x-button x-button-ghost\"\n >\n Load more\n </button>\n </div>\n </template>\n </PageLoaderButton>\n</template>\n\n<script>\nimport { PageLoaderButton } from '@empathyco/x-components'\n\nexport default {\n name: 'PageLoaderButtonDemo',\n components: {\n PageLoaderButton,\n },\n}\n</script>\n```\n\n### Customise the slots\n\nThis component allows to customise both the textContent and the buttonContent slots. The\ntextContent's slot layout can be replaced entirely, while the buttonContent's slot enables wrapping\ncontent inside and customizing its style using the buttonClasses prop.\n\n```vue live\n<template>\n <PageLoaderButton :buttonClasses=\"buttonClasses\">\n <template #textContent=\"{ resultsLength, totalResults }\">\n <div class=\"x-flex x-gap-4 x-text\">\n <span class=\"x-text-accent-50 x-font-bold\">{{ resultsLength }}</span>\n <span>of</span>\n <span class=\"x-text-accent-50\">{{ totalResults }}</span>\n </div>\n </template>\n <template #buttonContent>Load more results</template>\n </PageLoaderButton>\n</template>\n\n<script>\nimport { PageLoaderButton } from '@empathyco/x-components'\n\nexport default {\n name: 'PageLoaderButtonDemo',\n components: {\n PageLoaderButton,\n },\n data() {\n return {\n buttonClasses: 'x-rounded-full',\n }\n },\n}\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;;;;;;AAsCA;;;;;;AAME;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,kBAAkB;IACxB,UAAU,EAAE,EAAE,eAAc,EAAG;AAC/B,IAAA,KAAK,EAAE;AACL;;;;AAIE;AACF,QAAA,aAAa,EAAE;AACb,YAAA,IAAI,EAAE,MAAiC;AACvC,YAAA,OAAO,EAAE,EAAE;AACZ,SAAA;AACD;;;;AAIE;AACF,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAyC;AAChD,SAAA;AACF,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAA;QACT,MAAM,EAAE,gBAAgB,EAAE,YAAW,GAAI,MAAM,CAAC,iBAAiB,CAAc;AAE/E,QAAA,MAAM,EAAC,GAAI,KAAK,EAAC;AACjB,QAAA,MAAM,gBAAgB,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,CAAA;QACtD,MAAM,YAAW,GAAI,QAAQ,CAAC,MAAM,EAAE,CAAC,YAAY,CAAA;AAEnD;;;;;AAKE;AACF,QAAA,MAAM,MAAK,GAAI,QAAQ,CAAwB,MAAI;YACjD,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC,YAAW,EAAE;AACvE,QAAA,CAAC,CAAA;QAED,OAAO;YACL,UAAU;YACV,aAAa;YACb,YAAY;YACZ,MAAM;SACR;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
@@ -3,21 +3,21 @@ import { openBlock, createElementBlock, createElementVNode, normalizeClass, rend
|
|
|
3
3
|
import './page-selector.vue3.js';
|
|
4
4
|
import _export_sfc from '../_virtual/_plugin-vue_export-helper.js';
|
|
5
5
|
|
|
6
|
-
const _hoisted_1 =
|
|
7
|
-
|
|
8
|
-
class: "x-page-selector",
|
|
9
|
-
"aria-label": "Pagination"
|
|
10
|
-
};
|
|
11
|
-
const _hoisted_2 = ["disabled", "aria-disabled"];
|
|
6
|
+
const _hoisted_1 = ["aria-label"];
|
|
7
|
+
const _hoisted_2 = ["disabled", "aria-label", "aria-disabled"];
|
|
12
8
|
const _hoisted_3 = ["data-test", "aria-label", "aria-current", "onClick"];
|
|
13
|
-
const _hoisted_4 = ["disabled", "aria-disabled"];
|
|
9
|
+
const _hoisted_4 = ["disabled", "aria-label", "aria-disabled"];
|
|
14
10
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
15
|
-
return _ctx.visiblePages?.length > 1 ? (openBlock(), createElementBlock("nav",
|
|
11
|
+
return _ctx.visiblePages?.length > 1 ? (openBlock(), createElementBlock("nav", {
|
|
12
|
+
key: 0,
|
|
13
|
+
class: "x-page-selector",
|
|
14
|
+
"aria-label": _ctx.ariaLabels?.pagination
|
|
15
|
+
}, [
|
|
16
16
|
createElementVNode("button", {
|
|
17
17
|
class: normalizeClass(["xds:button", _ctx.buttonClasses]),
|
|
18
18
|
disabled: _ctx.currentPage === 1,
|
|
19
19
|
"data-test": "previous-page-button",
|
|
20
|
-
"aria-label":
|
|
20
|
+
"aria-label": _ctx.ariaLabels?.prevPage,
|
|
21
21
|
"aria-disabled": _ctx.currentPage === 1,
|
|
22
22
|
onClick: _cache[0] || (_cache[0] = ($event) => _ctx.selectPage(_ctx.currentPage - 1))
|
|
23
23
|
}, [
|
|
@@ -43,7 +43,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
43
43
|
}
|
|
44
44
|
]]),
|
|
45
45
|
"data-test": `page-button-${page.value}`,
|
|
46
|
-
"aria-label":
|
|
46
|
+
"aria-label": _ctx.ariaLabels?.numberPage(page.value),
|
|
47
47
|
"aria-current": page.isSelected ? "page" : void 0,
|
|
48
48
|
onClick: ($event) => _ctx.selectPage(page.value)
|
|
49
49
|
}, [
|
|
@@ -66,7 +66,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
66
66
|
class: normalizeClass(["xds:button", _ctx.buttonClasses]),
|
|
67
67
|
disabled: _ctx.currentPage === _ctx.totalPages,
|
|
68
68
|
"data-test": "next-page-button",
|
|
69
|
-
"aria-label":
|
|
69
|
+
"aria-label": _ctx.ariaLabels?.nextPage,
|
|
70
70
|
"aria-disabled": _ctx.currentPage === _ctx.totalPages,
|
|
71
71
|
onClick: _cache[1] || (_cache[1] = ($event) => _ctx.selectPage(_ctx.currentPage + 1))
|
|
72
72
|
}, [
|
|
@@ -78,7 +78,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
78
78
|
))
|
|
79
79
|
], true)
|
|
80
80
|
], 10, _hoisted_4)
|
|
81
|
-
])) : createCommentVNode("v-if", true);
|
|
81
|
+
], 8, _hoisted_1)) : createCommentVNode("v-if", true);
|
|
82
82
|
}
|
|
83
83
|
var pageSelector = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-b08cf95a"]]);
|
|
84
84
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-selector.vue.js","sources":["../../../src/components/page-selector.vue"],"sourcesContent":["<template>\n <nav v-if=\"visiblePages?.length > 1\" class=\"x-page-selector\" aria-label=\"Pagination\">\n <button\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :disabled=\"currentPage === 1\"\n data-test=\"previous-page-button\"\n aria-label=\"Previous page\"\n :aria-disabled=\"currentPage === 1\"\n @click=\"selectPage(currentPage - 1)\"\n >\n <slot name=\"previous-page-button\">Prev</slot>\n </button>\n\n <button\n v-for=\"page in visiblePages\"\n :key=\"page.value\"\n class=\"x-page-selector__page xds:button\"\n :class=\"[\n itemClasses(page.isSelected),\n {\n 'x-page-selector__page--current': page.isSelected,\n 'x-page-selector__page--hidden': page.value === hiddenPage,\n },\n ]\"\n :data-test=\"`page-button-${page.value}`\"\n :aria-label=\"`Page ${page.value}`\"\n :aria-current=\"page.isSelected ? 'page' : undefined\"\n @click=\"selectPage(page.value)\"\n >\n <slot name=\"page-button\" :page=\"page.value\" :is-selected=\"page.isSelected\">\n {{ page.value }}\n </slot>\n </button>\n\n <button\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :disabled=\"currentPage === totalPages\"\n data-test=\"next-page-button\"\n aria-label=\"Next page\"\n :aria-disabled=\"currentPage === totalPages\"\n @click=\"selectPage(currentPage + 1)\"\n >\n <slot name=\"next-page-button\">Next</slot>\n </button>\n </nav>\n</template>\n\n<script lang=\"ts\">\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport { computed, defineComponent } from 'vue'\nimport { useXBus } from '../composables'\n\ninterface PageItem {\n value: number | string\n isSelected: boolean\n}\n\n/**\n * Component that renders a pagination control with buttons for navigating\n * between pages. It displays the current page, allows selecting other pages,\n * and emits events when a page is selected.\n *\n * @public\n */\nexport default defineComponent({\n name: 'PageSelector',\n props: {\n /**\n * CSS classes to customize the prev/next buttons.\n */\n buttonClasses: {\n type: Array as PropType<(string | Dictionary<boolean>)[]>,\n default: () => [],\n },\n /**\n * The current page number.\n */\n currentPage: {\n type: Number,\n required: true,\n },\n /**\n * The string content of the hidden pages.\n */\n hiddenPage: {\n type: String,\n default: '...',\n },\n /**\n * CSS classes to customize the page items.\n */\n itemClasses: {\n type: Function as PropType<\n (isSelected: boolean) => string | Dictionary<boolean> | (string | Dictionary<boolean>)[]\n >,\n default: () => [],\n },\n /**\n * The number of pages to show before and after the current page.\n */\n range: {\n type: Number,\n default: 2,\n },\n /**\n * The class of the scroll container to scroll to top when a page is selected.\n */\n scrollTarget: {\n type: String,\n default: 'main-scroll',\n },\n /**\n * The total number of pages.\n */\n totalPages: {\n type: Number,\n required: true,\n },\n },\n setup(props) {\n const bus = useXBus()\n\n const visiblePages = computed(() => {\n const start = Math.max(props.currentPage - props.range, 1)\n const end = Math.min(props.currentPage + props.range, props.totalPages)\n const pages: PageItem[] = Array.from({ length: end - start + 1 }, (_, i) => {\n const pageValue: string | number = start + i\n return { value: pageValue, isSelected: pageValue === props.currentPage }\n })\n\n // Ensure first and last pages are always visible when needed\n if (start > 1) {\n pages.unshift({ value: 1, isSelected: props.currentPage === 1 })\n if (start > 2) {\n pages.splice(1, 0, { value: props.hiddenPage, isSelected: false })\n }\n }\n if (end < props.totalPages) {\n if (end < props.totalPages - 1) {\n pages.push({ value: props.hiddenPage, isSelected: false })\n }\n pages.push({\n value: props.totalPages,\n isSelected: props.totalPages === props.currentPage,\n })\n }\n\n return pages\n })\n\n /**\n * Handles the selection of a page.\n *\n * @param page - The page to select. Can be a number representing the page number or a string '...' indicating an ellipsis.\n */\n const selectPage = (page: number | string): void => {\n if (page === '...') {\n return\n }\n if (typeof page === 'number' && page > 0 && page <= props.totalPages) {\n bus.emit('UserSelectedAPage', page)\n /**\n * Emits scroll to top to prevent keeping the position if there is more content\n * after results, as for example Next Queries Preview.\n */\n bus.emit('UserClickedScrollToTop', props.scrollTarget)\n }\n }\n\n return {\n visiblePages,\n selectPage,\n }\n },\n})\n</script>\n\n<style scoped>\n.x-page-selector {\n display: flex;\n justify-content: center;\n align-items: center;\n gap: 2px;\n}\n\n.x-page-selector__page--current,\n.x-page-selector__page--hidden {\n cursor: default;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the \"UserSelectedAPage\" and the UserClickedScrollToTop events by default.\n\n## See it in action\n\nBasic example of how the component is rendered.\n\n```vue live\n<template>\n <PageSelector :current-page=\"page\" :total-pages=\"totalPages\" />\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 0,\n totalPages: 10,\n }\n },\n}\n</script>\n```\n\n### Customize the slots\n\nThis component allows to customise its content using slots.\n\n```vue live\n<template>\n <PageSelector\n :total-pages=\"totalPages\"\n :currentPage=\"page\"\n :item-classes=\"\n (isSelected: boolean) =>\n isSelected\n ? 'x-button-lead x-text-neutral-10'\n : 'x-text-neutral-90 x-button-outlined'\n \"\n :buttonClasses=\"['x-rounded-md']\"\n >\n <template #previous-page-button>\n <span>Back</span>\n </template>\n <template #page-button=\"{ page, isSelected }\">\n <h2 :class=\"{ 'x-text1': !isSelected }\">\n {{ page }}\n </h2>\n </template>\n <template #next-page-button>\n <span>Forward</span>\n </template>\n </PageSelector>\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 2,\n totalPages: 10,\n }\n },\n}\n</script>\n```\n\n### Customize the number of pages to show before and after the current page by changing the range default value.\n\n```vue live\n<template>\n <PageSelector :current-page=\"page\" :total-pages=\"totalPages\" :range=\"range\" />\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 6,\n totalPages: 100,\n range: 4,\n }\n },\n}\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_createElementVNode","_normalizeClass","_renderSlot","_createTextVNode","_Fragment","_renderList","_toDisplayString"],"mappings":";;;;;;;EACuC,KAAA,EAAM,iBAAA;AAAA,EAAkB,YAAA,EAAW;;;;;;AAA7D,EAAA,OAAA,IAAA,CAAA,YAAA,EAAc,MAAA,GAAM,CAAA,IAAAA,SAAA,EAAA,EAA/BC,kBAAA,CA6CM,KAAA,EA7CN,UAAA,EA6CM;AAAA,IA5CJC,kBAAA,CAUS,QAAA,EAAA;AAAA,MATP,KAAA,EAAKC,cAAA,CAAA,CAAC,YAAA,EACE,IAAA,CAAA,aAAa,CAAA,CAAA;AAAA,MACpB,UAAU,IAAA,CAAA,WAAA,KAAW,CAAA;AAAA,MACtB,WAAA,EAAU,sBAAA;AAAA,MACV,YAAA,EAAW,eAAA;AAAA,MACV,iBAAe,IAAA,CAAA,WAAA,KAAW,CAAA;AAAA,MAC1B,OAAA,EAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CA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K,KAAK,CAAA;AAAA,cAAA;AAAA;AAAA;AAAA,WAAA,EAAA,IAAA;;;;;;IAIjBN,kBAAA,CAUS,QAAA,EAAA;AAAA,MATP,KAAA,EAAKC,cAAA,CAAA,CAAC,YAAA,EACE,IAAA,CAAA,aAAa,CAAA,CAAA;AAAA,MACpB,UAAU,IAAA,CAAA,WAAA,KAAgB,IAAA,CAAA,UAAA;AAAA,MAC3B,WAAA,EAAU,kBAAA;AAAA,MACV,YAAA,EAAW,WAAA;AAAA,MACV,iBAAe,IAAA,CAAA,WAAA,KAAgB,IAAA,CAAA,UAAA;AAAA,MAC/B,OAAA,EAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,MAAA,KAAE,IAAA,CAAA,UAAA,CAAW,IAAA,CAAA,WAAA,GAAW,CAAA,CAAA;AAAA,KAAA,EAAA;AAE9B,MAAAC,UAAA,CAAyC,qCAAzC,MAAyC;AAAA,QAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAC,eAAA;AAAX,UAAA,MAAA;AAAA,UAAI;AAAA;AAAA,SAAA;AAAA,OAAA,EAAA,IAAA;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"page-selector.vue.js","sources":["../../../src/components/page-selector.vue"],"sourcesContent":["<template>\n <nav v-if=\"visiblePages?.length > 1\" class=\"x-page-selector\" :aria-label=\"ariaLabels?.pagination\">\n <button\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :disabled=\"currentPage === 1\"\n data-test=\"previous-page-button\"\n :aria-label=\"ariaLabels?.prevPage\"\n :aria-disabled=\"currentPage === 1\"\n @click=\"selectPage(currentPage - 1)\"\n >\n <slot name=\"previous-page-button\">Prev</slot>\n </button>\n\n <button\n v-for=\"page in visiblePages\"\n :key=\"page.value\"\n class=\"x-page-selector__page xds:button\"\n :class=\"[\n itemClasses(page.isSelected),\n {\n 'x-page-selector__page--current': page.isSelected,\n 'x-page-selector__page--hidden': page.value === hiddenPage,\n },\n ]\"\n :data-test=\"`page-button-${page.value}`\"\n :aria-label=\"ariaLabels?.numberPage!(page.value)\"\n :aria-current=\"page.isSelected ? 'page' : undefined\"\n @click=\"selectPage(page.value)\"\n >\n <slot name=\"page-button\" :page=\"page.value\" :is-selected=\"page.isSelected\">\n {{ page.value }}\n </slot>\n </button>\n\n <button\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :disabled=\"currentPage === totalPages\"\n data-test=\"next-page-button\"\n :aria-label=\"ariaLabels?.nextPage\"\n :aria-disabled=\"currentPage === totalPages\"\n @click=\"selectPage(currentPage + 1)\"\n >\n <slot name=\"next-page-button\">Next</slot>\n </button>\n </nav>\n</template>\n\n<script lang=\"ts\">\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport type { AriaLabels } from '../types'\nimport { computed, defineComponent, inject } from 'vue'\nimport { useXBus } from '../composables'\nimport { ACCESSIBILITY_KEY } from '../types'\n\ninterface PageItem {\n value: number | string\n isSelected: boolean\n}\n\n/**\n * Component that renders a pagination control with buttons for navigating\n * between pages. It displays the current page, allows selecting other pages,\n * and emits events when a page is selected.\n *\n * @public\n */\nexport default defineComponent({\n name: 'PageSelector',\n props: {\n /**\n * CSS classes to customize the prev/next buttons.\n */\n buttonClasses: {\n type: Array as PropType<(string | Dictionary<boolean>)[]>,\n default: () => [],\n },\n /**\n * The current page number.\n */\n currentPage: {\n type: Number,\n required: true,\n },\n /**\n * The string content of the hidden pages.\n */\n hiddenPage: {\n type: String,\n default: '...',\n },\n /**\n * CSS classes to customize the page items.\n */\n itemClasses: {\n type: Function as PropType<\n (isSelected: boolean) => string | Dictionary<boolean> | (string | Dictionary<boolean>)[]\n >,\n default: () => [],\n },\n /**\n * The number of pages to show before and after the current page.\n */\n range: {\n type: Number,\n default: 2,\n },\n /**\n * The class of the scroll container to scroll to top when a page is selected.\n */\n scrollTarget: {\n type: String,\n default: 'main-scroll',\n },\n /**\n * The total number of pages.\n */\n totalPages: {\n type: Number,\n required: true,\n },\n },\n setup(props) {\n const bus = useXBus()\n\n const { pageSelector: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n const visiblePages = computed(() => {\n const start = Math.max(props.currentPage - props.range, 1)\n const end = Math.min(props.currentPage + props.range, props.totalPages)\n const pages: PageItem[] = Array.from({ length: end - start + 1 }, (_, i) => {\n const pageValue: string | number = start + i\n return { value: pageValue, isSelected: pageValue === props.currentPage }\n })\n\n // Ensure first and last pages are always visible when needed\n if (start > 1) {\n pages.unshift({ value: 1, isSelected: props.currentPage === 1 })\n if (start > 2) {\n pages.splice(1, 0, { value: props.hiddenPage, isSelected: false })\n }\n }\n if (end < props.totalPages) {\n if (end < props.totalPages - 1) {\n pages.push({ value: props.hiddenPage, isSelected: false })\n }\n pages.push({\n value: props.totalPages,\n isSelected: props.totalPages === props.currentPage,\n })\n }\n\n return pages\n })\n\n /**\n * Handles the selection of a page.\n *\n * @param page - The page to select. Can be a number representing the page number or a string '...' indicating an ellipsis.\n */\n const selectPage = (page: number | string): void => {\n if (page === '...') {\n return\n }\n if (typeof page === 'number' && page > 0 && page <= props.totalPages) {\n bus.emit('UserSelectedAPage', page)\n /**\n * Emits scroll to top to prevent keeping the position if there is more content\n * after results, as for example Next Queries Preview.\n */\n bus.emit('UserClickedScrollToTop', props.scrollTarget)\n }\n }\n\n return {\n ariaLabels,\n visiblePages,\n selectPage,\n }\n },\n})\n</script>\n\n<style scoped>\n.x-page-selector {\n display: flex;\n justify-content: center;\n align-items: center;\n gap: 2px;\n}\n\n.x-page-selector__page--current,\n.x-page-selector__page--hidden {\n cursor: default;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the \"UserSelectedAPage\" and the UserClickedScrollToTop events by default.\n\n## See it in action\n\nBasic example of how the component is rendered.\n\n```vue live\n<template>\n <PageSelector :current-page=\"page\" :total-pages=\"totalPages\" />\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 0,\n totalPages: 10,\n }\n },\n}\n</script>\n```\n\n### Customize the slots\n\nThis component allows to customise its content using slots.\n\n```vue live\n<template>\n <PageSelector\n :total-pages=\"totalPages\"\n :currentPage=\"page\"\n :item-classes=\"\n (isSelected: boolean) =>\n isSelected\n ? 'x-button-lead x-text-neutral-10'\n : 'x-text-neutral-90 x-button-outlined'\n \"\n :buttonClasses=\"['x-rounded-md']\"\n >\n <template #previous-page-button>\n <span>Back</span>\n </template>\n <template #page-button=\"{ page, isSelected }\">\n <h2 :class=\"{ 'x-text1': !isSelected }\">\n {{ page }}\n </h2>\n </template>\n <template #next-page-button>\n <span>Forward</span>\n </template>\n </PageSelector>\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 2,\n totalPages: 10,\n }\n },\n}\n</script>\n```\n\n### Customize the number of pages to show before and after the current page by changing the range default value.\n\n```vue live\n<template>\n <PageSelector :current-page=\"page\" :total-pages=\"totalPages\" :range=\"range\" />\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 6,\n totalPages: 100,\n range: 4,\n }\n },\n}\n</script>\n```\n</docs>\n"],"names":["_createElementBlock","_createElementVNode","_normalizeClass","_renderSlot","_createTextVNode","_openBlock","_Fragment","_renderList","_toDisplayString"],"mappings":";;;;;;;;;;SACa,IAAA,CAAA,YAAA,EAAc,MAAA,GAAM,kBAA/BA,kBAAA,CA6CM,KAAA,EAAA;AAAA,IAAA,GAAA,EAAA,CAAA;IA7C+B,KAAA,EAAM,iBAAA;AAAA,IAAmB,cAAY,IAAA,CAAA,UAAA,EAAY;AAAA,GAAA,EAAA;IACpFC,kBAAA,CAUS,QAAA,EAAA;AAAA,MATP,KAAA,EA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/create-use-device.js';
|
|
3
3
|
import 'vuex';
|
|
4
4
|
import '../plugins/x-bus.js';
|
|
@@ -6,6 +6,7 @@ import '@empathyco/x-utils';
|
|
|
6
6
|
import '../plugins/x-plugin.js';
|
|
7
7
|
import { useXBus } from '../composables/use-x-bus.js';
|
|
8
8
|
import '@vueuse/core';
|
|
9
|
+
import { ACCESSIBILITY_KEY } from '../types/accessibility.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Component that renders a pagination control with buttons for navigating
|
|
@@ -69,6 +70,7 @@ var _sfc_main = defineComponent({
|
|
|
69
70
|
},
|
|
70
71
|
setup(props) {
|
|
71
72
|
const bus = useXBus();
|
|
73
|
+
const { pageSelector: ariaLabels } = inject(ACCESSIBILITY_KEY);
|
|
72
74
|
const visiblePages = computed(() => {
|
|
73
75
|
const start = Math.max(props.currentPage - props.range, 1);
|
|
74
76
|
const end = Math.min(props.currentPage + props.range, props.totalPages);
|
|
@@ -113,6 +115,7 @@ var _sfc_main = defineComponent({
|
|
|
113
115
|
}
|
|
114
116
|
};
|
|
115
117
|
return {
|
|
118
|
+
ariaLabels,
|
|
116
119
|
visiblePages,
|
|
117
120
|
selectPage,
|
|
118
121
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-selector.vue2.js","sources":["../../../src/components/page-selector.vue"],"sourcesContent":["<template>\n <nav v-if=\"visiblePages?.length > 1\" class=\"x-page-selector\" aria-label=\"Pagination\">\n <button\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :disabled=\"currentPage === 1\"\n data-test=\"previous-page-button\"\n aria-label=\"Previous page\"\n :aria-disabled=\"currentPage === 1\"\n @click=\"selectPage(currentPage - 1)\"\n >\n <slot name=\"previous-page-button\">Prev</slot>\n </button>\n\n <button\n v-for=\"page in visiblePages\"\n :key=\"page.value\"\n class=\"x-page-selector__page xds:button\"\n :class=\"[\n itemClasses(page.isSelected),\n {\n 'x-page-selector__page--current': page.isSelected,\n 'x-page-selector__page--hidden': page.value === hiddenPage,\n },\n ]\"\n :data-test=\"`page-button-${page.value}`\"\n :aria-label=\"`Page ${page.value}`\"\n :aria-current=\"page.isSelected ? 'page' : undefined\"\n @click=\"selectPage(page.value)\"\n >\n <slot name=\"page-button\" :page=\"page.value\" :is-selected=\"page.isSelected\">\n {{ page.value }}\n </slot>\n </button>\n\n <button\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :disabled=\"currentPage === totalPages\"\n data-test=\"next-page-button\"\n aria-label=\"Next page\"\n :aria-disabled=\"currentPage === totalPages\"\n @click=\"selectPage(currentPage + 1)\"\n >\n <slot name=\"next-page-button\">Next</slot>\n </button>\n </nav>\n</template>\n\n<script lang=\"ts\">\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport { computed, defineComponent } from 'vue'\nimport { useXBus } from '../composables'\n\ninterface PageItem {\n value: number | string\n isSelected: boolean\n}\n\n/**\n * Component that renders a pagination control with buttons for navigating\n * between pages. It displays the current page, allows selecting other pages,\n * and emits events when a page is selected.\n *\n * @public\n */\nexport default defineComponent({\n name: 'PageSelector',\n props: {\n /**\n * CSS classes to customize the prev/next buttons.\n */\n buttonClasses: {\n type: Array as PropType<(string | Dictionary<boolean>)[]>,\n default: () => [],\n },\n /**\n * The current page number.\n */\n currentPage: {\n type: Number,\n required: true,\n },\n /**\n * The string content of the hidden pages.\n */\n hiddenPage: {\n type: String,\n default: '...',\n },\n /**\n * CSS classes to customize the page items.\n */\n itemClasses: {\n type: Function as PropType<\n (isSelected: boolean) => string | Dictionary<boolean> | (string | Dictionary<boolean>)[]\n >,\n default: () => [],\n },\n /**\n * The number of pages to show before and after the current page.\n */\n range: {\n type: Number,\n default: 2,\n },\n /**\n * The class of the scroll container to scroll to top when a page is selected.\n */\n scrollTarget: {\n type: String,\n default: 'main-scroll',\n },\n /**\n * The total number of pages.\n */\n totalPages: {\n type: Number,\n required: true,\n },\n },\n setup(props) {\n const bus = useXBus()\n\n const visiblePages = computed(() => {\n const start = Math.max(props.currentPage - props.range, 1)\n const end = Math.min(props.currentPage + props.range, props.totalPages)\n const pages: PageItem[] = Array.from({ length: end - start + 1 }, (_, i) => {\n const pageValue: string | number = start + i\n return { value: pageValue, isSelected: pageValue === props.currentPage }\n })\n\n // Ensure first and last pages are always visible when needed\n if (start > 1) {\n pages.unshift({ value: 1, isSelected: props.currentPage === 1 })\n if (start > 2) {\n pages.splice(1, 0, { value: props.hiddenPage, isSelected: false })\n }\n }\n if (end < props.totalPages) {\n if (end < props.totalPages - 1) {\n pages.push({ value: props.hiddenPage, isSelected: false })\n }\n pages.push({\n value: props.totalPages,\n isSelected: props.totalPages === props.currentPage,\n })\n }\n\n return pages\n })\n\n /**\n * Handles the selection of a page.\n *\n * @param page - The page to select. Can be a number representing the page number or a string '...' indicating an ellipsis.\n */\n const selectPage = (page: number | string): void => {\n if (page === '...') {\n return\n }\n if (typeof page === 'number' && page > 0 && page <= props.totalPages) {\n bus.emit('UserSelectedAPage', page)\n /**\n * Emits scroll to top to prevent keeping the position if there is more content\n * after results, as for example Next Queries Preview.\n */\n bus.emit('UserClickedScrollToTop', props.scrollTarget)\n }\n }\n\n return {\n visiblePages,\n selectPage,\n }\n },\n})\n</script>\n\n<style scoped>\n.x-page-selector {\n display: flex;\n justify-content: center;\n align-items: center;\n gap: 2px;\n}\n\n.x-page-selector__page--current,\n.x-page-selector__page--hidden {\n cursor: default;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the \"UserSelectedAPage\" and the UserClickedScrollToTop events by default.\n\n## See it in action\n\nBasic example of how the component is rendered.\n\n```vue live\n<template>\n <PageSelector :current-page=\"page\" :total-pages=\"totalPages\" />\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 0,\n totalPages: 10,\n }\n },\n}\n</script>\n```\n\n### Customize the slots\n\nThis component allows to customise its content using slots.\n\n```vue live\n<template>\n <PageSelector\n :total-pages=\"totalPages\"\n :currentPage=\"page\"\n :item-classes=\"\n (isSelected: boolean) =>\n isSelected\n ? 'x-button-lead x-text-neutral-10'\n : 'x-text-neutral-90 x-button-outlined'\n \"\n :buttonClasses=\"['x-rounded-md']\"\n >\n <template #previous-page-button>\n <span>Back</span>\n </template>\n <template #page-button=\"{ page, isSelected }\">\n <h2 :class=\"{ 'x-text1': !isSelected }\">\n {{ page }}\n </h2>\n </template>\n <template #next-page-button>\n <span>Forward</span>\n </template>\n </PageSelector>\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 2,\n totalPages: 10,\n }\n },\n}\n</script>\n```\n\n### Customize the number of pages to show before and after the current page by changing the range default value.\n\n```vue live\n<template>\n <PageSelector :current-page=\"page\" :total-pages=\"totalPages\" :range=\"range\" />\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 6,\n totalPages: 100,\n range: 4,\n }\n },\n}\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;;;AA4DA;;;;;;AAME;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,cAAc;AACpB,IAAA,KAAK,EAAE;AACL;;AAEE;AACF,QAAA,aAAa,EAAE;AACb,YAAA,IAAI,EAAE,KAAmD;AACzD,YAAA,OAAO,EAAE,MAAM,EAAE;AAClB,SAAA;AACD;;AAEE;AACF,QAAA,WAAW,EAAE;AACX,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;AAEE;AACF,QAAA,UAAU,EAAE;AACV,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;AACD;;AAEE;AACF,QAAA,WAAW,EAAE;AACX,YAAA,IAAI,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,gBAAA,IAAI,KAAI,GAAI,CAAC,EAAE;AACb,oBAAA,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,KAAI,EAAG,CAAA;gBACnE;YACF;AACA,YAAA,IAAI,MAAM,KAAK,CAAC,UAAU,EAAE;gBAC1B,IAAI,GAAE,GAAI,KAAK,CAAC,UAAS,GAAI,CAAC,EAAE;AAC9B,oBAAA,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,KAAI,EAAG,CAAA;gBAC3D;gBACA,KAAK,CAAC,IAAI,CAAC;oBACT,KAAK,EAAE,KAAK,CAAC,UAAU;AACvB,oBAAA,UAAU,EAAE,KAAK,CAAC,eAAe,KAAK,CAAC,WAAW;AACnD,iBAAA,CAAA;YACH;AAEA,YAAA,OAAO,KAAI;AACb,QAAA,CAAC,CAAA;AAED;;;;AAIE;AACF,QAAA,MAAM,UAAS,GAAI,CAAC,IAAqB,KAAS;AAChD,YAAA,IAAI,IAAG,KAAM,KAAK,EAAE;gBAClB;YACF;AACA,YAAA,IAAI,OAAO,IAAG,KAAM,QAAO,IAAK,IAAG,GAAI,CAAA,IAAK,IAAG,IAAK,KAAK,CAAC,UAAU,EAAE;AACpE,gBAAA,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAA;AAClC;;;AAGE;gBACF,GAAG,CAAC,IAAI,CAAC,wBAAwB,EAAE,KAAK,CAAC,YAAY,CAAA;YACvD;AACF,QAAA,CAAA;QAEA,OAAO;YACL,YAAY;YACZ,UAAU;SACZ;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"page-selector.vue2.js","sources":["../../../src/components/page-selector.vue"],"sourcesContent":["<template>\n <nav v-if=\"visiblePages?.length > 1\" class=\"x-page-selector\" :aria-label=\"ariaLabels?.pagination\">\n <button\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :disabled=\"currentPage === 1\"\n data-test=\"previous-page-button\"\n :aria-label=\"ariaLabels?.prevPage\"\n :aria-disabled=\"currentPage === 1\"\n @click=\"selectPage(currentPage - 1)\"\n >\n <slot name=\"previous-page-button\">Prev</slot>\n </button>\n\n <button\n v-for=\"page in visiblePages\"\n :key=\"page.value\"\n class=\"x-page-selector__page xds:button\"\n :class=\"[\n itemClasses(page.isSelected),\n {\n 'x-page-selector__page--current': page.isSelected,\n 'x-page-selector__page--hidden': page.value === hiddenPage,\n },\n ]\"\n :data-test=\"`page-button-${page.value}`\"\n :aria-label=\"ariaLabels?.numberPage!(page.value)\"\n :aria-current=\"page.isSelected ? 'page' : undefined\"\n @click=\"selectPage(page.value)\"\n >\n <slot name=\"page-button\" :page=\"page.value\" :is-selected=\"page.isSelected\">\n {{ page.value }}\n </slot>\n </button>\n\n <button\n class=\"xds:button\"\n :class=\"buttonClasses\"\n :disabled=\"currentPage === totalPages\"\n data-test=\"next-page-button\"\n :aria-label=\"ariaLabels?.nextPage\"\n :aria-disabled=\"currentPage === totalPages\"\n @click=\"selectPage(currentPage + 1)\"\n >\n <slot name=\"next-page-button\">Next</slot>\n </button>\n </nav>\n</template>\n\n<script lang=\"ts\">\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport type { AriaLabels } from '../types'\nimport { computed, defineComponent, inject } from 'vue'\nimport { useXBus } from '../composables'\nimport { ACCESSIBILITY_KEY } from '../types'\n\ninterface PageItem {\n value: number | string\n isSelected: boolean\n}\n\n/**\n * Component that renders a pagination control with buttons for navigating\n * between pages. It displays the current page, allows selecting other pages,\n * and emits events when a page is selected.\n *\n * @public\n */\nexport default defineComponent({\n name: 'PageSelector',\n props: {\n /**\n * CSS classes to customize the prev/next buttons.\n */\n buttonClasses: {\n type: Array as PropType<(string | Dictionary<boolean>)[]>,\n default: () => [],\n },\n /**\n * The current page number.\n */\n currentPage: {\n type: Number,\n required: true,\n },\n /**\n * The string content of the hidden pages.\n */\n hiddenPage: {\n type: String,\n default: '...',\n },\n /**\n * CSS classes to customize the page items.\n */\n itemClasses: {\n type: Function as PropType<\n (isSelected: boolean) => string | Dictionary<boolean> | (string | Dictionary<boolean>)[]\n >,\n default: () => [],\n },\n /**\n * The number of pages to show before and after the current page.\n */\n range: {\n type: Number,\n default: 2,\n },\n /**\n * The class of the scroll container to scroll to top when a page is selected.\n */\n scrollTarget: {\n type: String,\n default: 'main-scroll',\n },\n /**\n * The total number of pages.\n */\n totalPages: {\n type: Number,\n required: true,\n },\n },\n setup(props) {\n const bus = useXBus()\n\n const { pageSelector: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n const visiblePages = computed(() => {\n const start = Math.max(props.currentPage - props.range, 1)\n const end = Math.min(props.currentPage + props.range, props.totalPages)\n const pages: PageItem[] = Array.from({ length: end - start + 1 }, (_, i) => {\n const pageValue: string | number = start + i\n return { value: pageValue, isSelected: pageValue === props.currentPage }\n })\n\n // Ensure first and last pages are always visible when needed\n if (start > 1) {\n pages.unshift({ value: 1, isSelected: props.currentPage === 1 })\n if (start > 2) {\n pages.splice(1, 0, { value: props.hiddenPage, isSelected: false })\n }\n }\n if (end < props.totalPages) {\n if (end < props.totalPages - 1) {\n pages.push({ value: props.hiddenPage, isSelected: false })\n }\n pages.push({\n value: props.totalPages,\n isSelected: props.totalPages === props.currentPage,\n })\n }\n\n return pages\n })\n\n /**\n * Handles the selection of a page.\n *\n * @param page - The page to select. Can be a number representing the page number or a string '...' indicating an ellipsis.\n */\n const selectPage = (page: number | string): void => {\n if (page === '...') {\n return\n }\n if (typeof page === 'number' && page > 0 && page <= props.totalPages) {\n bus.emit('UserSelectedAPage', page)\n /**\n * Emits scroll to top to prevent keeping the position if there is more content\n * after results, as for example Next Queries Preview.\n */\n bus.emit('UserClickedScrollToTop', props.scrollTarget)\n }\n }\n\n return {\n ariaLabels,\n visiblePages,\n selectPage,\n }\n },\n})\n</script>\n\n<style scoped>\n.x-page-selector {\n display: flex;\n justify-content: center;\n align-items: center;\n gap: 2px;\n}\n\n.x-page-selector__page--current,\n.x-page-selector__page--hidden {\n cursor: default;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the \"UserSelectedAPage\" and the UserClickedScrollToTop events by default.\n\n## See it in action\n\nBasic example of how the component is rendered.\n\n```vue live\n<template>\n <PageSelector :current-page=\"page\" :total-pages=\"totalPages\" />\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 0,\n totalPages: 10,\n }\n },\n}\n</script>\n```\n\n### Customize the slots\n\nThis component allows to customise its content using slots.\n\n```vue live\n<template>\n <PageSelector\n :total-pages=\"totalPages\"\n :currentPage=\"page\"\n :item-classes=\"\n (isSelected: boolean) =>\n isSelected\n ? 'x-button-lead x-text-neutral-10'\n : 'x-text-neutral-90 x-button-outlined'\n \"\n :buttonClasses=\"['x-rounded-md']\"\n >\n <template #previous-page-button>\n <span>Back</span>\n </template>\n <template #page-button=\"{ page, isSelected }\">\n <h2 :class=\"{ 'x-text1': !isSelected }\">\n {{ page }}\n </h2>\n </template>\n <template #next-page-button>\n <span>Forward</span>\n </template>\n </PageSelector>\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 2,\n totalPages: 10,\n }\n },\n}\n</script>\n```\n\n### Customize the number of pages to show before and after the current page by changing the range default value.\n\n```vue live\n<template>\n <PageSelector :current-page=\"page\" :total-pages=\"totalPages\" :range=\"range\" />\n</template>\n\n<script>\nimport { PageSelector } from '@empathyco/x-components'\n\nexport default {\n name: 'PageSelectorDemo',\n components: {\n PageSelector,\n },\n data() {\n return {\n page: 6,\n totalPages: 100,\n range: 4,\n }\n },\n}\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;;;;AA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AAI,IAAG,KAAM,KAAK,EAAE;gBAClB;YACF;AACA,YAAA,IAAI,OAAO,IAAG,KAAM,QAAO,IAAK,IAAG,GAAI,CAAA,IAAK,IAAG,IAAK,KAAK,CAAC,UAAU,EAAE;AACpE,gBAAA,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAA;AAClC;;;AAGE;gBACF,GAAG,CAAC,IAAI,CAAC,wBAAwB,EAAE,KAAK,CAAC,YAAY,CAAA;YACvD;AACF,QAAA,CAAA;QAEA,OAAO;YACL,UAAU;YACV,YAAY;YACZ,UAAU;SACZ;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
@@ -11,7 +11,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
11
11
|
animation: _ctx.animation,
|
|
12
12
|
class: "x-sort-dropdown",
|
|
13
13
|
"data-test": "sort-dropdown",
|
|
14
|
-
"aria-label":
|
|
14
|
+
"aria-label": _ctx.ariaLabels?.dropdown,
|
|
15
15
|
"onUpdate:modelValue": _ctx.emitUserClickedASort
|
|
16
16
|
}, {
|
|
17
17
|
toggle: withCtx(({ isOpen, item }) => [
|
|
@@ -34,7 +34,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
34
34
|
]),
|
|
35
35
|
_: 3
|
|
36
36
|
/* FORWARDED */
|
|
37
|
-
}, 8, ["items", "model-value", "animation", "onUpdate:modelValue"]);
|
|
37
|
+
}, 8, ["items", "model-value", "animation", "aria-label", "onUpdate:modelValue"]);
|
|
38
38
|
}
|
|
39
39
|
var sortDropdown = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
40
40
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort-dropdown.vue.js","sources":["../../../../src/components/sort/sort-dropdown.vue"],"sourcesContent":["<template>\n <BaseDropdown\n ref=\"rootRef\"\n :items=\"items\"\n :model-value=\"selectedSort\"\n :animation=\"animation\"\n class=\"x-sort-dropdown\"\n data-test=\"sort-dropdown\"\n aria-label=\"
|
|
1
|
+
{"version":3,"file":"sort-dropdown.vue.js","sources":["../../../../src/components/sort/sort-dropdown.vue"],"sourcesContent":["<template>\n <BaseDropdown\n ref=\"rootRef\"\n :items=\"items\"\n :model-value=\"selectedSort\"\n :animation=\"animation\"\n class=\"x-sort-dropdown\"\n data-test=\"sort-dropdown\"\n :aria-label=\"ariaLabels?.dropdown\"\n @update:model-value=\"emitUserClickedASort\"\n >\n <template #toggle=\"{ isOpen, item }\">\n <!--\n @slot Used to render the contents of the dropdown toggle button. If not provided, it uses\n the item slot as fallback.\n @binding {Sort} item - The sort data to render.\n @binding {boolean} isOpen - True if the dropdown is opened, and false if it is closed.\n -->\n <slot v-bind=\"{ isOpen, item }\" name=\"toggle\">{{ item }}</slot>\n </template>\n <template #item=\"{ item, isHighlighted, isSelected }\">\n <!--\n @slot (required) Used to render each one of the items content, and as fallback\n for the toggle button content slot if it is not provided.\n @binding {Sort} item - Sort to render\n @binding {boolean} isHighlighted - True when the item has the focus.\n @binding {boolean} isSelected - True when the item is selected.\n -->\n <slot v-bind=\"{ item, isHighlighted, isSelected }\" name=\"item\">{{ item }}</slot>\n </template>\n </BaseDropdown>\n</template>\n\n<script lang=\"ts\">\nimport type { Sort } from '@empathyco/x-types'\nimport type { Component, PropType } from 'vue'\nimport type { AriaLabels } from '../../types'\nimport type { XEvent } from '../../wiring/index'\nimport { defineComponent, inject, ref, watch } from 'vue'\nimport { use$x } from '../../composables/use-$x'\nimport { ACCESSIBILITY_KEY } from '../../types'\nimport BaseDropdown from '../base-dropdown.vue'\n\n/**\n * The `SortDropdown` component allows user to select the search results order. This component\n * also allows to change the selected sort programmatically.\n */\nexport default defineComponent({\n name: 'SortDropdown',\n components: { BaseDropdown },\n props: {\n /** The transition to use for opening and closing the dropdown. */\n animation: [String, Object] as PropType<string | Component>,\n /** The list of possible sort values. */\n items: {\n type: Array as PropType<Sort[]>,\n required: true,\n },\n selectedSort: {\n type: String as PropType<Sort>,\n required: true,\n },\n selectedSortProvidedEvent: {\n type: String as PropType<XEvent>,\n default: 'SelectedSortProvided',\n },\n clickedSortEvent: {\n type: String as PropType<XEvent>,\n default: 'UserClickedASort',\n },\n },\n emits: ['change'],\n setup(props, { emit }) {\n const $x = use$x()\n const rootRef = ref<typeof BaseDropdown>()\n\n const { sortDropdown: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n watch(\n () => props.selectedSort,\n value => $x.emit(props.selectedSortProvidedEvent, value),\n {\n immediate: true,\n },\n )\n\n /**\n * Emits the events related to the selection of a sort value.\n *\n * @remarks `(rootRef.value as any)?.$el` because rollup-plugin-vue understands\n * `ref<typeof BaseDropdown>` as VueConstructor which doesn't contain $el.\n *\n * @param sort - The selected sort.\n */\n function emitUserClickedASort(sort: Sort) {\n $x.emit(props.clickedSortEvent, sort, { target: (rootRef.value as any)?.$el })\n emit('change', sort)\n }\n\n return {\n ariaLabels,\n emitUserClickedASort,\n rootRef,\n }\n },\n})\n</script>\n\n<docs lang=\"mdx\">\n## Sort Dropdown\n\nThe `SortDropdown` component can be used to change the way the search results are ordered.\n\nTo do so, the list of valid sort values has to be provided using the `items` prop. These are the\nvalues that can be received then in the `SearchAdapter`.\n\nThe component also optionally accepts the selected sort, which can be set using the `v-model` prop.\nThis prop allows changing programmatically the selected sort, as it will be synced with the store\nimmediately. If this prop is not provided, the first item from the `items` prop will be the one\nselected by default.\n\nThis component also allows customizing both the toggle button and each one of the possible sort\nvalues. This can be done with the `toggle` and `item` slots.\n\n## Events\n\nThis component emits 2 different events:\n\n- [`SelectedSortProvided`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n To sync the selected sort with the store state value. This event is emitted as soon as the list of\n items is received, whenever this list changes if there is no provided value, and when the provided\n value changes.\n- [`UserClickedASort`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n As its name suggests, the event is emitted after the user clicks one of the sort options. This does\n not mean that the sort has changed, only that the user has clicked it.\n\n## Examples\n\n### Only providing the list of items\n\n```vue\n<template>\n <SortDropdown :items=\"sortValues\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}</template>\n <template #item=\"{ item, isHighlighted, isSelected }\">\n <span v-if=\"isSelected\">✅</span>\n <span v-if=\"isHighlighted\">🟢</span>\n {{ item }}\n </template>\n </SortDropdown>\n</template>\n\n<script setup>\nimport { SortDropdown } from '@empathyco/x-components/search'\nimport { ref } from 'vue'\n\nconst sortValues = ref(['Relevance', 'Price asc', 'Price desc'])\n</script>\n```\n\n### Providing also the selected value\n\n```vue\n<template>\n <SortDropdown v-model=\"selectedSort\" :items=\"sortValues\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}</template>\n <template #item=\"{ item, isHighlighted, isSelected }\">\n <span v-if=\"isSelected\">✅</span>\n <span v-if=\"isHighlighted\">🟢</span>\n {{ item }}\n </template>\n </SortDropdown>\n</template>\n\n<script setup>\nimport { SortDropdown } from '@empathyco/x-components/search'\nimport { ref } from 'vue'\n\nconst selectedSort = ref('Price asc')\nconst sortValues = ref(['Relevance', 'Price asc', 'Price desc'])\n</script>\n```\n</docs>\n"],"names":["_createBlock","_withCtx","_renderSlot","_normalizeProps","_guardReactiveProps","_createTextVNode"],"mappings":";;;;;;sBACEA,WAAA,CA6Be,uBAAA,EAAA;AAAA,IA5Bb,GAAA,EAAI,SAAA;AAAA,IACH,KAAA,EAAO,IAAA,CAAA,KAAA;AAAA,IACP,aAAA,EAAa,IAAA,CAAA,YAAA;AAAA,IACb,SAAA,EAAW,IAAA,CAAA,SAAA;AAAA,IACZ,KAAA,EAAM,iBAAA;AAAA,IACN,WAAA,EAAU,eAAA;AAAA,IACT,cAAY,IAAA,CAAA,UAAA,EAAY,QAAA;AAAA,IACxB,qBAAA,EAAoB,IAAA,CAAA;AAAA,GAAA,EAAA;AAEV,IAAA,MAAA,EAAMC,OAAA,CAOf,CAA+D,EAP5C,MAAA,EAAQ,IAAA,EAAI,KAAA;AAAA,MAO/BC,UAAA,CAA+D,IAAA,CAAA,MAAA,EAAA,QAAA,EAAAC,cAAA,CAAAC,kBAAA,CAAA,EAA/C,MAAA,EAAQ,IAAA,MAAxB,MAA+D;AAAA,QAAAC,eAAA;0BAAd,IAAI,CAAA;AAAA,UAAA;AAAA;AAAA;AAAA,OAAA;;AAE5C,IAAA,IAAA,EAAIJ,OAAA,CAQb,CAAgF,EAR/D,IAAA,EAAM,eAAe,UAAA,EAAU,KAAA;AAAA,MAQhDC,WAAgF,IAAA,CAAA,MAAA,EAAA,MAAA,EAAAC,cAAA,CAAAC,kBAAA,CAAA,EAAhE,IAAA,EAAM,aAAA,EAAe,UAAA,MAArC,MAAgF;AAAA,QAAAC,eAAA;0BAAd,IAAI,CAAA;AAAA,UAAA;AAAA;AAAA;AAAA,OAAA;;;;;;;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { defineComponent, ref, watch } from 'vue';
|
|
1
|
+
import { defineComponent, ref, inject, watch } from 'vue';
|
|
2
2
|
import { use$x } from '../../composables/use-_x.js';
|
|
3
|
+
import { ACCESSIBILITY_KEY } from '../../types/accessibility.js';
|
|
3
4
|
import BaseDropdown from '../base-dropdown.vue.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -34,6 +35,7 @@ var _sfc_main = defineComponent({
|
|
|
34
35
|
setup(props, { emit }) {
|
|
35
36
|
const $x = use$x();
|
|
36
37
|
const rootRef = ref();
|
|
38
|
+
const { sortDropdown: ariaLabels } = inject(ACCESSIBILITY_KEY);
|
|
37
39
|
watch(() => props.selectedSort, value => $x.emit(props.selectedSortProvidedEvent, value), {
|
|
38
40
|
immediate: true,
|
|
39
41
|
});
|
|
@@ -50,6 +52,7 @@ var _sfc_main = defineComponent({
|
|
|
50
52
|
emit('change', sort);
|
|
51
53
|
}
|
|
52
54
|
return {
|
|
55
|
+
ariaLabels,
|
|
53
56
|
emitUserClickedASort,
|
|
54
57
|
rootRef,
|
|
55
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort-dropdown.vue2.js","sources":["../../../../src/components/sort/sort-dropdown.vue"],"sourcesContent":["<template>\n <BaseDropdown\n ref=\"rootRef\"\n :items=\"items\"\n :model-value=\"selectedSort\"\n :animation=\"animation\"\n class=\"x-sort-dropdown\"\n data-test=\"sort-dropdown\"\n aria-label=\"
|
|
1
|
+
{"version":3,"file":"sort-dropdown.vue2.js","sources":["../../../../src/components/sort/sort-dropdown.vue"],"sourcesContent":["<template>\n <BaseDropdown\n ref=\"rootRef\"\n :items=\"items\"\n :model-value=\"selectedSort\"\n :animation=\"animation\"\n class=\"x-sort-dropdown\"\n data-test=\"sort-dropdown\"\n :aria-label=\"ariaLabels?.dropdown\"\n @update:model-value=\"emitUserClickedASort\"\n >\n <template #toggle=\"{ isOpen, item }\">\n <!--\n @slot Used to render the contents of the dropdown toggle button. If not provided, it uses\n the item slot as fallback.\n @binding {Sort} item - The sort data to render.\n @binding {boolean} isOpen - True if the dropdown is opened, and false if it is closed.\n -->\n <slot v-bind=\"{ isOpen, item }\" name=\"toggle\">{{ item }}</slot>\n </template>\n <template #item=\"{ item, isHighlighted, isSelected }\">\n <!--\n @slot (required) Used to render each one of the items content, and as fallback\n for the toggle button content slot if it is not provided.\n @binding {Sort} item - Sort to render\n @binding {boolean} isHighlighted - True when the item has the focus.\n @binding {boolean} isSelected - True when the item is selected.\n -->\n <slot v-bind=\"{ item, isHighlighted, isSelected }\" name=\"item\">{{ item }}</slot>\n </template>\n </BaseDropdown>\n</template>\n\n<script lang=\"ts\">\nimport type { Sort } from '@empathyco/x-types'\nimport type { Component, PropType } from 'vue'\nimport type { AriaLabels } from '../../types'\nimport type { XEvent } from '../../wiring/index'\nimport { defineComponent, inject, ref, watch } from 'vue'\nimport { use$x } from '../../composables/use-$x'\nimport { ACCESSIBILITY_KEY } from '../../types'\nimport BaseDropdown from '../base-dropdown.vue'\n\n/**\n * The `SortDropdown` component allows user to select the search results order. This component\n * also allows to change the selected sort programmatically.\n */\nexport default defineComponent({\n name: 'SortDropdown',\n components: { BaseDropdown },\n props: {\n /** The transition to use for opening and closing the dropdown. */\n animation: [String, Object] as PropType<string | Component>,\n /** The list of possible sort values. */\n items: {\n type: Array as PropType<Sort[]>,\n required: true,\n },\n selectedSort: {\n type: String as PropType<Sort>,\n required: true,\n },\n selectedSortProvidedEvent: {\n type: String as PropType<XEvent>,\n default: 'SelectedSortProvided',\n },\n clickedSortEvent: {\n type: String as PropType<XEvent>,\n default: 'UserClickedASort',\n },\n },\n emits: ['change'],\n setup(props, { emit }) {\n const $x = use$x()\n const rootRef = ref<typeof BaseDropdown>()\n\n const { sortDropdown: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n watch(\n () => props.selectedSort,\n value => $x.emit(props.selectedSortProvidedEvent, value),\n {\n immediate: true,\n },\n )\n\n /**\n * Emits the events related to the selection of a sort value.\n *\n * @remarks `(rootRef.value as any)?.$el` because rollup-plugin-vue understands\n * `ref<typeof BaseDropdown>` as VueConstructor which doesn't contain $el.\n *\n * @param sort - The selected sort.\n */\n function emitUserClickedASort(sort: Sort) {\n $x.emit(props.clickedSortEvent, sort, { target: (rootRef.value as any)?.$el })\n emit('change', sort)\n }\n\n return {\n ariaLabels,\n emitUserClickedASort,\n rootRef,\n }\n },\n})\n</script>\n\n<docs lang=\"mdx\">\n## Sort Dropdown\n\nThe `SortDropdown` component can be used to change the way the search results are ordered.\n\nTo do so, the list of valid sort values has to be provided using the `items` prop. These are the\nvalues that can be received then in the `SearchAdapter`.\n\nThe component also optionally accepts the selected sort, which can be set using the `v-model` prop.\nThis prop allows changing programmatically the selected sort, as it will be synced with the store\nimmediately. If this prop is not provided, the first item from the `items` prop will be the one\nselected by default.\n\nThis component also allows customizing both the toggle button and each one of the possible sort\nvalues. This can be done with the `toggle` and `item` slots.\n\n## Events\n\nThis component emits 2 different events:\n\n- [`SelectedSortProvided`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n To sync the selected sort with the store state value. This event is emitted as soon as the list of\n items is received, whenever this list changes if there is no provided value, and when the provided\n value changes.\n- [`UserClickedASort`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n As its name suggests, the event is emitted after the user clicks one of the sort options. This does\n not mean that the sort has changed, only that the user has clicked it.\n\n## Examples\n\n### Only providing the list of items\n\n```vue\n<template>\n <SortDropdown :items=\"sortValues\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}</template>\n <template #item=\"{ item, isHighlighted, isSelected }\">\n <span v-if=\"isSelected\">✅</span>\n <span v-if=\"isHighlighted\">🟢</span>\n {{ item }}\n </template>\n </SortDropdown>\n</template>\n\n<script setup>\nimport { SortDropdown } from '@empathyco/x-components/search'\nimport { ref } from 'vue'\n\nconst sortValues = ref(['Relevance', 'Price asc', 'Price desc'])\n</script>\n```\n\n### Providing also the selected value\n\n```vue\n<template>\n <SortDropdown v-model=\"selectedSort\" :items=\"sortValues\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}</template>\n <template #item=\"{ item, isHighlighted, isSelected }\">\n <span v-if=\"isSelected\">✅</span>\n <span v-if=\"isHighlighted\">🟢</span>\n {{ item }}\n </template>\n </SortDropdown>\n</template>\n\n<script setup>\nimport { SortDropdown } from '@empathyco/x-components/search'\nimport { ref } from 'vue'\n\nconst selectedSort = ref('Price asc')\nconst sortValues = ref(['Relevance', 'Price asc', 'Price desc'])\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;AA2CA;;;AAGE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,cAAc;IACpB,UAAU,EAAE,EAAE,YAAW,EAAG;AAC5B,IAAA,KAAK,EAAE;;AAEL,QAAA,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAiC;;AAE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uery } from './store/utils/query.util
|
|
|
173
173
|
export { setStatus } from './store/utils/status-store.utils.js';
|
|
174
174
|
export { createStoreEmitters } from './store/utils/store-emitters.utils.js';
|
|
175
175
|
export { RootXStoreModule } from './store/x.module.js';
|
|
176
|
+
export { ACCESSIBILITY_KEY } from './types/accessibility.js';
|
|
176
177
|
export { AnimationProp } from './types/animation-prop.js';
|
|
178
|
+
export { DEFAULT_ARIA_LABELS, mergeAccessibilityLabels } from './utils/accessibility.js';
|
|
177
179
|
export { arrayToObject, createEmitterArrayFilter, deepFilter, deepFlat, groupItemsBy, isArrayEmpty } from './utils/array.js';
|
|
178
180
|
export { CancelSymbol, cancellablePromise } from './utils/cancellable-promise.js';
|
|
179
181
|
export { clone } from './utils/clone.js';
|
package/js/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessibility.js","sources":["../../../src/types/accessibility.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\n\n/**\n * Configuration of the global aria labels for the components. Namespaces are the PascalCase\n * component names and every entry is optional, so the map can be set partially. The entries\n * `PageSelector.numberPage` and `BaseColumnPickerList.ariaLabel` are template strings: their\n * `page` and `column` tokens are substituted per item at resolution.\n *\n * @public\n */\nexport interface AriaLabels {\n pageSelector?: {\n pagination?: string\n prevPage?: string\n nextPage?: string\n numberPage?: (page: number | string) => string\n }\n aiCarousel?: { expand?: string; collapse?: string }\n baseColumnPickerDropdown?: { dropdown?: string }\n baseColumnPickerList?: { button?: (page: number) => string }\n pageLoaderButton?: { button?: string }\n baseModal?: { modal?: string }\n baseEventsModalOpen?: { button?: string }\n baseEventsModalClose?: { button?: string }\n sortDropdown?: { dropdown?: string }\n facets?: { root?: string }\n filtersSearch?: { input?: string }\n sliderFilter?: { min?: string; max?: string }\n editableNumberRangeFilter?: { min?: string; max?: string }\n searchInput?: { input?: string }\n clearHistoryQueries?: { button?: string }\n historyQueriesSwitch?: { root?: string }\n historyQuery?: { removeButton?: string }\n removeHistoryQuery?: { button?: string }\n scrollToTop?: { button?: string }\n baseDropdown?: { toggleButton?: string }\n}\n\nexport const ACCESSIBILITY_KEY: InjectionKey<AriaLabels> = Symbol('accessibility')\n"],"names":[],"mappings":"MAsCa,iBAAiB,GAA6B,MAAM,CAAC,eAAe;;;;"}
|