-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Building block for the builder fields that are of boolean type.
- Loading branch information
1 parent
dcc7bf0
commit 916cc3f
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import withFormik from '@bbbtech/storybook-formik'; | ||
import {ComponentMeta, ComponentStory} from '@storybook/react'; | ||
|
||
import Checkbox from './checkbox'; | ||
|
||
export default { | ||
title: 'Formio/Components/Checkbox', | ||
component: Checkbox, | ||
decorators: [withFormik], | ||
parameters: { | ||
modal: {noModal: true}, | ||
formik: {initialValues: {'my-checkbox': false}}, | ||
}, | ||
args: { | ||
name: 'my-checkbox', | ||
label: '', | ||
tooltip: '', | ||
}, | ||
} as ComponentMeta<typeof Checkbox>; | ||
|
||
const Template: ComponentStory<typeof Checkbox> = args => <Checkbox {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
label: 'Labeled checkbox', | ||
}; | ||
|
||
export const WithToolTip = Template.bind({}); | ||
WithToolTip.args = { | ||
label: 'With tooltip', | ||
tooltip: 'Hiya!', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Field} from 'formik'; | ||
|
||
import Component from './component'; | ||
import Tooltip from './tooltip'; | ||
|
||
export interface CheckboxProps { | ||
name: string; | ||
label?: React.ReactNode; | ||
tooltip?: string; | ||
} | ||
|
||
const Checkbox: React.FC<CheckboxProps> = ({name, label, tooltip = ''}) => { | ||
return ( | ||
<Component type="checkbox"> | ||
<div className="form-check checkbox"> | ||
<label className="form-check-label"> | ||
<Field name={name} as="input" type="checkbox" className="form-check-input" /> | ||
<span>{label}</span> | ||
{tooltip && ' '} | ||
<Tooltip text={tooltip} /> | ||
</label> | ||
</div> | ||
</Component> | ||
); | ||
}; | ||
|
||
export default Checkbox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters