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
39 changes: 39 additions & 0 deletions src/core/CheckBox/CheckBox/CheckBox.stories.tsx
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/CheckBox default', module)
// Litmus Portal
.add('Litmus Portal', () => (
<ThemedBackground platform="litmus-portal" row>
<CheckBox checked={true} disabled={false} />
</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>
));
28 changes: 28 additions & 0 deletions src/core/CheckBox/CheckBox/CheckBox.tsx
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 { useStyles } from './styles';
import { BaseCheckboxProps } from '../base';

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

const CheckBox: React.FC<CheckBoxProps> = ({ disabled, checked }) => {
const classes = useStyles();
const [check, setChecked] = useState<boolean>(checked);
const iconClass = check ? classes.checkedIcon : classes.icon;
return (
<Checkbox
className={classes.root}
checkedIcon={<span className={clsx(classes.icon, classes.checkedIcon)} />}
disabled={disabled}
checked={check}
onChange={() => setChecked(!check)}
icon={<span className={iconClass} />}
inputProps={{ 'aria-label': 'decorative checkbox' }}
/>
);
};
export { CheckBox };
15 changes: 15 additions & 0 deletions src/core/CheckBox/CheckBox/__tests__/CheckBox.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { render } from '@testing-library/react';
import React from 'react';
import { KuberaThemeProvider } from '../../../../theme';
import { CheckBox } from '../CheckBox';

describe('CheckBox', () => {
it('Renders', () => {
const { container } = render(
<KuberaThemeProvider platform="kubera-chaos">
<CheckBox checked={false} disabled={false} />
</KuberaThemeProvider>
);
container.querySelector('input');
S-ayanide marked this conversation as resolved.
Show resolved Hide resolved
});
});
1 change: 1 addition & 0 deletions src/core/CheckBox/CheckBox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CheckBox';
63 changes: 63 additions & 0 deletions src/core/CheckBox/CheckBox/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { makeStyles, Theme } from '@material-ui/core';

const useStyles = makeStyles((theme: Theme) => ({
root: {
'&:hover': {
backgroundColor: 'transparent',
},
'& span': {
borderRadius: '0.1875rem',
boxShadow: 'none',
backgroundColor: 'transparent',
},
},
icon: {
width: '1.5rem',
height: '1.5rem',
borderWidth: '0.03125rem',
borderStyle: 'solid',
borderColor: theme.palette.border.main,
'input:hover ~ &': {
borderColor: theme.palette.secondary.main,
},
'input:disabled ~ &': {
borderColor: theme.palette.disabledBackground,
},
},
checkedIcon: {
width: '1.5rem',
height: '1.5rem',
borderWidth: '0.03125rem',
borderStyle: 'solid',
borderColor: theme.palette.secondary.main,
'input:disabled ~ &': {
borderColor: theme.palette.disabledBackground,
'&:before': {
display: 'block',
width: '1.375rem',
height: '1.375rem',
backgroundImage:
S-ayanide marked this conversation as resolved.
Show resolved Hide resolved
"url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath" +
" fill-rule='evenodd' clip-rule='evenodd' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 " +
"1.003 0 00-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0012 5z' fill='%23" +
theme.palette.disabledBackground.split('#')[1] +
'\'/%3E%3C/svg%3E")',
content: '""',
},
},
'&:before': {
display: 'block',
width: '1.375rem',
height: '1.375rem',
backgroundImage:
"url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath" +
" fill-rule='evenodd' clip-rule='evenodd' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 " +
"1.003 0 00-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0012 5z' fill='%23" +
theme.palette.secondary.main.split('#')[1] +
'\'/%3E%3C/svg%3E")',
content: '""',
},
},
}));

export { useStyles };
3 changes: 3 additions & 0 deletions src/core/CheckBox/base.ts
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, 'disabled' | 'checked'>;
S-ayanide marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/core/CheckBox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CheckBox';
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Button';
export * from './CheckBox';