diff --git a/components/form/admin/types/dropdown.type.tsx b/components/form/admin/types/dropdown.type.tsx index 7808cfc..f819c17 100644 --- a/components/form/admin/types/dropdown.type.tsx +++ b/components/form/admin/types/dropdown.type.tsx @@ -1,9 +1,8 @@ -import {Form, Input} from 'antd' +import {Button, Col, Form, Input, Row} from 'antd' import React from 'react' import {AdminFieldTypeProps} from './type.props' export const DropdownType: React.FC = props => { - // TODO add dropdown options return (
= props => { > + + + {(fields, { add, remove }) => { + + return ( +
+ {fields.map((field, index) => ( + + + + + + + + + + + + + + + + + + ))} + + + + +
+ ) + }} +
) } diff --git a/components/form/admin/types/radio.type.tsx b/components/form/admin/types/radio.type.tsx index 93b96fb..2411d4a 100644 --- a/components/form/admin/types/radio.type.tsx +++ b/components/form/admin/types/radio.type.tsx @@ -1,10 +1,8 @@ -import {Form, Input} from 'antd' +import {Button, Col, Form, Input, Row} from 'antd' import React from 'react' import {AdminFieldTypeProps} from './type.props' export const RadioType: React.FC = props => { - // TODO Add radio support - return (
= props => { > + + + {(fields, { add, remove }) => { + + return ( +
+ {fields.map((field, index) => ( + + + + + + + + + + + + + + + + + + ))} + + + + +
+ ) + }} +
) } diff --git a/components/form/types/dropdown.type.tsx b/components/form/types/dropdown.type.tsx index f7a70c8..f28f69c 100644 --- a/components/form/types/dropdown.type.tsx +++ b/components/form/types/dropdown.type.tsx @@ -1,9 +1,11 @@ -import {Form, Input} from 'antd' -import React from 'react' +import {Form, Select} from 'antd' +import React, {useState} from 'react' +import {StyledSelect} from '../../styled/select' import {FieldTypeProps} from './type.props' -export const DropdownType: React.FC = ({field}) => { - // TODO add dropdown options +export const DropdownType: React.FC = ({field, design}) => { + const [open, setOpen] = useState(false) + return (
= ({field}) => { rules={[ { required: field.required, message: 'Please provide Information' }, ]} + initialValue={field.value || null} > - + setOpen(false)} onFocus={() => setOpen(true)} onSelect={() => setOpen(false)}> + {field.options.filter(option => option.key === null).map(option => ( + OK{option.title || option.value} + ))} +
) diff --git a/components/form/types/radio.type.tsx b/components/form/types/radio.type.tsx index 29fc290..197a234 100644 --- a/components/form/types/radio.type.tsx +++ b/components/form/types/radio.type.tsx @@ -1,10 +1,9 @@ -import {Form, Input} from 'antd' +import {Form, Radio} from 'antd' import React from 'react' +import {StyledRadio} from '../../styled/radio' import {FieldTypeProps} from './type.props' -export const RadioType: React.FC = ({field}) => { - // TODO Add radio support - +export const RadioType: React.FC = ({field, design}) => { return (
= ({field}) => { rules={[ { required: field.required, message: 'Please provide Information' }, ]} + initialValue={field.options.map(option => option.value).find(value => value === field.value)} > - + + {field.options.filter(option => option.key === null).map(option => ( + + {option.title || option.value} + + ))} +
) diff --git a/components/styled/radio.tsx b/components/styled/radio.tsx new file mode 100644 index 0000000..2479011 --- /dev/null +++ b/components/styled/radio.tsx @@ -0,0 +1,39 @@ +import {Radio} from 'antd' +import {RadioProps} from 'antd/lib/radio/interface' +import React from 'react' +import styled from 'styled-components' +import {FormDesignFragment} from '../../graphql/fragment/form.fragment' + +interface Props extends RadioProps { + design: FormDesignFragment +} + +const Field = styled(Radio)` + color: ${props => props.design.colors.answerColor}; + border-color: ${props => props.design.colors.answerColor}; + background: none; + + .ant-radio { + .ant-radio-inner { + border-color: ${props => props.design.colors.answerColor}; + + &::after { + background: ${props => props.design.colors.answerColor}; + } + } + + &::after { + border-color: ${props => props.design.colors.answerColor}; + } + } + + .anticon { + color: ${props => props.design.colors.answerColor}; + } +` + +export const StyledRadio: React.FC = ({children, ...props}) => { + return ( + {children} + ) +} diff --git a/components/styled/select.tsx b/components/styled/select.tsx new file mode 100644 index 0000000..3627671 --- /dev/null +++ b/components/styled/select.tsx @@ -0,0 +1,51 @@ +import {Select} from 'antd' +import {SelectProps} from 'antd/lib/select' +import React from 'react' +import styled from 'styled-components' +import {FormDesignFragment} from '../../graphql/fragment/form.fragment' +import {transparentize} from './color.change' + +interface Props extends SelectProps { + design: FormDesignFragment +} + +const Field = styled(Select)` + .ant-select-selector { + color: ${props => props.design.colors.answerColor}; + border-color: ${props => props.design.colors.answerColor} !important; + background: none !important; + border-right: none !important; + border-top: none !important; + border-left: none !important; + border-radius: 0 !important; + box-shadow: none !important; + } + + :focus { + outline: ${props => props.design.colors.answerColor} auto 5px + } + + :hover, + :active { + border-color: ${props => props.design.colors.answerColor}; + } + + input { + background: none !important; + color: ${props => props.design.colors.answerColor}; + + ::placeholder { + color: ${props => transparentize(props.design.colors.answerColor, 60)} + } + } + + .anticon { + color: ${props => props.design.colors.answerColor}; + } +` + +export const StyledSelect: React.FC = ({children, ...props}) => { + return ( + {children} + ) +} diff --git a/graphql/fragment/admin.form.fragment.ts b/graphql/fragment/admin.form.fragment.ts index f7f2ee7..97f657e 100644 --- a/graphql/fragment/admin.form.fragment.ts +++ b/graphql/fragment/admin.form.fragment.ts @@ -14,6 +14,20 @@ export interface AdminFormPageFragment { }[] } +export interface AdminFormFieldOptionFragment { + key?: number + title?: string + value: string +} + +export interface AdminFormFieldLogicJumpFragment { + fieldA?: string + valueB?: string + expressionString?: string + jumpTo?: string + enabled: boolean +} + export interface AdminFormFieldFragment { id: string title: string @@ -21,6 +35,15 @@ export interface AdminFormFieldFragment { description: string required: boolean value: string + + options: AdminFormFieldOptionFragment[] + + logicJump: AdminFormFieldLogicJumpFragment + + rating?: { + steps?: number + shape?: string + } } export interface AdminFormFragment { @@ -82,6 +105,24 @@ export const ADMIN_FORM_FRAGMENT = gql` description required value + + options { + key + title + value + } + + logicJump { + fieldA + valueB + expressionString + jumpTo + enabled + } + rating { + steps + shape + } } selfNotifications { diff --git a/graphql/fragment/form.fragment.ts b/graphql/fragment/form.fragment.ts index 1a2a226..03dd46a 100644 --- a/graphql/fragment/form.fragment.ts +++ b/graphql/fragment/form.fragment.ts @@ -15,6 +15,20 @@ export interface FormPageFragment { }[] } +export interface FormFieldOptionFragment { + key?: number + title?: string + value: string +} + +export interface FormFieldLogicJumpFragment { + fieldA?: string + valueB?: string + expressionString?: string + jumpTo?: string + enabled: boolean +} + export interface FormFieldFragment { id: string title: string @@ -22,6 +36,15 @@ export interface FormFieldFragment { description: string required: boolean value: string + + options: FormFieldOptionFragment[] + + logicJump: FormFieldLogicJumpFragment + + rating?: { + steps?: number + shape?: string + } } export interface FormDesignFragment { @@ -62,6 +85,24 @@ export const FORM_FRAGMENT = gql` description required value + + options { + key + title + value + } + + logicJump { + fieldA + valueB + expressionString + jumpTo + enabled + } + rating { + steps + shape + } } design {