Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
CAR-4260 extract header (#187)
Browse files Browse the repository at this point in the history
Extracts the CAR FOR YOU header in tree theme variations: Light, Dark and Transparent

BREAKING CHANGE: refactor button size interface:
    - removed: small: boolean
    - replaced: size: "samll" | "larege" | "responsive"

* WIP: first draft desktop header

* feat: desktop layouts for header variations

* feat: mobile navigations

* chore: cleanup and update code examples

* chore remove .DS_Store

* chore: fix format

* chore: update snapshots

* unify classNames to use one condition per theme

* chore: use ternary operation to determine fill color

* chore: move theme conditions to context

* feat: use tailwind propertiers for svg icon components

* chore: use tailwind colors everywhere

* fix: propper BEM name for custom class

* chore: update snapshots

* chore: cleanup remove unused classes

* fix: make demo with carforyou content responsive

* chore: update snapshot

* chore: minor optimizations

* fix: export all header types and components

* fix: export all the icons

* chore: white text by default for transparent theme

* chore: add transparent example and tweak some missed theme specific classes

* fix: add grey border to light theme

* chore: optimize dropdowns

* chore: update snapshots

* chore: format to the new rules

* fix: mixed up button sizes

* chore: use bigger logo for ld breakpoint

* fix: z-index for menues

* fix: update snapshots

* chore: make navigation fit width and create a separate z-index for the dropdowns

* chore: update snapshots

* fix: trigger pre release

* chore: clean up logo

* BREAKING CHANGE: refactor button size interface

* chore: clean up icons and move examples to storybook folder

* fix: only export required icons

* fix: remove render props where not needed

* fix: clean up themeing colors

* chore: change interface for language navigation

* fix: update snapshots

* fix: remove unused variable

* fix: move sections to named functions
  • Loading branch information
lkappeler authored May 27, 2020
1 parent 3311d0c commit b8ddd58
Show file tree
Hide file tree
Showing 20 changed files with 1,072 additions and 11 deletions.
11 changes: 11 additions & 0 deletions assets/header.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.bg-header_transparent {
background: linear-gradient(
-180deg,
rgba(0, 0, 0, 0.5) 0%,
rgba(0, 0, 0, 0.5) 22%,
rgba(0, 0, 0, 0.3) 38%,
rgba(0, 0, 0, 0.2) 53%,
rgba(0, 0, 0, 0.1) 79%,
rgba(0, 0, 0, 0) 100%
);
}
1 change: 1 addition & 0 deletions assets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@import "./input/index.css";
@import "./spinner.css";
@import "./intercom.css";
@import "./header.css";
11 changes: 11 additions & 0 deletions src/__tests__/__snapshots__/node.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ Object {
"checkbox": "24px",
"clearButton": "32px",
"full": "100%",
"header": "85px",
"headerSmall": "60px",
"headerTransparent": "166px",
"input": "52px",
"radioIndicator": "12px",
"screen": "100vh",
Expand Down Expand Up @@ -231,17 +234,21 @@ Object {
},
},
"margin": Object {
"-headerMenu": "-14px",
"-headerMenuMore": "-28px",
"-selectMenu": "-21px",
"-selectWithHintMenu": "-43px",
"0": "0",
"10": "10px",
"15": "15px",
"20": "20px",
"22": "22px",
"25": "25px",
"30": "30px",
"40": "40px",
"5": "5px",
"auto": "auto",
"headerMenu": "14px",
"labelPopupIcon": "3px",
"px": "1px",
},
Expand Down Expand Up @@ -353,9 +360,12 @@ Object {
"auto": "auto",
"checkbox": "24px",
"clearButton": "32px",
"logoDefault": "170px",
"logoSmall": "140px",
"modal": "570px",
"modalLarge": "770px",
"modalSmall": "370px",
"profileDropdown": "320px",
"radioIndicator": "12px",
"screen": "100vw",
"scrollbar": "14px",
Expand All @@ -364,6 +374,7 @@ Object {
"auto": "auto",
"clearButton": 10,
"dropdownMenu": 20,
"headerDropdown": 30,
"modal": 98,
"modalClose": 10,
"negative": -1,
Expand Down
8 changes: 4 additions & 4 deletions src/components/__tests__/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("<Button>", () => {

describe("button variations", () => {
it("renders small button", () => {
const { container } = render(<Button small>Label</Button>)
const { container } = render(<Button size="small">Label</Button>)
expect(container).toMatchSnapshot()
})

Expand All @@ -43,7 +43,7 @@ describe("<Button>", () => {

it("renders small disabled button", () => {
const { container } = render(
<Button disabled small>
<Button disabled size="small">
Label
</Button>
)
Expand All @@ -52,7 +52,7 @@ describe("<Button>", () => {

it("renders small teal button", () => {
const { container } = render(
<Button small teal>
<Button size="small" teal>
Label
</Button>
)
Expand All @@ -66,7 +66,7 @@ describe("<Button>", () => {

it("renders white Teal small button", () => {
const { container } = render(
<Button tealBorder small>
<Button tealBorder size="small">
Label
</Button>
)
Expand Down
10 changes: 7 additions & 3 deletions src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Props {
dataTestid?: string
teal?: boolean
tealBorder?: boolean
small?: boolean
size?: "large" | "small" | "responsive"
disabled?: boolean
onClick?: (event: MouseEvent<HTMLButtonElement>) => void
submit?: boolean
Expand All @@ -21,13 +21,17 @@ export const Button: FC<Props> = ({
dataTestid,
teal,
tealBorder,
small,
size = "large",
disabled,
onClick,
submit,
icon,
}) => {
const padding = classnames("px-10", small ? "min-h-36" : "min-h-52")
const padding = classnames("px-10", {
"min-h-36": size === "small",
"min-h-52": size === "large",
"min-h-36 lg:min-h-52": size === "responsive",
})
const classes = classnames("rounded border", {
"bg-teal hover:bg-teal-dark focus:bg-teal": teal,
"bg-white text-teal hover:opacity-60": tealBorder,
Expand Down
105 changes: 105 additions & 0 deletions src/components/header/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React, { FC, useState, useEffect, useContext } from "react"
import classNames from "classnames"

import { defaultConfig as tailwindConfig } from "../../tailwind/index"
const {
theme: {
colors: { black: colorDropdownArrow },
},
} = tailwindConfig

import ArrowDownM from "../icons/arrowDownMCrop"
import HeaderThemeContext, { HeaderTheme } from "./themeContext"

interface Props {
renderParent: () => JSX.Element
children: JSX.Element
theme?: HeaderTheme
stickOut?: "left" | "right"
}

const HeaderDropdown: FC<Props> = ({
renderParent,
stickOut = "right",
children,
}) => {
const [isOpen, setIsOpen] = useState(false)
const { isDark, isTransparent } = useContext(HeaderThemeContext)

useEffect(() => {
if (isOpen) {
document.addEventListener("click", toggle)
document.addEventListener("keydown", toggle)
}

return () => {
document.removeEventListener("click", toggle)
document.removeEventListener("keydown", toggle)
}
}, [isOpen])

const toggle = () => setIsOpen(!isOpen)

const renderClosedState = () => {
return (
<div
className={classNames(
"flex items-center cursor-pointer py-10 lg:py-0 hover:opacity-60",
{
"lg:text-white": isDark || isTransparent,
}
)}
onClick={toggle}
>
{renderParent()}
<ArrowDownM
height="28"
width="28"
color={colorDropdownArrow}
className={classNames("inline-block", {
"lg:text-white": isDark || isTransparent,
})}
/>
</div>
)
}

const renderOpenState = () => {
return (
<div className="bg-grey-1 lg:bg-transparent relative z-headerDropdown cursor-pointer -mx-headerMenu lg:mx-0 px-14 lg:px-0 py-10 lg:py-0">
<div
className={classNames(
"flex items-center font-bold lg:font-regular hover:opacity-60",
{
"lg:text-white": isDark || isTransparent,
}
)}
onClick={toggle}
>
{renderParent()}
<ArrowDownM
height="28"
width="28"
className={classNames("inline-block customRotate-180", {
"lg:text-white": isDark || isTransparent,
})}
/>
</div>
<div
className={classNames(
"text-black text-left whitespace-no-wrap bg-grey-1 md:bg-white relative lg:absolute lg:border lg:border-grey-2 lg:rounded-4 lg:shadow-hard",
{
"right-0": stickOut === "left",
}
)}
>
{children}
</div>
</div>
)
}

return isOpen ? renderOpenState() : renderClosedState()
}

export default HeaderDropdown
Loading

0 comments on commit b8ddd58

Please sign in to comment.