import * as React from 'react'; import { Form, Select, Submit, Checkbox, Radio, RadioContainer, MoneyWithCurrency, OpeningHoursDayObj, OpeningHoursSpecialDayObj, InputHeader, Button, ButtonTypes, Tags, Tag, SelectValue, ButtonProps, FormValidationSummary, ValidatorTypes, } from '../lib'; export interface TestProps {} export interface TestState { name: string; gender: 'M' | 'F' | ''; email: string; age: string; min1: string; checkbox1: boolean; checkbox2: boolean; validateFormSubmit: boolean; food: string; drink: string; touchOn: 'blur' | 'focus'; submitDisablesInputs: boolean; simulateUnmount: boolean; prices1: MoneyWithCurrency[]; prices2: MoneyWithCurrency[]; time1: Date; time2: Date; openingHours: OpeningHoursDayObj; openingHoursWeek: OpeningHoursDayObj[]; openingHoursWeekDay: OpeningHoursDayObj; openingHoursSpecial: OpeningHoursSpecialDayObj[]; website: string; tags: Tag[]; selectedValues: SelectValue[]; multipleValues: SelectValue[]; multipleReadonly: boolean; textAreaText: string; } export class AgeValidator { public static instance = new AgeValidator(); public Validate( value: string, isRequired: boolean, addError: (error: string) => void ): boolean { let num = Number(value); if (!isNaN(num)) { if (num <= 0) { addError('Not born yet?'); return false; } if (num > 122) { addError('Older than Jeanne Calment? Really?'); return false; } return true; } else { addError('Invalid age'); } return false; } } const tagsValidators: ValidatorTypes[] = ['email']; const types: ButtonTypes[] = [ 'primary', 'warning', 'error', 'info', 'success', 'gray', 'white', 'none', ]; const ButtonsShowcase: React.FC = (props) => { return (
{types.map((item, index) => ( ))}
); }; ButtonsShowcase.defaultProps = { className: 'my-2 mr-2', }; export class Test extends React.PureComponent { private form: Form; private initialState: TestState = { gender: '', name: '', email: '', age: '', min1: '', checkbox1: true, checkbox2: false, validateFormSubmit: true, food: 'breakfast', drink: 'breakfast', touchOn: 'focus', submitDisablesInputs: true, simulateUnmount: false, prices1: [], prices2: [], time1: new Date(), time2: new Date(), openingHours: { times: [], }, openingHoursWeek: [], openingHoursWeekDay: { times: [], }, openingHoursSpecial: [], website: '', tags: [], selectedValues: [], multipleValues: [ { value: 'One option' }, { value: 'Second option' }, { value: 'Third option' }, { value: 'one more option' }, { value: 'rly long last option' }, ], multipleReadonly: false, textAreaText: '', }; constructor(props: TestProps) { super(props); this.state = this.initialState; this.handleGenderChange = this.handleGenderChange.bind(this); this.submitForm = this.submitForm.bind(this); this.dynamicSubmitSuccessForm = this.dynamicSubmitSuccessForm.bind(this); this.dynamicSubmitErrorForm = this.dynamicSubmitErrorForm.bind(this); } public render() { let time2Max = new Date(); time2Max.setHours(time2Max.getHours() + 1); time2Max.setMinutes(time2Max.getMinutes() + 5); let time2Min = new Date(); time2Min.setHours(time2Min.getHours() - 1); time2Min.setMinutes(time2Min.getMinutes() - 5); return (
{!this.state.simulateUnmount && (
edit} title={'Example form'} subTitle={ "And this is subtitle. There's also icon on the left" } showExpandAll={true} type="hero" collapsible={true} collapsedDefault={false} mainButton={ Submit } extraButtons={[ , , ]} > {true && ( )} {false && (