UNPKG

@shopware-ag/meteor-component-library

Version:

The meteor component library is a Vue component library developed by Shopware. It is based on the [Meteor Design System](https://shopware.design/).

164 lines (163 loc) 6.53 kB
import '../mt-pagination.css'; import { defineComponent, watch, computed, openBlock, createElementBlock, createElementVNode, toDisplayString, unref, createVNode, normalizeStyle } from "vue"; import { _ as _sfc_main$1 } from "../mt-icon.vue_vue_type_style_index_0_lang-2cc5f73e.mjs"; import { useI18n } from "vue-i18n"; import { _ as _export_sfc } from "../_plugin-vue_export-helper-cc2b3d55.mjs"; const _hoisted_1 = { class: "mt-pagination" }; const _hoisted_2 = { class: "mt-pagination__info-text", "data-testid": "mt-pagination-info-text" }; const _hoisted_3 = { class: "mt-pagination__controls" }; const _hoisted_4 = ["disabled"]; const _hoisted_5 = { class: "visually-hidden" }; const _hoisted_6 = ["disabled"]; const _hoisted_7 = { class: "visually-hidden" }; const _hoisted_8 = ["value", "aria-label"]; const _hoisted_9 = ["disabled"]; const _hoisted_10 = { class: "visually-hidden" }; const _hoisted_11 = ["disabled"]; const _hoisted_12 = { class: "visually-hidden" }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "mt-pagination", props: { currentPage: {}, limit: {}, totalItems: {} }, emits: ["change-current-page"], setup(__props, { emit: __emit }) { const props = __props; const { t } = useI18n({ messages: { en: { infoText: "{start}-{end} of {totalItems}", firstPage: "First page", previousPage: "Previous page", nextPage: "Next page", lastPage: "Last page" }, de: { infoText: "{start}-{end} von {totalItems}", firstPage: "Erste Seite", previousPage: "Voherige Seite", nextPage: "Nächste Seite", lastPage: "Letzte Seite" } } }); const emit = __emit; watch( () => props.limit, () => { emit("change-current-page", 1); } ); const totalPages = computed(() => { return Math.max(1, Math.ceil(props.totalItems / props.limit)); }); const isOnFirstPage = computed(() => props.currentPage === 1); const isOnLastPage = computed(() => props.currentPage === totalPages.value); const inputLength = computed(() => { const length = props.currentPage.toString().length; if (length === 0) return "calc(1ch + 1px)"; return `calc(${length}ch + 1px)`; }); function onChangeInput(event) { const target = event.target; if (target.value === "") return; emit("change-current-page", parseInt(target.value)); } const firstVisibleItemNumber = computed(() => (props.currentPage - 1) * props.limit + 1); const lastVisibleItemNumber = computed(() => { const lastItemNumberWithLimitOnly = props.limit * props.currentPage; return lastItemNumberWithLimitOnly > props.totalItems ? props.totalItems : lastItemNumberWithLimitOnly; }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", _hoisted_1, [ createElementVNode("p", _hoisted_2, toDisplayString(unref(t)("infoText", { start: firstVisibleItemNumber.value, end: lastVisibleItemNumber.value, totalItems: _ctx.totalItems })), 1), createElementVNode("div", _hoisted_3, [ createElementVNode("button", { type: "button", class: "mt-pagination__button", disabled: isOnFirstPage.value, onClick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("change-current-page", 1)), "data-testid": "mt-pagination-first-page-button" }, [ createElementVNode("span", _hoisted_5, toDisplayString(unref(t)("firstPage")), 1), createVNode(_sfc_main$1, { name: "regular-double-chevron-left-s", size: "0.5rem", "aria-hidden": "true" }) ], 8, _hoisted_4), createElementVNode("button", { type: "button", class: "mt-pagination__button", disabled: isOnFirstPage.value, onClick: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("change-current-page", _ctx.currentPage - 1)), "data-testid": "mt-pagination-previous-page-button" }, [ createElementVNode("span", _hoisted_7, toDisplayString(unref(t)("previousPage")), 1), createVNode(_sfc_main$1, { name: "regular-chevron-left-s", size: "0.5rem", "aria-hidden": "true" }) ], 8, _hoisted_6), createElementVNode("input", { class: "mt-pagination__current-page-input", type: "number", min: "1", step: "1", style: normalizeStyle({ width: inputLength.value }), value: _ctx.currentPage, onInput: onChangeInput, "aria-label": `Page ${_ctx.currentPage}`, "data-testid": "mt-pagination-current-page-input" }, null, 44, _hoisted_8), createElementVNode("button", { type: "button", class: "mt-pagination__button", disabled: isOnLastPage.value, onClick: _cache[2] || (_cache[2] = ($event) => _ctx.$emit("change-current-page", _ctx.currentPage + 1)), "data-testid": "mt-pagination-next-page-button" }, [ createElementVNode("span", _hoisted_10, toDisplayString(unref(t)("nextPage")), 1), createVNode(_sfc_main$1, { name: "regular-chevron-right-s", size: "0.5rem", "aria-hidden": "true" }) ], 8, _hoisted_9), createElementVNode("button", { type: "button", class: "mt-pagination__button", disabled: isOnLastPage.value, onClick: _cache[3] || (_cache[3] = ($event) => _ctx.$emit("change-current-page", totalPages.value)), "data-testid": "mt-pagination-last-page-button" }, [ createElementVNode("span", _hoisted_12, toDisplayString(unref(t)("lastPage")), 1), createVNode(_sfc_main$1, { name: "regular-double-chevron-right-s", size: "0.5rem", "aria-hidden": "true" }) ], 8, _hoisted_11) ]) ]); }; } }); const mtPagination_vue_vue_type_style_index_0_scoped_96226e69_lang = ""; const MtPagination = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-96226e69"]]); export { MtPagination as default }; //# sourceMappingURL=MtPagination.js.map