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

Rename NotificationBanner component #979

Merged
merged 4 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/eleven-parrots-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': major
---

Rename NotificationBanner component into NotificationCard.
Copy link
Member

@connor-baer connor-baer Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd mention that we plan to deprecate it in the future (similar to what you wrote in the PR description).

Suggested change
Rename NotificationBanner component into NotificationCard.
Renamed the NotificationBanner component to NotificationCard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 55993ac

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import styled from '@emotion/styled';
import { NotificationBanner } from '@sumup/circuit-ui';

const BaseNotificationBanner = () => <NotificationBanner />;

const RedNotificationBanner = styled(NotificationBanner)`
color: red;
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import styled from '@emotion/styled';
import { NotificationCard } from '@sumup/circuit-ui';

const BaseNotificationBanner = () => <NotificationCard />;

const RedNotificationBanner = styled(NotificationCard)`
color: red;
`;
1 change: 1 addition & 0 deletions packages/circuit-ui/cli/migrate/__tests__/migrate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ defineTest('currency-utils', 'currency-utils-2');
defineTest('component-names-typography');
defineTest('typography-sizes');
defineTest('body-variant-highlight');
defineTest('component-names-v3');

function defineTest(transformName, testFilePrefix, testOptions = {}) {
const dirName = __dirname;
Expand Down
51 changes: 51 additions & 0 deletions packages/circuit-ui/cli/migrate/component-names-v3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2021, 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 { Transform, JSCodeshift, Collection } from 'jscodeshift';

import { findImportsByPath } from './utils';

function transformFactory(
j: JSCodeshift,
root: Collection,
componentNames: string[],
): void {
const [oldComponentName, newComponentName] = componentNames;
const imports = findImportsByPath(j, root, '@sumup/circuit-ui');

const componentImport = imports.find((i) => i.name === oldComponentName);

if (!componentImport) {
return;
}

root
.find(j.Identifier)
.filter((nodePath) => nodePath.node.name === oldComponentName)
.replaceWith(j.identifier(newComponentName));
}

const transform: Transform = (file, api) => {
const j = api.jscodeshift;
const root = j(file.source);

[['NotificationBanner', 'NotificationCard']].forEach((componentNames) => {
transformFactory(j, root, componentNames);
});

return root.toSource();
};

export default transform;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Status, Props, Story } from '../../../../.storybook/components';
import NotificationBanner from '../NotificationBanner';
import NotificationCard from '../NotificationCard';
import NotificationList from '../NotificationList';

# Notification
Expand Down Expand Up @@ -41,12 +41,12 @@ to use a call to action.

**Error**: When action is required by the user, attention notifications should be used and should clearly highlight which action is required. **A call to action must be displayed.**

## NotificationBanner
## NotificationCard

You can display a banner with a notification with the `NotificationBanner`, and position it at the top or bottom of a view.
You can display a banner with a notification with the `NotificationCard`, and position it at the top or bottom of a view.

<Story id="components-notification-notificationbanner--base" />
<Props of={NotificationBanner} />
<Props of={NotificationCard} />

## NotificationList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import Headline from '../Headline';
import Body from '../Body';
import Button from '../Button';
import NotificationList from '../NotificationList';
import NotificationBanner from '../NotificationBanner';
import NotificationCard from '../NotificationCard';

import docs from './Notification.docs.mdx';
import { Notification, NotificationProps } from './Notification';

export default {
title: 'Components/Notification',
component: Notification,
subcomponents: { NotificationList, NotificationBanner },
subcomponents: { NotificationList, NotificationCard },
parameters: {
docs: { page: docs },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import React from 'react';

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

import { NotificationBanner } from './NotificationBanner';
import { NotificationCard } from './NotificationCard';

describe('NotificationBanner', () => {
describe('NotificationCard', () => {
const children = <p>This is a notification.</p>;
/**
* Style tests.
*/
it('should render with default styles', () => {
const actual = create(<NotificationBanner>{children}</NotificationBanner>);
const actual = create(<NotificationCard>{children}</NotificationCard>);
expect(actual).toMatchSnapshot();
});

Expand All @@ -34,7 +34,7 @@ describe('NotificationBanner', () => {
*/
it('should meet accessibility guidelines', async () => {
const wrapper = renderToHtml(
<NotificationBanner>{children}</NotificationBanner>,
<NotificationCard>{children}</NotificationCard>,
);
const actual = await axe(wrapper);
expect(actual).toHaveNoViolations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ import Headline from '../Headline';
import Body from '../Body';
import Button from '../Button';

import {
NotificationBanner,
NotificationBannerProps,
} from './NotificationBanner';
import { NotificationCard, NotificationCardProps } from './NotificationCard';

export default {
title: 'Components/Notification/NotificationBanner',
component: NotificationBanner,
title: 'Components/Notification/NotificationCard',
component: NotificationCard,
};

export const Base = (args: NotificationBannerProps) => (
<NotificationBanner {...args}>
export const Base = (args: NotificationCardProps) => (
<NotificationCard {...args}>
<Notification variant="success">
<Headline as="h4" size="four" noMargin>
New Feature — Intelligent Reporting
Expand All @@ -44,5 +41,5 @@ export const Base = (args: NotificationBannerProps) => (
Learn more
</Button>
</Notification>
</NotificationBanner>
</NotificationCard>
);
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { css } from '@emotion/core';
import styled, { NoTheme, StyleProps } from '../../styles/styled';
import { shadow } from '../../styles/style-mixins';

export interface NotificationBannerProps extends HTMLProps<HTMLDivElement> {
export interface NotificationCardProps extends HTMLProps<HTMLDivElement> {
/**
* A single Notification.
*/
Expand All @@ -34,23 +34,23 @@ const outerStyles = ({ theme }: StyleProps) => css`
border-radius: 16px;
`;

const NotificationBannerOuter = styled('div')<NoTheme>(outerStyles, shadow());
const NotificationCardOuter = styled('div')<NoTheme>(outerStyles, shadow());

const innerStyles = ({ theme }: StyleProps) => css`
label: notification-banner__inner;
padding: ${theme.spacings.mega} ${theme.spacings.giga};
`;

const NotificationBannerInner = styled('div')<NoTheme>(innerStyles);
const NotificationCardInner = styled('div')<NoTheme>(innerStyles);

/**
* NotificationBanner displays a persistent Notification.
* NotificationCard displays a persistent Notification.
*/
export const NotificationBanner = ({
export const NotificationCard = ({
children,
...props
}: NotificationBannerProps) => (
<NotificationBannerOuter {...props} aria-live="polite" role="status">
<NotificationBannerInner>{children}</NotificationBannerInner>
</NotificationBannerOuter>
}: NotificationCardProps) => (
<NotificationCardOuter {...props} aria-live="polite" role="status">
<NotificationCardInner>{children}</NotificationCardInner>
</NotificationCardOuter>
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`NotificationBanner should render with default styles 1`] = `
exports[`NotificationCard should render with default styles 1`] = `
.circuit-1 {
width: 100%;
background-color: #FFF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import { NotificationBanner } from './NotificationBanner';
import { NotificationCard } from './NotificationCard';

export type { NotificationBannerProps } from './NotificationBanner';
export type { NotificationCardProps } from './NotificationCard';

export default NotificationBanner;
export default NotificationCard;
4 changes: 2 additions & 2 deletions packages/circuit-ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export type { SelectorGroupProps } from './components/SelectorGroup';
// Notifications
export { default as Notification } from './components/Notification';
export type { NotificationProps } from './components/Notification';
export { default as NotificationBanner } from './components/NotificationBanner';
export type { NotificationBannerProps } from './components/NotificationBanner';
export { default as NotificationCard } from './components/NotificationCard';
export type { NotificationCardProps } from './components/NotificationCard';
export { default as NotificationList } from './components/NotificationList';
export type { NotificationListProps } from './components/NotificationList';

Expand Down