-
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 SubTabButtonList component (#509)
Co-authored-by: 長田淳史 <> Co-authored-by: koji endo <[email protected]> Co-authored-by: KaWaite <[email protected]>
- Loading branch information
1 parent
748d9db
commit 61c9378
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
web/src/beta/components/SubTabButtonList/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,21 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import SubTabButtonList from "."; | ||
|
||
const meta: Meta<typeof SubTabButtonList> = { | ||
component: SubTabButtonList, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof SubTabButtonList>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
items: [ | ||
{ id: "1", name: "GIS", active: true }, | ||
{ id: "2", name: "Story", active: false }, | ||
{ id: "3", name: "Web AR", 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,41 @@ | ||
import Text from "@reearth/beta/components/Text"; | ||
import { SwitchField } from "@reearth/beta/hooks/useManageSwitchState/hooks"; | ||
import { styled, useTheme } from "@reearth/services/theme"; | ||
|
||
type CustomField = { | ||
name: string; | ||
}; | ||
type SwitchCustomField = SwitchField<CustomField>; | ||
|
||
export type Props = { | ||
items: SwitchCustomField[]; | ||
onChange?: (id: string) => void; | ||
}; | ||
const SubTabButtonList: React.FC<Props> = ({ items, onChange }) => { | ||
const theme = useTheme(); | ||
return ( | ||
<> | ||
{items.map((item, index) => ( | ||
<SubTabButton key={index} disabled={!!item?.active} onClick={() => onChange?.(item.id)}> | ||
<Text size="footnote" color={theme.general.content.main}> | ||
{item.name} | ||
</Text> | ||
</SubTabButton> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
const SubTabButton = styled.button<{ disabled: boolean }>` | ||
background: ${({ disabled, theme }) => (disabled ? theme.general.select : "inherit")}; | ||
padding: 8px; | ||
height: 32px; | ||
border-radius: 4px 4px 0px 0px; | ||
transition: all 0.5s; | ||
:hover { | ||
background: ${({ theme }) => theme.general.select}; | ||
} | ||
text-align: center; | ||
`; | ||
|
||
export default SubTabButtonList; |
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