-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Guillaume Chau <guillaume.b.chau@gmail.com>
- Loading branch information
Showing
10 changed files
with
198 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ a { | |
text-decoration: inherit; | ||
} | ||
|
||
input { | ||
input, button { | ||
font-family: inherit; | ||
} | ||
|
||
|
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
30 changes: 30 additions & 0 deletions
30
packages/histoire-controls/src/components/button/HstButton.story.vue
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,30 @@ | ||
<script lang="ts" setup> | ||
import HstButton from './HstButton.vue' | ||
const variants: Array<{name: string, bind?: unknown}> = [ | ||
{ name: 'Default' }, | ||
{ name: 'Primary', bind: { color: 'primary' } }, | ||
{ name: 'Flat', bind: { color: 'flat' } }, | ||
] | ||
</script> | ||
|
||
<template> | ||
<Story | ||
title="HstButton" | ||
group="controls" | ||
:layout="{ type: 'grid', width: '200px', iframe: false }" | ||
> | ||
<Variant | ||
v-for="(variant, key) of variants" | ||
:key="key" | ||
:title="variant.name" | ||
> | ||
<HstButton | ||
v-bind="variant.bind" | ||
class="htw-p-2" | ||
> | ||
Click me! | ||
</HstButton> | ||
</Variant> | ||
</Story> | ||
</template> |
26 changes: 26 additions & 0 deletions
26
packages/histoire-controls/src/components/button/HstButton.vue
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,26 @@ | ||
<script lang="ts"> | ||
export default { | ||
name: 'HstButton', | ||
} | ||
</script> | ||
|
||
<script setup lang="ts"> | ||
const colors = { | ||
default: 'htw-bg-gray-200 dark:htw-bg-gray-750 htw-text-gray-900 dark:htw-text-gray-100 hover:htw-bg-primary-200 dark:hover:htw-bg-primary-900', | ||
primary: 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black', | ||
flat: 'htw-bg-transparent hover:htw-bg-gray-500/20 htw-text-gray-900 dark:htw-text-gray-100', | ||
} | ||
defineProps<{ | ||
color?: keyof typeof colors | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<button | ||
class="htw-cursor-pointer htw-rounded-sm" | ||
:class="colors[color ?? 'default']" | ||
> | ||
<slot /> | ||
</button> | ||
</template> |
51 changes: 51 additions & 0 deletions
51
packages/histoire-controls/src/components/button/HstButtonGroup.story.vue
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,51 @@ | ||
<script lang="ts" setup> | ||
import HstButtonGroup from './HstButtonGroup.vue' | ||
const options = { | ||
slow: 'Slow', | ||
fast: 'Fast', | ||
max: 'Max', | ||
} | ||
const flatOptions = Object.keys(options) | ||
const objectOptions = Object.keys(options).map(key => ({ | ||
label: options[key], | ||
value: key, | ||
})) | ||
function initState () { | ||
return { | ||
speed: flatOptions[0], | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<Story | ||
title="HstButtonGroup" | ||
group="controls" | ||
:layout="{ type: 'single', iframe: false }" | ||
> | ||
<Variant | ||
title="playground" | ||
:init-state="initState" | ||
> | ||
<template #default="{ state }"> | ||
<HstButtonGroup | ||
v-model="state.speed" | ||
title="Label" | ||
:options="objectOptions" | ||
/> | ||
</template> | ||
|
||
<template #controls="{ state }"> | ||
<HstButtonGroup | ||
v-model="state.speed" | ||
title="Label" | ||
:options="objectOptions" | ||
/> | ||
</template> | ||
</Variant> | ||
</Story> | ||
</template> |
64 changes: 64 additions & 0 deletions
64
packages/histoire-controls/src/components/button/HstButtonGroup.vue
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,64 @@ | ||
<script lang="ts"> | ||
export default { | ||
name: 'HstButtonGroup', | ||
} | ||
</script> | ||
|
||
<script setup lang="ts"> | ||
import { computed, ComputedRef } from 'vue' | ||
import HstWrapper from '../HstWrapper.vue' | ||
import { HstControlOption } from '../../types' | ||
import HstButton from './HstButton.vue' | ||
const props = defineProps<{ | ||
title?: string | ||
modelValue: string | ||
options: HstControlOption[] | ||
}>() | ||
const formattedOptions: ComputedRef<Record<string, string>> = computed(() => { | ||
if (Array.isArray(props.options)) { | ||
return Object.fromEntries(props.options.map((value: string | HstControlOption) => { | ||
if (typeof value === 'string') { | ||
return [value, value] | ||
} else { | ||
return [value.value, value.label] | ||
} | ||
})) | ||
} | ||
return props.options | ||
}) | ||
const emit = defineEmits<{ | ||
(e: 'update:modelValue', value: string): void | ||
}>() | ||
function selectOption (value: string) { | ||
emit('update:modelValue', value) | ||
} | ||
</script> | ||
|
||
<template> | ||
<HstWrapper | ||
tag="div" | ||
role="group" | ||
:title="title" | ||
class="htw-flex-nowrap htw-items-center" | ||
> | ||
<div class="htw-flex htw-gap-px htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 htw-rounded-sm htw-p-px"> | ||
<HstButton | ||
v-for="( label, value ) in formattedOptions" | ||
:key="value" | ||
class="htw-px-1 htw-h-[22px] htw-flex-1 !htw-rounded-[3px]" | ||
:color="value === modelValue ? 'primary' : 'flat'" | ||
:rounded="false" | ||
@click="selectOption(value)" | ||
> | ||
{{ label }} | ||
</HstButton> | ||
</div> | ||
<template #actions> | ||
<slot name="actions" /> | ||
</template> | ||
</HstWrapper> | ||
</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
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