@splendidlabz/svelte 4.9.0 → 4.11.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/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @splendidlabz/svelte
2
2
 
3
+ ## 4.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8e3054d: Refactor Status to use `<output>` element with automatic live region: `role="alert"` for errors, `role="status"` for all other states. Add `statusText` prop. Form now accepts `status` and `statusText` props and renders a linked Status component.
8
+
9
+ ### Patch Changes
10
+
11
+ - 8e3054d: Fix accessibility of TextInput and Textarea: move `aria-label` onto the input element, make error live region always present in DOM (sr-only when empty), use `<output for={id} role="alert">` pattern for error announcements.
12
+ - df4623c: Resolve Svelte `state_referenced_locally` warnings in form, tabcordion, disclosure, and image components.
13
+ - Updated dependencies [42cd5a2]
14
+ - @splendidlabz/utils@1.11.6
15
+
16
+ ## 4.10.0
17
+
18
+ ### Minor Changes
19
+
20
+ - 13fdcd9: feat(Tabcordion): refactor to context-based API with TabcordionItem; simplify Accordion
21
+
22
+ **Tabcordion** — replaced `tabs` array prop with Svelte context + `TabcordionItem` children. CSS scoped per instance via IDs (no global `.tabs`/`.accordion-stack` bleed). New passthrough props: `accordion`, `tablist`, `tab`, `tabpanels`, `tabpanel`.
23
+
24
+ ```svelte
25
+ <Tabcordion>
26
+ <TabcordionItem title="Tab 1">Content for tab 1</TabcordionItem>
27
+ <TabcordionItem title="Tab 2">Content for tab 2</TabcordionItem>
28
+ </Tabcordion>
29
+ ```
30
+
31
+ **Accordion** — simplified: removed `closeOthers` prop and `accordion-controlled.js` dependency. `open` is now a bindable prop (default `false`). `onToggle` called via `isFunction` guard. Controlled and uncontrolled modes unified.
32
+
33
+ ### Patch Changes
34
+
35
+ - 5fdfc45: Updated `@iconify/svelte` to `5.2.1` for Svelte 5 compatibility.
36
+ - 58f768f: Removed `BrowserWithTabs` component. Added `title` and `titleClass` props to `Tab` for vertical tab layouts. Fixed `Tablist` class generation for non-top placements.
37
+ - Updated dependencies [c054af3]
38
+ - Updated dependencies [92d1320]
39
+ - Updated dependencies [60ce1ac]
40
+ - @splendidlabz/utils@1.11.5
41
+ - @splendidlabz/styles@4.8.0
42
+
3
43
  ## 4.9.0
4
44
 
5
45
  ### Minor Changes
@@ -1,42 +1,44 @@
1
1
  <script>
2
+ import { isFunction } from '@splendidlabz/utils'
2
3
  import { randomString } from '@splendidlabz/utils/dom'
3
4
  import { applyTransition, init } from '../../utils/index.js'
4
5
  import { reloadScripts } from '../../utils/loadscripts.js'
5
6
  import { IconSnippet } from '../Icon/IconSnippet.svelte'
6
7
  import { MarkdownSnippet } from '../Markdown/MarkdownSnippet.svelte'
7
8
 
8
- const {
9
+ let {
9
10
  id = randomString(9),
10
11
  class: klass,
11
- titleClass,
12
- contentClass,
13
- buttonClass,
14
- icon = 'tabler:chevron-right',
15
- iconClass,
16
- iconPosition = 'end',
17
- closeOthers = false,
18
- useMarkdown = true,
19
12
  titleTag = 'h3',
20
13
  transition = 'slide',
21
14
  title,
22
15
  content,
16
+ open = $bindable(false),
17
+ onToggle = undefined,
23
18
  children,
19
+ ...rest
24
20
  } = $props()
25
21
 
26
- let show = $state(false)
22
+ // svelte-ignore state_referenced_locally
23
+ const {
24
+ titleClass,
25
+ contentClass,
26
+ buttonClass,
27
+ icon = 'tabler:chevron-right',
28
+ iconClass,
29
+ iconPosition = 'end',
30
+ useMarkdown = true,
31
+ } = rest
27
32
 
28
33
  init(() => {
29
34
  if (!title) console.warn('Accordion: No title provided')
30
35
  if (!content && !children) console.warn('Accordion: No content provided')
31
36
  })
32
37
 
33
- // ========================================
34
- // Event Handlers
35
- // ========================================
36
38
  function handleClick(event) {
37
- // Toggle accordion show
38
- show = !show
39
- if (show && closeOthers) closeOtherAccordions(event)
39
+ open = !open
40
+ if (isFunction(onToggle)) onToggle(open)
41
+ if (open) closeOtherAccordions(event)
40
42
  }
41
43
 
42
44
  function handleKeydown(event) {
@@ -45,28 +47,26 @@
45
47
  }
46
48
 
47
49
  function closeAccordion() {
48
- show = false
50
+ open = false
51
+ if (isFunction(onToggle)) onToggle(false)
49
52
  }
50
53
 
51
- // ========================================
52
- // Helper functions
53
- // ========================================
54
54
  function closeOtherAccordions(event) {
55
55
  const container = event.target.closest('.accordion-stack')
56
56
  if (!container) return
57
57
  const closeButtons = container.querySelectorAll('.accordion-close-button')
58
58
  closeButtons.forEach(button => button.click())
59
- show = true
59
+ open = true
60
60
  }
61
61
  </script>
62
62
 
63
63
  <!-- Accordion HTML -->
64
- <div class="accordion {klass}" class:open={show}>
64
+ <div class="accordion {klass}" class:open>
65
65
  <svelte:element this={titleTag} class="accordion-title {titleClass}">
66
66
  <button
67
67
  class="accordion-button {buttonClass}"
68
68
  aria-controls={id}
69
- aria-expanded={show}
69
+ aria-expanded={open}
70
70
  onclick={handleClick}
71
71
  onkeydown={handleKeydown}
72
72
  >
@@ -85,7 +85,7 @@
85
85
  </button>
86
86
  </svelte:element>
87
87
 
88
- {#if show}
88
+ {#if open}
89
89
  <div
90
90
  {id}
91
91
  class="accordion-content {contentClass}"
@@ -0,0 +1,4 @@
1
+ export function resolveShow(open, internalShow) {
2
+ if (open === undefined) return internalShow
3
+ return open
4
+ }
@@ -0,0 +1,14 @@
1
+ import { describe, expect, test } from 'vitest'
2
+ import { resolveShow } from './accordion-controlled.js'
3
+
4
+ describe('resolveShow', () => {
5
+ test('returns internalShow when open is undefined', () => {
6
+ expect(resolveShow(undefined, true)).toBe(true)
7
+ expect(resolveShow(undefined, false)).toBe(false)
8
+ })
9
+
10
+ test('returns open value when open is provided', () => {
11
+ expect(resolveShow(true, false)).toBe(true)
12
+ expect(resolveShow(false, true)).toBe(false)
13
+ })
14
+ })
@@ -1,3 +1,2 @@
1
1
  import BrowserFrame from './BrowserFrame.svelte'
2
- import BrowserWithTabs from './BrowserWithTabs.svelte'
3
- export { BrowserFrame, BrowserWithTabs }
2
+ export { BrowserFrame }
@@ -10,42 +10,55 @@
10
10
  as = 'dialog',
11
11
  ref = $bindable(null),
12
12
  referenceNode = $bindable(null),
13
- ...p
13
+ ...props
14
14
  } = $props()
15
15
 
16
- p = mergeOpts(p)
17
-
18
- const {
19
- componentName = 'Popover',
20
- 'aria-label': ariaLabel,
21
- 'aria-labelledBy': ariaLabelledBy,
22
- 'aria-describedby': ariaDescribedBy,
23
-
24
- // Props
25
- id,
26
- popover = 'auto', // manual, hint
27
-
28
- // Event listeners
29
- onbeforetoggle = null,
30
- ontoggle = null,
31
- onopen = null,
32
- onclose = null,
33
-
34
- // Slots
35
- children,
36
- ...rest
37
- } = p
16
+ const p = $derived(mergeOpts(props))
17
+
18
+ const componentName = $derived(p.componentName ?? 'Popover')
19
+ const ariaLabel = $derived(p['aria-label'])
20
+ const ariaLabelledBy = $derived(p['aria-labelledBy'])
21
+ const ariaDescribedBy = $derived(p['aria-describedby'])
22
+
23
+ const id = $derived(p.id)
24
+ const popover = $derived(p.popover ?? 'auto') // manual, hint
25
+
26
+ const onbeforetoggle = $derived(p.onbeforetoggle ?? null)
27
+ const ontoggle = $derived(p.ontoggle ?? null)
28
+ const onopen = $derived(p.onopen ?? null)
29
+ const onclose = $derived(p.onclose ?? null)
30
+
31
+ const children = $derived(p.children)
32
+ const rest = $derived.by(() => {
33
+ const {
34
+ componentName = 'Popover',
35
+ 'aria-label': ariaLabel,
36
+ 'aria-labelledBy': ariaLabelledBy,
37
+ 'aria-describedby': ariaDescribedBy,
38
+ id,
39
+ popover = 'auto',
40
+ onbeforetoggle = null,
41
+ ontoggle = null,
42
+ onopen = null,
43
+ onclose = null,
44
+ children,
45
+ ...rest
46
+ } = p
47
+ return rest
48
+ })
38
49
 
39
50
  // ========================
40
51
  // Checks
41
52
  // ========================
42
- if (!id) throw new Error(`${componentName} requires an id`)
43
-
44
- // Accessible name warning
45
- checkForAccessibleName({
46
- name: `${componentName} (id: ${id})`,
47
- ariaLabel,
48
- ariaLabelledBy,
53
+ $effect(() => {
54
+ if (!id) throw new Error(`${componentName} requires an id`)
55
+
56
+ // Accessible name warning
57
+ checkForAccessibleName({
58
+ name: `${componentName} (id: ${id})`,
59
+ ariaLabel,
60
+ ariaLabelledBy,
61
+ })
49
62
  })
50
63
 
51
64
  // ========================================
@@ -54,7 +67,8 @@
54
67
  let trigger = null
55
68
  let floating = null
56
69
 
57
- const { picked: floatingOpts } = splitObject(rest, FLOATING_OPTS_KEYS)
70
+ const floatingSplit = $derived(splitObject(rest, FLOATING_OPTS_KEYS))
71
+ const floatingOpts = $derived(floatingSplit.picked)
58
72
 
59
73
  // ========================================
60
74
  // Event Listeners
@@ -20,26 +20,39 @@
20
20
  ...p
21
21
  } = $props()
22
22
 
23
- const opts = mergeOpts(DRAWER_CONTENT_OPTS, DRAWER_POSITION_OPTS[position], p)
23
+ const opts = $derived(
24
+ mergeOpts(DRAWER_CONTENT_OPTS, DRAWER_POSITION_OPTS[position], p),
25
+ )
24
26
 
25
- const {
26
- id,
27
- class: klass = '',
28
- style: styleString = '',
29
- backdropClass = '',
30
- portal = true,
31
- placement,
32
- backdrop,
33
- blurBackdrop,
27
+ const id = $derived(opts.id)
28
+ const klass = $derived(opts.class ?? '')
29
+ const styleString = $derived(opts.style ?? '')
30
+ const backdropClass = $derived(opts.backdropClass ?? '')
31
+ const portal = $derived(opts.portal ?? true)
32
+ const placement = $derived(opts.placement)
33
+ const backdrop = $derived(opts.backdrop)
34
+ const blurBackdrop = $derived(opts.blurBackdrop)
34
35
 
35
- // Slots
36
- ...rest
37
- } = opts
36
+ const rest = $derived.by(() => {
37
+ const {
38
+ id,
39
+ class: klass = '',
40
+ style: styleString = '',
41
+ backdropClass = '',
42
+ portal = true,
43
+ placement,
44
+ backdrop,
45
+ blurBackdrop,
46
+ ...rest
47
+ } = opts
48
+ return rest
49
+ })
38
50
 
39
- const { picked: transitionOpts } = splitObject(rest, TRANSITION_OPT_KEYS)
51
+ const transitionSplit = $derived(splitObject(rest, TRANSITION_OPT_KEYS))
52
+ const transitionOpts = $derived(transitionSplit.picked)
40
53
 
41
- const TBLR = getTBLRValues({ placement, position })
42
- const style = toStyleString(TBLR) + styleString
54
+ const TBLR = $derived(getTBLRValues({ placement, position }))
55
+ const style = $derived(toStyleString(TBLR) + styleString)
43
56
 
44
57
  let d = $derived(getDisclosure(id))
45
58
  let show = $derived(d?.state.show)
@@ -79,7 +92,7 @@
79
92
 
80
93
  {#if show}
81
94
  {#if position === 'fixed'}
82
- {#if opts.portal}
95
+ {#if portal}
83
96
  <Portal>{@render drawerBackdrop()}</Portal>
84
97
  {:else}
85
98
  {@render drawerBackdrop()}
@@ -9,17 +9,25 @@
9
9
  import { MODAL_CONTENT_OPTS } from './modal.js'
10
10
 
11
11
  let { ref = $bindable(null), ...p } = $props()
12
- const opts = mergeOpts(MODAL_CONTENT_OPTS, p)
12
+ const opts = $derived(mergeOpts(MODAL_CONTENT_OPTS, p))
13
13
 
14
- const {
15
- class: klass = '',
16
- backdrop,
17
- backdropClass,
18
- blurBackdrop,
19
- ...rest
20
- } = opts
14
+ const klass = $derived(opts.class ?? '')
15
+ const backdrop = $derived(opts.backdrop)
16
+ const backdropClass = $derived(opts.backdropClass)
17
+ const blurBackdrop = $derived(opts.blurBackdrop)
18
+ const rest = $derived.by(() => {
19
+ const {
20
+ class: klass = '',
21
+ backdrop,
22
+ backdropClass,
23
+ blurBackdrop,
24
+ ...rest
25
+ } = opts
26
+ return rest
27
+ })
21
28
 
22
- const { picked: transitionOpts } = splitObject(rest, TRANSITION_OPT_KEYS)
29
+ const transitionSplit = $derived(splitObject(rest, TRANSITION_OPT_KEYS))
30
+ const transitionOpts = $derived(transitionSplit.picked)
23
31
  </script>
24
32
 
25
33
  {#snippet modalBackdrop()}
@@ -18,43 +18,55 @@
18
18
 
19
19
  let { ref = $bindable(null), ...p } = $props()
20
20
 
21
- const {
22
- class: klass,
23
- id,
24
- role = 'dialog',
25
- 'aria-label': ariaLabel,
26
- 'aria-labelledBy': ariaLabelledBy,
27
- 'aria-describedby': ariaDescribedBy,
28
- componentName = 'DisclosureContent',
29
- portal = true,
30
- scrollToAnchor = false,
31
-
32
- // Slots
33
- children,
34
-
35
- // Event handlers are spread directly into ...rest
36
- // Custom events are onopen and onclose
37
- ...restProps
38
- } = p
21
+ const klass = $derived(p.class)
22
+ const id = $derived(p.id)
23
+ const role = $derived(p.role ?? 'dialog')
24
+ const ariaLabel = $derived(p['aria-label'])
25
+ const ariaLabelledBy = $derived(p['aria-labelledBy'])
26
+ const ariaDescribedBy = $derived(p['aria-describedby'])
27
+ const componentName = $derived(p.componentName ?? 'DisclosureContent')
28
+ const portal = $derived(p.portal ?? true)
29
+ const scrollToAnchor = $derived(p.scrollToAnchor ?? false)
30
+ const children = $derived(p.children)
31
+ const restProps = $derived.by(() => {
32
+ const {
33
+ class: klass,
34
+ id,
35
+ role = 'dialog',
36
+ 'aria-label': ariaLabel,
37
+ 'aria-labelledBy': ariaLabelledBy,
38
+ 'aria-describedby': ariaDescribedBy,
39
+ componentName = 'DisclosureContent',
40
+ portal = true,
41
+ scrollToAnchor = false,
42
+ children,
43
+ ...restProps
44
+ } = p
45
+ return restProps
46
+ })
39
47
 
40
- const { picked: disclosureContentOpts, omitted: rest } = splitObject(
41
- restProps,
42
- DISCLOSURE_CONTENT_OPT_KEYS,
48
+ const disclosureSplit = $derived(
49
+ splitObject(restProps, DISCLOSURE_CONTENT_OPT_KEYS),
43
50
  )
51
+ const disclosureContentOpts = $derived(disclosureSplit.picked)
52
+ const rest = $derived(disclosureSplit.omitted)
44
53
 
45
- const { picked: transitionOpts, omitted: remaining } = splitObject(
46
- rest,
47
- TRANSITION_OPT_KEYS,
54
+ const transitionSplit = $derived(
55
+ splitObject(rest, TRANSITION_OPT_KEYS),
48
56
  )
57
+ const transitionOpts = $derived(transitionSplit.picked)
58
+ const remaining = $derived(transitionSplit.omitted)
49
59
 
50
- if (!id) throw new Error(`${componentName} requires an id`)
60
+ $effect(() => {
61
+ if (!id) throw new Error(`${componentName} requires an id`)
51
62
 
52
- // Accessible name warning
53
- if (role === 'dialog' && !hasAccessibleName(ariaLabel, ariaLabelledBy)) {
54
- console.warn(
55
- `DrawerContent (with id: ${id}) is a dialog and should have an accessible name. Please create one with aria-label or aria-labelledby.`,
56
- )
57
- }
63
+ // Accessible name warning
64
+ if (role === 'dialog' && !hasAccessibleName(ariaLabel, ariaLabelledBy)) {
65
+ console.warn(
66
+ `DrawerContent (with id: ${id}) is a dialog and should have an accessible name. Please create one with aria-label or aria-labelledby.`,
67
+ )
68
+ }
69
+ })
58
70
 
59
71
  let d = $derived(getDisclosure(id))
60
72
  let show = $derived(d?.state.show)
@@ -8,26 +8,37 @@
8
8
 
9
9
  let { show = $bindable(false), ...p } = $props()
10
10
 
11
- const {
12
- class: klass = '',
13
- componentName = 'DisclosureTrigger',
14
- icon = 'tabler:menu',
15
- iconClass,
16
- 'aria-haspopup': ariaHasPopup = 'dialog',
17
- target,
11
+ const klass = $derived(p.class ?? '')
12
+ const componentName = $derived(p.componentName ?? 'DisclosureTrigger')
13
+ const icon = $derived(p.icon ?? 'tabler:menu')
14
+ const iconClass = $derived(p.iconClass)
15
+ const ariaHasPopup = $derived(p['aria-haspopup'] ?? 'dialog')
16
+ const target = $derived(p.target)
17
+ const children = $derived(p.children)
18
+ const restProps = $derived.by(() => {
19
+ const {
20
+ class: klass = '',
21
+ componentName = 'DisclosureTrigger',
22
+ icon = 'tabler:menu',
23
+ iconClass,
24
+ 'aria-haspopup': ariaHasPopup = 'dialog',
25
+ target,
26
+ children,
27
+ ...restProps
28
+ } = p
29
+ return restProps
30
+ })
18
31
 
19
- // Slots
20
- children,
21
- ...restProps
22
- } = p
23
-
24
- const { picked: triggerOpts, omitted: rest } = splitObject(
25
- restProps,
26
- DISCLOSURE_TRIGGER_OPT_KEYS,
32
+ const triggerSplit = $derived(
33
+ splitObject(restProps, DISCLOSURE_TRIGGER_OPT_KEYS),
27
34
  )
35
+ const triggerOpts = $derived(triggerSplit.picked)
36
+ const rest = $derived(triggerSplit.omitted)
28
37
 
29
- if (!target)
30
- throw new Error(`${componentName} must contain a target property`)
38
+ $effect(() => {
39
+ if (!target)
40
+ throw new Error(`${componentName} must contain a target property`)
41
+ })
31
42
 
32
43
  // TODO: Test creating an IconSnippet to render the icon vs contents
33
44
  // <script module> currently breaks when prettier is enabled. So, ¯\_(ツ)_/¯ if we can ever do that.
@@ -1,10 +1,12 @@
1
1
  <script>
2
2
  import { flattenArrayFields, formDataToObject } from '@splendidlabz/utils'
3
- import { sanitize as sanitizeFn } from '@splendidlabz/utils/dom'
3
+ import { randomString, sanitize as sanitizeFn } from '@splendidlabz/utils/dom'
4
+ import Status from '../Status.svelte'
4
5
  import Honeypot from './Honeypot.svelte'
5
6
 
6
7
  let {
7
8
  ref = $bindable(null),
9
+ id = $bindable(randomString()),
8
10
  class: klass = '',
9
11
  method = 'post',
10
12
  action = null,
@@ -14,6 +16,8 @@
14
16
  honeypotDuration = 2000,
15
17
  onsubmit = null,
16
18
  children,
19
+ status,
20
+ statusText,
17
21
  ...rest
18
22
  } = $props()
19
23
 
@@ -49,8 +53,9 @@
49
53
  </script>
50
54
 
51
55
  <form
52
- {...rest}
53
56
  bind:this={ref}
57
+ {id}
58
+ {...rest}
54
59
  class="form {klass}"
55
60
  {action}
56
61
  {method}
@@ -64,3 +69,4 @@
64
69
  {/if}
65
70
  {@render children?.()}
66
71
  </form>
72
+ <Status for={id} {status} {statusText} />
@@ -1,8 +1,8 @@
1
1
  <script>
2
2
  import { randomString } from '@splendidlabz/utils/dom'
3
3
  import { useActions } from '../../actions/use-actions'
4
- import Markdown from '../Markdown/Markdown.svelte'
5
4
  import { init } from '../../utils'
5
+ import Markdown from '../Markdown/Markdown.svelte'
6
6
 
7
7
  let {
8
8
  value = $bindable(''),
@@ -37,7 +37,7 @@
37
37
 
38
38
  // IDs for aria-describedby
39
39
  const hintId = $derived(hint ? id + '-hint' : '')
40
- const errorId = $derived(error ? id + '-error' : '')
40
+ const errorId = $derived(id + '-error')
41
41
  const describedBy = $derived(`${hintId} ${errorId}`.trim() || null)
42
42
 
43
43
  // ========================================
@@ -47,7 +47,8 @@
47
47
  const SUPPORTED_TYPES = ['text', 'email', 'password', 'search', 'url', 'tel']
48
48
  init(() => {
49
49
  if (!name) throw new Error('TextInput requires a name')
50
- if (!SUPPORTED_TYPES.includes(type)) throw new Error(`Invalid type: ${type}`)
50
+ if (!SUPPORTED_TYPES.includes(type))
51
+ throw new Error(`Invalid type: ${type}`)
51
52
  })
52
53
  </script>
53
54
 
@@ -62,6 +63,7 @@
62
63
  {...{ type }}
63
64
  aria-describedby={describedBy}
64
65
  aria-invalid={error ? 'true' : null}
66
+ aria-label={!labelVisible && label ? label : null}
65
67
  {disabled}
66
68
  {readonly}
67
69
  bind:value
@@ -75,7 +77,6 @@
75
77
  class="input-container text-input text-field {klass}"
76
78
  class:disabled
77
79
  class:readonly
78
- aria-label={(!labelVisible && label) || null}
79
80
  >
80
81
  {#if label && labelVisible}
81
82
  <label class="label input-meta {labelClass}" for={id}>
@@ -87,11 +88,17 @@
87
88
  <Markdown content={hint} inline />
88
89
  </div>
89
90
  {/if}
90
- {#if error}
91
- <output id={errorId} class="error input-meta {errorClass}" for={id}>
91
+ <output
92
+ id={errorId}
93
+ class="error input-meta {errorClass}"
94
+ class:sr-only={!error}
95
+ for={id}
96
+ role="alert"
97
+ >
98
+ {#if error}
92
99
  <Markdown content={error} inline />
93
- </output>
94
- {/if}
100
+ {/if}
101
+ </output>
95
102
 
96
103
  {#if before || after}
97
104
  <div class="input-group {inputGroupClass}">
@@ -33,7 +33,7 @@
33
33
 
34
34
  // IDs for aria-describedby
35
35
  const hintId = $derived(hint ? id + '-hint' : '')
36
- const errorId = $derived(error ? id + '-error' : '')
36
+ const errorId = $derived(id + '-error')
37
37
  const describedBy = $derived(`${hintId} ${errorId}`.trim() || null)
38
38
 
39
39
  // ========================================
@@ -84,11 +84,15 @@
84
84
  {#if hint}
85
85
  <div id={hintId} class="hint input-meta {hintClass}">{hint}</div>
86
86
  {/if}
87
- {#if error}
88
- <output id={errorId} class="error input-meta {errorClass}" for={id}
89
- >{error}</output
90
- >
91
- {/if}
87
+ <output
88
+ id={errorId}
89
+ for={id}
90
+ class="error input-meta {errorClass}"
91
+ class:sr-only={!error}
92
+ role="alert"
93
+ >
94
+ {#if error}{error}{/if}
95
+ </output>
92
96
 
93
97
  {#if before || after}
94
98
  <div class="input-group {inputGroupClass}">
@@ -16,9 +16,9 @@
16
16
  ...rest
17
17
  } = $props()
18
18
 
19
- const image = resolveImage(src)
20
- const isGif = image.format === 'gif' || image.src?.includes('.gif')
21
- const usePicture = picture && !isGif
19
+ const image = $derived(resolveImage(src))
20
+ const isGif = $derived(image.format === 'gif' || image.src?.includes('.gif'))
21
+ const usePicture = $derived(picture && !isGif)
22
22
  </script>
23
23
 
24
24
  {#snippet img()}
@@ -15,8 +15,12 @@
15
15
  ...p
16
16
  } = $props()
17
17
 
18
- const { p: figureProps, o: p1 } = splitObject(p, ['caption', 'captionClass'])
19
- const { p: pictureProps, o: rest } = splitObject(p1, ['pictureClass'])
18
+ const figureSplit = $derived(splitObject(p, ['caption', 'captionClass']))
19
+ const figureProps = $derived(figureSplit.p)
20
+ const p1 = $derived(figureSplit.o)
21
+ const pictureSplit = $derived(splitObject(p1, ['pictureClass']))
22
+ const pictureProps = $derived(pictureSplit.p)
23
+ const rest = $derived(pictureSplit.o)
20
24
  </script>
21
25
 
22
26
  {#snippet img()}
@@ -16,11 +16,12 @@
16
16
  ...rest
17
17
  } = $props()
18
18
 
19
- if (!sources) throw new Error('Missing prop: sources')
20
-
21
- const fallback = sources[fallbackIndex] ?? sources[sources.length - 1]
22
- const fallbackSrc = fallback.image.src
23
- const fallbackAttrs = fallback.image.attributes
19
+ const fallback = $derived.by(() => {
20
+ if (!sources) throw new Error('Missing prop: sources')
21
+ return sources[fallbackIndex] ?? sources[sources.length - 1]
22
+ })
23
+ const fallbackSrc = $derived(fallback.image.src)
24
+ const fallbackAttrs = $derived(fallback.image.attributes)
24
25
  </script>
25
26
 
26
27
  {#if figure}
@@ -1,5 +1,17 @@
1
1
  <script>
2
- let { status = $bindable('info'), class: klass = '', children, ...rest } = $props()
2
+ let {
3
+ class: klass = '',
4
+ status = $bindable('info'),
5
+ statusText = '',
6
+ children,
7
+ ...rest
8
+ } = $props()
9
+
10
+ const statusClasses = {
11
+ info: 'status-info',
12
+ success: 'status-success',
13
+ error: 'status-error',
14
+ }
3
15
 
4
16
  function getStatusString(status) {
5
17
  if (typeof status === 'string') return status
@@ -9,17 +21,23 @@
9
21
  return 'info'
10
22
  }
11
23
 
12
- const statusClasses = {
13
- info: 'status-info',
14
- success: 'status-success',
15
- error: 'status-error',
24
+ function getStatusClass(status) {
25
+ return statusClasses[getStatusString(status)]
16
26
  }
17
27
 
18
- let statusClass = $derived.by(_ => statusClasses[getStatusString(status)])
28
+ let statusClass = $derived(getStatusClass(status))
29
+ let role = $derived(getStatusString(status) === 'error' ? 'alert' : 'status')
19
30
  </script>
20
31
 
21
- <div {...rest} class="status {statusClass} {klass}">
22
- {#if children}
23
- {@render children()}
32
+ <output
33
+ {...rest}
34
+ class="status {statusClass} {klass}"
35
+ class:sr-only={!statusText && !children}
36
+ {role}
37
+ >
38
+ {#if statusText}
39
+ {statusText}
40
+ {:else}
41
+ {@render children?.()}
24
42
  {/if}
25
- </div>
43
+ </output>
@@ -0,0 +1,97 @@
1
+ <script>
2
+ import { randomString } from '@splendidlabz/utils/dom'
3
+ import { setContext } from 'svelte'
4
+ import Accordion from '../Accordion/Accordion.svelte'
5
+ import Tab from '../Tabs/Tab.svelte'
6
+ import Tablist from '../Tabs/Tablist.svelte'
7
+ import Tabpanel from '../Tabs/Tabpanel.svelte'
8
+ import Tabpanels from '../Tabs/Tabpanels.svelte'
9
+ import { getTab, selectTab } from '../Tabs/tabs.svelte.js'
10
+
11
+ const {
12
+ class: klass = '',
13
+ breakpoint = 768,
14
+ activeIndex: activeIndexProp = 0,
15
+ accordion = {},
16
+ tablist = {},
17
+ tab = {},
18
+ tabpanels = {},
19
+ tabpanel = {},
20
+ children,
21
+ ...rest
22
+ } = $props()
23
+
24
+ const tabcordionId = randomString()
25
+ const tabpanelsId = randomString()
26
+ function getActiveIndexProp() {
27
+ return activeIndexProp
28
+ }
29
+
30
+ let activeIndex = $state(getActiveIndexProp())
31
+ const items = $state([])
32
+
33
+ setContext('tabcordion', {
34
+ register(item) {
35
+ items.push(item)
36
+ return items.length - 1
37
+ },
38
+ })
39
+
40
+ $effect(() => {
41
+ activeIndex = activeIndexProp
42
+ })
43
+
44
+ $effect(() => {
45
+ const tabStore = getTab(tabpanelsId)
46
+ if (!tabStore) return
47
+ selectTab(tabStore, activeIndex, { shouldFocusOnTab: false })
48
+ })
49
+
50
+ function onTabChange({ Tab: tabStore }) {
51
+ activeIndex = tabStore.state.activeTabIndex
52
+ }
53
+ </script>
54
+
55
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
56
+ {@html `
57
+ <style>
58
+ #${tabcordionId} .tabs { display: none; }
59
+
60
+ @media (min-width: ${breakpoint}px) {
61
+ #${tabcordionId} .accordion-stack { display: none; }
62
+ #${tabcordionId} .tabs { display: block; }
63
+ }
64
+ </style>
65
+ `}
66
+
67
+ <!-- Render children purely for their registration side effect; they emit no DOM -->
68
+ {@render children?.()}
69
+
70
+ <div id={tabpanelsId} {...rest} class="tabcordion {klass}">
71
+ <div class="accordion-stack">
72
+ {#each items as item, i (i)}
73
+ <Accordion
74
+ {...accordion}
75
+ content={item.content}
76
+ onToggle={() => (activeIndex = i)}
77
+ open={i === activeIndex}
78
+ title={item.title}
79
+ />
80
+ {/each}
81
+ </div>
82
+
83
+ <div class="tabs">
84
+ <Tablist {...tablist} {onTabChange} target={tabpanelsId}>
85
+ {#each items as item, i (i)}
86
+ <Tab {...tab} active={i === activeIndex}>{@render item.title()}</Tab>
87
+ {/each}
88
+ </Tablist>
89
+ <Tabpanels {...tabpanels} id={tabpanelsId}>
90
+ {#each items as item, i (i)}
91
+ <Tabpanel {...tabpanel} active={i === activeIndex}>
92
+ {@render item.content()}
93
+ </Tabpanel>
94
+ {/each}
95
+ </Tabpanels>
96
+ </div>
97
+ </div>
@@ -0,0 +1,14 @@
1
+ <script>
2
+ import { getContext } from 'svelte'
3
+
4
+ const { title, content } = $props()
5
+ const ctx = getContext('tabcordion')
6
+ ctx?.register({
7
+ get title() {
8
+ return title
9
+ },
10
+ get content() {
11
+ return content
12
+ },
13
+ })
14
+ </script>
@@ -0,0 +1,4 @@
1
+ import Tabcordion from './Tabcordion.svelte'
2
+ import TabcordionItem from './TabcordionItem.svelte'
3
+
4
+ export { Tabcordion, TabcordionItem }
@@ -1,9 +1,22 @@
1
1
  <script>
2
- const { class: klass = '', active, children, ...rest } = $props()
2
+ const {
3
+ class: klass = '',
4
+ title,
5
+ titleClass,
6
+ active,
7
+ children,
8
+ ...rest
9
+ } = $props()
3
10
  </script>
4
11
 
5
- <button {...rest} class="tab {klass}" aria-selected={active} role="tab">
6
- {#if children}
7
- {@render children()}
12
+ <button
13
+ {...rest}
14
+ class="tab {title && 'vertical'} {klass}"
15
+ aria-selected={active}
16
+ role="tab"
17
+ >
18
+ {#if title}
19
+ <span class="tab-title {titleClass}">{title}</span>
8
20
  {/if}
21
+ {@render children?.()}
9
22
  </button>
@@ -26,16 +26,13 @@
26
26
  function getTablistClasses(tab) {
27
27
  if (!tab) return ''
28
28
  const { placement } = tab.state
29
+ if (placement !== 'top') return ''
29
30
 
30
- const scrollableClass = [
31
- placement === 'top' && scrollable && 'scrollable-horizontal',
32
- placement === 'top' &&
33
- preferHorizontalScroll &&
34
- 'scrollable-preferHorizontalScroll',
35
- placement === 'top' && preserveOutlines && 'preserve-outlines',
36
- ].join(' ')
37
-
38
- return scrollableClass
31
+ const classes = []
32
+ if (scrollable) classes.push('scrollable-horizontal')
33
+ if (preferHorizontalScroll) classes.push('scrollable-preferHorizontalScroll')
34
+ if (preserveOutlines) classes.push('preserve-outlines')
35
+ return classes.join(' ')
39
36
  }
40
37
  </script>
41
38
 
@@ -23,17 +23,16 @@ describe('tabs.css --placement custom property', () => {
23
23
  expect(match[0]).toContain('--placement: top')
24
24
  })
25
25
 
26
- test('.tablist-left sets --placement: left', () => {
27
- // Should appear somewhere in the file — could be @layer or @utility
28
- const leftBlock = css.match(/\.tablist-left\s*\{[^}]*\}/)
29
- expect(leftBlock).toBeTruthy()
30
- expect(leftBlock[0]).toContain('--placement: left')
26
+ test('tablist-left sets --placement: left', () => {
27
+ const match = css.match(/@utility tablist-left\s*\{[\s\S]*?\n\}/)
28
+ expect(match).toBeTruthy()
29
+ expect(match[0]).toContain('--placement: left')
31
30
  })
32
31
 
33
- test('.tablist-right sets --placement: right', () => {
34
- const rightBlock = css.match(/\.tablist-right\s*\{[^}]*\}/)
35
- expect(rightBlock).toBeTruthy()
36
- expect(rightBlock[0]).toContain('--placement: right')
32
+ test('tablist-right sets --placement: right', () => {
33
+ const match = css.match(/@utility tablist-right\s*\{[\s\S]*?\n\}/)
34
+ expect(match).toBeTruthy()
35
+ expect(match[0]).toContain('--placement: right')
37
36
  })
38
37
 
39
38
  test('all three placements are covered', () => {
@@ -25,6 +25,7 @@ export * from './Populate/index.js'
25
25
  export * from './Switcheroo/index.js'
26
26
  export * from './Table/index.js'
27
27
  export * from './Tabs/index.js'
28
+ export * from './Tabcordion/index.js'
28
29
 
29
30
  // TO REMOVE AFTER SHIFTING TO ASTRO
30
31
  export * from './Textwall/index.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splendidlabz/svelte",
3
3
  "type": "module",
4
- "version": "4.9.0",
4
+ "version": "4.11.0",
5
5
  "sideEffects": false,
6
6
  "homepage": "https://splendidlabz.com/docs/svelte",
7
7
  "scripts": {
@@ -23,22 +23,22 @@
23
23
  "./utils": "./utils/index.js"
24
24
  },
25
25
  "dependencies": {
26
- "@floating-ui/dom": "^1.6.13",
27
- "@iconify/svelte": "^4.2.0",
26
+ "@floating-ui/dom": "^1.7.6",
27
+ "@iconify/svelte": "^5.2.1",
28
28
  "@splendidlabz/styles": "*",
29
29
  "@splendidlabz/utils": "*",
30
30
  "autosuggest-highlight": "^3.3.4",
31
- "lodash-es": "^4.17.21",
32
- "node-html-parser": "^7.0.1"
31
+ "lodash-es": "^4.18.1",
32
+ "node-html-parser": "^7.1.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@splendidlabz/eslint-config": "2.1.3",
36
- "@sveltejs/vite-plugin-svelte": "^6.2.4",
35
+ "@splendidlabz/eslint-config": "2.1.4",
36
+ "@sveltejs/vite-plugin-svelte": "^7.0.0",
37
37
  "@testing-library/svelte": "^5.3.1",
38
- "@tsconfig/svelte": "^5.0.4",
39
- "happy-dom": "^20.8.8",
40
- "svelte": "^5.25.6",
41
- "svelte-check": "^4.2.1",
42
- "vitest": "^3.1.1"
38
+ "@tsconfig/svelte": "^5.0.8",
39
+ "happy-dom": "^20.9.0",
40
+ "svelte": "^5.55.4",
41
+ "svelte-check": "^4.4.6",
42
+ "vitest": "^4.1.4"
43
43
  }
44
44
  }
package/svelte.config.js CHANGED
@@ -3,7 +3,6 @@ export default {
3
3
  runes: true,
4
4
  },
5
5
  compilerOptions: {
6
- enableSourcemap: true,
7
6
  cssHash: ({ hash, css, name, filename }) => `${name}-${hash(css)}`,
8
7
  },
9
8
  onwarn: (warning, handler) => {
@@ -1,37 +0,0 @@
1
- <script>
2
- import { Resizer } from '../Resizer/index.js'
3
-
4
- let klass = ''
5
- export { klass as class }
6
- export let frameContentClass = ''
7
- export let contentClass = ''
8
- export let options = {}
9
- export let elem = null
10
- </script>
11
-
12
- <div class="BrowserFrame {klass}" bind:this={elem}>
13
- <div class="Vertical gap-0">
14
- <div class="FrameHeader">
15
- <div class="FrameHeaderDots">
16
- <div class="FrameHeaderDot"></div>
17
- <div class="FrameHeaderDot"></div>
18
- <div class="FrameHeaderDot"></div>
19
- </div>
20
- <div class="FrameHeaderTabs">
21
- <slot name="tablist" />
22
- </div>
23
- </div>
24
- <div class="FrameContent Stack {frameContentClass}">
25
- <div class="Background">
26
- <slot name="background" />
27
- </div>
28
- <div class="Content Vertical {contentClass}">
29
- <slot name="tabpanels" />
30
- <slot />
31
- </div>
32
- {#if options.resize}
33
- <Resizer options={{ target: '.BrowserFrame', ...options.resize }} />
34
- {/if}
35
- </div>
36
- </div>
37
- </div>