-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ButtonMenu * refactor: Removed ButtonMenuItem styled component
- Loading branch information
1 parent
855e648
commit 1a85549
Showing
10 changed files
with
142 additions
and
34 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
import { ButtonHTMLAttributes, ReactNode } from "react"; | ||
|
||
export const sizes = { | ||
SM: "sm", | ||
MD: "md", | ||
} as const; | ||
|
||
export const variants = { | ||
PRIMARY: "primary", | ||
SECONDARY: "secondary", | ||
OUTLINE: "outline", | ||
TEXT: "text", | ||
} as const; | ||
|
||
export type Sizes = typeof sizes[keyof typeof sizes]; | ||
export type Variants = typeof variants[keyof typeof variants]; | ||
|
||
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
variant?: Variants; | ||
size?: Sizes; | ||
startIcon?: ReactNode; | ||
endIcon?: ReactNode; | ||
} |
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,10 @@ | ||
import React from "react"; | ||
import Button from "../Button"; | ||
import { sizes } from "../Button/types"; | ||
import { ButtonMenuItemProps } from "./types"; | ||
|
||
const ButtonMenuItem: React.FC<ButtonMenuItemProps> = ({ isActive = false, size = sizes.MD, ...props }) => { | ||
return <Button variant={isActive ? "primary" : "secondary"} size={size} {...props} />; | ||
}; | ||
|
||
export default ButtonMenuItem; |
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,9 @@ | ||
import styled from "styled-components"; | ||
|
||
const StyledButtonMenu = styled.div` | ||
background-color: ${({ theme }) => theme.colors.tertiary}; | ||
border-radius: 16px; | ||
display: inline-flex; | ||
`; | ||
|
||
export default StyledButtonMenu; |
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,49 @@ | ||
import React, { useState } from "react"; | ||
import styled from "styled-components"; | ||
/* eslint-disable import/no-unresolved */ | ||
import { Meta } from "@storybook/react/types-6-0"; | ||
import ButtonMenu from "./index"; | ||
import ButtonMenuItem from "./ButtonMenuItem"; | ||
|
||
const Row = styled.div` | ||
margin-bottom: 32px; | ||
& > button + button { | ||
margin-left: 16px; | ||
} | ||
`; | ||
|
||
export default { | ||
title: "Button Menu", | ||
component: ButtonMenu, | ||
argTypes: {}, | ||
} as Meta; | ||
|
||
export const Default: React.FC = () => { | ||
const [index, setIndex] = useState(0); | ||
const [index1, setIndex1] = useState(1); | ||
|
||
const handleClick = (newIndex) => setIndex(newIndex); | ||
const handleClick1 = (newIndex) => setIndex1(newIndex); | ||
|
||
return ( | ||
<> | ||
<Row> | ||
<ButtonMenu activeIndex={index} onClick={handleClick}> | ||
<ButtonMenuItem>Button 1</ButtonMenuItem> | ||
<ButtonMenuItem>Button 2</ButtonMenuItem> | ||
<ButtonMenuItem>Button 3</ButtonMenuItem> | ||
<ButtonMenuItem>Button 4</ButtonMenuItem> | ||
</ButtonMenu> | ||
</Row> | ||
<Row> | ||
<ButtonMenu activeIndex={index1} onClick={handleClick1} size="sm"> | ||
<ButtonMenuItem>Button 1</ButtonMenuItem> | ||
<ButtonMenuItem>Button 2</ButtonMenuItem> | ||
<ButtonMenuItem>Button 3</ButtonMenuItem> | ||
<ButtonMenuItem>Button 4</ButtonMenuItem> | ||
</ButtonMenu> | ||
</Row> | ||
</> | ||
); | ||
}; |
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,17 @@ | ||
import React, { cloneElement, Children, ReactElement } from "react"; | ||
import StyledButtonMenu from "./StyledButtonMenu"; | ||
import { sizes } from "../Button/types"; | ||
import { ButtonMenuProps, ButtonMenuItemProps } from "./types"; | ||
|
||
const ButtonMenu: React.FC<ButtonMenuProps> = ({ activeIndex = 0, size = sizes.MD, onClick, children }) => { | ||
return ( | ||
<StyledButtonMenu> | ||
{Children.map(children, (child: ReactElement<ButtonMenuItemProps>, index) => { | ||
const handleClick = () => onClick && onClick(index); | ||
return cloneElement(child, { isActive: activeIndex === index, onClick: handleClick, size }); | ||
})} | ||
</StyledButtonMenu> | ||
); | ||
}; | ||
|
||
export default ButtonMenu; |
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,13 @@ | ||
import { ButtonProps, Sizes } from "../Button/types"; | ||
|
||
export interface ButtonMenuItemProps extends ButtonProps { | ||
isActive?: boolean; | ||
size?: Sizes; | ||
} | ||
|
||
export interface ButtonMenuProps { | ||
activeIndex?: number; | ||
onClick?: (index: number) => void; | ||
size?: Sizes; | ||
children: React.ReactElement[]; | ||
} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as Button } from "./components/Button"; | ||
export { default as ButtonMenu } from "./components/ButtonMenu"; | ||
export { default as ButtonMenuItem } from "./components/ButtonMenu/ButtonMenuItem"; | ||
export { default as ResetCSS } from "./ResetCSS"; | ||
|
||
export * from "./theme"; |