@mozaic-ds/vue 1.0.0-beta.7 → 1.0.0-beta.8
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/mozaic-vue.css +1 -1
- package/dist/mozaic-vue.d.ts +298 -115
- package/dist/mozaic-vue.js +860 -531
- package/dist/mozaic-vue.js.map +1 -1
- package/dist/mozaic-vue.umd.cjs +1 -1
- package/dist/mozaic-vue.umd.cjs.map +1 -1
- package/package.json +2 -2
- package/src/components/divider/MDivider.spec.ts +57 -0
- package/src/components/divider/MDivider.stories.ts +64 -0
- package/src/components/divider/MDivider.vue +56 -0
- package/src/components/pagination/MPagination.spec.ts +123 -0
- package/src/components/pagination/MPagination.stories.ts +83 -0
- package/src/components/pagination/MPagination.vue +140 -0
- package/src/components/tabs/MTabs.stories.ts +104 -0
- package/src/components/tabs/MTabs.vue +113 -0
- package/src/components/tabs/Mtabs.spec.ts +154 -0
- package/src/components/tag/MTag.spec.ts +107 -0
- package/src/components/tag/MTag.stories.ts +75 -0
- package/src/components/tag/MTag.vue +154 -0
- package/src/main.ts +4 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
|
2
|
+
import MDivider from './MDivider.vue';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof MDivider> = {
|
|
5
|
+
title: 'Structure/Divider',
|
|
6
|
+
component: MDivider,
|
|
7
|
+
argTypes: {
|
|
8
|
+
orientation: {
|
|
9
|
+
control: 'radio',
|
|
10
|
+
options: ['horizontal', 'vertical'],
|
|
11
|
+
},
|
|
12
|
+
style: {
|
|
13
|
+
control: 'radio',
|
|
14
|
+
options: ['primary', 'secondary', 'tertiary', 'inverse'],
|
|
15
|
+
},
|
|
16
|
+
size: {
|
|
17
|
+
control: 'radio',
|
|
18
|
+
options: ['s', 'm', 'l'],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
render: (args) => ({
|
|
22
|
+
components: { MDivider },
|
|
23
|
+
setup() {
|
|
24
|
+
return { args };
|
|
25
|
+
},
|
|
26
|
+
template: `
|
|
27
|
+
<div>
|
|
28
|
+
<MDivider v-bind="args"></MDivider>
|
|
29
|
+
<p style="padding: 1rem">Horizontal Divider</p>
|
|
30
|
+
</div>
|
|
31
|
+
`,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
export default meta;
|
|
35
|
+
type Story = StoryObj<typeof MDivider>;
|
|
36
|
+
|
|
37
|
+
export const Standard: Story = {};
|
|
38
|
+
|
|
39
|
+
export const Vertical: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
orientation: 'vertical'
|
|
42
|
+
},
|
|
43
|
+
render: (args) => ({
|
|
44
|
+
components: { MDivider },
|
|
45
|
+
setup() {
|
|
46
|
+
return { args };
|
|
47
|
+
},
|
|
48
|
+
template: `
|
|
49
|
+
<div>
|
|
50
|
+
<MDivider v-bind="args">
|
|
51
|
+
<p style="padding: 1rem">Vertical Divider</p>
|
|
52
|
+
</MDivider>
|
|
53
|
+
</div>
|
|
54
|
+
`,
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const Size: Story = {
|
|
59
|
+
args: { size: 'm' },
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const Secondary: Story = {
|
|
63
|
+
args: { style: 'secondary' },
|
|
64
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="mc-divider">
|
|
3
|
+
<div :class="classObject"></div>
|
|
4
|
+
<slot/>
|
|
5
|
+
</div>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { computed } from 'vue';
|
|
10
|
+
/**
|
|
11
|
+
* A Divider serves as a visual divider to separate content, providing a clear distinction between sections.
|
|
12
|
+
*/
|
|
13
|
+
const props = withDefaults(
|
|
14
|
+
defineProps<{
|
|
15
|
+
/**
|
|
16
|
+
* Determines the orientation of the divider
|
|
17
|
+
*/
|
|
18
|
+
orientation?: 'vertical' | 'horizontal';
|
|
19
|
+
/**
|
|
20
|
+
* Determines the style of the divider
|
|
21
|
+
*/
|
|
22
|
+
style?: 'primary' | 'secondary' | 'tertiary' | 'inverse';
|
|
23
|
+
/**
|
|
24
|
+
* Determines the size of the divider
|
|
25
|
+
*/
|
|
26
|
+
size?: 's' | 'm' | 'l';
|
|
27
|
+
}>(),
|
|
28
|
+
{
|
|
29
|
+
orientation: 'horizontal',
|
|
30
|
+
style: 'primary',
|
|
31
|
+
size: 's',
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const classObject = computed(() => {
|
|
36
|
+
return {
|
|
37
|
+
[`mc-divider-${props.orientation}`]: props.orientation,
|
|
38
|
+
[`mc-divider-horizontal--${props.style}`]:
|
|
39
|
+
props.style && props.style != 'primary',
|
|
40
|
+
[`mc-divider-horizontal--${props.size}`]: props.size && props.size != 's',
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<style lang="scss" scoped>
|
|
46
|
+
@use '@mozaic-ds/styles/components/divider';
|
|
47
|
+
|
|
48
|
+
.mc-divider-vertical {
|
|
49
|
+
content: "";
|
|
50
|
+
display: block;
|
|
51
|
+
height: 100%;
|
|
52
|
+
position: absolute;
|
|
53
|
+
top: 50%;
|
|
54
|
+
transform: translateY(-50%);
|
|
55
|
+
}
|
|
56
|
+
</style>
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { mount } from '@vue/test-utils';
|
|
3
|
+
import MPagination from './MPagination.vue';
|
|
4
|
+
|
|
5
|
+
const options = [
|
|
6
|
+
{ value: 1, text: 'Page 1' },
|
|
7
|
+
{ value: 2, text: 'Page 2' },
|
|
8
|
+
{ value: 3, text: 'Page 3' },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
describe('MPagination component', () => {
|
|
12
|
+
it('renders correctly with select when compact is false', () => {
|
|
13
|
+
const wrapper = mount(MPagination, {
|
|
14
|
+
props: {
|
|
15
|
+
id: 'test-pagination',
|
|
16
|
+
modelValue: 2,
|
|
17
|
+
options,
|
|
18
|
+
compact: false,
|
|
19
|
+
selectLabel: 'Select page',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Check buttons rendered as MButton (not MIconButton)
|
|
24
|
+
expect(wrapper.findAllComponents({ name: 'MButton' }).length).toBe(2);
|
|
25
|
+
expect(wrapper.findAllComponents({ name: 'MIconButton' }).length).toBe(0);
|
|
26
|
+
|
|
27
|
+
// Check select is present
|
|
28
|
+
expect(wrapper.find('select').exists()).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('renders icon buttons only when compact is true', () => {
|
|
32
|
+
const wrapper = mount(MPagination, {
|
|
33
|
+
props: {
|
|
34
|
+
id: 'test-pagination',
|
|
35
|
+
modelValue: 2,
|
|
36
|
+
options,
|
|
37
|
+
compact: true,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// MIconButton rendered for previous and next
|
|
42
|
+
expect(wrapper.findAllComponents({ name: 'MIconButton' }).length).toBe(2);
|
|
43
|
+
// No MButton when compact
|
|
44
|
+
expect(wrapper.findAllComponents({ name: 'MButton' }).length).toBe(0);
|
|
45
|
+
|
|
46
|
+
// No select rendered
|
|
47
|
+
expect(wrapper.find('select').exists()).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('disables previous button if on first page', async () => {
|
|
51
|
+
const wrapper = mount(MPagination, {
|
|
52
|
+
props: {
|
|
53
|
+
id: 'test-pagination',
|
|
54
|
+
modelValue: 1,
|
|
55
|
+
options,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
const prevButton = wrapper.findAllComponents({ name: 'MButton' })[0];
|
|
59
|
+
expect(prevButton.attributes('disabled')).toBeDefined();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('disables next button if on last page', async () => {
|
|
63
|
+
const wrapper = mount(MPagination, {
|
|
64
|
+
props: {
|
|
65
|
+
id: 'test-pagination',
|
|
66
|
+
modelValue: 3,
|
|
67
|
+
options,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
const buttons = wrapper.findAllComponents({ name: 'MButton' });
|
|
71
|
+
const nextButton = buttons[buttons.length - 1];
|
|
72
|
+
expect(nextButton.attributes('disabled')).toBeDefined();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('clicking previous button updates the modelValue', async () => {
|
|
76
|
+
const wrapper = mount(MPagination, {
|
|
77
|
+
props: {
|
|
78
|
+
id: 'test-pagination',
|
|
79
|
+
modelValue: 2,
|
|
80
|
+
options,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await wrapper.findAllComponents({ name: 'MButton' })[0].trigger('click');
|
|
85
|
+
// Should emit update:modelValue with value 1 (previous page)
|
|
86
|
+
expect(wrapper.emitted('update:modelValue')).toBeTruthy();
|
|
87
|
+
expect(wrapper.emitted('update:modelValue')![0]).toEqual([1]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('clicking next button updates the modelValue', async () => {
|
|
91
|
+
const wrapper = mount(MPagination, {
|
|
92
|
+
props: {
|
|
93
|
+
id: 'test-pagination',
|
|
94
|
+
modelValue: 2,
|
|
95
|
+
options,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const buttons = wrapper.findAllComponents({ name: 'MButton' });
|
|
100
|
+
await buttons[buttons.length - 1].trigger('click');
|
|
101
|
+
|
|
102
|
+
expect(wrapper.emitted('update:modelValue')).toBeTruthy();
|
|
103
|
+
expect(wrapper.emitted('update:modelValue')![0]).toEqual([3]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('emits update:modelValue when select value changes', async () => {
|
|
107
|
+
const wrapper = mount(MPagination, {
|
|
108
|
+
props: {
|
|
109
|
+
id: 'test-pagination',
|
|
110
|
+
modelValue: 1,
|
|
111
|
+
options,
|
|
112
|
+
compact: false,
|
|
113
|
+
selectLabel: 'Select page',
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const select = wrapper.find('select');
|
|
118
|
+
await select.setValue('3');
|
|
119
|
+
|
|
120
|
+
expect(wrapper.emitted('update:modelValue')).toBeTruthy();
|
|
121
|
+
expect(wrapper.emitted('update:modelValue')![0]).toEqual([3]);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
|
2
|
+
import { action } from '@storybook/addon-actions';
|
|
3
|
+
|
|
4
|
+
import MPagination from './MPagination.vue';
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof MPagination> = {
|
|
7
|
+
title: 'Navgation/Pagination',
|
|
8
|
+
component: MPagination,
|
|
9
|
+
parameters: {
|
|
10
|
+
docs: {
|
|
11
|
+
description: {
|
|
12
|
+
component:
|
|
13
|
+
'Pagination is a navigation component that allows users to browse through large sets of content by dividing it into discrete pages. It typically includes previous and next buttons, numeric page selectors, or dropdowns to jump between pages efficiently. Pagination improves usability and performance in content-heavy applications such as tables, search results, and articles by preventing long scrolls and reducing page load times.',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
args: {
|
|
18
|
+
id: 'paginationId',
|
|
19
|
+
modelValue: 10,
|
|
20
|
+
options: [
|
|
21
|
+
{
|
|
22
|
+
text: 'Page 1 of 99',
|
|
23
|
+
value: 1,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
text: 'Page 2 of 99',
|
|
27
|
+
value: 2,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
text: 'Page 3 of 99',
|
|
31
|
+
value: 3,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
text: 'Page 10 of 99',
|
|
35
|
+
value: 10,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
text: 'Page 99 of 99',
|
|
39
|
+
value: 99,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
selectLabel: 'Select page',
|
|
43
|
+
},
|
|
44
|
+
render: (args) => ({
|
|
45
|
+
components: { MPagination },
|
|
46
|
+
setup() {
|
|
47
|
+
const handleUpdate = action('update:modelValue');
|
|
48
|
+
|
|
49
|
+
return { args, handleUpdate };
|
|
50
|
+
},
|
|
51
|
+
template: `
|
|
52
|
+
<MPagination
|
|
53
|
+
v-bind="args"
|
|
54
|
+
@update:modelValue="handleUpdate"
|
|
55
|
+
/>
|
|
56
|
+
`,
|
|
57
|
+
}),
|
|
58
|
+
};
|
|
59
|
+
export default meta;
|
|
60
|
+
type Story = StoryObj<typeof MPagination>;
|
|
61
|
+
|
|
62
|
+
export const Default: Story = {};
|
|
63
|
+
|
|
64
|
+
export const First: Story = {
|
|
65
|
+
args: {
|
|
66
|
+
id: 'firstId',
|
|
67
|
+
modelValue: 1,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const Last: Story = {
|
|
72
|
+
args: {
|
|
73
|
+
id: 'lastId',
|
|
74
|
+
modelValue: 99,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const Compact: Story = {
|
|
79
|
+
args: {
|
|
80
|
+
id: 'compactId',
|
|
81
|
+
compact: true,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<nav class="mc-pagination" role="navigation" aria-label="pagination">
|
|
3
|
+
<MButton
|
|
4
|
+
v-if="!compact"
|
|
5
|
+
icon-position="only"
|
|
6
|
+
aria-label="Previous page"
|
|
7
|
+
:disabled="isFirstPage"
|
|
8
|
+
@click="previous"
|
|
9
|
+
>
|
|
10
|
+
<template #icon><ChevronLeft24 /></template>
|
|
11
|
+
</MButton>
|
|
12
|
+
<MIconButton
|
|
13
|
+
v-else
|
|
14
|
+
outlined
|
|
15
|
+
aria-label="Previous page"
|
|
16
|
+
:disabled="isFirstPage"
|
|
17
|
+
@click="previous"
|
|
18
|
+
>
|
|
19
|
+
<template #icon><ChevronLeft24 /></template>
|
|
20
|
+
</MIconButton>
|
|
21
|
+
|
|
22
|
+
<div v-if="!compact" class="mc-pagination__field">
|
|
23
|
+
<MSelect
|
|
24
|
+
class="mc-pagination__select"
|
|
25
|
+
:id="id"
|
|
26
|
+
v-model="currentValue"
|
|
27
|
+
:options="options"
|
|
28
|
+
@update:model-value="emit('update:modelValue', Number($event))"
|
|
29
|
+
:aria-label="selectLabel"
|
|
30
|
+
></MSelect>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<span v-if="compact" class="mc-pagination__label" aria-current="page">
|
|
34
|
+
{{ options.find(option => option.value === currentValue)?.text }}
|
|
35
|
+
</span>
|
|
36
|
+
|
|
37
|
+
<MButton
|
|
38
|
+
v-if="!compact"
|
|
39
|
+
icon-position="only"
|
|
40
|
+
aria-label="Next page"
|
|
41
|
+
:disabled="isLastPage"
|
|
42
|
+
@click="next"
|
|
43
|
+
>
|
|
44
|
+
<template #icon><ChevronRight24 /></template>
|
|
45
|
+
</MButton>
|
|
46
|
+
<MIconButton
|
|
47
|
+
v-else
|
|
48
|
+
outlined
|
|
49
|
+
aria-label="Next page"
|
|
50
|
+
:disabled="isLastPage"
|
|
51
|
+
@click="next"
|
|
52
|
+
>
|
|
53
|
+
<template #icon><ChevronRight24 /></template>
|
|
54
|
+
</MIconButton>
|
|
55
|
+
</nav>
|
|
56
|
+
</template>
|
|
57
|
+
|
|
58
|
+
<script setup lang="ts">
|
|
59
|
+
import { computed, ref, watch } from 'vue';
|
|
60
|
+
import MButton from '../button/MButton.vue';
|
|
61
|
+
import MSelect from '../select/MSelect.vue';
|
|
62
|
+
import ChevronLeft24 from '@mozaic-ds/icons-vue/src/components/ChevronLeft24/ChevronLeft24.vue';
|
|
63
|
+
import ChevronRight24 from '@mozaic-ds/icons-vue/src/components/ChevronRight24/ChevronRight24.vue';
|
|
64
|
+
import MIconButton from '../iconbutton/MIconButton.vue';
|
|
65
|
+
/**
|
|
66
|
+
* Pagination is a navigation component that allows users to browse through large sets of content by dividing it into discrete pages. It typically includes previous and next buttons, numeric page selectors, or dropdowns to jump between pages efficiently. Pagination improves usability and performance in content-heavy applications such as tables, search results, and articles by preventing long scrolls and reducing page load times.
|
|
67
|
+
*/
|
|
68
|
+
const props = defineProps<{
|
|
69
|
+
/**
|
|
70
|
+
* A unique identifier for the pagination.
|
|
71
|
+
*/
|
|
72
|
+
id: string;
|
|
73
|
+
/**
|
|
74
|
+
* The current value of the selected page.
|
|
75
|
+
*/
|
|
76
|
+
modelValue: number;
|
|
77
|
+
/**
|
|
78
|
+
* If `true`, display a compact version without the select.
|
|
79
|
+
*/
|
|
80
|
+
compact?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Define the available choices for the pagination select element.
|
|
83
|
+
*/
|
|
84
|
+
options: Array<{
|
|
85
|
+
id?: string;
|
|
86
|
+
text: string;
|
|
87
|
+
value: number;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Accessible label for the select of the pagination.
|
|
91
|
+
*/
|
|
92
|
+
selectLabel?: string;
|
|
93
|
+
}>();
|
|
94
|
+
|
|
95
|
+
const emit = defineEmits<{
|
|
96
|
+
/**
|
|
97
|
+
* Emits when the pagination value changes, updating the modelValue prop.
|
|
98
|
+
*/
|
|
99
|
+
(on: 'update:modelValue', value: number): void;
|
|
100
|
+
}>();
|
|
101
|
+
|
|
102
|
+
const currentValue = ref(props.modelValue);
|
|
103
|
+
|
|
104
|
+
watch(currentValue, (newVal) => {
|
|
105
|
+
if (newVal !== props.modelValue) {
|
|
106
|
+
emit('update:modelValue', newVal);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const currentIndex = computed(() =>
|
|
111
|
+
props.options.findIndex(opt => opt.value === currentValue.value)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const isFirstPage = computed(() => currentIndex.value === 0);
|
|
115
|
+
const isLastPage = computed(() => currentIndex.value === props.options.length - 1);
|
|
116
|
+
|
|
117
|
+
const previous = () => {
|
|
118
|
+
const currentIndex = props.options.findIndex(
|
|
119
|
+
(opt) => opt.value === currentValue.value,
|
|
120
|
+
);
|
|
121
|
+
if (currentIndex > 0) {
|
|
122
|
+
currentValue.value = props.options[currentIndex - 1].value;
|
|
123
|
+
emit('update:modelValue', props.options[currentIndex - 1].value);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const next = () => {
|
|
128
|
+
const currentIndex = props.options.findIndex(
|
|
129
|
+
(opt) => opt.value === currentValue.value,
|
|
130
|
+
);
|
|
131
|
+
if (currentIndex < props.options.length - 1) {
|
|
132
|
+
currentValue.value = props.options[currentIndex + 1].value;
|
|
133
|
+
emit('update:modelValue', props.options[currentIndex + 1].value);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
</script>
|
|
137
|
+
|
|
138
|
+
<style lang="scss" scoped>
|
|
139
|
+
@use '@mozaic-ds/styles/components/pagination';
|
|
140
|
+
</style>
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
|
2
|
+
import { action } from '@storybook/addon-actions';
|
|
3
|
+
|
|
4
|
+
import Mtabs from './MTabs.vue';
|
|
5
|
+
import ChevronRight24 from '@mozaic-ds/icons-vue/src/components/ChevronRight24/ChevronRight24.vue';
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Mtabs> = {
|
|
8
|
+
title: 'Navigation/Tabs',
|
|
9
|
+
component: Mtabs,
|
|
10
|
+
parameters: {
|
|
11
|
+
docs: {
|
|
12
|
+
description: {
|
|
13
|
+
component:
|
|
14
|
+
'Tabs are a navigation component that allows users to switch between different sections within the same context. They help organize content efficiently by displaying only one section at a time, reducing clutter and improving accessibility. Tabs can include icons, labels, and notification badges to provide additional context. They are commonly used in dashboards, product management, and settings interfaces.',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
args: {
|
|
19
|
+
tabs: [
|
|
20
|
+
{
|
|
21
|
+
label: 'Label',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: 'Label',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: 'Label',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: 'Label',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
render: (args) => ({
|
|
35
|
+
components: { Mtabs, ChevronRight24 },
|
|
36
|
+
setup() {
|
|
37
|
+
const handleUpdate = action('update:modelValue');
|
|
38
|
+
|
|
39
|
+
return { args, handleUpdate };
|
|
40
|
+
},
|
|
41
|
+
template: `
|
|
42
|
+
<Mtabs
|
|
43
|
+
v-bind="args"
|
|
44
|
+
@update:modelValue="handleUpdate"
|
|
45
|
+
></Mtabs>
|
|
46
|
+
`,
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
export default meta;
|
|
50
|
+
type Story = StoryObj<typeof Mtabs>;
|
|
51
|
+
|
|
52
|
+
export const Default: Story = {};
|
|
53
|
+
|
|
54
|
+
export const Icons: Story = {
|
|
55
|
+
args: {
|
|
56
|
+
tabs: [
|
|
57
|
+
{
|
|
58
|
+
label: 'Label',
|
|
59
|
+
icon: ChevronRight24,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: 'Label',
|
|
63
|
+
icon: ChevronRight24,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
label: 'Label',
|
|
67
|
+
icon: ChevronRight24,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
label: 'Label',
|
|
71
|
+
icon: ChevronRight24,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const Centered: Story = {
|
|
78
|
+
args: { centered: true },
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const NoDivider: Story = {
|
|
82
|
+
args: { divider: false },
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const Disabled: Story = {
|
|
86
|
+
args: {
|
|
87
|
+
tabs: [
|
|
88
|
+
{
|
|
89
|
+
label: 'Label',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
label: 'Label',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
label: 'Label',
|
|
96
|
+
disabled: true,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
label: 'Label',
|
|
100
|
+
disabled: true,
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<nav class="mc-tabs" :class="classObject">
|
|
3
|
+
<ul role="tablist" class="mc-tabs__list" :aria-label="description">
|
|
4
|
+
<li
|
|
5
|
+
v-for="(tab, index) in tabs"
|
|
6
|
+
:key="`tab-${index}`"
|
|
7
|
+
role="presentation"
|
|
8
|
+
class="mc-tabs__item"
|
|
9
|
+
>
|
|
10
|
+
<button
|
|
11
|
+
ref="tab"
|
|
12
|
+
role="tab"
|
|
13
|
+
class="mc-tabs__tab"
|
|
14
|
+
:class="{
|
|
15
|
+
'mc-tabs__tab--selected': isTabSelected(index),
|
|
16
|
+
'mc-tabs__tab--disabled': tab.disabled,
|
|
17
|
+
}"
|
|
18
|
+
:aria-selected="isTabSelected(index)"
|
|
19
|
+
type="button"
|
|
20
|
+
@click="onClickTab(index)"
|
|
21
|
+
>
|
|
22
|
+
<span v-if="tab.icon" class="mc-tabs__icon">
|
|
23
|
+
<component :is="tab.icon" />
|
|
24
|
+
</span>
|
|
25
|
+
<div class="mc-tabs__label">
|
|
26
|
+
<span>{{ tab.label }}</span>
|
|
27
|
+
</div>
|
|
28
|
+
</button>
|
|
29
|
+
</li>
|
|
30
|
+
</ul>
|
|
31
|
+
<MDivider v-if="divider"></MDivider>
|
|
32
|
+
</nav>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script setup lang="ts">
|
|
36
|
+
import { computed, ref, type Component } from 'vue';
|
|
37
|
+
import MDivider from '../divider/MDivider.vue';
|
|
38
|
+
/**
|
|
39
|
+
* Tabs are a navigation component that allows users to switch between different sections within the same context. They help organize content efficiently by displaying only one section at a time, reducing clutter and improving accessibility. Tabs can include icons, labels, and notification badges to provide additional context. They are commonly used in dashboards, product management, and settings interfaces.
|
|
40
|
+
*/
|
|
41
|
+
const props = withDefaults(
|
|
42
|
+
defineProps<{
|
|
43
|
+
/**
|
|
44
|
+
* A description indicating the purpose of the set of tabs. Useful for improving the accessibility of the component.
|
|
45
|
+
*/
|
|
46
|
+
description?: string;
|
|
47
|
+
/**
|
|
48
|
+
* If `true`, the divider will appear.
|
|
49
|
+
*/
|
|
50
|
+
divider?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* If `true`, the tabs of the component will be centered.
|
|
53
|
+
*/
|
|
54
|
+
centered?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The selected tab index, bound via v-model.
|
|
57
|
+
*/
|
|
58
|
+
modelValue?: number;
|
|
59
|
+
/**
|
|
60
|
+
* An array of objects that allows you to provide all the data needed to generate the content for each tab.
|
|
61
|
+
*/
|
|
62
|
+
tabs: Array<{
|
|
63
|
+
/**
|
|
64
|
+
* The icon displayed for the tab from Mozaic-icon-vue.
|
|
65
|
+
*/
|
|
66
|
+
icon?: Component;
|
|
67
|
+
/**
|
|
68
|
+
* The label displayed for the tab.
|
|
69
|
+
*/
|
|
70
|
+
label: string;
|
|
71
|
+
/**
|
|
72
|
+
* If `true`, the tab will be disabled.
|
|
73
|
+
*/
|
|
74
|
+
disabled?: boolean;
|
|
75
|
+
}>;
|
|
76
|
+
}>(),
|
|
77
|
+
{
|
|
78
|
+
modelValue: 0,
|
|
79
|
+
divider: true,
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const classObject = computed(() => {
|
|
84
|
+
return {
|
|
85
|
+
'mc-tabs--centered': props.centered,
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const modelValue = ref(props.modelValue);
|
|
90
|
+
|
|
91
|
+
const onClickTab = (index: number) => {
|
|
92
|
+
if (props.tabs[index].disabled) return;
|
|
93
|
+
if (index !== modelValue.value) {
|
|
94
|
+
modelValue.value = index;
|
|
95
|
+
emit('update:modelValue', index);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const isTabSelected = (index: number) => {
|
|
100
|
+
return modelValue.value === index;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const emit = defineEmits<{
|
|
104
|
+
/**
|
|
105
|
+
* Emits when the selected tab changes, updating the modelValue prop.
|
|
106
|
+
*/
|
|
107
|
+
(on: 'update:modelValue', value: number): void;
|
|
108
|
+
}>();
|
|
109
|
+
</script>
|
|
110
|
+
|
|
111
|
+
<style lang="scss" scoped>
|
|
112
|
+
@use '@mozaic-ds/styles/components/tabs';
|
|
113
|
+
</style>
|