Skip to content

Commit

Permalink
feat(checkbox): Added scale (#68)
Browse files Browse the repository at this point in the history
* feat(checkbox): Added scale

* chore(checkbox): Renamed function

Co-authored-by: RabbitDoge <72658581+RabbitDoge@users.noreply.github.com>
  • Loading branch information
hachiojidev and RabbitDoge committed Nov 25, 2020
1 parent 60e6e41 commit 0c1d224
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/components/Checkbox/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ export default {

export const Default: React.FC = () => {
return (
<div>
<Checkbox />
</div>
<>
<div style={{ marginBottom: "32px" }}>
<Checkbox />
</div>
<div>
<Checkbox scale="sm" />
</div>
</>
);
};
21 changes: 18 additions & 3 deletions src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import styled from "styled-components";
import { CheckboxProps, scales } from "./types";

const Checkbox = styled.input.attrs({ type: "checkbox" })`
const getScale = ({ scale }: CheckboxProps) => {
switch (scale) {
case scales.SM:
return "24px";
case scales.MD:
default:
return "32px";
}
};

const Checkbox = styled.input.attrs({ type: "checkbox" })<CheckboxProps>`
appearance: none;
overflow: hidden;
cursor: pointer;
position: relative;
display: inline-block;
height: 32px;
width: 32px;
height: ${getScale};
width: ${getScale};
vertical-align: middle;
transition: background-color 0.2s ease-in-out;
border: 0;
Expand Down Expand Up @@ -46,4 +57,8 @@ const Checkbox = styled.input.attrs({ type: "checkbox" })`
}
`;

Checkbox.defaultProps = {
scale: scales.MD,
};

export default Checkbox;
10 changes: 10 additions & 0 deletions src/components/Checkbox/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const scales = {
SM: "sm",
MD: "md",
} as const;

export type Scales = typeof scales[keyof typeof scales];

export interface CheckboxProps {
scale?: Scales;
}

0 comments on commit 0c1d224

Please sign in to comment.