Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button に文字列以外も入れられるようにする #132

Open
TwoSquirrels opened this issue Feb 19, 2025 · 0 comments
Open

Button に文字列以外も入れられるようにする #132

TwoSquirrels opened this issue Feb 19, 2025 · 0 comments

Comments

@TwoSquirrels
Copy link
Member

現在の各種 Button の実装だと、中身に文字列以外 (アイコンなど) を入れることができません。

<script setup lang="ts">
const { disabled = false } = defineProps<{
disabled?: boolean
text: string
padding?: string
}>()
const emit = defineEmits(['click'])
function onClick() {
emit('click')
}
</script>
<template>
<button
:disabled="disabled"
class="fontstyle-ui-control-strong inline-block h-9 rounded border border-brand-primary bg-brand-primary px-6 text-white enabled:hover:border-brand-secondary enabled:hover:bg-brand-secondary disabled:opacity-50"
:style="{ paddingLeft: padding, paddingRight: padding }"
@click="onClick"
>
{{ text }}
</button>
</template>

text を props で受け取る代わりに slot を用いることで中身の自由度を上げられ、汎用性を向上できます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant