@splendidlabz/svelte 4.1.0 → 4.3.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/components/Breadcrumbs/Breadcrumbs.svelte +19 -20
  3. package/components/Breadcrumbs/CrumbCustom.svelte +5 -6
  4. package/components/Codepen/Codepen.svelte +11 -14
  5. package/components/Codepen/index.js +0 -1
  6. package/components/Disclosure/Disclosure/DisclosureContent.svelte +2 -2
  7. package/components/Disclosure/Drawer/DrawerCloseButton.svelte +2 -2
  8. package/components/Disclosure/DrawerNew/{DrawerClose.svelte → DrawerCloseButton.svelte} +8 -4
  9. package/components/Disclosure/DrawerNew/{Drawer.svelte → DrawerContent.svelte} +10 -8
  10. package/components/Disclosure/DrawerNew/index.js +8 -3
  11. package/components/Disclosure/ModalNew/{Modal.svelte → ModalContent.svelte} +23 -7
  12. package/components/Disclosure/ModalNew/index.js +2 -2
  13. package/components/Disclosure/PopoverNew/PopoverContent.svelte +119 -0
  14. package/components/Disclosure/PopoverNew/PopoverTrigger.svelte +15 -5
  15. package/components/Disclosure/PopoverNew/floating.js +3 -0
  16. package/components/Disclosure/PopoverNew/index.js +2 -1
  17. package/components/Form/Form.svelte +2 -4
  18. package/components/Form/Honeypot.svelte +1 -23
  19. package/components/Form/index.js +0 -1
  20. package/components/LocalStorage/LocalStoragePush.svelte +22 -0
  21. package/components/LocalStorage/LocalStorageRemove.svelte +15 -0
  22. package/components/LocalStorage/index.js +4 -0
  23. package/components/SVG/SVG.svelte +49 -0
  24. package/components/SVG/index.js +2 -0
  25. package/components/SVG/parser.js +133 -0
  26. package/components/Status.svelte +8 -1
  27. package/components/Tabs/Tablist.svelte +2 -0
  28. package/components/Tabs/Tabpanels.svelte +1 -0
  29. package/components/Vimeo.svelte +3 -3
  30. package/components/Youtube.svelte +18 -7
  31. package/index.js +8 -8
  32. package/package.json +3 -3
  33. package/components/Codepen/Codepen.astro +0 -29
  34. package/components/Form/CustomSelect.svelte +0 -205
  35. package/components/PushToLocalStorage.svelte +0 -30
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @splendidlabz/svelte
2
2
 
3
+ ## 4.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Several updates
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @splendidlabz/utils@1.8.0
13
+ - @splendidlabz/styles@4.2.1
14
+
15
+ ## 4.2.0
16
+
17
+ ### Minor Changes
18
+
19
+ - Many changes! Woo
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [2c149fc]
24
+ - Updated dependencies
25
+ - @splendidlabz/utils@1.7.0
26
+ - @splendidlabz/styles@4.2.0
27
+
3
28
  ## 4.1.0
4
29
 
5
30
  ### Minor Changes
@@ -256,6 +281,7 @@
256
281
  ### Patch Changes
257
282
 
258
283
  - a9128f4: Major work on Forms and Form element controls in this patch.
284
+
259
285
  - Ensure `Form` works with normal `POST` request when `onSubmit` is not defined. Also included `felte` library for form validation in the future.
260
286
  - `TextInput` must now take in either a `label` or `placeholder`.
261
287
  - Add disabled and readonly styles to TextInput and its label
@@ -265,6 +291,7 @@
265
291
  - Add disabled and readonly styles to checkbox and its label
266
292
 
267
293
  There's some work on the internal `disclosure` action and stores as well.
294
+
268
295
  - Change default `focusTarget` to `null` to facilitate usage in other components.
269
296
  - Remove the need to pass in default `disclosure` options. This is now handled in the disclosure store automatically.
270
297
 
@@ -1,19 +1,18 @@
1
1
  <script>
2
2
  import { onMount } from 'svelte'
3
3
  import { mergeOpts } from '../../utils'
4
- import { Snippet } from '../_Shared/Snippet.svelte'
4
+ import Icon from '../Icon/Icon.svelte'
5
5
  import Crumb from './Crumb.svelte'
6
6
 
7
- const { ...p } = $props()
7
+ let { pathname = $bindable(''), ...p } = $props()
8
8
 
9
9
  const {
10
10
  class: klass = '',
11
- pathname = '',
12
11
 
13
12
  // Slots
13
+ children,
14
14
  before,
15
15
  after,
16
- children,
17
16
  ...rest
18
17
  } = p
19
18
 
@@ -26,18 +25,18 @@
26
25
  }
27
26
 
28
27
  const opts = mergeOpts(defaultOptions, rest)
29
-
30
28
  const { startingDepth, ariaCurrentType, labelCase } = opts
31
- const trailingSlash = hasTrailingSlash(pathname)
32
- let crumbs = $state(constructCrumbs(getURLArray(pathname), { trailingSlash }))
29
+
30
+ let trailingSlash = $derived(hasTrailingSlash(pathname))
31
+ let crumbs = $derived(
32
+ constructCrumbs(getURLArray(pathname), { trailingSlash }).slice(
33
+ startingDepth,
34
+ ),
35
+ )
33
36
 
34
37
  onMount(_ => {
35
38
  if (typeof window === 'undefined') return
36
- if (!pathname) {
37
- const { pathname } = window.location
38
- const trailingSlash = hasTrailingSlash(pathname)
39
- crumbs = constructCrumbs(getURLArray(pathname), { trailingSlash })
40
- }
39
+ if (!pathname) pathname = window.location.pathname
41
40
  })
42
41
 
43
42
  // Supporting functions
@@ -46,14 +45,9 @@
46
45
  }
47
46
 
48
47
  function getURLArray(pathname) {
49
- return pathname
50
- .split('/')
51
- .filter(str => str)
52
- .slice(startingDepth)
48
+ return pathname.split('/').filter(str => str)
53
49
  }
54
50
 
55
- // TODO: Breadcrumbs URL currently return a wrong address.
56
- // This needs to be fixed before breadcrumbs are usable.
57
51
  function constructCrumbs(urlArray, { trailingSlash = true } = {}) {
58
52
  return urlArray.map((crumb, index) => {
59
53
  return {
@@ -73,7 +67,12 @@
73
67
  <nav class={`breadcrumbs ${klass}`} aria-label="Breadcrumbs">
74
68
  <ul>
75
69
  {#if before}
76
- {@render before()}
70
+ <li class="crumb">
71
+ {@render before?.()}
72
+ <span class="crumb-divider">
73
+ <Icon icon={opts.divider} />
74
+ </span>
75
+ </li>
77
76
  {/if}
78
77
 
79
78
  {#if children}
@@ -87,6 +86,6 @@
87
86
  />
88
87
  {/each}
89
88
  {/if}
90
- {@render Snippet.block(after)}
89
+ {@render after?.()}
91
90
  </ul>
92
91
  </nav>
@@ -5,14 +5,13 @@
5
5
  class: klass = '',
6
6
  divider = 'tabler:chevron-right',
7
7
  children,
8
+ ...rest
8
9
  } = $props()
9
10
  </script>
10
11
 
11
- <li class="crumb {klass}">
12
- {#if children}
13
- {@render children()}
14
- {/if}
15
- <div class="crumb-divider">
12
+ <li {...rest} class="crumb {klass}">
13
+ {@render children?.()}
14
+ <span class="crumb-divider">
16
15
  <Icon icon={divider} />
17
- </div>
16
+ </span>
18
17
  </li>
@@ -1,24 +1,21 @@
1
1
  <script>
2
- let klass = ''
3
- export { klass as class }
4
- export let user, themeId, hash, title
5
- export let height = 300
6
- export let defaultTab = 'result'
2
+ const { title, link, height = 300, tabs = 'result', themeID } = $props()
3
+ const [, , , user, , hash] = link.split('/')
7
4
  </script>
8
5
 
9
6
  <div
10
- class="Codepen {klass}"
7
+ style="height: ${height}px;"
8
+ class="codepen"
9
+ data-default-tab={tabs}
11
10
  data-height={height}
12
- data-theme-id={themeId}
13
- data-default-tab={defaultTab}
14
- data-user={user}
15
- data-slug-hash={hash}
16
- style={`height: ${height}px;`}
17
11
  data-pen-title={title}
12
+ data-slug-hash={hash}
13
+ data-theme-id={themeID}
14
+ data-user={user}
18
15
  >
19
16
  <!-- prettier-ignore -->
20
- <span>See the Pen
21
- <a href={`https://codepen.io/${user}/pen/${hash}`}>{title}</a> by {user} (<a href={`https://codepen.io/${user}`}> @{user}</a>) on <a href="https://codepen.io">CodePen</a>.
17
+ <span>
18
+ See the Pen <a href={link}>{title}</a>by <a href={`https://codepen.io/${user}`}>@{user}</a> on<a href="https://codepen.io">CodePen</a>.
22
19
  </span>
23
- <script async src="https://static.codepen.io/assets/embed/ei.js"></script>
20
+ <script async src="https://public.codepenassets.com/embed/index.js"></script>
24
21
  </div>
@@ -1,3 +1,2 @@
1
1
  import Codepen from './Codepen.svelte'
2
-
3
2
  export { Codepen }
@@ -1,9 +1,9 @@
1
1
  <script>
2
2
  import { splitObject } from '@splendidlabz/utils'
3
3
  import {
4
- goToElement,
5
4
  hasAccessibleName,
6
5
  markActiveAnchorIn,
6
+ scrollToElement,
7
7
  } from '@splendidlabz/utils/dom'
8
8
  import {
9
9
  TRANSITION_OPT_KEYS,
@@ -62,7 +62,7 @@
62
62
  $effect(_ => {
63
63
  if (show && ref && scrollToAnchor) {
64
64
  const anchor = markActiveAnchorIn(ref)
65
- goToElement(anchor)
65
+ scrollToElement(anchor)
66
66
  }
67
67
  })
68
68
  </script>
@@ -23,10 +23,10 @@
23
23
  </script>
24
24
 
25
25
  <button
26
- aria-label="Close dialog"
26
+ bind:this={button}
27
27
  class="drawer-close-button {klass}"
28
+ aria-label="Close dialog"
28
29
  {...rest}
29
- bind:this={button}
30
30
  onclick={closeDrawer}
31
31
  >
32
32
  {#if children}
@@ -3,15 +3,19 @@
3
3
  import ModalClose from '../ModalNew/ModalClose.svelte'
4
4
  import PopoverClose from '../PopoverNew/PopoverClose.svelte'
5
5
 
6
- const { target, ...p } = $props()
6
+ const { class: klass = '', target, ...p } = $props()
7
7
 
8
8
  let sync = $derived(getEntry(target))
9
9
  let type = $derived(sync?.type)
10
+
11
+ const propsToPass = {
12
+ target,
13
+ class: `drawer-close-button ${klass}`,
14
+ }
10
15
  </script>
11
16
 
12
- <!-- FUCK THIS DOESN'T WORK -->
13
17
  {#if type === 'popover'}
14
- <PopoverClose {...p} {target} />
18
+ <PopoverClose {...propsToPass} {...p} />
15
19
  {:else}
16
- <ModalClose {...p} {target} />
20
+ <ModalClose {...propsToPass} {...p} />
17
21
  {/if}
@@ -3,8 +3,8 @@
3
3
  import { getParentElement } from '@splendidlabz/utils/dom'
4
4
  import { onMount } from 'svelte'
5
5
  import { mergeEntry, setEntry } from '../../../actions/sync.svelte.js'
6
- import Modal from '../ModalNew/Modal.svelte'
7
- import Popover from '../PopoverNew/Popover.svelte'
6
+ import ModalContent from '../ModalNew/ModalContent.svelte'
7
+ import PopoverContent from '../PopoverNew/PopoverContent.svelte'
8
8
 
9
9
  let {
10
10
  class: klass = '',
@@ -16,9 +16,6 @@
16
16
  const { id, ...rest } = p
17
17
  const useReferenceBoundaries = type === 'popover'
18
18
 
19
- const localRef = $state(null)
20
- if (!ref) ref = () => localRef
21
-
22
19
  let referenceNode = $state(null)
23
20
  setEntry(id, { type })
24
21
 
@@ -32,12 +29,17 @@
32
29
  id,
33
30
  ...rest,
34
31
  componentName: 'Drawer',
35
- class: `drawer ${klass}`,
32
+ class: `drawer-content ${klass}`,
36
33
  }
37
34
  </script>
38
35
 
39
36
  {#if type === 'modal'}
40
- <Modal bind:ref {...propsToPass} />
37
+ <ModalContent bind:ref {...propsToPass} />
41
38
  {:else}
42
- <Popover {referenceNode} {useReferenceBoundaries} bind:ref {...propsToPass} />
39
+ <PopoverContent
40
+ {referenceNode}
41
+ {useReferenceBoundaries}
42
+ bind:ref
43
+ {...propsToPass}
44
+ />
43
45
  {/if}
@@ -1,5 +1,10 @@
1
- import Drawer from './Drawer.svelte'
2
- import DrawerClose from './DrawerClose.svelte'
1
+ import DrawerCloseButton from './DrawerCloseButton.svelte'
2
+ import DrawerContent from './DrawerContent.svelte'
3
3
  import DrawerTrigger from './DrawerTrigger.svelte'
4
4
 
5
- export { Drawer, DrawerClose, DrawerTrigger }
5
+ export {
6
+ DrawerContent as Drawer,
7
+ DrawerCloseButton,
8
+ DrawerContent,
9
+ DrawerTrigger,
10
+ }
@@ -1,5 +1,9 @@
1
1
  <script>
2
- import { checkForAccessibleName } from '@splendidlabz/utils/dom'
2
+ import {
3
+ checkForAccessibleName,
4
+ markActiveAnchorIn,
5
+ scrollToElement,
6
+ } from '@splendidlabz/utils/dom'
3
7
  import { getTrigger, passEventToTrigger } from '../shared.js'
4
8
  let { ref = $bindable(null), ...p } = $props()
5
9
 
@@ -13,13 +17,17 @@
13
17
  placement = 'center',
14
18
 
15
19
  // Props
16
- // scrollToAnchor = false,
20
+ scrollToAnchor = false,
17
21
  lightDismiss = true,
18
22
 
19
23
  // Event listeners
20
24
  onclick = null,
21
25
  onbeforetoggle = null,
26
+ onbeforeopen = null,
27
+ onbeforeclose = null,
22
28
  ontoggle = null,
29
+ onopen = null,
30
+ onclose = null,
23
31
  onkeydown = null,
24
32
 
25
33
  // Slots
@@ -61,15 +69,23 @@
61
69
  if (!trigger) trigger = getTrigger(`[data-modal-trigger="${id}"]`)
62
70
  passEventToTrigger(event, trigger)
63
71
 
64
- // const { newState } = event
65
- // if (newState === 'open') ref.classList.add(animationInClass)
66
- // if (newState === 'closed') ref.classList.add(animationOutClass)
67
-
72
+ const { newState } = event
73
+ if (newState === 'open' && onbeforeopen) onbeforeopen(event)
74
+ if (newState === 'close' && onbeforeclose) onbeforeclose(event)
68
75
  if (onbeforetoggle) onbeforetoggle(event)
69
76
  }
70
77
 
71
78
  function handleToggle(event) {
72
79
  passEventToTrigger(event, trigger)
80
+
81
+ const { newState } = event
82
+ if (newState === 'open' && scrollToAnchor) {
83
+ const anchor = markActiveAnchorIn(ref)
84
+ scrollToElement(anchor)
85
+ }
86
+
87
+ if (newState === 'open' && onopen) onopen(event)
88
+ if (newState === 'close' && onclose) onclose(event)
73
89
  if (ontoggle) ontoggle(event)
74
90
  }
75
91
 
@@ -103,7 +119,7 @@
103
119
  {...rest}
104
120
  bind:this={ref}
105
121
  {id}
106
- class="modal {placementClass} {transitionClass} {klass}"
122
+ class="modal-content {placementClass} {transitionClass} {klass}"
107
123
  aria-describedby={ariaDescribedBy}
108
124
  aria-label={ariaLabel}
109
125
  aria-labelledby={ariaLabelledBy}
@@ -1,5 +1,5 @@
1
- import Modal from './Modal.svelte'
2
1
  import ModalClose from './ModalClose.svelte'
2
+ import ModalContent from './ModalContent.svelte'
3
3
  import ModalTrigger from './ModalTrigger.svelte'
4
4
 
5
- export { Modal, ModalClose, ModalTrigger }
5
+ export { ModalContent as Modal, ModalClose, ModalContent, ModalTrigger }
@@ -0,0 +1,119 @@
1
+ <script>
2
+ import { splitObject } from '@splendidlabz/utils'
3
+ import { checkForAccessibleName } from '@splendidlabz/utils/dom'
4
+ import { mergeOpts } from '../../../utils/merge-opts.js'
5
+ import { getTrigger, passEventToTrigger } from '../shared.js'
6
+ import { FLOATING_OPTS_KEYS, initFloating } from './floating.js'
7
+
8
+ let {
9
+ class: klass = '',
10
+ as = 'dialog',
11
+ ref = $bindable(null),
12
+ referenceNode = $bindable(null),
13
+ ...p
14
+ } = $props()
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
38
+
39
+ // ========================
40
+ // Checks
41
+ // ========================
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,
49
+ })
50
+
51
+ // ========================================
52
+ // Logic
53
+ // ========================================
54
+ let trigger = null
55
+ let floating = null
56
+
57
+ const { picked: floatingOpts } = splitObject(rest, FLOATING_OPTS_KEYS)
58
+
59
+ // ========================================
60
+ // Event Listeners
61
+ // ========================================
62
+ function beforetoggle(event) {
63
+ if (!trigger) trigger = getTrigger(`[popovertarget="${id}"]`)
64
+ passEventToTrigger(event, trigger)
65
+
66
+ const { newState } = event
67
+
68
+ if (newState === 'open') {
69
+ // Initialize floating.
70
+ if (!floating) {
71
+ floating = initFloating({
72
+ referenceNode: referenceNode || trigger,
73
+ floatingNode: ref,
74
+ ...floatingOpts,
75
+ })
76
+ }
77
+ floating.update()
78
+ }
79
+
80
+ // Calculate position before showing
81
+ if (onbeforetoggle) onbeforetoggle(event)
82
+ }
83
+
84
+ function handleToggle(event) {
85
+ passEventToTrigger(event, trigger)
86
+ const { newState } = event
87
+
88
+ // Send open event
89
+ if (newState === 'open') {
90
+ if (onopen) onopen(event)
91
+ }
92
+
93
+ if (newState === 'closed') {
94
+ floating.cleanup()
95
+ // Send close event
96
+ if (onclose) onclose(event)
97
+ }
98
+
99
+ // Send toggle event
100
+ if (ontoggle) ontoggle(event)
101
+ }
102
+ </script>
103
+
104
+ <!-- Snippets -->
105
+ <svelte:element
106
+ this={as}
107
+ bind:this={ref}
108
+ {...rest}
109
+ {id}
110
+ class="{klass} popover-content"
111
+ aria-describedby={ariaDescribedBy}
112
+ aria-label={ariaLabel}
113
+ aria-labelledby={ariaLabelledBy}
114
+ onbeforetoggle={beforetoggle}
115
+ ontoggle={handleToggle}
116
+ {popover}
117
+ >
118
+ {#if children}{@render children()}{/if}
119
+ </svelte:element>
@@ -2,7 +2,7 @@
2
2
  import { delay } from '@splendidlabz/utils'
3
3
  import { onMount } from 'svelte'
4
4
  import Icon from '../../Icon/Icon.svelte'
5
- let { show = $bindable(false), ref = $bindable(null), ...p } = $props()
5
+ let { show = $bindable(null), ref = $bindable(null), ...p } = $props()
6
6
 
7
7
  const {
8
8
  componentName = 'PopoverTrigger',
@@ -20,6 +20,8 @@
20
20
  // Event listeners
21
21
  onclick = null,
22
22
  ontoggle = null,
23
+ onopen = null,
24
+ onclose = null,
23
25
  ...rest
24
26
  } = p
25
27
 
@@ -44,9 +46,17 @@
44
46
 
45
47
  // Allows trigger to know whether the popover is open or closed
46
48
  function handleToggle(event) {
47
- const { newState, oldState } = event.detail
48
- if (newState === 'open') show = true
49
- if (oldState === 'closed') show = false
49
+ const { newState } = event.detail
50
+ if (newState === 'open') {
51
+ show = true
52
+ if (onopen) onopen(event)
53
+ }
54
+
55
+ if (newState === 'closed') {
56
+ show = false
57
+ if (onclose) onclose(event)
58
+ }
59
+
50
60
  if (ontoggle) ontoggle(event)
51
61
  }
52
62
  </script>
@@ -54,7 +64,7 @@
54
64
  <button
55
65
  {...rest}
56
66
  bind:this={ref}
57
- class="button {klass}"
67
+ class="button popover-trigger {klass}"
58
68
  data-show={show}
59
69
  ontoggle={handleToggle}
60
70
  popovertarget={target}
@@ -52,6 +52,7 @@ export function initFloating(options) {
52
52
 
53
53
  // Create arrow node — used for both styles
54
54
  const arrowNode = document.createElement('div')
55
+ const arrowClass = 'popover-content-arrow'
55
56
  const arrowHeight = resolveArrowHeight(options)
56
57
  const arrowWidth = getArrowWidth({ ...options, arrowHeight })
57
58
 
@@ -64,6 +65,7 @@ export function initFloating(options) {
64
65
  }
65
66
 
66
67
  applyArrowStyles({ boxStyle, ...arrowProps })
68
+ arrowNode.classList.add(arrowClass)
67
69
  if (arrow) floatingNode.appendChild(arrowNode)
68
70
 
69
71
  // Calculate offset
@@ -210,6 +212,7 @@ function applyArrowStyles({
210
212
  borderRadius: '0',
211
213
  borderTopRightRadius: arrowRadius,
212
214
  borderWidth: 'inherit',
215
+ borderColor: 'inherit',
213
216
  borderLeftWidth: '0',
214
217
  borderBottomWidth: '0',
215
218
  background: 'inherit',
@@ -1,5 +1,6 @@
1
1
  import Popover from './Popover.svelte'
2
2
  import PopoverClose from './PopoverClose.svelte'
3
+ import PopoverContent from './PopoverContent.svelte'
3
4
  import PopoverTrigger from './PopoverTrigger.svelte'
4
5
 
5
- export { Popover, PopoverClose, PopoverTrigger }
6
+ export { Popover, PopoverClose, PopoverContent, PopoverTrigger }
@@ -30,9 +30,6 @@
30
30
 
31
31
  function submit(event) {
32
32
  const form = event.target
33
- // Do a standard form submit without JS if the user did not provide a custom onSubmit callback
34
- if (!onsubmit) return form.submit()
35
-
36
33
  event.preventDefault()
37
34
 
38
35
  // Format form data before submitting
@@ -49,7 +46,8 @@
49
46
  if (isTooFast || hasHoneypotValue || noInteraction) return
50
47
  }
51
48
 
52
- onsubmit(data)
49
+ if (!onsubmit) return form.submit()
50
+ else onsubmit(data)
53
51
  }
54
52
  </script>
55
53
 
@@ -9,26 +9,4 @@
9
9
  } = $props()
10
10
  </script>
11
11
 
12
- <TextInput
13
- {...rest}
14
- {name}
15
- class="form-field-helper {klass}"
16
- aria-hidden="true"
17
- autocomplete="off"
18
- tabindex="-1"
19
- bind:value
20
- />
21
-
22
- <style>
23
- .form-field-helper {
24
- display: none;
25
- visibility: hidden;
26
- position: absolute;
27
- left: -9999px;
28
- opacity: 0;
29
- pointer-events: none;
30
- height: 0;
31
- width: 0;
32
- overflow: hidden;
33
- }
34
- </style>
12
+ <TextInput {...rest} {name} class="form-field-helper {klass}" bind:value />
@@ -3,7 +3,6 @@ export { default as ButtonGroup } from './ButtonGroup.svelte'
3
3
  export { default as Checkbox } from './Checkbox.svelte'
4
4
  export { default as Checkboxes } from './Checkboxes.svelte'
5
5
  export * from './Combobox/index.js'
6
- export { default as CustomSelect } from './CustomSelect.svelte'
7
6
  export { default as Form } from './Form.svelte'
8
7
  export { default as Hidden } from './Hidden.svelte'
9
8
  export { default as HiddenInput } from './HiddenInput.svelte'
@@ -0,0 +1,22 @@
1
+ <!-- @example
2
+ <PushToLocalStorage
3
+ name="user"
4
+ value={ firstName: 'Zell', email: '12345@gmail.com' }
5
+ />
6
+ -->
7
+
8
+ <script>
9
+ import { localStore } from '@splendidlabz/utils/dom'
10
+ import { onMount } from 'svelte'
11
+
12
+ const { name, value } = $props()
13
+ if (!name) throw new Error('name is required')
14
+
15
+ onMount(store)
16
+
17
+ function store() {
18
+ if (typeof window === 'undefined') return
19
+ if (!name) return
20
+ localStore.set(name, value)
21
+ }
22
+ </script>
@@ -0,0 +1,15 @@
1
+ <script>
2
+ import { localStore } from '@splendidlabz/utils/dom'
3
+ import { onMount } from 'svelte'
4
+
5
+ const { name } = $props()
6
+ if (!name) throw new Error('name is required')
7
+
8
+ onMount(store)
9
+
10
+ function store() {
11
+ if (typeof window === 'undefined') return
12
+ if (!name) return
13
+ localStore.remove(name)
14
+ }
15
+ </script>
@@ -0,0 +1,4 @@
1
+ import LocalStoragePush from './LocalStoragePush.svelte'
2
+ import LocalStorageRemove from './LocalStorageRemove.svelte'
3
+
4
+ export { LocalStoragePush, LocalStorageRemove }
@@ -0,0 +1,49 @@
1
+ <script>
2
+ import { toStyleString } from '@splendidlabz/utils'
3
+ import { onMount } from 'svelte'
4
+ import { domParser, naiveParser } from './parser.js'
5
+ const {
6
+ icon,
7
+ style,
8
+ parser = 'naive', // or DOM
9
+ children, // Just to remove children slots
10
+ ...p
11
+ } = $props()
12
+
13
+ const files = {
14
+ ...import.meta.glob(`/src/svg/**/*.svg`, { eager: true, query: 'raw' }),
15
+ ...import.meta.glob(`/src/svgs/**/*.svg`, { eager: true, query: 'raw' }),
16
+ }
17
+
18
+ // Find the SVG
19
+ if (!icon) throw new Error('icon property is required')
20
+
21
+ const file = Object.keys(files).find(file => {
22
+ const basename = file.split('/').pop()
23
+ return basename === `${icon}.svg`
24
+ })
25
+
26
+ if (!file) {
27
+ throw new Error(`${icon}.svg not found`)
28
+ }
29
+
30
+ const content = files[file].default
31
+ const svgProps = {
32
+ role: 'img',
33
+ xmlns: 'http://www.w3.org/2000/svg',
34
+ style: toStyleString(style),
35
+ ...p,
36
+ }
37
+
38
+ let svg = $state(null)
39
+
40
+ if (parser === 'naive') svg = naiveParser(content, svgProps)
41
+ if (parser === 'dom') {
42
+ onMount(_ => {
43
+ svg = domParser(content, svgProps)
44
+ })
45
+ }
46
+ </script>
47
+
48
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
49
+ {@html svg}
@@ -0,0 +1,2 @@
1
+ import SVG from './SVG.svelte'
2
+ export { SVG }
@@ -0,0 +1,133 @@
1
+ // Simple regex parsing to add/adjust SVG attributes
2
+ // Written by AI.
3
+ export function naiveParser(content, options) {
4
+ const { class: klass, width, height, attributes = {} } = options
5
+
6
+ // Parse the opening <svg> tag
7
+ const svgMatch = content.match(/<svg[^>]*>/i)
8
+ if (!svgMatch) return content
9
+
10
+ let svgTag = svgMatch[0]
11
+
12
+ // Extract existing attributes
13
+ const existingWidth = svgTag.match(/width="([^"]*)"/)
14
+ const existingHeight = svgTag.match(/height="([^"]*)"/)
15
+ const existingViewBox = svgTag.match(/viewBox="([^"]*)"/)
16
+
17
+ // Parse values
18
+ const currentWidth = existingWidth ? existingWidth[1] : null
19
+ const currentHeight = existingHeight ? existingHeight[1] : null
20
+ const currentViewBox = existingViewBox ? existingViewBox[1] : null
21
+
22
+ // Add class if provided
23
+ if (klass) {
24
+ if (svgTag.includes('class=')) {
25
+ // Add to existing class
26
+ svgTag = svgTag.replace(/class="([^"]*)"/, `class="$1 ${klass}"`)
27
+ } else {
28
+ // Add new class attribute
29
+ svgTag = svgTag.replace('>', ` class="${klass}">`)
30
+ }
31
+ }
32
+
33
+ // Handle width/height and viewBox relationship
34
+ let finalWidth = width || currentWidth
35
+ let finalHeight = height || currentHeight
36
+ let finalViewBox = currentViewBox
37
+
38
+ // If viewBox exists but width/height don't, extract from viewBox
39
+ if (currentViewBox && (!currentWidth || !currentHeight)) {
40
+ const viewBoxValues = currentViewBox.split(/\s+/)
41
+ if (viewBoxValues.length === 4) {
42
+ const [, , vbWidth, vbHeight] = viewBoxValues
43
+ if (!currentWidth && !width) finalWidth = vbWidth
44
+ if (!currentHeight && !height) finalHeight = vbHeight
45
+ }
46
+ }
47
+
48
+ // If width/height exist but viewBox doesn't, create viewBox
49
+ if (!currentViewBox && (finalWidth || finalHeight)) {
50
+ const vbWidth = finalWidth || '0'
51
+ const vbHeight = finalHeight || '0'
52
+ finalViewBox = `0 0 ${vbWidth} ${vbHeight}`
53
+ }
54
+
55
+ // Apply width if we have a final value
56
+ if (finalWidth) {
57
+ if (svgTag.includes('width=')) {
58
+ svgTag = svgTag.replace(/width="[^"]*"/, `width="${finalWidth}"`)
59
+ } else {
60
+ svgTag = svgTag.replace('>', ` width="${finalWidth}">`)
61
+ }
62
+ }
63
+
64
+ // Apply height if we have a final value
65
+ if (finalHeight) {
66
+ if (svgTag.includes('height=')) {
67
+ svgTag = svgTag.replace(/height="[^"]*"/, `height="${finalHeight}"`)
68
+ } else {
69
+ svgTag = svgTag.replace('>', ` height="${finalHeight}">`)
70
+ }
71
+ }
72
+
73
+ // Apply viewBox if we have a final value
74
+ if (finalViewBox) {
75
+ if (svgTag.includes('viewBox=')) {
76
+ svgTag = svgTag.replace(/viewBox="[^"]*"/, `viewBox="${finalViewBox}"`)
77
+ } else {
78
+ svgTag = svgTag.replace('>', ` viewBox="${finalViewBox}">`)
79
+ }
80
+ }
81
+
82
+ // Add any additional attributes
83
+ Object.entries(attributes).forEach(([key, value]) => {
84
+ if (svgTag.includes(`${key}=`)) {
85
+ svgTag = svgTag.replace(new RegExp(`${key}="[^"]*"`), `${key}="${value}"`)
86
+ } else {
87
+ svgTag = svgTag.replace('>', ` ${key}="${value}">`)
88
+ }
89
+ })
90
+
91
+ // Replace the original svg tag with the modified one
92
+ return content.replace(/<svg[^>]*>/i, svgTag)
93
+ }
94
+
95
+ // Uses DOM Parser to modify the SVG.
96
+ // Likely not needed.
97
+ // Written by AI.
98
+ export function domParser(content, options) {
99
+ const { className, width, height, attributes = {}, transform } = options
100
+
101
+ // Parse SVG content
102
+ const parser = new DOMParser()
103
+ const doc = parser.parseFromString(content, 'image/svg+xml')
104
+ const svgElement = doc.querySelector('svg')
105
+
106
+ if (!svgElement) return content
107
+
108
+ // Add class
109
+ if (className) {
110
+ const currentClass = svgElement.getAttribute('class') || ''
111
+ svgElement.setAttribute(
112
+ 'class',
113
+ currentClass ? `${currentClass} ${className}` : className,
114
+ )
115
+ }
116
+
117
+ // Set dimensions
118
+ if (width) svgElement.setAttribute('width', width)
119
+ if (height) svgElement.setAttribute('height', height)
120
+
121
+ // Add additional attributes
122
+ Object.entries(attributes).forEach(([key, value]) => {
123
+ svgElement.setAttribute(key, value)
124
+ })
125
+
126
+ // Apply custom transform function
127
+ if (typeof transform === 'function') {
128
+ transform(svgElement)
129
+ }
130
+
131
+ // Return the modified SVG
132
+ return svgElement.outerHTML
133
+ }
@@ -18,9 +18,16 @@
18
18
  status = 'info'
19
19
  }
20
20
  }
21
+
22
+ const statusClasses = {
23
+ info: 'status-info',
24
+ success: 'status-success',
25
+ error: 'status-error',
26
+ }
27
+ const statusClass = statusClasses[status]
21
28
  </script>
22
29
 
23
- <div {...rest} class="status {status && `status-${status}`} prose {klass}">
30
+ <div {...rest} class="status {statusClass} {klass}">
24
31
  {#if children}
25
32
  {@render children()}
26
33
  {/if}
@@ -28,6 +28,8 @@
28
28
  $: tab = $tabs.find(t => t.id === target)
29
29
  $: tablistClasses = getTablistClasses(tab)
30
30
 
31
+ if (!target) throw new Error('Tablist must have a target')
32
+
31
33
  function getTablistClasses(tab) {
32
34
  if (!tab) return ''
33
35
  const { placement } = tab.state
@@ -2,6 +2,7 @@
2
2
  import { tabpanels } from './tabs.js'
3
3
 
4
4
  const { id = null, class: klass = '', children, ...rest } = $props()
5
+ if (!id) throw new Error('Tabpanels must have an id')
5
6
  </script>
6
7
 
7
8
  <div {...rest} {id} class="tabpanels {klass}" use:tabpanels>
@@ -9,10 +9,10 @@
9
9
 
10
10
  <div class={`Vimeo ${klass}`}>
11
11
  <iframe
12
- {src}
13
- {title}
12
+ allow="autoplay; fullscreen; picture-in-picture"
14
13
  allowfullscreen
15
14
  frameborder="0"
16
- allow="autoplay; fullscreen; picture-in-picture"
15
+ {src}
16
+ {title}
17
17
  ></iframe>
18
18
  </div>
@@ -1,15 +1,26 @@
1
1
  <script>
2
- export let id, title
3
- const link = `https://www.youtube.com/embed/${id}`
2
+ import { toStyleString } from '@splendidlabz/utils'
3
+ const { class: klass = '', id, link, title, short = false } = $props()
4
+
5
+ if (!id && !link)
6
+ throw new Error('id or link is required for Youtube component')
7
+
8
+ const _id = id || link.split('/').pop()
9
+ const src = `https://www.youtube.com/embed/${_id}?vq=highres`
10
+
11
+ const style = toStyleString({
12
+ width: '100%',
13
+ aspectRatio: short ? '9/16' : '16/9',
14
+ })
4
15
  </script>
5
16
 
6
- <!-- IMPROVE: Not sure if height and width is needed -->
7
- <div class="Youtube">
17
+ <div class="youtube {klass}">
8
18
  <iframe
9
- src={link}
10
- {title}
11
- frameborder="0"
19
+ {style}
12
20
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
13
21
  allowfullscreen
22
+ frameborder="0"
23
+ {src}
24
+ {title}
14
25
  ></iframe>
15
26
  </div>
package/index.js CHANGED
@@ -1,13 +1,16 @@
1
+ export * from './components/Breadcrumbs/index.js'
2
+ export * from './components/BrowserFrame/index.js'
3
+ export * from './components/Codepen/index.js'
4
+ export * from './components/ContentList/index.js'
1
5
  export * from './components/Disclosure/index.js'
2
6
  export * from './components/Icon/index.js'
7
+ export * from './components/Resizer/index.js'
8
+ export * from './components/Scrambler/index.js'
9
+ export * from './components/SVG/index.js'
3
10
 
4
11
  // Not tested yet
5
12
  export * from './components/Accordion/index.js'
6
- export * from './components/Breadcrumbs/index.js'
7
- export * from './components/BrowserFrame/index.js'
8
13
  export * from './components/Callout/index.js'
9
- export * from './components/Codepen/index.js'
10
- export * from './components/ContentList/index.js'
11
14
  export * from './components/effects/index.js'
12
15
  export * from './components/FancyList/index.js'
13
16
  export * from './components/Form/index.js'
@@ -15,17 +18,15 @@ export * from './components/Highlight/index.js'
15
18
  export * from './components/InteractiveRegion/index.js'
16
19
  export * from './components/Link/index.js'
17
20
  export * from './components/List/index.js'
21
+ export * from './components/LocalStorage/index.js'
18
22
  export * from './components/Masonry/index.js'
19
23
  export * from './components/Populate/index.js'
20
- export * from './components/Resizer/index.js'
21
- export * from './components/Scrambler/index.js'
22
24
  export * from './components/Switcheroo/index.js'
23
25
  export * from './components/Table/index.js'
24
26
  export * from './components/Tabs/index.js'
25
27
 
26
28
  // TO REMOVE AFTER SHIFTING TO ASTRO
27
29
  export * from './components/Textwall/index.js'
28
-
29
30
  export * from './components/Typewriter/index.js'
30
31
 
31
32
  export { default as Copyright } from './components/Copyright.svelte'
@@ -34,7 +35,6 @@ export { default as Image } from './components/Image.svelte'
34
35
  export { default as Markdown } from './components/Markdown/Markdown.svelte'
35
36
  export { default as PerspectiveHover } from './components/PerspectiveHover/PerspectiveHover.svelte'
36
37
  export { default as Portal } from './components/Portal.svelte'
37
- export { default as PushToLocalStorage } from './components/PushToLocalStorage.svelte'
38
38
  export { default as Spotlight } from './components/Spotlight/Spotlight.svelte'
39
39
  export { default as Status } from './components/Status.svelte'
40
40
  export { default as Video } from './components/Video.svelte'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splendidlabz/svelte",
3
3
  "type": "module",
4
- "version": "4.1.0",
4
+ "version": "4.3.0",
5
5
  "sideEffects": false,
6
6
  "scripts": {
7
7
  "lint": "eslint . --fix",
@@ -21,8 +21,8 @@
21
21
  "dependencies": {
22
22
  "@floating-ui/dom": "^1.6.13",
23
23
  "@iconify/svelte": "^4.2.0",
24
- "@splendidlabz/styles": "4.1.0",
25
- "@splendidlabz/utils": "1.6.0",
24
+ "@splendidlabz/styles": "4.2.1",
25
+ "@splendidlabz/utils": "1.8.0",
26
26
  "autosuggest-highlight": "^3.3.4",
27
27
  "lodash-es": "^4.17.21",
28
28
  "node-html-parser": "^7.0.1"
@@ -1,29 +0,0 @@
1
- ---
2
- const {
3
- height = 300,
4
- defaultTab = 'result',
5
- user = 'zellwk',
6
- author = 'Zell Liew',
7
- themeID = 7929,
8
- hash,
9
- title,
10
- } = Astro.props
11
- ---
12
-
13
- <div
14
- class="Codepen"
15
- data-height={height}
16
- data-theme-id={themeID}
17
- data-default-tab={defaultTab}
18
- data-user={user}
19
- data-slug-hash={hash}
20
- style=`height: ${height}px;`
21
- data-pen-title={title}
22
- >
23
- <!-- prettier-ignore -->
24
- <span>
25
- See the Pen <a href=`https://codepen.io/${user}/pen/${hash}`> {title} </a>by {author} (<a href={`https://codepen.io/${user}`}>@{user}</a>) on<a href="https://codepen.io">CodePen</a>.
26
- </span>
27
-
28
- <script async src="https://static.codepen.io/assets/embed/ei.js"></script>
29
- </div>
@@ -1,205 +0,0 @@
1
- <script>
2
- /* eslint-disable no-labels */
3
- import { toTitle } from '@splendidlabz/utils'
4
- import { randomString } from '@splendidlabz/utils/dom'
5
- import { Popover, PopoverTrigger } from '../Disclosure/index.js'
6
- import Icon from '../Icon/Icon.svelte'
7
- import HiddenInput from './HiddenInput.svelte'
8
-
9
- let {
10
- name = '',
11
- items = $bindable([]),
12
- options = $bindable([]),
13
- selected = $bindable(null),
14
- ref = $bindable(null),
15
- ...p
16
- } = $props()
17
-
18
- const {
19
- // Classes
20
- class: klass = '',
21
- icon = null,
22
- iconClass = null,
23
- label = '',
24
- labelClass,
25
- labelVisible = true,
26
- hint = null,
27
- hintClass,
28
- fieldClass = null,
29
-
30
- // Options and props
31
- id = randomString(8),
32
- required = null,
33
- readonly = null,
34
- disabled = null,
35
- multiple = null,
36
- size = 0, // Number of lines to show, useful for multiselect, 0, but show 4 lines by default.
37
-
38
- onchange = null,
39
- ...rest
40
- } = p
41
-
42
- if (!options.length && !items.length) {
43
- console.error(
44
- 'Select requires either `options` or `items` to be passed in.',
45
- )
46
- }
47
-
48
- const isSingle = !multiple
49
- const hintId = hint ? id + '-hint' : ''
50
- const hintDescription = `${hintId}`.trim() || null
51
-
52
- let selectedItem = $derived(items.find(item => item.value === selected))
53
-
54
- // ========================================
55
- // Some Checks & Normalizations
56
- // ========================================
57
- // Fixes multiple name and selected values
58
- if (multiple) {
59
- if (!name.endsWith('[]')) name = name += '[]'
60
- if (!Array.isArray(selected)) selected = []
61
- }
62
-
63
- // Normalize items
64
- if (options.length) items = options
65
- items = items.map(option => {
66
- if (typeof option === 'string') option = { value: option }
67
-
68
- if (!option.label) option.label = toTitle(option.value)
69
-
70
- if (isSingle) {
71
- // Updates selected with selected options
72
- if (option.selected) selected = option.value
73
-
74
- // Updates options with selected values
75
- if (option.value === selected) option.selected = true
76
- else option.selected = false
77
- } else {
78
- // Updates selected with selected options
79
- if (option.selected && !selected.includes(option.value))
80
- selected.push(option.value)
81
-
82
- // Updates options with selected values
83
- if (selected.includes(option.value)) option.selected = true
84
- else option.selected = false
85
- }
86
-
87
- return option
88
- })
89
-
90
- // Preselect first item that is not disabled. (Single only)
91
- setSelected: if (!multiple && !selected) {
92
- const firstNotDisabled = items.findIndex(item => !item.disabled)
93
- if (firstNotDisabled === -1) break setSelected
94
- const s = items[firstNotDisabled] || items[0]
95
- s.selected = true
96
- selected = s.value
97
- }
98
-
99
- // Properties for the select element
100
- const properties = {
101
- ...rest,
102
- id,
103
- name,
104
- class: 'input ' + fieldClass,
105
- disabled: disabled || readonly,
106
- 'aria-describedby': hintDescription,
107
- onchange: handleChange,
108
- required,
109
- size,
110
- }
111
-
112
- function handleChange() {
113
- items.forEach(item => {
114
- if (item.value === selected) item.selected = true
115
- else item.selected = false
116
- })
117
- if (onchange) onchange()
118
- }
119
- </script>
120
-
121
- {#snippet select()}
122
- <select {...properties} bind:this={ref} bind:value={selected}>
123
- {#each items as option (option.value)}
124
- {@const { label: optionLabel, value, ...optionRest } = option}
125
- <option {...optionRest} {value}>{optionLabel}</option>
126
- {/each}
127
- </select>
128
- {/snippet}
129
-
130
- <!-- Svelte requires multiple to be passed as a standard attribute for it to bind to an array value, hence the duplication here -->
131
- {#snippet multiselect()}
132
- <select
133
- {...properties}
134
- bind:this={ref}
135
- aria-describedby={hintDescription}
136
- multiple
137
- bind:value={selected}
138
- >
139
- {#each items as option (option.value)}
140
- {@const { label: optionLabel, value, ...optionRest } = option}
141
- <option {...optionRest} {value}>{optionLabel}</option>
142
- {/each}
143
- </select>
144
- {/snippet}
145
-
146
- {#snippet selectIcon()}
147
- {#if icon}
148
- <Icon class={iconClass} {icon} />
149
- {:else}
150
- <svg class={iconClass} height="24" viewBox="0 0 24 24" width="24">
151
- <path
152
- d="M8 9L12 5L16 9M16 15L12 19L8 15"
153
- stroke="currentcolor"
154
- stroke-linecap="round"
155
- stroke-linejoin="round"
156
- stroke-width="2"
157
- />
158
- </svg>
159
- {/if}
160
- {/snippet}
161
-
162
- <div class="input-container select {klass}">
163
- {#if label && labelVisible}
164
- <label class="label input-meta {labelClass}" for={id}>{label}</label>
165
- {/if}
166
- {#if hint}
167
- <div id={hintId} class="hint input-meta {hintClass}">{hint}</div>
168
- {/if}
169
-
170
- <div class="input-group items-center stack" class:disabled class:readonly>
171
- <!-- Single Select -->
172
- {#if isSingle}
173
- {@render select()}
174
- {#if readonly}
175
- <HiddenInput {name} value={selected} />
176
- {/if}
177
-
178
- <div class="pos-right pointer-events-none z-[3]">
179
- {@render selectIcon()}
180
- </div>
181
- {/if}
182
-
183
- <!-- Multi Select -->
184
- {#if multiple}
185
- {@render multiselect()}
186
- {#if readonly}
187
- {#each selected as item (item)}
188
- <HiddenInput {name} value={item} />
189
- {/each}
190
- {/if}
191
- {/if}
192
- </div>
193
- </div>
194
-
195
- <PopoverTrigger class="horizontal justify-between" target="meh">
196
- <span> {selectedItem?.value} </span>
197
- <span> {@render selectIcon()} </span>
198
- </PopoverTrigger>
199
-
200
- <Popover id="meh" offset="0.5em" placement="bottom-end" role="listbox">
201
- {#each items as option (option.value)}
202
- {@const { label: optionLabel, value, ...optionRest } = option}
203
- <option {...optionRest} {value}>{optionLabel}</option>
204
- {/each}
205
- </Popover>
@@ -1,30 +0,0 @@
1
- <!-- @example
2
- <PushToLocalStorage
3
- values={{ firstName: 'Zell', email: '12345@gmail.com' }} client:idle
4
- />
5
-
6
- Stored value can be an object as well
7
- <PushToLocalStorage
8
- values={{
9
- user: {
10
- firstName: 'Zell',
11
- email: '12345@gmail.com',
12
- },
13
- }}
14
- client:idle
15
- />
16
- -->
17
-
18
- <script>
19
- import { isEmpty, objectForEach } from '@splendidlabz/utils'
20
- import { localStore } from '@splendidlabz/utils/dom'
21
- export let values = {}
22
-
23
- store(values)
24
-
25
- function store(values) {
26
- if (typeof window === 'undefined') return
27
- if (isEmpty(values)) return
28
- objectForEach(values, ({ key, value }) => localStore.set(key, value))
29
- }
30
- </script>