@functionalcms/svelte-components 4.8.19 → 4.9.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.
@@ -19,6 +19,7 @@
19
19
  /** The maximum size of a file in bytes */
20
20
  maxFileSize?: number;
21
21
  children?: Snippet<[]>;
22
+ css: string;
22
23
  /** Called when a file does not meet the upload criteria (size, or type) */
23
24
  onFileRejected?: (opts: { reason: FileRejectedReason; file: File }) => void;
24
25
 
@@ -59,7 +60,7 @@
59
60
  onUpload,
60
61
  onFileRejected,
61
62
  accept,
62
- class: className,
63
+ class: css,
63
64
  ...rest
64
65
  }: FileDropZoneProps = $props();
65
66
 
@@ -13,6 +13,7 @@ export interface FileDropZoneProps extends Omit<HTMLInputAttributes, 'multiple'>
13
13
  /** The maximum size of a file in bytes */
14
14
  maxFileSize?: number;
15
15
  children?: Snippet<[]>;
16
+ css: string;
16
17
  /** Called when a file does not meet the upload criteria (size, or type) */
17
18
  onFileRejected?: (opts: {
18
19
  reason: FileRejectedReason;
@@ -13,7 +13,7 @@
13
13
  window.addEventListener('message', (e) => {
14
14
  !!e.data.frameHeight &&
15
15
  e.data.pricingUuid === handle&&
16
- (document.getElementById(handle).style.height = e.data.frameHeight);
16
+ (document.getElementById(handle)?.style?.height = e.data.frameHeight);
17
17
  });
18
18
  }
19
19
  </script>
@@ -0,0 +1,362 @@
1
+ <script lang="ts">
2
+ import { cn } from '../../utils.js';
3
+ import { NavigationDirection, Tab, TabSizes } from './tabs.js';
4
+
5
+ interface Props {
6
+ tabs: Array<Tab>; //` = [];
7
+ size?: TabSizes; //` = '';
8
+ isBorderless?: boolean; //` = false;
9
+ isVerticalOrientation?: boolean; //` = false;
10
+ isSkinned?: boolean; //` = true;
11
+ }
12
+
13
+ let {
14
+ tabs,
15
+ size = TabSizes.empty,
16
+ isBorderless,
17
+ isVerticalOrientation,
18
+ isSkinned,
19
+ }: Props = $props();
20
+
21
+ let dynamicComponentRefs = $state([]); //https://svelte.dev/tutorial/component-this
22
+ let tabButtonRefs: Array<HTMLButtonElement> = $state([]);
23
+ let activePanel = $state(null);
24
+
25
+ const baseStyles = () => `tabs ${isVerticalOrientation ? 'tabs-vertical' : ''}`;
26
+
27
+ const selectTab = (index: number) => {
28
+ tabs = tabs.map((tab, i) => {
29
+ tab.isActive = index === i ? true : false;
30
+ return tab;
31
+ });
32
+ };
33
+ let activeTabs = tabs.filter((tab) => tab.isActive);
34
+ if (activeTabs.length === 0) {
35
+ selectTab(0);
36
+ }
37
+
38
+ let tablistClasses = $derived(
39
+ cn(isSkinned ? 'tab-list' : 'tab-list-base', isBorderless ? `tab-borderless` : '')
40
+ );
41
+
42
+ let tabButtonClasses = $derived((tab: any) => {
43
+ const klasses = [
44
+ `tab-item`,
45
+ `tab-button`,
46
+ tab.isActive ? 'active' : '',
47
+ size === TabSizes.large ? 'tab-button-large' : '',
48
+ size === TabSizes.xlarge ? 'tab-button-xlarge' : ''
49
+ ];
50
+ return klasses.filter((klass) => klass.length).join(' ');
51
+ });
52
+
53
+ const focusTab = (index: number, direction: NavigationDirection = NavigationDirection.asc) => {
54
+ // console.log("tabButtonRefs: ", tabButtonRefs);
55
+ // console.log("dynamicComponentRefs: ", dynamicComponentRefs);
56
+ /**
57
+ * direction is optional because we only need that when we're arrow navigating.
58
+ * If they've hit ENTER|SPACE we're focusing the current item. If HOME focus(0).
59
+ * If END focus(tabButtons.length - 1)...and so on.
60
+ */
61
+ let i = index;
62
+ if (direction === NavigationDirection.asc) {
63
+ i += 1;
64
+ } else if (direction === NavigationDirection.desc) {
65
+ i -= 1;
66
+ }
67
+
68
+ // Circular navigation
69
+ //
70
+ // If we've went beyond "start" circle around to last
71
+ if (i < 0) {
72
+ i = tabs.length - 1;
73
+ } else if (i >= tabs.length) {
74
+ // We've went beyond "last" so circle around to first
75
+ i = 0;
76
+ }
77
+
78
+ /**
79
+ * Figure out at run-time whether this was build with dynamicComponentRefs (consumer
80
+ * used their own tabButtonComponent), or tabButtonRefs (we generated the buttons here)
81
+ */
82
+
83
+ let nextTab: any;
84
+ if (tabButtonRefs.length) {
85
+ nextTab = tabButtonRefs[i];
86
+ } else if (dynamicComponentRefs.length) {
87
+ // Same logic as above, but we're using the binding to component instance
88
+ nextTab = dynamicComponentRefs[i];
89
+ }
90
+ // Edge case: We hit a tab button that's been disabled. If so, we recurse, but
91
+ // only if we've been supplied a `direction`. Otherwise, nothing left to do.
92
+ if ((nextTab.isDisabled && nextTab.isDisabled()) || (nextTab.disabled && direction)) {
93
+ // Retry with new `i` index going in same direction
94
+ focusTab(i, direction);
95
+ } else {
96
+ // Nominal case is to just focs next tab :)
97
+ nextTab.focus();
98
+ }
99
+ };
100
+
101
+ const handleKeyDown = (ev: any, index: number) => {
102
+ switch (ev.key) {
103
+ case 'Up': // These first cases are IEEdge :(
104
+ case 'ArrowUp':
105
+ if (isVerticalOrientation) {
106
+ focusTab(index, NavigationDirection.desc);
107
+ }
108
+ break;
109
+ case 'Down':
110
+ case 'ArrowDown':
111
+ if (isVerticalOrientation) {
112
+ focusTab(index, NavigationDirection.asc);
113
+ }
114
+ break;
115
+ case 'Left':
116
+ case 'ArrowLeft':
117
+ if (!isVerticalOrientation) {
118
+ focusTab(index, NavigationDirection.desc);
119
+ }
120
+ break;
121
+ case 'Right':
122
+ case 'ArrowRight':
123
+ if (!isVerticalOrientation) {
124
+ focusTab(index, NavigationDirection.asc);
125
+ }
126
+ break;
127
+ case 'Home':
128
+ case 'ArrowHome':
129
+ focusTab(0);
130
+ break;
131
+ case 'End':
132
+ case 'ArrowEnd':
133
+ focusTab(tabs.length - 1);
134
+ break;
135
+ case 'Enter':
136
+ case 'Space':
137
+ focusTab(index);
138
+ selectTab(index);
139
+ break;
140
+ default:
141
+ return;
142
+ }
143
+ ev.preventDefault();
144
+ };
145
+ </script>
146
+
147
+ <div class={baseStyles()}>
148
+ <div
149
+ class={tablistClasses}
150
+ role="tablist"
151
+ aria-orientation={isVerticalOrientation ? 'vertical' : 'horizontal'}
152
+ >
153
+ {#each tabs as tab, i}
154
+ <!-- {#if tab.tabButtonComponent}
155
+ <svelte:component
156
+ this={tab.tabButtonComponent}
157
+ bind:this={dynamicComponentRefs[i]}
158
+ on:click={() => selectTab(i)}
159
+ on:keydown={(e) => handleKeyDown(e, i)}
160
+ disabled={isDisabled || disabledOptions.includes(tab.title) || undefined}
161
+ classes={tabButtonClasses(tab)}
162
+ role="tab"
163
+ ariaControls={tab.ariaControls}
164
+ isActive={tab.isActive}
165
+ >
166
+ {tab.title}
167
+ </svelte:component>
168
+ {:else} -->
169
+ <button
170
+ bind:this={tabButtonRefs[i]}
171
+ on:click={() => selectTab(i)}
172
+ on:keydown={(e) => handleKeyDown(e, i)}
173
+ disabled={tab.isDisabled}
174
+ class={tabButtonClasses(tab)}
175
+ role="tab"
176
+ aria-controls={tab.ariaControls}
177
+ tabindex={tab.isActive ? 0 : -1}
178
+ aria-selected={tab.isActive}
179
+ >
180
+ {tab.title}
181
+ </button>
182
+ <!-- {/if} -->
183
+ {/each}
184
+ </div>
185
+ {#if activePanel}
186
+ {@render activePanel?.tabPanelComponent()}
187
+ {/if}
188
+ <!-- {#each tabs as panel}
189
+ {#if panel.isActive}
190
+ {@render panel?.tabPanelComponent()}
191
+
192
+ {/each} -->
193
+ </div>
194
+
195
+ <style>
196
+ /* TODO -- should we use these for .nav? */
197
+ .tabs {
198
+ display: flex;
199
+ flex-direction: column;
200
+ }
201
+
202
+ .tabs-vertical {
203
+ flex-direction: row;
204
+ }
205
+
206
+ .tab-list,
207
+ .tab-list-base {
208
+ display: flex;
209
+ flex-flow: row wrap;
210
+ flex: 0 0 auto;
211
+ }
212
+
213
+ .tab-list,
214
+ .tab-skinned {
215
+ padding-inline-start: 0;
216
+ margin-block-end: 0;
217
+ border-bottom: var(--agnostic-tabs-border-size, 1px) solid
218
+ var(--agnostic-tabs-bgcolor, var(--agnostic-gray-light));
219
+ transition-property: all;
220
+ transition-duration: var(--agnostic-timing-medium);
221
+ }
222
+
223
+ /* In vertical orientation we want our tab buttons to stack */
224
+ .tabs-vertical .tab-list,
225
+ .tabs-vertical .tab-base {
226
+ flex-direction: column;
227
+ border: none;
228
+ }
229
+
230
+ /* We can ask for .tab-button which is base and skin combined, or, we can utilize .tab-button-base
231
+ if we'd like to only blank out buttons but otherwise skin ourselves. */
232
+ .tab-button,
233
+ .tab-button-base {
234
+ /* Blank out the button */
235
+ background-color: transparent;
236
+ border: 0;
237
+ border-radius: 0;
238
+ box-shadow: none;
239
+
240
+ /* This fixes issue where upon focus, the a11y focus ring's box shadow would get tucked beneat
241
+ adjacent tab buttons; relative creates new stacking context https://stackoverflow.com/a/31276836 */
242
+ position: relative;
243
+
244
+ /* Reset margins/padding; this will get added back if it's a "skinned" tab button. However, we have
245
+ a use case where a tab-button is wrapping a faux button. For that, we don't want margins/padding because
246
+ the faux button provides that. */
247
+ margin-inline-start: 0;
248
+ margin-inline-end: 0;
249
+ padding-block-start: 0;
250
+ padding-block-end: 0;
251
+ padding-inline-start: 0;
252
+ padding-inline-end: 0;
253
+ }
254
+
255
+ .tab-button,
256
+ .tab-button-skin {
257
+ display: block;
258
+
259
+ /* Since this is a "skinned tab button" we add our padding here to previously "reset" .tab-button-base */
260
+ padding-block-start: var(--agnostic-vertical-pad, 0.5rem);
261
+ padding-block-end: var(--agnostic-vertical-pad, 0.5rem);
262
+ padding-inline-start: var(--agnostic-side-padding, 0.75rem);
263
+ padding-inline-end: var(--agnostic-side-padding, 0.75rem);
264
+ font-family: var(--agnostic-btn-font-family, var(--agnostic-font-family-body));
265
+ font-weight: var(--agnostic-btn-font-weight, 400);
266
+ font-size: var(--agnostic-btn-font-size, 1rem);
267
+
268
+ /* this can be overriden, but it might mess with the balance of the button heights across variants */
269
+ line-height: var(--agnostic-line-height, var(--fluid-20, 1.25rem));
270
+ color: var(--agnostic-tabs-primary, var(--agnostic-primary));
271
+ text-decoration: none;
272
+ transition:
273
+ color var(--agnostic-timing-fast) ease-in-out,
274
+ background-color var(--agnostic-timing-fast) ease-in-out,
275
+ border-color var(--agnostic-timing-fast) ease-in-out;
276
+ }
277
+
278
+ /* We pull back the 2nd subsequent tabs to remove the double border */
279
+ .tab-button:not(:first-of-type),
280
+ .tab-button-base:not(:first-of-type) {
281
+ margin-inline-start: -1px;
282
+ }
283
+
284
+ .tab-borderless {
285
+ border: none !important;
286
+ }
287
+
288
+ .tab-button-large {
289
+ padding-block-start: calc(var(--agnostic-input-side-padding) * 1.25);
290
+ padding-block-end: calc(var(--agnostic-input-side-padding) * 1.25);
291
+ padding-inline-start: calc(var(--agnostic-input-side-padding) * 1.75);
292
+ padding-inline-end: calc(var(--agnostic-input-side-padding) * 1.75);
293
+ }
294
+
295
+ .tab-button-xlarge {
296
+ padding-block-start: calc(var(--agnostic-input-side-padding) * 2);
297
+ padding-block-end: calc(var(--agnostic-input-side-padding) * 2);
298
+ padding-inline-start: calc(var(--agnostic-input-side-padding) * 3);
299
+ padding-inline-end: calc(var(--agnostic-input-side-padding) * 3);
300
+ }
301
+
302
+ .tab-item.tab-button {
303
+ margin-block-end: -1px;
304
+ background: 0 0;
305
+ border: 1px solid transparent;
306
+ border-top-left-radius: var(--agnostic-tabs-radius, 0.25rem);
307
+ border-top-right-radius: var(--agnostic-tabs-radius, 0.25rem);
308
+ }
309
+
310
+ .tab-item.tab-button.active {
311
+ color: var(--agnostic-dark);
312
+ background-color: var(--agnostic-light);
313
+ border-color: var(--agnostic-gray-light) var(--agnostic-gray-light) var(--agnostic-light);
314
+ }
315
+
316
+ .tab-item:hover,
317
+ .tab-button:focus {
318
+ border-color: var(--agnostic-focus-ring-outline-width) var(--agnostic-focus-ring-outline-width)
319
+ var(--agnostic-gray-light);
320
+ isolation: isolate;
321
+ z-index: 1;
322
+ cursor: pointer;
323
+ }
324
+
325
+ .tabs-vertical .tab-button {
326
+ border: none;
327
+ }
328
+
329
+ .tab-button:disabled {
330
+ color: var(--agnostic-tabs-disabled-bg, var(--agnostic-gray-mid-dark));
331
+ background-color: transparent;
332
+ border-color: transparent;
333
+ opacity: 80%;
334
+ }
335
+
336
+ /**
337
+ * Elects to additively use the AgnosticUI custom focus ring alongside the border
338
+ * we already add above. It just makes things look more consistent across components.
339
+ * For example, when we tab into the panels and links within.
340
+ */
341
+ .tab-button-base:focus,
342
+ .tab-panel:focus,
343
+ .tab-button:focus {
344
+ box-shadow: 0 0 0 var(--agnostic-focus-ring-outline-width) var(--agnostic-focus-ring-color);
345
+
346
+ /* Needed for High Contrast mode */
347
+ outline: var(--agnostic-focus-ring-outline-width) var(--agnostic-focus-ring-outline-style)
348
+ var(--agnostic-focus-ring-outline-color);
349
+ transition: box-shadow var(--agnostic-timing-fast) ease-out;
350
+ }
351
+
352
+ @media (prefers-reduced-motion), (update: slow) {
353
+ .tab-button,
354
+ .tab-button-base:focus,
355
+ .tab-button:focus,
356
+ .tab-panel:focus,
357
+ .tab-list,
358
+ .tab-skinned {
359
+ transition-duration: 0.001ms !important;
360
+ }
361
+ }
362
+ </style>
@@ -1,26 +1,11 @@
1
- export default Tabs;
2
- type Tabs = SvelteComponent<{
3
- [x: string]: never;
4
- }, {
5
- [evt: string]: CustomEvent<any>;
6
- }, {}> & {
7
- $$bindings?: string | undefined;
8
- };
9
- declare const Tabs: $$__sveltets_2_IsomorphicComponent<{
10
- [x: string]: never;
11
- }, {
12
- [evt: string]: CustomEvent<any>;
13
- }, {}, {}, string>;
14
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
15
- new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
16
- $$bindings?: Bindings;
17
- } & Exports;
18
- (internal: unknown, props: {
19
- $$events?: Events;
20
- $$slots?: Slots;
21
- }): Exports & {
22
- $set?: any;
23
- $on?: any;
24
- };
25
- z_$$bindings?: Bindings;
1
+ import { Tab, TabSizes } from './tabs.js';
2
+ interface Props {
3
+ tabs: Array<Tab>;
4
+ size?: TabSizes;
5
+ isBorderless?: boolean;
6
+ isVerticalOrientation?: boolean;
7
+ isSkinned?: boolean;
26
8
  }
9
+ declare const Tabs: import("svelte").Component<Props, {}, "">;
10
+ type Tabs = ReturnType<typeof Tabs>;
11
+ export default Tabs;
@@ -1,10 +1,21 @@
1
1
  import type { Snippet } from "svelte";
2
2
  export interface Tab {
3
3
  title: string;
4
- tabPanelComponent: Snippet;
4
+ tabId?: string;
5
+ tabHref?: string;
6
+ tabPanelComponent?: Snippet;
5
7
  tabButtonComponent?: Snippet;
6
8
  isActive?: boolean;
7
9
  ariaControls?: string;
10
+ isDisabled?: boolean;
11
+ }
12
+ export declare enum TabSizes {
13
+ 'small' = 0,
14
+ 'large' = 1,
15
+ 'xlarge' = 2,
16
+ empty = ""
17
+ }
18
+ export declare enum NavigationDirection {
19
+ 'asc' = 0,
20
+ 'desc' = 1
8
21
  }
9
- export type TabSizes = 'small' | 'large' | 'xlarge' | '';
10
- export type NavigationDirection = 'asc' | 'desc';
@@ -1,2 +1,13 @@
1
1
  ;
2
- export {};
2
+ export var TabSizes;
3
+ (function (TabSizes) {
4
+ TabSizes[TabSizes["small"] = 0] = "small";
5
+ TabSizes[TabSizes["large"] = 1] = "large";
6
+ TabSizes[TabSizes["xlarge"] = 2] = "xlarge";
7
+ TabSizes["empty"] = "";
8
+ })(TabSizes || (TabSizes = {}));
9
+ export var NavigationDirection;
10
+ (function (NavigationDirection) {
11
+ NavigationDirection[NavigationDirection["asc"] = 0] = "asc";
12
+ NavigationDirection[NavigationDirection["desc"] = 1] = "desc";
13
+ })(NavigationDirection || (NavigationDirection = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionalcms/svelte-components",
3
- "version": "4.8.19",
3
+ "version": "4.9.1",
4
4
  "watch": {
5
5
  "build": {
6
6
  "patterns": [