Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create and customize checkbox component
- Loading branch information
1 parent
7354dfb
commit a871f0b
Showing
5 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/yoroi-extension/app/assets/images/forms/checkbox-checked.inline.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
packages/yoroi-extension/app/assets/images/forms/checkbox-outline.inline.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions
88
packages/yoroi-extension/app/components/common/CheckboxLabel.js
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,88 @@ | ||
// @flow | ||
import type { Node } from 'react'; | ||
import { Checkbox, FormControlLabel, Typography } from '@mui/material'; | ||
|
||
import OutlineIcon from '../../assets/images/forms/checkbox-outline.inline.svg'; | ||
import CheckedIcon from '../../assets/images/forms/checkbox-checked.inline.svg'; | ||
import { Box } from '@mui/system'; | ||
import ReactMarkdown from 'react-markdown'; | ||
|
||
type Props = {| | ||
label: string | Node, | ||
labelProps?: Object, | ||
sx?: Object, | ||
labelSx?: Object, | ||
descriptionSx?: Object, | ||
description?: ?string, | ||
checked: boolean, | ||
disabled?: boolean, | ||
onChange: () => void, | ||
|}; | ||
function CheckboxLabel({ | ||
label, | ||
disabled, | ||
labelProps, | ||
description, | ||
sx, | ||
labelSx, | ||
descriptionSx, | ||
...checkboxProps | ||
}: Props): Node { | ||
return ( | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
disabled={disabled} | ||
icon={<OutlineIcon />} | ||
checkedIcon={<CheckedIcon />} | ||
{...checkboxProps} | ||
/> | ||
} | ||
label={ | ||
<Box | ||
sx={{ | ||
margin: 0, | ||
'p + p': { | ||
fontSize: '0.75rem', | ||
letterSpacing: '0.5px', | ||
...(descriptionSx !== null && descriptionSx), | ||
}, | ||
strong: { fontWeight: 500 }, | ||
}} | ||
> | ||
<Typography | ||
marginBottom={description ? '8px' : 0} | ||
sx={{ | ||
color: 'var(--mui-checkbox-label-text-color)', | ||
fontWeight: 300, | ||
...(labelSx !== null && labelSx), | ||
}} | ||
> | ||
{label} | ||
</Typography> | ||
{Boolean(description) && <ReactMarkdown source={description} escapeHtml={false} />} | ||
</Box> | ||
} | ||
sx={{ | ||
alignItems: description !== null ? 'center' : 'flex-start', | ||
margin: 0, | ||
'& .MuiFormControlLabel-label': { | ||
flex: 1, | ||
}, | ||
...(sx !== null && sx), | ||
}} | ||
{...labelProps} | ||
/> | ||
); | ||
} | ||
|
||
export default CheckboxLabel; | ||
|
||
CheckboxLabel.defaultProps = { | ||
labelProps: null, | ||
sx: null, | ||
labelSx: null, | ||
descriptionSx: null, | ||
disabled: false, | ||
description: null, | ||
}; |
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
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