Skip to content

Commit 03cd149

Browse files
committed
dedicated checkbox input init
1 parent 99d3260 commit 03cd149

File tree

8 files changed

+107
-2
lines changed

8 files changed

+107
-2
lines changed

src-ts/lib/contact-support-form/ContactSupportForm.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const ContactSupportForm: FC<ContactSupportFormProps> = (props: ContactSupportFo
1919
const { profile }: ProfileContextData = useContext(profileContext)
2020

2121
function generateRequest(inputs: ReadonlyArray<FormInputModel>): ContactSupportRequest {
22+
const activeEl: any = formGetInputModel(inputs, 'active')
23+
console.log('generateRequest', activeEl)
24+
2225
const firstName: string = formGetInputModel(inputs, ContactSupportFormField.first).value as string
2326
const lastName: string = formGetInputModel(inputs, ContactSupportFormField.last).value as string
2427
const email: string = formGetInputModel(inputs, ContactSupportFormField.email).value as string

src-ts/lib/contact-support-form/contact-support-form.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export const contactSupportFormDef: FormDefinition = {
2222
groups: [
2323
{
2424
inputs: [
25+
{
26+
checked: true,
27+
label: 'Activate',
28+
name: 'active',
29+
type: 'checkbox',
30+
},
2531
{
2632
label: 'First Name',
2733
name: ContactSupportFormField.first,

src-ts/lib/form/form-groups/FormGroups.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FormInputModel } from '../form-input.model'
66

77
import { FormCardSet } from './form-card-set'
88
import FormGroupItem from './form-group-item/FormGroupItem'
9-
import { InputRating, InputText, InputTextarea } from './form-input'
9+
import { InputCheckbox, InputRating, InputText, InputTextarea } from './form-input'
1010
import { FormInputRow } from './form-input-row'
1111
import { InputTextTypes } from './form-input/input-text/InputText'
1212
import FormRadio from './form-radio'
@@ -44,7 +44,6 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
4444
/>
4545
)
4646
break
47-
4847
case 'textarea':
4948
inputElement = (
5049
<InputTextarea
@@ -57,6 +56,15 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
5756
)
5857
break
5958
case 'checkbox':
59+
inputElement = (
60+
<InputCheckbox
61+
{...input}
62+
onChange={onChange}
63+
tabIndex={tabIndex}
64+
type={'checkbox'}
65+
/>
66+
)
67+
break
6068
case 'radio':
6169
inputElement = (
6270
<FormRadio

src-ts/lib/form/form-groups/form-input/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './input-checkbox'
12
export * from './form-input-autcomplete-option.enum'
23
export * from './input-rating'
34
export * from './input-text'
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@use '../../../../styles/typography';
2+
@import '../../../../styles/includes';
3+
4+
.form-input-checkbox {
5+
@extend .body-small;
6+
color: $black-60;
7+
box-sizing: border-box;
8+
border: 0;
9+
width: 100%;
10+
padding: 0;
11+
margin: 0;
12+
height: auto;
13+
border-radius: 0;
14+
15+
&:focus {
16+
box-shadow: none;
17+
border: none;
18+
outline: none;
19+
color: $black-100;
20+
}
21+
22+
&:disabled {
23+
background-color: $black-10;
24+
}
25+
26+
&.checkbox {
27+
& {
28+
width: 20px;
29+
height: 20px;
30+
}
31+
}
32+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import cn from 'classnames'
2+
import { ChangeEvent, Dispatch, FC, FocusEvent, SetStateAction, useState } from 'react'
3+
4+
import { InputWrapper } from '../input-wrapper'
5+
6+
import styles from './InputCheckbox.module.scss'
7+
8+
export type InputCheckboxTypes = 'checkbox' | 'password' | 'text'
9+
10+
interface InputCheckboxProps {
11+
readonly checked?: boolean
12+
readonly className?: string
13+
readonly dirty?: boolean
14+
readonly disabled?: boolean
15+
readonly error?: string
16+
readonly hideInlineErrors?: boolean
17+
readonly hint?: string
18+
readonly label?: string | JSX.Element
19+
readonly name: string
20+
readonly onChange: (event: ChangeEvent<HTMLInputElement>) => void
21+
readonly tabIndex: number
22+
readonly type: InputCheckboxTypes
23+
}
24+
25+
const InputCheckbox: FC<InputCheckboxProps> = (props: InputCheckboxProps) => {
26+
27+
const [checked, setChecked]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(props.checked || false)
28+
29+
return (
30+
<InputWrapper
31+
{...props}
32+
dirty={!!props.dirty}
33+
disabled={!!props.disabled}
34+
label={props.label || props.name}
35+
hideInlineErrors={props.hideInlineErrors}
36+
>
37+
<input
38+
className={cn(styles['form-input-checkbox'], styles[props.type])}
39+
disabled={!!props.disabled}
40+
onChange={(event) => {
41+
setChecked(!checked)
42+
props.onChange(event)
43+
}}
44+
name={props.name}
45+
tabIndex={props.tabIndex}
46+
type={'checkbox'}
47+
checked={checked}
48+
/>
49+
</InputWrapper>
50+
)
51+
}
52+
53+
export default InputCheckbox
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as InputCheckbox } from './InputCheckbox'

src-ts/lib/form/form-input.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface FormCard {
2020
export interface FormInputModel {
2121
readonly autocomplete?: FormInputAutocompleteOption
2222
readonly cards?: ReadonlyArray<FormCard>
23+
checked?: boolean
2324
readonly className?: string
2425
readonly dependentFields?: Array<string>
2526
dirty?: boolean

0 commit comments

Comments
 (0)