@splendidlabz/svelte 4.9.0 → 4.10.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,32 @@
1
1
  # @splendidlabz/svelte
2
2
 
3
+ ## 4.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 13fdcd9: feat(Tabcordion): refactor to context-based API with TabcordionItem; simplify Accordion
8
+
9
+ **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`.
10
+
11
+ ```svelte
12
+ <Tabcordion>
13
+ <TabcordionItem title="Tab 1">Content for tab 1</TabcordionItem>
14
+ <TabcordionItem title="Tab 2">Content for tab 2</TabcordionItem>
15
+ </Tabcordion>
16
+ ```
17
+
18
+ **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.
19
+
20
+ ### Patch Changes
21
+
22
+ - 5fdfc45: Updated `@iconify/svelte` to `5.2.1` for Svelte 5 compatibility.
23
+ - 58f768f: Removed `BrowserWithTabs` component. Added `title` and `titleClass` props to `Tab` for vertical tab layouts. Fixed `Tablist` class generation for non-top placements.
24
+ - Updated dependencies [c054af3]
25
+ - Updated dependencies [92d1320]
26
+ - Updated dependencies [60ce1ac]
27
+ - @splendidlabz/utils@1.11.5
28
+ - @splendidlabz/styles@4.8.0
29
+
3
30
  ## 4.9.0
4
31
 
5
32
  ### 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 }
@@ -0,0 +1,89 @@
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
+ let activeIndex = $state(activeIndexProp)
27
+ const items = $state([])
28
+
29
+ setContext('tabcordion', {
30
+ register(item) {
31
+ items.push(item)
32
+ return items.length - 1
33
+ },
34
+ })
35
+
36
+ $effect(() => {
37
+ const tabStore = getTab(tabpanelsId)
38
+ if (!tabStore) return
39
+ selectTab(tabStore, activeIndex, { shouldFocusOnTab: false })
40
+ })
41
+
42
+ function onTabChange({ Tab: tabStore }) {
43
+ activeIndex = tabStore.state.activeTabIndex
44
+ }
45
+ </script>
46
+
47
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
48
+ {@html `
49
+ <style>
50
+ #${tabcordionId} .tabs { display: none; }
51
+
52
+ @media (min-width: ${breakpoint}px) {
53
+ #${tabcordionId} .accordion-stack { display: none; }
54
+ #${tabcordionId} .tabs { display: block; }
55
+ }
56
+ </style>
57
+ `}
58
+
59
+ <!-- Render children purely for their registration side effect; they emit no DOM -->
60
+ {@render children?.()}
61
+
62
+ <div id={tabpanelsId} {...rest} class="tabcordion {klass}">
63
+ <div class="accordion-stack">
64
+ {#each items as item, i (i)}
65
+ <Accordion
66
+ {...accordion}
67
+ content={item.content}
68
+ onToggle={() => (activeIndex = i)}
69
+ open={i === activeIndex}
70
+ title={item.title}
71
+ />
72
+ {/each}
73
+ </div>
74
+
75
+ <div class="tabs">
76
+ <Tablist {...tablist} {onTabChange} target={tabpanelsId}>
77
+ {#each items as item, i (i)}
78
+ <Tab {...tab} active={i === activeIndex}>{@render item.title()}</Tab>
79
+ {/each}
80
+ </Tablist>
81
+ <Tabpanels {...tabpanels} id={tabpanelsId}>
82
+ {#each items as item, i (i)}
83
+ <Tabpanel {...tabpanel} active={i === activeIndex}>
84
+ {@render item.content()}
85
+ </Tabpanel>
86
+ {/each}
87
+ </Tabpanels>
88
+ </div>
89
+ </div>
@@ -0,0 +1,7 @@
1
+ <script>
2
+ import { getContext } from 'svelte'
3
+
4
+ const { title, content } = $props()
5
+ const ctx = getContext('tabcordion')
6
+ ctx?.register({ title, content })
7
+ </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.10.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
  }
@@ -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>