cynx-lib 1.3.80 → 1.3.82
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/gen.js +77 -77
- package/package.json +1 -1
- package/ui/components/Drawer.jsx +208 -208
- package/ui/components/Layout.jsx +138 -138
- package/ui/components/LoginPage.jsx +405 -405
- package/ui/components/Pagination.jsx +145 -145
- package/ui/components/PrivacyBlur.jsx +603 -603
- package/ui/components/Sidebar.jsx +820 -820
- package/utils/index.js +20 -20
- package/utils/utils/duration.js +139 -139
- package/utils/utils/oidc.js +214 -214
- package/utils/utils/realtime.js +1634 -1634
- package/utils/utils/session.js +58 -58
- package/utils/utils/storage.js +393 -393
- package/utils/utils/storage_manager.cjs +84 -7
- package/utils/utils/storage_manager.js +95 -8
- package/utils/utils/ui.js +111 -111
- package/vue/components/Badge.vue +79 -79
- package/vue/components/Button.vue +209 -209
- package/vue/components/Checkbox.vue +103 -103
- package/vue/components/CircularProgress.vue +383 -383
- package/vue/components/Divider.vue +94 -94
- package/vue/components/Drawer.vue +243 -243
- package/vue/components/InfoBadge.vue +223 -223
- package/vue/components/Input.vue +341 -341
- package/vue/components/LinearProgress.vue +268 -268
- package/vue/components/Modal.vue +226 -226
- package/vue/components/Pagination.vue +199 -199
- package/vue/components/Select.vue +713 -713
- package/vue/components/Sidebar.vue +955 -955
- package/vue/components/Skeleton.vue +91 -91
- package/vue/components/Spinner.vue +263 -263
- package/vue/components/StatusTag.vue +89 -89
- package/vue/components/TabBar.vue +176 -176
- package/vue/components/Table.vue +388 -388
- package/vue/components/TimePicker.vue +399 -399
- package/vue/components/Toggle.vue +115 -115
- package/vue/components/XTable.vue +119 -119
- package/vue/composables/useAutoSkeletonRows.ts +71 -71
- package/vue/index.d.ts +67 -67
- package/vue/index.js +86 -86
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed, useSlots } from "vue";
|
|
3
|
-
|
|
4
|
-
const SIZE_CONFIG: Record<string, any> = {
|
|
5
|
-
xs: { hMargin: "8px 0", vMargin: "0 4px", vHeight: "14px", fontSize: ".7rem", padding: "0 8px" },
|
|
6
|
-
sm: { hMargin: "12px 0", vMargin: "0 8px", vHeight: "18px", fontSize: ".75rem", padding: "0 10px" },
|
|
7
|
-
md: { hMargin: "16px 0", vMargin: "0 12px", vHeight: "24px", fontSize: ".82rem", padding: "0 12px" },
|
|
8
|
-
lg: { hMargin: "24px 0", vMargin: "0 16px", vHeight: "32px", fontSize: ".9rem", padding: "0 16px" },
|
|
9
|
-
xl: { hMargin: "32px 0", vMargin: "0 24px", vHeight: "48px", fontSize: "1rem", padding: "0 20px" },
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const props = withDefaults(
|
|
13
|
-
defineProps<{
|
|
14
|
-
label?: string;
|
|
15
|
-
orientation?: "horizontal" | "vertical";
|
|
16
|
-
align?: "left" | "center" | "right";
|
|
17
|
-
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
18
|
-
color?: string;
|
|
19
|
-
thickness?: number | string;
|
|
20
|
-
variant?: string;
|
|
21
|
-
}>(),
|
|
22
|
-
{
|
|
23
|
-
orientation: "horizontal",
|
|
24
|
-
align: "center",
|
|
25
|
-
size: "md",
|
|
26
|
-
color: "var(--border, #d7d8e0)",
|
|
27
|
-
thickness: 1,
|
|
28
|
-
variant: "solid",
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const slots = useSlots();
|
|
33
|
-
const hasContent = computed(() => Boolean(props.label || slots.default));
|
|
34
|
-
const cfg = computed(() => SIZE_CONFIG[props.size] || SIZE_CONFIG.md);
|
|
35
|
-
const thickStr = computed(() =>
|
|
36
|
-
typeof props.thickness === "number" ? `${props.thickness}px` : props.thickness
|
|
37
|
-
);
|
|
38
|
-
const lineStyle = computed(() => `${thickStr.value} ${props.variant} ${props.color}`);
|
|
39
|
-
const leftFlex = computed(() => (props.align === "left" ? "0 0 16px" : "1"));
|
|
40
|
-
const rightFlex = computed(() => (props.align === "right" ? "0 0 16px" : "1"));
|
|
41
|
-
</script>
|
|
42
|
-
|
|
43
|
-
<template>
|
|
44
|
-
<div
|
|
45
|
-
v-if="orientation === 'vertical'"
|
|
46
|
-
class="cynx-divider cynx-divider-vertical"
|
|
47
|
-
:style="{
|
|
48
|
-
display: 'inline-block',
|
|
49
|
-
width: 0,
|
|
50
|
-
height: cfg.vHeight,
|
|
51
|
-
margin: cfg.vMargin,
|
|
52
|
-
borderLeft: lineStyle,
|
|
53
|
-
verticalAlign: 'middle',
|
|
54
|
-
alignSelf: 'center',
|
|
55
|
-
flexShrink: 0,
|
|
56
|
-
}"
|
|
57
|
-
/>
|
|
58
|
-
|
|
59
|
-
<div
|
|
60
|
-
v-else-if="hasContent"
|
|
61
|
-
class="cynx-divider cynx-divider-horizontal"
|
|
62
|
-
:style="{
|
|
63
|
-
display: 'flex',
|
|
64
|
-
alignItems: 'center',
|
|
65
|
-
width: '100%',
|
|
66
|
-
margin: cfg.hMargin,
|
|
67
|
-
}"
|
|
68
|
-
>
|
|
69
|
-
<div :style="{ flex: leftFlex, borderBottom: lineStyle }" />
|
|
70
|
-
<span
|
|
71
|
-
:style="{
|
|
72
|
-
padding: cfg.padding,
|
|
73
|
-
fontSize: cfg.fontSize,
|
|
74
|
-
color: 'var(--muted, #9b9daa)',
|
|
75
|
-
fontWeight: 500,
|
|
76
|
-
whiteSpace: 'nowrap',
|
|
77
|
-
lineHeight: 1,
|
|
78
|
-
}"
|
|
79
|
-
>
|
|
80
|
-
<slot>{{ label }}</slot>
|
|
81
|
-
</span>
|
|
82
|
-
<div :style="{ flex: rightFlex, borderBottom: lineStyle }" />
|
|
83
|
-
</div>
|
|
84
|
-
|
|
85
|
-
<div
|
|
86
|
-
v-else
|
|
87
|
-
class="cynx-divider cynx-divider-horizontal"
|
|
88
|
-
:style="{
|
|
89
|
-
width: '100%',
|
|
90
|
-
margin: cfg.hMargin,
|
|
91
|
-
borderBottom: lineStyle,
|
|
92
|
-
}"
|
|
93
|
-
/>
|
|
94
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, useSlots } from "vue";
|
|
3
|
+
|
|
4
|
+
const SIZE_CONFIG: Record<string, any> = {
|
|
5
|
+
xs: { hMargin: "8px 0", vMargin: "0 4px", vHeight: "14px", fontSize: ".7rem", padding: "0 8px" },
|
|
6
|
+
sm: { hMargin: "12px 0", vMargin: "0 8px", vHeight: "18px", fontSize: ".75rem", padding: "0 10px" },
|
|
7
|
+
md: { hMargin: "16px 0", vMargin: "0 12px", vHeight: "24px", fontSize: ".82rem", padding: "0 12px" },
|
|
8
|
+
lg: { hMargin: "24px 0", vMargin: "0 16px", vHeight: "32px", fontSize: ".9rem", padding: "0 16px" },
|
|
9
|
+
xl: { hMargin: "32px 0", vMargin: "0 24px", vHeight: "48px", fontSize: "1rem", padding: "0 20px" },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(
|
|
13
|
+
defineProps<{
|
|
14
|
+
label?: string;
|
|
15
|
+
orientation?: "horizontal" | "vertical";
|
|
16
|
+
align?: "left" | "center" | "right";
|
|
17
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
18
|
+
color?: string;
|
|
19
|
+
thickness?: number | string;
|
|
20
|
+
variant?: string;
|
|
21
|
+
}>(),
|
|
22
|
+
{
|
|
23
|
+
orientation: "horizontal",
|
|
24
|
+
align: "center",
|
|
25
|
+
size: "md",
|
|
26
|
+
color: "var(--border, #d7d8e0)",
|
|
27
|
+
thickness: 1,
|
|
28
|
+
variant: "solid",
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const slots = useSlots();
|
|
33
|
+
const hasContent = computed(() => Boolean(props.label || slots.default));
|
|
34
|
+
const cfg = computed(() => SIZE_CONFIG[props.size] || SIZE_CONFIG.md);
|
|
35
|
+
const thickStr = computed(() =>
|
|
36
|
+
typeof props.thickness === "number" ? `${props.thickness}px` : props.thickness
|
|
37
|
+
);
|
|
38
|
+
const lineStyle = computed(() => `${thickStr.value} ${props.variant} ${props.color}`);
|
|
39
|
+
const leftFlex = computed(() => (props.align === "left" ? "0 0 16px" : "1"));
|
|
40
|
+
const rightFlex = computed(() => (props.align === "right" ? "0 0 16px" : "1"));
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<div
|
|
45
|
+
v-if="orientation === 'vertical'"
|
|
46
|
+
class="cynx-divider cynx-divider-vertical"
|
|
47
|
+
:style="{
|
|
48
|
+
display: 'inline-block',
|
|
49
|
+
width: 0,
|
|
50
|
+
height: cfg.vHeight,
|
|
51
|
+
margin: cfg.vMargin,
|
|
52
|
+
borderLeft: lineStyle,
|
|
53
|
+
verticalAlign: 'middle',
|
|
54
|
+
alignSelf: 'center',
|
|
55
|
+
flexShrink: 0,
|
|
56
|
+
}"
|
|
57
|
+
/>
|
|
58
|
+
|
|
59
|
+
<div
|
|
60
|
+
v-else-if="hasContent"
|
|
61
|
+
class="cynx-divider cynx-divider-horizontal"
|
|
62
|
+
:style="{
|
|
63
|
+
display: 'flex',
|
|
64
|
+
alignItems: 'center',
|
|
65
|
+
width: '100%',
|
|
66
|
+
margin: cfg.hMargin,
|
|
67
|
+
}"
|
|
68
|
+
>
|
|
69
|
+
<div :style="{ flex: leftFlex, borderBottom: lineStyle }" />
|
|
70
|
+
<span
|
|
71
|
+
:style="{
|
|
72
|
+
padding: cfg.padding,
|
|
73
|
+
fontSize: cfg.fontSize,
|
|
74
|
+
color: 'var(--muted, #9b9daa)',
|
|
75
|
+
fontWeight: 500,
|
|
76
|
+
whiteSpace: 'nowrap',
|
|
77
|
+
lineHeight: 1,
|
|
78
|
+
}"
|
|
79
|
+
>
|
|
80
|
+
<slot>{{ label }}</slot>
|
|
81
|
+
</span>
|
|
82
|
+
<div :style="{ flex: rightFlex, borderBottom: lineStyle }" />
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
<div
|
|
86
|
+
v-else
|
|
87
|
+
class="cynx-divider cynx-divider-horizontal"
|
|
88
|
+
:style="{
|
|
89
|
+
width: '100%',
|
|
90
|
+
margin: cfg.hMargin,
|
|
91
|
+
borderBottom: lineStyle,
|
|
92
|
+
}"
|
|
93
|
+
/>
|
|
94
|
+
</template>
|
|
@@ -1,243 +1,243 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { ref, watch, onUnmounted, computed } from "vue";
|
|
3
|
-
import { X } from "lucide-vue-next";
|
|
4
|
-
|
|
5
|
-
const props = withDefaults(
|
|
6
|
-
defineProps<{
|
|
7
|
-
modelValue?: boolean;
|
|
8
|
-
open?: boolean;
|
|
9
|
-
title?: string;
|
|
10
|
-
description?: string;
|
|
11
|
-
width?: number | string;
|
|
12
|
-
maxWidth?: number | string;
|
|
13
|
-
side?: "right" | "left";
|
|
14
|
-
showClose?: boolean;
|
|
15
|
-
bodyStyle?: Record<string, any>;
|
|
16
|
-
style?: Record<string, any>;
|
|
17
|
-
}>(),
|
|
18
|
-
{
|
|
19
|
-
modelValue: false,
|
|
20
|
-
open: false,
|
|
21
|
-
title: "",
|
|
22
|
-
description: "",
|
|
23
|
-
width: 560,
|
|
24
|
-
maxWidth: "100vw",
|
|
25
|
-
side: "right",
|
|
26
|
-
showClose: true,
|
|
27
|
-
bodyStyle: () => ({}),
|
|
28
|
-
style: () => ({}),
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const emit = defineEmits<{
|
|
33
|
-
(e: "update:modelValue", value: boolean): void;
|
|
34
|
-
(e: "update:open", value: boolean): void;
|
|
35
|
-
(e: "close"): void;
|
|
36
|
-
}>();
|
|
37
|
-
|
|
38
|
-
const isOpen = computed(() => props.modelValue || props.open);
|
|
39
|
-
const closing = ref(false);
|
|
40
|
-
|
|
41
|
-
const STYLES = `
|
|
42
|
-
@keyframes cynxDrawerFadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
43
|
-
@keyframes cynxDrawerFadeOut { from { opacity: 1; } to { opacity: 0; } }
|
|
44
|
-
@keyframes cynxDrawerSlideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
|
|
45
|
-
@keyframes cynxDrawerSlideOutRight { from { transform: translateX(0); } to { transform: translateX(100%); } }
|
|
46
|
-
@keyframes cynxDrawerSlideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }
|
|
47
|
-
@keyframes cynxDrawerSlideOutLeft { from { transform: translateX(0); } to { transform: translateX(-100%); } }
|
|
48
|
-
`;
|
|
49
|
-
|
|
50
|
-
let _id = "cynx-drawer-styles";
|
|
51
|
-
function ensureStyles() {
|
|
52
|
-
if (typeof document === "undefined") return;
|
|
53
|
-
if (document.getElementById(_id)) return;
|
|
54
|
-
const tag = document.createElement("style");
|
|
55
|
-
tag.id = _id;
|
|
56
|
-
tag.textContent = STYLES;
|
|
57
|
-
document.head.appendChild(tag);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (typeof document !== "undefined") ensureStyles();
|
|
61
|
-
|
|
62
|
-
function close() {
|
|
63
|
-
if (closing.value) return;
|
|
64
|
-
closing.value = true;
|
|
65
|
-
setTimeout(() => {
|
|
66
|
-
closing.value = false;
|
|
67
|
-
emit("update:modelValue", false);
|
|
68
|
-
emit("update:open", false);
|
|
69
|
-
emit("close");
|
|
70
|
-
}, 260);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function handleKeydown(e: KeyboardEvent) {
|
|
74
|
-
if (e.key === "Escape" && isOpen.value) {
|
|
75
|
-
close();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
watch(
|
|
80
|
-
isOpen,
|
|
81
|
-
(val) => {
|
|
82
|
-
if (typeof document === "undefined") return;
|
|
83
|
-
if (val) {
|
|
84
|
-
document.body.style.overflow = "hidden";
|
|
85
|
-
window.addEventListener("keydown", handleKeydown);
|
|
86
|
-
} else {
|
|
87
|
-
document.body.style.overflow = "";
|
|
88
|
-
window.removeEventListener("keydown", handleKeydown);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
{ immediate: true }
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
onUnmounted(() => {
|
|
95
|
-
if (typeof document !== "undefined") {
|
|
96
|
-
document.body.style.overflow = "";
|
|
97
|
-
window.removeEventListener("keydown", handleKeydown);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const resolvedWidth = computed(() => {
|
|
102
|
-
if (typeof props.width === "number") return `${props.width}px`;
|
|
103
|
-
return props.width;
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const slideInAnim = computed(() =>
|
|
107
|
-
props.side === "left" ? "cynxDrawerSlideInLeft" : "cynxDrawerSlideInRight"
|
|
108
|
-
);
|
|
109
|
-
const slideOutAnim = computed(() =>
|
|
110
|
-
props.side === "left" ? "cynxDrawerSlideOutLeft" : "cynxDrawerSlideOutRight"
|
|
111
|
-
);
|
|
112
|
-
</script>
|
|
113
|
-
|
|
114
|
-
<template>
|
|
115
|
-
<Teleport to="body">
|
|
116
|
-
<div
|
|
117
|
-
v-if="isOpen || closing"
|
|
118
|
-
class="cynx-drawer-backdrop"
|
|
119
|
-
:style="{
|
|
120
|
-
position: 'fixed',
|
|
121
|
-
inset: 0,
|
|
122
|
-
background: 'rgba(20, 22, 41, .45)',
|
|
123
|
-
zIndex: 8500,
|
|
124
|
-
display: 'flex',
|
|
125
|
-
justifyContent: side === 'left' ? 'flex-start' : 'flex-end',
|
|
126
|
-
animation: `${closing ? 'cynxDrawerFadeOut' : 'cynxDrawerFadeIn'} .26s ease forwards`,
|
|
127
|
-
}"
|
|
128
|
-
@mousedown.self="close"
|
|
129
|
-
>
|
|
130
|
-
<div
|
|
131
|
-
class="cynx-drawer-panel"
|
|
132
|
-
:style="{
|
|
133
|
-
background: 'var(--surface, #ffffff)',
|
|
134
|
-
borderLeft: side === 'right' ? '1px solid var(--border, var(--bd, #e2e8f0))' : 'none',
|
|
135
|
-
borderRight: side === 'left' ? '1px solid var(--border, var(--bd, #e2e8f0))' : 'none',
|
|
136
|
-
width: resolvedWidth,
|
|
137
|
-
maxWidth: '100vw',
|
|
138
|
-
height: '100%',
|
|
139
|
-
boxShadow: 'var(--shadow-lg, 0 20px 60px rgba(0, 0, 0, .25))',
|
|
140
|
-
display: 'flex',
|
|
141
|
-
flexDirection: 'column',
|
|
142
|
-
overflow: 'hidden',
|
|
143
|
-
animation: `${closing ? slideOutAnim : slideInAnim} .26s cubic-bezier(.16, 1, .3, 1) forwards`,
|
|
144
|
-
...style,
|
|
145
|
-
}"
|
|
146
|
-
@mousedown.stop
|
|
147
|
-
>
|
|
148
|
-
<!-- Header -->
|
|
149
|
-
<div
|
|
150
|
-
class="cynx-drawer-hdr"
|
|
151
|
-
:style="{
|
|
152
|
-
display: 'flex',
|
|
153
|
-
alignItems: 'center',
|
|
154
|
-
justifyContent: 'space-between',
|
|
155
|
-
padding: '16px 20px',
|
|
156
|
-
borderBottom: '1px solid var(--border-light, #ebebf0)',
|
|
157
|
-
flexShrink: 0,
|
|
158
|
-
}"
|
|
159
|
-
>
|
|
160
|
-
<slot name="header">
|
|
161
|
-
<div style="display: flex; flex-direction: column; gap: 2px;">
|
|
162
|
-
<span
|
|
163
|
-
class="cynx-drawer-title"
|
|
164
|
-
:style="{
|
|
165
|
-
fontSize: '1rem',
|
|
166
|
-
fontWeight: 700,
|
|
167
|
-
letterSpacing: '-.01em',
|
|
168
|
-
color: 'var(--t, var(--primary-text, #0f111c))',
|
|
169
|
-
}"
|
|
170
|
-
>
|
|
171
|
-
{{ title }}
|
|
172
|
-
</span>
|
|
173
|
-
<span
|
|
174
|
-
v-if="description"
|
|
175
|
-
class="cynx-drawer-desc"
|
|
176
|
-
:style="{
|
|
177
|
-
fontSize: '.75rem',
|
|
178
|
-
color: 'var(--muted, #797b8d)',
|
|
179
|
-
}"
|
|
180
|
-
>
|
|
181
|
-
{{ description }}
|
|
182
|
-
</span>
|
|
183
|
-
</div>
|
|
184
|
-
</slot>
|
|
185
|
-
|
|
186
|
-
<button
|
|
187
|
-
v-if="showClose"
|
|
188
|
-
type="button"
|
|
189
|
-
class="cynx-drawer-close"
|
|
190
|
-
:style="{
|
|
191
|
-
background: 'none',
|
|
192
|
-
border: 'none',
|
|
193
|
-
cursor: 'pointer',
|
|
194
|
-
padding: '6px',
|
|
195
|
-
borderRadius: '6px',
|
|
196
|
-
color: 'var(--muted, #797b8d)',
|
|
197
|
-
display: 'flex',
|
|
198
|
-
alignItems: 'center',
|
|
199
|
-
justifyContent: 'center',
|
|
200
|
-
transition: 'all .14s',
|
|
201
|
-
}"
|
|
202
|
-
@click="close"
|
|
203
|
-
>
|
|
204
|
-
<X :size="18" />
|
|
205
|
-
</button>
|
|
206
|
-
</div>
|
|
207
|
-
|
|
208
|
-
<!-- Body -->
|
|
209
|
-
<div
|
|
210
|
-
class="cynx-drawer-body custom-scrollbar"
|
|
211
|
-
:style="{
|
|
212
|
-
padding: '20px',
|
|
213
|
-
overflowX: 'hidden',
|
|
214
|
-
overflowY: 'auto',
|
|
215
|
-
flex: '1 1 auto',
|
|
216
|
-
minHeight: 0,
|
|
217
|
-
color: 'var(--t, var(--primary-text, #0f111c))',
|
|
218
|
-
...bodyStyle,
|
|
219
|
-
}"
|
|
220
|
-
>
|
|
221
|
-
<slot />
|
|
222
|
-
</div>
|
|
223
|
-
|
|
224
|
-
<!-- Footer -->
|
|
225
|
-
<div
|
|
226
|
-
v-if="$slots.footer"
|
|
227
|
-
class="cynx-drawer-footer"
|
|
228
|
-
:style="{
|
|
229
|
-
display: 'flex',
|
|
230
|
-
justifyContent: 'flex-end',
|
|
231
|
-
gap: '8px',
|
|
232
|
-
padding: '14px 20px',
|
|
233
|
-
borderTop: '1px solid var(--border-light, #ebebf0)',
|
|
234
|
-
background: 'var(--grey-1, #f5f5f8)',
|
|
235
|
-
flexShrink: 0,
|
|
236
|
-
}"
|
|
237
|
-
>
|
|
238
|
-
<slot name="footer" />
|
|
239
|
-
</div>
|
|
240
|
-
</div>
|
|
241
|
-
</div>
|
|
242
|
-
</Teleport>
|
|
243
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, watch, onUnmounted, computed } from "vue";
|
|
3
|
+
import { X } from "lucide-vue-next";
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
modelValue?: boolean;
|
|
8
|
+
open?: boolean;
|
|
9
|
+
title?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
width?: number | string;
|
|
12
|
+
maxWidth?: number | string;
|
|
13
|
+
side?: "right" | "left";
|
|
14
|
+
showClose?: boolean;
|
|
15
|
+
bodyStyle?: Record<string, any>;
|
|
16
|
+
style?: Record<string, any>;
|
|
17
|
+
}>(),
|
|
18
|
+
{
|
|
19
|
+
modelValue: false,
|
|
20
|
+
open: false,
|
|
21
|
+
title: "",
|
|
22
|
+
description: "",
|
|
23
|
+
width: 560,
|
|
24
|
+
maxWidth: "100vw",
|
|
25
|
+
side: "right",
|
|
26
|
+
showClose: true,
|
|
27
|
+
bodyStyle: () => ({}),
|
|
28
|
+
style: () => ({}),
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const emit = defineEmits<{
|
|
33
|
+
(e: "update:modelValue", value: boolean): void;
|
|
34
|
+
(e: "update:open", value: boolean): void;
|
|
35
|
+
(e: "close"): void;
|
|
36
|
+
}>();
|
|
37
|
+
|
|
38
|
+
const isOpen = computed(() => props.modelValue || props.open);
|
|
39
|
+
const closing = ref(false);
|
|
40
|
+
|
|
41
|
+
const STYLES = `
|
|
42
|
+
@keyframes cynxDrawerFadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
43
|
+
@keyframes cynxDrawerFadeOut { from { opacity: 1; } to { opacity: 0; } }
|
|
44
|
+
@keyframes cynxDrawerSlideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
|
|
45
|
+
@keyframes cynxDrawerSlideOutRight { from { transform: translateX(0); } to { transform: translateX(100%); } }
|
|
46
|
+
@keyframes cynxDrawerSlideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }
|
|
47
|
+
@keyframes cynxDrawerSlideOutLeft { from { transform: translateX(0); } to { transform: translateX(-100%); } }
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
let _id = "cynx-drawer-styles";
|
|
51
|
+
function ensureStyles() {
|
|
52
|
+
if (typeof document === "undefined") return;
|
|
53
|
+
if (document.getElementById(_id)) return;
|
|
54
|
+
const tag = document.createElement("style");
|
|
55
|
+
tag.id = _id;
|
|
56
|
+
tag.textContent = STYLES;
|
|
57
|
+
document.head.appendChild(tag);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (typeof document !== "undefined") ensureStyles();
|
|
61
|
+
|
|
62
|
+
function close() {
|
|
63
|
+
if (closing.value) return;
|
|
64
|
+
closing.value = true;
|
|
65
|
+
setTimeout(() => {
|
|
66
|
+
closing.value = false;
|
|
67
|
+
emit("update:modelValue", false);
|
|
68
|
+
emit("update:open", false);
|
|
69
|
+
emit("close");
|
|
70
|
+
}, 260);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
74
|
+
if (e.key === "Escape" && isOpen.value) {
|
|
75
|
+
close();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
watch(
|
|
80
|
+
isOpen,
|
|
81
|
+
(val) => {
|
|
82
|
+
if (typeof document === "undefined") return;
|
|
83
|
+
if (val) {
|
|
84
|
+
document.body.style.overflow = "hidden";
|
|
85
|
+
window.addEventListener("keydown", handleKeydown);
|
|
86
|
+
} else {
|
|
87
|
+
document.body.style.overflow = "";
|
|
88
|
+
window.removeEventListener("keydown", handleKeydown);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{ immediate: true }
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
onUnmounted(() => {
|
|
95
|
+
if (typeof document !== "undefined") {
|
|
96
|
+
document.body.style.overflow = "";
|
|
97
|
+
window.removeEventListener("keydown", handleKeydown);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const resolvedWidth = computed(() => {
|
|
102
|
+
if (typeof props.width === "number") return `${props.width}px`;
|
|
103
|
+
return props.width;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const slideInAnim = computed(() =>
|
|
107
|
+
props.side === "left" ? "cynxDrawerSlideInLeft" : "cynxDrawerSlideInRight"
|
|
108
|
+
);
|
|
109
|
+
const slideOutAnim = computed(() =>
|
|
110
|
+
props.side === "left" ? "cynxDrawerSlideOutLeft" : "cynxDrawerSlideOutRight"
|
|
111
|
+
);
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<template>
|
|
115
|
+
<Teleport to="body">
|
|
116
|
+
<div
|
|
117
|
+
v-if="isOpen || closing"
|
|
118
|
+
class="cynx-drawer-backdrop"
|
|
119
|
+
:style="{
|
|
120
|
+
position: 'fixed',
|
|
121
|
+
inset: 0,
|
|
122
|
+
background: 'rgba(20, 22, 41, .45)',
|
|
123
|
+
zIndex: 8500,
|
|
124
|
+
display: 'flex',
|
|
125
|
+
justifyContent: side === 'left' ? 'flex-start' : 'flex-end',
|
|
126
|
+
animation: `${closing ? 'cynxDrawerFadeOut' : 'cynxDrawerFadeIn'} .26s ease forwards`,
|
|
127
|
+
}"
|
|
128
|
+
@mousedown.self="close"
|
|
129
|
+
>
|
|
130
|
+
<div
|
|
131
|
+
class="cynx-drawer-panel"
|
|
132
|
+
:style="{
|
|
133
|
+
background: 'var(--surface, #ffffff)',
|
|
134
|
+
borderLeft: side === 'right' ? '1px solid var(--border, var(--bd, #e2e8f0))' : 'none',
|
|
135
|
+
borderRight: side === 'left' ? '1px solid var(--border, var(--bd, #e2e8f0))' : 'none',
|
|
136
|
+
width: resolvedWidth,
|
|
137
|
+
maxWidth: '100vw',
|
|
138
|
+
height: '100%',
|
|
139
|
+
boxShadow: 'var(--shadow-lg, 0 20px 60px rgba(0, 0, 0, .25))',
|
|
140
|
+
display: 'flex',
|
|
141
|
+
flexDirection: 'column',
|
|
142
|
+
overflow: 'hidden',
|
|
143
|
+
animation: `${closing ? slideOutAnim : slideInAnim} .26s cubic-bezier(.16, 1, .3, 1) forwards`,
|
|
144
|
+
...style,
|
|
145
|
+
}"
|
|
146
|
+
@mousedown.stop
|
|
147
|
+
>
|
|
148
|
+
<!-- Header -->
|
|
149
|
+
<div
|
|
150
|
+
class="cynx-drawer-hdr"
|
|
151
|
+
:style="{
|
|
152
|
+
display: 'flex',
|
|
153
|
+
alignItems: 'center',
|
|
154
|
+
justifyContent: 'space-between',
|
|
155
|
+
padding: '16px 20px',
|
|
156
|
+
borderBottom: '1px solid var(--border-light, #ebebf0)',
|
|
157
|
+
flexShrink: 0,
|
|
158
|
+
}"
|
|
159
|
+
>
|
|
160
|
+
<slot name="header">
|
|
161
|
+
<div style="display: flex; flex-direction: column; gap: 2px;">
|
|
162
|
+
<span
|
|
163
|
+
class="cynx-drawer-title"
|
|
164
|
+
:style="{
|
|
165
|
+
fontSize: '1rem',
|
|
166
|
+
fontWeight: 700,
|
|
167
|
+
letterSpacing: '-.01em',
|
|
168
|
+
color: 'var(--t, var(--primary-text, #0f111c))',
|
|
169
|
+
}"
|
|
170
|
+
>
|
|
171
|
+
{{ title }}
|
|
172
|
+
</span>
|
|
173
|
+
<span
|
|
174
|
+
v-if="description"
|
|
175
|
+
class="cynx-drawer-desc"
|
|
176
|
+
:style="{
|
|
177
|
+
fontSize: '.75rem',
|
|
178
|
+
color: 'var(--muted, #797b8d)',
|
|
179
|
+
}"
|
|
180
|
+
>
|
|
181
|
+
{{ description }}
|
|
182
|
+
</span>
|
|
183
|
+
</div>
|
|
184
|
+
</slot>
|
|
185
|
+
|
|
186
|
+
<button
|
|
187
|
+
v-if="showClose"
|
|
188
|
+
type="button"
|
|
189
|
+
class="cynx-drawer-close"
|
|
190
|
+
:style="{
|
|
191
|
+
background: 'none',
|
|
192
|
+
border: 'none',
|
|
193
|
+
cursor: 'pointer',
|
|
194
|
+
padding: '6px',
|
|
195
|
+
borderRadius: '6px',
|
|
196
|
+
color: 'var(--muted, #797b8d)',
|
|
197
|
+
display: 'flex',
|
|
198
|
+
alignItems: 'center',
|
|
199
|
+
justifyContent: 'center',
|
|
200
|
+
transition: 'all .14s',
|
|
201
|
+
}"
|
|
202
|
+
@click="close"
|
|
203
|
+
>
|
|
204
|
+
<X :size="18" />
|
|
205
|
+
</button>
|
|
206
|
+
</div>
|
|
207
|
+
|
|
208
|
+
<!-- Body -->
|
|
209
|
+
<div
|
|
210
|
+
class="cynx-drawer-body custom-scrollbar"
|
|
211
|
+
:style="{
|
|
212
|
+
padding: '20px',
|
|
213
|
+
overflowX: 'hidden',
|
|
214
|
+
overflowY: 'auto',
|
|
215
|
+
flex: '1 1 auto',
|
|
216
|
+
minHeight: 0,
|
|
217
|
+
color: 'var(--t, var(--primary-text, #0f111c))',
|
|
218
|
+
...bodyStyle,
|
|
219
|
+
}"
|
|
220
|
+
>
|
|
221
|
+
<slot />
|
|
222
|
+
</div>
|
|
223
|
+
|
|
224
|
+
<!-- Footer -->
|
|
225
|
+
<div
|
|
226
|
+
v-if="$slots.footer"
|
|
227
|
+
class="cynx-drawer-footer"
|
|
228
|
+
:style="{
|
|
229
|
+
display: 'flex',
|
|
230
|
+
justifyContent: 'flex-end',
|
|
231
|
+
gap: '8px',
|
|
232
|
+
padding: '14px 20px',
|
|
233
|
+
borderTop: '1px solid var(--border-light, #ebebf0)',
|
|
234
|
+
background: 'var(--grey-1, #f5f5f8)',
|
|
235
|
+
flexShrink: 0,
|
|
236
|
+
}"
|
|
237
|
+
>
|
|
238
|
+
<slot name="footer" />
|
|
239
|
+
</div>
|
|
240
|
+
</div>
|
|
241
|
+
</div>
|
|
242
|
+
</Teleport>
|
|
243
|
+
</template>
|