-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TabMenu) - Adding TabMenu to UI kit (with correct rebasing) (#19)
* chore(tab-menu): Rough component setup * chore(tab-menu): Testing user * style(styled-tab): V rough component layout and styles * style(styled-tab): Specific styles applied * style(styled-tab): Refinding styles and element types * fix(tab-menu): Tidy interfaces and props being passed to tab-bar * test(tab-menu): Added snapshot * style(tab-menu): Update comp names and add extra stories * chore(tab-menu): Remove unused commented code * test(tab-menu): Fix incorrect test import * style(tab-menu): Add width % handling below 576px * test(tab-menu): Update snaps * test(tab-menu): Remove test files from this PR - see #1 for proposal on implementing tests * style(tab-menu): Move away from % widths and towards flex-grow * style(tab-menu): Set 8px min padding to tab * style(tab-menu): Fix import order * style(tab-menu): Remove styled tabmenu comp and move into tabmenu * style(tab-menu): Change breakpoint for style change to 853px * test(tab-menu): Add tabmenu test file * test(tab-menu): Remove duplicate setupTests * fix(tab-menu): Del & regenerate yarn.lock
- Loading branch information
Showing
8 changed files
with
216 additions
and
15 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/pancake-uikit/src/__tests__/components/tabmenu.test.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,50 @@ | ||
import React from "react"; | ||
import { renderWithTheme } from "../../testHelpers"; | ||
import { TabMenu, Tab } from "../../components/TabMenu"; | ||
|
||
const handleClick = jest.fn(); | ||
|
||
it("renders correctly", () => { | ||
const { asFragment } = renderWithTheme( | ||
<TabMenu activeIndex={0} onItemClick={handleClick}> | ||
<Tab>Item 1</Tab> | ||
<Tab>Item 2</Tab> | ||
</TabMenu> | ||
); | ||
expect(asFragment()).toMatchInlineSnapshot(` | ||
<DocumentFragment> | ||
<div | ||
class="sc-bdfBwQ sc-gsTCUz sc-dlfnbm iwJkGQ ckYhbt hfSAvK" | ||
> | ||
<div | ||
class="sc-bdfBwQ sc-gsTCUz sc-hKgILt iwJkGQ ckYhbt kGuCa-d" | ||
> | ||
<button | ||
class="sc-eCssSg ixipzp" | ||
color="card" | ||
> | ||
<div | ||
class="sc-jSgupP dTcSYX" | ||
color="card" | ||
font-weight="600" | ||
> | ||
Item 1 | ||
</div> | ||
</button> | ||
<button | ||
class="sc-eCssSg bTcWnb" | ||
color="textSubtle" | ||
> | ||
<div | ||
class="sc-jSgupP fEsPNW" | ||
color="textSubtle" | ||
font-weight="600" | ||
> | ||
Item 2 | ||
</div> | ||
</button> | ||
</div> | ||
</div> | ||
</DocumentFragment> | ||
`); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/pancake-uikit/src/components/TabMenu/StyledTab.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,26 @@ | ||
import styled from "styled-components"; | ||
|
||
interface StyledTabProps { | ||
color: "card" | "textSubtle"; | ||
bgColor: "textSubtle" | "input"; | ||
} | ||
|
||
const StyledTab = styled.button<StyledTabProps>` | ||
display: inline-flex; | ||
justify-content: center; | ||
cursor: pointer; | ||
border: 0; | ||
outline: 0; | ||
flex-grow: 1; | ||
padding: 8px; | ||
border-radius: 16px 16px 0 0; | ||
color: ${({ theme, color }) => theme.colors[color]}; | ||
background-color: ${({ theme, bgColor }) => theme.colors[bgColor]}; | ||
${({ theme }) => theme.mediaQueries.md} { | ||
flex-grow: 0; | ||
padding: 8px 12px; | ||
} | ||
`; | ||
|
||
export default StyledTab; |
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,15 @@ | ||
import React from "react"; | ||
import StyledTab from "./StyledTab"; | ||
import { TabProps } from "./types"; | ||
import { Text } from "../Text"; | ||
|
||
const Tab: React.FC<TabProps> = ({ isActive = false, onClick, children }) => { | ||
return ( | ||
<StyledTab onClick={onClick} bgColor={isActive ? "textSubtle" : "input"} color={isActive ? "card" : "textSubtle"}> | ||
<Text fontWeight={600} color={isActive ? "card" : "textSubtle"}> | ||
{children} | ||
</Text> | ||
</StyledTab> | ||
); | ||
}; | ||
export default Tab; |
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,46 @@ | ||
import React, { cloneElement, Children, ReactElement } from "react"; | ||
import styled from "styled-components"; | ||
import Flex from "../Box/Flex"; | ||
import { TabMenuProps } from "./types"; | ||
|
||
const Wrapper = styled(Flex)` | ||
border-bottom: 2px solid ${({ theme }) => theme.colors.textSubtle}; | ||
padding: 0 16px; | ||
overflow-y: scroll; | ||
::-webkit-scrollbar { | ||
display: none; | ||
} | ||
-ms-overflow-style: none; /* IE and Edge */ | ||
scrollbar-width: none; /* Firefox */ | ||
`; | ||
|
||
const Inner = styled(Flex)` | ||
justify-content: space-between; | ||
flex-grow: 1; | ||
& > button + button { | ||
margin-left: 4px; | ||
} | ||
${({ theme }) => theme.mediaQueries.md} { | ||
flex-grow: 0; | ||
} | ||
`; | ||
|
||
const ButtonMenu: React.FC<TabMenuProps> = ({ activeIndex = 0, onItemClick, children }) => { | ||
return ( | ||
<Wrapper> | ||
<Inner> | ||
{Children.map(children, (child: ReactElement, index) => { | ||
return cloneElement(child, { | ||
isActive: activeIndex === index, | ||
onClick: onItemClick ? () => onItemClick(index) : undefined, | ||
}); | ||
})} | ||
</Inner> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default ButtonMenu; |
52 changes: 52 additions & 0 deletions
52
packages/pancake-uikit/src/components/TabMenu/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,52 @@ | ||
import React, { useState } from "react"; | ||
import styled from "styled-components"; | ||
/* eslint-disable import/no-unresolved */ | ||
import { Meta } from "@storybook/react/types-6-0"; | ||
import TabMenu from "./TabMenu"; | ||
import Tab from "./Tab"; | ||
|
||
export default { | ||
title: "Components/Tab Menu", | ||
component: TabMenu, | ||
argTypes: {}, | ||
} as Meta; | ||
|
||
const Row = styled.div` | ||
margin-bottom: 32px; | ||
`; | ||
|
||
export const Default: React.FC = () => { | ||
const [index, setIndex] = useState(0); | ||
const [index2, setIndex2] = useState(0); | ||
const [index3, setIndex3] = useState(0); | ||
const handleClick = (newIndex) => setIndex(newIndex); | ||
const handleClick2 = (newIndex) => setIndex2(newIndex); | ||
const handleClick3 = (newIndex) => setIndex3(newIndex); | ||
|
||
return ( | ||
<> | ||
<Row> | ||
<TabMenu activeIndex={index} onItemClick={handleClick}> | ||
<Tab>Total</Tab> | ||
<Tab>Cakers</Tab> | ||
<Tab>Flippers</Tab> | ||
<Tab>Storm</Tab> | ||
</TabMenu> | ||
</Row> | ||
<Row> | ||
<TabMenu activeIndex={index2} onItemClick={handleClick2}> | ||
<Tab>#1 Team</Tab> | ||
<Tab>#2 Team</Tab> | ||
<Tab>#3 Team</Tab> | ||
</TabMenu> | ||
</Row> | ||
<Row> | ||
<TabMenu activeIndex={index3} onItemClick={handleClick3}> | ||
<Tab>Really long tab name</Tab> | ||
<Tab>Short</Tab> | ||
<Tab>Medium length</Tab> | ||
</TabMenu> | ||
</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,3 @@ | ||
export { default as TabMenu } from "./TabMenu"; | ||
export { default as Tab } from "./Tab"; | ||
export type { TabMenuProps, TabProps } from "./types"; |
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 @@ | ||
export interface TabMenuProps { | ||
activeIndex?: number; | ||
onItemClick?: (index: number) => void; | ||
children: React.ReactElement[]; | ||
} | ||
export interface TabProps { | ||
isActive?: boolean; | ||
onClick?: () => void; | ||
} |
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