sprintify-ui 0.0.112 → 0.0.114
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/dist/sprintify-ui.es.js +2101 -2101
- package/dist/types/src/components/BaseClickOutside.vue.d.ts +26 -0
- package/dist/types/src/composables/clickOutside.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/BaseClickOutside.vue +37 -0
- package/src/components/BaseDropdown.stories.js +27 -0
- package/src/components/BaseDropdown.vue +8 -3
- package/src/composables/clickOutside.ts +14 -8
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MaybeElement } from '@vueuse/core';
|
|
2
|
+
import { MaybeRef } from '@vueuse/shared';
|
|
3
|
+
import { PropType } from 'vue';
|
|
4
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
5
|
+
includes: {
|
|
6
|
+
type: PropType<(string | MaybeRef<MaybeElement>)[]>;
|
|
7
|
+
default: () => never[];
|
|
8
|
+
};
|
|
9
|
+
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "clickOutside"[], "clickOutside", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
10
|
+
includes: {
|
|
11
|
+
type: PropType<(string | MaybeRef<MaybeElement>)[]>;
|
|
12
|
+
default: () => never[];
|
|
13
|
+
};
|
|
14
|
+
}>> & {
|
|
15
|
+
onClickOutside?: ((...args: any[]) => any) | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
includes: (string | MaybeRef<MaybeElement>)[];
|
|
18
|
+
}>, {
|
|
19
|
+
default: (_: {}) => any;
|
|
20
|
+
}>;
|
|
21
|
+
export default _default;
|
|
22
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
23
|
+
new (): {
|
|
24
|
+
$slots: S;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MaybeElementRef } from '@vueuse/core';
|
|
2
2
|
interface UseClickOutsideOptions {
|
|
3
|
-
includes?: (MaybeElementRef | string)[];
|
|
3
|
+
includes?: () => (MaybeElementRef | string)[];
|
|
4
4
|
}
|
|
5
5
|
export declare function useClickOutside(element: MaybeElementRef, callback: () => void, options?: UseClickOutsideOptions): {
|
|
6
6
|
stop: () => void;
|
package/package.json
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="root">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts" setup>
|
|
8
|
+
import { useClickOutside } from '@/composables/clickOutside';
|
|
9
|
+
import { MaybeElement } from '@vueuse/core';
|
|
10
|
+
import { MaybeRef } from '@vueuse/shared';
|
|
11
|
+
import { PropType } from 'vue';
|
|
12
|
+
|
|
13
|
+
const props = defineProps({
|
|
14
|
+
includes: {
|
|
15
|
+
type: Array as PropType<(MaybeRef<MaybeElement> | string)[]>,
|
|
16
|
+
default: () => [],
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const emit = defineEmits(['clickOutside']);
|
|
21
|
+
|
|
22
|
+
const root = ref<null | HTMLElement>(null);
|
|
23
|
+
|
|
24
|
+
const includes = [] as (MaybeRef<MaybeElement> | string)[];
|
|
25
|
+
|
|
26
|
+
function addInclude(include: MaybeRef<MaybeElement> | string) {
|
|
27
|
+
includes.push(include);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
provide('clickOutside:addInclude', addInclude);
|
|
31
|
+
|
|
32
|
+
useClickOutside(root, () => emit('clickOutside'), {
|
|
33
|
+
includes: () => {
|
|
34
|
+
return [...includes, ...props.includes];
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
</script>
|
|
@@ -3,6 +3,7 @@ import BaseAutocomplete from './BaseAutocomplete.vue';
|
|
|
3
3
|
import BaseModalCenter from './BaseModalCenter.vue';
|
|
4
4
|
import BaseDropdown from './BaseDropdown.vue';
|
|
5
5
|
import BaseDatePicker from './BaseDatePicker.vue';
|
|
6
|
+
import BaseClickOutside from './BaseClickOutside.vue';
|
|
6
7
|
import { options } from '../../.storybook/utils';
|
|
7
8
|
|
|
8
9
|
const items = [];
|
|
@@ -181,3 +182,29 @@ export const WithDatePicker = (args) => ({
|
|
|
181
182
|
WithDatePicker.args = {
|
|
182
183
|
placement: 'bottom-start',
|
|
183
184
|
};
|
|
185
|
+
|
|
186
|
+
export const WithinClickOutside = (args) => ({
|
|
187
|
+
components: { BaseDropdown, BaseClickOutside },
|
|
188
|
+
setup() {
|
|
189
|
+
function onClickOutside() {
|
|
190
|
+
alert('click outside');
|
|
191
|
+
}
|
|
192
|
+
return { args, items, onClickOutside };
|
|
193
|
+
},
|
|
194
|
+
template: `
|
|
195
|
+
<BaseClickOutside @clickOutside="onClickOutside">
|
|
196
|
+
<div class="bg-slate-200 shadow-md min-h-[100px] p-3">
|
|
197
|
+
<BaseDropdown v-bind="args">
|
|
198
|
+
<template #button>
|
|
199
|
+
<div class="btn btn-primary">Click me</div>
|
|
200
|
+
</template>
|
|
201
|
+
<template #dropdown>
|
|
202
|
+
<div class="bg-white shadow-lg rounded border p-2 w-[260px]">
|
|
203
|
+
...
|
|
204
|
+
</div>
|
|
205
|
+
</template>
|
|
206
|
+
</BaseDropdown>
|
|
207
|
+
</div>
|
|
208
|
+
</BaseClickOutside>
|
|
209
|
+
`,
|
|
210
|
+
});
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
|
|
35
35
|
<script lang="ts" setup>
|
|
36
36
|
import { useClickOutside } from '@/composables/clickOutside';
|
|
37
|
-
import { useResizeObserver } from '@vueuse/core';
|
|
37
|
+
import { MaybeElement, MaybeRef, useResizeObserver } from '@vueuse/core';
|
|
38
38
|
import { throttle } from 'lodash';
|
|
39
39
|
import { PropType, StyleValue } from 'vue';
|
|
40
40
|
import { disableScroll, enableScroll } from '../utils';
|
|
@@ -43,7 +43,6 @@ const button = ref<HTMLElement | null>(null);
|
|
|
43
43
|
const dropdown = ref<HTMLElement | null>(null);
|
|
44
44
|
|
|
45
45
|
const showDropdown = ref(false);
|
|
46
|
-
|
|
47
46
|
const props = defineProps({
|
|
48
47
|
placement: {
|
|
49
48
|
type: String as PropType<
|
|
@@ -163,7 +162,7 @@ useClickOutside(
|
|
|
163
162
|
close();
|
|
164
163
|
}
|
|
165
164
|
},
|
|
166
|
-
{ includes: [button] }
|
|
165
|
+
{ includes: () => [button] }
|
|
167
166
|
);
|
|
168
167
|
|
|
169
168
|
const placementInternal = computed(() => {
|
|
@@ -251,6 +250,12 @@ const dropdownStyles = computed((): StyleValue => {
|
|
|
251
250
|
return styles as StyleValue;
|
|
252
251
|
});
|
|
253
252
|
|
|
253
|
+
const addClickOutsideInclude = inject('clickOutside:addInclude', () => {
|
|
254
|
+
return;
|
|
255
|
+
}) as (include: MaybeRef<MaybeElement> | string) => void;
|
|
256
|
+
|
|
257
|
+
addClickOutsideInclude(dropdown);
|
|
258
|
+
|
|
254
259
|
onBeforeUnmount(() => {
|
|
255
260
|
close();
|
|
256
261
|
deactivate();
|
|
@@ -2,7 +2,7 @@ import { MaybeElementRef, unrefElement, tryOnScopeDispose } from '@vueuse/core';
|
|
|
2
2
|
import { isString } from 'lodash';
|
|
3
3
|
|
|
4
4
|
interface UseClickOutsideOptions {
|
|
5
|
-
includes?: (MaybeElementRef | string)[];
|
|
5
|
+
includes?: () => (MaybeElementRef | string)[];
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export function useClickOutside(
|
|
@@ -30,16 +30,22 @@ export function useClickOutside(
|
|
|
30
30
|
|
|
31
31
|
const includeEls = [] as Element[];
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const optionIncludes = [];
|
|
34
|
+
|
|
35
|
+
if (options.includes) {
|
|
36
|
+
optionIncludes.push(...options.includes());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
optionIncludes.forEach((include) => {
|
|
34
40
|
if (isString(include)) {
|
|
35
41
|
includeEls.push(...document.querySelectorAll(include));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
} else {
|
|
43
|
+
const element = unrefElement(include);
|
|
44
|
+
if (element) {
|
|
45
|
+
includeEls.push(element);
|
|
46
|
+
}
|
|
41
47
|
}
|
|
42
|
-
})
|
|
48
|
+
});
|
|
43
49
|
|
|
44
50
|
if (!el) {
|
|
45
51
|
return;
|