-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(button-group): refine styles (#222)
Co-authored-by: Kia Ishii <kia.king.08@gmail.com>
- Loading branch information
1 parent
27223ff
commit 06f5934
Showing
7 changed files
with
145 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script setup lang="ts"> | ||
import SButton from 'sefirot/components/SButton.vue' | ||
import SButtonGroup from 'sefirot/components/SButtonGroup.vue' | ||
</script> | ||
|
||
# SButtonGroup | ||
|
||
`<SButtonGroup>` is a component that groups multiple buttons together. | ||
|
||
<Showcase | ||
path="/components/SButtonGroup.vue" | ||
story="/stories-components-sbuttongroup-01-playground-story-vue" | ||
> | ||
<SButtonGroup> | ||
<SButton mode="mute" label="Left" /> | ||
<SButton mode="mute" label="Middle" /> | ||
<SButton mode="mute" label="Right" /> | ||
</SButtonGroup> | ||
</Showcase> | ||
## Usage | ||
|
||
Wrap `<SButton>` with `<SButtonGroup>` component. Note that currently it does not support button types other than `:type="fill"`. If you pass other type buttons the style might get corrupted. | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
import SButton from '@globalbrain/sefirot/lib/components/SButton.vue' | ||
import SButtonGroup from '@globalbrain/sefirot/lib/components/SButtonGroup.vue' | ||
</script> | ||
<template> | ||
<SButtonGroup> | ||
<SButton mode="mute" label="Left" /> | ||
<SButton mode="mute" label="Middle" /> | ||
<SButton mode="mute" label="Right" /> | ||
</SButtonGroup> | ||
</template> | ||
``` | ||
|
||
## Slots | ||
|
||
Here are the list of slots you may define within the component. | ||
|
||
### `#default` | ||
|
||
You may pass in any number of `<SButton>` components. The component will group them together. | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
import SButton from '@globalbrain/sefirot/lib/components/SButton.vue' | ||
import SButtonGroup from '@globalbrain/sefirot/lib/components/SButtonGroup.vue' | ||
</script> | ||
<template> | ||
<SButtonGroup> | ||
<SButton mode="mute" label="Left" /> | ||
<SButton mode="mute" label="Middle" /> | ||
<SButton mode="mute" label="Right" /> | ||
</SButtonGroup> | ||
</template> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,17 @@ | ||
<script setup lang="ts"> | ||
import { PropType, computed } from 'vue' | ||
export interface ButtonGroupItem { | ||
label: string | ||
value: string | ||
mode?: Mode | ||
} | ||
export type Mode = 'neutral' | 'info' | 'success' | 'warning' | 'danger' | ||
export type Size = 'mini' | 'small' | 'medium' | 'large' | 'jumbo' | ||
const props = defineProps({ | ||
items: { type: Array as PropType<ButtonGroupItem[]>, required: true }, | ||
size: { type: String as PropType<Size>, default: 'medium' }, | ||
modelValue: { type: String, default: null } | ||
}) | ||
const emit = defineEmits(['update:modelValue']) | ||
const classes = computed(() => [props.size]) | ||
function getButtonClasses(button: ButtonGroupItem) { | ||
return [ | ||
{ active: button.value === props.modelValue }, | ||
button.mode ?? 'neutral' | ||
] | ||
} | ||
function handleClick(value: string) { | ||
emit('update:modelValue', value) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="SButtonGroup" :class="classes"> | ||
<button | ||
v-for="item in items" | ||
:key="item.value" | ||
class="button" | ||
:class="getButtonClasses(item)" | ||
@click="handleClick(item.value)" | ||
> | ||
<span class="content"> | ||
{{ item.label }} | ||
</span> | ||
</button> | ||
<div class="SButtonGroup"> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<style lang="postcss" scoped> | ||
.SButtonGroup { | ||
display: flex; | ||
width: fit-content; | ||
border: 1px solid var(--c-divider); | ||
border-radius: 4px; | ||
overflow: hidden; | ||
} | ||
.SButtonGroup.mini { | ||
height: 28px; | ||
.button { | ||
padding: 0 8px; | ||
height: 28px; | ||
font-size: 12px; | ||
font-weight: 500; | ||
} | ||
} | ||
.SButtonGroup.small { | ||
height: 32px; | ||
.button { | ||
padding: 0 10px; | ||
height: 32px; | ||
font-size: 12px; | ||
font-weight: 500; | ||
} | ||
} | ||
.SButtonGroup.medium { | ||
height: 40px; | ||
.button { | ||
padding: 0 12px; | ||
height: 40px; | ||
font-size: 13px; | ||
font-weight: 500; | ||
} | ||
} | ||
.SButtonGroup.large { | ||
height: 48px; | ||
.button { | ||
padding: 0 14px; | ||
height: 48px; | ||
font-size: 14px; | ||
font-weight: 500; | ||
} | ||
} | ||
.SButtonGroup.jumbo { | ||
height: 64px; | ||
.button { | ||
padding: 0 24px; | ||
height: 64px; | ||
font-size: 14px; | ||
font-weight: 500; | ||
} | ||
} | ||
.button { | ||
border-left: 1px solid transparent; | ||
letter-spacing: .4px; | ||
color: var(--c-text-2); | ||
white-space: nowrap; | ||
transition: color .25s, background-color .25s; | ||
&:hover { | ||
color: var(--c-text-1); | ||
} | ||
} | ||
.button:not(:first-child) { | ||
border-left: 1px solid var(--c-divider); | ||
} | ||
.button.active { | ||
color: var(--c-text-dark-1); | ||
} | ||
<style scoped lang="postcss"> | ||
.SButtonGroup :slotted(.SButton) { | ||
border-left-width: 0; | ||
border-radius: 0; | ||
.button.neutral.active { background-color: var(--c-black); } | ||
.button.info.active { background-color: var(--c-info); } | ||
.button.success.active { background-color: var(--c-success); } | ||
.button.warning.active { background-color: var(--c-warning); } | ||
.button.danger.active { background-color: var(--c-danger); } | ||
&:first-child { border-left-width: 1px; } | ||
.content { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 100%; | ||
height: 100%; | ||
&:first-child { border-radius: 6px 0 0 6px; } | ||
&:last-child { border-radius: 0 6px 6px 0; } | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,69 @@ | ||
<script setup lang="ts"> | ||
import SButtonGroup, { ButtonGroupItem } from 'sefirot/components/SButtonGroup.vue' | ||
import { ref } from 'vue' | ||
import SButton, { Mode, Size } from 'sefirot/components/SButton.vue' | ||
import SButtonGroup from 'sefirot/components/SButtonGroup.vue' | ||
const value = ref('button-a') | ||
const items: ButtonGroupItem[] = [ | ||
{ label: 'Button A', value: 'button-a' }, | ||
{ label: 'Button B', value: 'button-b' }, | ||
{ label: 'Button C', value: 'button-c' } | ||
] | ||
function state() { | ||
return { | ||
size: 'medium' as Size, | ||
mode: 'mute' as Mode, | ||
labelA: 'Left', | ||
labelB: 'Middle', | ||
labelC: 'Right' | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<Board | ||
title="Components / SButtonGroup / 01. Playground" | ||
docs="/components/button-group" | ||
:state="state" | ||
> | ||
<SButtonGroup :items="items" v-model="value" /> | ||
<template #controls="{ state }"> | ||
<HstSelect | ||
title="size" | ||
:options="{ | ||
mini: 'mini', | ||
small: 'small', | ||
medium: 'medium', | ||
large: 'large', | ||
jumbo: 'jumbo' | ||
}" | ||
v-model="state.size" | ||
/> | ||
<HstSelect | ||
title="mode" | ||
:options="{ | ||
neutral: 'neutral', | ||
mute: 'mute', | ||
white: 'white', | ||
black: 'black', | ||
info: 'info', | ||
success: 'success', | ||
warning: 'warning', | ||
danger: 'danger' | ||
}" | ||
v-model="state.mode" | ||
/> | ||
<HstText | ||
title="label a" | ||
v-model="state.labelA" | ||
/> | ||
<HstText | ||
title="label b" | ||
v-model="state.labelB" | ||
/> | ||
<HstText | ||
title="label c" | ||
v-model="state.labelC" | ||
/> | ||
</template> | ||
<template #default="{ state }"> | ||
<SButtonGroup> | ||
<SButton :size="state.size" :mode="state.mode" :label="state.labelA" /> | ||
<SButton :size="state.size" :mode="state.mode" :label="state.labelB" /> | ||
<SButton :size="state.size" :mode="state.mode" :label="state.labelC" /> | ||
</SButtonGroup> | ||
</template> | ||
</Board> | ||
</template> |
Oops, something went wrong.