You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.2 KiB
31 lines
1.2 KiB
import { NotificationType, Form, FormValue } from '../types'
|
|
|
|
export function notificationTypeToClassName(type: NotificationType): string {
|
|
switch (type) {
|
|
case 'info': return 'is-info'
|
|
case 'success': return 'is-success'
|
|
case 'error': return 'is-danger'
|
|
}
|
|
}
|
|
|
|
export const objectToQuerystring = (obj: object) => Object.entries(obj).filter(([_, value]) => value !== undefined).map(([name, value]) => `${name}=${value}`).join('&')
|
|
|
|
export function setTitle(title: string, decorate: boolean = true) {
|
|
if (decorate) {
|
|
document.title = `${title} | Flexor`
|
|
} else {
|
|
document.title = title
|
|
}
|
|
}
|
|
|
|
export function valueFromForm<T extends FormValue>(form: Form, name: string): T | undefined
|
|
export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue: T): T
|
|
export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue?: T): T | undefined
|
|
export function valueFromForm<T extends FormValue>(form: Form, name: string, defaultValue?: T): T | undefined {
|
|
const field = form[name]
|
|
|
|
if (!field) return defaultValue
|
|
if (field.value === undefined) return defaultValue
|
|
|
|
return field.value as T
|
|
}
|