-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(#228): Implement KtFieldEmail
- Loading branch information
1 parent
aeb16da
commit 8eb3acb
Showing
8 changed files
with
132 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
76 changes: 76 additions & 0 deletions
76
packages/kotti-ui/source/kotti-field-email/KtFieldEmail.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,76 @@ | ||
<template> | ||
<KtField | ||
v-bind="{ field }" | ||
:getEmptyValue="() => null" | ||
:helpTextSlot="$slots.helpText" | ||
> | ||
<input v-bind="inputProps" @input="onInput" /> | ||
</KtField> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, computed } from '@vue/composition-api' | ||
import { KtField } from '../kotti-field' | ||
import { KOTTI_FIELD_PROPS } from '../kotti-field/constants' | ||
import { useField, useForceUpdate } from '../kotti-field/hooks' | ||
import { KOTTI_FIELD_EMAIL_SUPPORTS } from './constants' | ||
import { KottiFieldEmail } from './types' | ||
export default defineComponent({ | ||
name: 'KtFieldEmail', | ||
components: { KtField }, | ||
props: { | ||
...KOTTI_FIELD_PROPS, | ||
value: { default: null, type: String }, | ||
}, | ||
setup(props: KottiFieldEmail.Props, { emit }) { | ||
const field = useField<KottiFieldEmail.Value, string | null>({ | ||
emit, | ||
isCorrectDataType: (value): value is KottiFieldEmail.Value => | ||
typeof value === 'string' || value === null, | ||
isEmpty: (value) => value === null, | ||
props, | ||
supports: KOTTI_FIELD_EMAIL_SUPPORTS, | ||
}) | ||
const { forceUpdate, forceUpdateKey } = useForceUpdate() | ||
return { | ||
field, | ||
inputProps: computed( | ||
(): Partial<HTMLInputElement> & { | ||
class: object | ||
forceUpdateKey: number | ||
} => ({ | ||
...field.inputProps, | ||
class: ['kt-field-email__wrapper'], | ||
forceUpdateKey: forceUpdateKey.value, | ||
type: 'email', | ||
size: 1, | ||
value: field.currentValue ?? '', | ||
placeholder: props.placeholder ?? undefined, | ||
}), | ||
), | ||
onInput: (event: { target: HTMLInputElement }) => { | ||
const newValue = event.target.value | ||
field.setValue(newValue === '' ? null : newValue) | ||
forceUpdate() | ||
}, | ||
} | ||
}, | ||
}) | ||
</script> | ||
|
||
<style lang="scss"> | ||
.kt-field-email__wrapper { | ||
display: flex; | ||
width: 100%; | ||
padding: 0; | ||
margin: 0; | ||
line-height: 1.6; | ||
border: 0; | ||
} | ||
</style> |
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,8 @@ | ||
import { KottiField } from '../kotti-field/types' | ||
|
||
export const KOTTI_FIELD_EMAIL_SUPPORTS: KottiField.Supports = { | ||
clear: true, | ||
decoration: true, | ||
placeholder: true, | ||
tabIndex: true, | ||
} |
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,25 @@ | ||
import { FIELD_META_BASE_SLOTS } from '../kotti-field/meta' | ||
import { MetaDesignType } from '../types/kotti' | ||
import { attachMeta, makeInstallable } from '../utilities' | ||
|
||
import { KOTTI_FIELD_EMAIL_SUPPORTS } from './constants' | ||
import KtFieldEmailVue from './KtFieldEmail.vue' | ||
|
||
export const KtFieldEmail = attachMeta( | ||
makeInstallable(KtFieldEmailVue), | ||
{ | ||
addedVersion: '2.0.0', | ||
deprecated: null, | ||
designs: { | ||
type: MetaDesignType.FIGMA, | ||
url: 'https://www.figma.com/file/0yFVivSWXgFf2ddEF92zkf/Kotti-Design-System?node-id=415%3A4', | ||
}, | ||
slots: FIELD_META_BASE_SLOTS, | ||
typeScript: { | ||
namespace: 'Kotti.FieldEmail', | ||
}, | ||
}, | ||
{ supports: KOTTI_FIELD_EMAIL_SUPPORTS }, | ||
) | ||
|
||
export * from './constants' |
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,7 @@ | ||
import { KottiField } from '../kotti-field/types' | ||
|
||
export namespace KottiFieldEmail { | ||
export type Props = KottiField.Props<Value, string | null> | ||
|
||
export type Value = string | null | ||
} |
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