Skip to content

Commit

Permalink
Add TopNavigation component (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Aug 11, 2021
1 parent d087dd9 commit 12ef7cf
Show file tree
Hide file tree
Showing 46 changed files with 1,987 additions and 93 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-adults-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': minor
---

Added a new TopNavigation component. It is part of the [application shell](https://developers.google.com/web/fundamentals/architecture/app-shell) and contains the branding, page links, and the user profile menu.
5 changes: 5 additions & 0 deletions .changeset/tough-bulldogs-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/icons': minor
---

Added classnames to parts of the SumUp logo so they can be targeted for individual styling.
8 changes: 8 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ const SORT_ORDER = {
Typography: { Headline: {}, SubHeadline: {}, Body: {} },
Layout: {},
Forms: {},
Navigation: {
TopNavigation: {},
SideNavigation: {},
Pagination: {},
Tabs: {},
Sidebar: {},
Hamburger: {},
},
Components: {},
Hooks: {},
Packages: {
Expand Down
23 changes: 13 additions & 10 deletions .storybook/util/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SubHeadline,
Body,
List,
spacing,
} from '@sumup/circuit-ui';

import { Link } from '../components';
Expand Down Expand Up @@ -36,16 +37,14 @@ const withThemeProvider = (Component, baseProps = {}) => (props = {}) => (
const TEXT_SIZE = 'one';

const headlineStyles = (theme) => css`
margin-bottom: ${theme.spacings.mega};
*:not(h1):not(h2):not(h3) + & {
margin-top: ${theme.spacings.peta};
margin-bottom: ${theme.spacings.giga};
margin-bottom: ${theme.spacings.mega};
}
`;

const subHeadlineStyles = (theme) => css`
margin-top: ${theme.spacings.giga};
`;

const italicStyles = css`
font-style: italic;
`;
Expand All @@ -69,13 +68,17 @@ export const components = {
h4: withThemeProvider(Headline, {
as: 'h4',
size: 'four',
css: subHeadlineStyles,
css: spacing({ top: 'giga' }),
}),
subheadline: withThemeProvider(SubHeadline, {
as: 'subheadline',
css: subHeadlineStyles,
h5: withThemeProvider(SubHeadline, {
as: 'h5',
css: spacing({ top: 'giga' }),
}),
p: withThemeProvider(Body, {
as: 'p',
size: TEXT_SIZE,
css: spacing({ bottom: 'kilo' }),
}),
p: withThemeProvider(Body, { as: 'p', size: TEXT_SIZE }),
li: withThemeProvider(Body, { as: 'li', size: TEXT_SIZE }),
strong: withThemeProvider(Body, {
as: 'strong',
Expand Down
1 change: 1 addition & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@emotion/babel-preset-css-prop",
{
"autoLabel": false,
"sourceMap": false,
"labelFormat": "[filename]--[local]"
}
]
Expand Down
7 changes: 3 additions & 4 deletions packages/circuit-ui/components/Anchor/Anchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ export const Anchor = forwardRef(
({ tracking, ...props }: AnchorProps, ref?: BaseProps['ref']): ReturnType => {
const components = useComponents();

// Need to typecast here because the StyledAnchor expects a button-like
// component for its `as` prop. It's safe to ignore that constraint here.
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
const Link = components.Link as any;
// Need to typecast here because the styled component types restrict the
// `as` prop to a string. It's safe to ignore that constraint here.
const Link = (components.Link as unknown) as string;

const handleClick = useClickEvent(props.onClick, tracking, 'anchor');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BaseStylesService should return the global base styles 1`] = `"@font-face{font-family:'aktiv-grotesk';font-weight:400;font-display:swap;src:url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-400.woff2') format('woff2'),url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-400.woff') format('woff'),url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-400.eot') format('embedded-opentype');}@font-face{font-family:'aktiv-grotesk';font-weight:700;font-display:swap;src:url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-700.woff2') format('woff2'),url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-700.woff') format('woff'),url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-700.eot') format('embedded-opentype');}html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block;}body{line-height:1;}blockquote,q{quotes:none;}blockquote::before,blockquote::after,q::before,q::after{content:'';content:none;}table{border-collapse:collapse;border-spacing:0;}*,*::before,*::after{box-sizing:inherit;}html{box-sizing:border-box;overflow-x:hidden;[type='button']{appearance:none;}}body{background-color:#FFF;color:#1A1A1A;font-size:16px;line-height:24px;;;}html,body,input,select,optgroup,textarea,button{font-weight:400;font-family:aktiv-grotesk, -apple-system, BlinkMacSystemFont, \\"Segoe UI\\", Roboto, Helvetica, Arial, sans-serif, \\"Apple Color Emoji\\", \\"Segoe UI Emoji\\", \\"Segoe UI Symbol\\";font-feature-settings:'kern';-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility;}pre,code{font-family:Consolas, monaco, monospace;}/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJhc2VTdHlsZXNTZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXNCOEQiLCJmaW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XG4gICAgLXdlYmtpdC1mb250LXNtb290aGluZzogYW50aWFsaWFzZWQ7XG4gICAgLW1vei1vc3gtZm9udC1zbW9vdGhpbmc6IGdyYXlzY2FsZTtcbiAgICB0ZXh0LXJlbmRlcmluZzogb3B0aW1pemVMZWdpYmlsaXR5O1xuICB9XG5cbiAgcHJlLFxuICBjb2RlIHtcbiAgICBmb250LWZhbWlseTogJHt0aGVtZS5mb250U3RhY2subW9ub307XG4gIH1cbmA7XG4iXX0= */"`;
exports[`BaseStylesService should return the global base styles 1`] = `"@font-face{font-family:'aktiv-grotesk';font-weight:400;font-display:swap;src:url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-400.woff2') format('woff2'),url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-400.woff') format('woff'),url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-400.eot') format('embedded-opentype');}@font-face{font-family:'aktiv-grotesk';font-weight:700;font-display:swap;src:url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-700.woff2') format('woff2'),url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-700.woff') format('woff'),url('https://static.sumup.com/fonts/latin-greek-cyrillic/aktiv-grotest-700.eot') format('embedded-opentype');}html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block;}body{line-height:1;}blockquote,q{quotes:none;}blockquote::before,blockquote::after,q::before,q::after{content:'';content:none;}table{border-collapse:collapse;border-spacing:0;}*,*::before,*::after{box-sizing:inherit;}html{box-sizing:border-box;overflow-x:hidden;[type='button']{appearance:none;}}body{background-color:#FFF;color:#1A1A1A;font-size:16px;line-height:24px;;;}html,body,input,select,optgroup,textarea,button{font-weight:400;font-family:aktiv-grotesk, -apple-system, BlinkMacSystemFont, \\"Segoe UI\\", Roboto, Helvetica, Arial, sans-serif, \\"Apple Color Emoji\\", \\"Segoe UI Emoji\\", \\"Segoe UI Symbol\\";font-feature-settings:'kern';-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility;}pre,code{font-family:Consolas, monaco, monospace;}"`;
2 changes: 1 addition & 1 deletion packages/circuit-ui/components/Body/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Variant = 'highlight' | 'quote' | 'success' | 'error' | 'subtle';
export interface BodyProps
extends Omit<HTMLProps<HTMLParagraphElement>, 'size'> {
/**
* Choose from 2 font sizes.
* Choose from 2 font sizes. Default `one`.
*/
size?: Size;
/**
Expand Down
7 changes: 3 additions & 4 deletions packages/circuit-ui/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,9 @@ export const Button = forwardRef(
): ReturnType => {
const components = useComponents();

// Need to typecast here because the StyledButton expects a button-like
// component for its `as` prop. It's safe to ignore that constraint here.
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
const Link = components.Link as any;
// Need to typecast here because the styled component types restrict the
// `as` prop to a string. It's safe to ignore that constraint here.
const Link = (components.Link as unknown) as string;

const handleClick = useClickEvent(props.onClick, tracking, 'button');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ export const TextAndImage = (args) => (
src="https://source.unsplash.com/TpHmEoVSmfQ/1600x900"
alt="Aerial photo of turbulent turquoise ocean waves"
/>
<StyledHeadline size="one">Get The SumUp Card Reader Today!</StyledHeadline>
<StyledHeadline>Get The SumUp Card Reader Today!</StyledHeadline>
</Slide>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2019, SumUp Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { createContext, ReactNode } from 'react';

import { Link, LinkProps } from './components/Link';

export const defaultComponents = { Link };

export type ComponentsContextType = {
Link: (props: LinkProps) => ReactNode;
};

export const ComponentsContext = createContext<ComponentsContextType>(
defaultComponents,
);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

import { createRef } from 'react';

import Link from './Link';
import { render, renderToHtml, axe } from '../../../../util/test-utils';

import { Link } from './Link';

describe('Link', () => {
const defaultProps = {
Expand All @@ -31,7 +33,7 @@ describe('Link', () => {
* Should accept a working ref for button
*/
it('should accept a working ref', () => {
const tref = createRef();
const tref = createRef<HTMLAnchorElement>();
const { container } = render(
<Link {...defaultProps} ref={tref}>
This is a link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,21 @@
* limitations under the License.
*/

import { forwardRef } from 'react';
import PropTypes from 'prop-types';
import { forwardRef, HTMLProps, Ref } from 'react';

import { childrenPropType } from '../../../../util/shared-prop-types';
export interface LinkProps extends HTMLProps<HTMLAnchorElement> {
ref?: Ref<HTMLAnchorElement>;
}

/**
* A barebones Link component that's basically just an `<a>` tag
*/
const Link = forwardRef(({ children, ...props }, ref) => (
<a {...props} ref={ref}>
{children}
</a>
));
export const Link = forwardRef(
({ children, ...props }: LinkProps, ref: LinkProps['ref']) => (
<a {...props} ref={ref}>
{children}
</a>
),
);

Link.displayName = 'Link';

Link.propTypes = {
children: childrenPropType,
ref: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({ current: PropTypes.any }),
]),
};

/**
* @component
*/
export default Link;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
* limitations under the License.
*/

import Link from './Link';

export { Link };
export { Link } from './Link';
export type { LinkProps } from './Link';
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
* limitations under the License.
*/

import { createContext } from 'react';
export { ComponentsContext } from './ComponentsContext';
export { useComponents } from './useComponents';

import * as defaultComponents from './components';

const ComponentsContext = createContext(defaultComponents);

export default ComponentsContext;
export type { ComponentsContextType } from './ComponentsContext';
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@

import { useContext } from 'react';

import ComponentsContext from './ComponentsContext';
import * as defaultComponents from './components';
import {
ComponentsContext,
ComponentsContextType,
defaultComponents,
} from './ComponentsContext';

/**
* Subscribe to the components context with a hook.
*/
const useComponents = () => {
export const useComponents = (): ComponentsContextType => {
const components = useContext(ComponentsContext) || {};
return { ...defaultComponents, ...components };
};

/**
* @component
*/
export default useComponents;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useState } from 'react';
import { Hamburger, HamburgerProps } from './Hamburger';

export default {
title: 'Components/Hamburger',
title: 'Navigation/Hamburger',
component: Hamburger,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/circuit-ui/components/Header/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Hamburger from '../Hamburger';
import Header from '.';

export default {
title: 'Components/Header',
title: 'Navigation/Header',
component: Header,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/circuit-ui/components/Headline/Headline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Size = 'one' | 'two' | 'three' | 'four';
export interface HeadlineProps
extends Omit<HTMLProps<HTMLHeadingElement>, 'size'> {
/**
* A Circuit UI headline size.
* A Circuit UI headline size. Default `one`.
*/
size?: Size;
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/circuit-ui/components/Pagination/Pagination.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Status, Props, Story } from '../../../../.storybook/components';

Pagination provides a way for users to visualize bulks of information distributed over multiple pages, while always providing an anchor to move from where they currently are in the list.

<Story id="components-pagination--base" />
<Story id="navigation-pagination--base" />
<Props />

## When to use it
Expand All @@ -22,4 +22,4 @@ Use it when you have a list of more than 25 items related to the same category.

When there are more than 5 pages in total, the pagination is displayed as a dropdown.

<Story id="components-pagination--many-pages" />
<Story id="navigation-pagination--many-pages" />
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import docs from './Pagination.docs.mdx';
import { Pagination, PaginationProps } from './Pagination';

export default {
title: 'Components/Pagination',
title: 'Navigation/Pagination',
component: Pagination,
parameters: {
docs: { page: docs },
Expand Down
Loading

0 comments on commit 12ef7cf

Please sign in to comment.