diff --git a/.changeset/brown-cobras-invite.md b/.changeset/brown-cobras-invite.md new file mode 100644 index 0000000000..470f8e0731 --- /dev/null +++ b/.changeset/brown-cobras-invite.md @@ -0,0 +1,5 @@ +--- +"@sumup-oss/circuit-ui": minor +--- + +Added a new `weight` prop to the Body component. Choose between the `regular` and `bold` font weights. diff --git a/.changeset/soft-drinks-accept.md b/.changeset/soft-drinks-accept.md new file mode 100644 index 0000000000..8a74ca3489 --- /dev/null +++ b/.changeset/soft-drinks-accept.md @@ -0,0 +1,5 @@ +--- +'@sumup-oss/circuit-ui': minor +--- + +Deprecated the Body component's `variant` prop. Use the new `weight` prop instead of the `highlight` variant and use custom CSS to replace the other variants. diff --git a/packages/circuit-ui/components/Body/Body.mdx b/packages/circuit-ui/components/Body/Body.mdx index acb19ee7cb..ce74d9127e 100644 --- a/packages/circuit-ui/components/Body/Body.mdx +++ b/packages/circuit-ui/components/Body/Body.mdx @@ -30,6 +30,8 @@ The Body component comes in three weights. Use the default `regular` weight in m ### Variants + + The Body component accepts five different variants—`highlight`, `quote`, `confirm`, `alert` and `subtle`—to tailor it according to the content we are presenting. Different variants will render different HTML elements by default: diff --git a/packages/circuit-ui/components/Body/Body.stories.tsx b/packages/circuit-ui/components/Body/Body.stories.tsx index ae3a36af8e..70b869e38c 100644 --- a/packages/circuit-ui/components/Body/Body.stories.tsx +++ b/packages/circuit-ui/components/Body/Body.stories.tsx @@ -13,6 +13,8 @@ * limitations under the License. */ +import { BodyLarge } from '../BodyLarge/BodyLarge.js'; + import type { BodyProps } from './Body.js'; import { Body } from './index.js'; @@ -23,6 +25,7 @@ const content = export default { title: 'Typography/Body', component: Body, + subcomponents: { BodyLarge }, argTypes: { as: { control: 'text' }, }, diff --git a/packages/circuit-ui/components/Body/Body.tsx b/packages/circuit-ui/components/Body/Body.tsx index d1502d025d..bac58c7b73 100644 --- a/packages/circuit-ui/components/Body/Body.tsx +++ b/packages/circuit-ui/components/Body/Body.tsx @@ -44,7 +44,8 @@ export interface BodyProps extends HTMLAttributes { */ weight?: 'regular' | 'bold'; /** - * Choose from style variants. + * @deprecated Use the `weight` prop instead of the `highlight` variant and + * use custom CSS to replace the other variants. */ variant?: Variant; /** @@ -75,6 +76,20 @@ export const Body = forwardRef( const Element = as || getHTMLElement(variant); if (process.env.NODE_ENV !== 'production') { + if (variant) { + if (variant === 'highlight') { + deprecate( + 'Body', + 'The "highlight" variant has been deprecated. Use the "weight" prop instead.', + ); + } else { + deprecate( + 'Body', + `The "${variant}" variant has been deprecated. Use custom CSS instead.`, + ); + } + } + const deprecatedSizeMap: Record = { 'one': 'm', 'two': 's', diff --git a/packages/circuit-ui/components/BodyLarge/BodyLarge.mdx b/packages/circuit-ui/components/BodyLarge/BodyLarge.mdx deleted file mode 100644 index fa308ec5f6..0000000000 --- a/packages/circuit-ui/components/BodyLarge/BodyLarge.mdx +++ /dev/null @@ -1,31 +0,0 @@ -import { Meta, Status, Props, Story } from '../../../../.storybook/components'; -import * as Stories from './BodyLarge.stories'; - - - -# BodyLarge - - -Use the Body component in size `l` instead. - - -The BodyLarge component is used to render content with large typography. Typically, large typography is intended for landing pages. In most cases, the [Body](Typography/Body) should be used instead. - - - - -## Component variations - -### Variants - -The BodyLarge accepts five different variants—`highlight`, `quote`, `confirm`, `alert` and `subtle`—to tailor it according to the content we are presenting. - -The `highlight` variant will render a `` element by default, while the `quote` variant will render a `blockquote`. - - - ---- - -## Accessibility - -All accessibility guidelines for the [Body component](Typography/Body) also apply to the BodyLarge component. diff --git a/packages/circuit-ui/components/BodyLarge/BodyLarge.module.css b/packages/circuit-ui/components/BodyLarge/BodyLarge.module.css deleted file mode 100644 index e2645d1970..0000000000 --- a/packages/circuit-ui/components/BodyLarge/BodyLarge.module.css +++ /dev/null @@ -1,31 +0,0 @@ -.base { - font-size: var(--cui-typography-body-l-font-size); - font-weight: var(--cui-font-weight-regular); - line-height: var(--cui-typography-body-l-line-height); -} - -/* Variants */ - -.highlight, -strong { - font-weight: var(--cui-font-weight-bold); -} - -.quote, -blockquote { - padding-left: var(--cui-spacings-kilo); - font-style: italic; - border-left: var(--cui-border-width-mega) solid var(--cui-border-accent); -} - -.confirm { - color: var(--cui-fg-success); -} - -.alert { - color: var(--cui-fg-danger); -} - -.subtle { - color: var(--cui-fg-subtle); -} diff --git a/packages/circuit-ui/components/BodyLarge/BodyLarge.stories.tsx b/packages/circuit-ui/components/BodyLarge/BodyLarge.stories.tsx deleted file mode 100644 index 6106a374b5..0000000000 --- a/packages/circuit-ui/components/BodyLarge/BodyLarge.stories.tsx +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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 type { BodyLargeProps } from './BodyLarge.js'; - -import { BodyLarge } from './index.js'; - -const content = - 'An electronic circuit is composed of individual electronic components, such as resistors, transistors, capacitors, inductors and diodes, connected by conductive wires or traces through which electric current can flow.'; - -export default { - title: 'Typography/BodyLarge', - component: BodyLarge, - argTypes: { - as: { control: 'text' }, - }, -}; - -export const Base = (args: BodyLargeProps) => ( - {content} -); - -const variants = ['highlight', 'quote', 'confirm', 'alert', 'subtle'] as const; - -export const Variants = (args: BodyLargeProps) => - variants.map((variant) => ( - - This is a {variant} BodyLarge - - )); diff --git a/packages/circuit-ui/components/BodyLarge/BodyLarge.tsx b/packages/circuit-ui/components/BodyLarge/BodyLarge.tsx index 476324ebd4..ec6dc6fb0a 100644 --- a/packages/circuit-ui/components/BodyLarge/BodyLarge.tsx +++ b/packages/circuit-ui/components/BodyLarge/BodyLarge.tsx @@ -13,46 +13,17 @@ * limitations under the License. */ -import { forwardRef, type HTMLAttributes, type Ref } from 'react'; +import { forwardRef } from 'react'; -import type { AsPropType } from '../../types/prop-types.js'; -import { clsx } from '../../styles/clsx.js'; import { deprecate } from '../../util/logger.js'; +import { Body, type BodyProps } from '../Body/Body.js'; -import classes from './BodyLarge.module.css'; - -type Variant = 'highlight' | 'quote' | 'confirm' | 'alert' | 'subtle'; - -export interface BodyLargeProps extends HTMLAttributes { - /** - * Choose from style variants. - */ - variant?: Variant; - /** - * Render the text using any HTML element. - */ - as?: AsPropType; - /** - * The ref to the HTML DOM element. - */ - ref?: Ref; -} - -function getHTMLElement(variant?: Variant): AsPropType { - if (variant === 'highlight') { - return 'strong'; - } - if (variant === 'quote') { - return 'blockquote'; - } - return 'p'; -} - +export type BodyLargeProps = Omit; /** * @deprecated Use the Body component in size `l` instead. */ export const BodyLarge = forwardRef( - ({ className, as, variant, ...props }, ref) => { + (props, ref) => { if (process.env.NODE_ENV !== 'production') { deprecate( 'BodyLarge', @@ -60,14 +31,7 @@ export const BodyLarge = forwardRef( ); } - const Element = as || getHTMLElement(variant); - return ( - - ); + return ; }, ); diff --git a/packages/eslint-plugin-circuit-ui/no-deprecated-props/index.ts b/packages/eslint-plugin-circuit-ui/no-deprecated-props/index.ts index 661a80551d..afde936391 100644 --- a/packages/eslint-plugin-circuit-ui/no-deprecated-props/index.ts +++ b/packages/eslint-plugin-circuit-ui/no-deprecated-props/index.ts @@ -65,6 +65,12 @@ const mappings: Config[] = [ props: ['variant'], alternative: '', }, + { + components: ['Body'], + props: ['variant'], + alternative: + 'Use the `weight` prop instead of the `highlight` variant and use custom CSS to replace the other variants.', + }, ]; export const noDeprecatedProps = createRule({