Skip to content

Commit

Permalink
feat(TabMenu) - Adding TabMenu to UI kit (with correct rebasing) (#19)
Browse files Browse the repository at this point in the history
* 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
ChefHutch authored Mar 19, 2021
1 parent f7679f7 commit 8061551
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 15 deletions.
50 changes: 50 additions & 0 deletions packages/pancake-uikit/src/__tests__/components/tabmenu.test.tsx
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 packages/pancake-uikit/src/components/TabMenu/StyledTab.tsx
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;
15 changes: 15 additions & 0 deletions packages/pancake-uikit/src/components/TabMenu/Tab.tsx
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;
46 changes: 46 additions & 0 deletions packages/pancake-uikit/src/components/TabMenu/TabMenu.tsx
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 packages/pancake-uikit/src/components/TabMenu/index.stories.tsx
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>
</>
);
};
3 changes: 3 additions & 0 deletions packages/pancake-uikit/src/components/TabMenu/index.tsx
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";
9 changes: 9 additions & 0 deletions packages/pancake-uikit/src/components/TabMenu/types.ts
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;
}
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3361,9 +3361,9 @@
"@types/istanbul-lib-report" "*"

"@types/jest@*":
version "26.0.20"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.20.tgz#cd2f2702ecf69e86b586e1f5223a60e454056307"
integrity sha512-9zi2Y+5USJRxd0FsahERhBwlcvFh6D2GLQnY2FH2BzK8J9s9omvNHIbvABwIluXa0fD8XVKMLTO0aOEuUfACAA==
version "26.0.21"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.21.tgz#3a73c2731e7e4f0fbaea56ce7ff8c79cf812bd24"
integrity sha512-ab9TyM/69yg7eew9eOwKMUmvIZAKEGZYlq/dhe5/0IMUd/QLJv5ldRMdddSn+u22N13FP3s5jYyktxuBwY0kDA==
dependencies:
jest-diff "^26.0.0"
pretty-format "^26.0.0"
Expand Down Expand Up @@ -6520,9 +6520,9 @@ ejs@^3.1.2:
jake "^10.6.1"

electron-to-chromium@^1.3.564, electron-to-chromium@^1.3.649:
version "1.3.690"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.690.tgz#54df63ec42fba6b8e9e05fe4be52caeeedb6e634"
integrity sha512-zPbaSv1c8LUKqQ+scNxJKv01RYFkVVF1xli+b+3Ty8ONujHjAMg+t/COmdZqrtnS1gT+g4hbSodHillymt1Lww==
version "1.3.691"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.691.tgz#a671eaf135a3ccec0915eb8d844a0952aba79f3b"
integrity sha512-ZqiO69KImmOGCyoH0icQPU3SndJiW93juEvf63gQngyhODO6SpQIPMTOHldtCs5DS5GMKvAkquk230E2zt2vpw==

element-resize-detector@^1.2.1:
version "1.2.2"
Expand Down Expand Up @@ -12767,9 +12767,9 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
inherits "^2.0.1"

rollup@^2.39.0:
version "2.41.4"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.41.4.tgz#2a674d64db4322482d440699acb060dc6dd9e65f"
integrity sha512-f9IHfMO8p2Y8OdisI7Oj3oKkPuaQ6cgSwYqAi0TDvP3w2p+oX1VejX/w28a1h8WTnrapzfO5d4Uqhww+gL0b0g==
version "2.41.5"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.41.5.tgz#e79cef8cc5c121612528f590319639b1f32da2d7"
integrity sha512-uG+WNNxhOYyeuO7oRt98GA2CNVRgQ67zca75UQVMPzMrLG9FUKzTCgvYVWhtB18TNbV7Uqxo97h+wErAnpFNJw==
optionalDependencies:
fsevents "~2.3.1"

Expand Down Expand Up @@ -13399,9 +13399,9 @@ strict-uri-encode@^2.0.0:
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=

string-length@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/string-length/-/string-length-4.0.1.tgz#4a973bf31ef77c4edbceadd6af2611996985f8a1"
integrity sha512-PKyXUd0LK0ePjSOnWn34V2uD6acUWev9uy0Ft05k0E8xRW+SKcA0F7eMr7h5xlzfn+4O3N+55rduYyet3Jk+jw==
version "4.0.2"
resolved "https://registry.yarnpkg.com/string-length/-/string-length-4.0.2.tgz#a8a8dc7bd5c1a82b9b3c8b87e125f66871b6e57a"
integrity sha512-+l6rNN5fYHNhZZy41RXsYptCjA2Igmq4EG7kZAYFQI1E1VTXarr6ZPXBg6eq7Y6eK4FEhY6AJlyuFIb/v/S0VQ==
dependencies:
char-regex "^1.0.2"
strip-ansi "^6.0.0"
Expand Down Expand Up @@ -14059,9 +14059,9 @@ ts-essentials@^2.0.3:
integrity sha512-3IVX4nI6B5cc31/GFFE+i8ey/N2eA0CZDbo6n0yrz0zDX8ZJ8djmU1p+XRz7G3is0F3bB3pu2pAroFdAWQKU3w==

ts-jest@^26.5.1:
version "26.5.3"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.5.3.tgz#a6ee00ba547be3b09877550df40a1465d0295554"
integrity sha512-nBiiFGNvtujdLryU7MiMQh1iPmnZ/QvOskBbD2kURiI1MwqvxlxNnaAB/z9TbslMqCsSbu5BXvSSQPc5tvHGeA==
version "26.5.4"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.5.4.tgz#207f4c114812a9c6d5746dd4d1cdf899eafc9686"
integrity sha512-I5Qsddo+VTm94SukBJ4cPimOoFZsYTeElR2xy6H2TOVs+NsvgYglW8KuQgKoApOKuaU/Ix/vrF9ebFZlb5D2Pg==
dependencies:
bs-logger "0.x"
buffer-from "1.x"
Expand Down

0 comments on commit 8061551

Please sign in to comment.