pxd 0.0.55 → 0.0.60
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 +18 -4
- package/dist/components/_internal/fragment-container.vue +3 -2
- package/dist/components/active-graph/index.d.vue.ts +2 -3
- package/dist/components/active-graph/index.vue +23 -16
- package/dist/components/active-graph/types.d.ts +4 -3
- package/dist/components/avatar/index.vue +19 -10
- package/dist/components/avatar/types.d.ts +0 -12
- package/dist/components/avatar-group/index.d.vue.ts +2 -2
- package/dist/components/avatar-group/index.vue +4 -3
- package/dist/components/avatar-group/types.d.ts +11 -0
- package/dist/components/badge/index.d.vue.ts +1 -1
- package/dist/components/badge/index.vue +47 -3
- package/dist/components/badge/types.d.ts +24 -1
- package/dist/components/book/index.vue +3 -2
- package/dist/components/browser/index.vue +6 -2
- package/dist/components/button/index.d.vue.ts +1 -1
- package/dist/components/button/index.vue +60 -12
- package/dist/components/carousel/index.d.vue.ts +24 -2
- package/dist/components/carousel/index.vue +341 -28
- package/dist/components/carousel/types.d.ts +2 -2
- package/dist/components/carousel-item/index.d.vue.ts +13 -0
- package/dist/components/carousel-item/index.vue +49 -0
- package/dist/components/checkbox/index.d.vue.ts +1 -5
- package/dist/components/checkbox/index.vue +66 -31
- package/dist/components/checkbox/types.d.ts +2 -14
- package/dist/components/checkbox-group/index.d.vue.ts +2 -7
- package/dist/components/checkbox-group/index.vue +11 -29
- package/dist/components/checkbox-group/types.d.ts +12 -0
- package/dist/components/chip/index.d.vue.ts +1 -1
- package/dist/components/chip/index.vue +31 -2
- package/dist/components/choicebox/index.d.vue.ts +11 -5
- package/dist/components/choicebox/index.vue +36 -54
- package/dist/components/choicebox/types.d.ts +11 -18
- package/dist/components/choicebox-item/index.d.vue.ts +16 -0
- package/dist/components/choicebox-item/index.vue +67 -0
- package/dist/components/choicebox-item/types.d.ts +12 -0
- package/dist/components/collapse/index.d.vue.ts +5 -4
- package/dist/components/collapse/index.vue +47 -30
- package/dist/components/collapse/types.d.ts +2 -5
- package/dist/components/collapse-group/index.d.vue.ts +2 -4
- package/dist/components/collapse-group/index.vue +8 -20
- package/dist/components/collapse-group/types.d.ts +6 -0
- package/dist/components/command-menu/index.vue +6 -7
- package/dist/components/command-menu/types.d.ts +0 -5
- package/dist/components/command-menu-group/index.d.vue.ts +1 -1
- package/dist/components/command-menu-group/index.vue +3 -2
- package/dist/components/command-menu-group/types.d.ts +5 -0
- package/dist/components/config-provider/index.d.vue.ts +2 -2
- package/dist/components/config-provider/index.vue +6 -4
- package/dist/components/countdown/index.vue +3 -2
- package/dist/components/countdown/types.d.ts +2 -2
- package/dist/components/dash-line/index.vue +3 -1
- package/dist/components/description/index.d.vue.ts +1 -1
- package/dist/components/description/index.vue +8 -7
- package/dist/components/description/types.d.ts +1 -1
- package/dist/components/drawer/index.d.vue.ts +3 -2
- package/dist/components/drawer/index.vue +20 -15
- package/dist/components/drawer/types.d.ts +3 -3
- package/dist/components/ellipsis-text/index.d.vue.ts +14 -0
- package/dist/components/ellipsis-text/index.vue +242 -0
- package/dist/components/ellipsis-text/types.d.ts +14 -0
- package/dist/components/empty-state/index.vue +6 -2
- package/dist/components/error/index.d.vue.ts +1 -3
- package/dist/components/error/index.vue +21 -6
- package/dist/components/error/types.d.ts +7 -1
- package/dist/components/fader/index.vue +30 -11
- package/dist/components/fader/types.d.ts +2 -2
- package/dist/components/gauge/index.vue +7 -2
- package/dist/components/grid/index.vue +9 -4
- package/dist/components/grid/types.d.ts +0 -5
- package/dist/components/grid-item/index.d.vue.ts +1 -1
- package/dist/components/grid-item/index.vue +16 -8
- package/dist/components/grid-item/types.d.ts +6 -0
- package/dist/components/hold-button/index.d.vue.ts +2 -2
- package/dist/components/hold-button/index.vue +7 -4
- package/dist/components/index.d.ts +7 -3
- package/dist/components/index.js +7 -3
- package/dist/components/input/index.d.vue.ts +8 -8
- package/dist/components/input/index.vue +54 -21
- package/dist/components/input/types.d.ts +7 -10
- package/dist/components/intersection-observer/index.d.vue.ts +0 -1
- package/dist/components/intersection-observer/index.vue +12 -3
- package/dist/components/kbd/index.vue +1 -1
- package/dist/components/link-button/index.d.vue.ts +1 -1
- package/dist/components/link-button/index.vue +5 -4
- package/dist/components/link-button/types.d.ts +1 -1
- package/dist/components/list/index.d.vue.ts +8 -5
- package/dist/components/list/index.vue +50 -54
- package/dist/components/list/types.d.ts +3 -20
- package/dist/components/list-item/index.d.vue.ts +4 -3
- package/dist/components/list-item/index.vue +44 -18
- package/dist/components/list-item/types.d.ts +15 -0
- package/dist/components/loading-bar/index.vue +33 -2
- package/dist/components/loading-bar/types.d.ts +1 -1
- package/dist/components/loading-dots/index.vue +3 -2
- package/dist/components/menu/index.d.vue.ts +5 -2
- package/dist/components/menu/index.vue +4 -1
- package/dist/components/menu/types.d.ts +5 -0
- package/dist/components/message/index.d.vue.ts +11 -8
- package/dist/components/message/index.vue +4 -12
- package/dist/components/message/types.d.ts +1 -12
- package/dist/components/message-item/index.d.vue.ts +1 -3
- package/dist/components/message-item/index.vue +13 -7
- package/dist/components/message-item/types.d.ts +11 -0
- package/dist/components/modal/index.d.vue.ts +3 -2
- package/dist/components/modal/index.vue +17 -13
- package/dist/components/modal/types.d.ts +3 -3
- package/dist/components/noise-background/index.vue +4 -3
- package/dist/components/note/index.d.vue.ts +1 -2
- package/dist/components/note/index.vue +81 -29
- package/dist/components/note/types.d.ts +10 -2
- package/dist/components/number-input/index.d.vue.ts +5 -4
- package/dist/components/number-input/index.vue +36 -6
- package/dist/components/number-input/types.d.ts +2 -0
- package/dist/components/overlay/index.vue +1 -1
- package/dist/components/overlay/types.d.ts +1 -1
- package/dist/components/pagination/index.vue +5 -3
- package/dist/components/pin-input/index.d.vue.ts +7 -2
- package/dist/components/pin-input/index.vue +60 -23
- package/dist/components/pin-input/types.d.ts +0 -4
- package/dist/components/placeholder/index.vue +2 -1
- package/dist/components/popover/index.d.vue.ts +1 -1
- package/dist/components/popover/index.vue +116 -78
- package/dist/components/popover/types.d.ts +2 -0
- package/dist/components/progress/index.d.vue.ts +1 -1
- package/dist/components/progress/index.vue +15 -2
- package/dist/components/project-banner/index.d.vue.ts +18 -0
- package/dist/components/project-banner/index.vue +59 -0
- package/dist/components/project-banner/types.d.ts +8 -0
- package/dist/components/radio/index.vue +62 -20
- package/dist/components/radio/types.d.ts +1 -14
- package/dist/components/radio-group/index.d.vue.ts +2 -4
- package/dist/components/radio-group/index.vue +11 -16
- package/dist/components/radio-group/types.d.ts +12 -0
- package/dist/components/resizable/types.d.ts +5 -10
- package/dist/components/resizable-handle/index.vue +1 -1
- package/dist/components/resizable-panel/index.d.vue.ts +1 -1
- package/dist/components/resizable-panel/index.vue +7 -2
- package/dist/components/resizable-panel/types.d.ts +4 -0
- package/dist/components/scrollable/index.d.vue.ts +29 -0
- package/dist/components/scrollable/index.vue +98 -83
- package/dist/components/scrollable/types.d.ts +19 -5
- package/dist/components/skeleton/index.vue +24 -1
- package/dist/components/slider/index.d.vue.ts +6 -6
- package/dist/components/slider/index.vue +86 -44
- package/dist/components/slider/types.d.ts +1 -1
- package/dist/components/snippet/index.vue +28 -2
- package/dist/components/spinner/index.vue +4 -2
- package/dist/components/stack/index.d.vue.ts +2 -2
- package/dist/components/stack/index.vue +35 -3
- package/dist/components/stack/types.d.ts +1 -1
- package/dist/components/status-dot/index.vue +5 -1
- package/dist/components/switch/index.d.vue.ts +10 -1
- package/dist/components/switch/index.vue +35 -44
- package/dist/components/switch/types.d.ts +4 -12
- package/dist/components/switch-item/index.d.vue.ts +14 -0
- package/dist/components/switch-item/index.vue +79 -0
- package/dist/components/switch-item/types.d.ts +9 -0
- package/dist/components/teleport/index.d.vue.ts +1 -1
- package/dist/components/teleport/index.vue +1 -1
- package/dist/components/teleport/types.d.ts +1 -1
- package/dist/components/text/index.d.vue.ts +1 -2
- package/dist/components/text/index.vue +36 -22
- package/dist/components/text/types.d.ts +1 -1
- package/dist/components/textarea/index.d.vue.ts +4 -4
- package/dist/components/textarea/index.vue +33 -4
- package/dist/components/textarea/types.d.ts +0 -1
- package/dist/components/time-picker/index.d.vue.ts +1 -2
- package/dist/components/time-picker/index.vue +43 -9
- package/dist/components/time-picker/types.d.ts +1 -2
- package/dist/components/toggle/index.vue +11 -10
- package/dist/components/toggle-button/index.d.vue.ts +22 -0
- package/dist/components/toggle-button/index.vue +110 -0
- package/dist/components/toggle-button/types.d.ts +16 -0
- package/dist/components/{choicebox-group → toggle-button-group}/index.d.vue.ts +5 -5
- package/dist/components/toggle-button-group/index.vue +68 -0
- package/dist/components/toggle-button-group/types.d.ts +22 -0
- package/dist/components/tooltip/index.d.vue.ts +2 -0
- package/dist/components/tooltip/index.vue +9 -3
- package/dist/components/tooltip/types.d.ts +2 -0
- package/dist/components/virtual-list/index.d.vue.ts +25 -4
- package/dist/components/virtual-list/index.vue +66 -10
- package/dist/components/virtual-list/types.d.ts +9 -4
- package/dist/composables/index.d.ts +2 -2
- package/dist/composables/index.js +2 -2
- package/dist/composables/use-browser-observer.d.ts +5 -5
- package/dist/composables/use-browser-observer.js +23 -20
- package/dist/composables/use-copy-click.js +4 -0
- package/dist/composables/use-countdown.d.ts +2 -2
- package/dist/composables/use-focus-trap.d.ts +6 -2
- package/dist/composables/use-focus-trap.js +19 -7
- package/dist/composables/use-forward-ref-expose.d.ts +2 -0
- package/dist/composables/use-forward-ref-expose.js +41 -0
- package/dist/composables/use-message.d.ts +3 -6
- package/dist/composables/use-model-value.d.ts +9 -8
- package/dist/composables/use-popover-responsive.d.ts +2 -2
- package/dist/composables/use-popover-responsive.js +3 -3
- package/dist/composables/use-repeat-action.js +2 -2
- package/dist/composables/use-virtual-list.d.ts +21 -12
- package/dist/composables/use-virtual-list.js +90 -158
- package/dist/composables/use-window-size.d.ts +4 -0
- package/dist/composables/use-window-size.js +27 -0
- package/dist/contexts/avatar.d.ts +5 -2
- package/dist/contexts/carousel.d.ts +4 -4
- package/dist/contexts/carousel.js +1 -1
- package/dist/contexts/checkbox.d.ts +7 -2
- package/dist/contexts/choicebox.d.ts +8 -4
- package/dist/contexts/choicebox.js +1 -4
- package/dist/contexts/collapse.d.ts +5 -6
- package/dist/contexts/collapse.js +1 -1
- package/dist/contexts/config-provider.d.ts +5 -0
- package/dist/{composables/use-config-provider-context.js → contexts/config-provider.js} +8 -5
- package/dist/contexts/radio.d.ts +8 -2
- package/dist/contexts/switch.d.ts +8 -4
- package/dist/contexts/switch.js +1 -2
- package/dist/contexts/toggle-button.d.ts +7 -0
- package/dist/contexts/toggle-button.js +2 -0
- package/dist/styles/source.css +14 -2
- package/dist/styles/styles.css +2 -2
- package/dist/styles/tw.css +14 -2
- package/dist/types/shared/props.d.ts +1 -3
- package/dist/types/shared/utils.d.ts +0 -3
- package/dist/utils/context.d.ts +1 -0
- package/dist/utils/get.d.ts +1 -0
- package/dist/utils/get.js +14 -0
- package/dist/utils/responsive.js +2 -1
- package/dist/utils/throttle.js +9 -7
- package/dist/utils/uid.d.ts +1 -1
- package/dist/utils/uid.js +2 -2
- package/package.json +23 -21
- package/volar.d.ts +7 -3
- package/dist/components/badge/cn.d.ts +0 -90
- package/dist/components/badge/cn.js +0 -44
- package/dist/components/button/cn.d.ts +0 -121
- package/dist/components/button/cn.js +0 -55
- package/dist/components/carousel-group/index.d.vue.ts +0 -35
- package/dist/components/carousel-group/index.vue +0 -368
- package/dist/components/checkbox/cn.d.ts +0 -67
- package/dist/components/checkbox/cn.js +0 -31
- package/dist/components/chip/cn.d.ts +0 -49
- package/dist/components/chip/cn.js +0 -26
- package/dist/components/choicebox-group/index.vue +0 -65
- package/dist/components/error/cn.d.ts +0 -22
- package/dist/components/error/cn.js +0 -15
- package/dist/components/input/cn.d.ts +0 -73
- package/dist/components/input/cn.js +0 -36
- package/dist/components/list-item/cn.d.ts +0 -22
- package/dist/components/list-item/cn.js +0 -15
- package/dist/components/loading-bar/cn.d.ts +0 -70
- package/dist/components/loading-bar/cn.js +0 -32
- package/dist/components/note/cn.d.ts +0 -121
- package/dist/components/note/cn.js +0 -66
- package/dist/components/pin-input/cn.d.ts +0 -46
- package/dist/components/pin-input/cn.js +0 -25
- package/dist/components/progress/cn.d.ts +0 -19
- package/dist/components/progress/cn.js +0 -14
- package/dist/components/radio/cn.d.ts +0 -46
- package/dist/components/radio/cn.js +0 -42
- package/dist/components/skeleton/cn.d.ts +0 -43
- package/dist/components/skeleton/cn.js +0 -24
- package/dist/components/snippet/cn.d.ts +0 -52
- package/dist/components/snippet/cn.js +0 -27
- package/dist/components/stack/cn.d.ts +0 -70
- package/dist/components/stack/cn.js +0 -33
- package/dist/components/switch/cn.d.ts +0 -16
- package/dist/components/switch/cn.js +0 -13
- package/dist/components/switch-group/index.d.vue.ts +0 -23
- package/dist/components/switch-group/index.vue +0 -54
- package/dist/components/text/cn.d.ts +0 -67
- package/dist/components/text/cn.js +0 -34
- package/dist/components/textarea/cn.d.ts +0 -58
- package/dist/components/textarea/cn.js +0 -30
- package/dist/composables/use-config-provider-context.d.ts +0 -3
- package/dist/composables/use-unique-id-context.d.ts +0 -2
- package/dist/composables/use-unique-id-context.js +0 -11
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, onBeforeUnmount, shallowRef } from "vue";
|
|
3
|
-
import { useConfigProvider } from "../../
|
|
3
|
+
import { useConfigProvider } from "../../contexts/config-provider";
|
|
4
4
|
import { useModelValue } from "../../composables/use-model-value";
|
|
5
5
|
import { cachedOff, cachedOn, once } from "../../utils/event";
|
|
6
6
|
import { getFallbackValue } from "../../utils/get";
|
|
7
|
+
import { NOOP } from "../../utils/event";
|
|
8
|
+
import { throttleByRaf } from "../../utils/throttle";
|
|
7
9
|
defineOptions({
|
|
8
10
|
name: "PSlider",
|
|
11
|
+
inheritAttrs: false,
|
|
9
12
|
model: {
|
|
10
13
|
prop: "modelValue",
|
|
11
14
|
event: "update:modelValue"
|
|
@@ -44,14 +47,14 @@ const VARIANTS = {
|
|
|
44
47
|
error: "hsl(var(--color-red-700-value))"
|
|
45
48
|
};
|
|
46
49
|
let isDragging = false;
|
|
47
|
-
let
|
|
48
|
-
let
|
|
50
|
+
let sliderRect = null;
|
|
51
|
+
let lastClientX = null;
|
|
49
52
|
const configProvider = useConfigProvider();
|
|
50
53
|
const sliderRef = shallowRef();
|
|
51
54
|
const modelValue = useModelValue(props, emits);
|
|
52
55
|
const activeThumb = shallowRef();
|
|
53
56
|
const computedSize = computed(() => getFallbackValue(props.size, SIZES, configProvider.size));
|
|
54
|
-
const
|
|
57
|
+
const valueRange = computed(() => {
|
|
55
58
|
if (props.range) {
|
|
56
59
|
return Array.isArray(modelValue.value) ? modelValue.value : [props.min, modelValue.value];
|
|
57
60
|
}
|
|
@@ -62,8 +65,8 @@ function getPercentage(value) {
|
|
|
62
65
|
const range = max - min;
|
|
63
66
|
return Math.max(0, Math.min(100, (value - min) / range * 100));
|
|
64
67
|
}
|
|
65
|
-
const startPercentage = computed(() => getPercentage(
|
|
66
|
-
const endPercentage = computed(() => getPercentage(
|
|
68
|
+
const startPercentage = computed(() => getPercentage(valueRange.value[0]));
|
|
69
|
+
const endPercentage = computed(() => getPercentage(valueRange.value[1]));
|
|
67
70
|
const trackStyle = computed(() => {
|
|
68
71
|
const backgroundColor = props.disabled ? "var(--color-gray-alpha-400)" : getFallbackValue(props.variant, VARIANTS, "primary");
|
|
69
72
|
if (props.range) {
|
|
@@ -82,7 +85,7 @@ function updateValueFromPosition(clientX) {
|
|
|
82
85
|
if (!sliderRef.value || !activeThumb.value) {
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
85
|
-
const rect = sliderRef.value.getBoundingClientRect();
|
|
88
|
+
const rect = sliderRect ?? sliderRef.value.getBoundingClientRect();
|
|
86
89
|
const posPercentage = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
|
|
87
90
|
const range = props.max - props.min;
|
|
88
91
|
const rawValue = props.min + posPercentage * range;
|
|
@@ -91,7 +94,7 @@ function updateValueFromPosition(clientX) {
|
|
|
91
94
|
Math.min(props.max, props.step > 0 ? Math.round(rawValue / props.step) * props.step : rawValue)
|
|
92
95
|
);
|
|
93
96
|
if (props.range) {
|
|
94
|
-
const newValueArray = [...
|
|
97
|
+
const newValueArray = [...valueRange.value];
|
|
95
98
|
if (activeThumb.value === "start") {
|
|
96
99
|
newValueArray[0] = newValue;
|
|
97
100
|
if (newValue > newValueArray[1]) {
|
|
@@ -107,28 +110,23 @@ function updateValueFromPosition(clientX) {
|
|
|
107
110
|
activeThumb.value = "start";
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
|
-
if (
|
|
113
|
+
if (valueRange.value[0] !== newValueArray[0] || valueRange.value[1] !== newValueArray[1]) {
|
|
111
114
|
modelValue.value = newValueArray;
|
|
112
115
|
}
|
|
113
116
|
} else if (modelValue.value !== newValue) {
|
|
114
117
|
modelValue.value = newValue;
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
+
const scheduleUpdate = throttleByRaf(() => {
|
|
121
|
+
if (lastClientX !== null) {
|
|
122
|
+
updateValueFromPosition(lastClientX);
|
|
120
123
|
}
|
|
121
|
-
|
|
122
|
-
animationFrameId = null;
|
|
123
|
-
if (lastClientX !== null) {
|
|
124
|
-
updateValueFromPosition(lastClientX);
|
|
125
|
-
}
|
|
126
|
-
if (isDragging) {
|
|
127
|
-
scheduleUpdate();
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
124
|
+
});
|
|
131
125
|
function startDragging(ev, thumb) {
|
|
126
|
+
if (!sliderRef.value) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
sliderRect = sliderRef.value.getBoundingClientRect();
|
|
132
130
|
isDragging = true;
|
|
133
131
|
activeThumb.value = thumb;
|
|
134
132
|
lastClientX = ev.clientX;
|
|
@@ -148,11 +146,9 @@ function handleMove(ev) {
|
|
|
148
146
|
function endDragging() {
|
|
149
147
|
isDragging = false;
|
|
150
148
|
lastClientX = null;
|
|
149
|
+
sliderRect = null;
|
|
151
150
|
activeThumb.value = null;
|
|
152
|
-
|
|
153
|
-
cancelAnimationFrame(animationFrameId);
|
|
154
|
-
animationFrameId = null;
|
|
155
|
-
}
|
|
151
|
+
scheduleUpdate.cancel();
|
|
156
152
|
cachedOff(document, "pointermove", handleMove);
|
|
157
153
|
cachedOff(document, "pointercancel", endDragging);
|
|
158
154
|
}
|
|
@@ -184,14 +180,43 @@ function initModelValue() {
|
|
|
184
180
|
if (props.range && !Array.isArray(modelValue.value)) {
|
|
185
181
|
modelValue.value = [props.min, modelValue.value];
|
|
186
182
|
} else if (!props.range && Array.isArray(modelValue.value)) {
|
|
187
|
-
modelValue.value = modelValue.value[1];
|
|
183
|
+
modelValue.value = modelValue.value[1] ?? 0;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function onThumbKeydown(ev) {
|
|
187
|
+
if (props.disabled) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const { code } = ev;
|
|
191
|
+
const delta = code === "ArrowLeft" ? -props.step : code === "ArrowRight" ? props.step : 0;
|
|
192
|
+
if (!delta) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
ev.preventDefault();
|
|
196
|
+
const target = ev.target;
|
|
197
|
+
const isStart = target.dataset.rangeStart === "true";
|
|
198
|
+
if (props.range) {
|
|
199
|
+
const [startVal, endVal] = valueRange.value;
|
|
200
|
+
const newRange = [startVal, endVal];
|
|
201
|
+
if (isStart) {
|
|
202
|
+
newRange[0] = Math.max(props.min, Math.min(endVal, startVal + delta));
|
|
203
|
+
} else {
|
|
204
|
+
newRange[1] = Math.max(startVal, Math.min(props.max, endVal + delta));
|
|
205
|
+
}
|
|
206
|
+
if (newRange[0] !== startVal || newRange[1] !== endVal) {
|
|
207
|
+
modelValue.value = newRange;
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
const current = modelValue.value;
|
|
211
|
+
const newValue = Math.max(props.min, Math.min(props.max, current + delta));
|
|
212
|
+
if (newValue !== current) {
|
|
213
|
+
modelValue.value = newValue;
|
|
214
|
+
}
|
|
188
215
|
}
|
|
189
216
|
}
|
|
190
217
|
initModelValue();
|
|
191
218
|
onBeforeUnmount(() => {
|
|
192
|
-
|
|
193
|
-
cancelAnimationFrame(animationFrameId);
|
|
194
|
-
}
|
|
219
|
+
scheduleUpdate.cancel();
|
|
195
220
|
cachedOff(document, "pointermove", handleMove);
|
|
196
221
|
cachedOff(document, "pointerup", endDragging);
|
|
197
222
|
cachedOff(document, "pointercancel", endDragging);
|
|
@@ -200,9 +225,10 @@ onBeforeUnmount(() => {
|
|
|
200
225
|
|
|
201
226
|
<template>
|
|
202
227
|
<div
|
|
228
|
+
v-bind="$attrs"
|
|
203
229
|
ref="sliderRef"
|
|
204
230
|
:role="range ? 'group' : 'slider'"
|
|
205
|
-
class="pxd-slider group/slider relative flex touch-none items-center rounded-full bg-gray-200 select-none"
|
|
231
|
+
class="pxd-slider group/slider relative flex w-full max-w-full shrink-0 touch-none items-center rounded-full bg-gray-200 select-none"
|
|
206
232
|
:class="[{ 'cursor-not-allowed': disabled }, computedSize.track]"
|
|
207
233
|
@pointerdown.prevent="onWrapperPointerdown"
|
|
208
234
|
>
|
|
@@ -210,27 +236,43 @@ onBeforeUnmount(() => {
|
|
|
210
236
|
|
|
211
237
|
<div
|
|
212
238
|
v-if="props.range"
|
|
213
|
-
|
|
214
|
-
:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
]"
|
|
239
|
+
tabindex="0"
|
|
240
|
+
:data-dragging="isDragging && activeThumb === 'start'"
|
|
241
|
+
:data-range-start="true"
|
|
242
|
+
class="pxd-slider--thumb group rounded-xs absolute -translate-x-1/2 touch-none appearance-none bg-none self-focus-ring outline-none hover:z-1 active:[--slider-thumb-scale:1.3] motion-safe:before:transition-all pointer-fine:hover:[--slider-thumb-scale:1.3]"
|
|
243
|
+
:class="[{ 'pointer-events-none': disabled }, computedSize.thumb]"
|
|
218
244
|
:style="{ left: `${startPercentage}%` }"
|
|
245
|
+
@keydown="onThumbKeydown"
|
|
246
|
+
@contextmenu.prevent="NOOP"
|
|
219
247
|
@pointerdown.prevent.stop="startDragging($event, 'start')"
|
|
220
|
-
|
|
248
|
+
>
|
|
249
|
+
<span
|
|
250
|
+
class="py-1 px-1.5 text-xs -top-8 shadow-sm pointer-events-none absolute left-1/2 -translate-x-1/2 rounded-md bg-gray-1000 whitespace-nowrap text-gray-100 opacity-0 select-none group-hover:opacity-100 group-data-[dragging=true]:opacity-100 motion-safe:transition-opacity"
|
|
251
|
+
>
|
|
252
|
+
{{ valueRange[0] }}
|
|
253
|
+
</span>
|
|
254
|
+
</div>
|
|
221
255
|
|
|
222
256
|
<div
|
|
223
|
-
|
|
224
|
-
:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
]"
|
|
257
|
+
tabindex="0"
|
|
258
|
+
:data-range-start="range ? false : true"
|
|
259
|
+
:data-dragging="isDragging && activeThumb === 'end'"
|
|
260
|
+
class="pxd-slider--thumb group rounded-xs absolute -translate-x-1/2 touch-none appearance-auto bg-none self-focus-ring outline-none hover:z-1 active:[--slider-thumb-scale:1.3] motion-safe:before:transition-all pointer-fine:hover:[--slider-thumb-scale:1.3]"
|
|
261
|
+
:class="[{ 'pointer-events-none': disabled }, computedSize.thumb]"
|
|
228
262
|
:style="{ left: `${endPercentage}%` }"
|
|
263
|
+
@keydown="onThumbKeydown"
|
|
264
|
+
@contextmenu.prevent="NOOP"
|
|
229
265
|
@pointerdown.prevent.stop="startDragging($event, 'end')"
|
|
230
|
-
|
|
266
|
+
>
|
|
267
|
+
<span
|
|
268
|
+
class="py-1 px-1.5 text-xs -top-8 shadow-sm pointer-events-none absolute left-1/2 -translate-x-1/2 rounded-md bg-gray-1000 whitespace-nowrap text-gray-100 opacity-0 select-none group-hover:opacity-100 group-data-[dragging=true]:opacity-100 motion-safe:transition-opacity"
|
|
269
|
+
>
|
|
270
|
+
{{ valueRange[1] }}
|
|
271
|
+
</span>
|
|
272
|
+
</div>
|
|
231
273
|
</div>
|
|
232
274
|
</template>
|
|
233
275
|
|
|
234
276
|
<style>
|
|
235
|
-
.pxd-slider--thumb{box-shadow:0 0 0 1px var(--color-gray-alpha-500),0 1px 2px var(--color-gray-alpha-100)}.pxd-slider--thumb:after{
|
|
277
|
+
.pxd-slider--thumb[data-dragging=true]{--slider-thumb-scale:1.3}.pxd-slider--thumb:after,.pxd-slider--thumb:before{border-radius:inherit;content:"";left:50%;position:absolute;top:50%;transform:translate3d(-50%,-50%,0) scale(var(--slider-thumb-scale,1))}.pxd-slider--thumb:before{background-color:#fff;box-shadow:0 0 0 1px var(--color-gray-alpha-500),0 1px 2px var(--color-gray-alpha-100);height:100%;width:100%}.dark .pxd-slider--thumb:before{box-shadow:0 0 0 1px #000,0 1px 2px #0000000a}.pxd-slider--thumb:after{height:200%;width:200%}.pxd-slider:active .pxd-slider--thumb,.pxd-slider:active .pxd-slider--track{will-change:width,left}
|
|
236
278
|
</style>
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import CheckIcon from "@gdsicon/vue/check";
|
|
3
3
|
import CopyIcon from "@gdsicon/vue/copy";
|
|
4
4
|
import { computed } from "vue";
|
|
5
|
-
import { useConfigProvider } from "../../
|
|
5
|
+
import { useConfigProvider } from "../../contexts/config-provider";
|
|
6
6
|
import { useCopyClick } from "../../composables/use-copy-click";
|
|
7
7
|
import { getCssUnitValue, isTruthyProp, toArray } from "../../utils/format";
|
|
8
|
-
import {
|
|
8
|
+
import { tv } from "tailwind-variants";
|
|
9
9
|
defineOptions({
|
|
10
10
|
name: "PSnippet",
|
|
11
11
|
inheritAttrs: false
|
|
@@ -18,6 +18,32 @@ const props = defineProps({
|
|
|
18
18
|
variant: { type: String, required: false, default: "default" }
|
|
19
19
|
});
|
|
20
20
|
const emits = defineEmits(["copy"]);
|
|
21
|
+
const snippetVariant = tv({
|
|
22
|
+
base: "pxd-snippet pr-12 relative flex items-center rounded-lg border motion-safe:transition-all",
|
|
23
|
+
variants: {
|
|
24
|
+
size: {
|
|
25
|
+
sm: "min-h-7.5 pl-3.5 pr-1.5 py-2 text-sm",
|
|
26
|
+
md: "min-h-9 pl-3.5 pr-2.5 py-2.5 text-sm",
|
|
27
|
+
lg: "min-h-10 pl-3.5 pr-3.5 py-3 text-base"
|
|
28
|
+
},
|
|
29
|
+
variant: {
|
|
30
|
+
default: "border-gray-alpha-300 bg-background-100",
|
|
31
|
+
primary: "border-gray-alpha-300 bg-primary text-gray-100",
|
|
32
|
+
success: "border-gray-alpha-300 bg-blue-200 text-blue-900",
|
|
33
|
+
error: "border-gray-alpha-300 bg-red-200 text-red-900",
|
|
34
|
+
warning: "border-gray-alpha-300 bg-amber-200 text-amber-900"
|
|
35
|
+
},
|
|
36
|
+
prompt: {
|
|
37
|
+
true: "pxd-snippet--prompt",
|
|
38
|
+
false: ""
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
defaultVariants: {
|
|
42
|
+
size: "md",
|
|
43
|
+
variant: "default",
|
|
44
|
+
prompt: false
|
|
45
|
+
}
|
|
46
|
+
});
|
|
21
47
|
const configProvider = useConfigProvider();
|
|
22
48
|
const { isCopied, copyText } = useCopyClick();
|
|
23
49
|
const renderIcon = computed(() => isCopied.value ? CheckIcon : CopyIcon);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
defineOptions({
|
|
3
|
-
name: "PSpinner"
|
|
3
|
+
name: "PSpinner",
|
|
4
|
+
inheritAttrs: false
|
|
4
5
|
});
|
|
5
6
|
const ITEMS_COUNT = 12;
|
|
6
7
|
const ROTATE_STEP = 360 / ITEMS_COUNT;
|
|
@@ -9,7 +10,8 @@ const OPACITY_STEP = 1 / ITEMS_COUNT;
|
|
|
9
10
|
|
|
10
11
|
<template>
|
|
11
12
|
<div
|
|
12
|
-
class="pxd-spinner transform-origin-center motion-safe:animate-spin pointer-events-none relative size-em overflow-hidden text-gray-700"
|
|
13
|
+
class="pxd-spinner transform-origin-center motion-safe:animate-spin pointer-events-none relative size-em overflow-hidden text-gray-700 content-visibility-auto intrinsic-size-auto"
|
|
14
|
+
v-bind="$attrs"
|
|
13
15
|
>
|
|
14
16
|
<div class="pxd-spinner-container top-0 left-0 absolute size-full">
|
|
15
17
|
<div
|
|
@@ -4,11 +4,11 @@ type __VLS_Slots = {} & {
|
|
|
4
4
|
default?: (props: typeof __VLS_8) => any;
|
|
5
5
|
};
|
|
6
6
|
declare const __VLS_base: import("vue").DefineComponent<StackProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<StackProps> & Readonly<{}>, {
|
|
7
|
-
align: import("./types").Align;
|
|
8
7
|
as: import("../../types/shared").ComponentAs;
|
|
8
|
+
align: import("./types").Align;
|
|
9
9
|
wrap: boolean;
|
|
10
|
-
justify: import("./types").Align;
|
|
11
10
|
scale: number;
|
|
11
|
+
justify: import("./types").Align;
|
|
12
12
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
13
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
14
14
|
declare const _default: typeof __VLS_export;
|
|
@@ -1,20 +1,52 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import { getResponsiveValue } from "../../utils/responsive";
|
|
4
|
-
import {
|
|
4
|
+
import { tv } from "tailwind-variants";
|
|
5
5
|
defineOptions({
|
|
6
6
|
name: "PStack",
|
|
7
7
|
inheritAttrs: false
|
|
8
8
|
});
|
|
9
9
|
const props = defineProps({
|
|
10
|
-
as: { type:
|
|
11
|
-
wrap: { type: Boolean, required: false, default: true },
|
|
10
|
+
as: { type: [String, Object], required: false, default: "div" },
|
|
12
11
|
gap: { type: [String, Number, Object], required: false },
|
|
12
|
+
wrap: { type: Boolean, required: false, default: true },
|
|
13
13
|
scale: { type: Number, required: false, default: 4 },
|
|
14
14
|
align: { type: String, required: false, default: "start" },
|
|
15
15
|
justify: { type: String, required: false, default: "start" },
|
|
16
16
|
direction: { type: [String, Object], required: false }
|
|
17
17
|
});
|
|
18
|
+
const stackVariant = tv({
|
|
19
|
+
base: "pxd-stack flex max-w-full gap-(--xs) [--xs:1rem]",
|
|
20
|
+
variants: {
|
|
21
|
+
wrap: {
|
|
22
|
+
true: "flex-wrap",
|
|
23
|
+
false: ""
|
|
24
|
+
},
|
|
25
|
+
align: {
|
|
26
|
+
start: "items-start",
|
|
27
|
+
end: "items-end",
|
|
28
|
+
center: "items-center",
|
|
29
|
+
between: "items-between",
|
|
30
|
+
around: "items-around",
|
|
31
|
+
evenly: "items-evenly",
|
|
32
|
+
stretch: "items-stretch"
|
|
33
|
+
},
|
|
34
|
+
justify: {
|
|
35
|
+
start: "flex-start",
|
|
36
|
+
end: "flex-end",
|
|
37
|
+
center: "justify-center",
|
|
38
|
+
between: "justify-between",
|
|
39
|
+
around: "justify-around",
|
|
40
|
+
evenly: "justify-evenly",
|
|
41
|
+
stretch: "justify-stretch"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
defaultVariants: {
|
|
45
|
+
wrap: true,
|
|
46
|
+
align: "start",
|
|
47
|
+
justify: "start"
|
|
48
|
+
}
|
|
49
|
+
});
|
|
18
50
|
const presetDir = {
|
|
19
51
|
"--xs:vertical": "flex-col",
|
|
20
52
|
"--xs:horizontal": "flex-row",
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { capitalize as capitalizeText } from "../../utils/format";
|
|
3
|
+
defineOptions({
|
|
4
|
+
name: "PStatusDot",
|
|
5
|
+
inheritAttrs: false
|
|
6
|
+
});
|
|
3
7
|
const props = defineProps({
|
|
4
8
|
label: { type: [Boolean, String, Number, Array, null], required: false, default: false },
|
|
5
9
|
state: { type: String, required: false, default: "QUEUED" }
|
|
@@ -24,7 +28,7 @@ function getLabelText() {
|
|
|
24
28
|
</script>
|
|
25
29
|
|
|
26
30
|
<template>
|
|
27
|
-
<span class="pxd-state-dot inline-flex items-center">
|
|
31
|
+
<span class="pxd-state-dot inline-flex items-center" v-bind="$attrs">
|
|
28
32
|
<i
|
|
29
33
|
aria-hidden="true"
|
|
30
34
|
class="w-2.5 h-2.5 inline-block rounded-full"
|
|
@@ -3,7 +3,16 @@ declare var __VLS_1: {};
|
|
|
3
3
|
type __VLS_Slots = {} & {
|
|
4
4
|
default?: (props: typeof __VLS_1) => any;
|
|
5
5
|
};
|
|
6
|
-
declare const __VLS_base: import("vue").DefineComponent<SwitchProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
6
|
+
declare const __VLS_base: import("vue").DefineComponent<SwitchProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
7
|
+
change: (args_0: NonNullable<string | number | undefined>) => any;
|
|
8
|
+
"update:modelValue": (args_0: NonNullable<string | number | undefined>) => any;
|
|
9
|
+
}, string, import("vue").PublicProps, Readonly<SwitchProps> & Readonly<{
|
|
10
|
+
onChange?: ((args_0: NonNullable<string | number | undefined>) => any) | undefined;
|
|
11
|
+
"onUpdate:modelValue"?: ((args_0: NonNullable<string | number | undefined>) => any) | undefined;
|
|
12
|
+
}>, {
|
|
13
|
+
options: import("../../types/shared").ComponentOption[];
|
|
14
|
+
modelValue: string | number;
|
|
15
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
16
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
8
17
|
declare const _default: typeof __VLS_export;
|
|
9
18
|
export default _default;
|
|
@@ -1,62 +1,53 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed } from "vue";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { useConfigProvider } from "../../contexts/config-provider";
|
|
4
|
+
import { useModelValue } from "../../composables/use-model-value";
|
|
5
|
+
import { provideSwitchContext } from "../../contexts/switch";
|
|
6
|
+
import { getFallbackValue } from "../../utils/get";
|
|
5
7
|
import { getUniqueId } from "../../utils/uid";
|
|
6
|
-
import
|
|
8
|
+
import PSwitchItem from "../switch-item/index.vue";
|
|
7
9
|
defineOptions({
|
|
8
10
|
name: "PSwitch",
|
|
11
|
+
inheritAttrs: false,
|
|
9
12
|
model: {
|
|
10
13
|
prop: "modelValue",
|
|
11
14
|
event: "update:modelValue"
|
|
12
15
|
}
|
|
13
16
|
});
|
|
14
17
|
const props = defineProps({
|
|
15
|
-
label: { type: [String, Number, Array, null], required: false },
|
|
16
|
-
value: { type: [String, Number], required: true },
|
|
17
18
|
disabled: { type: Boolean, required: false },
|
|
18
|
-
|
|
19
|
+
fullWidth: { type: Boolean, required: false },
|
|
20
|
+
size: { type: String, required: false },
|
|
21
|
+
options: { type: Array, required: false, default: () => [] },
|
|
22
|
+
modelValue: { type: [String, Number], required: false, default: "" }
|
|
19
23
|
});
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
function onSwitchFocusIn() {
|
|
31
|
-
if (computedDisabled.value) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
switchGroupModelValue.value = props.value;
|
|
35
|
-
}
|
|
24
|
+
const emits = defineEmits(["change", "update:modelValue"]);
|
|
25
|
+
const SIZES = {
|
|
26
|
+
sm: "h-7.5",
|
|
27
|
+
md: "h-9",
|
|
28
|
+
lg: "h-10"
|
|
29
|
+
};
|
|
30
|
+
const configProvider = useConfigProvider();
|
|
31
|
+
const modelValue = useModelValue(props, emits);
|
|
32
|
+
const computedSize = computed(() => getFallbackValue(props.size, SIZES, configProvider.size));
|
|
33
|
+
provideSwitchContext({ props, emits, name: getUniqueId() });
|
|
36
34
|
</script>
|
|
37
35
|
|
|
38
36
|
<template>
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
class="
|
|
42
|
-
|
|
37
|
+
<div
|
|
38
|
+
class="pxd-switch p-1 flex touch-manipulation rounded-lg border"
|
|
39
|
+
:class="[fullWidth ? 'w-full' : 'w-max', computedSize]"
|
|
40
|
+
v-bind="$attrs"
|
|
43
41
|
>
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
<div :class="computedClasses" @focusin="onSwitchFocusIn">
|
|
57
|
-
<slot>
|
|
58
|
-
{{ label }}
|
|
59
|
-
</slot>
|
|
60
|
-
</div>
|
|
61
|
-
</label>
|
|
42
|
+
<slot>
|
|
43
|
+
<PSwitchItem
|
|
44
|
+
v-for="option in options"
|
|
45
|
+
:key="option.value"
|
|
46
|
+
v-model="modelValue"
|
|
47
|
+
:label="option.label"
|
|
48
|
+
:value="option.value"
|
|
49
|
+
:disabled="option.disabled"
|
|
50
|
+
/>
|
|
51
|
+
</slot>
|
|
52
|
+
</div>
|
|
62
53
|
</template>
|
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentOption, ComponentSize } from '../../types/shared'
|
|
2
2
|
|
|
3
3
|
export interface SwitchProps {
|
|
4
|
-
label?: ComponentLabel
|
|
5
|
-
value: string | number
|
|
6
4
|
disabled?: boolean
|
|
7
|
-
required?: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface SwitchGroupProps {
|
|
11
|
-
disabled?: boolean
|
|
12
|
-
required?: boolean
|
|
13
5
|
fullWidth?: boolean
|
|
14
6
|
size?: ComponentSize
|
|
15
7
|
options?: ComponentOption[]
|
|
16
8
|
modelValue?: string | number
|
|
17
9
|
}
|
|
18
10
|
|
|
19
|
-
export interface
|
|
20
|
-
change: [NonNullable<
|
|
21
|
-
'update:modelValue': [NonNullable<
|
|
11
|
+
export interface SwitchEmits {
|
|
12
|
+
change: [NonNullable<SwitchProps['modelValue']>]
|
|
13
|
+
'update:modelValue': [NonNullable<SwitchProps['modelValue']>]
|
|
22
14
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SwitchItemProps } from './types';
|
|
2
|
+
declare var __VLS_1: {};
|
|
3
|
+
type __VLS_Slots = {} & {
|
|
4
|
+
default?: (props: typeof __VLS_1) => any;
|
|
5
|
+
};
|
|
6
|
+
declare const __VLS_base: import("vue").DefineComponent<SwitchItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<SwitchItemProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
8
|
+
declare const _default: typeof __VLS_export;
|
|
9
|
+
export default _default;
|
|
10
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
11
|
+
new (): {
|
|
12
|
+
$slots: S;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { useSwitchContext } from "../../contexts/switch";
|
|
4
|
+
import { useModelValue } from "../../composables/use-model-value";
|
|
5
|
+
import { getUniqueId } from "../../utils/uid";
|
|
6
|
+
import { tv } from "tailwind-variants";
|
|
7
|
+
defineOptions({
|
|
8
|
+
name: "PSwitchItem",
|
|
9
|
+
inheritAttrs: false,
|
|
10
|
+
model: {
|
|
11
|
+
prop: "modelValue",
|
|
12
|
+
event: "update:modelValue"
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const props = defineProps({
|
|
16
|
+
label: { type: [String, Number, Array, null], required: false },
|
|
17
|
+
value: { type: [String, Number], required: true },
|
|
18
|
+
disabled: { type: Boolean, required: false }
|
|
19
|
+
});
|
|
20
|
+
const emits = defineEmits([]);
|
|
21
|
+
const switchVariant = tv({
|
|
22
|
+
base: "pxd-switch-item--label px-2.5 text-sm font-medium flex size-full items-center justify-center truncate rounded-sm text-foreground-secondary peer-focus-ring select-none peer-checked:bg-gray-100 peer-disabled:cursor-not-allowed peer-disabled:text-gray-800 empty:hidden hover:text-foreground motion-safe:transition-all",
|
|
23
|
+
variants: {
|
|
24
|
+
disabled: {
|
|
25
|
+
true: "",
|
|
26
|
+
false: "peer-checked:text-foreground"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
defaultVariants: {
|
|
30
|
+
disabled: false
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const uniqueId = getUniqueId();
|
|
34
|
+
const switchGroupContext = useSwitchContext();
|
|
35
|
+
const switchGroupName = switchGroupContext?.name ?? getUniqueId();
|
|
36
|
+
const modelValue = useModelValue(
|
|
37
|
+
switchGroupContext?.props ?? props,
|
|
38
|
+
switchGroupContext?.emits ?? emits
|
|
39
|
+
);
|
|
40
|
+
const isChecked = computed(() => modelValue.value === props.value);
|
|
41
|
+
const isDisabled = computed(() => props.disabled || switchGroupContext?.props.disabled);
|
|
42
|
+
const computedClasses = computed(() => {
|
|
43
|
+
return switchVariant({ disabled: isDisabled.value });
|
|
44
|
+
});
|
|
45
|
+
function onInputChange() {
|
|
46
|
+
if (isDisabled.value) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
modelValue.value = props.value;
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<template>
|
|
54
|
+
<label
|
|
55
|
+
role="switch"
|
|
56
|
+
:aria-selected="isChecked"
|
|
57
|
+
:data-disabled="isDisabled"
|
|
58
|
+
class="pxd-switch-item flex-1 shrink-0 cursor-pointer"
|
|
59
|
+
:for="uniqueId"
|
|
60
|
+
v-bind="$attrs"
|
|
61
|
+
>
|
|
62
|
+
<input
|
|
63
|
+
:id="uniqueId"
|
|
64
|
+
type="radio"
|
|
65
|
+
:value="value"
|
|
66
|
+
class="peer visually-hidden"
|
|
67
|
+
:checked="isChecked"
|
|
68
|
+
:name="switchGroupName"
|
|
69
|
+
:disabled="isDisabled"
|
|
70
|
+
@change="onInputChange"
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
<div :class="computedClasses" @focusin="onInputChange">
|
|
74
|
+
<slot>
|
|
75
|
+
{{ label }}
|
|
76
|
+
</slot>
|
|
77
|
+
</div>
|
|
78
|
+
</label>
|
|
79
|
+
</template>
|