Skip to content

Commit

Permalink
Add LinkButton
Browse files Browse the repository at this point in the history
  • Loading branch information
happylifetaka committed Mar 15, 2024
1 parent 1c884a5 commit fcb82b4
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/ui/components/LinkButton.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { StoryFn } from '@storybook/vue3'
import LinkButton from './LinkButton.vue'

export default {
title: 'LinkButton',
component: LinkButton,
args: {
title: 'button',
backgroundColor: 'vue-green',
color: 'white',
href: 'https://example.com',
},
}

const Template: StoryFn<unknown> = (args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { LinkButton },
setup() {
return { args }
},
template: `<div style="width: 400px;">
<LinkButton v-bind="args">{{ args.title }}</LinkButton>
</div>`,
})

export const Default = Template.bind({})

export const TargetBlank = Template.bind({})
TargetBlank.args = {
target:'_blank'
}
70 changes: 70 additions & 0 deletions packages/ui/components/LinkButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<script setup lang="ts">
import { ButtonHTMLAttributes,ref,computed } from 'vue'
import CssResetButton from './CssResetButton.vue'
import type { Color as ColorType } from '@vuejs-jp/model'
import { useColor } from '@vuejs-jp/composable'
type _LinkButtonProps = Omit<ButtonHTMLAttributes, 'onClick'>
interface LinkButtonProps extends /* @vue-ignore */ _LinkButtonProps {
backgroundColor: ColorType
color: ColorType
href: string
target: string
}
const props = defineProps<LinkButtonProps>()
const { color } = useColor()

Check warning on line 16 in packages/ui/components/LinkButton.vue

View workflow job for this annotation

GitHub Actions / lint (18.19.0)

Duplicate key 'color'. May cause name collision in script or template tag
const hover = ref(false)
const hoverIn = () => {
hover.value = true
}
const hoverOut = () => {
hover.value = false
}
const style = computed(() =>{
if (hover.value){
return {
color: color(props.backgroundColor),
backgroundColor: color(props.color),
borderSize:'1px',
borderColor:props.backgroundColor
}
}
return {
backgroundColor: color(props.backgroundColor),
color: color(props.color)
}
})
</script>

<template>
<a :href="props.href" :target="target" @mouseover="hoverIn" @mouseleave="hoverOut" @focus="{}" @blur="{}">
<CssResetButton
type="button"
:style="style"
class="link-button"
v-bind="props">
<slot />
</CssResetButton>
</a>
</template>

<style scoped>
.link-button {
display: inline-flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 100%;
padding: 22px 66px;
border-radius: 40px;
font-weight: bold;
font-size: 20px;
cursor: pointer;
border-style: solid;
}
.link-button:hover {
transition: .2s;
}
</style>

0 comments on commit fcb82b4

Please sign in to comment.