-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Section and Header components, and height prop to Container
- Loading branch information
Showing
52 changed files
with
590 additions
and
158 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 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,36 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import Container from "./Container"; | ||
import Logo, { NAMES as LOGO_NAMES } from "./internal/Logo"; | ||
|
||
function HeaderLogo({ name }) { | ||
return ( | ||
<Logo name={name} color="primary.blue.t100" height="5" height-xs="7" /> | ||
); | ||
} | ||
|
||
HeaderLogo.propTypes = { | ||
name: PropTypes.oneOf(LOGO_NAMES).isRequired | ||
}; | ||
|
||
function Header({ children }) { | ||
return ( | ||
<header> | ||
<Container bg="white" height="10" height-lg="13" boxShadow="header"> | ||
<Container hasBreakpointWidth={true} height="100%"> | ||
<div css={{ display: "flex", height: "100%", alignItems: "center" }}> | ||
{children} | ||
</div> | ||
</Container> | ||
</Container> | ||
</header> | ||
); | ||
} | ||
|
||
Header.propTypes = { | ||
children: PropTypes.node.isRequired | ||
}; | ||
|
||
Header.Logo = HeaderLogo; | ||
|
||
export default Header; |
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,37 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import Container, { BACKGROUNDS as CONTAINER_BACKGROUNDS } from "./Container"; | ||
import Grid from "./Grid"; | ||
import { responsivePaddingType } from "../hooks/useResponsiveProp"; | ||
import useAllResponsiveProps from "../hooks/useAllResponsiveProps"; | ||
|
||
export const BACKGROUNDS = CONTAINER_BACKGROUNDS; | ||
|
||
export const DEFAULT_PROPS = { | ||
debug: false | ||
}; | ||
|
||
function Section(_props) { | ||
const props = { ...DEFAULT_PROPS, ..._props }; | ||
const { bg, debug, children } = props; | ||
const paddingProps = useAllResponsiveProps(props, "padding"); | ||
|
||
return ( | ||
<Container bg={bg} {...paddingProps}> | ||
<Container hasBreakpointWidth> | ||
<Grid cols={4} cols-sm={8} cols-lg={12} colsGutter="30px" debug={debug}> | ||
{children} | ||
</Grid> | ||
</Container> | ||
</Container> | ||
); | ||
} | ||
|
||
Section.propTypes = { | ||
bg: PropTypes.oneOf(BACKGROUNDS), | ||
...responsivePaddingType, | ||
debug: PropTypes.bool, | ||
children: PropTypes.node | ||
}; | ||
|
||
export default Section; |
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,43 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import LatitudeLogo from "../../logos/latitude"; | ||
import GemLogo from "../../logos/gem"; | ||
import { responsiveHeightType } from "../../hooks/useResponsiveProp"; | ||
import useAllResponsiveProps from "../../hooks/useAllResponsiveProps"; | ||
|
||
export const NAMES = ["latitude", "gem"]; | ||
export const COLORS = ["primary.blue.t100", "black", "white"]; | ||
|
||
export const DEFAULT_PROPS = {}; | ||
|
||
function Logo(_props) { | ||
const props = { ...DEFAULT_PROPS, ..._props }; | ||
const { name, color } = props; | ||
const heightProps = useAllResponsiveProps(props, "height"); | ||
const logoProps = { | ||
color, | ||
...heightProps | ||
}; | ||
|
||
switch (name) { | ||
case "latitude": { | ||
return <LatitudeLogo {...logoProps} />; | ||
} | ||
|
||
case "gem": { | ||
return <GemLogo {...logoProps} />; | ||
} | ||
|
||
default: { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
Logo.propTypes = { | ||
name: PropTypes.oneOf(NAMES).isRequired, | ||
color: PropTypes.oneOf(COLORS).isRequired, | ||
...responsiveHeightType | ||
}; | ||
|
||
export default Logo; |
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,36 @@ | ||
import useTheme from "./useTheme"; | ||
import { getPropName } from "./useResponsiveProp"; | ||
|
||
function useAllResponsiveProps(props, propName) { | ||
const theme = useTheme(); | ||
const breakpoints = Object.keys(theme.breakpoints); | ||
const result = {}; | ||
|
||
/* | ||
ESLint complains about: | ||
props.hasOwnProperty[prop] | ||
See: https://eslint.org/docs/rules/no-prototype-builtins | ||
*/ | ||
if (Object.prototype.hasOwnProperty.call(props, propName)) { | ||
result[propName] = props[propName]; | ||
} | ||
|
||
breakpoints.forEach(bp => { | ||
const prop = getPropName(propName, bp); | ||
|
||
/* | ||
ESLint complains about: | ||
props.hasOwnProperty[prop] | ||
See: https://eslint.org/docs/rules/no-prototype-builtins | ||
*/ | ||
if (Object.prototype.hasOwnProperty.call(props, prop)) { | ||
result[prop] = props[prop]; | ||
} | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
export default useAllResponsiveProps; |
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,47 @@ | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
import useAllResponsiveProps from "./useAllResponsiveProps"; | ||
import { TestWrapper } from "../utils/test"; | ||
|
||
describe("useAllResponsiveProps", () => { | ||
it("collects all the responsive props", () => { | ||
const props = { | ||
padding: "4", | ||
"padding-xs": 5, | ||
"padding-sm": "0", | ||
"padding-md": "6", | ||
"padding-lg": "1 2 3", | ||
"padding-xl": "0 8", | ||
anotherProp: "some value" | ||
}; | ||
const { result } = renderHook( | ||
() => useAllResponsiveProps(props, "padding"), | ||
{ wrapper: TestWrapper } | ||
); | ||
|
||
expect(result.current).toStrictEqual({ | ||
padding: "4", | ||
"padding-xs": 5, | ||
"padding-sm": "0", | ||
"padding-md": "6", | ||
"padding-lg": "1 2 3", | ||
"padding-xl": "0 8" | ||
}); | ||
}); | ||
|
||
it("drops responsive props that do not exist", () => { | ||
const props = { | ||
"padding-xs": 5, | ||
"padding-md": "6", | ||
anotherProp: "some value" | ||
}; | ||
const { result } = renderHook( | ||
() => useAllResponsiveProps(props, "padding"), | ||
{ wrapper: TestWrapper } | ||
); | ||
|
||
expect(result.current).toStrictEqual({ | ||
"padding-xs": 5, | ||
"padding-md": "6" | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.