From f32dbb9de5cce9d1ce2c7bf50be4b00850691a83 Mon Sep 17 00:00:00 2001
From: Joshua Graber <68428039+joshuagraber@users.noreply.github.com>
Date: Tue, 15 Oct 2024 10:39:02 -0400
Subject: [PATCH] feat(components): add textarea input (#111)
---
.../FormV2/__snapshots__/formv2.spec.ts.snap | 20 ++++++++
src/components/FormV2/formv2.spec.ts | 17 +++++++
.../InputTextArea/PdapInputTextArea.vue | 48 +++++++++++++++++++
src/components/InputTextArea/index.ts | 1 +
src/components/InputTextArea/types.ts | 6 +++
src/demo/pages/FormV2Demo.vue | 18 +++++++
src/styles/components.css | 18 +++++--
7 files changed, 124 insertions(+), 4 deletions(-)
create mode 100644 src/components/InputTextArea/PdapInputTextArea.vue
create mode 100644 src/components/InputTextArea/index.ts
create mode 100644 src/components/InputTextArea/types.ts
diff --git a/src/components/FormV2/__snapshots__/formv2.spec.ts.snap b/src/components/FormV2/__snapshots__/formv2.spec.ts.snap
index 096aa7d..511338a 100644
--- a/src/components/FormV2/__snapshots__/formv2.spec.ts.snap
+++ b/src/components/FormV2/__snapshots__/formv2.spec.ts.snap
@@ -30,6 +30,11 @@ exports[`PdapFormV2 > calls submit event with form values on valid submission 1`
+
+
+
+
+
`;
@@ -63,6 +68,11 @@ exports[`PdapFormV2 > renders default error message when form has errors 1`] = `
+
`;
@@ -102,6 +112,11 @@ exports[`PdapFormV2 > renders error message when errorMessage prop is provided 1
+
+
+
+
+
`;
@@ -135,5 +150,10 @@ exports[`PdapFormV2 > renders the form element 1`] = `
+
+
+
+
+
`;
diff --git a/src/components/FormV2/formv2.spec.ts b/src/components/FormV2/formv2.spec.ts
index bd46453..10738f1 100644
--- a/src/components/FormV2/formv2.spec.ts
+++ b/src/components/FormV2/formv2.spec.ts
@@ -5,6 +5,7 @@ import PdapFormV2 from './PdapFormV2.vue';
import InputCheckbox from '../InputCheckbox/PdapInputCheckbox.vue';
import InputText from '../InputText/PdapInputText.vue';
import InputPassword from '../InputPassword/PdapInputPassword.vue';
+import InputTextArea from '../InputTextArea/PdapInputTextArea.vue';
vi.mock('vue-router');
vi.mock('vue', async () => {
@@ -46,6 +47,7 @@ const BASE_CONFIG = {
email: '',
password: '',
'ice-cream': false,
+ notes: '',
},
schema: [
{
@@ -69,6 +71,12 @@ const BASE_CONFIG = {
password: { value: true, message: 'Password is too weak' },
},
},
+ {
+ name: 'notes',
+ validators: {
+ required: { value: true, message: 'Notes are required' },
+ },
+ },
],
id: 'test',
name: 'test',
@@ -101,6 +109,12 @@ const BASE_CONFIG = {
name="ice-cream"
label="Ice Cream"
:defaultChecked="false"
+ />
+
`,
},
@@ -109,6 +123,7 @@ const BASE_CONFIG = {
InputCheckbox,
InputText,
InputPassword,
+ InputTextArea,
},
},
};
@@ -164,6 +179,7 @@ describe('PdapFormV2', () => {
await form.find('input[name="email"]').setValue('john@example.com');
await form.find('input[name="password"]').setValue('Password123!');
await form.find('input[name="ice-cream"]').setChecked();
+ await form.find('textarea[name="notes"]').setValue('This is a note');
await form.trigger('submit');
await wrapper.vm.$forceUpdate();
@@ -175,6 +191,7 @@ describe('PdapFormV2', () => {
email: 'john@example.com',
password: 'Password123!',
'ice-cream': true,
+ notes: 'This is a note',
},
expect.any(Event)
);
diff --git a/src/components/InputTextArea/PdapInputTextArea.vue b/src/components/InputTextArea/PdapInputTextArea.vue
new file mode 100644
index 0000000..3867186
--- /dev/null
+++ b/src/components/InputTextArea/PdapInputTextArea.vue
@@ -0,0 +1,48 @@
+
+
+
+
+
diff --git a/src/components/InputTextArea/index.ts b/src/components/InputTextArea/index.ts
new file mode 100644
index 0000000..de92cf5
--- /dev/null
+++ b/src/components/InputTextArea/index.ts
@@ -0,0 +1 @@
+export { default as InputTextArea } from './PdapInputTextArea.vue';
diff --git a/src/components/InputTextArea/types.ts b/src/components/InputTextArea/types.ts
new file mode 100644
index 0000000..5524af8
--- /dev/null
+++ b/src/components/InputTextArea/types.ts
@@ -0,0 +1,6 @@
+export interface PdapInputTextAreaProps {
+ id: string;
+ label?: string;
+ name: string;
+ placeholder?: string;
+}
diff --git a/src/demo/pages/FormV2Demo.vue b/src/demo/pages/FormV2Demo.vue
index 0a4ace3..243b861 100644
--- a/src/demo/pages/FormV2Demo.vue
+++ b/src/demo/pages/FormV2Demo.vue
@@ -52,6 +52,13 @@
+
+
@@ -64,12 +71,14 @@ import { InputText } from '../../components/InputText';
import { InputCheckbox } from '../../components/InputCheckbox';
import { InputPassword } from '../../components/InputPassword';
import { InputSelect } from '../../components/InputSelect';
+import PdapInputTextArea from '../../components/InputTextArea/PdapInputTextArea.vue';
const INPUT_CHECKBOX_NAME = 'ice-cream';
const INPUT_TEXT_PLACEHOLDER = 'Paul';
const INPUT_TEXT_NAME = 'first-name';
const INPUT_PASSWORD_NAME = 'password';
const INPUT_SELECT_NAME = 'flavors';
+const INPUT_TEXT_AREA_NAME = 'notes';
const ICE_CREAM_FLAVORS = [
{
@@ -128,6 +137,15 @@ const SCHEMA = [
},
},
},
+ // {
+ // name: INPUT_TEXT_AREA_NAME,
+ // validators: {
+ // required: {
+ // message: 'Please add some notes.',
+ // value: true,
+ // },
+ // },
+ // },
];
diff --git a/src/styles/components.css b/src/styles/components.css
index 19642a1..137ff26 100644
--- a/src/styles/components.css
+++ b/src/styles/components.css
@@ -41,17 +41,22 @@
@apply h-[max-content] gap-1 leading-normal mb-3 w-full flex flex-col;
}
- .pdap-input input {
+ .pdap-input input,
+ .pdap-input textarea {
@apply dark:bg-neutral-950 border border-neutral-500 border-solid px-3 py-2 text-[rgba(0,0,0)];
}
- .pdap-input input::placeholder {
+ .pdap-input input::placeholder,
+ .pdap-input textarea::placeholder{
@apply text-neutral-600 text-lg;
}
.pdap-input input:focus,
.pdap-input input:focus-within,
- .pdap-input input:focus-visible {
+ .pdap-input input:focus-visible,
+ .pdap-input textarea:focus,
+ .pdap-input textarea:focus-within,
+ .pdap-input textarea:focus-visible {
@apply border-2 border-blue-light border-solid outline-none;
}
@@ -69,7 +74,8 @@
}
.pdap-input-error input,
- .pdap-input-error div[role="combobox"] {
+ .pdap-input-error div[role="combobox"],
+ .pdap-input-error textarea {
@apply border-red-800 dark:border-red-300;
}
@@ -106,4 +112,8 @@
@apply cursor-pointer;
}
+ /* Text area */
+ .pdap-input textarea {
+ @apply text-lg;
+ }
}
\ No newline at end of file