-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checkbox component #27
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f8206c9
checkbox-component
Hasmik8 f3ee9c7
fix issues
Hasmik8 4567210
create test checkbox
Hasmik8 2d13d60
fix error test
Hasmik8 95fe63f
fix
Hasmik8 bcda10f
fix interface && base props issue
Hasmik8 f0e7d2e
update branch
Hasmik8 bb6f381
remove icon
Hasmik8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,39 @@ | ||
import { storiesOf } from '@storybook/react'; | ||
import React from 'react'; | ||
import { ThemedBackground } from '../../utils/storybook'; | ||
import { CheckBox } from '../CheckBox'; | ||
|
||
storiesOf('CheckBox', module) | ||
// Litmus Portal | ||
.add('Litmus Portal', () => ( | ||
<ThemedBackground platform="litmus-portal" row> | ||
<CheckBox checked={true} disabled={true} /> | ||
</ThemedBackground> | ||
)) | ||
|
||
// Kubera Chaos | ||
.add('Kubera Chaos', () => ( | ||
<ThemedBackground platform="kubera-chaos" row> | ||
<CheckBox checked={true} disabled={false} /> | ||
</ThemedBackground> | ||
)) | ||
|
||
// Kubera Propel | ||
.add('Kubera Propel', () => ( | ||
<ThemedBackground platform="kubera-propel" row> | ||
<CheckBox checked={false} disabled={false} /> | ||
</ThemedBackground> | ||
)) | ||
// Kubera Portal | ||
.add('Kubera Portal', () => ( | ||
<ThemedBackground platform="kubera-portal" row> | ||
<CheckBox checked={false} disabled={false} /> | ||
</ThemedBackground> | ||
)) | ||
|
||
// Kubera Core | ||
.add('Kubera Core', () => ( | ||
<ThemedBackground platform="kubera-core" row> | ||
<CheckBox checked={false} disabled={false} /> | ||
</ThemedBackground> | ||
)); |
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,22 @@ | ||
import { Checkbox } from '@material-ui/core'; | ||
import React, { useState } from 'react'; | ||
import CheckOutlinedIcon from '@material-ui/icons/CheckOutlined'; | ||
import { useStyles } from './styles'; | ||
import { CheckboxProps } from '@material-ui/core/Checkbox'; | ||
|
||
const CheckBox: React.FC<CheckboxProps> = ({ disabled, checked }) => { | ||
const classes = useStyles(); | ||
const [check, setChecked] = useState<boolean | undefined>(checked); | ||
return ( | ||
<Checkbox | ||
data-testid="checkbox" | ||
className={classes.root} | ||
checkedIcon={<CheckOutlinedIcon />} | ||
disabled={disabled} | ||
checked={check} | ||
onChange={() => setChecked(!check)} | ||
inputProps={{ 'aria-label': 'decorative checkbox' }} | ||
/> | ||
); | ||
}; | ||
export { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { render, cleanup } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { KuberaThemeProvider } from '../../../theme'; | ||
import { CheckBox } from '../CheckBox'; | ||
|
||
afterEach(cleanup); | ||
jest.useFakeTimers(); | ||
|
||
describe('CheckBox', () => { | ||
it('Renders', () => { | ||
const { getByTestId } = render( | ||
<KuberaThemeProvider platform="kubera-chaos"> | ||
<CheckBox checked={false} disabled={false} /> | ||
</KuberaThemeProvider> | ||
); | ||
const checkbox = getByTestId('checkbox').querySelector( | ||
'input[type="checkbox"]' | ||
); | ||
expect(checkbox).toHaveProperty('checked', false); | ||
expect(checkbox).toHaveProperty('disabled', false); | ||
}); | ||
}); |
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 @@ | ||
export * from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { makeStyles, Theme } from '@material-ui/core'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
root: { | ||
'&:hover': { | ||
backgroundColor: 'transparent', | ||
}, | ||
width: '1.5rem', | ||
height: '1.5rem', | ||
'& svg': { | ||
display: 'none', | ||
}, | ||
}, | ||
'@global': { | ||
'.MuiCheckbox-root': { | ||
borderRadius: '0.1875rem', | ||
boxShadow: 'none', | ||
backgroundColor: 'transparent', | ||
borderWidth: '0.03125rem', | ||
borderStyle: 'solid', | ||
borderColor: theme.palette.border.main, | ||
'&:hover': { | ||
borderColor: theme.palette.secondary.main, | ||
}, | ||
'&:disabled': { | ||
borderColor: theme.palette.disabledBackground, | ||
}, | ||
}, | ||
'.Mui-checked': { | ||
borderColor: theme.palette.secondary.main, | ||
'& svg': { | ||
display: 'block', | ||
}, | ||
}, | ||
'.Mui-disabled': { | ||
borderColor: theme.palette.text.disabled, | ||
}, | ||
}, | ||
})); | ||
|
||
export { useStyles }; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change if I pass
Checkbox check={true}
and mutate the state here then checkbox would be unchecked but the place where we have implemented it still would remaintrue
which is a loopholeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@S-ayanide When passing the checkox checked paraemeter=true via props, then checkbox is being checked and when clicking on the checkbox, it becomes unchecked. And vica versa. If there is an issue, let me know pls