@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.
@@ -0,0 +1,154 @@
1
+ import { mount } from '@vue/test-utils';
2
+ import { describe, it, expect } from 'vitest';
3
+ import MTabs from './MTabs.vue';
4
+ import { defineComponent, h } from 'vue';
5
+
6
+ describe('MTabs.vue', () => {
7
+ const tabs = [
8
+ { label: 'Tab 1' },
9
+ { label: 'Tab 2' },
10
+ { label: 'Tab 3' },
11
+ ];
12
+
13
+ it('renders tabs with correct labels', () => {
14
+ const wrapper = mount(MTabs, {
15
+ props: {
16
+ tabs,
17
+ },
18
+ });
19
+
20
+ const tabElements = wrapper.findAll('li.mc-tabs__item');
21
+ expect(tabElements.length).toBe(tabs.length);
22
+
23
+ tabs.forEach((tab, i) => {
24
+ expect(tabElements[i].text()).toContain(tab.label);
25
+ });
26
+ });
27
+
28
+ it('applies selected class and aria-selected attribute based on modelValue and updates on tab click', async () => {
29
+ const wrapper = mount(MTabs, {
30
+ props: {
31
+ tabs,
32
+ modelValue: 0,
33
+ },
34
+ });
35
+
36
+ const buttons = wrapper.findAll('button.mc-tabs__tab');
37
+
38
+ buttons.forEach((button, i) => {
39
+ if (i === 0) {
40
+ expect(button.classes()).toContain('mc-tabs__tab--selected');
41
+ expect(button.attributes('aria-selected')).toBe('true');
42
+ } else {
43
+ expect(button.classes()).not.toContain('mc-tabs__tab--selected');
44
+ expect(button.attributes('aria-selected')).toBe('false');
45
+ }
46
+ });
47
+
48
+ await buttons[1].trigger('click');
49
+
50
+ expect(wrapper.emitted('update:modelValue')).toBeTruthy();
51
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual([1]);
52
+
53
+ await wrapper.setProps({ modelValue: 1 });
54
+
55
+ const updatedButtons = wrapper.findAll('button.mc-tabs__tab');
56
+ updatedButtons.forEach((button, i) => {
57
+ if (i === 1) {
58
+ expect(button.classes()).toContain('mc-tabs__tab--selected');
59
+ expect(button.attributes('aria-selected')).toBe('true');
60
+ } else {
61
+ expect(button.classes()).not.toContain('mc-tabs__tab--selected');
62
+ expect(button.attributes('aria-selected')).toBe('false');
63
+ }
64
+ });
65
+ });
66
+
67
+
68
+ it('adds divider and centered classes based on props', async () => {
69
+ const wrapper = mount(MTabs, {
70
+ props: {
71
+ tabs,
72
+ divider: true,
73
+ centered: true,
74
+ },
75
+ });
76
+
77
+ expect(wrapper.classes()).toContain('mc-tabs--centered');
78
+ expect(wrapper.findComponent({ name: 'MDivider' }).exists()).toBe(true);
79
+
80
+ await wrapper.setProps({ divider: false, centered: false });
81
+
82
+ expect(wrapper.classes()).not.toContain('mc-tabs--centered');
83
+ expect(wrapper.findComponent({ name: 'MDivider' }).exists()).toBe(false);
84
+ });
85
+
86
+ it('sets aria-label on tablist based on description prop', () => {
87
+ const description = 'Main tabs navigation';
88
+ const wrapper = mount(MTabs, {
89
+ props: {
90
+ tabs,
91
+ description,
92
+ },
93
+ });
94
+
95
+ const ul = wrapper.find('ul[role="tablist"]');
96
+ expect(ul.attributes('aria-label')).toBe(description);
97
+ });
98
+
99
+ it('renders no tabs if tabs prop is empty', () => {
100
+ const wrapper = mount(MTabs, { props: { tabs: [] } });
101
+ expect(wrapper.findAll('li.mc-tabs__item').length).toBe(0);
102
+ });
103
+
104
+ it('emits update:modelValue on tab click if tab is not disabled', async () => {
105
+ const wrapper = mount(MTabs, {
106
+ props: {
107
+ tabs: [
108
+ { label: 'Tab 1' },
109
+ { label: 'Tab 2', disabled: true },
110
+ { label: 'Tab 3' },
111
+ ],
112
+ modelValue: 0,
113
+ },
114
+ });
115
+
116
+ const buttons = wrapper.findAll('button.mc-tabs__tab');
117
+
118
+ await buttons[2].trigger('click');
119
+ expect(wrapper.emitted('update:modelValue')).toBeTruthy();
120
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual([2]);
121
+
122
+ await buttons[1].trigger('click');
123
+ expect(wrapper.emitted('update:modelValue')!.length).toBe(1);
124
+ });
125
+
126
+ it('renders icon component when icon prop is provided', () => {
127
+ const DummyIcon = defineComponent({
128
+ name: 'DummyIcon',
129
+ render() {
130
+ return h('svg', { class: 'dummy-icon' }, [
131
+ h('circle', { cx: 10, cy: 10, r: 10 }),
132
+ ]);
133
+ },
134
+ });
135
+
136
+ const tabsWithIcon = [
137
+ { label: 'Tab 1', icon: DummyIcon },
138
+ { label: 'Tab 2' },
139
+ ];
140
+
141
+ const wrapper = mount(MTabs, {
142
+ props: {
143
+ tabs: tabsWithIcon,
144
+ },
145
+ });
146
+
147
+ const firstTabButton = wrapper.findAll('button.mc-tabs__tab')[0];
148
+ expect(firstTabButton.findComponent(DummyIcon).exists()).toBe(true);
149
+ expect(firstTabButton.find('svg.dummy-icon').exists()).toBe(true);
150
+
151
+ const secondTabButton = wrapper.findAll('button.mc-tabs__tab')[1];
152
+ expect(secondTabButton.findComponent(DummyIcon).exists()).toBe(false);
153
+ });
154
+ });
@@ -0,0 +1,107 @@
1
+ import { mount } from '@vue/test-utils';
2
+ import MTag from './MTag.vue';
3
+ import { describe, it, expect, vi } from 'vitest';
4
+
5
+ describe('MTag.vue', () => {
6
+ it('renders a selectable tag with a checkbox and label', async () => {
7
+ const wrapper = mount(MTag, {
8
+ props: {
9
+ type: 'selectable',
10
+ label: 'Test Tag',
11
+ modelValue: false,
12
+ id: 'test-tag-id',
13
+ name: 'test-tag',
14
+ },
15
+ });
16
+
17
+ const checkbox = wrapper.find('input');
18
+ const label = wrapper.find('.mc-tag__label');
19
+
20
+ expect(checkbox.exists()).toBe(true);
21
+ expect(label.text()).toBe('Test Tag');
22
+ expect(checkbox.element.checked).toBe(false);
23
+
24
+ await checkbox.setChecked();
25
+ expect(wrapper.emitted()['update:modelValue'][0]).toEqual([true]);
26
+ });
27
+
28
+ it('renders an interactive tag as a button with label', () => {
29
+ const wrapper = mount(MTag, {
30
+ props: {
31
+ type: 'interactive',
32
+ label: 'Interactive Tag',
33
+ },
34
+ });
35
+
36
+ const button = wrapper.find('button');
37
+ const label = wrapper.find('.mc-tag__label');
38
+
39
+ expect(button.exists()).toBe(true);
40
+ expect(label.text()).toBe('Interactive Tag');
41
+ });
42
+
43
+ it('renders a contextualised tag with badge number', () => {
44
+ const wrapper = mount(MTag, {
45
+ props: {
46
+ type: 'contextualised',
47
+ label: 'Contextualised Tag',
48
+ contextualisedNumber: 42,
49
+ },
50
+ });
51
+
52
+ const badge = wrapper.findComponent({ name: 'MNumberBadge' });
53
+ const label = wrapper.find('.mc-tag__label');
54
+
55
+ expect(badge.exists()).toBe(true);
56
+ expect(badge.props('label')).toBe(42);
57
+ expect(label.text()).toBe('Contextualised Tag');
58
+ });
59
+
60
+ it('renders a removable tag with a delete button and emits remove event', async () => {
61
+ const removeTag = vi.fn();
62
+ const wrapper = mount(MTag, {
63
+ props: {
64
+ type: 'removable',
65
+ label: 'Removable Tag',
66
+ id: 'removable-tag-id',
67
+ },
68
+ global: {
69
+ mocks: {
70
+ emit: removeTag,
71
+ },
72
+ },
73
+ });
74
+
75
+ const removeButton = wrapper.find('button.mc-tag-removable__remove');
76
+ expect(removeButton.exists()).toBe(true);
77
+
78
+ await removeButton.trigger('click');
79
+ expect(removeTag).toHaveBeenCalledWith('remove-tag', 'removable-tag-id');
80
+ });
81
+
82
+ it('renders with the correct size classes based on the size prop', () => {
83
+ const wrapper = mount(MTag, {
84
+ props: {
85
+ type: 'informative',
86
+ label: 'Informative Tag',
87
+ size: 'l',
88
+ },
89
+ });
90
+
91
+ const element = wrapper.find('span.mc-tag');
92
+ expect(element.classes()).toContain('mc-tag--l');
93
+ });
94
+
95
+ it('should disable the tag when the disabled prop is true', () => {
96
+ const wrapper = mount(MTag, {
97
+ props: {
98
+ type: 'selectable',
99
+ label: 'Disabled Tag',
100
+ disabled: true,
101
+ },
102
+ });
103
+
104
+ const checkbox = wrapper.find('input');
105
+ expect(checkbox.element.disabled).toBe(true);
106
+ });
107
+ });
@@ -0,0 +1,75 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3';
2
+ import { action } from '@storybook/addon-actions';
3
+ import MTag from './MTag.vue';
4
+
5
+ const meta: Meta<typeof MTag> = {
6
+ title: 'Indicators/Tag',
7
+ component: MTag,
8
+ parameters: {
9
+ docs: {
10
+ description: {
11
+ component:
12
+ 'A Status dot is a small visual indicator used to represent the state or condition of an element. It is often color-coded to convey different statuses at a glance, such as availability, activity, or urgency. Status Dots are commonly found in user presence indicators, system statuses, or process tracking to provide quick, unobtrusive feedback.',
13
+ },
14
+ },
15
+ },
16
+ args: {
17
+ label: 'Tag label',
18
+ },
19
+ render: (args) => ({
20
+ components: { MTag },
21
+ setup() {
22
+ const handleUpdate = action('update:modelValue');
23
+ const handleRemoveTag = action('remove-tag');
24
+
25
+ return { args, handleUpdate, handleRemoveTag };
26
+ },
27
+ template: `
28
+ <MTag
29
+ v-bind="args"
30
+ @update:modelValue="handleUpdate"
31
+ @remove-tag="handleRemoveTag"
32
+ ></MTag>
33
+ `,
34
+ }),
35
+ };
36
+ export default meta;
37
+ type Story = StoryObj<typeof MTag>;
38
+
39
+ export const Default: Story = {};
40
+
41
+ export const Size: Story = {
42
+ args: { size: 's' },
43
+ };
44
+
45
+ export const Interactive: Story = {
46
+ args: { type: 'interactive' },
47
+ };
48
+
49
+ export const Disabled: Story = {
50
+ args: {
51
+ type: 'interactive',
52
+ disabled: true,
53
+ },
54
+ };
55
+
56
+ export const Contextualised: Story = {
57
+ args: {
58
+ type: 'contextualised',
59
+ contextualisedNumber: 99,
60
+ },
61
+ };
62
+
63
+ export const Removable: Story = {
64
+ args: {
65
+ type: 'removable',
66
+ id: 'tagId',
67
+ },
68
+ };
69
+
70
+ export const Selectable: Story = {
71
+ args: {
72
+ type: 'selectable',
73
+ modelValue: true,
74
+ },
75
+ };
@@ -0,0 +1,154 @@
1
+ <template>
2
+ <label
3
+ v-if="type === 'selectable'"
4
+ :for="id"
5
+ class="mc-tag"
6
+ :class="classObject"
7
+ >
8
+ <input
9
+ type="checkbox"
10
+ class="mc-tag__input"
11
+ :id="id"
12
+ :name="name"
13
+ :checked="modelValue"
14
+ :disabled="disabled"
15
+ @change="
16
+ emit('update:modelValue', ($event.target as HTMLInputElement).checked)
17
+ "
18
+ v-bind="$attrs"
19
+ />
20
+ <span class="mc-tag__label">{{ label }}</span>
21
+ </label>
22
+
23
+ <button
24
+ v-else-if="type === 'interactive'"
25
+ class="mc-tag"
26
+ type="button"
27
+ :class="classObject"
28
+ :disabled="disabled"
29
+ v-bind="$attrs"
30
+ >
31
+ <span class="mc-tag__label">{{ label }}</span>
32
+ </button>
33
+
34
+ <button
35
+ v-else-if="type === 'contextualised'"
36
+ class="mc-tag"
37
+ type="button"
38
+ :class="classObject"
39
+ :disabled="disabled"
40
+ v-bind="$attrs"
41
+ >
42
+ <MNumberBadge
43
+ appearance="inverse"
44
+ :label="contextualisedNumber"
45
+ :size="size === 'l' ? 'm' : undefined"
46
+ />
47
+ <span class="mc-tag__label">{{ label }}</span>
48
+ </button>
49
+
50
+ <span
51
+ v-else-if="type === 'removable'"
52
+ class="mc-tag"
53
+ :class="classObject"
54
+ v-bind="$attrs"
55
+ >
56
+ <span class="mc-tag__label">{{ label }}</span>
57
+ <button
58
+ class="mc-tag-removable__remove"
59
+ type="button"
60
+ @click="id && emit('remove-tag', id)"
61
+ >
62
+ <CrossCircleFilled24
63
+ class="mc-tag-removable__icon"
64
+ aria-hidden="true"
65
+ />
66
+ <span class="mc-tag-removable__text">removableLabel</span>
67
+ </button>
68
+ </span>
69
+
70
+ <!-- informative -->
71
+ <span v-else class="mc-tag" :class="classObject" v-bind="$attrs">
72
+ <span class="mc-tag__label">{{ label }}</span>
73
+ </span>
74
+ </template>
75
+
76
+ <script setup lang="ts">
77
+ import { computed } from 'vue';
78
+ import CrossCircleFilled24 from '@mozaic-ds/icons-vue/src/components/CrossCircleFilled24/CrossCircleFilled24.vue';
79
+ import MNumberBadge from '../numberbadge/MNumberBadge.vue';
80
+ /**
81
+ * A Tag is a UI element used to filter data, categorize, select or deselect an option. It can appear standalone, in a group, or embedded within other components. Depending on its use, a tag can be interactive (clickable, removable, selectable) or static (serving as a visual indicator).
82
+ */
83
+ const props = withDefaults(
84
+ defineProps<{
85
+ /**
86
+ * Defines the behavior and layout of the tag.
87
+ */
88
+ type?:
89
+ | 'informative'
90
+ | 'interactive'
91
+ | 'contextualised'
92
+ | 'removable'
93
+ | 'selectable';
94
+ /**
95
+ * Determines the size of the tag.
96
+ */
97
+ size?: 's' | 'm' | 'l';
98
+ /**
99
+ * A unique identifier for the tag, used to associate the label with the form element. **Required** when type is 'selectable' or 'removable'.
100
+ */
101
+ id?: string;
102
+ /**
103
+ * The name attribute for the tag element, typically used for form submission. (only relevant for type: 'selectable').
104
+ */
105
+ name?: string;
106
+ /**
107
+ * The text label displayed next to the tag.
108
+ */
109
+ label: string;
110
+ /**
111
+ * The tag's checked state, bound via v-model. Used only for type: 'selectable'.
112
+ */
113
+ modelValue?: boolean;
114
+ /**
115
+ * If `true`, disables the tag, making it non-interactive. Applicable to selectable, interactive, and contextualised types.
116
+ */
117
+ disabled?: boolean;
118
+ /**
119
+ * A number displayed in the badge when the tag is contextualised.
120
+ */
121
+ contextualisedNumber?: number;
122
+ /**
123
+ * Accessible label text for the remove button in removable tags.
124
+ */
125
+ removableLabel?: string;
126
+ }>(),
127
+ {
128
+ type: 'informative',
129
+ contextualisedNumber: 99,
130
+ },
131
+ );
132
+
133
+ const classObject = computed(() => {
134
+ return {
135
+ [`mc-tag-${props.type}`]: props.type && props.type != 'informative',
136
+ [`mc-tag--${props.size}`]: props.size && props.size != 'm',
137
+ };
138
+ });
139
+
140
+ const emit = defineEmits<{
141
+ /**
142
+ * Emits when the tag value changes, updating the modelValue prop.
143
+ */
144
+ (on: 'update:modelValue', value: boolean): void;
145
+ /**
146
+ * Emits when the remove button of a tag is clicked, passing the tag's ID.
147
+ */
148
+ (on: 'remove-tag', id: string): void;
149
+ }>();
150
+ </script>
151
+
152
+ <style lang="scss" scoped>
153
+ @use '@mozaic-ds/styles/components/tag';
154
+ </style>
package/src/main.ts CHANGED
@@ -2,6 +2,7 @@ export { default as MBreadcrumb } from './components/breadcrumb/MBreadcrumb.vue'
2
2
  export { default as MButton } from './components/button/MButton.vue';
3
3
  export { default as MCheckbox } from './components/checkbox/MCheckbox.vue';
4
4
  export { default as MCheckboxGroup } from './components/checkboxgroup/MCheckboxGroup.vue';
5
+ export { default as MDivider } from './components/divider/MDivider.vue';
5
6
  export { default as MField } from './components/field/MField.vue';
6
7
  export { default as MFieldGroup } from './components/fieldgroup/MFieldGroup.vue';
7
8
  export { default as MIconButton } from './components/iconbutton/MIconButton.vue';
@@ -9,6 +10,7 @@ export { default as MLink } from './components/link/MLink.vue';
9
10
  export { default as MLoader } from './components/loader/MLoader.vue';
10
11
  export { default as MNumberBadge } from './components/numberbadge/MNumberBadge.vue';
11
12
  export { default as MOverlay } from './components/overlay/MOverlay.vue';
13
+ export { default as MPagination } from './components/pagination/MPagination.vue';
12
14
  export { default as MPasswordInput } from './components/passwordinput/MPasswordInput.vue';
13
15
  export { default as MQuantitySelector } from './components/quantityselector/MQuantitySelector.vue';
14
16
  export { default as MRadio } from './components/radio/MRadio.vue';
@@ -16,6 +18,8 @@ export { default as MRadioGroup } from './components/radiogroup/MRadioGroup.vue'
16
18
  export { default as MSelect } from './components/select/MSelect.vue';
17
19
  export { default as MStatusBadge } from './components/statusbadge/MStatusBadge.vue';
18
20
  export { default as MStatusNotification } from './components/statusnotification/MStatusNotification.vue';
21
+ export { default as MTabs } from './components/tabs/MTabs.vue';
22
+ export { default as MTag } from './components/tag/MTag.vue';
19
23
  export { default as MTextArea } from './components/textarea/MTextArea.vue';
20
24
  export { default as MTextInput } from './components/textinput/MTextInput.vue';
21
25
  export { default as MToggle } from './components/toggle/MToggle.vue';