Skip to content

Commit

Permalink
chore(web): Add SidePanelSectionField component (#505)
Browse files Browse the repository at this point in the history
Co-authored-by: koji endo <[email protected]>
Co-authored-by: KaWaite <[email protected]>
  • Loading branch information
3 people authored Jun 23, 2023
1 parent eaed817 commit 4b70565
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions web/src/beta/components/Icon/Icons/arrowToggle.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 @@ -18,6 +18,7 @@ import ArrowRight from "./Icons/arrowRight.svg";
import ArrowLongLeft from "./Icons/arrowLongLeft.svg";
import ArrowLongRight from "./Icons/arrowLongRight.svg";
import ArrowDown from "./Icons/arrowDown.svg";
import ArrowToggle from "./Icons/arrowToggle.svg";

// Indicator
import Crosshair from "./Icons/crosshair.svg";
Expand Down Expand Up @@ -60,6 +61,7 @@ export default {
arrowLongLeft: ArrowLongLeft,
arrowLongRight: ArrowLongRight,
arrowDown: ArrowDown,
arrowToggle: ArrowToggle,
cancel: Cancel,
crosshair: Crosshair,
plusSquare: PlusSquare,
Expand Down
24 changes: 24 additions & 0 deletions web/src/beta/components/SidePanelSectionField/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Meta, StoryObj } from "@storybook/react";

import Component from ".";

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

export default meta;

type Story = StoryObj<typeof Component>;

export const Default: Story = {
args: {
title: "Title",
children: <p>Item</p>,
},
};

export const Empty: Story = {
args: {
title: "Title",
},
};
55 changes: 55 additions & 0 deletions web/src/beta/components/SidePanelSectionField/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { useState, ReactNode } from "react";

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

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

const SidePanelSectionField: React.FC<{
title: string;
children?: ReactNode;
}> = ({ title, children }) => {
const theme = useTheme();
const [opened, setOpened] = useState(false);

return (
<Field>
<Header onClick={() => setOpened(!opened)}>
<Text
size="footnote"
color={theme.general.content.strong}
otherProperties={{ height: "16px" }}>
{title}
</Text>
<ArrowIcon
icon="arrowToggle"
size={12}
color={theme.general.content.main}
opened={opened}
/>
</Header>
{opened && children}
</Field>
);
};

const Field = styled.div`
box-sizing: border-box;
border-bottom: 1px solid ${props => props.theme.general.bg.weak};
`;
const Header = styled.div`
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px;
height: 32px;
cursor: pointer;
`;
const ArrowIcon = styled(Icon)<{ opened: boolean }>`
transform: rotate(${props => (props.opened ? 90 : 180)}deg);
`;

export default SidePanelSectionField;

0 comments on commit 4b70565

Please sign in to comment.