@coyalabs/bts-style 1.1.0 → 1.1.1

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.
@@ -1,8 +1,11 @@
1
1
  <script>
2
2
  import { slide } from 'svelte/transition';
3
+ import { createEventDispatcher } from 'svelte';
3
4
  import Button from './Button.svelte';
4
5
  import { icons } from '../icons.js';
5
6
 
7
+ const dispatch = createEventDispatcher();
8
+
6
9
  /** @type {{ name: string, type: 'file' | 'folder', children?: any[] }[]} */
7
10
  export let items = [];
8
11
 
@@ -19,11 +22,20 @@
19
22
 
20
23
  /**
21
24
  * @param {string} id
25
+ * @param {any} item
22
26
  */
23
- function toggle(id) {
27
+ function toggle(id, item) {
24
28
  if (expanded.has(id)) expanded.delete(id);
25
29
  else expanded.add(id);
26
30
  expanded = expanded;
31
+ dispatch('itemClick', { item, type: 'folder' });
32
+ }
33
+
34
+ /**
35
+ * @param {any} item
36
+ */
37
+ function handleItemClick(item) {
38
+ dispatch('itemClick', { item, type: 'file' });
27
39
  }
28
40
 
29
41
  /**
@@ -98,7 +110,7 @@
98
110
  {@const isNested = level > 0}
99
111
 
100
112
  {#if item.type === 'folder'}
101
- <div class="folder" on:click={() => toggle(id)} on:keydown={() => {}} role="button" tabindex="0">
113
+ <div class="folder" on:click={() => toggle(id, item)} on:keydown={() => {}} role="button" tabindex="0">
102
114
  <Button
103
115
  theme="primary"
104
116
  icon={icons.folder}
@@ -114,20 +126,22 @@
114
126
  </div>
115
127
  {#if open && item.children}
116
128
  <div transition:slide={{ duration: 150 }}>
117
- <svelte:self items={item.children} {showCount} {itemIcon} level={level + 1} />
129
+ <svelte:self items={item.children} {showCount} {itemIcon} level={level + 1} on:itemClick />
118
130
  </div>
119
131
  {/if}
120
132
  {:else}
121
- <Button
122
- theme="secondary"
123
- icon={itemIcon}
124
- borderRadiusTopLeft={isNested ? '15px' : '25px'}
125
- borderRadiusTopRight={isNested ? '15px' : '25px'}
126
- borderRadiusBottomLeft={isNested && !isLast ? '15px' : '25px'}
127
- borderRadiusBottomRight={isNested && !isLast ? '15px' : '25px'}
128
- >
129
- {item.name}
130
- </Button>
133
+ <div on:click={() => handleItemClick(item)} on:keydown={() => {}} role="button" tabindex="0">
134
+ <Button
135
+ theme="secondary"
136
+ icon={itemIcon}
137
+ borderRadiusTopLeft={isNested ? '15px' : '25px'}
138
+ borderRadiusTopRight={isNested ? '15px' : '25px'}
139
+ borderRadiusBottomLeft={isNested && !isLast ? '15px' : '25px'}
140
+ borderRadiusBottomRight={isNested && !isLast ? '15px' : '25px'}
141
+ >
142
+ {item.name}
143
+ </Button>
144
+ </div>
131
145
  {/if}
132
146
  {/each}
133
147
  </div>
@@ -13,6 +13,8 @@ type TreeDirectory = SvelteComponent<{
13
13
  expandAll?: (() => void) | undefined;
14
14
  collapseAll?: (() => void) | undefined;
15
15
  }, {
16
+ itemClick: CustomEvent<any>;
17
+ } & {
16
18
  [evt: string]: CustomEvent<any>;
17
19
  }, {}> & {
18
20
  $$bindings?: string | undefined;
@@ -36,6 +38,8 @@ declare const TreeDirectory: $$__sveltets_2_IsomorphicComponent<{
36
38
  expandAll?: (() => void) | undefined;
37
39
  collapseAll?: (() => void) | undefined;
38
40
  }, {
41
+ itemClick: CustomEvent<any>;
42
+ } & {
39
43
  [evt: string]: CustomEvent<any>;
40
44
  }, {}, {
41
45
  getState: () => string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coyalabs/bts-style",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "BTS Theme Svelte component templates",
5
5
  "type": "module",
6
6
  "exports": {