Skip to content

Commit

Permalink
feat(kt-fields-kt-field-inline-edit): add autoComplete prop
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagoballadares committed Sep 3, 2024
1 parent 0c59f19 commit b1896d9
Show file tree
Hide file tree
Showing 29 changed files with 154 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,23 @@
isOptional
label="helpDescription"
/>
<KtFieldText formKey="helpText" isOptional label="helpText" />
<div class="field-row">
<KtFieldText formKey="helpText" isOptional label="helpText" />
<KtFieldSingleSelect
formKey="autoComplete"
helpText="Support Varies"
isOptional
isUnsorted
label="autoComplete"
:options="autoCompleteOptions"
/>
<KtFieldText
formKey="autoCompleteToken"
helpText="A space-separated <token-list> that describes the meaning of the autocompletion value. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#values"
:isDisabled="settings.autoComplete !== 'token'"
isOptional
label="<token>"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -101,6 +116,8 @@ export default defineComponent({
const getInitialValue = () => ({ fieldValue: null })
const settings = ref<{
autoComplete: Kotti.FieldText.Value
autoCompleteToken: Kotti.FieldText.Value
booleanFlags: {
hideValidation: Kotti.FieldToggle.Value
isDisabled: Kotti.FieldToggle.Value
Expand All @@ -119,6 +136,8 @@ export default defineComponent({
textStyle: Kotti.FieldInlineEdit.TextStyle | null
validation: Kotti.Field.Validation.Result['type'] | null
}>({
autoComplete: null,
autoCompleteToken: null,
booleanFlags: {
hideValidation: false,
isDisabled: false,
Expand All @@ -143,10 +162,21 @@ export default defineComponent({
)
return {
autoCompleteOptions: computed(() => [
...Object.values(Kotti.Field.AutoComplete).map((option) => ({
label: option,
value: option,
})),
{ label: '<token>', value: 'token' },
]),
component: KtFieldInlineEdit,
formValue,
fieldValue: computed(() => formValue.value.fieldValue),
fieldProps: computed(() => ({
autoComplete:
settings.value.autoComplete === 'token'
? settings.value.autoCompleteToken
: settings.value.autoComplete,
dataTest: settings.value.dataTest,
helpDescription: settings.value.helpDescription,
helpText: settings.value.helpText,
Expand Down
89 changes: 70 additions & 19 deletions packages/documentation/pages/usage/components/form-fields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,26 @@
</template>
</KtFieldSingleSelect>
</div>
<div
v-if="componentDefinition.supports.autoComplete"
class="field-row"
>
<KtFieldSingleSelect
formKey="autoComplete"
helpText="Support Varies"
:isOptional="settings.component !== 'KtFieldPassword'"
isUnsorted
label="autoComplete"
:options="autoCompleteOptions"
/>
<KtFieldText
formKey="autoCompleteToken"
helpText="A space-separated <token-list> that describes the meaning of the autocompletion value. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#values"
:isDisabled="settings.autoComplete !== 'token'"
isOptional
label="<token>"
/>
</div>
<KtFormControllerObject
v-if="componentDefinition.additionalProps.length > 0"
formKey="additionalProps"
Expand All @@ -307,17 +327,6 @@
label="actions"
type="switch"
/>
<KtFieldSingleSelect
v-if="
componentDefinition.additionalProps.includes('autoComplete')
"
formKey="autoComplete"
label="autoComplete"
:options="[
{ label: 'current-password', value: 'current-password' },
{ label: 'new-password', value: 'new-password' },
]"
/>
<KtFieldNumber
v-if="
componentDefinition.additionalProps.includes(
Expand Down Expand Up @@ -752,7 +761,7 @@ import {
import { Yoco } from '@3yourmind/yoco'
import { TimeConversion } from '@metatypes/units'
import cloneDeep from 'lodash/cloneDeep.js'
import { computed, defineComponent, ref } from 'vue'
import { computed, defineComponent, ref, watch } from 'vue'
import { useRouter } from '../../../hooks/use-router'
import {
Expand Down Expand Up @@ -890,7 +899,7 @@ const components: Array<{
supports: KtFieldNumber.meta.supports,
},
{
additionalProps: ['autoComplete'],
additionalProps: [],
formKey: 'textValue',
name: 'KtFieldPassword',
supports: KtFieldPassword.meta.supports,
Expand Down Expand Up @@ -1166,7 +1175,6 @@ export default defineComponent({
additionalProps: {
allowMultiple: Kotti.FieldToggle.Value
allowPhotos: Kotti.FieldToggle.Value
autoComplete: 'current-password' | 'new-password'
autoSize: Kotti.FieldToggle.Value
clearOnSelect: Kotti.FieldToggle.Value
collapseExtensionsAfter: Kotti.FieldNumber.Value
Expand Down Expand Up @@ -1202,6 +1210,8 @@ export default defineComponent({
showHeaderSideSlot: ComponentValue['showHeaderSideSlot']
toggleType: 'checkbox' | 'switch'
}
autoComplete: string
autoCompleteToken: Kotti.FieldText.Value
booleanFlags: {
hideClear: Kotti.FieldToggle.Value
hideValidation: Kotti.FieldToggle.Value
Expand Down Expand Up @@ -1232,7 +1242,6 @@ export default defineComponent({
additionalProps: {
allowMultiple: false,
allowPhotos: false,
autoComplete: 'current-password',
autoSize: false,
clearOnSelect: false,
collapseExtensionsAfter: null,
Expand Down Expand Up @@ -1268,6 +1277,8 @@ export default defineComponent({
showHeaderSideSlot: false,
toggleType: 'checkbox',
},
autoComplete: Kotti.Field.AutoComplete.OFF,
autoCompleteToken: null,
booleanFlags: {
hideClear: false,
hideValidation: false,
Expand Down Expand Up @@ -1361,6 +1372,14 @@ export default defineComponent({
tabIndex: settings.value.tabIndex,
})
if (componentDefinition.value.supports.autoComplete)
Object.assign(additionalProps, {
autoComplete:
settings.value.autoComplete === 'token'
? settings.value.autoCompleteToken
: settings.value.autoComplete,
})
if (
componentDefinition.value.additionalProps.includes('toggleType') &&
settings.value.additionalProps.toggleType !== 'checkbox' // Exclude Default Value
Expand All @@ -1383,10 +1402,6 @@ export default defineComponent({
maxHeight: settings.value.additionalProps.maxHeight,
})
if (componentDefinition.value.additionalProps.includes('autoComplete'))
Object.assign(additionalProps, {
autoComplete: settings.value.additionalProps.autoComplete,
})
if (
componentDefinition.value.additionalProps.includes(
'numberDecimalPlaces',
Expand Down Expand Up @@ -1670,7 +1685,43 @@ export default defineComponent({
}),
)
watch(
() => settings.value.component,
(newComponent, oldComponent) => {
if (
newComponent === 'KtFieldPassword' &&
oldComponent !== 'KtFieldPassword'
)
settings.value = {
...settings.value,
autoComplete: Kotti.FieldPassword.AutoComplete.CURRENT,
}
else if (
newComponent !== 'KtFieldPassword' &&
oldComponent === 'KtFieldPassword'
)
settings.value = {
...settings.value,
autoComplete: Kotti.Field.AutoComplete.OFF,
}
},
)
return {
autoCompleteOptions: computed(() =>
settings.value.component === 'KtFieldPassword'
? Object.values(Kotti.FieldPassword.AutoComplete).map((option) => ({
label: option,
value: option,
}))
: [
...Object.values(Kotti.Field.AutoComplete).map((option) => ({
label: option,
value: option,
})),
{ label: '<token>', value: 'token' },
],
),
component: computed(
(): { meta: Kotti.Meta; name: string } =>
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export default defineComponent({
forceUpdateKey: number
} => ({
...field.inputProps,
autocomplete: props.autoComplete,
class: {
'kt-field-currency__input': true,
},
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-field-currency/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { KottiField } from '../kotti-field/types'
import { DECIMAL_SEPARATORS_CHARACTER_SET } from '../utilities'

export const KOTTI_FIELD_CURRENCY_SUPPORTS: KottiField.Supports = {
autoComplete: true,
clear: false,
decoration: false,
placeholder: true,
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-field-currency/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export module KottiFieldCurrency {
export const propsSchema = KottiField.propsSchema
.merge(
KottiField.potentiallySupportedPropsSchema.pick({
autoComplete: true,
tabIndex: true,
}),
)
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-field-date/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const DATE_FORMAT_REGEX = /^\d{4}-\d{2}-\d{2}$/
export const DATE_TIME_FORMAT_REGEX = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?$/

export const KOTTI_FIELD_DATE_SUPPORTS: KottiField.Supports = {
autoComplete: false,
clear: true,
decoration: false,
placeholder: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum ErrorCodes {
}

export const KOTTI_FIELD_FILE_UPLOAD_SUPPORTS: KottiField.Supports = {
autoComplete: false,
clear: false,
decoration: false,
placeholder: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export default defineComponent({
forceUpdateKey: number
} => ({
...sharedProps.value,
autocomplete: props.autoComplete,
class: {
'kt-field-inline-edit__input': true,
...(props.textStyle !== null && { [props.textStyle]: true }),
Expand Down Expand Up @@ -307,6 +308,7 @@ export default defineComponent({
forceUpdateKey: number
} => ({
...sharedProps.value,
autocomplete: props.autoComplete,
class: {
'kt-field-inline-edit__input': true,
'kt-field-inline-edit__input--is-multiline': true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { KottiField } from '../kotti-field/types'

export const KOTTI_FIELD_INLINE_EDIT_SUPPORTS: KottiField.Supports = {
autoComplete: true,
clear: false,
decoration: false,
placeholder: true,
Expand Down
7 changes: 6 additions & 1 deletion packages/kotti-ui/source/kotti-field-inline-edit/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export module KottiFieldInlineEdit {
}

export const propsSchema = KottiField.propsSchema
.merge(KottiField.potentiallySupportedPropsSchema.pick({ tabIndex: true }))
.merge(
KottiField.potentiallySupportedPropsSchema.pick({
autoComplete: true,
tabIndex: true,
}),
)
.extend({
isReadonly: z.boolean().default(false),
isMultiline: z.boolean().default(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export default defineComponent({
forceUpdateKey: number
} => ({
...field.inputProps,
autocomplete: props.autoComplete,
class: {
'kt-field-number__input': true,
'kt-field-number__input--has-maximum': showMaximum.value,
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-field-number/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DecimalSeparator } from '../types/kotti'
import { DECIMAL_SEPARATORS_CHARACTER_SET } from '../utilities'

export const KOTTI_FIELD_NUMBER_SUPPORTS: KottiField.Supports = {
autoComplete: true,
clear: false,
decoration: true,
placeholder: true,
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-field-number/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export module KottiFieldNumber {
export const propsSchema = KottiField.propsSchema
.merge(
KottiField.potentiallySupportedPropsSchema.pick({
autoComplete: true,
leftIcon: true,
prefix: true,
rightIcon: true,
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-field-password/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { KottiField } from '../kotti-field/types'

export const KOTTI_FIELD_PASSWORD_SUPPORTS: KottiField.Supports = {
autoComplete: true,
clear: true,
decoration: true,
placeholder: true,
Expand Down
5 changes: 4 additions & 1 deletion packages/kotti-ui/source/kotti-field-password/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ export module KottiFieldPassword {
export enum AutoComplete {
CURRENT = 'current-password',
NEW = 'new-password',
ONE_TIME_CODE = 'one-time-code',
}
export const propsSchema = KottiField.propsSchema
.merge(KottiField.potentiallySupportedPropsSchema)
.merge(
KottiField.potentiallySupportedPropsSchema.omit({ autoComplete: true }),
)
.extend({
placeholder: z.string().nullable().default(null),
autoComplete: createLooseZodEnumSchema(AutoComplete),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { KottiField } from '../kotti-field/types'

export const KOTTI_FIELD_RADIO_GROUP_SUPPORTS: KottiField.Supports = {
autoComplete: false,
clear: false,
decoration: false,
placeholder: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export default defineComponent({
),
inputProps: computed(() => ({
...field.inputProps,
autocomplete: props.autoComplete,
class: ['kt-field-select__wrapper'],
forceUpdateKey: forceUpdateKey.value,
placeholder: props.placeholder ?? undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/source/kotti-field-select/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { KottiField } from '../kotti-field/types'

export const KOTTI_FIELD_SELECT_SUPPORTS: KottiField.Supports = {
autoComplete: true,
clear: true,
decoration: true,
placeholder: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default defineComponent({
forceUpdateKey: number
} => ({
...field.inputProps,
autocomplete: props.autoComplete,
class: 'kt-field-text-area__wrapper',
forceUpdateKey: forceUpdateKey.value,
placeholder: props.placeholder ?? undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { KottiField } from '../kotti-field/types'

export const KOTTI_FIELD_TEXT_AREA_SUPPORTS: KottiField.Supports = {
autoComplete: true,
clear: false,
decoration: false,
placeholder: true,
Expand Down
Loading

0 comments on commit b1896d9

Please sign in to comment.