@splendidlabz/svelte 0.4.0 → 3.0.0-alpha.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 (60) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/actions/index.js +2 -5
  3. package/actions/portal.js +1 -1
  4. package/actions/scroll-observer.js +1 -1
  5. package/common.js +1 -1
  6. package/components/Accordion/Accordion.svelte +67 -60
  7. package/components/Breadcrumbs/Crumb.svelte +1 -1
  8. package/components/Breadcrumbs/CrumbCustom.svelte +1 -1
  9. package/components/{BrowserFrame.svelte → BrowserFrame/BrowserFrame.svelte} +1 -1
  10. package/components/BrowserFrame/index.js +3 -0
  11. package/components/ContentList/ContentList-old.svelte +1 -1
  12. package/components/ContentList/ContentList.svelte +1 -1
  13. package/components/Copyright.svelte +19 -0
  14. package/components/Disclosure/Drawer/DrawerCloseButton.svelte +21 -15
  15. package/components/Disclosure/Drawer/DrawerContent.svelte +92 -128
  16. package/components/Disclosure/Drawer/DrawerTrigger.svelte +38 -20
  17. package/components/Disclosure/Dropdown/DropdownTrigger.svelte +1 -1
  18. package/components/Disclosure/Modal/exit-intent.js +1 -1
  19. package/components/Disclosure/Popover/PopoverCloseButton.svelte +1 -1
  20. package/components/Disclosure/disclosure.svelte.js +432 -0
  21. package/components/FancyList/FancyList.svelte +1 -1
  22. package/components/Form/Checkbox.svelte +3 -3
  23. package/components/Form/Checkboxes.svelte +1 -1
  24. package/components/Form/Combobox/combobox.js +6 -5
  25. package/components/Form/Radio.svelte +3 -3
  26. package/components/Form/Radios.svelte +1 -1
  27. package/components/Form/Select.svelte +4 -4
  28. package/components/Form/TextInput.svelte +88 -65
  29. package/components/Form/Textarea.svelte +87 -64
  30. package/components/Highlight.svelte +46 -0
  31. package/components/Icon/Icon.svelte +43 -0
  32. package/components/Icon/index.js +2 -0
  33. package/components/PerspectiveHover/PerspectiveHover.svelte +1 -1
  34. package/components/PerspectiveHover/perspective-hover.js +1 -1
  35. package/components/Portal.svelte +1 -1
  36. package/components/Spotlight/PointerPosition.js +1 -1
  37. package/components/Spotlight/Spotlight.svelte +1 -1
  38. package/components/Tabs/tabs.js +8 -11
  39. package/components/Video.svelte +1 -1
  40. package/components/Vimeo.svelte +1 -1
  41. package/components/Youtube.svelte +1 -1
  42. package/components/_shared/accessibility.js +1 -0
  43. package/components/effects/index.js +0 -0
  44. package/index.js +7 -4
  45. package/package.json +11 -12
  46. package/utils/index.js +2 -0
  47. package/utils/merge-opts.js +5 -0
  48. package/components/Disclosure/Drawer/DrawerContent-wrecked.svelte +0 -198
  49. package/components/Resizer/draggable.js +0 -23
  50. package/components/SVG/SVG.svelte +0 -120
  51. package/components/Tabs-Old/Tab.svelte +0 -9
  52. package/components/Tabs-Old/Tablist.svelte +0 -13
  53. package/components/Tabs-Old/Tabpanel.svelte +0 -10
  54. package/components/Tabs-Old/Tabpanels.svelte +0 -14
  55. package/components/Tabs-Old/Tabs.svelte +0 -83
  56. package/components/Tabs-Old/index.js +0 -7
  57. package/components/Tabs-Old/tabs.js +0 -306
  58. package/components/_shared/key.js +0 -1
  59. /package/components/{BrowserWithTabs.svelte → BrowserFrame/BrowserWithTabs.svelte} +0 -0
  60. /package/{components/_shared → utils}/transitions.js +0 -0
@@ -1,306 +0,0 @@
1
- export default function createTabs({
2
- activeTab = 0,
3
- orientation = 'horizontal',
4
- placement = 'left',
5
- mode = 'tab',
6
- breakpoints = null,
7
- scrollBehaviour = 'auto',
8
- }) {
9
- // Structure of _Tabs
10
- // { tab: HTMLElement, panel: HTMLElement, id }
11
- let tabsNode = null
12
- const _tabs = []
13
-
14
- let state = {
15
- activeTab: 0,
16
- orientation,
17
- placement,
18
- mode,
19
- curentStructure: mode,
20
- shouldFocus: false, // What is this?!
21
- }
22
-
23
- state = new Proxy(state, {
24
- get(target, prop) {
25
- return Reflect.get(...arguments)
26
- },
27
-
28
- set(target, prop) {
29
- Reflect.set(...arguments)
30
- if (prop === 'activeTab') {
31
- toIndexSystem()
32
- setActiveTab()
33
- setActivePanel()
34
- dispatchChange()
35
- }
36
-
37
- if (prop === 'mode') {
38
- // Maybe detect if the value has changed if possible. Cos if it didn't change then no need to do anything here. One way is ta add a currentStructure into the state.
39
- const value = target[prop]
40
- if (value === 'tab') toTab()
41
- if (value === 'accordion') toAccordion()
42
- }
43
- return true
44
- },
45
- })
46
-
47
- // Initial Setup
48
- updateTabStructure({ orientation, placement, mode })
49
-
50
- // ========================
51
- // Public API
52
- // ========================
53
- function tabs(node) {
54
- tabsNode = node
55
- }
56
-
57
- function tablist(node) {
58
- const tabs = Array.from(node.querySelectorAll('[role="tab"]'))
59
-
60
- tabs.forEach((tab, index) => {
61
- const slot = _tabs[index] || {}
62
- if (slot) _tabs[index] = { ...slot, tab, index }
63
- if (!slot) tabs.push({ tab })
64
- })
65
-
66
- // Add Event Listeners
67
- node.addEventListener('click', handleClick)
68
- node.addEventListener('keydown', handleKeyboard)
69
-
70
- initializeActiveTab()
71
-
72
- return {
73
- destroy() {
74
- node.removeEventListener('click', handleClick)
75
- node.removeEventListener('keydown', handleKeyboard)
76
- },
77
- }
78
- }
79
-
80
- function tabpanels(node) {
81
- const panels = Array.from(node.querySelectorAll('[role="tabpanel"]'))
82
-
83
- panels.forEach((panel, index) => {
84
- const slot = _tabs[index] || {}
85
- if (slot) _tabs[index] = { ...slot, panel, target: panel.id }
86
- if (!slot) tabs.push({ panel, target: panel.id })
87
- })
88
-
89
- initializeActiveTab()
90
-
91
- node.addEventListener('keydown', handleKeyboardInTabpanel)
92
- window.addEventListener('hashchange', initializeActiveTab)
93
-
94
- return {
95
- destroy() {
96
- node.removeEventListener('keydown', handleKeyboardInTabpanel)
97
- window.removeEventListener('hashchange', initializeActiveTab)
98
- },
99
- }
100
- }
101
-
102
- // ========================
103
- // Internal API
104
- // ========================
105
-
106
- // Initialize to what the user provided.
107
- // But if the URL contains the #id of the tabpanel then we initialize to that tabpanel instead.
108
- function initializeActiveTab() {
109
- state.activeTab = getInitialActiveTab()
110
-
111
- const { hash } = window.location
112
- if (hash) return scrollToTab(hash)
113
- }
114
-
115
- // Base the active tab according to the 'active' attribute placed in tabs
116
- function getInitialActiveTab() {
117
- const activeTabRef = _tabs.findIndex(
118
- ({ tab }) => tab.getAttribute('aria-selected') === 'true',
119
- )
120
-
121
- if (activeTabRef >= 0) return activeTabRef
122
- return activeTab // Returns the user defined activeTab in properties if 'aria-selected' is not found in the tabs
123
- }
124
-
125
- function scrollToTab(hash) {
126
- const target = _tabs.find(item => {
127
- return `#${item.target}` === hash
128
- })
129
- if (!target) return
130
-
131
- // Set the active tab.
132
- state.activeTab = target.index
133
-
134
- // Scroll user to the Tabs component instead of the Tabpanel — so users can still see the Tabs.
135
- target.tab.parentElement?.parentElement?.scrollIntoView({
136
- behavior: scrollBehaviour,
137
- })
138
- }
139
-
140
- function toIndexSystem() {
141
- if (typeof state.activeTab === 'number') return
142
- const activeIndex = _tabs.findIndex(tab => {
143
- return tab.target === state.activeTab
144
- })
145
- state.activeTab = activeIndex
146
- }
147
-
148
- function isActiveTab(index) {
149
- if (typeof state.activeTab === 'number') {
150
- return state.activeTab === index
151
- }
152
- }
153
-
154
- function setActiveTab() {
155
- _tabs.forEach((item, index) => {
156
- const { tab } = item
157
- if (isActiveTab(index)) {
158
- tab.setAttribute('aria-selected', 'true')
159
- tab.setAttribute('tabindex', '0')
160
-
161
- if (state.shouldFocus) tab.focus()
162
- } else {
163
- tab.removeAttribute('aria-selected')
164
- tab.setAttribute('tabindex', '-1')
165
- }
166
- })
167
- }
168
-
169
- function setActivePanel() {
170
- _tabs.forEach((item, index) => {
171
- const { panel } = item
172
- if (!panel) return // Because they may not have initialized yet
173
- if (isActiveTab(index)) {
174
- panel.removeAttribute('hidden')
175
- panel.setAttribute('tabindex', '0')
176
- } else {
177
- panel.setAttribute('hidden', 'true')
178
- panel.removeAttribute('tabindex')
179
- }
180
- })
181
- }
182
-
183
- function dispatchChange() {
184
- if (!tabsNode) return
185
- const { activeTab, orientation, placement, mode } = state
186
- const event = new CustomEvent('change', {
187
- detail: {
188
- activeTab,
189
- activeTabNode: _tabs[activeTab].tab,
190
- orientation,
191
- placement,
192
- mode,
193
- },
194
- })
195
-
196
- tabsNode.dispatchEvent(event)
197
- }
198
-
199
- function activatePrevTab() {
200
- if (state.activeTab > 0) {
201
- state.shouldFocus = true
202
- state.activeTab = state.activeTab - 1
203
- }
204
- }
205
-
206
- function activateNextTab() {
207
- if (state.activeTab < _tabs.length - 1) {
208
- state.shouldFocus = true
209
- state.activeTab = state.activeTab + 1
210
- }
211
- }
212
-
213
- function focusTab() {
214
- const activeTab = _tabs[state.activeTab]
215
- const { tab } = activeTab
216
- tab.focus()
217
- }
218
-
219
- function focusTabpanel() {
220
- const activeTab = _tabs[state.activeTab]
221
- const { panel } = activeTab
222
- panel.focus()
223
- }
224
-
225
- function updateTabStructure(structure) {
226
- const { placement, orientation, mode } = structure
227
-
228
- if (orientation !== 'horizontal' && orientation !== 'vertical') {
229
- throw new Error(
230
- `The orientation must be either "horizontal" or "vertical". You passed: ${orientation}`,
231
- )
232
- }
233
-
234
- if (placement !== 'left' && placement !== 'right') {
235
- throw new Error(
236
- `The placement must be either "left" or "right". You passed: ${placement}`,
237
- )
238
- }
239
-
240
- if (mode !== 'tab' && mode !== 'accordion') {
241
- throw new Error(
242
- `The mode must be either "tab" or "accordion". You passed: ${mode}`,
243
- )
244
- }
245
-
246
- state.orientation = orientation
247
- state.placement = placement
248
- state.mode = mode
249
- }
250
-
251
- function toTab() {
252
- // if (state.currentStructure === 'tab') return
253
- }
254
-
255
- function toAccordion() {
256
- // if (state.currentStructure === 'accordion') return
257
- }
258
-
259
- // ========================
260
- // Event Handlers
261
- // ========================
262
- function handleClick(event) {
263
- const tab = event.target.closest('[role="tab"]')
264
- const item = _tabs.find(item => item.tab === tab)
265
- if (!item) return
266
-
267
- state.shouldFocus = true
268
- state.activeTab = item.index
269
- }
270
-
271
- function handleKeyboard(event) {
272
- if (state.orientation === 'horizontal') {
273
- if (event.key === 'ArrowLeft') activatePrevTab()
274
- if (event.key === 'ArrowRight') activateNextTab()
275
- if (event.key === 'ArrowDown') focusTabpanel()
276
- }
277
-
278
- if (state.orientation === 'vertical') {
279
- if (event.key === 'ArrowUp') activatePrevTab()
280
- if (event.key === 'ArrowDown') activateNextTab()
281
-
282
- if (placement === 'left' && event.key === 'ArrowRight') focusTabpanel()
283
- if (placement === 'right' && event.key === 'ArrowLeft') focusTabpanel()
284
- }
285
- }
286
-
287
- function handleKeyboardInTabpanel(event) {
288
- if (state.orientation === 'horizontal') {
289
- if (event.key === 'ArrowUp') focusTab()
290
- }
291
-
292
- if (state.orientation === 'vertical') {
293
- if (placement === 'left' && event.key === 'ArrowLeft') focusTab()
294
- if (placement === 'right' && event.key === 'ArrowRight') focusTab()
295
- }
296
- }
297
-
298
- return {
299
- tabs,
300
- tablist,
301
- tabpanels,
302
- updateTabStructure,
303
- activateNextTab,
304
- activatePrevTab,
305
- }
306
- }
@@ -1 +0,0 @@
1
- export const key = Symbol('key')
File without changes