2022-04-09 14:56:52 +00:00
|
|
|
<template>
|
|
|
|
<button type="button" :class="classes" @click="onClick" :style="style">{{ label }}</button>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-09 17:15:46 +00:00
|
|
|
import './button.css'
|
|
|
|
import { reactive, computed } from 'vue'
|
2022-04-09 14:56:52 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'my-button',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
primary: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
validator: function (value) {
|
2022-04-09 17:15:46 +00:00
|
|
|
return ['small', 'medium', 'large'].indexOf(value) !== -1
|
2022-04-09 14:56:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
backgroundColor: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
emits: ['click'],
|
|
|
|
|
|
|
|
setup(props, { emit }) {
|
2022-04-09 17:15:46 +00:00
|
|
|
props = reactive(props)
|
2022-04-09 14:56:52 +00:00
|
|
|
return {
|
|
|
|
classes: computed(() => ({
|
|
|
|
'storybook-button': true,
|
|
|
|
'storybook-button--primary': props.primary,
|
|
|
|
'storybook-button--secondary': !props.primary,
|
|
|
|
[`storybook-button--${props.size || 'medium'}`]: true,
|
|
|
|
})),
|
|
|
|
style: computed(() => ({
|
|
|
|
backgroundColor: props.backgroundColor,
|
|
|
|
})),
|
|
|
|
onClick() {
|
2022-04-09 17:15:46 +00:00
|
|
|
emit('click')
|
|
|
|
},
|
2022-04-09 14:56:52 +00:00
|
|
|
}
|
|
|
|
},
|
2022-04-09 17:15:46 +00:00
|
|
|
}
|
2022-04-09 14:56:52 +00:00
|
|
|
</script>
|