@justeattakeaway/pie-skeleton 0.0.1 → 0.2.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/src/skeleton.scss CHANGED
@@ -1,7 +1,271 @@
1
+ @use 'sass:meta';
2
+ @use 'sass:string';
3
+ @use 'sass:list';
4
+ @use '@justeat/pie-design-tokens/dist/jet.scss' as tokens;
1
5
  @use '@justeattakeaway/pie-css/scss' as p;
6
+ @use '@justeattakeaway/pie-css/scss/mixins/components/button' as btn;
7
+
8
+ // Build the list of typography identifiers from the design tokens at build time.
9
+ // Every font-* token ending in -size or -size--narrow (excluding font-size-*), with the suffix removed.
10
+ // New typography tokens are picked up on the next build, so there is no hand-maintained list.
11
+ $font-identifiers: ();
12
+
13
+ @each $name, $value in meta.module-variables('tokens') {
14
+ @if string.index($name, 'font-') == 1 and not string.index($name, 'font-size') {
15
+ @if string.index($name, '-size--narrow') {
16
+ $font-identifiers: list.append($font-identifiers, string.slice($name, 1, string.index($name, '-size--narrow') - 1), comma);
17
+ } @else if string.slice($name, -5) == '-size' {
18
+ $font-identifiers: list.append($font-identifiers, string.slice($name, 1, -6), comma);
19
+ }
20
+ }
21
+ }
22
+
23
+ // The pie-button sizes a pill can match, via height="button-{size}".
24
+ $button-sizes: ('xsmall', 'small-productive', 'small-expressive', 'medium', 'large');
25
+
26
+ // The shimmer shared by every shape (box, circle, pill, text bar and star). A soft diagonal
27
+ // band of the matching shimmer token (at 50% opacity) sweeps from left to right. The band is
28
+ // anchored to the viewport (background-attachment: fixed), so every skeleton on the page
29
+ // shares one continuous wave and shapes light up as the wave passes over them, rather than
30
+ // each shape animating its own band. The band starts off the leading edge, so a shape that is
31
+ // not animating (reduced motion, or a frozen visual test) shows only the flat background colour.
32
+ @mixin skeleton-shimmer {
33
+ background-attachment: fixed;
34
+ background-color: var(--skeleton-bg);
35
+ background-image: linear-gradient(
36
+ 135deg,
37
+ transparent 40%,
38
+ var(--skeleton-shimmer-color) 50%,
39
+ transparent 60%
40
+ );
41
+ background-position: 150% 0;
42
+ background-repeat: no-repeat;
43
+ background-size: 200% 100%;
44
+
45
+ animation: skeletonShimmer var(--skeleton-shimmer-duration) linear infinite;
46
+ animation-direction: var(--skeleton-shimmer-direction);
47
+ }
48
+
49
+ @keyframes skeletonShimmer {
50
+ 0% {
51
+ background-position: 150% 0;
52
+ }
53
+
54
+ // The band finishes its sweep after 1000ms (83.333% of the 1200ms cycle), then rests for the
55
+ // remaining 200ms before the next sweep.
56
+ 83.333% {
57
+ background-position: -50% 0;
58
+ }
59
+
60
+ 100% {
61
+ background-position: -50% 0;
62
+ }
63
+ }
2
64
 
3
65
  :host {
4
- // Note: For consistency sake, the recommended display should be either
5
- // "block" or "inline-block", otherwise it can be ommited for floating elements
6
66
  display: block;
67
+
68
+ // Skeletons are decorative, never interactive.
69
+ pointer-events: none;
70
+ }
71
+
72
+ .c-skeleton {
73
+ --skeleton-bg: var(--dt-color-skeleton-01);
74
+ --skeleton-border-radius: var(--dt-radius-rounded-b);
75
+ --skeleton-text-radius: var(--dt-radius-rounded-a);
76
+ --skeleton-star-size: var(--dt-spacing-e);
77
+ --skeleton-shimmer: var(--dt-color-skeleton-shimmer-01);
78
+ --skeleton-shimmer-color: color-mix(in srgb, var(--skeleton-shimmer) 50%, transparent);
79
+
80
+ // The Figma spec calls for a 1200ms cycle: the band sweeps for 1000ms, then rests for 200ms
81
+ // before looping. pie-design-tokens has no skeleton duration token (the motion-timing tokens
82
+ // top out at 350ms), so this is defined locally and flagged to design to add one.
83
+ --skeleton-shimmer-duration: 1200ms;
84
+
85
+ // Reversed in RTL so the shimmer follows the reading direction (right to left).
86
+ --skeleton-shimmer-direction: normal;
87
+
88
+ position: relative;
89
+ overflow: hidden;
90
+ width: 100%;
91
+ }
92
+
93
+ :host(:dir(rtl)) .c-skeleton {
94
+ --skeleton-shimmer-direction: reverse;
95
+ }
96
+
97
+ // Background colours
98
+ .c-skeleton--backgroundDefault {
99
+ --skeleton-bg: var(--dt-color-skeleton-01);
100
+ --skeleton-shimmer: var(--dt-color-skeleton-shimmer-01);
101
+ }
102
+
103
+ .c-skeleton--backgroundStrong {
104
+ --skeleton-bg: var(--dt-color-skeleton-02);
105
+ --skeleton-shimmer: var(--dt-color-skeleton-shimmer-02);
106
+ }
107
+
108
+ .c-skeleton--backgroundSubtle {
109
+ --skeleton-bg: var(--dt-color-skeleton-03);
110
+ --skeleton-shimmer: var(--dt-color-skeleton-shimmer-03);
111
+ }
112
+
113
+ // Shapes
114
+ .c-skeleton--box,
115
+ .c-skeleton--circle,
116
+ .c-skeleton--pill,
117
+ .c-skeleton-star {
118
+ @include skeleton-shimmer;
119
+ }
120
+
121
+ // Box
122
+ .c-skeleton--box {
123
+ border-radius: var(--skeleton-border-radius);
124
+ }
125
+
126
+ .c-skeleton--radius-rounded-none {
127
+ --skeleton-border-radius: var(--dt-radius-rounded-none);
128
+ }
129
+
130
+ .c-skeleton--radius-rounded-a {
131
+ --skeleton-border-radius: var(--dt-radius-rounded-a);
132
+ }
133
+
134
+ .c-skeleton--radius-rounded-b {
135
+ --skeleton-border-radius: var(--dt-radius-rounded-b);
136
+ }
137
+
138
+ .c-skeleton--radius-rounded-c {
139
+ --skeleton-border-radius: var(--dt-radius-rounded-c);
140
+ }
141
+
142
+ .c-skeleton--radius-rounded-d {
143
+ --skeleton-border-radius: var(--dt-radius-rounded-d);
144
+ }
145
+
146
+ .c-skeleton--radius-rounded-e {
147
+ --skeleton-border-radius: var(--dt-radius-rounded-e);
148
+ }
149
+
150
+ .c-skeleton--radius-rounded-f {
151
+ --skeleton-border-radius: var(--dt-radius-rounded-f);
152
+ }
153
+
154
+ .c-skeleton--radius-rounded-g {
155
+ --skeleton-border-radius: var(--dt-radius-rounded-g);
156
+ }
157
+
158
+ // Box aspect ratios
159
+ .c-skeleton--1by1 {
160
+ aspect-ratio: 1 / 1;
161
+ }
162
+
163
+ .c-skeleton--4by3 {
164
+ aspect-ratio: 4 / 3;
165
+ }
166
+
167
+ .c-skeleton--16by9 {
168
+ aspect-ratio: 16 / 9;
169
+ }
170
+
171
+ .c-skeleton--3by4 {
172
+ aspect-ratio: 3 / 4;
173
+ }
174
+
175
+ .c-skeleton--9by16 {
176
+ aspect-ratio: 9 / 16;
177
+ }
178
+
179
+ // Circle
180
+ .c-skeleton--circle {
181
+ border-radius: 50%;
182
+ aspect-ratio: 1 / 1;
183
+ }
184
+
185
+ // Pill
186
+ .c-skeleton--pill {
187
+ // border-box keeps the reused button padding inside the pill's specified size,
188
+ // so its default width and any explicit height match the real button.
189
+ box-sizing: border-box;
190
+ border-radius: var(--dt-radius-rounded-e);
191
+ }
192
+
193
+ @each $size in $button-sizes {
194
+ .c-skeleton--button-#{$size} {
195
+ @include btn.button-padding-properties;
196
+ @include btn.button-size($size, 'c-skeleton');
197
+
198
+ line-height: var(--btn-line-height);
199
+
200
+ // A zero-width character makes the pill exactly one line box tall, like a button label.
201
+ &:before {
202
+ content: '\200b';
203
+ }
204
+ }
205
+ }
206
+
207
+ // Text
208
+ .c-skeleton-line {
209
+ @include p.font-theme('font-body-l');
210
+
211
+ position: relative;
212
+ border-radius: var(--skeleton-text-radius);
213
+
214
+ // A zero-width character makes the line exactly one line box tall.
215
+ &:before {
216
+ content: '\200b';
217
+ }
218
+
219
+ &:after {
220
+ @include skeleton-shimmer;
221
+ content: '';
222
+ position: absolute;
223
+ inset-inline: 0;
224
+ inset-block-start: calc(50% - 0.5em);
225
+ block-size: 1em;
226
+ border-radius: var(--skeleton-text-radius);
227
+ }
228
+
229
+ // With more than one line, the last line is half width (set through the is-last class).
230
+ &.is-last:after {
231
+ inset-inline-end: 50%;
232
+ }
233
+ }
234
+
235
+ @each $identifier in $font-identifiers {
236
+ .c-skeleton-line--#{$identifier} {
237
+ @include p.font-theme($identifier);
238
+ }
239
+ }
240
+
241
+ // Star
242
+ .c-skeleton--star {
243
+ display: flex;
244
+ gap: 0;
245
+ width: fit-content;
246
+ }
247
+
248
+ .c-skeleton-star {
249
+ flex: 0 0 auto;
250
+ inline-size: var(--skeleton-star-size);
251
+ block-size: var(--skeleton-star-size);
252
+
253
+ // The PIE star icon (star-filled) masks the background into a star shape.
254
+ mask-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2016'%3E%3Cpath%20d='m12.288%2014.449-4.183-2.197a.22.22%200%200%200-.21%200L3.713%2014.45%204.5%209.794a.25.25%200%200%200%200-.193L1.07%206.302l4.673-.682a.23.23%200%200%200%20.166-.114L8%201.271l2.091%204.235a.23.23%200%200%200%20.167.114l4.672.682-3.386%203.3a.25.25%200%200%200-.061.192z'/%3E%3C/svg%3E");
255
+ mask-position: center;
256
+ mask-repeat: no-repeat;
257
+ mask-size: contain;
258
+ }
259
+
260
+ // Motion-sensitive users get a static placeholder: no shimmer, just the background colour.
261
+ @media (prefers-reduced-motion: reduce) {
262
+ .c-skeleton--box,
263
+ .c-skeleton--circle,
264
+ .c-skeleton--pill,
265
+ .c-skeleton-star,
266
+ .c-skeleton-line:after {
267
+ background-image: none;
268
+
269
+ animation: none;
270
+ }
7
271
  }