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

chore(web): Add CheckboxField component #508

Merged
merged 9 commits into from
Jun 28, 2023
18 changes: 18 additions & 0 deletions web/src/beta/components/CheckboxField/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Meta, StoryObj } from "@storybook/react";

import CheckBoxField from ".";

const meta: Meta<typeof CheckBoxField> = {
component: CheckBoxField,
};

export default meta;

type Story = StoryObj<typeof CheckBoxField>;

export const Default: Story = {
args: {
label: "takanawa_3D_Tiles",
checked: false,
},
};
57 changes: 57 additions & 0 deletions web/src/beta/components/CheckboxField/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { FC } from "react";

import { styled, useTheme, PublishTheme } from "@reearth/services/theme";

import Icon from "../Icon";
import Text from "../Text";

export type Props = {
publishedTheme?: PublishTheme;
onClick?: (value: boolean) => void;
checked?: boolean;
label: string;
};

const CheckBoxField: FC<Props> = ({ onClick, checked, label, publishedTheme }) => {
const theme = useTheme();
return (
<Field>
<BoxFeild
onClick={() => onClick?.(checked !== undefined ? checked : false)}
publishedTheme={publishedTheme}>
{checked && <CheckMark icon="checkmark" publishedTheme={publishedTheme} />}
</BoxFeild>
{label && (
<Text size="xs" color={publishedTheme?.mainText || theme.main.text}>
{label}
</Text>
)}
</Field>
);
};

const Field = styled.div`
isoppp marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
align-items: center;
gap: 12px;
width: 100%;
height: 20px;
`;

const BoxFeild = styled.button<{ publishedTheme?: PublishTheme }>`
box-sizing: border-box;
width: 20px;
height: 20px;
border: 1px solid ${({ theme, publishedTheme }) => publishedTheme?.weakText || theme.main.weak};
border-radius: 4px;
`;

const CheckMark = styled(Icon)<{ publishedTheme?: PublishTheme }>`
padding-left: 15%;
padding-right: 10%;
padding-top: 25%;
padding-bottom: 20.83%;
isoppp marked this conversation as resolved.
Show resolved Hide resolved
color: ${({ theme, publishedTheme }) => publishedTheme?.mainText || theme.main.text};
`;

export default CheckBoxField;
3 changes: 3 additions & 0 deletions web/src/beta/components/Icon/Icons/checkMark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions web/src/beta/components/Icon/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Crosshair from "./Icons/crosshair.svg";
import PlusSquare from "./Icons/plusSquare.svg";
import Cancel from "./Icons/cancel.svg";
import ActionButton from "./Icons/actionButton.svg";
import CheckMark from "./Icons/checkMark.svg";

// Dataset
import File from "./Icons/fileIcon.svg";
Expand Down Expand Up @@ -57,4 +58,5 @@ export default {
playLeft: PlayLeft,
timeline: Timeline,
actionbutton: ActionButton,
checkmark: CheckMark,
};