Skip to content

Commit e2718af

Browse files
authored
Merge pull request #8 from tableflowhq/feature/checkbox
Checkbox component, adjustments in Input/dropdown
2 parents e802cdb + 382909d commit e2718af

File tree

6 files changed

+96
-3
lines changed

6 files changed

+96
-3
lines changed

src/Checkbox/Checkbox.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ComponentMeta, ComponentStory } from "@storybook/react";
2+
import { iconsArray } from "../Icon/types";
3+
import CheckboxComponent from ".";
4+
import { CheckboxProps } from "./types";
5+
6+
export default {
7+
title: "User Interface/Checkbox",
8+
component: CheckboxComponent,
9+
} as ComponentMeta<typeof CheckboxComponent>;
10+
11+
const Template: ComponentStory<typeof CheckboxComponent> = (args: CheckboxProps) => <CheckboxComponent {...args} />;
12+
13+
export const Checkbox = Template.bind({});
14+
Checkbox.args = {
15+
label: "Text",
16+
};

src/Checkbox/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import classes from "../utils/classes";
2+
import { CheckboxProps } from "./types";
3+
import style from "./style/Checkbox.module.scss";
4+
5+
export default function Checkbox({ label, className, ...props }: CheckboxProps) {
6+
const containerClasses = classes([style.container, className]);
7+
8+
return (
9+
<label className={containerClasses}>
10+
<input type="checkbox" {...props} />
11+
<span>{label}</span>
12+
</label>
13+
);
14+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.container {
2+
display: inline-block;
3+
display: flex;
4+
gap: var(--m-xs);
5+
align-items: center;
6+
7+
&:has(input:not(:disabled)) {
8+
cursor: pointer;
9+
}
10+
11+
input[type="checkbox"] {
12+
-webkit-appearance: none;
13+
appearance: none;
14+
background-color: transparent;
15+
margin: 0;
16+
color: var(--color-primary);
17+
width: var(--m);
18+
height: var(--m);
19+
border: 2px solid var(--color-border);
20+
display: grid;
21+
place-content: center;
22+
border-radius: var(--border-radius-1);
23+
cursor: pointer;
24+
25+
&::before {
26+
content: "";
27+
width: var(--m-xs);
28+
height: var(--m-xs);
29+
}
30+
31+
&:checked {
32+
background-color: var(--color-primary);
33+
border-color: var(--color-primary);
34+
}
35+
36+
&:checked::before {
37+
clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
38+
box-shadow: inset 1em 1em var(--color-input-background);
39+
}
40+
41+
//&:not(:disabled) {
42+
// &:focus {
43+
// outline: 1px solid var(--color-border);
44+
// outline-offset: 3px;
45+
// }
46+
//}
47+
48+
&:disabled {
49+
--container-color: var(--container-disabled);
50+
color: var(--container-disabled);
51+
cursor: default;
52+
background-color: var(--color-input-disabled);
53+
}
54+
}
55+
}

src/Checkbox/types/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { InputHTMLAttributes, ReactElement } from "react";
2+
3+
export type CheckboxProps = InputHTMLAttributes<HTMLInputElement> & {
4+
label?: string | ReactElement;
5+
};

src/Input/style/Input.module.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
.inputWrapper {
3131
background-color: var(--color-input-background);
3232
border-radius: var(--border-radius-2);
33-
outline: 2px solid transparent;
33+
outline: 1px solid transparent;
3434
padding: calc(var(--m-xxs) / 2);
3535
border: 1px solid var(--color-border);
3636
font-weight: 400;
@@ -172,12 +172,13 @@
172172
background-color: var(--color-input-background);
173173
border-radius: var(--border-radius-2);
174174
padding: var(--m-xxxxs);
175-
outline: 2px solid var(--color-text);
175+
outline: 1px solid var(--color-border);
176176
display: flex;
177177
flex-direction: column;
178178
gap: var(--m-xxxxs);
179179
max-height: calc(100vh - 8px);
180180
overflow-y: auto;
181+
margin-top: var(--m-xxxxs);
181182
}
182183

183184
.option {

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import "./style/index.scss";
2727
import Badge from "./Badge";
2828
import Box from "./Box";
2929
import Button from "./Button";
30+
import Checkbox from "./Checkbox";
3031
import Dialog from "./Dialog";
3132
import Errors from "./Errors";
3233
import Icon from "./Icon";
@@ -48,6 +49,7 @@ export {
4849
Badge,
4950
Box,
5051
Button,
52+
Checkbox,
5153
Dialog,
5254
Errors,
5355
Frame,
@@ -65,7 +67,7 @@ export {
6567
Tabs,
6668
TagEditor,
6769
ThemeToggle,
68-
Tooltip
70+
Tooltip,
6971
};
7072

7173
export {

0 commit comments

Comments
 (0)