@svar-ui/svelte-toolbar 2.6.0 → 2.6.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.
- package/package.json +3 -3
- package/src/buttons/ButtonList.svelte +38 -0
- package/src/buttons/Icon.svelte +5 -3
- package/src/components/BarComponent.svelte +1 -16
- package/src/components/Toolbar.svelte +7 -2
- package/src/helpers.js +14 -4
- package/src/index.js +4 -2
- package/whatsnew.md +7 -0
- package/src/buttons/Button.svelte +0 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svar-ui/svelte-toolbar",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Svelte toolbar component. Lightweight, customizable, easy-to-use.",
|
|
5
5
|
"productTag": "toolbar",
|
|
6
6
|
"productTrial": false,
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://svar.dev/svelte/core/",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@svar-ui/svelte-core": "2.6.
|
|
37
|
-
"@svar-ui/lib-dom": "0.
|
|
36
|
+
"@svar-ui/svelte-core": "2.6.1",
|
|
37
|
+
"@svar-ui/lib-dom": "0.14.0"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"src",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { Button } from "@svar-ui/svelte-core";
|
|
3
|
+
|
|
4
|
+
let { css, disabled, options, onchange, value = $bindable() } = $props();
|
|
5
|
+
|
|
6
|
+
function onClickHandler(id) {
|
|
7
|
+
value = id;
|
|
8
|
+
onchange && onchange({ value: id });
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<div class="wx-button-list {css}">
|
|
13
|
+
{#each options as option}
|
|
14
|
+
<Button
|
|
15
|
+
type={value === option.id ? "primary" : ""}
|
|
16
|
+
{disabled}
|
|
17
|
+
text={option.label}
|
|
18
|
+
onclick={() => onClickHandler(option.id)}
|
|
19
|
+
/>
|
|
20
|
+
{/each}
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<style>
|
|
24
|
+
.wx-button-list {
|
|
25
|
+
line-height: normal;
|
|
26
|
+
}
|
|
27
|
+
.wx-button-list :global(button) {
|
|
28
|
+
width: 100%;
|
|
29
|
+
}
|
|
30
|
+
.wx-button-list :global(button:not(:first-child)) {
|
|
31
|
+
border-top-left-radius: 0;
|
|
32
|
+
border-top-right-radius: 0;
|
|
33
|
+
}
|
|
34
|
+
.wx-button-list :global(button:not(:last-child)) {
|
|
35
|
+
border-bottom-left-radius: 0;
|
|
36
|
+
border-bottom-right-radius: 0;
|
|
37
|
+
}
|
|
38
|
+
</style>
|
package/src/buttons/Icon.svelte
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
{#if menu}
|
|
9
9
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
10
10
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
11
|
-
<div class="wx-item" {onclick}>
|
|
12
|
-
|
|
11
|
+
<div class="wx-item" class:wx-text-icon={text} {onclick}>
|
|
12
|
+
<i class="{icon || 'wxi-empty'} {css || ''}"></i>
|
|
13
13
|
{text}
|
|
14
14
|
</div>
|
|
15
15
|
{:else}
|
|
@@ -18,10 +18,12 @@
|
|
|
18
18
|
|
|
19
19
|
<style>
|
|
20
20
|
i {
|
|
21
|
-
margin-right: 8px;
|
|
22
21
|
font-size: var(--wx-icon-size);
|
|
23
22
|
color: var(--wx-color-font);
|
|
24
23
|
}
|
|
24
|
+
.wx-text-icon i {
|
|
25
|
+
margin-right: 8px;
|
|
26
|
+
}
|
|
25
27
|
.wx-item {
|
|
26
28
|
cursor: pointer;
|
|
27
29
|
white-space: nowrap;
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
import Spacer from "../buttons/Spacer.svelte";
|
|
6
6
|
|
|
7
7
|
let { item = {}, menu = false, values, onclick, onchange } = $props();
|
|
8
|
-
|
|
9
|
-
let itemComponent = $derived(getItemHandler(item.comp || "label"));
|
|
8
|
+
let itemComponent = $derived(getItemHandler(item.comp, { menu }));
|
|
10
9
|
|
|
11
10
|
function onClick() {
|
|
12
11
|
if (item.handler) item.handler(item);
|
|
@@ -56,30 +55,16 @@
|
|
|
56
55
|
display: flex;
|
|
57
56
|
}
|
|
58
57
|
.wx-menu.wx-tb-element {
|
|
59
|
-
height: 36px;
|
|
60
58
|
line-height: 36px;
|
|
61
59
|
padding: 2px 8px;
|
|
62
60
|
background-color: var(--wx-background);
|
|
63
61
|
}
|
|
64
|
-
|
|
65
62
|
.wx-menu :global(button) {
|
|
66
63
|
width: 100%;
|
|
67
|
-
background: transparent;
|
|
68
|
-
text-align: left;
|
|
69
|
-
padding-left: 0;
|
|
70
|
-
font-weight: var(--wx-font-weight);
|
|
71
|
-
font-size: var(--wx-font-size);
|
|
72
64
|
}
|
|
73
65
|
.wx-menu :global(.wx-tb-element) {
|
|
74
66
|
align-self: stretch;
|
|
75
67
|
}
|
|
76
|
-
.wx-menu.wx-tb-element :global(button:hover) {
|
|
77
|
-
background: var(--wx-background-alt);
|
|
78
|
-
}
|
|
79
|
-
.wx-menu :global(button i) {
|
|
80
|
-
margin-right: 4px;
|
|
81
|
-
font-size: var(--wx-icon-size);
|
|
82
|
-
}
|
|
83
68
|
.wx-menu.wx-tb-element:hover {
|
|
84
69
|
background: var(--wx-background-alt);
|
|
85
70
|
}
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
let menuItems = $state([]);
|
|
30
30
|
|
|
31
31
|
const barItems = $derived(normalizeToolbarItems(items));
|
|
32
|
+
const vertical = $derived(layout === "column");
|
|
32
33
|
|
|
33
34
|
function getTotalWidth() {
|
|
34
35
|
const nodes = div.children;
|
|
@@ -79,7 +80,7 @@
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
function processOverflow() {
|
|
82
|
-
if (overflow === "wrap") return;
|
|
83
|
+
if (overflow === "wrap" || vertical) return;
|
|
83
84
|
|
|
84
85
|
const nodes = div.children;
|
|
85
86
|
// restore all items so widths can be measured
|
|
@@ -146,7 +147,7 @@
|
|
|
146
147
|
<div
|
|
147
148
|
class="wx-toolbar {css}"
|
|
148
149
|
class:wx-wrap={overflow === "wrap"}
|
|
149
|
-
class:wx-column={
|
|
150
|
+
class:wx-column={vertical}
|
|
150
151
|
class:wx-has-menu={menuItems.length}
|
|
151
152
|
bind:this={div}
|
|
152
153
|
>
|
|
@@ -186,5 +187,9 @@
|
|
|
186
187
|
}
|
|
187
188
|
.wx-column {
|
|
188
189
|
flex-flow: column;
|
|
190
|
+
width: auto;
|
|
191
|
+
}
|
|
192
|
+
.wx-column :global(.wx-tb-element) {
|
|
193
|
+
width: 100%;
|
|
189
194
|
}
|
|
190
195
|
</style>
|
package/src/helpers.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { uid } from "@svar-ui/lib-dom";
|
|
2
2
|
|
|
3
3
|
const handlers = {};
|
|
4
|
-
export function getItemHandler(type) {
|
|
5
|
-
|
|
4
|
+
export function getItemHandler(type, config = null) {
|
|
5
|
+
// try to get the handler for the config, fallback to the type
|
|
6
|
+
// so we need not register all button types for alternative modes
|
|
7
|
+
const c =
|
|
8
|
+
typeof type === "string"
|
|
9
|
+
? handlers[getID(type, config)] || handlers[type]
|
|
10
|
+
: type;
|
|
11
|
+
return c || handlers["label"];
|
|
6
12
|
}
|
|
7
|
-
export function registerToolbarItem(type, handler) {
|
|
8
|
-
handlers[type] = handler;
|
|
13
|
+
export function registerToolbarItem(type, handler, config = null) {
|
|
14
|
+
handlers[getID(type, config)] = handler;
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
// Assign stable ids and collapse consecutive separators
|
|
@@ -30,3 +36,7 @@ export function collapseSeparators(items) {
|
|
|
30
36
|
}
|
|
31
37
|
return out;
|
|
32
38
|
}
|
|
39
|
+
|
|
40
|
+
function getID(type, config = null) {
|
|
41
|
+
return `${type}${config?.menu ? ":menu" : ""}`;
|
|
42
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
import { Button } from "@svar-ui/svelte-core";
|
|
1
2
|
import Toolbar from "./components/Toolbar.svelte";
|
|
2
3
|
import { registerToolbarItem } from "./helpers.js";
|
|
3
4
|
|
|
4
5
|
import Separator from "./buttons/Separator.svelte";
|
|
5
6
|
import Spacer from "./buttons/Spacer.svelte";
|
|
6
|
-
import
|
|
7
|
+
import ButtonList from "./buttons/ButtonList.svelte";
|
|
7
8
|
import Label from "./buttons/Label.svelte";
|
|
8
9
|
import Icon from "./buttons/Icon.svelte";
|
|
9
10
|
import Item from "./buttons/Item.svelte";
|
|
10
11
|
|
|
11
12
|
registerToolbarItem("button", Button);
|
|
13
|
+
registerToolbarItem("button", Icon, { menu: true });
|
|
12
14
|
registerToolbarItem("separator", Separator);
|
|
13
15
|
registerToolbarItem("spacer", Spacer);
|
|
14
16
|
registerToolbarItem("label", Label);
|
|
15
17
|
registerToolbarItem("item", Item);
|
|
16
18
|
registerToolbarItem("icon", Icon);
|
|
17
19
|
|
|
18
|
-
export { Toolbar, registerToolbarItem };
|
|
20
|
+
export { Toolbar, ButtonList, registerToolbarItem };
|
package/whatsnew.md
CHANGED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { Button } from "@svar-ui/svelte-core";
|
|
3
|
-
|
|
4
|
-
let {
|
|
5
|
-
icon,
|
|
6
|
-
title,
|
|
7
|
-
text = "",
|
|
8
|
-
tooltip,
|
|
9
|
-
css,
|
|
10
|
-
type,
|
|
11
|
-
disabled,
|
|
12
|
-
menu,
|
|
13
|
-
onclick,
|
|
14
|
-
} = $props();
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
{#if menu}
|
|
18
|
-
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
19
|
-
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
20
|
-
<div class="wx-item" {onclick}>
|
|
21
|
-
<i class="{icon || 'wxi-empty'} {css || ''}"></i>
|
|
22
|
-
{text}
|
|
23
|
-
</div>
|
|
24
|
-
{:else}
|
|
25
|
-
<Button {icon} {type} {css} {title} {text} {tooltip} {disabled} {onclick} />
|
|
26
|
-
{/if}
|
|
27
|
-
|
|
28
|
-
<style>
|
|
29
|
-
i {
|
|
30
|
-
margin-right: 8px;
|
|
31
|
-
font-size: var(--wx-button-icon-size);
|
|
32
|
-
color: var(--wx-icon-color);
|
|
33
|
-
}
|
|
34
|
-
.wx-item {
|
|
35
|
-
cursor: pointer;
|
|
36
|
-
white-space: nowrap;
|
|
37
|
-
line-height: 26px;
|
|
38
|
-
}
|
|
39
|
-
</style>
|