@splendidlabz/svelte 3.0.0-alpha.3 → 3.0.0-beta.6

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 (67) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/actions/index.js +2 -0
  3. package/actions/sync.svelte.js +21 -0
  4. package/actions/use-actions.js +27 -0
  5. package/{components/_shared/use-actions.js → actions/use-transition.js} +1 -0
  6. package/components/Accordion/Accordion.svelte +3 -3
  7. package/components/Disclosure/Disclosure/DisclosureCloseButton.svelte +37 -0
  8. package/components/Disclosure/Disclosure/DisclosureContent.svelte +97 -0
  9. package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +51 -0
  10. package/components/Disclosure/Disclosure/disclosure-popover.svelte.js +7 -0
  11. package/components/Disclosure/Disclosure/disclosure.svelte.js +461 -0
  12. package/components/Disclosure/Disclosure/index.js +4 -0
  13. package/components/Disclosure/DisclosureNew/DisclosureCloseButton.svelte +38 -0
  14. package/components/Disclosure/DisclosureNew/DisclosureContent.svelte +53 -0
  15. package/components/Disclosure/DisclosureNew/DisclosureTrigger.svelte +79 -0
  16. package/components/Disclosure/DisclosureNew/disclosures.svelte.js +55 -0
  17. package/components/Disclosure/DisclosureNew/index.js +5 -0
  18. package/components/Disclosure/Drawer/Drawer.svelte +18 -22
  19. package/components/Disclosure/Drawer/DrawerCloseButton.svelte +2 -2
  20. package/components/Disclosure/Drawer/DrawerContent.svelte +41 -77
  21. package/components/Disclosure/Drawer/DrawerNew.svelte +0 -0
  22. package/components/Disclosure/Drawer/DrawerTrigger.svelte +7 -46
  23. package/components/Disclosure/Drawer/drawer.js +2 -70
  24. package/components/Disclosure/DrawerNew/Drawer.svelte +39 -0
  25. package/components/Disclosure/DrawerNew/DrawerClose.svelte +0 -0
  26. package/components/Disclosure/DrawerNew/DrawerTrigger.svelte +16 -0
  27. package/components/Disclosure/DrawerNew/drawer.js +44 -0
  28. package/components/Disclosure/DrawerNew/index.js +5 -0
  29. package/components/Disclosure/Modal/Modal.svelte +30 -0
  30. package/components/Disclosure/Modal/ModalCloseButton.svelte +7 -0
  31. package/components/Disclosure/Modal/ModalContent.svelte +40 -1
  32. package/components/Disclosure/Modal/ModalTrigger.svelte +7 -29
  33. package/components/Disclosure/Modal/index.js +5 -0
  34. package/components/Disclosure/Modal/modal.js +3 -12
  35. package/components/Disclosure/ModalNew/Modal.svelte +110 -0
  36. package/components/Disclosure/ModalNew/ModalClose.svelte +42 -0
  37. package/components/Disclosure/ModalNew/ModalTrigger.svelte +68 -0
  38. package/components/Disclosure/ModalNew/index.js +5 -0
  39. package/components/Disclosure/Popover/PopoverContent.svelte +2 -2
  40. package/components/Disclosure/Popover/PopoverTrigger.svelte +1 -1
  41. package/components/Disclosure/PopoverNew/Popover.svelte +105 -0
  42. package/components/Disclosure/PopoverNew/PopoverClose.svelte +38 -0
  43. package/components/Disclosure/PopoverNew/PopoverTrigger.svelte +67 -0
  44. package/components/Disclosure/PopoverNew/floating.js +329 -0
  45. package/components/Disclosure/PopoverNew/index.js +5 -0
  46. package/components/Disclosure/disclosure.js +1 -1
  47. package/components/Disclosure/disclosure.svelte.js +3 -3
  48. package/components/Disclosure/index.js +7 -3
  49. package/components/Disclosure/shared.js +9 -0
  50. package/components/Form/Checkbox.svelte +72 -57
  51. package/components/Form/Checkboxes.svelte +42 -24
  52. package/components/Form/HiddenInput.svelte +1 -1
  53. package/components/Form/Radio.svelte +62 -45
  54. package/components/Form/Radios.svelte +42 -24
  55. package/components/Form/Select.svelte +125 -77
  56. package/components/Form/SelectOld2.svelte +127 -0
  57. package/components/Form/TextInput.svelte +1 -1
  58. package/components/Form/Textarea.svelte +1 -1
  59. package/components/Icon/IconSnippet.svelte +7 -0
  60. package/components/Portal.svelte +8 -5
  61. package/eslint.config.js +2 -0
  62. package/package.json +6 -6
  63. package/svelte.config.js +5 -0
  64. package/utils/merge-opts.js +9 -1
  65. package/utils/transitions.js +75 -4
  66. package/.eslintrc.cjs +0 -3
  67. package/components/_shared/accessibility.js +0 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @splendidlabz/svelte
2
2
 
3
+ ## 3.0.0-beta.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Remove default export
8
+
9
+ ## 3.0.0-alpha.5
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [5fe7c51]
14
+ - @splendidlabz/utils@1.5.0-alpha.3
15
+ - @splendidlabz/styles@3.0.0-alpha.5
16
+
17
+ ## 3.0.0-alpha.4
18
+
19
+ ### Patch Changes
20
+
21
+ - 2ba13ba: - Include select element
22
+ - Include Checkboxes
23
+ - Include Radios
24
+ - Updated dependencies [2ba13ba]
25
+ - Updated dependencies [acf9faf]
26
+ - @splendidlabz/styles@3.0.0-alpha.4
27
+ - @splendidlabz/utils@1.5.0-alpha.2
28
+
3
29
  ## 3.0.0-alpha.3
4
30
 
5
31
  ### Patch Changes
package/actions/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from '../components/Populate/actions.js'
2
2
  export * from './resize-observer.js'
3
3
  export * from './scroll-observer.js'
4
+ export * from './sync.svelte.js'
5
+ export * from './use-actions.js'
@@ -0,0 +1,21 @@
1
+ import { SvelteMap } from 'svelte/reactivity'
2
+
3
+ const syncStore = new SvelteMap()
4
+
5
+ export function getEntry(id) {
6
+ return syncStore.get(id)
7
+ }
8
+
9
+ export function setEntry(id, value) {
10
+ return syncStore.set(id, value)
11
+ }
12
+
13
+ export function mergeEntry(id, value) {
14
+ const entry = getEntry(id)
15
+ if (!entry) return setEntry(id, value)
16
+ return syncStore.set(id, { ...entry, ...value })
17
+ }
18
+
19
+ export function removeEntry(id) {
20
+ return syncStore.delete(id)
21
+ }
@@ -0,0 +1,27 @@
1
+ // Grabbed from https://github.com/radiofrance/svelte-component-actions/tree/main
2
+ export function useActions(node, actions) {
3
+ if (!actions) return
4
+
5
+ const actionReturns = actions.map(actionEntry => {
6
+ const { fn, props } = actionEntry
7
+ return fn(node, props)
8
+ })
9
+
10
+ return {
11
+ update(newActions) {
12
+ if (!newActions || newActions.length !== actionReturns.length) {
13
+ throw new Error('You must not change the length of an actions array.')
14
+ }
15
+ newActions.forEach((actionEntry, i) => {
16
+ const returnEntry = actionReturns[i]
17
+ const { props } = actionEntry
18
+ returnEntry?.update?.(props)
19
+ })
20
+ },
21
+ destroy() {
22
+ actionReturns.forEach(returnEntry => {
23
+ returnEntry?.destroy?.()
24
+ })
25
+ },
26
+ }
27
+ }
@@ -1,4 +1,5 @@
1
1
  // Grabbed from https://github.com/radiofrance/svelte-component-actions/tree/main
2
+ // TODO: Add transition action
2
3
  export function useActions(node, actions) {
3
4
  if (!actions) return
4
5
 
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { randomString } from '@splendidlabz/utils/dom'
3
- import { mergeOpts, transit } from '../../utils/index.js'
3
+ import { applyTransition, mergeOpts } from '../../utils/index.js'
4
4
  import Icon from '../Icon/Icon.svelte'
5
5
 
6
6
  const p = $props()
@@ -73,7 +73,7 @@
73
73
 
74
74
  <!-- The output -->
75
75
 
76
- <div class="accordion {klass}" class:is-expanded={show}>
76
+ <div class="accordion {klass}" class:open={show}>
77
77
  <svelte:element this={opts.titleTag} class="accordion-title {titleClass}">
78
78
  <button
79
79
  class="accordion-button {buttonClass}"
@@ -93,7 +93,7 @@
93
93
  <div
94
94
  {id}
95
95
  class="accordion-content {contentClass}"
96
- transition:transit={{
96
+ transition:applyTransition={{
97
97
  transition: opts.transition,
98
98
  }}
99
99
  >
@@ -0,0 +1,37 @@
1
+ <script>
2
+ import Icon from '../../Icon/Icon.svelte'
3
+ import { close, getDisclosure } from './disclosure.svelte.js'
4
+
5
+ const {
6
+ class: klass = '',
7
+ icon = 'tabler:x',
8
+ iconClass = '',
9
+ target = '',
10
+ children,
11
+ ...rest
12
+ } = $props()
13
+
14
+ let button = null
15
+
16
+ function closeDrawer() {
17
+ const id =
18
+ document.querySelector(`${target}`)?.id ||
19
+ button.closest('.disclosure-content').id
20
+ const d = getDisclosure(id)
21
+ close(d, { shouldFocusWhenClosing: true })
22
+ }
23
+ </script>
24
+
25
+ <button
26
+ aria-label="Close"
27
+ class="button-icon {klass}"
28
+ {...rest}
29
+ bind:this={button}
30
+ onclick={closeDrawer}
31
+ >
32
+ {#if children}
33
+ {@render children()}
34
+ {:else}
35
+ <Icon class={iconClass} {icon} />
36
+ {/if}
37
+ </button>
@@ -0,0 +1,97 @@
1
+ <script>
2
+ import { splitObject } from '@splendidlabz/utils'
3
+ import {
4
+ goToElement,
5
+ hasAccessibleName,
6
+ markActiveAnchorIn,
7
+ } from '@splendidlabz/utils/dom'
8
+ import {
9
+ TRANSITION_OPT_KEYS,
10
+ applyTransition,
11
+ } from '../../../utils/transitions.js'
12
+ import Portal from '../../Portal.svelte'
13
+ import {
14
+ DISCLOSURE_CONTENT_OPT_KEYS,
15
+ disclosureContent,
16
+ getDisclosure,
17
+ } from '../disclosure.svelte.js'
18
+
19
+ let { ref = $bindable(null), ...p } = $props()
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
39
+
40
+ const { picked: disclosureContentOpts, omitted: rest } = splitObject(
41
+ restProps,
42
+ DISCLOSURE_CONTENT_OPT_KEYS,
43
+ )
44
+
45
+ const { picked: transitionOpts, omitted: remaining } = splitObject(
46
+ rest,
47
+ TRANSITION_OPT_KEYS,
48
+ )
49
+
50
+ if (!id) throw new Error(`${componentName} requires an id`)
51
+
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
+ }
58
+
59
+ let d = $derived(getDisclosure(id))
60
+ let show = $derived(d?.state.show)
61
+
62
+ $effect(_ => {
63
+ if (show && ref && scrollToAnchor) {
64
+ const anchor = markActiveAnchorIn(ref)
65
+ goToElement(anchor)
66
+ }
67
+ })
68
+ </script>
69
+
70
+ <!-- Snippets -->
71
+ {#snippet dc()}
72
+ <div
73
+ {...remaining}
74
+ {id}
75
+ class="disclosure-content {klass}"
76
+ {role}
77
+ bind:this={ref}
78
+ use:disclosureContent={{ options: disclosureContentOpts }}
79
+ aria-label={ariaLabel}
80
+ aria-labelledby={ariaLabelledBy}
81
+ aria-describedby={ariaDescribedBy}
82
+ transition:applyTransition|global={transitionOpts}
83
+ >
84
+ {#if children}
85
+ {@render children()}
86
+ {/if}
87
+ </div>
88
+ {/snippet}
89
+
90
+ <!-- Render -->
91
+ {#if show}
92
+ {#if portal}
93
+ <Portal>{@render dc()}</Portal>
94
+ {:else}
95
+ {@render dc()}
96
+ {/if}
97
+ {/if}
@@ -0,0 +1,51 @@
1
+ <script>
2
+ import { splitObject } from '@splendidlabz/utils'
3
+ import Icon from '../../Icon/Icon.svelte'
4
+ import {
5
+ DISCLOSURE_TRIGGER_OPT_KEYS,
6
+ disclosureTrigger,
7
+ } from '../disclosure.svelte.js'
8
+
9
+ let { show = $bindable(false), ...p } = $props()
10
+
11
+ const {
12
+ class: klass = '',
13
+ componentName = 'DisclosureTrigger',
14
+ icon = 'tabler:menu',
15
+ iconClass,
16
+ 'aria-haspopup': ariaHasPopup = 'dialog',
17
+ target,
18
+
19
+ // Slots
20
+ children,
21
+ ...restProps
22
+ } = p
23
+
24
+ const { picked: triggerOpts, omitted: rest } = splitObject(
25
+ restProps,
26
+ DISCLOSURE_TRIGGER_OPT_KEYS,
27
+ )
28
+
29
+ if (!target)
30
+ throw new Error(`${componentName} must contain a target property`)
31
+
32
+ // TODO: Test creating an IconSnippet to render the icon vs contents
33
+ // <script module> currently breaks when prettier is enabled. So, ¯\_(ツ)_/¯ if we can ever do that.
34
+ </script>
35
+
36
+ <button
37
+ {...rest}
38
+ {target}
39
+ class="button {klass}"
40
+ aria-haspopup={ariaHasPopup}
41
+ use:disclosureTrigger={{
42
+ state: { show },
43
+ options: triggerOpts,
44
+ }}
45
+ >
46
+ {#if children}
47
+ {@render children()}
48
+ {:else if icon}
49
+ <Icon class={iconClass} {icon} />
50
+ {/if}
51
+ </button>
@@ -0,0 +1,7 @@
1
+ const TRIGGER_OPTS = {
2
+ lightDismiss: true,
3
+ }
4
+
5
+ export function disclosureTrigger(node, props = {}) {}
6
+
7
+ export function disclosureContent(node, props = {}) {}