feat: inherit attrs to Textarea + fix Input label color (#245)

* feat: add more attributes to Textarea

* refactor: use `inheritAttrs` option to simplify code

* fix: `Input` label color in dark mode
This commit is contained in:
WangYK
2023-11-21 19:22:25 +08:00
committed by GitHub
parent 67091e1d90
commit a4a717f4e0
7 changed files with 147 additions and 18 deletions

View File

@@ -1,6 +1,8 @@
<script setup> <script setup>
import FwbTextareaExample from './textarea/examples/FwbTextareaExample.vue' import FwbTextareaExample from './textarea/examples/FwbTextareaExample.vue'
import FwbTextareaExampleComment from './textarea/examples/FwbTextareaExampleComment.vue' import FwbTextareaExampleComment from './textarea/examples/FwbTextareaExampleComment.vue'
import FwbTextareaExampleDisabled from './textarea/examples/FwbTextareaExampleDisabled.vue'
import FwbTextareaExampleFormId from './textarea/examples/FwbTextareaExampleFormId.vue'
</script> </script>
# Vue Textarea - Flowbite # Vue Textarea - Flowbite
@@ -24,7 +26,7 @@ Get started with the default example of a textarea component below.
v-model="message" v-model="message"
:rows="4" :rows="4"
label="Your message" label="Your message"
placeholder="Write you message..." placeholder="Write your message..."
/> />
</template> </template>
@@ -50,7 +52,7 @@ Most often the textarea component is used as the main text field input element i
:rows="3" :rows="3"
custom custom
label="Your message" label="Your message"
placeholder="Write you message..." placeholder="Write your message..."
> >
<template #footer> <template #footer>
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
@@ -93,3 +95,55 @@ import { FwbA, FwbButton, FwbTextarea } from 'flowbite-vue'
const message = ref('') const message = ref('')
</script> </script>
``` ```
## Disabled / Readonly Textarea
<fwb-textarea-example-disabled />
```vue
<template>
<div>
<fwb-textarea
v-model="message"
label="Your message"
placeholder="Write your message..."
disabled
/>
<fwb-textarea
v-model="message"
label="Your message"
placeholder="Write your message..."
readonly
/>
</div>
</template>
```
## Textarea with form ID
<fwb-textarea-example-form-id />
```vue
<template>
<div>
<form id="my-form" @submit.prevent="handleSubmit">
<!-- Inside the form -->
<fwb-textarea
v-model="message"
label="Your message"
placeholder="Write your message..."
/>
<fwb-button type="submit">
Submit
</fwb-button>
</form>
<!-- Outside the form -->
<fwb-textarea
v-model="message"
label="Your message"
placeholder="Write your message..."
form="my-form"
required
/>
</div>
</template>
```

View File

@@ -4,7 +4,7 @@
v-model="message" v-model="message"
:rows="4" :rows="4"
label="Your message" label="Your message"
placeholder="Write you message..." placeholder="Write your message..."
/> />
</div> </div>
</template> </template>

View File

@@ -5,7 +5,7 @@
:rows="3" :rows="3"
custom custom
label="Your message" label="Your message"
placeholder="Write you message..." placeholder="Write your message..."
> >
<template #footer> <template #footer>
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
@@ -84,7 +84,10 @@
</fwb-textarea> </fwb-textarea>
<p class="ml-auto text-xs text-gray-500 dark:text-gray-400"> <p class="ml-auto text-xs text-gray-500 dark:text-gray-400">
Remember, contributions to this topic should follow our Remember, contributions to this topic should follow our
<fwb-a href="#"> <fwb-a
class="underline"
href="#"
>
Community Guidelines Community Guidelines
</fwb-a>. </fwb-a>.
</p> </p>

View File

@@ -0,0 +1,36 @@
<template>
<form
class="vp-raw"
@submit.prevent
>
<fwb-textarea
v-model="message"
label="Textarea with minlength 10 and maxlength 20"
minlength="10"
maxlength="20"
required
/>
<fwb-textarea
v-model="message"
label="Disabled textarea"
placeholder="Cannot be edited"
disabled
/>
<fwb-textarea
v-model="message"
label="Readonly textarea"
placeholder="Cannot be edited"
readonly
/>
<fwb-button type="submit">
Validate
</fwb-button>
</form>
</template>
<script setup>
import { ref } from 'vue'
import { FwbButton, FwbTextarea } from '../../../../src/index'
const message = ref('Edit me!')
</script>

View File

@@ -0,0 +1,36 @@
<template>
<div class="flex flex-col gap-y-4">
<form
id="fwb-textarea-example-form-id"
class="vp-raw"
@submit.prevent
>
<fwb-input
v-model="inputMessage"
label="Input inside the form"
placeholder="Write your message..."
/>
<fwb-button
class="mt-2"
type="submit"
>
Validate
</fwb-button>
</form>
<fwb-textarea
v-model="textareaMessage"
label="Textarea outside the form"
form="fwb-textarea-example-form-id"
minlength="20"
required
/>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { FwbButton, FwbInput, FwbTextarea } from '../../../../src/index'
const inputMessage = ref('')
const textareaMessage = ref('')
</script>

View File

@@ -55,7 +55,7 @@ export function useInputClasses (props: UseInputClassesProps): {
? 'text-green-700 dark:text-green-500' ? 'text-green-700 dark:text-green-500'
: vs === validationStatusMap.Error : vs === validationStatusMap.Error
? 'text-red-700 dark:text-red-500' ? 'text-red-700 dark:text-red-500'
: 'text-gray-900 dark:text-gray-300' : 'text-gray-900 dark:text-white'
return twMerge(baseLabelClasses, classByStatus) return twMerge(baseLabelClasses, classByStatus)
}) })

View File

@@ -4,8 +4,9 @@
<span :class="wrapperClasses"> <span :class="wrapperClasses">
<textarea <textarea
v-model="model" v-model="model"
:rows="rows" v-bind="$attrs"
:class="textareaClasses" :class="textareaClasses"
:rows="rows"
:placeholder="placeholder" :placeholder="placeholder"
/> />
<span <span
@@ -23,13 +24,17 @@ import { computed } from 'vue'
import { useTextareaClasses } from './composables/useTextareaClasses' import { useTextareaClasses } from './composables/useTextareaClasses'
interface TextareaProps { interface TextareaProps {
modelValue?: string; modelValue?: string
label?: string; label?: string
rows?: number; rows?: number
custom?: boolean; custom?: boolean
placeholder?: string; placeholder?: string
} }
defineOptions({
inheritAttrs: false,
})
const props = withDefaults(defineProps<TextareaProps>(), { const props = withDefaults(defineProps<TextareaProps>(), {
modelValue: '', modelValue: '',
label: 'Your message', label: 'Your message',
@@ -48,10 +53,5 @@ const model = computed({
}, },
}) })
const { const { textareaClasses, labelClasses, wrapperClasses, footerClasses } = useTextareaClasses(props.custom)
textareaClasses,
labelClasses,
wrapperClasses,
footerClasses,
} = useTextareaClasses(props.custom)
</script> </script>