@fluid-topics/ft-snap-scroll 0.1.17 → 0.2.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.
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { css, html } from "lit";
8
8
  import { property, query, state } from "lit/decorators.js";
9
- import { customElement, Debouncer, designSystemVariables, FtCssVariable, FtLitElement, isSafari, setVariable } from "@fluid-topics/ft-wc-utils";
9
+ import { Debouncer, designSystemVariables, FtCssVariable, FtLitElement, isSafari, setVariable } from "@fluid-topics/ft-wc-utils";
10
10
  import { FtButton, FtButtonCssVariables } from "@fluid-topics/ft-button";
11
11
  import { classMap } from "lit/directives/class-map.js";
12
12
  export const FtSnapScrollCssVariables = {
@@ -20,7 +20,7 @@ export class CurrentElementChange extends CustomEvent {
20
20
  super("current-element-change", { detail: { index, element } });
21
21
  }
22
22
  }
23
- let FtSnapScroll = class FtSnapScroll extends FtLitElement {
23
+ export class FtSnapScroll extends FtLitElement {
24
24
  constructor() {
25
25
  super(...arguments);
26
26
  this.horizontal = false;
@@ -41,135 +41,6 @@ let FtSnapScroll = class FtSnapScroll extends FtLitElement {
41
41
  this.scrollDebouncer = new Debouncer(200);
42
42
  this.updateScrollDebouncer = new Debouncer(100);
43
43
  }
44
- // language=CSS
45
- getStyles() {
46
- return css `
47
- .ft-snap-scroll {
48
- box-sizing: border-box;
49
- position: relative;
50
- display: flex;
51
-
52
- --ft-snap-scroll-transparent-color: transparent;
53
- }
54
-
55
- .ft-snap-scroll.ft-snap-scroll--safari-fix {
56
- /* Safari handles "transparent" as rgba(0,0,0,0) so it's ugly in linear-gradiant with default --ft-color-surface */
57
- /* this value should be overridden with --ft-color-surface with alpha set to 0 when needed */
58
- --ft-snap-scroll-transparent-color: rgba(255, 255, 255, 0);
59
- }
60
-
61
- .ft-snap-scroll,
62
- .ft-snap-scroll--content {
63
- overflow: hidden;
64
- }
65
-
66
- .ft-snap-scroll--limit-size,
67
- .ft-snap-scroll--limit-size .ft-snap-scroll--content {
68
- width: 100%;
69
- height: 100%;
70
- }
71
-
72
- .ft-snap-scroll--content {
73
- flex-grow: 1;
74
- flex-shrink: 1;
75
- box-sizing: border-box;
76
- scroll-snap-align: start;
77
- display: flex;
78
- flex-wrap: nowrap;
79
- align-items: flex-start;
80
- justify-content: flex-start;
81
- gap: ${FtSnapScrollCssVariables.gap};
82
- }
83
-
84
- .ft-snap-scroll--hide-scrollbar .ft-snap-scroll--content::-webkit-scrollbar {
85
- display: none;
86
- }
87
-
88
- .ft-snap-scroll--hide-scrollbar .ft-snap-scroll--content {
89
- -ms-overflow-style: none;
90
- scrollbar-width: none;
91
- }
92
-
93
- .ft-snap-scroll--content::slotted(*) {
94
- flex-shrink: 0;
95
- flex-grow: 1;
96
- max-height: 100%;
97
- max-width: 100%;
98
- }
99
-
100
- .ft-snap-scroll--horizontal,
101
- .ft-snap-scroll--horizontal .ft-snap-scroll--content {
102
- width: 100%;
103
- }
104
-
105
- .ft-snap-scroll--vertical,
106
- .ft-snap-scroll--vertical .ft-snap-scroll--content {
107
- height: 100%;
108
- }
109
-
110
- .ft-snap-scroll--horizontal .ft-snap-scroll--content {
111
- flex-direction: row;
112
- overflow-x: auto;
113
- }
114
-
115
- .ft-snap-scroll--vertical .ft-snap-scroll--content {
116
- flex-direction: column;
117
- overflow-y: auto;
118
- }
119
-
120
- .ft-snap-scroll--previous,
121
- .ft-snap-scroll--next {
122
- position: absolute;
123
- display: flex;
124
- z-index: ${FtSnapScrollCssVariables.buttonsZIndex};
125
- opacity: 1;
126
- transition: background-color .5s ease-in-out, opacity .5s ease-in-out, z-index .5s ease-in-out;
127
- ${setVariable(FtButtonCssVariables.backgroundColor, "transparent")};
128
- ${setVariable(FtButtonCssVariables.color, FtSnapScrollCssVariables.buttonsColor)};
129
- }
130
-
131
- .ft-snap-scroll--previous[hidden],
132
- .ft-snap-scroll--next[hidden] {
133
- z-index: -1;
134
- opacity: 0;
135
- }
136
-
137
- .ft-snap-scroll--horizontal .ft-snap-scroll--previous {
138
- top: 0;
139
- left: -1px;
140
- bottom: 0;
141
- background: linear-gradient(to right, ${FtSnapScrollCssVariables.colorSurface} 50%, var(--ft-snap-scroll-transparent-color));
142
- }
143
-
144
- .ft-snap-scroll--vertical .ft-snap-scroll--previous {
145
- top: -1px;
146
- left: 0;
147
- right: 0;
148
- background: linear-gradient(to bottom, ${FtSnapScrollCssVariables.colorSurface} 50%, var(--ft-snap-scroll-transparent-color));
149
- }
150
-
151
- .ft-snap-scroll--horizontal .ft-snap-scroll--next {
152
- top: 0;
153
- right: -1px;
154
- bottom: 0;
155
- background: linear-gradient(to left, ${FtSnapScrollCssVariables.colorSurface} 50%, var(--ft-snap-scroll-transparent-color));
156
- }
157
-
158
- .ft-snap-scroll--vertical .ft-snap-scroll--next {
159
- left: 0;
160
- right: 0;
161
- bottom: -1px;
162
- background: linear-gradient(to top, ${FtSnapScrollCssVariables.colorSurface} 50%, var(--ft-snap-scroll-transparent-color));
163
- }
164
-
165
- .ft-snap-scroll--horizontal .ft-snap-scroll--previous:hover,
166
- .ft-snap-scroll--horizontal .ft-snap-scroll--next:hover,
167
- .ft-snap-scroll--vertical .ft-snap-scroll--previous:hover,
168
- .ft-snap-scroll--vertical .ft-snap-scroll--next:hover {
169
- background-color: ${FtSnapScrollCssVariables.colorSurface};
170
- }
171
- `;
172
- }
173
44
  scrollToIndex(index) {
174
45
  this.scrollToElement(this.elements[index]);
175
46
  }
@@ -190,7 +61,7 @@ let FtSnapScroll = class FtSnapScroll extends FtLitElement {
190
61
  next() {
191
62
  this.scrollToElement(this.elements[Math.min(this.closestIndexFromStart() + 1, this.elements.length - 1)]);
192
63
  }
193
- getTemplate() {
64
+ render() {
194
65
  const classes = classMap({
195
66
  "ft-snap-scroll": true,
196
67
  "ft-snap-scroll--horizontal": this.horizontal,
@@ -339,10 +210,137 @@ let FtSnapScroll = class FtSnapScroll extends FtLitElement {
339
210
  const offset = element === this.elements[0] ? 0 : this.controlsSize;
340
211
  return Math.abs(this.getOffset(element) - this.contentSlot[this.scrollAttribute] - offset);
341
212
  }
342
- };
213
+ }
343
214
  FtSnapScroll.elementDefinitions = {
344
215
  "ft-button": FtButton,
345
216
  };
217
+ // language=CSS
218
+ FtSnapScroll.styles = css `
219
+ .ft-snap-scroll {
220
+ box-sizing: border-box;
221
+ position: relative;
222
+ display: flex;
223
+
224
+ --ft-snap-scroll-transparent-color: transparent;
225
+ }
226
+
227
+ .ft-snap-scroll.ft-snap-scroll--safari-fix {
228
+ /* Safari handles "transparent" as rgba(0,0,0,0) so it's ugly in linear-gradiant with default --ft-color-surface */
229
+ /* this value should be overridden with --ft-color-surface with alpha set to 0 when needed */
230
+ --ft-snap-scroll-transparent-color: rgba(255, 255, 255, 0);
231
+ }
232
+
233
+ .ft-snap-scroll,
234
+ .ft-snap-scroll--content {
235
+ overflow: hidden;
236
+ }
237
+
238
+ .ft-snap-scroll--limit-size,
239
+ .ft-snap-scroll--limit-size .ft-snap-scroll--content {
240
+ width: 100%;
241
+ height: 100%;
242
+ }
243
+
244
+ .ft-snap-scroll--content {
245
+ flex-grow: 1;
246
+ flex-shrink: 1;
247
+ box-sizing: border-box;
248
+ scroll-snap-align: start;
249
+ display: flex;
250
+ flex-wrap: nowrap;
251
+ align-items: flex-start;
252
+ justify-content: flex-start;
253
+ gap: ${FtSnapScrollCssVariables.gap};
254
+ }
255
+
256
+ .ft-snap-scroll--hide-scrollbar .ft-snap-scroll--content::-webkit-scrollbar {
257
+ display: none;
258
+ }
259
+
260
+ .ft-snap-scroll--hide-scrollbar .ft-snap-scroll--content {
261
+ -ms-overflow-style: none;
262
+ scrollbar-width: none;
263
+ }
264
+
265
+ .ft-snap-scroll--content::slotted(*) {
266
+ flex-shrink: 0;
267
+ flex-grow: 1;
268
+ max-height: 100%;
269
+ max-width: 100%;
270
+ }
271
+
272
+ .ft-snap-scroll--horizontal,
273
+ .ft-snap-scroll--horizontal .ft-snap-scroll--content {
274
+ width: 100%;
275
+ }
276
+
277
+ .ft-snap-scroll--vertical,
278
+ .ft-snap-scroll--vertical .ft-snap-scroll--content {
279
+ height: 100%;
280
+ }
281
+
282
+ .ft-snap-scroll--horizontal .ft-snap-scroll--content {
283
+ flex-direction: row;
284
+ overflow-x: auto;
285
+ }
286
+
287
+ .ft-snap-scroll--vertical .ft-snap-scroll--content {
288
+ flex-direction: column;
289
+ overflow-y: auto;
290
+ }
291
+
292
+ .ft-snap-scroll--previous,
293
+ .ft-snap-scroll--next {
294
+ position: absolute;
295
+ display: flex;
296
+ z-index: ${FtSnapScrollCssVariables.buttonsZIndex};
297
+ opacity: 1;
298
+ transition: background-color .5s ease-in-out, opacity .5s ease-in-out, z-index .5s ease-in-out;
299
+ ${setVariable(FtButtonCssVariables.backgroundColor, "transparent")};
300
+ ${setVariable(FtButtonCssVariables.color, FtSnapScrollCssVariables.buttonsColor)};
301
+ }
302
+
303
+ .ft-snap-scroll--previous[hidden],
304
+ .ft-snap-scroll--next[hidden] {
305
+ z-index: -1;
306
+ opacity: 0;
307
+ }
308
+
309
+ .ft-snap-scroll--horizontal .ft-snap-scroll--previous {
310
+ top: 0;
311
+ left: -1px;
312
+ bottom: 0;
313
+ background: linear-gradient(to right, ${FtSnapScrollCssVariables.colorSurface} 50%, var(--ft-snap-scroll-transparent-color));
314
+ }
315
+
316
+ .ft-snap-scroll--vertical .ft-snap-scroll--previous {
317
+ top: -1px;
318
+ left: 0;
319
+ right: 0;
320
+ background: linear-gradient(to bottom, ${FtSnapScrollCssVariables.colorSurface} 50%, var(--ft-snap-scroll-transparent-color));
321
+ }
322
+
323
+ .ft-snap-scroll--horizontal .ft-snap-scroll--next {
324
+ top: 0;
325
+ right: -1px;
326
+ bottom: 0;
327
+ background: linear-gradient(to left, ${FtSnapScrollCssVariables.colorSurface} 50%, var(--ft-snap-scroll-transparent-color));
328
+ }
329
+
330
+ .ft-snap-scroll--vertical .ft-snap-scroll--next {
331
+ left: 0;
332
+ right: 0;
333
+ bottom: -1px;
334
+ background: linear-gradient(to top, ${FtSnapScrollCssVariables.colorSurface} 50%, var(--ft-snap-scroll-transparent-color));
335
+ }
336
+
337
+ .ft-snap-scroll--horizontal .ft-snap-scroll--previous:hover,
338
+ .ft-snap-scroll--horizontal .ft-snap-scroll--next:hover,
339
+ .ft-snap-scroll--vertical .ft-snap-scroll--previous:hover,
340
+ .ft-snap-scroll--vertical .ft-snap-scroll--next:hover {
341
+ background-color: ${FtSnapScrollCssVariables.colorSurface};
342
+ }
343
+ `;
346
344
  __decorate([
347
345
  property({ type: Boolean })
348
346
  ], FtSnapScroll.prototype, "horizontal", void 0);
@@ -373,8 +371,4 @@ __decorate([
373
371
  __decorate([
374
372
  query(".ft-snap-scroll--content")
375
373
  ], FtSnapScroll.prototype, "contentSlot", void 0);
376
- FtSnapScroll = __decorate([
377
- customElement("ft-snap-scroll")
378
- ], FtSnapScroll);
379
- export { FtSnapScroll };
380
374
  //# sourceMappingURL=ft-snap-scroll.js.map