import * as React from 'react'; import { Dropdown, Form, Time, Text, Select, Submit, DynamicSubmit, Checkbox, Radio, RadioContainer, Money, OpeningHoursDay, MoneyWithCurrency, OpeningHoursDayObj, OpeningHoursWeek, OpeningHoursSpecialDayObj, OpeningHoursSpecial, InputHeader, Button, ButtonTypes, Tags, Tag, NumberValidator, TextArea, OpeningHoursWeekDayObj, SelectValue, TextProps, ValidatorTypes, IBaseValidator, ButtonProps, FormValidationSummary, InputHeaderRaw, TimeSpan, TimeSpanUnit, } from '../lib/index'; import moment, { Duration } from 'moment'; export interface BasicProps {} export interface BasicState { name: string | null; gender: 'M' | 'F' | ''; email: string; age: string; min1: string; hideNumber: boolean | undefined; justNumber: number; checkbox1: boolean; checkbox2: boolean; validateFormSubmit: boolean; food: string; drink: string; touchOn: 'blur' | 'focus'; submitDisablesInputs: boolean; simulateUnmount: boolean; prices1: MoneyWithCurrency[]; prices2: MoneyWithCurrency[]; prices3: MoneyWithCurrency[]; time1: Duration; time2: Duration; timeSpan: Duration; openingHours: OpeningHoursDayObj; openingHoursWeek: OpeningHoursWeekDayObj[]; 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 existingTags: Tag[] = [ { id: 1, name: 'Food', }, { id: 2, name: 'Drink', }, { id: 3, name: 'Beer', }, { id: 4, name: 'Wine', }, { id: 5, name: 'Gluten free', }, { id: 6, name: 'Fruit', }, ]; const currencies1 = [ { label: 'GBP', value: 'GBP' }, { label: 'EUR', value: 'EUR' }, ]; const currencies2 = [ { label: 'GBP', value: 'GBP' }, { label: 'EUR', value: 'EUR' }, { label: 'USD', value: 'USD' }, ]; const currencies3 = [ { label: 'GBP', value: 'GBP', forceSelected: true }, { label: 'EUR', value: 'EUR' }, { label: 'USD', value: 'USD' }, ]; const genderValues = [ { value: 'M', label: 'Male' }, { value: 'F', label: 'Female' }, ]; const tagsEmailTextProps: TextProps = { validators: ['email'], }; const emailValidators: ValidatorTypes[] = ['email']; const urlValidators: ValidatorTypes[] = ['url']; const customAgeValidator: IBaseValidator[] = [AgeValidator.instance]; const customNumberValidator: IBaseValidator[] = [ new NumberValidator({ min: 0 }), ]; const numberValidator: TextProps['validators'] = ['number']; 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 Basic extends React.PureComponent { private form: Form | undefined; private specialDaysInputHeader: React.RefObject; private initialState: BasicState = { gender: '', name: 'Test', email: '', age: '', min1: '', checkbox1: true, checkbox2: false, validateFormSubmit: true, food: 'breakfast', drink: 'breakfast', touchOn: 'focus', submitDisablesInputs: true, simulateUnmount: false, prices1: [], prices2: [], prices3: [], timeSpan: moment.duration(0), time1: moment.duration(0), time2: moment.duration(0), 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: '', justNumber: undefined, hideNumber: undefined, }; constructor(props: BasicProps) { 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); this.specialDaysInputHeader = React.createRef(); } public render() { let time2Max = moment.duration().add(1, 'hour').add(5, 'minutes'); let time2Min = moment.duration().subtract(1, 'hour').subtract(5, 'minutes'); return (
{!this.state.simulateUnmount && (
edit} title={'Example form'} subTitle={ "And this is subtitle. There's also icon on the left" } showExpandAll={true} collapsible={true} collapsedDefault={false} mainButton={ Submit } extraButtons={[ , , ]} shouldToggleCollapseOnHeaderClick={true} >
This is some help text. It can also do bold{' '} and other stuff.

} />