Skip to content

Commit

Permalink
Remove deprecated props (#2063)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer authored Apr 25, 2023
1 parent 496d8c9 commit fef5b95
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 1,543 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-pots-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': major
---

Removed the deprecated `children` prop from the Checkbox component. Use the `label` prop instead.
5 changes: 5 additions & 0 deletions .changeset/serious-schools-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': major
---

Removed the deprecated `confirm`, `notify`, and `alert` variants from the Badge, NotificationInline, and NotificationToast components. Use the `success`, `warning`, and `danger` variants instead.
3 changes: 0 additions & 3 deletions packages/circuit-ui/components/Badge/Badge.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ describe('Badge', () => {
'warning',
'danger',
'promo',
'confirm',
'notify',
'alert',
] as const;

it.each(variants)('should render with %s styles', (variant) => {
Expand Down
50 changes: 6 additions & 44 deletions packages/circuit-ui/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,12 @@ import { css } from '@emotion/react';

import styled, { StyleProps } from '../../styles/styled';
import { typography } from '../../styles/style-mixins';
import { withDeprecation } from '../../util/logger';

export interface BadgeProps extends HTMLAttributes<HTMLDivElement> {
/**
* Choose the style variant. Default: 'neutral'.
*/
variant?:
| 'neutral'
| 'success'
| 'warning'
| 'danger'
| 'promo'
/**
* @deprecated
*/
| 'confirm'
/**
* @deprecated
*/
| 'notify'
/**
* @deprecated
*/
| 'alert';
variant?: 'neutral' | 'success' | 'warning' | 'danger' | 'promo';
/**
* Use the circular badge to indicate a count of items related to an element.
*/
Expand All @@ -63,22 +45,19 @@ const baseStyles = ({ theme }: StyleProps) => css`

const variantStyles = ({ variant = 'neutral' }: BadgeProps) => {
switch (variant) {
case 'success':
case 'confirm': {
case 'success': {
return css`
background-color: var(--cui-bg-success-strong);
color: var(--cui-fg-on-strong);
`;
}
case 'warning':
case 'notify': {
case 'warning': {
return css`
background-color: var(--cui-bg-warning-strong);
color: var(--cui-fg-on-strong);
`;
}
case 'danger':
case 'alert': {
case 'danger': {
return css`
background-color: var(--cui-bg-danger-strong);
color: var(--cui-fg-on-strong);
Expand Down Expand Up @@ -124,28 +103,11 @@ const circleStyles = ({ circle = false, children }: BadgeProps) =>
* A badge communicates the status of an element or the count of items
* related to an element.
*/
const StyledBadge = styled('div')<BadgeProps>(
export const Badge = styled('div')<BadgeProps>(
typography('two'),
baseStyles,
variantStyles,
circleStyles,
);

StyledBadge.displayName = 'Badge';

export const Badge =
process.env.NODE_ENV === 'production'
? StyledBadge
: withDeprecation(StyledBadge, ({ variant }) => {
const deprecatedMap: Record<string, string> = {
confirm: 'success',
notify: 'warning',
alert: 'danger',
};

if (variant && deprecatedMap[variant]) {
return `The "${variant}" variant has been deprecated. Use "${deprecatedMap[variant]}" instead.`;
}

return null;
});
Badge.displayName = 'Badge';
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,6 @@ exports[`Badge > should have the correct circle styles 1`] = `
</div>
`;

exports[`Badge > should render with alert styles 1`] = `
.circuit-0 {
font-size: 0.875rem;
line-height: 1.25rem;
border-radius: 999999px;
display: inline-block;
padding: 2px 8px;
font-weight: 700;
text-align: center;
letter-spacing: 0.25px;
background-color: var(--cui-bg-danger-strong);
color: var(--cui-fg-on-strong);
}
<div>
<div
class="circuit-0"
/>
</div>
`;

exports[`Badge > should render with confirm styles 1`] = `
.circuit-0 {
font-size: 0.875rem;
line-height: 1.25rem;
border-radius: 999999px;
display: inline-block;
padding: 2px 8px;
font-weight: 700;
text-align: center;
letter-spacing: 0.25px;
background-color: var(--cui-bg-success-strong);
color: var(--cui-fg-on-strong);
}
<div>
<div
class="circuit-0"
/>
</div>
`;

exports[`Badge > should render with danger styles 1`] = `
.circuit-0 {
font-size: 0.875rem;
Expand Down Expand Up @@ -141,27 +99,6 @@ exports[`Badge > should render with neutral styles 1`] = `
</div>
`;

exports[`Badge > should render with notify styles 1`] = `
.circuit-0 {
font-size: 0.875rem;
line-height: 1.25rem;
border-radius: 999999px;
display: inline-block;
padding: 2px 8px;
font-weight: 700;
text-align: center;
letter-spacing: 0.25px;
background-color: var(--cui-bg-warning-strong);
color: var(--cui-fg-on-strong);
}
<div>
<div
class="circuit-0"
/>
</div>
`;

exports[`Badge > should render with promo styles 1`] = `
.circuit-0 {
font-size: 0.875rem;
Expand Down
33 changes: 20 additions & 13 deletions packages/circuit-ui/components/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {

const CheckboxWithState = ({
checked: initial = false,
children,
label,
...props
}: CheckboxProps) => {
const [checked, setChecked] = useState(initial);
Expand All @@ -39,9 +39,12 @@ const CheckboxWithState = ({
setChecked((prev) => !prev);
};
return (
<Checkbox {...props} checked={checked} onChange={handleChange}>
{children || (checked ? 'Checked' : 'Unchecked')}
</Checkbox>
<Checkbox
{...props}
label={label || (checked ? 'Checked' : 'Unchecked')}
checked={checked}
onChange={handleChange}
/>
);
};

Expand Down Expand Up @@ -74,14 +77,18 @@ Disabled.args = {

export const Multiple = (args: CheckboxProps) => (
<>
<CheckboxWithState {...args} value="apples" name="fruits">
Apples
</CheckboxWithState>
<CheckboxWithState {...args} value="bananas" name="fruits">
Bananas
</CheckboxWithState>
<CheckboxWithState {...args} value="oranges" name="fruits">
Oranges
</CheckboxWithState>
<CheckboxWithState {...args} value="apples" name="fruits" label="Apples" />
<CheckboxWithState
{...args}
value="bananas"
name="fruits"
label="Bananas"
/>
<CheckboxWithState
{...args}
value="oranges"
name="fruits"
label="Oranges"
/>
</>
);
25 changes: 6 additions & 19 deletions packages/circuit-ui/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Checkmark } from '@sumup/icons';
import styled, { StyleProps } from '../../styles/styled';
import { hideVisually, focusOutline } from '../../styles/style-mixins';
import { FieldValidationHint, FieldWrapper } from '../FieldAtoms';
import { deprecate } from '../../util/logger';
import { AccessibilityError } from '../../util/errors';

export interface CheckboxProps extends InputHTMLAttributes<HTMLInputElement> {
Expand All @@ -40,12 +39,7 @@ export interface CheckboxProps extends InputHTMLAttributes<HTMLInputElement> {
* The ref to the HTML DOM element.
*/
ref?: Ref<HTMLInputElement>;
/**
* @deprecated
*
* Use the `label` prop instead.
*/
children?: InputHTMLAttributes<HTMLInputElement>['children'];
children?: never;
}

const labelBaseStyles = css`
Expand All @@ -58,11 +52,13 @@ const labelBaseStyles = css`

const CheckboxLabel = styled('label')(labelBaseStyles);

type WrapperElProps = Pick<CheckboxProps, 'className' | 'style' | 'disabled'>;

const wrapperBaseStyles = () => css`
position: relative;
`;

const CheckboxWrapper = styled(FieldWrapper)<CheckboxProps>(wrapperBaseStyles);
const CheckboxWrapper = styled(FieldWrapper)<WrapperElProps>(wrapperBaseStyles);

type InputElProps = Pick<CheckboxProps, 'invalid' | 'disabled'>;

Expand Down Expand Up @@ -179,7 +175,6 @@ export const Checkbox = forwardRef(
(
{
label,
children,
value,
'id': customId,
name,
Expand All @@ -193,18 +188,10 @@ export const Checkbox = forwardRef(
}: CheckboxProps,
ref: CheckboxProps['ref'],
) => {
if (process.env.NODE_ENV !== 'production' && children) {
deprecate(
'Checkbox',
'The `children` prop has been deprecated. Use the `label` prop instead.',
);
}

if (
process.env.NODE_ENV !== 'production' &&
process.env.NODE_ENV !== 'test' &&
!label &&
!children
!label
) {
throw new AccessibilityError('Checkbox', 'The `label` prop is missing.');
}
Expand All @@ -230,7 +217,7 @@ export const Checkbox = forwardRef(
aria-describedby={descriptionIds}
/>
<CheckboxLabel htmlFor={checkboxId}>
{label || children}
{label}
<Checkmark aria-hidden="true" />
</CheckboxLabel>
<FieldValidationHint
Expand Down
2 changes: 1 addition & 1 deletion packages/circuit-ui/components/ListItem/ListItem.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('ListItem', () => {
const wrapper = renderListItem(create, {
...baseProps,
leadingComponent: (
<Badge variant="alert" circle>
<Badge variant="danger" circle>
3
</Badge>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const item: Item = {
};

const LeadingBadge = (
<Badge variant="alert" circle>
<Badge variant="danger" circle>
3
</Badge>
);
Expand Down
Loading

0 comments on commit fef5b95

Please sign in to comment.