-
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
Changes from 5 commits
f8206c9
f3ee9c7
4567210
2d13d60
95fe63f
bcda10f
f0e7d2e
bb6f381
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
)); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,28 @@ | ||||||
import { Checkbox } from '@material-ui/core'; | ||||||
import React, { useState } from 'react'; | ||||||
// import clsx from 'clsx'; | ||||||
import CheckOutlinedIcon from '@material-ui/icons/CheckOutlined'; | ||||||
import { useStyles } from './styles'; | ||||||
import { BaseCheckboxProps } from './base'; | ||||||
|
||||||
interface CheckBoxProps extends BaseCheckboxProps { | ||||||
checked: boolean; | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checkbox API already provides |
||||||
|
||||||
const CheckBox: React.FC<CheckBoxProps> = ({ disabled, checked }) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const classes = useStyles(); | ||||||
const [check, setChecked] = useState<boolean>(checked); | ||||||
return ( | ||||||
<Checkbox | ||||||
data-testid="checkbox" | ||||||
className={classes.root} | ||||||
checkedIcon={<CheckOutlinedIcon />} | ||||||
disabled={disabled} | ||||||
checked={check} | ||||||
icon={<span></span>} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not required. It's an empty span. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @S-ayanide This icon appears when checkbox is unchecked and when I delete that icon design breaks,this empty span is required There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a way around. if you take a look at the third checkbox from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a workaround for this |
||||||
onChange={() => setChecked(!check)} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this change if I pass There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
inputProps={{ 'aria-label': 'decorative checkbox' }} | ||||||
/> | ||||||
); | ||||||
}; | ||||||
export { CheckBox }; |
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); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { CheckboxProps } from '@material-ui/core/Checkbox'; | ||
|
||
export type BaseCheckboxProps = Omit<CheckboxProps, 'checked'>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here This |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './CheckBox'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { makeStyles, Theme } from '@material-ui/core'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
root: { | ||
'&:hover': { | ||
backgroundColor: 'transparent', | ||
}, | ||
width: '1.5rem', | ||
height: '1.5rem', | ||
}, | ||
'@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, | ||
}, | ||
'.Mui-disabled': { | ||
borderColor: theme.palette.text.disabled, | ||
}, | ||
}, | ||
})); | ||
|
||
export { useStyles }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './Button'; | ||
export * from './CheckBox'; | ||
export * from './Pills'; |
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.
Can you please remove commented lines!