@teammodlr/ui-kit 2.1.67 → 2.1.69

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.
@@ -0,0 +1,51 @@
1
+ <template>
2
+ <div>
3
+ <button @click="showDialog">Show Dialog</button>
4
+ <button @click="showDialog2">Show Dialog 2</button>
5
+ {{ testTitle }}
6
+ </div>
7
+ </template>
8
+
9
+ <script lang="ts" setup>
10
+ import {ref, h} from 'vue';
11
+ import {useDialog} from '../useDialog';
12
+
13
+ const dialog = useDialog();
14
+ const testTitle = ref('This is a test');
15
+
16
+ function renderMessage({message}: { message: string }) {
17
+ return h('p', [
18
+ 'Here are ',
19
+ h('span', {style: 'color: red'}, [message]),
20
+ ' that using render function',
21
+ ]);
22
+ }
23
+
24
+ function showDialog() {
25
+ dialog.create('hello', {
26
+ title: testTitle,
27
+ render: renderMessage,
28
+ props: {message: testTitle},
29
+ open: true,
30
+ });
31
+
32
+ setTimeout(() => {
33
+ testTitle.value = 'changed';
34
+ }, 4000);
35
+ }
36
+
37
+ function showDialog2() {
38
+ dialog.create('hello-two', {
39
+ title: "Hello Second Dialog",
40
+ render: renderMessage,
41
+ props: {message: testTitle},
42
+ open: true,
43
+ modal: false,
44
+ draggable: true
45
+ });
46
+
47
+ setTimeout(() => {
48
+ testTitle.value = 'changed again';
49
+ }, 4000);
50
+ }
51
+ </script>
@@ -0,0 +1,26 @@
1
+ import MDialogProvider from '../DialogProvider.vue';
2
+ import { MDialogProviderBasic } from './index';
3
+
4
+ const Template = (args: any) => ({
5
+ components: {
6
+ MDialogProvider,
7
+ MDialogProviderBasic
8
+ },
9
+ setup() {
10
+ return {
11
+ args
12
+ }
13
+ },
14
+ template: `
15
+ <m-dialog-provider v-bind="args">
16
+ <MDialogProviderBasic />
17
+ </m-dialog-provider>
18
+ `
19
+ });
20
+
21
+ export default {
22
+ component: MDialogProvider,
23
+ title: 'Components/DialogProvider'
24
+ };
25
+
26
+ export const Primary = Template.bind({});
@@ -0,0 +1 @@
1
+ export { default as MDialogProviderBasic } from './basic.vue';
@@ -0,0 +1,25 @@
1
+ import type { Ref, VNodeChild } from 'vue';
2
+
3
+ export type DialogContent = VNodeChild;
4
+
5
+ export interface DialogOptions {
6
+ title?: string | Ref<string>;
7
+ render?: (props: any) => VNodeChild;
8
+ props?: { [key: string]: any };
9
+ onClose?: () => void;
10
+ open?: boolean;
11
+ draggable?: boolean;
12
+ modal?: boolean;
13
+ }
14
+
15
+ export interface DialogReactive {
16
+ key: string;
17
+ options: DialogOptions;
18
+ open: () => void;
19
+ close: () => void;
20
+ }
21
+
22
+ export interface DialogApiInjection {
23
+ create: (key: string, options?: DialogOptions) => DialogReactive;
24
+ remove: (key: string) => void;
25
+ }
@@ -0,0 +1,14 @@
1
+ import { inject } from 'vue';
2
+ import type { DialogApiInjection} from "./types";
3
+
4
+ export function useDialog(): DialogApiInjection {
5
+ const api = inject('m-dialog', null);
6
+
7
+ if (api === null) {
8
+ throw new Error(
9
+ `m-dialog api is not provided, ensure component is wrapped in <m-dialog-provider />`
10
+ )
11
+ }
12
+
13
+ return api;
14
+ }
@@ -48,4 +48,5 @@ export { default as MVirtualScroll } from './virtualscroll/VirtualScroll.vue';
48
48
  export { default as MConfirm } from './confirm/Confirm.vue';
49
49
  export { default as MConfirmProvider } from './confirm/ConfirmProvider.vue';
50
50
  export { default as MDialog } from './dialog/Dialog.vue';
51
+ export { default as MDialogProvider } from './dialogprovider/DialogProvider.vue';
51
52
  export { default as MTree } from './tree/Tree.vue';
@@ -28,7 +28,6 @@
28
28
  import {
29
29
  ref,
30
30
  reactive,
31
- Teleport,
32
31
  defineComponent,
33
32
  provide,
34
33
  computed
@@ -43,11 +42,8 @@ import type {
43
42
  } from './types';
44
43
  import type { PropType } from 'vue';
45
44
  import MMessage from './Message.vue';
46
- import { useId } from '../../composables/useCachedUid';
47
45
  import * as style from './style';
48
46
  import { modalScale } from '../../styles/transitions.css';
49
- import { useIsServer } from '../../composables/useIsServer';
50
- export type MessageProviderInst = MessageApiInjection;
51
47
 
52
48
  interface PrivateMessageReactive extends MessageReactive {
53
49
  key: string;
@@ -1,76 +1,111 @@
1
- <template>
2
- <div :class="style.slider">
3
- <div :class="style.sliderTransparent">
4
- <div ref="slider" @mousedown="handleMouseDown" :class="style.sliderBar" :style="{ background: background }">
5
- </div>
6
- </div>
7
-
8
- <div style="position: absolute; inset: 0px 9px;" @mousedown="handleMouseDown">
9
- <div draggable :class="style.hueSliderThumb" @mousedown="handleMouseDown" :style="{ left: `${modelValue}%` }"></div>
10
- </div>
11
- </div>
12
- </template>
13
-
14
- <script lang="ts">
15
- import { watch } from "vue";
16
- import { defineComponent, ref } from 'vue';
17
- import * as style from './style';
18
- import { useMouseInElement, useMousePressed } from '@vueuse/core';
19
-
20
- export default defineComponent({
21
- name: "MSlider",
22
- props: {
23
- modelValue: {
24
- type: Number,
25
- required: true
26
- },
27
- background: {
28
- type: String,
29
- default: ""
30
- }
31
- },
32
- components: {},
33
- emits: ['update:modelValue'],
34
- setup(props, { emit }) {
35
- const slider = ref<HTMLElement>();
36
-
37
- const { elementX } = useMouseInElement(slider);
38
- const { pressed } = useMousePressed();
39
-
40
- watch(() => pressed.value, () => {
41
- if (!pressed.value) {
42
- dragging.value = false;
43
- }
44
- });
45
-
46
- watch(() => elementX.value, () => {
47
- if (!dragging.value) {
48
- return;
49
- }
50
-
51
- setThumbPosition();
52
- });
53
-
54
-
55
- const dragging = ref(false);
56
-
57
- const setThumbPosition = () => {
58
- emit('update:modelValue', ((Math.min(Math.max(elementX.value, 0), slider.value?.clientWidth || 0) / (slider.value?.clientWidth || 0)) * 100));
59
- };
60
-
61
- const handleMouseDown = () => {
62
- dragging.value = true;
63
- setThumbPosition();
64
- };
65
-
66
- return {
67
- setThumbPosition,
68
- elementX,
69
- pressed,
70
- handleMouseDown,
71
- slider,
72
- style,
73
- };
74
- }
75
- })
76
- </script>
1
+ <template>
2
+ <div :class="style.slider">
3
+ <div :class="style.sliderTransparent">
4
+ <div ref="slider" :class="style.sliderBar" :style="{ background: background }" @mousedown="handleMouseDown"
5
+ @touchstart.prevent="handleMouseDown">
6
+ </div>
7
+ </div>
8
+
9
+ <div style="position: absolute; inset: 0px 9px;" @mousedown="handleMouseDown"
10
+ @touchstart.prevent="handleMouseDown">
11
+ <div :class="style.hueSliderThumb" :style="{ left: `${modelValue}%` }"></div>
12
+ </div>
13
+ </div>
14
+ </template>
15
+
16
+ <script lang="ts">
17
+ import { defineComponent, ref, onMounted, onUnmounted } from 'vue';
18
+ import * as style from './style';
19
+
20
+ export default defineComponent({
21
+ name: 'MSlider',
22
+ props: {
23
+ modelValue: {
24
+ type: Number,
25
+ required: true,
26
+ },
27
+ background: {
28
+ type: String,
29
+ default: '',
30
+ },
31
+ },
32
+ emits: ['update:modelValue', 'change'],
33
+ setup(props, { emit }) {
34
+ const slider = ref<HTMLElement | null>(null);
35
+ const dragging = ref(false);
36
+
37
+ const handleMouseDown = (event: MouseEvent | TouchEvent) => {
38
+ dragging.value = true;
39
+ setThumbPosition(event);
40
+
41
+ document.addEventListener('mousemove', onMouseMove);
42
+ document.addEventListener('mouseup', onMouseUp);
43
+ document.addEventListener('touchmove', onTouchMove);
44
+ document.addEventListener('touchend', onTouchEnd);
45
+ };
46
+
47
+ const onMouseMove = (event: MouseEvent) => {
48
+ if (dragging.value) {
49
+ setThumbPosition(event);
50
+ }
51
+ };
52
+
53
+ const onMouseUp = () => {
54
+ if (dragging.value) {
55
+ dragging.value = false;
56
+ removeEventListeners();
57
+ emit('change', props.modelValue);
58
+ }
59
+ };
60
+
61
+ const onTouchMove = (event: TouchEvent) => {
62
+ if (dragging.value) {
63
+ setThumbPosition(event);
64
+ }
65
+ };
66
+
67
+ const onTouchEnd = () => {
68
+ if (dragging.value) {
69
+ dragging.value = false;
70
+ removeEventListeners();
71
+ emit('change', props.modelValue);
72
+ }
73
+ };
74
+
75
+ const setThumbPosition = (event: MouseEvent | TouchEvent) => {
76
+ const rect = slider.value?.getBoundingClientRect();
77
+ if (!rect) return;
78
+
79
+ let clientX;
80
+ if (event instanceof MouseEvent) {
81
+ clientX = event.clientX;
82
+ } else if (event instanceof TouchEvent) {
83
+ clientX = event.touches[0].clientX;
84
+ } else {
85
+ return;
86
+ }
87
+
88
+ const position = Math.min(Math.max(clientX - rect.left, 0), rect.width);
89
+ const value = (position / rect.width) * 100;
90
+ emit('update:modelValue', value);
91
+ };
92
+
93
+ const removeEventListeners = () => {
94
+ document.removeEventListener('mousemove', onMouseMove);
95
+ document.removeEventListener('mouseup', onMouseUp);
96
+ document.removeEventListener('touchmove', onTouchMove);
97
+ document.removeEventListener('touchend', onTouchEnd);
98
+ };
99
+
100
+ onUnmounted(() => {
101
+ removeEventListeners();
102
+ });
103
+
104
+ return {
105
+ handleMouseDown,
106
+ slider,
107
+ style,
108
+ };
109
+ },
110
+ });
111
+ </script>
@@ -1,4 +1,5 @@
1
1
  export { useMessage } from '../components/messageprovider/useMessage';
2
+ export { useDialog } from '../components/dialogprovider/useDialog';
2
3
  export { useConfirm } from '../components/confirm/useConfirm';
3
4
  export { usePopper } from './usePopper';
4
5
  export { useZIndex } from './useZIndex';