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 SwitchButtonList Component #526

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

import SwitchButtonList from ".";

export default {
component: SwitchButtonList,
} as Meta;

type Story = StoryObj<typeof SwitchButtonList>;

export const Default: Story = {
args: {
list: [
{ id: "1", text: "PC", active: true },
{ id: "2", text: "Ipad", active: false },
{ id: "3", text: "Phone", active: false },
],
},
};
54 changes: 54 additions & 0 deletions web/src/beta/components/SwitchButtonList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Text from "@reearth/beta/components/Text";
import { SwitchField } from "@reearth/beta/hooks/useManageSwitchState/hooks";
import { styled, useTheme } from "@reearth/services/theme";

type AdditionalField = {
text: string;
};
type SwitchAdditionalField = SwitchField<AdditionalField>;

export type Props = {
list: SwitchAdditionalField[];
onChange?: (id: string) => void;
};
const SwitchButtonList: React.FC<Props> = ({ list, onChange }) => {
const theme = useTheme();
return (
<>
{list.map((item, index) => (
<SwitchButton
key={index}
disabled={!!item?.active}
onClick={() => onChange?.(item.id)}
first={index === 0}
end={index === list.length - 1}>
<Text
size="footnote"
color={item.active ? theme.general.content.strong : theme.general.content.main}>
{item.text}
</Text>
</SwitchButton>
))}
</>
);
};
const SwitchButton = styled.button<{
disabled: boolean;
first: boolean;
end: boolean;
}>`
background: ${props =>
props.disabled ? props.theme.general.select : props.theme.general.bg.strong};
padding: 8px;
height: 32px;
border-top-left-radius: ${props => (props.first ? "4px" : "0px")};
border-top-right-radius: ${props => (props.end ? "4px" : "0px")};
border-bottom-left-radius: ${props => (props.first ? "4px" : "0px")};
border-bottom-right-radius: ${props => (props.end ? "4px" : "0px")};
transition: all 0.5s ease;
:hover {
background: ${props => props.theme.general.select};
}
`;

export default SwitchButtonList;