mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
ts: add FormFieldDisplay types
This commit is contained in:
parent
50fda7861d
commit
509f68e5d9
2 changed files with 55 additions and 1 deletions
|
@ -23,3 +23,9 @@ export type CustomRoute = {
|
||||||
text: string
|
text: string
|
||||||
icon?: string
|
icon?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HELPERS
|
||||||
|
|
||||||
|
export type ArrInnerType<T> = T extends (infer ElementType)[]
|
||||||
|
? ElementType
|
||||||
|
: never
|
||||||
|
|
|
@ -5,7 +5,7 @@ import type {
|
||||||
} from '@vuelidate/core'
|
} from '@vuelidate/core'
|
||||||
import type { RouteLocationRaw } from 'vue-router'
|
import type { RouteLocationRaw } from 'vue-router'
|
||||||
|
|
||||||
import type { Cols } from '@/types/commons'
|
import type { ArrInnerType, Cols } from '@/types/commons'
|
||||||
|
|
||||||
type StateValidation = false | null
|
type StateValidation = false | null
|
||||||
type StateVariant = 'success' | 'info' | 'warning' | 'danger'
|
type StateVariant = 'success' | 'info' | 'warning' | 'danger'
|
||||||
|
@ -142,9 +142,49 @@ const ANY_WRITABLE_COMPONENTS = [
|
||||||
'TagsSelectizeItem',
|
'TagsSelectizeItem',
|
||||||
'TextAreaItem',
|
'TextAreaItem',
|
||||||
] as const
|
] as const
|
||||||
|
const ANY_DISPLAY_COMPONENTS = [
|
||||||
|
'ButtonItem',
|
||||||
|
'DisplayTextItem',
|
||||||
|
'MarkdownItem',
|
||||||
|
'ReadOnlyAlertItem',
|
||||||
|
] as const
|
||||||
|
|
||||||
|
type AnyItemComponents = AnyDisplayComponents | AnyWritableComponents
|
||||||
|
export type AnyDisplayComponents = (typeof ANY_DISPLAY_COMPONENTS)[number]
|
||||||
export type AnyWritableComponents = (typeof ANY_WRITABLE_COMPONENTS)[number]
|
export type AnyWritableComponents = (typeof ANY_WRITABLE_COMPONENTS)[number]
|
||||||
|
|
||||||
|
export function isWritableComponent<MV extends any = any>(
|
||||||
|
field:
|
||||||
|
| FormField<AnyWritableComponents, MV>
|
||||||
|
| FormField
|
||||||
|
| FormFieldReadonly
|
||||||
|
| FormFieldDisplay,
|
||||||
|
): field is
|
||||||
|
| FormField<AnyWritableComponents, MV>
|
||||||
|
| FormFieldReadonly<AnyWritableComponents> {
|
||||||
|
return ANY_WRITABLE_COMPONENTS.includes(
|
||||||
|
field.component as AnyWritableComponents,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isDisplayComponent(
|
||||||
|
field:
|
||||||
|
| FormField<AnyWritableComponents>
|
||||||
|
| FormField
|
||||||
|
| FormFieldReadonly
|
||||||
|
| FormFieldDisplay,
|
||||||
|
): field is FormFieldDisplay {
|
||||||
|
return ANY_DISPLAY_COMPONENTS.includes(
|
||||||
|
field.component as AnyDisplayComponents,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
type ItemComponentToItemProps = {
|
type ItemComponentToItemProps = {
|
||||||
|
// DISPLAY
|
||||||
|
ButtonItem: ButtonItemProps
|
||||||
|
DisplayTextItem: DisplayTextItemProps
|
||||||
|
MarkdownItem: MarkdownItemProps
|
||||||
|
ReadOnlyAlertItem: ReadOnlyAlertItemProps
|
||||||
// WRITABLE
|
// WRITABLE
|
||||||
AdressItem: AdressItemProps
|
AdressItem: AdressItemProps
|
||||||
CheckboxItem: CheckboxItemProps
|
CheckboxItem: CheckboxItemProps
|
||||||
|
@ -204,6 +244,14 @@ type FormFieldReadonly<
|
||||||
readonly: true
|
readonly: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FormFieldDisplay<C extends AnyDisplayComponents = AnyDisplayComponents> = {
|
||||||
|
component: C
|
||||||
|
props: ItemComponentToItemProps[C]
|
||||||
|
visible?: boolean
|
||||||
|
hr?: boolean
|
||||||
|
readonly?: true
|
||||||
|
}
|
||||||
|
|
||||||
export type FormFieldProps<
|
export type FormFieldProps<
|
||||||
C extends AnyWritableComponents,
|
C extends AnyWritableComponents,
|
||||||
MV extends any,
|
MV extends any,
|
||||||
|
|
Loading…
Add table
Reference in a new issue