Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tab bar no rebase #18

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
50ff8a1
chore(tab-menu): Rough component setup
RichardPK Mar 16, 2021
7925853
chore(tab-menu): Testing user
ChefHutch Mar 16, 2021
6f1d11d
style(styled-tab): V rough component layout and styles
ChefHutch Mar 16, 2021
8cde88f
style(styled-tab): Specific styles applied
ChefHutch Mar 16, 2021
071ef1d
style(styled-tab): Refinding styles and element types
ChefHutch Mar 16, 2021
38d25a7
fix(tab-menu): Tidy interfaces and props being passed to tab-bar
ChefHutch Mar 16, 2021
a7a6552
test(tab-menu): Added snapshot
ChefHutch Mar 16, 2021
b763939
styles(tab-menu): Update comp names and add extra stories
ChefHutch Mar 16, 2021
1a4d0a6
chore(tab-menu): Remove unused commented code
ChefHutch Mar 16, 2021
0283216
text(tab-menu): Fix incorrect test import
ChefHutch Mar 16, 2021
5700308
style(tab-menu): Add width % handling below 576px
ChefHutch Mar 16, 2021
ac131ba
test(tab-menu): Update snaps
ChefHutch Mar 16, 2021
b19df6b
test(tab-menu): Remove test files from this PR - see #1 for proposal …
ChefHutch Mar 17, 2021
1f54262
fix(merge): fix merge-conflicts
ChefHutch Mar 17, 2021
93342b1
style(tab-menu): Move away from % widths and towards flex-grow
ChefHutch Mar 17, 2021
9e4e9de
style(tab-menu): Set 8px min padding to tab
ChefHutch Mar 17, 2021
1139fae
style(tab-menu): Fix import order
ChefHutch Mar 17, 2021
09edc45
style(tab-menu): Remove styled tabmenu comp and move into tabmenu
ChefHutch Mar 17, 2021
d2f02f3
style(tab-menu): Change breakpoint for style change to 853px
ChefHutch Mar 17, 2021
0c25fc9
test(tab-menu): Add tabmenu test file
ChefHutch Mar 18, 2021
2b0d7ef
test(tab-menu): Remove duplicate setupTests
ChefHutch Mar 18, 2021
e6caf40
fix(merge): Fix merge-conflicts
ChefHutch Mar 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}