Feat: Add disabled option on select and buttons

This commit is contained in:
jhynsoo 2024-05-20 10:44:23 +09:00
parent ceed039a80
commit 4ad8f97e6b
3 changed files with 27 additions and 9 deletions

View File

@ -8,11 +8,15 @@ const { type, primary } = defineProps({
type: Boolean,
default: false,
},
disabled: {
type: Boolean,
default: false,
},
});
</script>
<template>
<button :type="type" :class="primary ? 'primary' : ''">
<button :disabled="disabled" :type="type" :class="primary ? 'primary' : ''">
<slot></slot>
</button>
</template>
@ -31,6 +35,10 @@ button {
transform 0.25s;
}
button:disabled {
cursor: initial;
}
button.primary {
background-color: var(--color-primary);
color: var(--color-background);
@ -46,10 +54,6 @@ button.primary {
}
}
button:active {
transform: scale(0.95);
}
button.primary:active {
background-color: var(--color-primary-soft);
}

View File

@ -3,7 +3,7 @@
import { computed, onMounted, ref } from 'vue';
import FilledButton from './FilledButton.vue';
const { placeholder, options, optionName } = defineProps({
const { placeholder, options, optionName, disabled } = defineProps({
placeholder: {
type: String,
default: '----',
@ -16,7 +16,16 @@ const { placeholder, options, optionName } = defineProps({
type: String,
default: 'value',
},
modelValue: {
sidoCode: Number,
},
disabled: {
type: Boolean,
default: false,
},
});
const updateModel = defineEmits(['update:modelValue']);
const body = document.querySelector('body');
const buttonRef = ref(null);
const isOpen = ref(false);
@ -32,7 +41,6 @@ onMounted(() => {
const selectedName = computed(() => selected.value?.[optionName] ?? selected.value);
function handleOpen() {
console.log('open');
isOpen.value = true;
body.style.pointerEvents = 'none';
body.style.overflow = 'hidden';
@ -53,12 +61,14 @@ function handleClose({ target }) {
function handleSelect(option) {
selected.value = option;
updateModel('update:modelValue', option);
closeMenu();
}
</script>
<template>
<FilledButton
:disabled="disabled"
:class="'select' + (isOpen ? ' active' : '')"
ref="buttonRef"
@mousedown="handleOpen"

View File

@ -8,11 +8,15 @@ const { type, primary } = defineProps({
type: Boolean,
default: false,
},
disabled: {
type: Boolean,
default: false,
},
});
</script>
<template>
<button :type="type" :class="primary ? 'primary' : ''">
<button :disabled="disabled" :type="type" :class="primary ? 'primary' : ''">
<slot></slot>
</button>
</template>