Skip to content

Commit

Permalink
Merge pull request #181 from pateljannat/textarea-label
Browse files Browse the repository at this point in the history
feat: label in textarea
  • Loading branch information
pateljannat authored Sep 11, 2024
2 parents 4f168d8 + d2ca6f9 commit 6801d65
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/components/Textarea.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<template>
<textarea
:placeholder="placeholder"
:class="inputClasses"
:disabled="disabled"
:id="id"
:value="modelValue"
:rows="rows"
@input="handleChange"
@change="handleChange"
v-bind="attrs"
/>
<div class="space-y-1.5">
<label class="block" :class="labelClasses" v-if="label" :for="id">
{{ label }}
</label>
<textarea
:placeholder="placeholder"
:class="inputClasses"
:disabled="disabled"
:id="id"
:value="modelValue"
:rows="rows"
@input="handleChange"
@change="handleChange"
v-bind="attrs"
/>
</div>
</template>

<script setup lang="ts">
Expand All @@ -26,6 +31,7 @@ interface TextareaProps {
modelValue?: string
debounce?: number
rows?: number
label?: string
}
const props = withDefaults(defineProps<TextareaProps>(), {
Expand All @@ -52,7 +58,7 @@ const inputClasses = computed(() => {
lg: ['py-1.5 px-3'],
xl: ['py-1.5 px-3'],
}[props.size]
let variant = props.disabled ? 'disabled' : props.variant
let variantClasses = {
subtle:
Expand All @@ -74,6 +80,18 @@ const inputClasses = computed(() => {
]
})
const labelClasses = computed(() => {
return [
{
sm: 'text-xs',
md: 'text-base',
lg: 'text-lg',
xl: 'text-xl',
}[props.size],
'text-gray-600',
]
})
let emitChange = (value: string) => {
emit('update:modelValue', value)
}
Expand Down

0 comments on commit 6801d65

Please sign in to comment.