Skip to content
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
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"types": "index.d.ts",
"dependencies": {
"@material-ui/core": "^4.10.2",
"@material-ui/icons": "^4.9.1",
"react": "^16.9.0",
"react-dom": "^16.9.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { storiesOf } from '@storybook/react';
import React from 'react';
import { ThemedBackground } from '../../../utils/storybook';
import { ThemedBackground } from '../../utils/storybook';
import { CheckBox } from '../CheckBox';

storiesOf('CheckBox/CheckBox default', module)
storiesOf('CheckBox', module)
// Litmus Portal
.add('Litmus Portal', () => (
<ThemedBackground platform="litmus-portal" row>
<CheckBox checked={true} disabled={false} />
<CheckBox checked={true} disabled={true} />
</ThemedBackground>
))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Checkbox } from '@material-ui/core';
import React, { useState } from 'react';
import clsx from 'clsx';
// import clsx from 'clsx';
Copy link
Contributor

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!

import CheckOutlinedIcon from '@material-ui/icons/CheckOutlined';
import { useStyles } from './styles';
import { BaseCheckboxProps } from '../base';
import { BaseCheckboxProps } from './base';

interface CheckBoxProps extends BaseCheckboxProps {
disabled: boolean;
checked: boolean;
}

const CheckBox: React.FC<CheckBoxProps> = ({ disabled, checked }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const CheckBox: React.FC<CheckBoxProps> = ({ disabled, checked }) => {
const CheckBox: React.FC = ({ disabled, checked }) => {

const classes = useStyles();
const [check, setChecked] = useState<boolean>(checked);
const iconClass = check ? classes.checkedIcon : classes.icon;
return (
<Checkbox
data-testid="checkbox"
className={classes.root}
checkedIcon={<span className={clsx(classes.icon, classes.checkedIcon)} />}
checkedIcon={<CheckOutlinedIcon />}
disabled={disabled}
checked={check}
icon={<span></span>}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required. It's an empty span.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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 Basic Checkbox here you'll find they don't use icons as a parameter at all still you can check and uncheck without breaking the design.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a workaround for this icon parameter! Did the above reference help?

onChange={() => setChecked(!check)}
Copy link
Contributor

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 remain true which is a loophole

Copy link
Contributor Author

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

icon={<span className={iconClass} />}
inputProps={{ 'aria-label': 'decorative checkbox' }}
/>
);
Expand Down
15 changes: 0 additions & 15 deletions src/core/CheckBox/CheckBox/__tests__/CheckBox.test.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/core/CheckBox/CheckBox/index.ts

This file was deleted.

63 changes: 0 additions & 63 deletions src/core/CheckBox/CheckBox/styles.ts

This file was deleted.

17 changes: 17 additions & 0 deletions src/core/CheckBox/__tests__/CheckBox.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { render, fireEvent } from '@testing-library/react';
import React from 'react';
import { KuberaThemeProvider } from '../../../theme';
import { CheckBox } from '../CheckBox';

describe('CheckBox', () => {
it('Renders', () => {
const { getByTestId } = render(
<KuberaThemeProvider platform="kubera-chaos">
<CheckBox checked={false} disabled={false} />
</KuberaThemeProvider>
);
let checkbox = getByTestId('checkbox') as HTMLInputElement;
fireEvent.click(checkbox);
expect(checkbox.checked).toBeFalsy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come if the initial value is false....after clicking it becomes false again (toBeFalsy)
Can you explain the test cases in the comments on what is being done...
I might have misunderstood it too...apologies for that...if that's the case...but regardless explanation for test cases is good

});
});
2 changes: 1 addition & 1 deletion src/core/CheckBox/base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { CheckboxProps } from '@material-ui/core/Checkbox';

export type BaseCheckboxProps = Omit<CheckboxProps, 'disabled' | 'checked'>;
export type BaseCheckboxProps = Omit<CheckboxProps, 'checked'>;
37 changes: 37 additions & 0 deletions src/core/CheckBox/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { makeStyles, Theme } from '@material-ui/core';

const useStyles = makeStyles((theme: Theme) => ({
root: {
'&:hover': {
backgroundColor: 'transparent',
},
'& svg': {
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 };
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './Button';
export * from './CheckBox';
export * from './Pills';
You are viewing a condensed version of this merge commit. You can view the full changes here.