const createSimpleForm = (): ComponentStore => {
const nameInput = new ComponentStore('name', 'RsInput')
// value - simple value of the prop, the prop value can also be a localized value or a calculated value
nameInput.props.placeholder = {value: 'Enter your name'}
nameInput.props.label = {value: 'Name'}
// make this field required
nameInput.schema = {
validations: [{key: 'required'}],
}
// set the properties of the tooltip
nameInput.tooltipProps = {
text: {value: 'Name'}
}
const passwordInput = new ComponentStore('password', 'RsInput')
passwordInput.props = {
placeholder: {value: 'Enter you password'},
label: {value: 'Password'},
passwordMask: {value: true},
}
passwordInput.tooltipProps = {
text: {value: 'Password'},
placement: {value: 'top'},
}
const submitButton = new ComponentStore('submit', 'RsButton')
submitButton.props = {
children: {value: 'Login'},
color: {value: 'blue'},
appearance: {value: 'primary'},
}
// add a validate action
submitButton.events = {
onClick: [
{
name: 'validate',
type: 'common',
}
]
}
// root element of the form, always screen
const root = new ComponentStore('screen', 'Screen')
root.children = [
nameInput,
passwordInput,
submitButton,
]
return root
}
const createForm = (): PersistedForm => {
// main object
return {
defaultLanguage: 'en-US',
form: createSimpleForm(),
languages: [],
localization: {},
// type of component that displays the tooltip
tooltipType: 'RsTooltip',
// type of component that displays the error
errorType: 'RsErrorMessage',
}
}
export const codeGeneratedForm = (): string => {
const persistedForm = createForm()
return JSON.stringify(persistedForm)
}