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

[WIP]: added new ui component checkbox #34

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
9 changes: 9 additions & 0 deletions src/components/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ const Template: Story<ComponentProps<typeof Checkbox>> = (props: any) => (
);

export const Basic = Template.bind({});
export const Disabled = Template.bind({});


Basic.args = {
name: 'chkbox1',
label: 'Checkbox label',
variant: 'basic',
};
Disabled.args = {
name: 'chkbox2',
label: 'Checkbox label',
variant: 'basic',
disabled: false,
};

46 changes: 39 additions & 7 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Flex } from '../Flex';
import { getMargin, visuallyHidden } from '../../theme/utils';
import { Icon } from '../Icon';
import { polyIcons } from '../../theme';
import { width } from 'styled-system';

export type CheckboxVariant = 'basic';

Expand All @@ -13,6 +14,7 @@ export type CheckboxProps = {
onChange?: ChangeEventHandler<HTMLInputElement>;
defaultChecked?: boolean;
checked?: boolean;
disabled?: boolean;
name?: string;
label?: React.ComponentType | JSX.Element | string;
indeterminate?: boolean;
Expand Down Expand Up @@ -45,26 +47,53 @@ const MinusBoxIcon = styled(Icon)<any>(() => ({
margin: 'auto',
transition: `150ms`,
}));

const CheckboxInput = styled.div(({ theme }) => ({
// const LabelComponent = styled.label<{ variant: string; margin?: string }>(
// ({ theme, variant, margin }) => ({
// ...(theme.CHECKBOX[variant] || {}),
// ...(margin
// ? {
// display: 'inline-block',
// margin: getMargin({ theme, margin }),
// }
// : {}),
// }),
// );
const CheckboxInput = styled.div<{disabled: boolean}>(({ theme, disabled }) => ({
position: 'relative',
cursor: 'pointer',
transition: `200ms`,
boxSizing: 'border-box',
border: `2px solid ${theme.COLOR.gray3}`,
border: `2px solid ${disabled ? 'blue' : 'red'}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to pull the color codes from the new theme instead of hardcoding them.

Copy link
Author

Choose a reason for hiding this comment

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

fixed it please check

borderRadius: theme.RADIUS.s,
minWidth: '1.125rem',
minHeight: '1.125rem',
backgroundColor: '#fff',
userSelect: 'none',

[`${Input}:focus + &`]: {
borderColor: theme.COLOR.brandMain,
border: `2px solid #5B9EF8`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check for hardcoded color name

Copy link
Author

Choose a reason for hiding this comment

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

fixed it please check

position: 'relative',
padding: '12px',
zIndex: '1',
},

[`${Input}:checked:focus + &`]: {
borderColor: theme.COLOR.gray5,
border: `2px solid #5B9EF8`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check for hardcoded color name

Copy link
Author

Choose a reason for hiding this comment

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

fixed it please check

padding: '12px',
},
[`${Input}:checked:focus + ::before + &`]: {
backgroundColor: 'red',
content: ' ',
position: 'absolute',
zIndex: '-1',
top: '5px',
left: '5px',
right: '5px',
bottom: '5px',
border: '115px solid #ffea00'
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check for hardcoded color name

Copy link

@lbrekhov lbrekhov Oct 17, 2022

Choose a reason for hiding this comment

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

Hey, what you mean here?
To extract into a variable?

},
[`${Input}:checked:disabled + &`]: {
backgroundColor: 'red',
},

[`${Input}:checked + &`]: {
backgroundColor: theme.COLOR.gray5,
Expand Down Expand Up @@ -124,12 +153,13 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
label,
indeterminate,
name,
disabled,
...props
} = checkboxProps;

const checkedProps =
typeof checked !== 'undefined' ? { checked } : { defaultChecked };

const isDisabled = true
return (
<LabelComponent variant={variant} margin={margin}>
<Flex variant="raw" align="center">
Expand All @@ -142,6 +172,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
type="checkbox"
/>
<CheckboxInput
disabled={!isDisabled}
{...(indeterminate ? { className: 'indeterminate' } : {})}
>
<MinusBoxIcon
Expand All @@ -157,6 +188,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
className="checkIcon"
/>
</CheckboxInput>
<div></div>
<Fragment key={`${name}Label`}>
{typeof label === 'string' ? (
<Label variant="raw">{label}</Label>
Expand Down