-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): add textarea input (#111)
- Loading branch information
1 parent
ad35c57
commit f32dbb9
Showing
7 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<template> | ||
<div class="pdap-input" :class="{ ['pdap-input-error']: error }"> | ||
<label v-if="$slots.label" :for="id"><slot name="label" /></label> | ||
<label v-else-if="label" :for="id">{{ label }}</label> | ||
<div v-if="$slots.error && error" class="pdap-input-error-message"> | ||
<slot name="error" /> | ||
</div> | ||
<div v-else-if="error" class="pdap-input-error-message">{{ error }}</div> | ||
|
||
<textarea | ||
:id="id" | ||
:name="name" | ||
:placeholder="placeholder" | ||
:value="String(value)" | ||
v-bind="$attrs" | ||
type="text" | ||
@input="onInput" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, inject, useSlots } from 'vue'; | ||
import { PdapInputTextAreaProps } from './types'; | ||
import { PdapFormProvideV2 } from '../FormV2/types'; | ||
import { provideKey } from '../FormV2/util'; | ||
const { label, name } = withDefaults(defineProps<PdapInputTextAreaProps>(), { | ||
placeholder: 'Enter text here', | ||
}); | ||
const slots = useSlots(); | ||
if (!slots.label && !label) | ||
throw new Error( | ||
'All form inputs must have a label, passed as a slot or a prop' | ||
); | ||
const { values, setValues, v$ } = inject<PdapFormProvideV2>(provideKey)!; | ||
const error = computed(() => { | ||
return v$.value[name]?.$error ? v$.value[name]?.$errors?.[0]?.$message : ''; | ||
}); | ||
const value = computed(() => values.value[name] ?? ''); | ||
function onInput(e: Event) { | ||
setValues({ [name]: (e.target as unknown as HTMLInputElement).value }); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as InputTextArea } from './PdapInputTextArea.vue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface PdapInputTextAreaProps { | ||
id: string; | ||
label?: string; | ||
name: string; | ||
placeholder?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters