From 7569ca63be261deefe59998f9fc490a9ed0cd018 Mon Sep 17 00:00:00 2001 From: Vasu Singh Date: Tue, 11 Jul 2023 00:12:06 +0530 Subject: [PATCH] feat(component): New component textarea --- docs/.vitepress/config.ts | 1 + docs/components/textarea.md | 65 +++++++++++++++++++ .../textarea/examples/CommentTextarea.vue | 27 ++++++++ .../textarea/examples/DefaultTextarea.vue | 12 ++++ src/components/Textarea/Textarea.vue | 49 ++++++++++++++ .../composables/useTextareaClasses.ts | 33 ++++++++++ src/index.ts | 2 + 7 files changed, 189 insertions(+) create mode 100644 docs/components/textarea.md create mode 100644 docs/components/textarea/examples/CommentTextarea.vue create mode 100644 docs/components/textarea/examples/DefaultTextarea.vue create mode 100644 src/components/Textarea/Textarea.vue create mode 100644 src/components/Textarea/composables/useTextareaClasses.ts diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 3deff50..f9b2d9e 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -68,6 +68,7 @@ function getFormComponents() { { text: 'Checkbox', link: 'components/checkbox' }, { text: 'Select', link: 'components/select' }, { text: 'Toggle', link: 'components/toggle' }, + { text: 'Textarea', link: 'components/textarea' }, { text: 'Range', link: 'components/range' }, { text: 'Radio', link: 'components/radio' }, ] diff --git a/docs/components/textarea.md b/docs/components/textarea.md new file mode 100644 index 0000000..e7c010c --- /dev/null +++ b/docs/components/textarea.md @@ -0,0 +1,65 @@ + + +# Vue Textarea - Flowbite + +#### Use the textarea component as a multi-line text field input and use it inside form elements available in multiple sizes, styles, and variants + +--- + +:::tip +Original reference: [https://flowbite.com/docs/forms/textarea/](https://flowbite.com/docs/forms/textarea/) +::: + +## Textarea example + +Get started with the default example of a textarea component below. + +```vue + + + +``` + + diff --git a/docs/components/textarea/examples/CommentTextarea.vue b/docs/components/textarea/examples/CommentTextarea.vue new file mode 100644 index 0000000..08d5fe2 --- /dev/null +++ b/docs/components/textarea/examples/CommentTextarea.vue @@ -0,0 +1,27 @@ + + + diff --git a/docs/components/textarea/examples/DefaultTextarea.vue b/docs/components/textarea/examples/DefaultTextarea.vue new file mode 100644 index 0000000..f42924d --- /dev/null +++ b/docs/components/textarea/examples/DefaultTextarea.vue @@ -0,0 +1,12 @@ + + + diff --git a/src/components/Textarea/composables/useTextareaClasses.ts b/src/components/Textarea/composables/useTextareaClasses.ts new file mode 100644 index 0000000..70fe3d3 --- /dev/null +++ b/src/components/Textarea/composables/useTextareaClasses.ts @@ -0,0 +1,33 @@ +import { simplifyTailwindClasses } from '@/utils/simplifyTailwindClasses' +import { computed } from 'vue' + +const textareaWrapperClasses = 'w-full mb-4 border border-gray-200 rounded-lg bg-gray-50 dark:bg-gray-700 dark:border-gray-600' +const textareaDefaultClasses = 'block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-200 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500' +const textareaLabelClasses = 'block mb-2 text-sm font-medium text-gray-900 dark:text-white' +const textareaFooterClasses = 'py-2 px-3 border-gray-200 dark:border-gray-600' + +export function useTextareaClasses(custom: boolean) { + const textareaClasses = computed(() => { + return simplifyTailwindClasses(textareaDefaultClasses, custom? 'bg-white dark:bg-gray-800 border-none': 'border') + }) + + const labelClasses = computed(() => { + return textareaLabelClasses + }) + + const wrapperClasses = computed(() => { + if(custom) return textareaWrapperClasses + return '' + }) + + const footerClasses = computed(() => { + return textareaFooterClasses + }) + + return { + textareaClasses, + labelClasses, + wrapperClasses, + footerClasses, + } +} diff --git a/src/index.ts b/src/index.ts index 7f63749..fd75ae9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,4 +62,6 @@ export { default as Range } from './components/Range/Range.vue' export { default as Radio } from './components/Radio/Radio.vue' +export { default as Textarea } from './components/Textarea/Textarea.vue' + export * from './composables'