@weni/unnnic-system 3.27.2 → 3.28.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/dist/index.d.ts +142 -30
- package/dist/style.css +1 -1
- package/dist/unnnic.mjs +5707 -5703
- package/dist/unnnic.umd.js +25 -25
- package/package.json +1 -1
- package/src/components/ui/popover/PopoverContent.vue +9 -31
- package/src/components/ui/popover/PopoverFooter.vue +21 -6
- package/src/components/ui/popover/__tests__/PopoverFooter.spec.js +116 -0
- package/src/components/ui/popover/context.ts +4 -0
- package/src/stories/PopoverOption.stories.js +53 -0
package/package.json
CHANGED
|
@@ -11,17 +11,12 @@
|
|
|
11
11
|
"
|
|
12
12
|
>
|
|
13
13
|
<section :class="`unnnic-popover__content ${props.class || ''}`">
|
|
14
|
-
<
|
|
15
|
-
:is="child"
|
|
16
|
-
v-for="(child, index) in contentChildren"
|
|
17
|
-
:key="index"
|
|
18
|
-
/>
|
|
14
|
+
<slot />
|
|
19
15
|
</section>
|
|
20
16
|
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
:key="index"
|
|
17
|
+
<div
|
|
18
|
+
ref="footerContainer"
|
|
19
|
+
data-testid="popover-footer-container"
|
|
25
20
|
/>
|
|
26
21
|
</PopoverContent>
|
|
27
22
|
</PopoverPortal>
|
|
@@ -29,13 +24,14 @@
|
|
|
29
24
|
|
|
30
25
|
<script setup lang="ts">
|
|
31
26
|
import type { PopoverContentEmits, PopoverContentProps } from 'reka-ui';
|
|
32
|
-
import type { HTMLAttributes
|
|
33
|
-
import { computed,
|
|
27
|
+
import type { HTMLAttributes } from 'vue';
|
|
28
|
+
import { computed, provide, ref } from 'vue';
|
|
34
29
|
import { reactiveOmit } from '@vueuse/core';
|
|
35
30
|
import { PopoverContent, PopoverPortal, useForwardPropsEmits } from 'reka-ui';
|
|
36
31
|
import { cn } from '@/lib/utils';
|
|
37
32
|
import { useLayerZIndex } from '@/lib/layer-manager';
|
|
38
33
|
import { useTeleportTarget } from '@/lib/teleport-target';
|
|
34
|
+
import { POPOVER_FOOTER_TARGET } from './context';
|
|
39
35
|
|
|
40
36
|
defineOptions({
|
|
41
37
|
inheritAttrs: false,
|
|
@@ -63,29 +59,11 @@ const delegatedProps = reactiveOmit(props, 'class', 'size');
|
|
|
63
59
|
|
|
64
60
|
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
65
61
|
|
|
66
|
-
const slots = useSlots() as Slots;
|
|
67
|
-
|
|
68
62
|
const popoverZIndex = useLayerZIndex();
|
|
69
63
|
const portalTarget = useTeleportTarget();
|
|
70
64
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
return componentType?.name || componentType?.__name;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const contentChildren = computed(() => {
|
|
77
|
-
const defaultSlot = slots.default?.() || [];
|
|
78
|
-
return defaultSlot.filter(
|
|
79
|
-
(vnode: VNode) => getComponentName(vnode) !== 'UnnnicPopoverFooter',
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const footerChildren = computed(() => {
|
|
84
|
-
const defaultSlot = slots.default?.() || [];
|
|
85
|
-
return defaultSlot.filter(
|
|
86
|
-
(vnode: VNode) => getComponentName(vnode) === 'UnnnicPopoverFooter',
|
|
87
|
-
);
|
|
88
|
-
});
|
|
65
|
+
const footerContainer = ref<HTMLElement | null>(null);
|
|
66
|
+
provide(POPOVER_FOOTER_TARGET, footerContainer);
|
|
89
67
|
|
|
90
68
|
const contentWidth = computed(() => {
|
|
91
69
|
if (props.width) return props.width;
|
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<Teleport
|
|
3
|
+
v-if="target"
|
|
4
|
+
:to="target"
|
|
5
|
+
>
|
|
6
|
+
<footer class="unnnic-popover__footer">
|
|
7
|
+
<slot />
|
|
8
|
+
</footer>
|
|
9
|
+
</Teleport>
|
|
10
|
+
|
|
11
|
+
<footer
|
|
12
|
+
v-else
|
|
13
|
+
class="unnnic-popover__footer"
|
|
14
|
+
>
|
|
3
15
|
<slot />
|
|
4
16
|
</footer>
|
|
5
17
|
</template>
|
|
6
18
|
|
|
7
19
|
<script setup lang="ts">
|
|
20
|
+
import { inject } from 'vue';
|
|
21
|
+
import { POPOVER_FOOTER_TARGET } from './context';
|
|
22
|
+
|
|
8
23
|
defineOptions({
|
|
9
24
|
name: 'UnnnicPopoverFooter',
|
|
10
25
|
});
|
|
26
|
+
|
|
27
|
+
// When rendered inside a PopoverContent, teleport into its footer container.
|
|
28
|
+
// Falls back to inline rendering when used standalone (no target provided).
|
|
29
|
+
const target = inject(POPOVER_FOOTER_TARGET, null);
|
|
11
30
|
</script>
|
|
12
31
|
|
|
13
32
|
<style lang="scss">
|
|
@@ -21,12 +40,8 @@ $popover-space: $unnnic-space-4;
|
|
|
21
40
|
padding: $popover-space;
|
|
22
41
|
|
|
23
42
|
display: flex;
|
|
24
|
-
justify-content:
|
|
43
|
+
justify-content: flex-end;
|
|
25
44
|
align-items: center;
|
|
26
45
|
gap: $unnnic-space-2;
|
|
27
|
-
|
|
28
|
-
> * {
|
|
29
|
-
width: 100%;
|
|
30
|
-
}
|
|
31
46
|
}
|
|
32
47
|
</style>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { mount, flushPromises } from '@vue/test-utils';
|
|
2
|
+
import { describe, it, expect } from 'vitest';
|
|
3
|
+
import PopoverContent from '../PopoverContent.vue';
|
|
4
|
+
import PopoverFooter from '../PopoverFooter.vue';
|
|
5
|
+
|
|
6
|
+
// Render reka-ui's portal/content inline so the component's own markup
|
|
7
|
+
// (`.unnnic-popover__content` + footer container) is testable. The native
|
|
8
|
+
// Teleport is kept real so we can assert the footer actually moves.
|
|
9
|
+
const inlineSlot = { template: '<div><slot /></div>' };
|
|
10
|
+
|
|
11
|
+
const globalStubs = {
|
|
12
|
+
PopoverPortal: inlineSlot,
|
|
13
|
+
PopoverContent: inlineSlot,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// A child component that renders the footer from its own template, simulating
|
|
17
|
+
// a footer nested inside a consumer component rather than a direct slot child.
|
|
18
|
+
const NestedFooterChild = {
|
|
19
|
+
components: { PopoverFooter },
|
|
20
|
+
template: `
|
|
21
|
+
<section data-testid="nested-wrapper">
|
|
22
|
+
<PopoverFooter>
|
|
23
|
+
<button data-testid="nested-footer-btn">Save</button>
|
|
24
|
+
</PopoverFooter>
|
|
25
|
+
</section>
|
|
26
|
+
`,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const mountPopover = (defaultSlot) =>
|
|
30
|
+
mount(PopoverContent, {
|
|
31
|
+
attachTo: document.body,
|
|
32
|
+
slots: { default: defaultSlot },
|
|
33
|
+
global: {
|
|
34
|
+
stubs: globalStubs,
|
|
35
|
+
components: { PopoverFooter, NestedFooterChild },
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const content = (wrapper) => wrapper.find('.unnnic-popover__content');
|
|
40
|
+
const footerContainer = (wrapper) =>
|
|
41
|
+
wrapper.find('[data-testid="popover-footer-container"]');
|
|
42
|
+
|
|
43
|
+
describe('UnnnicPopoverFooter', () => {
|
|
44
|
+
it('renders a direct footer child inside the footer container, outside the content', async () => {
|
|
45
|
+
const wrapper = mountPopover(
|
|
46
|
+
`<p data-testid="body">Body</p>
|
|
47
|
+
<PopoverFooter><button data-testid="footer-btn">Save</button></PopoverFooter>`,
|
|
48
|
+
);
|
|
49
|
+
await flushPromises();
|
|
50
|
+
|
|
51
|
+
expect(
|
|
52
|
+
footerContainer(wrapper).find('.unnnic-popover__footer').exists(),
|
|
53
|
+
).toBe(true);
|
|
54
|
+
expect(content(wrapper).find('.unnnic-popover__footer').exists()).toBe(
|
|
55
|
+
false,
|
|
56
|
+
);
|
|
57
|
+
expect(wrapper.find('[data-testid="footer-btn"]').exists()).toBe(true);
|
|
58
|
+
|
|
59
|
+
wrapper.unmount();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders a footer nested inside a child component in the footer container', async () => {
|
|
63
|
+
const wrapper = mountPopover('<NestedFooterChild />');
|
|
64
|
+
await flushPromises();
|
|
65
|
+
|
|
66
|
+
expect(
|
|
67
|
+
footerContainer(wrapper).find('.unnnic-popover__footer').exists(),
|
|
68
|
+
).toBe(true);
|
|
69
|
+
expect(
|
|
70
|
+
footerContainer(wrapper)
|
|
71
|
+
.find('[data-testid="nested-footer-btn"]')
|
|
72
|
+
.exists(),
|
|
73
|
+
).toBe(true);
|
|
74
|
+
expect(content(wrapper).find('.unnnic-popover__footer').exists()).toBe(
|
|
75
|
+
false,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
wrapper.unmount();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('renders no footer area when no footer is provided', async () => {
|
|
82
|
+
const wrapper = mountPopover('<p data-testid="body">Body</p>');
|
|
83
|
+
await flushPromises();
|
|
84
|
+
|
|
85
|
+
expect(wrapper.find('.unnnic-popover__footer').exists()).toBe(false);
|
|
86
|
+
expect(footerContainer(wrapper).element.children.length).toBe(0);
|
|
87
|
+
|
|
88
|
+
wrapper.unmount();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('teleports every footer into the container when multiple are provided', async () => {
|
|
92
|
+
const wrapper = mountPopover(
|
|
93
|
+
`<PopoverFooter><span>First</span></PopoverFooter>
|
|
94
|
+
<PopoverFooter><span>Second</span></PopoverFooter>`,
|
|
95
|
+
);
|
|
96
|
+
await flushPromises();
|
|
97
|
+
|
|
98
|
+
const footers = footerContainer(wrapper).findAll('.unnnic-popover__footer');
|
|
99
|
+
expect(footers).toHaveLength(2);
|
|
100
|
+
expect(content(wrapper).find('.unnnic-popover__footer').exists()).toBe(
|
|
101
|
+
false,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
wrapper.unmount();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('renders inline as a fallback when used without a PopoverContent target', () => {
|
|
108
|
+
const wrapper = mount(PopoverFooter, {
|
|
109
|
+
slots: { default: '<button data-testid="standalone">Save</button>' },
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const footer = wrapper.find('.unnnic-popover__footer');
|
|
113
|
+
expect(footer.exists()).toBe(true);
|
|
114
|
+
expect(footer.find('[data-testid="standalone"]').exists()).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PopoverOption } from '../components/ui/popover';
|
|
2
|
+
import UnnnicTag from '../components/Tag/Tag.vue';
|
|
2
3
|
import colorsList from '../utils/colorsList';
|
|
3
4
|
|
|
4
5
|
export default {
|
|
@@ -73,3 +74,55 @@ export const Default = {
|
|
|
73
74
|
`,
|
|
74
75
|
}),
|
|
75
76
|
};
|
|
77
|
+
|
|
78
|
+
export const WithTag = {
|
|
79
|
+
parameters: {
|
|
80
|
+
docs: {
|
|
81
|
+
description: {
|
|
82
|
+
story:
|
|
83
|
+
'Uses the default slot to render custom content, such as a label alongside a status tag. The option keeps the `space-between` layout, so the tag stays aligned to the end.',
|
|
84
|
+
},
|
|
85
|
+
source: {
|
|
86
|
+
code: `<UnnnicPopoverOption v-for="option in options" :key="option.value">
|
|
87
|
+
<span class="popover-option__label">{{ option.label }}</span>
|
|
88
|
+
<UnnnicTag
|
|
89
|
+
type="default"
|
|
90
|
+
size="small"
|
|
91
|
+
:scheme="statusConfig[option.status].scheme"
|
|
92
|
+
:text="statusConfig[option.status].text"
|
|
93
|
+
/>
|
|
94
|
+
</UnnnicPopoverOption>`,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
render: () => ({
|
|
99
|
+
components: { PopoverOption, UnnnicTag },
|
|
100
|
+
data() {
|
|
101
|
+
return {
|
|
102
|
+
options: [
|
|
103
|
+
{ label: 'John Doe', value: 'john-doe', status: 'online' },
|
|
104
|
+
{ label: 'Jane Doe', value: 'jane-doe', status: 'lunch' },
|
|
105
|
+
{ label: 'James Smith', value: 'james-smith', status: 'offline' },
|
|
106
|
+
],
|
|
107
|
+
statusConfig: {
|
|
108
|
+
online: { scheme: 'green', text: 'Online' },
|
|
109
|
+
lunch: { scheme: 'orange', text: 'Lunch' },
|
|
110
|
+
offline: { scheme: 'gray', text: 'Offline' },
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
template: `
|
|
115
|
+
<section style="display: flex; flex-direction: column; gap: 8px; width: 280px;">
|
|
116
|
+
<PopoverOption v-for="option in options" :key="option.value" :label="option.label">
|
|
117
|
+
<span style="flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">{{ option.label }}</span>
|
|
118
|
+
<unnnic-tag
|
|
119
|
+
type="default"
|
|
120
|
+
size="small"
|
|
121
|
+
:scheme="statusConfig[option.status].scheme"
|
|
122
|
+
:text="statusConfig[option.status].text"
|
|
123
|
+
/>
|
|
124
|
+
</PopoverOption>
|
|
125
|
+
</section>
|
|
126
|
+
`,
|
|
127
|
+
}),
|
|
128
|
+
};
|