@varlet/ui 3.16.2 → 3.17.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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/es/action-sheet/style/index.mjs +1 -1
- package/es/index.bundle.mjs +13 -1
- package/es/index.mjs +11 -1
- package/es/segmented-button/SegmentedButton.mjs +141 -0
- package/es/segmented-button/SegmentedButtonSfc.css +0 -0
- package/es/segmented-button/index.mjs +12 -0
- package/es/segmented-button/props.mjs +17 -0
- package/es/segmented-button/provide.mjs +16 -0
- package/es/segmented-button/segmentedButton.css +1 -0
- package/es/segmented-button/style/index.mjs +5 -0
- package/es/segmented-buttons/SegmentedButtons.mjs +218 -0
- package/es/segmented-buttons/SegmentedButtonsSfc.css +0 -0
- package/es/segmented-buttons/index.mjs +12 -0
- package/es/segmented-buttons/props.mjs +38 -0
- package/es/segmented-buttons/provide.mjs +16 -0
- package/es/segmented-buttons/segmentedButtons.css +1 -0
- package/es/segmented-buttons/style/index.mjs +7 -0
- package/es/snackbar/style/index.mjs +1 -1
- package/es/style.mjs +2 -0
- package/es/themes/dark/index.mjs +4 -2
- package/es/themes/dark/segmentedButton.mjs +22 -0
- package/es/themes/dark/segmentedButtons.mjs +11 -0
- package/es/themes/md3-dark/index.mjs +4 -2
- package/es/themes/md3-dark/segmentedButton.mjs +22 -0
- package/es/themes/md3-dark/segmentedButtons.mjs +11 -0
- package/es/themes/md3-light/index.mjs +4 -2
- package/es/themes/md3-light/segmentedButton.mjs +22 -0
- package/es/themes/md3-light/segmentedButtons.mjs +11 -0
- package/es/utils/components.mjs +1 -1
- package/es/varlet.css +1 -1
- package/es/varlet.esm.js +7721 -8288
- package/highlight/web-types.en-US.json +156 -1
- package/highlight/web-types.zh-CN.json +156 -1
- package/lib/varlet.cjs.js +1985 -2667
- package/lib/varlet.css +1 -1
- package/package.json +7 -7
- package/types/index.d.ts +4 -0
- package/types/segmentedButton.d.ts +33 -0
- package/types/segmentedButtons.d.ts +58 -0
- package/types/styleVars.d.ts +23 -0
- package/umd/varlet.js +7 -7
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Varlet is a `Vue3` component library based on Material Design 2 and 3, supportin
|
|
|
26
26
|
|
|
27
27
|
### Features
|
|
28
28
|
|
|
29
|
-
- 🚀 Provide
|
|
29
|
+
- 🚀 Provide 70+ high quality general purpose components
|
|
30
30
|
- 🚀 Components are very lightweight
|
|
31
31
|
- 💪 Developed by Chinese, complete Chinese and English documentation and logistics support
|
|
32
32
|
- 🛠️ Support on-demand introduction
|
package/README.zh-CN.md
CHANGED
package/es/index.bundle.mjs
CHANGED
|
@@ -70,6 +70,8 @@ import Rate from './rate/index.mjs'
|
|
|
70
70
|
import Result from './result/index.mjs'
|
|
71
71
|
import Ripple from './ripple/index.mjs'
|
|
72
72
|
import Row from './row/index.mjs'
|
|
73
|
+
import SegmentedButton from './segmented-button/index.mjs'
|
|
74
|
+
import SegmentedButtons from './segmented-buttons/index.mjs'
|
|
73
75
|
import Select from './select/index.mjs'
|
|
74
76
|
import Signature from './signature/index.mjs'
|
|
75
77
|
import Skeleton from './skeleton/index.mjs'
|
|
@@ -166,6 +168,8 @@ export * from './rate/index.mjs'
|
|
|
166
168
|
export * from './result/index.mjs'
|
|
167
169
|
export * from './ripple/index.mjs'
|
|
168
170
|
export * from './row/index.mjs'
|
|
171
|
+
export * from './segmented-button/index.mjs'
|
|
172
|
+
export * from './segmented-buttons/index.mjs'
|
|
169
173
|
export * from './select/index.mjs'
|
|
170
174
|
export * from './signature/index.mjs'
|
|
171
175
|
export * from './skeleton/index.mjs'
|
|
@@ -262,6 +266,8 @@ import './rate/style/index.mjs'
|
|
|
262
266
|
import './result/style/index.mjs'
|
|
263
267
|
import './ripple/style/index.mjs'
|
|
264
268
|
import './row/style/index.mjs'
|
|
269
|
+
import './segmented-button/style/index.mjs'
|
|
270
|
+
import './segmented-buttons/style/index.mjs'
|
|
265
271
|
import './select/style/index.mjs'
|
|
266
272
|
import './signature/style/index.mjs'
|
|
267
273
|
import './skeleton/style/index.mjs'
|
|
@@ -286,7 +292,7 @@ import './tooltip/style/index.mjs'
|
|
|
286
292
|
import './uploader/style/index.mjs'
|
|
287
293
|
import './watermark/style/index.mjs'
|
|
288
294
|
|
|
289
|
-
const version = '3.
|
|
295
|
+
const version = '3.17.1'
|
|
290
296
|
|
|
291
297
|
function install(app) {
|
|
292
298
|
ActionSheet.install && app.use(ActionSheet)
|
|
@@ -361,6 +367,8 @@ function install(app) {
|
|
|
361
367
|
Result.install && app.use(Result)
|
|
362
368
|
Ripple.install && app.use(Ripple)
|
|
363
369
|
Row.install && app.use(Row)
|
|
370
|
+
SegmentedButton.install && app.use(SegmentedButton)
|
|
371
|
+
SegmentedButtons.install && app.use(SegmentedButtons)
|
|
364
372
|
Select.install && app.use(Select)
|
|
365
373
|
Signature.install && app.use(Signature)
|
|
366
374
|
Skeleton.install && app.use(Skeleton)
|
|
@@ -461,6 +469,8 @@ export {
|
|
|
461
469
|
Result,
|
|
462
470
|
Ripple,
|
|
463
471
|
Row,
|
|
472
|
+
SegmentedButton,
|
|
473
|
+
SegmentedButtons,
|
|
464
474
|
Select,
|
|
465
475
|
Signature,
|
|
466
476
|
Skeleton,
|
|
@@ -561,6 +571,8 @@ export default {
|
|
|
561
571
|
Result,
|
|
562
572
|
Ripple,
|
|
563
573
|
Row,
|
|
574
|
+
SegmentedButton,
|
|
575
|
+
SegmentedButtons,
|
|
564
576
|
Select,
|
|
565
577
|
Signature,
|
|
566
578
|
Skeleton,
|
package/es/index.mjs
CHANGED
|
@@ -70,6 +70,8 @@ import Rate from './rate/index.mjs'
|
|
|
70
70
|
import Result from './result/index.mjs'
|
|
71
71
|
import Ripple from './ripple/index.mjs'
|
|
72
72
|
import Row from './row/index.mjs'
|
|
73
|
+
import SegmentedButton from './segmented-button/index.mjs'
|
|
74
|
+
import SegmentedButtons from './segmented-buttons/index.mjs'
|
|
73
75
|
import Select from './select/index.mjs'
|
|
74
76
|
import Signature from './signature/index.mjs'
|
|
75
77
|
import Skeleton from './skeleton/index.mjs'
|
|
@@ -166,6 +168,8 @@ export * from './rate/index.mjs'
|
|
|
166
168
|
export * from './result/index.mjs'
|
|
167
169
|
export * from './ripple/index.mjs'
|
|
168
170
|
export * from './row/index.mjs'
|
|
171
|
+
export * from './segmented-button/index.mjs'
|
|
172
|
+
export * from './segmented-buttons/index.mjs'
|
|
169
173
|
export * from './select/index.mjs'
|
|
170
174
|
export * from './signature/index.mjs'
|
|
171
175
|
export * from './skeleton/index.mjs'
|
|
@@ -190,7 +194,7 @@ export * from './tooltip/index.mjs'
|
|
|
190
194
|
export * from './uploader/index.mjs'
|
|
191
195
|
export * from './watermark/index.mjs'
|
|
192
196
|
|
|
193
|
-
const version = '3.
|
|
197
|
+
const version = '3.17.1'
|
|
194
198
|
|
|
195
199
|
function install(app) {
|
|
196
200
|
ActionSheet.install && app.use(ActionSheet)
|
|
@@ -265,6 +269,8 @@ function install(app) {
|
|
|
265
269
|
Result.install && app.use(Result)
|
|
266
270
|
Ripple.install && app.use(Ripple)
|
|
267
271
|
Row.install && app.use(Row)
|
|
272
|
+
SegmentedButton.install && app.use(SegmentedButton)
|
|
273
|
+
SegmentedButtons.install && app.use(SegmentedButtons)
|
|
268
274
|
Select.install && app.use(Select)
|
|
269
275
|
Signature.install && app.use(Signature)
|
|
270
276
|
Skeleton.install && app.use(Skeleton)
|
|
@@ -365,6 +371,8 @@ export {
|
|
|
365
371
|
Result,
|
|
366
372
|
Ripple,
|
|
367
373
|
Row,
|
|
374
|
+
SegmentedButton,
|
|
375
|
+
SegmentedButtons,
|
|
368
376
|
Select,
|
|
369
377
|
Signature,
|
|
370
378
|
Skeleton,
|
|
@@ -465,6 +473,8 @@ export default {
|
|
|
465
473
|
Result,
|
|
466
474
|
Ripple,
|
|
467
475
|
Row,
|
|
476
|
+
SegmentedButton,
|
|
477
|
+
SegmentedButtons,
|
|
468
478
|
Select,
|
|
469
479
|
Signature,
|
|
470
480
|
Skeleton,
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { call, isArray } from "@varlet/shared";
|
|
2
|
+
import { computed, defineComponent, ref } from "vue";
|
|
3
|
+
import { useForm } from "../form/provide.mjs";
|
|
4
|
+
import Hover from "../hover/index.mjs";
|
|
5
|
+
import VarHoverOverlay, { useHoverOverlay } from "../hover-overlay/index.mjs";
|
|
6
|
+
import VarIcon from "../icon/index.mjs";
|
|
7
|
+
import Ripple from "../ripple/index.mjs";
|
|
8
|
+
import { createNamespace } from "../utils/components.mjs";
|
|
9
|
+
import { props } from "./props.mjs";
|
|
10
|
+
import { useSegmentedButtons } from "./provide.mjs";
|
|
11
|
+
const { name, n, classes } = createNamespace("segmented-button");
|
|
12
|
+
import { renderSlot as _renderSlot, resolveComponent as _resolveComponent, normalizeClass as _normalizeClass, createVNode as _createVNode, createCommentVNode as _createCommentVNode, createElementVNode as _createElementVNode, resolveDirective as _resolveDirective, openBlock as _openBlock, createElementBlock as _createElementBlock, withDirectives as _withDirectives } from "vue";
|
|
13
|
+
const _hoisted_1 = ["role", "aria-checked", "aria-disabled", "disabled", "tabindex"];
|
|
14
|
+
function __render__(_ctx, _cache) {
|
|
15
|
+
const _component_var_icon = _resolveComponent("var-icon");
|
|
16
|
+
const _component_var_hover_overlay = _resolveComponent("var-hover-overlay");
|
|
17
|
+
const _directive_ripple = _resolveDirective("ripple");
|
|
18
|
+
const _directive_hover = _resolveDirective("hover");
|
|
19
|
+
return _withDirectives((_openBlock(), _createElementBlock("button", {
|
|
20
|
+
ref: "segmentedButton",
|
|
21
|
+
role: _ctx.segmentedButtons.multiple.value ? "checkbox" : "radio",
|
|
22
|
+
"aria-checked": _ctx.checked,
|
|
23
|
+
"aria-disabled": _ctx.formDisabled || _ctx.disabled || _ctx.formReadonly || _ctx.readonly,
|
|
24
|
+
disabled: _ctx.formDisabled || _ctx.disabled,
|
|
25
|
+
tabindex: _ctx.formDisabled || _ctx.disabled ? void 0 : "0",
|
|
26
|
+
class: _normalizeClass(
|
|
27
|
+
_ctx.classes(
|
|
28
|
+
_ctx.n(),
|
|
29
|
+
_ctx.n("$--box"),
|
|
30
|
+
_ctx.n(`--${_ctx.segmentedButtons.size.value}`),
|
|
31
|
+
[_ctx.checked, _ctx.n("--checked"), _ctx.n("--unchecked")],
|
|
32
|
+
[_ctx.formDisabled || _ctx.disabled, _ctx.n("--disabled")]
|
|
33
|
+
)
|
|
34
|
+
),
|
|
35
|
+
type: "button",
|
|
36
|
+
onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleClick && _ctx.handleClick(...args)),
|
|
37
|
+
onFocus: _cache[1] || (_cache[1] = ($event) => _ctx.isFocusing = true),
|
|
38
|
+
onBlur: _cache[2] || (_cache[2] = ($event) => _ctx.isFocusing = false)
|
|
39
|
+
}, [
|
|
40
|
+
_createElementVNode(
|
|
41
|
+
"div",
|
|
42
|
+
{
|
|
43
|
+
class: _normalizeClass(_ctx.n("content"))
|
|
44
|
+
},
|
|
45
|
+
[
|
|
46
|
+
_ctx.segmentedButtons.checkmark.value && _ctx.checked ? _renderSlot(_ctx.$slots, "checkmark", {
|
|
47
|
+
key: 0,
|
|
48
|
+
checked: _ctx.checked
|
|
49
|
+
}, () => [
|
|
50
|
+
_createVNode(_component_var_icon, {
|
|
51
|
+
class: _normalizeClass(_ctx.n("icon")),
|
|
52
|
+
"var-segmented-button-cover": "",
|
|
53
|
+
name: "check"
|
|
54
|
+
}, null, 8, ["class"])
|
|
55
|
+
]) : _createCommentVNode("v-if", true),
|
|
56
|
+
_renderSlot(_ctx.$slots, "default", { checked: _ctx.checked })
|
|
57
|
+
],
|
|
58
|
+
2
|
|
59
|
+
/* CLASS */
|
|
60
|
+
),
|
|
61
|
+
_createVNode(_component_var_hover_overlay, {
|
|
62
|
+
hovering: !_ctx.formDisabled && !_ctx.disabled && _ctx.hovering,
|
|
63
|
+
focusing: !_ctx.formDisabled && !_ctx.disabled && _ctx.isFocusing
|
|
64
|
+
}, null, 8, ["hovering", "focusing"])
|
|
65
|
+
], 42, _hoisted_1)), [
|
|
66
|
+
[_directive_ripple, { disabled: _ctx.formReadonly || _ctx.readonly || _ctx.formDisabled || _ctx.disabled || !_ctx.ripple }],
|
|
67
|
+
[_directive_hover, _ctx.handleHovering, "desktop"]
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
const __sfc__ = defineComponent({
|
|
71
|
+
name,
|
|
72
|
+
directives: { Ripple, Hover },
|
|
73
|
+
components: { VarHoverOverlay, VarIcon },
|
|
74
|
+
props,
|
|
75
|
+
setup(props2) {
|
|
76
|
+
const segmentedButton = ref();
|
|
77
|
+
const isFocusing = ref(false);
|
|
78
|
+
const checked = ref(false);
|
|
79
|
+
const { segmentedButtons, bindSegmentedButtons } = useSegmentedButtons();
|
|
80
|
+
const { hovering, handleHovering } = useHoverOverlay();
|
|
81
|
+
const { form } = useForm();
|
|
82
|
+
const segmentedButtonProvider = {
|
|
83
|
+
checked: computed(() => checked.value),
|
|
84
|
+
disabled: computed(() => (form == null ? void 0 : form.disabled.value) || props2.disabled),
|
|
85
|
+
isFocusing: computed(() => isFocusing.value),
|
|
86
|
+
sync,
|
|
87
|
+
toggle,
|
|
88
|
+
move
|
|
89
|
+
};
|
|
90
|
+
bindSegmentedButtons(segmentedButtonProvider);
|
|
91
|
+
function handleClick(event) {
|
|
92
|
+
if ((form == null ? void 0 : form.disabled.value) || props2.disabled) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
call(props2.onClick, event);
|
|
96
|
+
toggle();
|
|
97
|
+
}
|
|
98
|
+
function toggle() {
|
|
99
|
+
if ((form == null ? void 0 : form.disabled.value) || props2.disabled) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if ((form == null ? void 0 : form.readonly.value) || props2.readonly) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
segmentedButtons.onClick(props2.checkedValue, checked.value);
|
|
106
|
+
}
|
|
107
|
+
function sync(v) {
|
|
108
|
+
const nextChecked = isArray(v) ? v.includes(props2.checkedValue) : v === props2.checkedValue;
|
|
109
|
+
checked.value = nextChecked;
|
|
110
|
+
return nextChecked;
|
|
111
|
+
}
|
|
112
|
+
function move(selectWhenFocused) {
|
|
113
|
+
if ((form == null ? void 0 : form.disabled.value) || props2.disabled) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
segmentedButton.value.focus();
|
|
117
|
+
if (selectWhenFocused && !(form == null ? void 0 : form.readonly.value) && !props2.readonly) {
|
|
118
|
+
segmentedButton.value.click();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
segmentedButton,
|
|
123
|
+
segmentedButtons,
|
|
124
|
+
isFocusing,
|
|
125
|
+
checked,
|
|
126
|
+
formDisabled: form == null ? void 0 : form.disabled,
|
|
127
|
+
formReadonly: form == null ? void 0 : form.readonly,
|
|
128
|
+
hovering,
|
|
129
|
+
n,
|
|
130
|
+
classes,
|
|
131
|
+
handleHovering,
|
|
132
|
+
handleClick,
|
|
133
|
+
toggle
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
__sfc__.render = __render__;
|
|
138
|
+
var stdin_default = __sfc__;
|
|
139
|
+
export {
|
|
140
|
+
stdin_default as default
|
|
141
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { withInstall, withPropsDefaultsSetter } from "../utils/components.mjs";
|
|
2
|
+
import { props as segmentedButtonProps } from "./props.mjs";
|
|
3
|
+
import SegmentedButton from "./SegmentedButton.mjs";
|
|
4
|
+
withInstall(SegmentedButton);
|
|
5
|
+
withPropsDefaultsSetter(SegmentedButton, segmentedButtonProps);
|
|
6
|
+
const _SegmentedButtonComponent = SegmentedButton;
|
|
7
|
+
var stdin_default = SegmentedButton;
|
|
8
|
+
export {
|
|
9
|
+
_SegmentedButtonComponent,
|
|
10
|
+
stdin_default as default,
|
|
11
|
+
segmentedButtonProps
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineListenerProp } from "../utils/components.mjs";
|
|
2
|
+
const props = {
|
|
3
|
+
checkedValue: {
|
|
4
|
+
type: [String, Number, Boolean, Object, Array],
|
|
5
|
+
default: void 0
|
|
6
|
+
},
|
|
7
|
+
disabled: Boolean,
|
|
8
|
+
readonly: Boolean,
|
|
9
|
+
ripple: {
|
|
10
|
+
type: Boolean,
|
|
11
|
+
default: true
|
|
12
|
+
},
|
|
13
|
+
onClick: defineListenerProp()
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
props
|
|
17
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { assert } from "@varlet/shared";
|
|
2
|
+
import { useParent } from "@varlet/use";
|
|
3
|
+
import { SEGMENTED_BUTTONS_BIND_BUTTON_KEY } from "../segmented-buttons/provide.mjs";
|
|
4
|
+
function useSegmentedButtons() {
|
|
5
|
+
const { bindParent, parentProvider } = useParent(
|
|
6
|
+
SEGMENTED_BUTTONS_BIND_BUTTON_KEY
|
|
7
|
+
);
|
|
8
|
+
assert(!!bindParent, "SegmentedButton", "<var-segmented-button/> must in <var-segmented-buttons/>");
|
|
9
|
+
return {
|
|
10
|
+
segmentedButtons: parentProvider,
|
|
11
|
+
bindSegmentedButtons: bindParent
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
useSegmentedButtons
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root { --segmented-button-text-color: var(--color-text); --segmented-button-checked-background: hsla(var(--hsl-primary), 0.2); --segmented-button-checked-text-color: var(--color-primary); --segmented-button-disabled-background: var(--color-disabled); --segmented-button-disabled-color: var(--color-text-disabled); --segmented-button-mini-padding: 0 8px; --segmented-button-small-padding: 0 12px; --segmented-button-normal-padding: 0 16px; --segmented-button-large-padding: 0 22px; --segmented-button-mini-height: 20px; --segmented-button-small-height: 28px; --segmented-button-normal-height: 36px; --segmented-button-large-height: 44px; --segmented-button-mini-font-size: var(--font-size-xs); --segmented-button-small-font-size: var(--font-size-sm); --segmented-button-normal-font-size: var(--font-size-md); --segmented-button-large-font-size: var(--font-size-lg);}.var-segmented-button { position: relative; display: inline-flex; justify-content: center; align-items: center; outline: none; border: none; background-color: transparent; color: var(--segmented-button-text-color); user-select: none; cursor: pointer; font-family: inherit; white-space: nowrap; transition: background-color 0.25s, color 0.25s; -webkit-tap-highlight-color: transparent;}.var-segmented-button__content { display: inline-flex; align-items: center; justify-content: center;}.var-segmented-button__icon[var-segmented-button-cover] { font-size: 18px; margin-right: 6px;}.var-segmented-button--normal { height: var(--segmented-button-normal-height); padding: var(--segmented-button-normal-padding); font-size: var(--segmented-button-normal-font-size);}.var-segmented-button--large { height: var(--segmented-button-large-height); padding: var(--segmented-button-large-padding); font-size: var(--segmented-button-large-font-size);}.var-segmented-button--small { height: var(--segmented-button-small-height); padding: var(--segmented-button-small-padding); font-size: var(--segmented-button-small-font-size);}.var-segmented-button--mini { height: var(--segmented-button-mini-height); padding: var(--segmented-button-mini-padding); font-size: var(--segmented-button-mini-font-size);}.var-segmented-button--checked { background-color: var(--segmented-button-checked-background); color: var(--segmented-button-checked-text-color);}.var-segmented-button--disabled { color: var(--segmented-button-disabled-color); cursor: not-allowed;}.var-segmented-button--checked.var-segmented-button--disabled { background-color: var(--segmented-button-disabled-background);}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { call, callOrReturn, isArray } from "@varlet/shared";
|
|
2
|
+
import { useEventListener } from "@varlet/use";
|
|
3
|
+
import { computed, defineComponent, nextTick, watch } from "vue";
|
|
4
|
+
import VarFormDetails from "../form-details/index.mjs";
|
|
5
|
+
import { useForm } from "../form/provide.mjs";
|
|
6
|
+
import VarSegmentedButton from "../segmented-button/index.mjs";
|
|
7
|
+
import { createNamespace, MaybeVNode, useValidation } from "../utils/components.mjs";
|
|
8
|
+
import {
|
|
9
|
+
props
|
|
10
|
+
} from "./props.mjs";
|
|
11
|
+
import { useSegmentedButtons } from "./provide.mjs";
|
|
12
|
+
const { name, n, classes } = createNamespace("segmented-buttons");
|
|
13
|
+
import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, resolveComponent as _resolveComponent, createVNode as _createVNode, withCtx as _withCtx, createBlock as _createBlock, createCommentVNode as _createCommentVNode, renderSlot as _renderSlot, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode } from "vue";
|
|
14
|
+
const _hoisted_1 = ["role"];
|
|
15
|
+
function __render__(_ctx, _cache) {
|
|
16
|
+
const _component_maybe_v_node = _resolveComponent("maybe-v-node");
|
|
17
|
+
const _component_var_segmented_button = _resolveComponent("var-segmented-button");
|
|
18
|
+
const _component_var_form_details = _resolveComponent("var-form-details");
|
|
19
|
+
return _openBlock(), _createElementBlock(
|
|
20
|
+
"div",
|
|
21
|
+
{
|
|
22
|
+
class: _normalizeClass(_ctx.n("wrap"))
|
|
23
|
+
},
|
|
24
|
+
[
|
|
25
|
+
_createElementVNode("div", {
|
|
26
|
+
role: _ctx.multiple ? "group" : "radiogroup",
|
|
27
|
+
class: _normalizeClass([_ctx.n(), _ctx.hasError ? _ctx.n("--error") : null])
|
|
28
|
+
}, [
|
|
29
|
+
_ctx.options.length ? (_openBlock(true), _createElementBlock(
|
|
30
|
+
_Fragment,
|
|
31
|
+
{ key: 0 },
|
|
32
|
+
_renderList(_ctx.options, (option) => {
|
|
33
|
+
return _openBlock(), _createBlock(_component_var_segmented_button, {
|
|
34
|
+
key: _ctx.getOptionValue(option),
|
|
35
|
+
"checked-value": _ctx.getOptionValue(option),
|
|
36
|
+
disabled: option.disabled,
|
|
37
|
+
ripple: option.ripple
|
|
38
|
+
}, {
|
|
39
|
+
default: _withCtx(() => [
|
|
40
|
+
_createVNode(_component_maybe_v_node, {
|
|
41
|
+
is: _ctx.renderOptionLabel(option)
|
|
42
|
+
}, null, 8, ["is"])
|
|
43
|
+
]),
|
|
44
|
+
_: 2
|
|
45
|
+
/* DYNAMIC */
|
|
46
|
+
}, 1032, ["checked-value", "disabled", "ripple"]);
|
|
47
|
+
}),
|
|
48
|
+
128
|
|
49
|
+
/* KEYED_FRAGMENT */
|
|
50
|
+
)) : _createCommentVNode("v-if", true),
|
|
51
|
+
_renderSlot(_ctx.$slots, "default")
|
|
52
|
+
], 10, _hoisted_1),
|
|
53
|
+
_createVNode(_component_var_form_details, { "error-message": _ctx.errorMessage }, null, 8, ["error-message"])
|
|
54
|
+
],
|
|
55
|
+
2
|
|
56
|
+
/* CLASS */
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
const __sfc__ = defineComponent({
|
|
60
|
+
name,
|
|
61
|
+
components: {
|
|
62
|
+
VarFormDetails,
|
|
63
|
+
VarSegmentedButton,
|
|
64
|
+
MaybeVNode
|
|
65
|
+
},
|
|
66
|
+
props,
|
|
67
|
+
setup(props2) {
|
|
68
|
+
const { length, buttons, bindButtons } = useSegmentedButtons();
|
|
69
|
+
const { bindForm } = useForm();
|
|
70
|
+
const {
|
|
71
|
+
errorMessage,
|
|
72
|
+
validateWithTrigger: vt,
|
|
73
|
+
validate: v,
|
|
74
|
+
// expose
|
|
75
|
+
resetValidation
|
|
76
|
+
} = useValidation();
|
|
77
|
+
const segmentedButtonsProvider = {
|
|
78
|
+
multiple: computed(() => props2.multiple),
|
|
79
|
+
checkmark: computed(() => props2.checkmark),
|
|
80
|
+
size: computed(() => props2.size),
|
|
81
|
+
onClick
|
|
82
|
+
};
|
|
83
|
+
const segmentedButtonsValidationProvider = {
|
|
84
|
+
validate,
|
|
85
|
+
reset,
|
|
86
|
+
resetValidation
|
|
87
|
+
};
|
|
88
|
+
watch(() => props2.modelValue, syncButtons);
|
|
89
|
+
watch(() => length.value, syncButtons);
|
|
90
|
+
bindButtons(segmentedButtonsProvider);
|
|
91
|
+
call(bindForm, segmentedButtonsValidationProvider);
|
|
92
|
+
useEventListener(() => window, "keydown", handleKeydown);
|
|
93
|
+
useEventListener(() => window, "keyup", handleKeyup);
|
|
94
|
+
function getSafeModelValue() {
|
|
95
|
+
return props2.multiple ? isArray(props2.modelValue) ? props2.modelValue : [] : props2.modelValue;
|
|
96
|
+
}
|
|
97
|
+
function isChecked(value) {
|
|
98
|
+
const modelValue = getSafeModelValue();
|
|
99
|
+
return isArray(modelValue) ? modelValue.includes(value) : modelValue === value;
|
|
100
|
+
}
|
|
101
|
+
function renderOptionLabel(option) {
|
|
102
|
+
return callOrReturn(option[props2.labelKey], option, isChecked(getOptionValue(option)));
|
|
103
|
+
}
|
|
104
|
+
function getOptionValue(option) {
|
|
105
|
+
return option[props2.valueKey];
|
|
106
|
+
}
|
|
107
|
+
function handleKeydown(event) {
|
|
108
|
+
const focusingButtonIndex = buttons.findIndex(({ isFocusing }) => isFocusing.value);
|
|
109
|
+
if (focusingButtonIndex === -1) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const hasMoveableButton = buttons.some(
|
|
113
|
+
({ disabled }, index) => index === focusingButtonIndex ? false : !disabled.value
|
|
114
|
+
);
|
|
115
|
+
if (!hasMoveableButton) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (["ArrowLeft", "ArrowRight"].includes(event.key)) {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
}
|
|
121
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
}
|
|
124
|
+
if (event.key === "ArrowLeft") {
|
|
125
|
+
moveButton(focusingButtonIndex, "prev");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (event.key === "ArrowRight") {
|
|
129
|
+
moveButton(focusingButtonIndex, "next");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (event.key === "Enter") {
|
|
133
|
+
buttons[focusingButtonIndex].toggle();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function handleKeyup(event) {
|
|
137
|
+
const focusingButtonIndex = buttons.findIndex(({ isFocusing }) => isFocusing.value);
|
|
138
|
+
if (focusingButtonIndex === -1) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (event.key !== " ") {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
buttons[focusingButtonIndex].toggle();
|
|
146
|
+
}
|
|
147
|
+
function moveButton(fromIndex, method) {
|
|
148
|
+
while (true) {
|
|
149
|
+
fromIndex += method === "prev" ? -1 : 1;
|
|
150
|
+
if (fromIndex < 0) {
|
|
151
|
+
fromIndex = buttons.length - 1;
|
|
152
|
+
}
|
|
153
|
+
if (fromIndex > buttons.length - 1) {
|
|
154
|
+
fromIndex = 0;
|
|
155
|
+
}
|
|
156
|
+
const button = buttons[fromIndex];
|
|
157
|
+
if (!button.disabled.value) {
|
|
158
|
+
button.move(!props2.multiple);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function validateWithTrigger(trigger) {
|
|
164
|
+
nextTick(() => {
|
|
165
|
+
vt(props2.validateTrigger, trigger, props2.rules, getSafeModelValue());
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function onClick(changedValue, checked) {
|
|
169
|
+
validateWithTrigger("onClick");
|
|
170
|
+
if (!props2.multiple) {
|
|
171
|
+
if (checked) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
change(changedValue);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const modelValue = getSafeModelValue();
|
|
178
|
+
if (checked) {
|
|
179
|
+
change(modelValue.filter((value) => value !== changedValue));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
change([...modelValue, changedValue]);
|
|
183
|
+
}
|
|
184
|
+
function syncButtons() {
|
|
185
|
+
const modelValue = getSafeModelValue();
|
|
186
|
+
buttons.forEach(({ sync }) => sync(modelValue));
|
|
187
|
+
}
|
|
188
|
+
function change(changedModelValue) {
|
|
189
|
+
call(props2["onUpdate:modelValue"], changedModelValue);
|
|
190
|
+
call(props2.onChange, changedModelValue);
|
|
191
|
+
validateWithTrigger("onChange");
|
|
192
|
+
}
|
|
193
|
+
const hasError = computed(() => !!errorMessage.value);
|
|
194
|
+
function validate() {
|
|
195
|
+
return v(props2.rules, getSafeModelValue());
|
|
196
|
+
}
|
|
197
|
+
function reset() {
|
|
198
|
+
call(props2["onUpdate:modelValue"], props2.multiple ? [] : void 0);
|
|
199
|
+
resetValidation();
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
errorMessage,
|
|
203
|
+
n,
|
|
204
|
+
classes,
|
|
205
|
+
renderOptionLabel,
|
|
206
|
+
getOptionValue,
|
|
207
|
+
hasError,
|
|
208
|
+
validate,
|
|
209
|
+
reset,
|
|
210
|
+
resetValidation
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
__sfc__.render = __render__;
|
|
215
|
+
var stdin_default = __sfc__;
|
|
216
|
+
export {
|
|
217
|
+
stdin_default as default
|
|
218
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { withInstall, withPropsDefaultsSetter } from "../utils/components.mjs";
|
|
2
|
+
import { props as segmentedButtonsProps } from "./props.mjs";
|
|
3
|
+
import SegmentedButtons from "./SegmentedButtons.mjs";
|
|
4
|
+
withInstall(SegmentedButtons);
|
|
5
|
+
withPropsDefaultsSetter(SegmentedButtons, segmentedButtonsProps);
|
|
6
|
+
const _SegmentedButtonsComponent = SegmentedButtons;
|
|
7
|
+
var stdin_default = SegmentedButtons;
|
|
8
|
+
export {
|
|
9
|
+
_SegmentedButtonsComponent,
|
|
10
|
+
stdin_default as default,
|
|
11
|
+
segmentedButtonsProps
|
|
12
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineListenerProp } from "../utils/components.mjs";
|
|
2
|
+
const props = {
|
|
3
|
+
modelValue: {
|
|
4
|
+
type: [String, Number, Boolean, Object, Array],
|
|
5
|
+
default: void 0
|
|
6
|
+
},
|
|
7
|
+
options: {
|
|
8
|
+
type: Array,
|
|
9
|
+
default: () => []
|
|
10
|
+
},
|
|
11
|
+
labelKey: {
|
|
12
|
+
type: String,
|
|
13
|
+
default: "label"
|
|
14
|
+
},
|
|
15
|
+
valueKey: {
|
|
16
|
+
type: String,
|
|
17
|
+
default: "value"
|
|
18
|
+
},
|
|
19
|
+
multiple: Boolean,
|
|
20
|
+
checkmark: {
|
|
21
|
+
type: Boolean,
|
|
22
|
+
default: true
|
|
23
|
+
},
|
|
24
|
+
size: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: "normal"
|
|
27
|
+
},
|
|
28
|
+
validateTrigger: {
|
|
29
|
+
type: Array,
|
|
30
|
+
default: () => ["onChange"]
|
|
31
|
+
},
|
|
32
|
+
rules: [Array, Function, Object],
|
|
33
|
+
onChange: defineListenerProp(),
|
|
34
|
+
"onUpdate:modelValue": defineListenerProp()
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
props
|
|
38
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useChildren } from "@varlet/use";
|
|
2
|
+
const SEGMENTED_BUTTONS_BIND_BUTTON_KEY = /* @__PURE__ */ Symbol("SEGMENTED_BUTTONS_BIND_BUTTON_KEY");
|
|
3
|
+
function useSegmentedButtons() {
|
|
4
|
+
const { bindChildren, childProviders, length } = useChildren(
|
|
5
|
+
SEGMENTED_BUTTONS_BIND_BUTTON_KEY
|
|
6
|
+
);
|
|
7
|
+
return {
|
|
8
|
+
length,
|
|
9
|
+
buttons: childProviders,
|
|
10
|
+
bindButtons: bindChildren
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
SEGMENTED_BUTTONS_BIND_BUTTON_KEY,
|
|
15
|
+
useSegmentedButtons
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root { --segmented-buttons-border-color: var(--color-outline); --segmented-buttons-border-radius: 4px; --segmented-buttons-border-width: 1px; --segmented-buttons-error-border-color: var(--color-danger); --segmented-buttons-error-color: var(--color-danger); --segmented-buttons-error-checked-background: hsla(var(--hsl-danger), 0.12);}.var-segmented-buttons { display: inline-flex; max-width: 100%; overflow: hidden; border: var(--segmented-buttons-border-width) solid var(--segmented-buttons-border-color); border-radius: var(--segmented-buttons-border-radius);}.var-segmented-buttons__wrap { display: inline-flex; flex-direction: column; align-items: flex-start;}.var-segmented-buttons .var-segmented-button:not(:last-child) { border-right: var(--segmented-buttons-border-width) solid var(--segmented-buttons-border-color);}.var-segmented-buttons--error { border-color: var(--segmented-buttons-error-border-color);}.var-segmented-buttons--error .var-segmented-button { color: var(--segmented-buttons-error-color);}.var-segmented-buttons--error .var-segmented-button:not(:last-child) { border-right-color: var(--segmented-buttons-error-border-color);}.var-segmented-buttons--error .var-segmented-button--checked { background-color: var(--segmented-buttons-error-checked-background); color: var(--segmented-buttons-error-color);}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import '../../styles/common.css'
|
|
2
|
+
import '../../form-details/formDetails.css'
|
|
3
|
+
import '../../ripple/ripple.css'
|
|
4
|
+
import '../../hover-overlay/hoverOverlay.css'
|
|
5
|
+
import '../../segmented-button/segmentedButton.css'
|
|
6
|
+
import '../segmentedButtons.css'
|
|
7
|
+
import '../SegmentedButtonsSfc.css'
|
package/es/style.mjs
CHANGED
|
@@ -70,6 +70,8 @@ import './rate/style/index.mjs'
|
|
|
70
70
|
import './result/style/index.mjs'
|
|
71
71
|
import './ripple/style/index.mjs'
|
|
72
72
|
import './row/style/index.mjs'
|
|
73
|
+
import './segmented-button/style/index.mjs'
|
|
74
|
+
import './segmented-buttons/style/index.mjs'
|
|
73
75
|
import './select/style/index.mjs'
|
|
74
76
|
import './signature/style/index.mjs'
|
|
75
77
|
import './skeleton/style/index.mjs'
|