@rokkit/core 1.0.0-next.12 → 1.0.0-next.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/core",
3
- "version": "1.0.0-next.12",
3
+ "version": "1.0.0-next.13",
4
4
  "description": "Core components, actions and stores for svelte apps.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -6,6 +6,7 @@
6
6
  import Icon from './Icon.svelte'
7
7
  import Text from './items/Text.svelte'
8
8
  import List from './List.svelte'
9
+ import Slider from './Slider.svelte'
9
10
 
10
11
  const dispatch = createEventDispatcher()
11
12
 
@@ -62,10 +63,11 @@
62
63
  {/if}
63
64
  </button>
64
65
  {#if open}
65
- <div
66
+ <!-- <div
66
67
  class="flex flex-col absolute z-10 h-fit w-full menu"
67
68
  style:top="{offsetTop}px"
68
- >
69
+ > -->
70
+ <Slider top={offsetTop}>
69
71
  <List
70
72
  {items}
71
73
  {fields}
@@ -74,6 +76,7 @@
74
76
  on:select={handleSelect}
75
77
  tabindex="-1"
76
78
  />
77
- </div>
79
+ </Slider>
80
+ <!-- </div> -->
78
81
  {/if}
79
82
  </drop-down>
@@ -0,0 +1,31 @@
1
+ <script>
2
+ import TabItems from './TabItems.svelte'
3
+ import TabItem from './TabItem.svelte'
4
+
5
+ let className = ''
6
+ export { className as class }
7
+ export let items = []
8
+ export let fields = {}
9
+ export let title = null
10
+ export let allowAdd = false
11
+ export let allowClose = false
12
+ export let value = items[0]
13
+
14
+ function addTab() {
15
+ items = [...items, {}]
16
+ value = items[items.length - 1]
17
+ }
18
+ </script>
19
+
20
+ <tab-view class="flex flex-col w-full flex-grow {className}">
21
+ <tabs class="flex flex-row flex-shrink-0 w-full select-none cursor-pointer">
22
+ {#if title}
23
+ <p>{title}</p>
24
+ {/if}
25
+ <TabItems {items} {fields} {allowClose} bind:value on:close />
26
+ {#if allowAdd}
27
+ <TabItem label="+" on:click={addTab} />
28
+ {/if}
29
+ </tabs>
30
+ <content class="flex flex-col flex-grow"><slot /></content>
31
+ </tab-view>
package/src/Tabs.svelte CHANGED
@@ -1,31 +1,49 @@
1
1
  <script>
2
- import TabItems from './TabItems.svelte'
3
- import TabItem from './TabItem.svelte'
2
+ import { defaultFields } from './constants'
3
+ import { Text } from './items'
4
+ import { navigator } from './actions'
5
+ import { createEventDispatcher } from 'svelte'
6
+
7
+ const dispatch = createEventDispatcher()
4
8
 
5
9
  let className = ''
6
10
  export { className as class }
7
11
  export let items = []
8
12
  export let fields = {}
9
- export let title = null
10
- export let allowAdd = false
11
- export let allowClose = false
12
- export let value = items[0]
13
+ export let using = {}
14
+ export let value = null
15
+ let cursor = []
16
+
17
+ function handleNav(event) {
18
+ value = event.detail.node
19
+ cursor = event.detail.path
13
20
 
14
- function addTab() {
15
- items = [...items, {}]
16
- value = items[items.length - 1]
21
+ dispatch('select', { item: value, indices: cursor })
17
22
  }
23
+ $: fields = { ...defaultFields, ...fields }
24
+ $: using = { default: Text, ...using }
18
25
  </script>
19
26
 
20
- <tab-view class="flex flex-col w-full flex-grow {className}">
21
- <tabs class="flex flex-row flex-shrink-0 w-full select-none cursor-pointer">
22
- {#if title}
23
- <p>{title}</p>
24
- {/if}
25
- <TabItems {items} {fields} {allowClose} bind:value on:close />
26
- {#if allowAdd}
27
- <TabItem label="+" on:click={addTab} />
28
- {/if}
29
- </tabs>
30
- <content class="flex flex-col flex-grow"><slot /></content>
31
- </tab-view>
27
+ <tabs
28
+ class="flex w-full {className}"
29
+ tabindex="0"
30
+ role="listbox"
31
+ use:navigator={{
32
+ items,
33
+ fields,
34
+ vertical: false,
35
+ indices: cursor
36
+ }}
37
+ on:move={handleNav}
38
+ on:select={handleNav}
39
+ >
40
+ {#each items as item, index}
41
+ {@const component = item[fields.component]
42
+ ? using[item[fields.component]] || using.default
43
+ : using.default}
44
+
45
+ <item class="flex" class:is-selected={item === value} data-path={index}>
46
+ <svelte:component this={component} content={item} {fields} />
47
+ </item>
48
+ {/each}
49
+ </tabs>
@@ -2,6 +2,7 @@ export function navigable(
2
2
  node,
3
3
  { horizontal = true, nested = false, enabled = true } = {}
4
4
  ) {
5
+ // console.log(node, enabled)
5
6
  if (!enabled) return { destroy() {} }
6
7
  const previous = () => node.dispatchEvent(new CustomEvent('previous'))
7
8
  const next = () => node.dispatchEvent(new CustomEvent('next'))
@@ -12,6 +12,7 @@
12
12
  class="flex flex-row flex-grow gap-2 items-center content"
13
13
  href={content[fields.url]}
14
14
  {target}
15
+ tabindex="-1"
15
16
  >
16
17
  <Text {content} {fields} />
17
18
  </a>