Skip to content

Commit

Permalink
chore(web): Add SwitchButtonList Component (#526)
Browse files Browse the repository at this point in the history
Co-authored-by: JAESUNG_PARK <[email protected]>
Co-authored-by: 長田淳史 <>
Co-authored-by: KaWaite <[email protected]>
  • Loading branch information
3 people authored Jul 3, 2023
1 parent b49f0ff commit 34c54f7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
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;

0 comments on commit 34c54f7

Please sign in to comment.