@skeletonlabs/skeleton 2.6.0 → 2.6.1-dev.04dfa822

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.
@@ -17,18 +17,42 @@ export function focusTrap(node, enabled) {
17
17
  elemFirst.focus();
18
18
  }
19
19
  }
20
+ // Sort focusable elements by tabindex, positive first, then 0
21
+ const sortByTabIndex = (focusableElems) => {
22
+ return focusableElems
23
+ .filter((elem) => elem.tabIndex >= 0)
24
+ .sort((a, b) => {
25
+ if (a.tabIndex === 0 && b.tabIndex > 0)
26
+ return 1; // Move 0 to end of array
27
+ else if (a.tabIndex > 0 && b.tabIndex === 0)
28
+ return -1; // Move 0 to end of array
29
+ else
30
+ return a.tabIndex - b.tabIndex; // Sort non-zero values in ascending order
31
+ });
32
+ };
33
+ // Get element with smallest focusindex value, or first focusable element
34
+ const getFocusTrapTarget = (elemFirst) => {
35
+ // Get elements with data-focusindex attribute
36
+ const focusindexElements = [...node.querySelectorAll('[data-focusindex]')];
37
+ if (!focusindexElements || focusindexElements.length === 0)
38
+ return elemFirst;
39
+ // return smallest focusindex element or elemFirst
40
+ return (focusindexElements.sort((a, b) => {
41
+ return +a.dataset.focusindex - +b.dataset.focusindex;
42
+ })[0] || elemFirst);
43
+ };
20
44
  const onScanElements = (fromObserver) => {
21
45
  if (enabled === false)
22
46
  return;
23
- // Gather all focusable elements
24
- const focusableElems = Array.from(node.querySelectorAll(elemWhitelist));
47
+ // Gather all focusable elements, sorted according to tabindex
48
+ const focusableElems = sortByTabIndex(Array.from(node.querySelectorAll(elemWhitelist)));
25
49
  if (focusableElems.length) {
26
50
  // Set first/last focusable elements
27
51
  elemFirst = focusableElems[0];
28
52
  elemLast = focusableElems[focusableElems.length - 1];
29
- // Auto-focus first focusable element only when not called from observer
53
+ // Auto-focus focusTrapTarget or first focusable element only when not called from observer
30
54
  if (!fromObserver)
31
- elemFirst.focus();
55
+ getFocusTrapTarget(elemFirst).focus();
32
56
  // Listen for keydown on first & last element
33
57
  elemFirst.addEventListener('keydown', onFirstElemKeydown);
34
58
  elemLast.addEventListener('keydown', onLastElemKeydown);
@@ -1,12 +1,11 @@
1
- <script>import { getContext } from "svelte";
2
- import { createEventDispatcher } from "svelte";
1
+ <script>import { createEventDispatcher, getContext } from "svelte";
3
2
  import { dynamicTransition } from "../../internal/transitions.js";
4
3
  const dispatch = createEventDispatcher();
5
4
  export let open = false;
6
5
  export let id = String(Math.random());
7
6
  const cBase = "";
8
7
  const cControl = "text-start w-full flex items-center space-x-4";
9
- const cControlCaret = "fill-current w-3 transition-transform duration-[200ms]";
8
+ const cControlIcons = "fill-current w-3 transition-transform duration-[200ms]";
10
9
  const cPanel = "";
11
10
  export let autocollapse = getContext("autocollapse");
12
11
  export let active = getContext("active");
@@ -24,6 +23,10 @@ export let transitionIn = getContext("transitionIn");
24
23
  export let transitionInParams = getContext("transitionInParams");
25
24
  export let transitionOut = getContext("transitionOut");
26
25
  export let transitionOutParams = getContext("transitionOutParams");
26
+ const svgCaretIcon = `
27
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class={classesControlCaret}>
28
+ <path d="M201.4 374.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 306.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z" />
29
+ </svg>`;
27
30
  function setActive(event) {
28
31
  if (autocollapse === true) {
29
32
  active.set(id);
@@ -56,7 +59,9 @@ $:
56
59
  $:
57
60
  classesCaretState = openState ? caretOpen : caretClosed;
58
61
  $:
59
- classesControlCaret = `${cControlCaret} ${regionCaret} ${classesCaretState}`;
62
+ classesControlCaret = `${cControlIcons} ${regionCaret} ${classesCaretState}`;
63
+ $:
64
+ classesControlIcons = `${cControlIcons} ${regionCaret}`;
60
65
  $:
61
66
  classesPanel = `${cPanel} ${padding} ${rounded} ${regionPanel}`;
62
67
  </script>
@@ -88,15 +93,21 @@ $:
88
93
  <div class="accordion-summary flex-1">
89
94
  <slot name="summary">(summary)</slot>
90
95
  </div>
91
- <!-- Caret -->
92
- <div class="accordion-summary-caret {classesControlCaret}">
96
+ <!-- Icons -->
97
+ {#if $$slots.iconClosed || $$slots.iconOpen}
98
+ <!-- Custom -->
99
+ <!-- If a custom icon is provided, do not use rotation -->
100
+ <div class="accordion-summary-icons {classesControlIcons}">
101
+ {#if openState}
102
+ <slot name="iconClosed">{@html svgCaretIcon}</slot>
103
+ {:else}
104
+ <slot name="iconOpen">{@html svgCaretIcon}</slot>
105
+ {/if}
106
+ </div>
107
+ {:else}
93
108
  <!-- SVG Caret -->
94
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
95
- <path
96
- d="M201.4 374.6c12.5 12.5 32.8 12.5 45.3 0l160-160c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L224 306.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l160 160z"
97
- />
98
- </svg>
99
- </div>
109
+ <div class="accordion-summary-caret {classesControlCaret}">{@html svgCaretIcon}</div>
110
+ {/if}
100
111
  </button>
101
112
  <!-- Panel -->
102
113
  {#if openState}
@@ -28,7 +28,7 @@ declare class __sveltets_Render<TransitionIn extends Transition, TransitionOut e
28
28
  regionControl?: string | undefined;
29
29
  /** Provide arbitrary classes to content panel region.*/
30
30
  regionPanel?: string | undefined;
31
- /** Provide arbitrary classes caret icon region.*/
31
+ /** Provide arbitrary classes default region.*/
32
32
  regionCaret?: string | undefined;
33
33
  /** Enable/Disable transitions*/
34
34
  transitions?: boolean | undefined;
@@ -59,6 +59,8 @@ declare class __sveltets_Render<TransitionIn extends Transition, TransitionOut e
59
59
  slots(): {
60
60
  lead: {};
61
61
  summary: {};
62
+ iconClosed: {};
63
+ iconOpen: {};
62
64
  content: {};
63
65
  };
64
66
  }
@@ -1,5 +1,6 @@
1
1
  <script>export let initials = "AB";
2
2
  export let fill = "fill-token";
3
+ export let fontSize = 150;
3
4
  export let src = "";
4
5
  export let fallback = "";
5
6
  export let action = () => {
@@ -12,7 +13,7 @@ export let rounded = "rounded-full";
12
13
  export let shadow = "";
13
14
  export let cursor = "";
14
15
  let cBase = "flex aspect-square text-surface-50 font-semibold justify-center items-center overflow-hidden isolate";
15
- let cImage = "w-full h-full object-cover";
16
+ let cImage = "w-full object-cover";
16
17
  $:
17
18
  classesBase = `${cBase} ${background} ${width} ${border} ${rounded} ${shadow} ${cursor} ${$$props.class ?? ""}`;
18
19
  function prunedRestProps() {
@@ -36,7 +37,15 @@ function prunedRestProps() {
36
37
  />
37
38
  {:else}
38
39
  <svg class="avatar-initials w-full h-full" viewBox="0 0 512 512">
39
- <text x="50%" y="50%" dominant-baseline="central" text-anchor="middle" font-weight="bold" font-size={150} class="avatar-text {fill}">
40
+ <text
41
+ x="50%"
42
+ y="50%"
43
+ dominant-baseline="central"
44
+ text-anchor="middle"
45
+ font-weight="bold"
46
+ font-size={fontSize}
47
+ class="avatar-text {fill}"
48
+ >
40
49
  {String(initials).substring(0, 2).toUpperCase()}
41
50
  </text>
42
51
  </svg>
@@ -7,6 +7,8 @@ declare const __propDef: {
7
7
  initials?: string | undefined;
8
8
  /** Initials only - Provide classes to set the SVG text fill color.*/
9
9
  fill?: string | undefined;
10
+ /** Initials only - Set the base font size for the scalable SVG text.*/
11
+ fontSize?: number | undefined;
10
12
  /** Provide the avatar image element source.*/
11
13
  src?: string | undefined;
12
14
  /** Provide the fallback image element source.*/
@@ -4,6 +4,7 @@ export let max = 100;
4
4
  export let height = "h-2";
5
5
  export let rounded = "rounded-token";
6
6
  export let transition = "transition-[width]";
7
+ export let animIndeterminate = "anim-indeterminate";
7
8
  export let meter = "bg-surface-900-50-token";
8
9
  export let track = "bg-surface-200-700-token";
9
10
  export let labelledby = "";
@@ -14,7 +15,7 @@ $:
14
15
  $:
15
16
  indeterminate = value === void 0 || value < 0;
16
17
  $:
17
- classesIndeterminate = indeterminate ? "animIndeterminate" : "";
18
+ classesIndeterminate = indeterminate ? animIndeterminate : "";
18
19
  $:
19
20
  classesTrack = `${cTrack} ${track} ${height} ${rounded} ${$$props.class ?? ""}`;
20
21
  $:
@@ -36,12 +37,12 @@ $:
36
37
  </div>
37
38
 
38
39
  <style>
39
- .animIndeterminate {
40
+ .anim-indeterminate {
40
41
  transform-origin: 0% 50%;
41
- animation: animIndeterminate 2s infinite linear;
42
+ animation: anim-indeterminate 2s infinite linear;
42
43
  }
43
44
  /* prettier-ignore */
44
- @keyframes animIndeterminate {
45
+ @keyframes anim-indeterminate {
45
46
  0% { transform: translateX(0) scaleX(0); }
46
47
  40% { transform: translateX(0) scaleX(0.4); }
47
48
  100% { transform: translateX(100%) scaleX(0.5); }
@@ -14,6 +14,8 @@ declare const __propDef: {
14
14
  rounded?: string | undefined;
15
15
  /** Provide classes to set the meter transition styles.*/
16
16
  transition?: string | undefined;
17
+ /** Provide classes to replace the default animation styles.*/
18
+ animIndeterminate?: string | undefined;
17
19
  /** Sets the base classes of the meter element.*/
18
20
  meter?: string | undefined;
19
21
  /** Sets the base classes of the track element.*/
@@ -1,8 +1,9 @@
1
1
  <script>import { setContext } from "svelte";
2
2
  export let display = "inline-flex";
3
+ export let flexDirection = "flex-row";
4
+ export let gap = "gap-1";
3
5
  export let background = "bg-surface-200-700-token";
4
6
  export let border = "border-token border-surface-400-500-token";
5
- export let spacing = "";
6
7
  export let rounded = "rounded-token";
7
8
  export let padding = "px-4 py-1";
8
9
  export let active = "variant-filled";
@@ -20,9 +21,7 @@ setContext("fill", fill);
20
21
  setContext("regionLabel", regionLabel);
21
22
  const cBase = "p-1";
22
23
  $:
23
- spacing = `${display.includes("flex-col") ? "" : "space-x-1"}`;
24
- $:
25
- classesBase = `${cBase} ${display} ${background} ${border} ${spacing} ${rounded} ${$$props.class ?? ""}`;
24
+ classesBase = `${cBase} ${display} ${flexDirection} ${gap} ${background} ${border} ${rounded} ${$$props.class ?? ""}`;
26
25
  </script>
27
26
 
28
27
  <div class="radio-group {classesBase}" data-testid="radio-group" role="radiogroup" aria-labelledby={labelledby}>
@@ -2,14 +2,16 @@ import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
4
  [x: string]: any;
5
- /** Provide display classes. Set `flex` to stretch full width.*/
5
+ /** Provide display classes. Use `flex` to stretch full width.*/
6
6
  display?: string | undefined;
7
+ /** Provide classes to set flex-direction. Use `flex-col` for vertical layout.*/
8
+ flexDirection?: string | undefined;
9
+ /** Provide classes to set gap spacing between items.*/
10
+ gap?: string | undefined;
7
11
  /** Provide classes to set the base background color.*/
8
12
  background?: string | undefined;
9
13
  /** Provide classes to set the border styles.*/
10
14
  border?: string | undefined;
11
- /** Provide classes horizontal spacing between items.*/
12
- spacing?: string | undefined;
13
15
  /** Provide classes to set the border radius.*/
14
16
  rounded?: string | undefined;
15
17
  /** Provide classes to set the RadioItem padding.*/
@@ -7,8 +7,8 @@ import { dynamicTransition } from "../../internal/transitions.js";
7
7
  const dispatch = createEventDispatcher();
8
8
  import { focusTrap } from "../../actions/FocusTrap/focusTrap.js";
9
9
  import { getModalStore } from "./stores.js";
10
- export let position = "items-center";
11
10
  export let components = {};
11
+ export let position = "items-center";
12
12
  export let background = "bg-surface-100-800-token";
13
13
  export let width = "w-modal";
14
14
  export let height = "h-auto";
@@ -22,7 +22,7 @@ export let buttonPositive = "variant-filled";
22
22
  export let buttonTextCancel = "Cancel";
23
23
  export let buttonTextConfirm = "Confirm";
24
24
  export let buttonTextSubmit = "Submit";
25
- export let regionBackdrop = "bg-surface-backdrop-token";
25
+ export let regionBackdrop = "";
26
26
  export let regionHeader = "text-2xl font-bold";
27
27
  export let regionBody = "max-h-[200px] overflow-hidden";
28
28
  export let regionFooter = "flex justify-end space-x-2";
@@ -31,8 +31,8 @@ export let transitionIn = fly;
31
31
  export let transitionInParams = { duration: 150, opacity: 0, x: 0, y: 100 };
32
32
  export let transitionOut = fly;
33
33
  export let transitionOutParams = { duration: 150, opacity: 0, x: 0, y: 100 };
34
- const cBackdrop = "fixed top-0 left-0 right-0 bottom-0 overflow-y-auto";
35
- const cTransitionLayer = "w-full h-fit min-h-full p-4 overflow-y-auto flex justify-center";
34
+ const cBackdrop = "fixed top-0 left-0 right-0 bottom-0 bg-surface-backdrop-token p-4";
35
+ const cTransitionLayer = "w-full h-fit min-h-full overflow-y-auto flex justify-center";
36
36
  const cModal = "block overflow-y-auto";
37
37
  const cModalImage = "w-full h-auto";
38
38
  let promptValue;
@@ -43,17 +43,35 @@ const buttonTextDefaults = {
43
43
  };
44
44
  let currentComponent;
45
45
  let registeredInteractionWithBackdrop = false;
46
+ let modalElement;
47
+ let windowHeight;
48
+ let backdropOverflow = "overflow-y-hidden";
46
49
  const modalStore = getModalStore();
47
- modalStore.subscribe((modals) => {
48
- if (!modals.length)
49
- return;
50
+ $:
51
+ if ($modalStore.length)
52
+ handleModals($modalStore);
53
+ function handleModals(modals) {
50
54
  if (modals[0].type === "prompt")
51
55
  promptValue = modals[0].value;
52
56
  buttonTextCancel = modals[0].buttonTextCancel || buttonTextDefaults.buttonTextCancel;
53
57
  buttonTextConfirm = modals[0].buttonTextConfirm || buttonTextDefaults.buttonTextConfirm;
54
58
  buttonTextSubmit = modals[0].buttonTextSubmit || buttonTextDefaults.buttonTextSubmit;
55
59
  currentComponent = typeof modals[0].component === "string" ? components[modals[0].component] : modals[0].component;
56
- });
60
+ }
61
+ function onModalHeightChange(modal) {
62
+ let modalHeight = modal?.clientHeight;
63
+ if (!modalHeight)
64
+ modalHeight = modal?.firstChild?.clientHeight;
65
+ if (!modalHeight)
66
+ return;
67
+ if (modalHeight > windowHeight) {
68
+ backdropOverflow = "overflow-y-auto";
69
+ } else {
70
+ backdropOverflow = "overflow-y-hidden";
71
+ }
72
+ }
73
+ $:
74
+ onModalHeightChange(modalElement);
57
75
  function onBackdropInteractionBegin(event) {
58
76
  if (!(event.target instanceof Element))
59
77
  return;
@@ -131,7 +149,7 @@ $:
131
149
  };
132
150
  </script>
133
151
 
134
- <svelte:window on:keydown={onKeyDown} />
152
+ <svelte:window bind:innerHeight={windowHeight} on:keydown={onKeyDown} />
135
153
 
136
154
  {#if $modalStore.length > 0}
137
155
  {#key $modalStore}
@@ -139,7 +157,7 @@ $:
139
157
  <!-- FIXME: resolve a11y warnings -->
140
158
  <!-- svelte-ignore a11y-no-static-element-interactions -->
141
159
  <div
142
- class="modal-backdrop {classesBackdrop}"
160
+ class="modal-backdrop {classesBackdrop} {backdropOverflow}"
143
161
  data-testid="modal-backdrop"
144
162
  on:mousedown={onBackdropInteractionBegin}
145
163
  on:mouseup={onBackdropInteractionEnd}
@@ -156,7 +174,14 @@ $:
156
174
  >
157
175
  {#if $modalStore[0].type !== 'component'}
158
176
  <!-- Modal: Presets -->
159
- <div class="modal {classesModal}" data-testid="modal" role="dialog" aria-modal="true" aria-label={$modalStore[0].title ?? ''}>
177
+ <div
178
+ class="modal {classesModal}"
179
+ bind:this={modalElement}
180
+ data-testid="modal"
181
+ role="dialog"
182
+ aria-modal="true"
183
+ aria-label={$modalStore[0].title ?? ''}
184
+ >
160
185
  <!-- Header -->
161
186
  {#if $modalStore[0]?.title}
162
187
  <header class="modal-header {regionHeader}">{@html $modalStore[0].title}</header>
@@ -196,6 +221,7 @@ $:
196
221
  <!-- Modal: Components -->
197
222
  <!-- Note: keep `contents` class to allow widths from children -->
198
223
  <div
224
+ bind:this={modalElement}
199
225
  class="modal contents {$modalStore[0]?.modalClasses ?? ''}"
200
226
  data-testid="modal-component"
201
227
  role="dialog"
@@ -6,10 +6,10 @@ import type { ModalComponent } from './types.js';
6
6
  declare class __sveltets_Render<TransitionIn extends Transition = FlyTransition, TransitionOut extends Transition = FlyTransition> {
7
7
  props(): {
8
8
  [x: string]: any;
9
- /** Set the modal position within the backdrop container*/
10
- position?: string | undefined;
11
9
  /** Register a list of reusable component modals.*/
12
10
  components?: Record<string, ModalComponent> | undefined;
11
+ /** Set the modal position within the backdrop container*/
12
+ position?: string | undefined;
13
13
  /** Provide classes to style the modal background.*/
14
14
  background?: string | undefined;
15
15
  /** Provide classes to style the modal width.*/
@@ -36,7 +36,7 @@ declare class __sveltets_Render<TransitionIn extends Transition = FlyTransition,
36
36
  buttonTextConfirm?: string | undefined;
37
37
  /** Override the text for the Submit button.*/
38
38
  buttonTextSubmit?: string | undefined;
39
- /** Provide classes to style the backdrop.*/
39
+ /** Provide arbitrary classes to the backdrop region.*/
40
40
  regionBackdrop?: string | undefined;
41
41
  /** Provide arbitrary classes to modal header region.*/
42
42
  regionHeader?: string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skeletonlabs/skeleton",
3
- "version": "2.6.0",
3
+ "version": "2.6.1-dev.04dfa822",
4
4
  "description": "A SvelteKit component library.",
5
5
  "author": "endigo9740 <chris@skeletonlabs.dev>",
6
6
  "repository": {