@teammodlr/ui-kit 3.0.0-beta.9 → 3.0.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/lib/components/cardcontextmenu/CardContextMenu.vue.d.ts +4 -2
- package/lib/components/checkbox/Checkbox.vue.d.ts +4 -4
- package/lib/components/clearbutton/ClearButton.vue.d.ts +9 -0
- package/lib/components/clearbutton/style/ClearButton.css.d.ts +2 -0
- package/lib/components/clearbutton/style/index.d.ts +1 -0
- package/lib/components/colorpicker/ColorPicker.vue.d.ts +6 -4
- package/lib/components/colorpicker/style/ColorPicker.css.d.ts +1 -0
- package/lib/components/dialog/Dialog.vue.d.ts +14 -6
- package/lib/components/dialog/style/Dialog.css.d.ts +2 -0
- package/lib/components/drawer/Drawer.vue.d.ts +146 -0
- package/lib/components/drawer/style/Drawer.css.d.ts +33 -0
- package/lib/components/drawer/style/index.d.ts +1 -0
- package/lib/components/dropdown/Dropdown.vue.d.ts +4 -2
- package/lib/components/form/Form.vue.d.ts +4 -2
- package/lib/components/hovercard/HoverCard.vue.d.ts +124 -0
- package/lib/components/hovercard/style/HoverCard.css.d.ts +3 -0
- package/lib/components/hovercard/style/index.d.ts +1 -0
- package/lib/components/index.d.ts +3 -0
- package/lib/components/input/Input.vue.d.ts +20 -5
- package/lib/components/input/style/Input.css.d.ts +4 -0
- package/lib/components/modal/Modal.vue.d.ts +11 -4
- package/lib/components/pagination/Pagination.vue.d.ts +6 -3
- package/lib/components/paneldialog/PanelDialog.vue.d.ts +175 -0
- package/lib/components/paneldialog/style/PanelDialog.css.d.ts +8 -0
- package/lib/components/paneldialog/style/index.d.ts +1 -0
- package/lib/components/popover/Popover.vue.d.ts +28 -2
- package/lib/components/radio/Radio.vue.d.ts +5 -5
- package/lib/components/radiobutton/RadioButton.vue.d.ts +4 -4
- package/lib/components/radiobuttongroup/RadioButtonGroup.vue.d.ts +4 -2
- package/lib/components/select/Select.vue.d.ts +94 -91
- package/lib/components/select/style/Select.css.d.ts +9 -1
- package/lib/components/slider/Slider.vue.d.ts +6 -3
- package/lib/components/switch/Switch.vue.d.ts +4 -4
- package/lib/components/tab/Tab.vue.d.ts +10 -2
- package/lib/components/tab/TabGroup.vue.d.ts +6 -3
- package/lib/components/table/Table.vue.d.ts +4 -2
- package/lib/components/textarea/Textarea.vue.d.ts +16 -5
- package/lib/components/textarea/style/Textarea.css.d.ts +2 -0
- package/lib/components/tree/Tree.vue.d.ts +6 -3
- package/lib/composables/useInput.d.ts +9 -2
- package/lib/index.cjs.js +3 -3
- package/lib/index.es.js +8526 -6393
- package/lib/style.css +1 -1
- package/lib/tsconfig.app.tsbuildinfo +1 -0
- package/lib/tsconfig.vitest.tsbuildinfo +1 -0
- package/package.json +7 -4
- package/src/components/cardcontextmenu/CardContextMenu.vue +3 -1
- package/src/components/cardcontextmenu/style/Dropdown.css.ts +7 -0
- package/src/components/clearbutton/ClearButton.vue +41 -0
- package/src/components/clearbutton/style/ClearButton.css.ts +37 -0
- package/src/components/clearbutton/style/index.ts +1 -0
- package/src/components/colorpicker/ColorPicker.vue +12 -12
- package/src/components/colorpicker/examples/basic.vue +8 -17
- package/src/components/colorpicker/style/ColorPicker.css.ts +6 -1
- package/src/components/dialog/Dialog.vue +12 -6
- package/src/components/dialog/style/Dialog.css.ts +30 -0
- package/src/components/drawer/Drawer.vue +280 -0
- package/src/components/drawer/examples/basic.vue +15 -0
- package/src/components/drawer/examples/custom-title.vue +21 -0
- package/src/components/drawer/examples/index.stories.ts +24 -0
- package/src/components/drawer/examples/index.ts +7 -0
- package/src/components/drawer/examples/no-mask.vue +15 -0
- package/src/components/drawer/examples/no-outside-close.vue +15 -0
- package/src/components/drawer/examples/placements.vue +28 -0
- package/src/components/drawer/examples/with-footer.vue +21 -0
- package/src/components/drawer/examples/with-trigger.vue +13 -0
- package/src/components/drawer/style/Drawer.css.ts +208 -0
- package/src/components/drawer/style/index.ts +1 -0
- package/src/components/dropdown/Dropdown.vue +4 -2
- package/src/components/form/Form.vue +3 -3
- package/src/components/hovercard/HoverCard.vue +165 -0
- package/src/components/hovercard/style/HoverCard.css.ts +175 -0
- package/src/components/hovercard/style/index.ts +1 -0
- package/src/components/index.ts +3 -0
- package/src/components/input/Input.vue +52 -4
- package/src/components/input/examples/clearable.vue +18 -0
- package/src/components/input/examples/index.stories.ts +3 -1
- package/src/components/input/examples/index.ts +1 -0
- package/src/components/input/style/Input.css.ts +19 -0
- package/src/components/messageprovider/MessageProvider.vue +33 -7
- package/src/components/modal/Modal.vue +28 -11
- package/src/components/pagination/Pagination.vue +4 -1
- package/src/components/paneldialog/PanelDialog.vue +509 -0
- package/src/components/paneldialog/examples/basic.vue +36 -0
- package/src/components/paneldialog/examples/index.stories.ts +22 -0
- package/src/components/paneldialog/examples/index.ts +2 -0
- package/src/components/paneldialog/examples/modal.vue +31 -0
- package/src/components/paneldialog/style/PanelDialog.css.ts +90 -0
- package/src/components/paneldialog/style/index.ts +1 -0
- package/src/components/popover/Popover.vue +9 -2
- package/src/components/radiobuttongroup/RadioButtonGroup.vue +3 -1
- package/src/components/select/Select.vue +211 -111
- package/src/components/select/examples/clearable.vue +18 -0
- package/src/components/select/examples/fill.vue +52 -0
- package/src/components/select/examples/index.stories.ts +4 -1
- package/src/components/select/examples/index.ts +3 -0
- package/src/components/select/examples/remote.vue +54 -0
- package/src/components/select/style/Select.css.ts +140 -24
- package/src/components/slider/Slider.vue +4 -1
- package/src/components/tab/Tab.vue +4 -2
- package/src/components/tab/TabGroup.vue +4 -4
- package/src/components/tab/style/Tab.css.ts +6 -0
- package/src/components/table/Table.vue +3 -3
- package/src/components/textarea/Textarea.vue +40 -4
- package/src/components/textarea/examples/clearable.vue +16 -0
- package/src/components/textarea/examples/index.stories.ts +2 -1
- package/src/components/textarea/examples/index.ts +1 -0
- package/src/components/textarea/style/Textarea.css.ts +10 -0
- package/src/components/tree/Tree.vue +4 -1
- package/src/composables/useInput.ts +10 -2
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<DialogRoot :open="isOpen" :modal="modal" @update:open="handleOpenChange">
|
|
3
|
+
<DialogPortal to="body">
|
|
4
|
+
<Transition
|
|
5
|
+
type="animation"
|
|
6
|
+
:enter-active-class="fade.enterActive"
|
|
7
|
+
:leave-active-class="fade.leaveActive"
|
|
8
|
+
:enter-from-class="fade.enterFrom"
|
|
9
|
+
:leave-to-class="fade.leaveTo"
|
|
10
|
+
>
|
|
11
|
+
<DialogOverlay v-if="isOpen && modal" force-mount :class="style.backdrop" :style="{ zIndex, pointerEvents: 'auto' }" />
|
|
12
|
+
</Transition>
|
|
13
|
+
<Transition
|
|
14
|
+
type="animation"
|
|
15
|
+
:enter-active-class="modalScale.enterActive"
|
|
16
|
+
:leave-active-class="modalScale.leaveActive"
|
|
17
|
+
:enter-from-class="modalScale.enterFrom"
|
|
18
|
+
:leave-to-class="modalScale.leaveTo"
|
|
19
|
+
@after-leave="handleAfterLeave"
|
|
20
|
+
>
|
|
21
|
+
<DialogContent
|
|
22
|
+
v-if="isOpen"
|
|
23
|
+
ref="dialogContent"
|
|
24
|
+
force-mount
|
|
25
|
+
:class="contentClasses"
|
|
26
|
+
:style="contentStyle"
|
|
27
|
+
:disable-outside-pointer-events="modal"
|
|
28
|
+
@open-auto-focus="handleOpenAutoFocus"
|
|
29
|
+
@escape-key-down="handleEscapeKeyDown"
|
|
30
|
+
@pointer-down-outside.prevent
|
|
31
|
+
@focus-outside="handleFocusOutside"
|
|
32
|
+
@interact-outside.prevent
|
|
33
|
+
>
|
|
34
|
+
<FocusScope :trapped="focusTrap" :loop="focusTrap" :class="focusScopeClasses">
|
|
35
|
+
<slot name="backdrop" />
|
|
36
|
+
<div v-if="backdrop && !$slots.backdrop" :class="[style.backdrop, backdropClass]" />
|
|
37
|
+
<div
|
|
38
|
+
ref="panel"
|
|
39
|
+
:class="[style.panel, panelClass]"
|
|
40
|
+
:style="panelComputedStyle"
|
|
41
|
+
@pointerdown="onPanelPointerDown"
|
|
42
|
+
>
|
|
43
|
+
<slot :close="close" />
|
|
44
|
+
</div>
|
|
45
|
+
</FocusScope>
|
|
46
|
+
</DialogContent>
|
|
47
|
+
</Transition>
|
|
48
|
+
</DialogPortal>
|
|
49
|
+
</DialogRoot>
|
|
50
|
+
</template>
|
|
51
|
+
<script lang="ts">
|
|
52
|
+
import { fade, modalScale } from '../../styles/transitions.css';
|
|
53
|
+
import {
|
|
54
|
+
DialogContent,
|
|
55
|
+
DialogOverlay,
|
|
56
|
+
DialogPortal,
|
|
57
|
+
DialogRoot,
|
|
58
|
+
FocusScope
|
|
59
|
+
} from 'reka-ui';
|
|
60
|
+
import {
|
|
61
|
+
computed,
|
|
62
|
+
defineComponent,
|
|
63
|
+
nextTick,
|
|
64
|
+
onBeforeUnmount,
|
|
65
|
+
provide,
|
|
66
|
+
ref,
|
|
67
|
+
shallowRef,
|
|
68
|
+
watch,
|
|
69
|
+
type ComponentPublicInstance,
|
|
70
|
+
type CSSProperties,
|
|
71
|
+
type PropType
|
|
72
|
+
} from 'vue';
|
|
73
|
+
import type { ComputedRef } from 'vue';
|
|
74
|
+
import { useZIndex, ZINDEX } from '../../composables/useZIndex';
|
|
75
|
+
import { useEventListener } from '@vueuse/core';
|
|
76
|
+
import * as style from './style';
|
|
77
|
+
|
|
78
|
+
function toCssSize(value: number | string | undefined): string | undefined {
|
|
79
|
+
if (value === undefined) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return typeof value === 'number' ? `${value}px` : value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function resolveElement(
|
|
87
|
+
value: HTMLElement | ComponentPublicInstance | null | undefined
|
|
88
|
+
): HTMLElement | null {
|
|
89
|
+
if (!value) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (value instanceof HTMLElement) {
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if ('$el' in value && value.$el instanceof HTMLElement) {
|
|
98
|
+
return value.$el;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default defineComponent({
|
|
105
|
+
name: 'PanelDialog',
|
|
106
|
+
components: {
|
|
107
|
+
DialogContent,
|
|
108
|
+
DialogOverlay,
|
|
109
|
+
DialogPortal,
|
|
110
|
+
DialogRoot,
|
|
111
|
+
FocusScope
|
|
112
|
+
},
|
|
113
|
+
props: {
|
|
114
|
+
open: {
|
|
115
|
+
type: Boolean,
|
|
116
|
+
default: false
|
|
117
|
+
},
|
|
118
|
+
modal: {
|
|
119
|
+
type: Boolean,
|
|
120
|
+
default: false
|
|
121
|
+
},
|
|
122
|
+
width: {
|
|
123
|
+
type: [Number, String] as PropType<number | string>,
|
|
124
|
+
default: '500px'
|
|
125
|
+
},
|
|
126
|
+
height: {
|
|
127
|
+
type: [Number, String] as PropType<number | string>,
|
|
128
|
+
default: undefined
|
|
129
|
+
},
|
|
130
|
+
maxHeight: {
|
|
131
|
+
type: [Number, String] as PropType<number | string>,
|
|
132
|
+
default: '85vh'
|
|
133
|
+
},
|
|
134
|
+
draggable: {
|
|
135
|
+
type: Boolean,
|
|
136
|
+
default: true
|
|
137
|
+
},
|
|
138
|
+
handleSelector: {
|
|
139
|
+
type: String,
|
|
140
|
+
default: '[data-panel-handle]'
|
|
141
|
+
},
|
|
142
|
+
backdrop: {
|
|
143
|
+
type: Boolean,
|
|
144
|
+
default: false
|
|
145
|
+
},
|
|
146
|
+
backdropClass: {
|
|
147
|
+
type: String,
|
|
148
|
+
default: ''
|
|
149
|
+
},
|
|
150
|
+
panelClass: {
|
|
151
|
+
type: [String, Array, Object] as PropType<string | unknown[] | Record<string, unknown>>,
|
|
152
|
+
default: ''
|
|
153
|
+
},
|
|
154
|
+
panelStyle: {
|
|
155
|
+
type: Object as PropType<CSSProperties>,
|
|
156
|
+
default: undefined
|
|
157
|
+
},
|
|
158
|
+
zIndex: {
|
|
159
|
+
type: Number
|
|
160
|
+
},
|
|
161
|
+
focusTrap: {
|
|
162
|
+
type: Boolean,
|
|
163
|
+
default: true
|
|
164
|
+
},
|
|
165
|
+
onClose: {
|
|
166
|
+
type: Function as PropType<() => void>,
|
|
167
|
+
default: () => {}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
emits: {
|
|
171
|
+
onOpen: () => true,
|
|
172
|
+
onClose: () => true,
|
|
173
|
+
'update:open': (_value: boolean) => true,
|
|
174
|
+
open: () => true,
|
|
175
|
+
close: () => true,
|
|
176
|
+
// Fired once the leave animation has finished and the panel is out of the DOM
|
|
177
|
+
'after-leave': () => true
|
|
178
|
+
},
|
|
179
|
+
setup(props, { emit, expose }) {
|
|
180
|
+
const dialogContent = shallowRef<HTMLElement | ComponentPublicInstance | null>(null);
|
|
181
|
+
const panel = ref<HTMLElement | null>(null);
|
|
182
|
+
const { nextZIndex, current: maxZIndex } = useZIndex();
|
|
183
|
+
const zIndex = ref(props.zIndex ?? nextZIndex());
|
|
184
|
+
provide(ZINDEX, zIndex);
|
|
185
|
+
const hasOpened = ref(false);
|
|
186
|
+
|
|
187
|
+
const offsetX = ref(0);
|
|
188
|
+
const offsetY = ref(0);
|
|
189
|
+
const isDragging = ref(false);
|
|
190
|
+
|
|
191
|
+
const dialogContentElement = computed(() => resolveElement(dialogContent.value));
|
|
192
|
+
|
|
193
|
+
const isOpen = computed(() => props.open);
|
|
194
|
+
|
|
195
|
+
const contentClasses = computed(() => [
|
|
196
|
+
style.dialogContent,
|
|
197
|
+
props.modal ? style.dialogContentModal : style.dialogContentNonModal
|
|
198
|
+
]);
|
|
199
|
+
|
|
200
|
+
const contentStyle: ComputedRef<CSSProperties> = computed(() => ({
|
|
201
|
+
zIndex: zIndex.value
|
|
202
|
+
}));
|
|
203
|
+
|
|
204
|
+
const focusScopeClasses = computed(() => [
|
|
205
|
+
style.focusScope,
|
|
206
|
+
props.modal ? style.focusScopeModal : style.focusScopeNonModal
|
|
207
|
+
]);
|
|
208
|
+
|
|
209
|
+
const panelComputedStyle: ComputedRef<CSSProperties> = computed(() => ({
|
|
210
|
+
...props.panelStyle,
|
|
211
|
+
width: toCssSize(props.width),
|
|
212
|
+
height: toCssSize(props.height),
|
|
213
|
+
maxHeight: toCssSize(props.maxHeight),
|
|
214
|
+
transform: `translate(${offsetX.value}px, ${offsetY.value}px)`
|
|
215
|
+
}));
|
|
216
|
+
|
|
217
|
+
const focusableSelector = [
|
|
218
|
+
'[autofocus]',
|
|
219
|
+
'input:not([type="hidden"])',
|
|
220
|
+
'textarea',
|
|
221
|
+
'select',
|
|
222
|
+
'[contenteditable="true"]',
|
|
223
|
+
'button',
|
|
224
|
+
'a[href]',
|
|
225
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
226
|
+
].join(', ');
|
|
227
|
+
|
|
228
|
+
function close(): void {
|
|
229
|
+
handleOpenChange(false);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function handleEscapeKeyDown(event: KeyboardEvent): void {
|
|
233
|
+
event.preventDefault();
|
|
234
|
+
event.stopPropagation();
|
|
235
|
+
close();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function handleAfterLeave(): void {
|
|
239
|
+
emit('close');
|
|
240
|
+
emit('after-leave');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function onCloseEmit(): void {
|
|
244
|
+
emit('onClose');
|
|
245
|
+
if (props.onClose) {
|
|
246
|
+
props.onClose();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function onEnter(): void {
|
|
251
|
+
emit('onOpen');
|
|
252
|
+
emit('open');
|
|
253
|
+
zIndex.value = props.zIndex ?? nextZIndex();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function handleFocusOutside(event: Event): void {
|
|
257
|
+
event.preventDefault();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function handleOpenAutoFocus(event: Event): void {
|
|
261
|
+
const element = dialogContentElement.value ?? panel.value;
|
|
262
|
+
|
|
263
|
+
if (!element) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const firstFocusableElement = Array.from(
|
|
268
|
+
element.querySelectorAll<HTMLElement>(focusableSelector)
|
|
269
|
+
).find(candidate => {
|
|
270
|
+
return (
|
|
271
|
+
!candidate.matches(':disabled') &&
|
|
272
|
+
candidate.getAttribute('aria-disabled') !== 'true' &&
|
|
273
|
+
candidate.getAttribute('aria-hidden') !== 'true' &&
|
|
274
|
+
candidate.getClientRects().length > 0
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
if (!firstFocusableElement) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
event.preventDefault();
|
|
283
|
+
firstFocusableElement.focus();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function handleOpenChange(value: boolean): void {
|
|
287
|
+
if (!value && props.open) {
|
|
288
|
+
emit('update:open', false);
|
|
289
|
+
onCloseEmit();
|
|
290
|
+
hasOpened.value = false;
|
|
291
|
+
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
emit('update:open', value);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function clampOffset(): void {
|
|
299
|
+
const element = panel.value;
|
|
300
|
+
|
|
301
|
+
if (!element) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const rect = element.getBoundingClientRect();
|
|
306
|
+
let dx = 0;
|
|
307
|
+
let dy = 0;
|
|
308
|
+
|
|
309
|
+
if (rect.width < window.innerWidth) {
|
|
310
|
+
if (rect.left < 0) {
|
|
311
|
+
dx = -rect.left;
|
|
312
|
+
} else if (rect.right > window.innerWidth) {
|
|
313
|
+
dx = window.innerWidth - rect.right;
|
|
314
|
+
}
|
|
315
|
+
} else if (rect.left !== 0) {
|
|
316
|
+
dx = -rect.left;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (rect.height < window.innerHeight) {
|
|
320
|
+
if (rect.top < 0) {
|
|
321
|
+
dy = -rect.top;
|
|
322
|
+
} else if (rect.bottom > window.innerHeight) {
|
|
323
|
+
dy = window.innerHeight - rect.bottom;
|
|
324
|
+
}
|
|
325
|
+
} else if (rect.top !== 0) {
|
|
326
|
+
dy = -rect.top;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (dx !== 0 || dy !== 0) {
|
|
330
|
+
offsetX.value += dx;
|
|
331
|
+
offsetY.value += dy;
|
|
332
|
+
element.style.transform = `translate(${offsetX.value}px, ${offsetY.value}px)`;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function resetPosition(): void {
|
|
337
|
+
offsetX.value = 0;
|
|
338
|
+
offsetY.value = 0;
|
|
339
|
+
|
|
340
|
+
if (panel.value) {
|
|
341
|
+
panel.value.style.transform = 'translate(0px, 0px)';
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
interface DragState {
|
|
346
|
+
startX: number;
|
|
347
|
+
startY: number;
|
|
348
|
+
baseX: number;
|
|
349
|
+
baseY: number;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
let dragState: DragState | null = null;
|
|
353
|
+
|
|
354
|
+
function onPointerMove(event: PointerEvent): void {
|
|
355
|
+
if (!dragState || !panel.value) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const element = panel.value;
|
|
360
|
+
const renderedRect = element.getBoundingClientRect();
|
|
361
|
+
const renderedX = offsetX.value;
|
|
362
|
+
const renderedY = offsetY.value;
|
|
363
|
+
let nextX = dragState.baseX + (event.clientX - dragState.startX);
|
|
364
|
+
let nextY = dragState.baseY + (event.clientY - dragState.startY);
|
|
365
|
+
const dx = nextX - renderedX;
|
|
366
|
+
const dy = nextY - renderedY;
|
|
367
|
+
const nextRect = {
|
|
368
|
+
left: renderedRect.left + dx,
|
|
369
|
+
right: renderedRect.right + dx,
|
|
370
|
+
top: renderedRect.top + dy,
|
|
371
|
+
bottom: renderedRect.bottom + dy,
|
|
372
|
+
width: renderedRect.width,
|
|
373
|
+
height: renderedRect.height
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
if (nextRect.width < window.innerWidth) {
|
|
377
|
+
if (nextRect.left < 0) {
|
|
378
|
+
nextX -= nextRect.left;
|
|
379
|
+
} else if (nextRect.right > window.innerWidth) {
|
|
380
|
+
nextX -= nextRect.right - window.innerWidth;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (nextRect.height < window.innerHeight) {
|
|
385
|
+
if (nextRect.top < 0) {
|
|
386
|
+
nextY -= nextRect.top;
|
|
387
|
+
} else if (nextRect.bottom > window.innerHeight) {
|
|
388
|
+
nextY -= nextRect.bottom - window.innerHeight;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
offsetX.value = nextX;
|
|
393
|
+
offsetY.value = nextY;
|
|
394
|
+
element.style.transform = `translate(${nextX}px, ${nextY}px)`;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function onPointerUp(): void {
|
|
398
|
+
dragState = null;
|
|
399
|
+
isDragging.value = false;
|
|
400
|
+
window.removeEventListener('pointermove', onPointerMove);
|
|
401
|
+
window.removeEventListener('pointerup', onPointerUp);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function onPanelPointerDown(event: PointerEvent): void {
|
|
405
|
+
if (!props.draggable || !panel.value) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (event.button !== 0) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const target = event.target as HTMLElement | null;
|
|
414
|
+
|
|
415
|
+
if (!target || typeof target.closest !== 'function') {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (props.handleSelector && !target.closest(props.handleSelector)) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (
|
|
424
|
+
target.closest(
|
|
425
|
+
'button, input, select, textarea, a[href], [contenteditable="true"]'
|
|
426
|
+
)
|
|
427
|
+
) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (zIndex.value < maxZIndex.value) {
|
|
432
|
+
zIndex.value = nextZIndex();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
dragState = {
|
|
436
|
+
startX: event.clientX,
|
|
437
|
+
startY: event.clientY,
|
|
438
|
+
baseX: offsetX.value,
|
|
439
|
+
baseY: offsetY.value
|
|
440
|
+
};
|
|
441
|
+
isDragging.value = true;
|
|
442
|
+
window.addEventListener('pointermove', onPointerMove);
|
|
443
|
+
window.addEventListener('pointerup', onPointerUp);
|
|
444
|
+
event.preventDefault();
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function onWindowResize(): void {
|
|
448
|
+
if (props.open) {
|
|
449
|
+
nextTick(() => clampOffset());
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
useEventListener(window, 'resize', onWindowResize);
|
|
454
|
+
|
|
455
|
+
onBeforeUnmount(() => {
|
|
456
|
+
window.removeEventListener('pointermove', onPointerMove);
|
|
457
|
+
window.removeEventListener('pointerup', onPointerUp);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
watch(
|
|
461
|
+
() => props.open,
|
|
462
|
+
async newVal => {
|
|
463
|
+
if (newVal) {
|
|
464
|
+
await nextTick();
|
|
465
|
+
resetPosition();
|
|
466
|
+
nextTick(() => clampOffset());
|
|
467
|
+
zIndex.value = props.zIndex ?? nextZIndex();
|
|
468
|
+
if (!hasOpened.value) {
|
|
469
|
+
onEnter();
|
|
470
|
+
hasOpened.value = true;
|
|
471
|
+
}
|
|
472
|
+
} else {
|
|
473
|
+
hasOpened.value = false;
|
|
474
|
+
if (dragState) {
|
|
475
|
+
onPointerUp();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
{ immediate: true }
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
expose({
|
|
483
|
+
close
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
return {
|
|
487
|
+
dialogContent,
|
|
488
|
+
panel,
|
|
489
|
+
zIndex,
|
|
490
|
+
fade,
|
|
491
|
+
modalScale,
|
|
492
|
+
style,
|
|
493
|
+
isOpen,
|
|
494
|
+
contentClasses,
|
|
495
|
+
contentStyle,
|
|
496
|
+
focusScopeClasses,
|
|
497
|
+
panelComputedStyle,
|
|
498
|
+
isDragging,
|
|
499
|
+
close,
|
|
500
|
+
handleAfterLeave,
|
|
501
|
+
handleEscapeKeyDown,
|
|
502
|
+
handleOpenChange,
|
|
503
|
+
handleOpenAutoFocus,
|
|
504
|
+
handleFocusOutside,
|
|
505
|
+
onPanelPointerDown
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
</script>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<button @click="open = true">Open panel</button>
|
|
4
|
+
<MPanelDialog
|
|
5
|
+
v-model:open="open"
|
|
6
|
+
:modal="false"
|
|
7
|
+
width="500px"
|
|
8
|
+
:draggable="true"
|
|
9
|
+
@onClose="closed"
|
|
10
|
+
>
|
|
11
|
+
<div data-panel-handle style="padding: 12px 16px; border-bottom: 1px solid #e4e2ea; font-weight: 600;">
|
|
12
|
+
Draggable panel (grab here)
|
|
13
|
+
</div>
|
|
14
|
+
<div style="padding: 16px; display: flex; flex-direction: column; gap: 12px;">
|
|
15
|
+
<p style="margin: 0;">Non-modal floating panel. Drag by the header. Background stays interactive.</p>
|
|
16
|
+
<MInput placeholder="Focus me — blue ring must remain" />
|
|
17
|
+
<input type="text" placeholder="Native input" />
|
|
18
|
+
<div style="display: flex; gap: 8px; justify-content: flex-end;">
|
|
19
|
+
<button @click="open = false">Close</button>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</MPanelDialog>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<script lang="ts" setup>
|
|
27
|
+
import { ref } from 'vue';
|
|
28
|
+
import MPanelDialog from '../PanelDialog.vue';
|
|
29
|
+
import MInput from '../../input/Input.vue';
|
|
30
|
+
|
|
31
|
+
const open = ref(false);
|
|
32
|
+
|
|
33
|
+
function closed(): void {
|
|
34
|
+
console.log('closed');
|
|
35
|
+
}
|
|
36
|
+
</script>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import MPanelDialog from '../PanelDialog.vue';
|
|
2
|
+
import { MPanelDialogBasic, MPanelDialogModal } from './index';
|
|
3
|
+
import { createStory } from '../../../__storybook__';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
component: MPanelDialog,
|
|
7
|
+
title: 'Components/PanelDialog',
|
|
8
|
+
argTypes: {
|
|
9
|
+
open: { control: 'boolean' },
|
|
10
|
+
modal: { control: 'boolean' },
|
|
11
|
+
draggable: { control: 'boolean' },
|
|
12
|
+
width: { control: 'text' },
|
|
13
|
+
height: { control: 'text' },
|
|
14
|
+
maxHeight: { control: 'text' },
|
|
15
|
+
handleSelector: { control: 'text' },
|
|
16
|
+
backdrop: { control: 'boolean' },
|
|
17
|
+
focusTrap: { control: 'boolean' }
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const Basic = createStory(MPanelDialogBasic);
|
|
22
|
+
export const Modal = createStory(MPanelDialogModal);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<button @click="open = true">Open modal panel</button>
|
|
4
|
+
<MPanelDialog
|
|
5
|
+
v-model:open="open"
|
|
6
|
+
:modal="true"
|
|
7
|
+
width="520px"
|
|
8
|
+
:draggable="false"
|
|
9
|
+
:backdrop="true"
|
|
10
|
+
>
|
|
11
|
+
<div data-panel-handle style="padding: 12px 16px; border-bottom: 1px solid #e4e2ea; font-weight: 600;">
|
|
12
|
+
Modal panel (drag disabled)
|
|
13
|
+
</div>
|
|
14
|
+
<div style="padding: 16px; display: flex; flex-direction: column; gap: 12px;">
|
|
15
|
+
<p style="margin: 0;">Modal variant blocks background interaction and shows an overlay.</p>
|
|
16
|
+
<MInput placeholder="Focus trap stays inside" />
|
|
17
|
+
<div style="display: flex; gap: 8px; justify-content: flex-end;">
|
|
18
|
+
<button @click="open = false">Close</button>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</MPanelDialog>
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script lang="ts" setup>
|
|
26
|
+
import { ref } from 'vue';
|
|
27
|
+
import MPanelDialog from '../PanelDialog.vue';
|
|
28
|
+
import MInput from '../../input/Input.vue';
|
|
29
|
+
|
|
30
|
+
const open = ref(false);
|
|
31
|
+
</script>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { globalStyle, style } from '@vanilla-extract/css';
|
|
2
|
+
import { themeVars } from '../../../styles/theme.css';
|
|
3
|
+
|
|
4
|
+
export const backdrop = style({
|
|
5
|
+
position: 'fixed',
|
|
6
|
+
inset: 0,
|
|
7
|
+
backgroundColor: 'rgba(0,0,0,.45)',
|
|
8
|
+
pointerEvents: 'none'
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const dialogContent = style({
|
|
12
|
+
position: 'fixed',
|
|
13
|
+
inset: 0,
|
|
14
|
+
display: 'flex',
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
justifyContent: 'center',
|
|
17
|
+
outline: 'none',
|
|
18
|
+
selectors: {
|
|
19
|
+
'&:focus': {
|
|
20
|
+
outline: 'none'
|
|
21
|
+
},
|
|
22
|
+
'&:focus-visible': {
|
|
23
|
+
outline: 'none'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const dialogContentModal = style({
|
|
29
|
+
pointerEvents: 'auto'
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const dialogContentNonModal = style({
|
|
33
|
+
pointerEvents: 'none'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const focusScope = style({
|
|
37
|
+
display: 'flex',
|
|
38
|
+
alignItems: 'center',
|
|
39
|
+
justifyContent: 'center',
|
|
40
|
+
width: '100%',
|
|
41
|
+
height: '100%',
|
|
42
|
+
outline: 'none',
|
|
43
|
+
selectors: {
|
|
44
|
+
'&:focus': {
|
|
45
|
+
outline: 'none'
|
|
46
|
+
},
|
|
47
|
+
'&:focus-visible': {
|
|
48
|
+
outline: 'none'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const focusScopeNonModal = style({
|
|
54
|
+
pointerEvents: 'none'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const focusScopeModal = style({
|
|
58
|
+
pointerEvents: 'auto'
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const panel = style({
|
|
62
|
+
position: 'relative',
|
|
63
|
+
display: 'flex',
|
|
64
|
+
flexDirection: 'column',
|
|
65
|
+
backgroundColor: '#FFF',
|
|
66
|
+
backgroundClip: 'padding-box',
|
|
67
|
+
border: `1px solid ${themeVars.color.gray[300]}`,
|
|
68
|
+
borderRadius: themeVars.rounded.medium,
|
|
69
|
+
boxShadow: `2px 2px 8px rgba(128, 128, 128, 0.1), 0 9px 28px 8px rgba(0,0,0,.05)`,
|
|
70
|
+
overflow: 'hidden',
|
|
71
|
+
outline: 'none',
|
|
72
|
+
pointerEvents: 'auto',
|
|
73
|
+
maxWidth: 'calc(100vw - 32px)',
|
|
74
|
+
selectors: {
|
|
75
|
+
'&:focus': {
|
|
76
|
+
outline: 'none'
|
|
77
|
+
},
|
|
78
|
+
'&:focus-visible': {
|
|
79
|
+
outline: 'none'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
globalStyle(`${panel} [data-panel-handle]`, {
|
|
85
|
+
cursor: 'grab'
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
globalStyle(`${panel} [data-panel-handle]:active`, {
|
|
89
|
+
cursor: 'grabbing'
|
|
90
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PanelDialog.css';
|