scb-wc-test 0.1.71 → 0.1.73

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.
@@ -0,0 +1,18 @@
1
+ import { LitElement } from 'lit';
2
+ export declare class ScbPagination extends LitElement {
3
+ variant: 'icon-text' | 'icon';
4
+ page: number;
5
+ totalPages: number;
6
+ pagingHref: string;
7
+ paginationAriaLabel: string;
8
+ currentAriaLabel: string;
9
+ pagingNumberAriaLabel: string;
10
+ isNarrow: boolean;
11
+ static styles: import('lit').CSSResult[];
12
+ private _prevPage;
13
+ private _nextPage;
14
+ connectedCallback(): void;
15
+ disconnectedCallback(): void;
16
+ private _onResize;
17
+ render(): import('lit-html').TemplateResult<1> | null;
18
+ }
@@ -0,0 +1,264 @@
1
+ import { css as g, LitElement as h, html as a } from "lit";
2
+ import { property as p, customElement as b } from "lit/decorators.js";
3
+ import "../scb-link/scb-link.js";
4
+ import "../scb-button/scb-button.js";
5
+ import "../scb-icon-button/scb-icon-button.js";
6
+ import "@material/web/icon/icon.js";
7
+ import "@material/web/focus/md-focus-ring.js";
8
+ var u = Object.defineProperty, v = Object.getOwnPropertyDescriptor, l = (d, e, s, i) => {
9
+ for (var r = i > 1 ? void 0 : i ? v(e, s) : e, c = d.length - 1, n; c >= 0; c--)
10
+ (n = d[c]) && (r = (i ? n(e, s, r) : n(r)) || r);
11
+ return i && r && u(e, s, r), r;
12
+ };
13
+ let o = class extends h {
14
+ constructor() {
15
+ super(...arguments), this.variant = "icon-text", this.page = 1, this.totalPages = 0, this.pagingHref = "/products?page=", this.paginationAriaLabel = "Paginering", this.currentAriaLabel = "Nuvarande sida, ", this.pagingNumberAriaLabel = "Gå till sida ", this.isNarrow = window.innerWidth <= 768, this._onResize = () => {
16
+ this.isNarrow = window.innerWidth <= 768;
17
+ };
18
+ }
19
+ _prevPage() {
20
+ this.page > 1 && this.page--, this.dispatchEvent(new CustomEvent("page-change", { detail: { page: this.page } }));
21
+ }
22
+ _nextPage() {
23
+ this.page < this.totalPages && this.page++, this.dispatchEvent(new CustomEvent("page-change", { detail: { page: this.page } }));
24
+ }
25
+ connectedCallback() {
26
+ super.connectedCallback(), window.addEventListener("resize", this._onResize), this._onResize();
27
+ }
28
+ disconnectedCallback() {
29
+ super.disconnectedCallback(), window.removeEventListener("resize", this._onResize);
30
+ }
31
+ render() {
32
+ if (this.totalPages === 0) return null;
33
+ const d = this.variant ? `${this.variant.toLowerCase()}` : "", e = [], { page: s, totalPages: i } = this, r = window.innerWidth <= 768, c = r ? 1 : 2, n = (t) => t === s ? a`
34
+ <li>
35
+ <span
36
+ class="page-number active"
37
+ aria-current="page"
38
+ aria-label="${this.currentAriaLabel} ${t}"
39
+ >${t}</span>
40
+ </li>
41
+ ` : a`
42
+ <li>
43
+ <scb-link
44
+ class="page-number${t === s ? " active" : ""}"
45
+ @click=${() => {
46
+ this.page = t, this.dispatchEvent(new CustomEvent("page-change", { detail: { page: t } }));
47
+ }}
48
+ aria-current=${t === s ? "page" : void 0}
49
+ aria-label="${this.pagingNumberAriaLabel} ${t}"
50
+ href=${this.pagingHref}${t}
51
+ ?disabled=${t === s}>${t}
52
+ </scb-link>
53
+ </li>
54
+ `;
55
+ if (i <= 8)
56
+ for (let t = 1; t <= i; t++)
57
+ e.push(n(t));
58
+ else if (e.push(n(1)), s <= 4 && !r) {
59
+ for (let t = 2; t <= 5; t++) e.push(n(t));
60
+ i > 6 ? (e.push(a`<li><span class="ellipsis" aria-hidden="true">…</span></li>`), e.push(n(i))) : i === 6 && e.push(n(i));
61
+ } else if (s <= 3 && r) {
62
+ for (let t = 2; t <= 3; t++) e.push(n(t));
63
+ i > 4 ? (e.push(a`<li><span class="ellipsis" aria-hidden="true">…</span></li>`), e.push(n(i))) : i === 4 && e.push(n(i));
64
+ } else if (s >= i - (c + 1)) {
65
+ e.push(a`<li><span class="ellipsis" aria-hidden="true">…</span></li>`);
66
+ for (let t = i - c * 2; t <= i; t++)
67
+ t > 1 && e.push(n(t));
68
+ } else {
69
+ e.push(a`<li><span class="ellipsis" aria-hidden="true">…</span></li>`);
70
+ for (let t = s - c; t <= s + c; t++)
71
+ t > 1 && t < i && e.push(n(t));
72
+ e.push(a`<li><span class="ellipsis" aria-hidden="true">…</span></li>`), e.push(n(i));
73
+ }
74
+ return r ? a`
75
+ <nav aria-label="${this.paginationAriaLabel}" class="pagination ${d}">
76
+ <div class="pagination-row">
77
+ <div class="prev">
78
+ ${this.variant === "icon" ? a`<scb-icon-button icon="chevron_left" @click=${this._prevPage} ?disabled=${this.page === 1} aria-label="Föregående sida"></scb-icon-button>` : a`<scb-button variant="text" label="Föregående" icon="chevron_left" @click=${this._prevPage} ?disabled=${this.page === 1} aria-label="Föregående sida"></scb-button>`}
79
+ </div>
80
+ <ol>
81
+ ${e}
82
+ </ol>
83
+ </div>
84
+ <div class="next">
85
+ ${this.variant === "icon" ? a`<scb-icon-button icon="chevron_right" @click=${this._nextPage} ?disabled=${this.page === this.totalPages} aria-label="Nästa sida"></scb-icon-button>` : a`<scb-button variant="text" label="Nästa" icon="chevron_right" iconPosition="right" @click=${this._nextPage} ?disabled=${this.page === this.totalPages} aria-label="Nästa sida" trailing-icon></scb-button>`}
86
+ </div>
87
+ </nav>
88
+ ` : a`
89
+ <nav aria-label="${this.paginationAriaLabel}" class="pagination ${d}">
90
+ <div class="pagination-row">
91
+ <div class="prev">
92
+ ${this.variant === "icon" ? a`<scb-icon-button icon="chevron_left" @click=${this._prevPage} ?disabled=${this.page === 1} aria-label="Föregående sida"></scb-icon-button>` : a`<scb-button variant="text" label="Föregående" icon="chevron_left" @click=${this._prevPage} ?disabled=${this.page === 1} aria-label="Föregående sida"></scb-button>`}
93
+ </div>
94
+ <ol>
95
+ ${e}
96
+ </ol>
97
+ <div class="next">
98
+ ${this.variant === "icon" ? a`<scb-icon-button icon="chevron_right" @click=${this._nextPage} ?disabled=${this.page === this.totalPages} aria-label="Nästa sida"></scb-icon-button>` : a`<scb-button variant="text" label="Nästa" icon="chevron_right" iconPosition="right" @click=${this._nextPage} ?disabled=${this.page === this.totalPages} aria-label="Nästa sida" trailing-icon></scb-button>`}
99
+ </div>
100
+ </div>
101
+ </nav>
102
+ `;
103
+ }
104
+ };
105
+ o.styles = [
106
+ g`
107
+ :host .pagination {
108
+ --md-text-button-label-text-color: var(--md-sys-color-on-surface, #0F0865);
109
+ --md-text-button-pressed-state-layer-color: var(--md-sys-color-on-surface, #0F0865);
110
+ --md-text-button-focus-label-text-color: var(--md-sys-color-on-surface, #0F0865);
111
+ --md-text-button-hover-label-text-color: var(--md-sys-color-on-surface, #0F0865);
112
+ --md-text-button-pressed-label-text-color: var(--md-sys-color-on-surface, #0F0865);
113
+ --md-text-button-label-text-weight: var(--weight-regular, 400);
114
+ --md-text-button-label-text-line-height: var(--md-sys-typescale-body-medium-line-height, 24px);
115
+ --md-text-button-label-text-size: var(--md-sys-typescale-body-medium-size, 16px);
116
+ --md-text-button-icon-color : var(--md-sys-color-on-surface, #0F0865);
117
+ --md-text-button-focus-icon-color : var(--md-sys-color-on-surface, #0F0865);
118
+ --md-text-button-hover-icon-color : var(--md-sys-color-on-surface, #0F0865);
119
+ --md-text-button-pressed-icon-color : var(--md-sys-color-on-surface, #0F0865);
120
+ --scb-link-decoration: none;
121
+ --scb-link-color: var(--md-sys-color-on-surface, #0F0865);
122
+
123
+ scb-link.page-number a {
124
+ cursor: pointer;
125
+ text-decoration: none;
126
+ display: inline-flex;
127
+ }
128
+ }
129
+
130
+ .pagination {
131
+ width: 100%;
132
+ display: flex;
133
+ flex-direction: column;
134
+ gap: 0;
135
+ }
136
+ .pagination-row {
137
+ width: 100%;
138
+ display: flex;
139
+ flex-direction: row;
140
+ align-items: center;
141
+ gap: 4px;
142
+ }
143
+ .pagination-row .prev {
144
+ display: flex;
145
+ justify-content: flex-start;
146
+ width: auto;
147
+ }
148
+ .pagination-row ol {
149
+ width: auto;
150
+ display: flex;
151
+ flex-direction: row;
152
+ justify-content: flex-start;
153
+ gap: 4px;
154
+ margin: 0;
155
+ padding: 0;
156
+ list-style: none;
157
+ }
158
+ .pagination-row ol li {
159
+ min-width: 40px;
160
+ min-height: 40px;
161
+ display: flex;
162
+ align-items: center;
163
+ justify-content: center;
164
+ }
165
+ .pagination-row .next {
166
+ display: flex;
167
+ justify-content: flex-start;
168
+ align-items: center;
169
+ width: auto;
170
+ margin-top: 0;
171
+ }
172
+ scb-link.page-number a {
173
+ cursor: pointer;
174
+ text-decoration: none;
175
+ display: inline-flex;
176
+ }
177
+ .page-number.active {
178
+ display: inline-flex;
179
+ align-items: center;
180
+ justify-content: center;
181
+ border-radius: 50%;
182
+ background: var(--md-sys-color-primary, #1F44FF);
183
+ color: var(--md-sys-color-on-primary, #FFF);
184
+ text-align: center;
185
+ width: 40px;
186
+ height: 40px;
187
+ }
188
+ .page-number.active {
189
+ font-family: var(--brand-font, 'Inter', sans-serif);
190
+ }
191
+ .ellipsis {
192
+ margin: 0 4px;
193
+ color: #888;
194
+ user-select: none;
195
+ pointer-events: none;
196
+ }
197
+ scb-button[disabled] {
198
+ opacity: 0.5;
199
+ pointer-events: none;
200
+ }
201
+
202
+ @media (max-width: 768px) {
203
+
204
+ .pagination .prev {
205
+ display: flex;
206
+ justify-content: flex-start;
207
+ }
208
+ .pagination .next {
209
+ width: 100%;
210
+ margin-top: 8px;
211
+ }
212
+ }
213
+
214
+ @media (max-width: 390px) {
215
+ .pagination-row {
216
+ flex-direction: column;
217
+ gap: 0;
218
+ }
219
+ .pagination-row .prev {
220
+ width: 100%;
221
+ margin-bottom: 8px;
222
+ align-items: center;
223
+ }
224
+ .pagination-row ol {
225
+ width: 100%;
226
+ align-items: center;
227
+ }
228
+ .pagination-row .next {
229
+ width: 100%;
230
+ margin-top: 8px;
231
+ }
232
+ }
233
+ `
234
+ ];
235
+ l([
236
+ p({ type: String })
237
+ ], o.prototype, "variant", 2);
238
+ l([
239
+ p({ type: Number })
240
+ ], o.prototype, "page", 2);
241
+ l([
242
+ p({ type: Number, attribute: "total-pages" })
243
+ ], o.prototype, "totalPages", 2);
244
+ l([
245
+ p({ type: String, attribute: "paging-href" })
246
+ ], o.prototype, "pagingHref", 2);
247
+ l([
248
+ p({ type: String, attribute: "pagination-aria-label" })
249
+ ], o.prototype, "paginationAriaLabel", 2);
250
+ l([
251
+ p({ type: String, attribute: "current-aria-label" })
252
+ ], o.prototype, "currentAriaLabel", 2);
253
+ l([
254
+ p({ type: String, attribute: "paging-number-aria-label" })
255
+ ], o.prototype, "pagingNumberAriaLabel", 2);
256
+ l([
257
+ p({ type: Boolean })
258
+ ], o.prototype, "isNarrow", 2);
259
+ o = l([
260
+ b("scb-pagination")
261
+ ], o);
262
+ export {
263
+ o as ScbPagination
264
+ };