-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(web): Add SwitchButtonList Component (#526)
Co-authored-by: JAESUNG_PARK <[email protected]> Co-authored-by: 長田淳史 <> Co-authored-by: KaWaite <[email protected]>
- Loading branch information
1 parent
b49f0ff
commit 34c54f7
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
web/src/beta/components/SwitchButtonList/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |