@redvars/peacock 3.15.0 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@redvars/peacock",
3
3
  "description": "The foundation for beautiful user interfaces",
4
4
  "license": "Apache-2.0",
5
- "version": "3.15.0",
5
+ "version": "3.16.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.js",
package/readme.md CHANGED
@@ -44,9 +44,9 @@ Visit [https://peacock.redvars.com](https://peacock.redvars.com) to view the doc
44
44
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
45
45
  <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
46
46
 
47
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@redvars/peacock@3.15.0/dist/assets/styles.css"></link>
47
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@redvars/peacock@3.16.0/dist/assets/styles.css"></link>
48
48
  <script type='module'
49
- src='https://cdn.jsdelivr.net/npm/@redvars/peacock@3.15.0/dist/loader.js'></script>
49
+ src='https://cdn.jsdelivr.net/npm/@redvars/peacock@3.16.0/dist/loader.js'></script>
50
50
  </head>
51
51
 
52
52
  <wc-button>Button</wc-button>
@@ -0,0 +1,50 @@
1
+ /** A slot in the page list: a page number, or a gap shown as an ellipsis. */
2
+ export type PageItem = number | 'ellipsis';
3
+
4
+ function range(from: number, to: number): number[] {
5
+ return Array.from({ length: to - from + 1 }, (_, index) => from + index);
6
+ }
7
+
8
+ /**
9
+ * Builds the page list shown by the `full` pagination variant.
10
+ *
11
+ * The list always keeps the first and last page, the current page and `siblings` pages on each
12
+ * side of it, and fills the rest with an ellipsis. It never holds more than
13
+ * `2 * siblings + 5` slots, so the control keeps its width while the user moves through pages.
14
+ *
15
+ * @example
16
+ * getPageItems(5, 24); // [1, 'ellipsis', 4, 5, 6, 'ellipsis', 24]
17
+ * getPageItems(2, 24); // [1, 2, 3, 4, 5, 'ellipsis', 24]
18
+ */
19
+ export function getPageItems(
20
+ current: number,
21
+ total: number,
22
+ siblings: number = 1,
23
+ ): PageItem[] {
24
+ const totalPages = Math.max(1, Math.trunc(total));
25
+ const page = Math.min(Math.max(1, Math.trunc(current)), totalPages);
26
+ const maxSlots = 2 * siblings + 5;
27
+
28
+ if (totalPages <= maxSlots) {
29
+ return range(1, totalPages);
30
+ }
31
+
32
+ const start = Math.max(page - siblings, 1);
33
+ const end = Math.min(page + siblings, totalPages);
34
+ // A gap of one page is shown as that page; only a gap of two or more becomes an ellipsis.
35
+ const showStartGap = start > 3;
36
+ const showEndGap = end < totalPages - 2;
37
+ // Pages shown on the side without a gap: the window, the edge page and the slot the
38
+ // ellipsis would have taken.
39
+ const edgeCount = 2 * siblings + 3;
40
+
41
+ if (!showStartGap && showEndGap) {
42
+ return [...range(1, edgeCount), 'ellipsis', totalPages];
43
+ }
44
+
45
+ if (showStartGap && !showEndGap) {
46
+ return [1, 'ellipsis', ...range(totalPages - edgeCount + 1, totalPages)];
47
+ }
48
+
49
+ return [1, 'ellipsis', ...range(start, end), 'ellipsis', totalPages];
50
+ }
@@ -5,69 +5,184 @@
5
5
  :host {
6
6
  display: block;
7
7
  container-type: inline-size;
8
+ --pagination-background: var(--color-surface, #fff);
9
+ --_pagination-target-size: 2.5rem;
8
10
  }
9
11
 
10
12
  .pagination {
11
13
  display: flex;
12
- align-items: center;
13
- justify-content: space-between;
14
14
  flex-wrap: wrap;
15
- gap: var(--spacing-200, 1rem);
16
- row-gap: var(--spacing-100, 0.5rem);
17
- background: var(--color-surface, #fff);
18
- padding: var(--spacing-150, 0.75rem) var(--spacing-200, 1rem);
19
-
20
- @container (min-width: 48rem) {
21
- flex-wrap: nowrap;
22
- justify-content: flex-end;
23
- row-gap: 0;
15
+ align-items: center;
16
+ gap: var(--spacing-100, 0.5rem) var(--spacing-300, 1.5rem);
17
+ padding: var(--spacing-100, 0.5rem) var(--spacing-200, 1rem);
18
+ background: var(--pagination-background);
19
+ color: var(--color-on-surface-variant);
20
+
21
+ @include mixin.get-typography-not-important('body-medium');
22
+ }
23
+
24
+ // Status on the start side, actions on the end side.
25
+ .range {
26
+ flex: 1 1 auto;
27
+ white-space: nowrap;
28
+ font-variant-numeric: tabular-nums;
29
+ }
30
+
31
+ .page-size {
32
+ display: inline-flex;
33
+ align-items: center;
34
+ gap: var(--spacing-100, 0.5rem);
35
+ }
36
+
37
+ .page-size-label {
38
+ white-space: nowrap;
39
+ }
40
+
41
+ .page-size-select {
42
+ inline-size: 5.5rem;
43
+ --field-height: var(--_pagination-target-size);
44
+ --field-padding-block: 0;
45
+ }
46
+
47
+ .controls {
48
+ display: inline-flex;
49
+ align-items: center;
50
+ gap: var(--spacing-050, 0.25rem);
51
+ }
52
+
53
+ .nav-button {
54
+ --button-container-shape: var(--shape-corner-full);
55
+ }
56
+
57
+ .page-list {
58
+ display: flex;
59
+ align-items: center;
60
+ gap: var(--spacing-025, 0.125rem);
61
+ margin: 0;
62
+ padding: 0;
63
+ list-style: none;
64
+ }
65
+
66
+ .page-button {
67
+ @include mixin.reset-button-styles;
68
+ @include mixin.get-typography-not-important('label-large');
69
+
70
+ display: inline-flex;
71
+ align-items: center;
72
+ justify-content: center;
73
+ min-inline-size: var(--_pagination-target-size);
74
+ block-size: var(--_pagination-target-size);
75
+ padding: 0 var(--spacing-100, 0.5rem);
76
+ border-radius: var(--shape-corner-full);
77
+ color: var(--color-on-surface-variant);
78
+ font-variant-numeric: tabular-nums;
79
+ cursor: pointer;
80
+ transition: background-color var(--duration-short2, 100ms) ease;
81
+
82
+ &:hover {
83
+ background: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
24
84
  }
25
85
 
26
- .page-size {
27
- display: inline-flex;
28
- align-items: center;
29
- gap: var(--spacing-100, 0.5rem);
30
- min-inline-size: max-content;
86
+ &:active {
87
+ background: color-mix(in srgb, var(--color-on-surface) 12%, transparent);
31
88
  }
32
89
 
33
- .page-size-label {
34
- @include mixin.get-typography-not-important('body-small');
35
- color: var(--color-on-surface-variant);
36
- white-space: nowrap;
90
+ &:focus-visible {
91
+ outline: 2px solid var(--color-primary);
92
+ outline-offset: 2px;
37
93
  }
38
94
 
39
- .page-size-select {
40
- inline-size: 5.5rem;
41
- min-inline-size: 5.5rem;
42
- --field-container-height: 2.5rem;
95
+ &.current {
96
+ background: var(--color-secondary-container);
97
+ color: var(--color-on-secondary-container);
98
+ cursor: default;
43
99
  }
100
+ }
101
+
102
+ .page-ellipsis {
103
+ display: inline-flex;
104
+ align-items: center;
105
+ justify-content: center;
106
+ min-inline-size: var(--_pagination-target-size);
107
+ block-size: var(--_pagination-target-size);
108
+ user-select: none;
109
+ }
44
110
 
45
- .pagination-item-count {
46
- order: 3;
47
- margin-inline-start: 0;
48
- inline-size: 100%;
49
- display: flex;
50
- align-items: center;
51
-
52
- @container (min-width: 48rem) {
53
- order: 0;
54
- margin-inline-start: auto;
55
- inline-size: auto;
56
- }
111
+ .page-jump {
112
+ display: inline-flex;
113
+ align-items: center;
114
+ gap: var(--spacing-100, 0.5rem);
115
+ padding-inline: var(--spacing-050, 0.25rem);
116
+ white-space: nowrap;
117
+ font-variant-numeric: tabular-nums;
118
+ }
119
+
120
+ .page-input {
121
+ @include mixin.get-typography-not-important('body-medium');
122
+
123
+ inline-size: 3.5rem;
124
+ block-size: 2rem;
125
+ padding: 0 var(--spacing-100, 0.5rem);
126
+ border: 1px solid var(--color-outline-variant);
127
+ border-radius: var(--shape-corner-small);
128
+ background: var(--color-surface);
129
+ color: var(--color-on-surface);
130
+ text-align: center;
131
+ font-variant-numeric: tabular-nums;
132
+ appearance: textfield;
133
+
134
+ &::-webkit-inner-spin-button,
135
+ &::-webkit-outer-spin-button {
136
+ appearance: none;
137
+ margin: 0;
57
138
  }
58
139
 
59
- .pagination-text {
60
- @include mixin.get-typography-not-important('body-medium');
61
- color: var(--color-on-surface-variant);
140
+ &:hover {
141
+ border-color: var(--color-outline);
62
142
  }
63
143
 
64
- .pagination-actions {
144
+ &:focus-visible {
145
+ outline: 2px solid var(--color-primary);
146
+ outline-offset: -1px;
147
+ border-color: transparent;
148
+ }
149
+ }
150
+
151
+ // In the full variant the jump field is the narrow-screen fallback for the page list.
152
+ .variant-full .page-jump {
153
+ display: none;
154
+ }
155
+
156
+ @container (max-width: 40rem) {
157
+ .variant-full .page-list {
158
+ display: none;
159
+ }
160
+
161
+ .variant-full .page-jump {
65
162
  display: inline-flex;
66
- align-items: center;
67
- gap: var(--spacing-025, 0.125rem);
68
163
  }
69
164
 
70
- .nav-button {
71
- --button-container-shape: var(--shape-corner-full);
165
+ .page-size-label {
166
+ display: none;
167
+ }
168
+ }
169
+
170
+ // Phone width: range and rows per page share the first line, page controls take the second.
171
+ @container (max-width: 26rem) {
172
+ .controls {
173
+ flex-basis: 100%;
174
+ justify-content: space-between;
72
175
  }
73
176
  }
177
+
178
+ .visually-hidden {
179
+ position: absolute;
180
+ inline-size: 1px;
181
+ block-size: 1px;
182
+ margin: -1px;
183
+ padding: 0;
184
+ overflow: hidden;
185
+ clip-path: inset(50%);
186
+ white-space: nowrap;
187
+ border: 0;
188
+ }