Skip to content

Commit ac49577

Browse files
committed
Add ButtonGroup component
1 parent 2b2a18b commit ac49577

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { shallowMount } from '@vue/test-utils';
2+
import ButtonGroup from './ButtonGroup.vue';
3+
4+
describe('ButtonGroup', () => {
5+
it('renders a button group', () => {
6+
const wrapper = shallowMount(ButtonGroup, {
7+
slots: {
8+
default: '<button>Save</button><button>Edit</button><button>Delete</button>'
9+
}
10+
});
11+
12+
expect(wrapper.findAll('button')).toHaveLength(3);
13+
});
14+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import type { Meta, StoryObj } from '@storybook/vue3';
2+
3+
import ButtonGroup from './ButtonGroup.vue';
4+
import Button from '../Button/Button.vue';
5+
6+
const meta = {
7+
title: 'Components/ButtonGroup',
8+
component: ButtonGroup
9+
} satisfies Meta<typeof ButtonGroup>;
10+
11+
export default meta;
12+
type Story = StoryObj<typeof meta>;
13+
14+
export const Group1: Story = {
15+
render: (args) => ({
16+
components: { ButtonGroup, Button },
17+
setup() {
18+
return { args };
19+
},
20+
template: `<ButtonGroup v-bind="args">
21+
<Button status="info">Save</Button>
22+
<Button status="info">Edit</Button>
23+
<Button status="info">Delete</Button>
24+
</ButtonGroup>`
25+
})
26+
};
27+
28+
export const Group2: Story = {
29+
render: (args) => ({
30+
components: { ButtonGroup, Button },
31+
setup() {
32+
const iconSrc = new URL('@/docs/assets/ChevronRight.svg', import.meta.url).href;
33+
return { args, iconSrc };
34+
},
35+
template: `<ButtonGroup v-bind="args">
36+
<Button status="info" round>Save</Button>
37+
<Button status="info" round>Edit</Button>
38+
<Button status="info" round>Delete</Button>
39+
</ButtonGroup>`
40+
})
41+
};
42+
43+
export const Group3: Story = {
44+
render: (args) => ({
45+
components: { ButtonGroup, Button },
46+
setup() {
47+
const iconSrc = new URL('@/docs/assets/ChevronDown.svg', import.meta.url).href;
48+
return { args, iconSrc };
49+
},
50+
template: `<ButtonGroup v-bind="args">
51+
<Button status="info">Save</Button>
52+
<Button status="info" :icon="{ src: iconSrc, position: 'icon-only' }">More</Button>
53+
</ButtonGroup>`
54+
})
55+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div role="group" class="j-btn-group">
3+
<slot />
4+
</div>
5+
</template>
6+
7+
<script lang="ts" setup></script>
8+
9+
<style lang="scss" scoped>
10+
.j-btn-group {
11+
display: flex;
12+
gap: 0;
13+
flex-wrap: nowrap;
14+
15+
:deep(> *) {
16+
&:not(:first-child) {
17+
border-top-left-radius: 0;
18+
border-bottom-left-radius: 0;
19+
}
20+
21+
&:not(:last-child) {
22+
border-top-right-radius: 0;
23+
border-bottom-right-radius: 0;
24+
}
25+
}
26+
}
27+
</style>

0 commit comments

Comments
 (0)