From 089db67ec86120ef726614b2fe429fd1d5c77966 Mon Sep 17 00:00:00 2001 From: Kiril Videlov Date: Tue, 28 Mar 2023 16:01:34 +0200 Subject: [PATCH] button group component --- src/lib/components/ButtonGroup.svelte | 41 ++++++++++++++++------ src/lib/components/index.ts | 1 + src/stories/ButtonGroup.stories.ts | 50 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 src/stories/ButtonGroup.stories.ts diff --git a/src/lib/components/ButtonGroup.svelte b/src/lib/components/ButtonGroup.svelte index dc1076208..ab57ae9eb 100644 --- a/src/lib/components/ButtonGroup.svelte +++ b/src/lib/components/ButtonGroup.svelte @@ -1,17 +1,36 @@ -{#if $$slots.middle} -
- - - + +{#if !middleLabel} +
+
{:else} -
- - +
+ + +
{/if} + + diff --git a/src/lib/components/index.ts b/src/lib/components/index.ts index ad5d06a08..15821aede 100644 --- a/src/lib/components/index.ts +++ b/src/lib/components/index.ts @@ -5,3 +5,4 @@ export { default as CodeViewer } from './CodeViewer'; export { default as CommandPalette } from './CommandPalette'; export { default as Modal } from './Modal.svelte'; export { default as Button } from './Button.svelte'; +export { default as ButtonGroup } from './ButtonGroup.svelte'; diff --git a/src/stories/ButtonGroup.stories.ts b/src/stories/ButtonGroup.stories.ts new file mode 100644 index 000000000..96e2930a6 --- /dev/null +++ b/src/stories/ButtonGroup.stories.ts @@ -0,0 +1,50 @@ +import type { Meta, StoryObj } from '@storybook/svelte'; + +import ButtonGroup from '$lib/components/ButtonGroup.svelte'; + +// More on how to set up stories at: https://storybook.js.org/docs/7.0/svelte/writing-stories/introduction +const meta: Meta = { + title: 'GitButler/ButtonGroup', + component: ButtonGroup, + tags: ['autodocs'], + argTypes: { + leftLabel: { control: 'text' }, + rightLabel: { control: 'text' }, + middleLabel: { control: 'text' }, + } +}; + +export default meta; +type Story = StoryObj; + +export const TwoButtons: Story = { + args: { + leftLabel: 'Cancel', + rightLabel: 'Submit', + } +}; + +export const TwoButtonsWide: Story = { + args: { + leftLabel: 'Cancel', + rightLabel: 'Submit', + wide: true, + } +}; + +export const ThreeButtons: Story = { + args: { + leftLabel: 'Left', + middleLabel: 'Middle', + rightLabel: 'Right', + } +}; + +export const ThreeButtonsWide: Story = { + args: { + leftLabel: 'Left', + middleLabel: 'Middle', + rightLabel: 'Right', + wide: true, + } +};