### Install Circuit UI Package (Shell) Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/introduction/2-getting-started.mdx Install the main Circuit UI package using npm or yarn in your project directory. ```sh # With npm: npm install @sumup-oss/circuit-ui # With yarn v1 yarn add @sumup-oss/circuit-ui ``` -------------------------------- ### Install Circuit UI Peer Dependencies (Shell) Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/introduction/2-getting-started.mdx Install the mandatory peer dependencies required by Circuit UI, including design tokens, icons, intl, React, and temporal-polyfill. ```sh # With npm: npm install --save @sumup-oss/design-tokens @sumup-oss/icons @sumup-oss/intl react react-dom temporal-polyfill # With yarn v1 yarn add @sumup-oss/design-tokens @sumup-oss/icons @sumup-oss/intl react react-dom temporal-polyfill ``` -------------------------------- ### Running Development Server with npm Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/nextjs/template/README.md This command starts the local development server for the Next.js application. It is the first step required to run the project locally and begin development. ```bash npm run dev ``` -------------------------------- ### Install New Circuit UI v2 Packages (@sumup/design-tokens, @sumup/icons, etc.) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Install the new separate packages that functionality was extracted into in Circuit UI v2, such as design tokens, icons, internationalization utilities, and event tracking, using both Yarn and npm. ```sh # With yarn yarn add @sumup/collector @sumup/design-tokens @sumup/icons @sumup/intl # With npm npm install --save @sumup/collector @sumup/design-tokens @sumup/icons @sumup/intl ``` -------------------------------- ### Import Circuit UI Styles and Theme (TSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/introduction/2-getting-started.mdx Import the necessary font styles, theme styles (light mode shown), and Circuit UI component styles into your application's main layout file (e.g., _app.tsx or layout.tsx in Next.js). Imports should be ordered as fonts, theme, then component styles. ```tsx // /app/layout.tsx or /pages/_app.tsx for Next.js import '@sumup-oss/design-tokens/fonts.css'; import '@sumup-oss/design-tokens/light.css'; import '@sumup-oss/circuit-ui/styles.css'; ``` -------------------------------- ### Starting Development Server npm Shell Source: https://github.com/sumup-oss/circuit-ui/blob/main/CONTRIBUTING.md Runs the start script, which typically builds packages on every change for development. ```Shell npm run start ``` -------------------------------- ### Starting Development Server Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/nextjs/README.md Runs the development build of the Next.js application. This typically starts a local server and enables hot module replacement for rapid development. The app should open automatically in the browser. ```shell npm run dev ``` -------------------------------- ### Installing Project Dependencies Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/astro/README.md Installs all necessary dependencies listed in the project's package.json file. ```npm npm install ``` -------------------------------- ### Install Circuit UI from Release Channel (bash) Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/contributing/4-release-process.mdx Use this command to install a specific version of Circuit UI from a designated release channel (e.g., `main`, `canary`, `next`) using npm. ```bash npm install @sumup-oss/circuit-ui@ ``` -------------------------------- ### Install Design Tokens Package - Shell Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/design-tokens/README.md Install the @sumup-oss/design-tokens package using either npm or yarn package managers. Run one of the provided commands in your terminal. ```sh # With npm npm install @sumup-oss/design-tokens # With yarn v1 yarn add @sumup-oss/design-tokens ``` -------------------------------- ### Starting Local Development Server Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/astro/README.md Starts the local development server for the Astro project, typically accessible at localhost:4321. ```npm npm run dev ``` -------------------------------- ### Installing @sumup-oss/eslint-plugin-circuit-ui Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/eslint-plugin-circuit-ui/README.md Install the ESLint plugin using npm or yarn as a development dependency. Requires Node.js and a package manager. ```sh npm install --save-dev @sumup-oss/eslint-plugin-circuit-ui ``` ```sh yarn add --dev @sumup-oss/eslint-plugin-circuit-ui ``` -------------------------------- ### Migrating Circuit UI Packages to @sumup-oss Scope (npm) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md This command sequence shows how to uninstall the old Circuit UI packages under the @sumup scope and install the new packages under the @sumup-oss scope, including the new required peer dependency 'temporal-polyfill'. This is necessary due to the package scope rename in v9. ```sh npm uninstall @sumup/circuit-ui @sumup/design-tokens @sumup/icons @sumup/intl npm install @sumup-oss/circuit-ui @sumup-oss/design-tokens @sumup-oss/icons @sumup-oss/intl temporal-polyfill ``` -------------------------------- ### Installing Dependencies npm Shell Source: https://github.com/sumup-oss/circuit-ui/blob/main/CONTRIBUTING.md Installs all necessary project dependencies in the repository's root directory. ```Shell npm install ``` -------------------------------- ### Getting Help with Astro CLI Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/astro/README.md Displays the help documentation for the Astro command-line interface. ```npm npm run astro -- --help ``` -------------------------------- ### Install Circuit UI v2 Peer Dependencies (React, Emotion) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Install the required peer dependencies for Circuit UI v2, including React, React DOM, and Emotion libraries, using both Yarn and npm. Circuit UI v2 requires React v16.8+. ```sh # With yarn yarn add react react-dom @emotion/core @emotion/styled emotion-theming # With npm npm install --save react-dom @emotion/core @emotion/styled emotion-theming ``` -------------------------------- ### Running Tests with Jest Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/nextjs/README.md Starts the Jest test runner to execute unit and integration tests. The setup includes `@testing-library/react` for UI component testing. The runner watches for file changes and re-runs tests automatically. ```shell npm run test ``` -------------------------------- ### Configure Viewport and Safe Areas (TSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/introduction/2-getting-started.mdx Ensure the viewport meta tag includes `viewport-fit=cover` and apply padding to the body using CSS safe area environment variables to handle notches and rounded corners on mobile devices. This example shows integration within a Next.js App component. ```tsx // /app/layout.tsx or /pages/_app.tsx for Next.js import '@sumup-oss/design-tokens/fonts.css'; import '@sumup-oss/design-tokens/light.css'; import '@sumup-oss/circuit-ui/styles.css'; import Head from 'next/head'; export default function App() { return ( <> {/* Your app */} ); } ``` -------------------------------- ### Installing @sumup-oss/icons with npm/yarn (Shell) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/icons/README.md These commands show how to install the @sumup-oss/icons package using either the npm or yarn package managers. This is the standard way to add the library as a dependency to your project. ```sh # With npm npm install @sumup-oss/icons # With yarn v1 yarn add @sumup-oss/icons ``` -------------------------------- ### Installing Circuit UI Stylelint Plugin with npm/yarn Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/stylelint-plugin-circuit-ui/README.md This snippet shows how to install the @sumup-oss/stylelint-plugin-circuit-ui package as a development dependency using either npm or yarn package managers. ```sh # With npm npm install --save-dev @sumup-oss/stylelint-plugin-circuit-ui # With yarn v1 yarn add --dev @sumup-oss/stylelint-plugin-circuit-ui ``` -------------------------------- ### Importing Dependencies for Documentation Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/SkipLink/SkipLink.mdx Imports necessary components from the storybook setup and the component's stories file to structure and render the documentation page. ```JavaScript import {Meta, Props, Status, Story} from '../../../../.storybook/components'; import * as Stories from './SkipLink.stories'; ``` -------------------------------- ### Installing Circuit UI with npm or yarn (sh) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/README.md This snippet provides commands to install the Circuit UI library using either npm or yarn package managers. It saves the package as a project dependency. ```sh # With npm npm install --save @sumup-oss/circuit-ui # With yarn v1 yarn add @sumup-oss/circuit-ui ``` -------------------------------- ### Preloading Inter Font in HTML Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md To optimize font loading speed, add preload links for the Inter font subsets your application uses to the global element of your HTML document. This example shows preloading the 'latin' subset. ```html ``` -------------------------------- ### Running Unit Tests (bash) Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/contributing/3-testing.mdx Execute this command in the project root to start unit tests in watch mode using Vitest and Testing Library. ```bash npm run test ``` -------------------------------- ### Apply Inline Styles to Inputs (Circuit UI v6) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Example demonstrating how to apply inline-block display and margin to Circuit UI Input components using Emotion.js css prop to replicate the functionality of the removed `inline` prop. ```tsx const inlineStyles = (theme) => css` display: inline-block; margin-right: ${theme.spacings.mega}; `; function Address() { return ( <> ); } ``` -------------------------------- ### Upgrading Circuit UI and Design Tokens Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md This command upgrades the Circuit UI and Design Tokens packages to their latest versions using Yarn. It is a necessary step when migrating between versions to get the latest features and changes. ```sh yarn upgrade @sumup/circuit-ui @sumup/design-tokens --latest ``` -------------------------------- ### Example of Description List HTML Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/List/List.mdx Demonstrates the HTML structure of a description list (
) with definition terms (
) and definition descriptions (
). This structure is discouraged due to inconsistent screen reader support. ```html
Account number
12345
Sign-up date
21.12.2021
``` -------------------------------- ### Upgrade Stylelint Plugin (sh) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Upgrades the Circuit UI Stylelint plugin dependency using npm. ```sh npm upgrade @sumup/stylelint-plugin-circuit-ui ``` -------------------------------- ### Installing Circuit UI Peer Dependencies (sh) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/README.md This snippet provides commands to install the required peer dependencies for Circuit UI using either npm or yarn. These dependencies include React, ReactDOM, and SumUp's design tokens, icons, and internationalization libraries. ```sh # With npm npm install --save react react-dom @sumup-oss/design-tokens @sumup-oss/icons @sumup-oss/intl # With yarn v1 yarn add react react-dom @sumup-oss/design-tokens @sumup-oss/icons @sumup-oss/intl ``` -------------------------------- ### Starting Development Server with Rebuild (Shell) Source: https://github.com/sumup-oss/circuit-ui/blob/main/CONTRIBUTING.md Runs the development server in the repository root, which automatically rebuilds all packages upon changes. This is the easiest way to ensure changes in one package are recognized in others. ```Shell npm run start ``` -------------------------------- ### Adding Circuit UI Stylelint Plugin to Configuration (JSON) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/stylelint-plugin-circuit-ui/README.md This JSON snippet demonstrates how to add the installed @sumup-oss/stylelint-plugin-circuit-ui to your Stylelint configuration file by listing it in the 'plugins' array. ```json { "plugins": ["@sumup-oss/stylelint-plugin-circuit-ui"] } ``` -------------------------------- ### Upgrade Circuit UI Dependencies (Shell) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Upgrade the core Circuit UI package and its peer dependencies (@sumup/design-tokens, @sumup/icons) to their latest versions using Yarn. ```Shell yarn upgrade @sumup/circuit-ui @sumup/design-tokens @sumup/icons --latest ``` -------------------------------- ### Bootstrapping Packages npm Shell Source: https://github.com/sumup-oss/circuit-ui/blob/main/CONTRIBUTING.md Runs the bootstrap script in the root directory to build and set up the packages within the monorepo after installation. ```Shell npm run bootstrap ``` -------------------------------- ### Install Legacy Date Picker Dependencies Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/CHANGELOG.md Install the required peer dependencies for the legacy date picker components (SingleDayPicker, RangePicker, CalendarTag, CalendarTagTwoStep) after they have been moved to the legacy status. ```bash npm install react-dates@^21.8 moment@^2.29 ``` -------------------------------- ### Upgrade Circuit UI and Dependencies - Shell Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Command to upgrade the main Circuit UI package (`@sumup/circuit-ui`) and its peer dependencies (`@sumup/design-tokens`, `@sumup/icons`) using npm. ```Shell npm upgrade @sumup/circuit-ui @sumup/design-tokens @sumup/icons ``` -------------------------------- ### Upgrading Circuit UI and Peer Dependencies Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md This command upgrades the core Circuit UI package along with its essential peer dependencies to their latest versions using npm. ```sh npm upgrade @sumup-oss/circuit-ui @sumup-oss/design-tokens @sumup-oss/icons @sumup-oss/stylelint-plugin-circuit-ui @sumup-oss/eslint-plugin-circuit-ui ``` -------------------------------- ### Updating JavaScript/TypeScript Imports After Package Scope Change Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md This diff example illustrates how to update import statements in JavaScript or TypeScript code to reflect the new @sumup-oss package scope. It shows changes for both standard imports and jest.mock calls. ```diff -import { Button, type ButtonProps } from '@sumup/circuit-ui'; +import { Button, type ButtonProps } from '@sumup-oss/circuit-ui'; -jest.mock('@sumup-oss/circuit-ui', () => ({ - ...jest.requireActual( - '@sumup-oss/circuit-ui', - ), -})); +jest.mock('@sumup-oss/circuit-ui', () => ({ + ...jest.requireActual( + '@sumup-oss/circuit-ui', + ), +})); ``` -------------------------------- ### Upgrade Emotion.js Dependencies (sh) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Upgrades Emotion.js related dependencies if your application uses Emotion or imports legacy Circuit UI components. ```sh npm upgrade @emotion/is-prop-valid @emotion/react @emotion/styled ``` -------------------------------- ### Running Storybook npm Shell Source: https://github.com/sumup-oss/circuit-ui/blob/main/CONTRIBUTING.md Runs the docs script, which typically starts the Storybook documentation site in development mode. ```Shell npm run docs ``` -------------------------------- ### Set Environment Variable to Disable Circuit UI Errors (Shell) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md This command sets the `UNSAFE_DISABLE_NO_MARGIN_ERRORS` environment variable to `true` before running the development server (`yarn dev` or `yarn start`). This temporarily disables runtime errors in Circuit UI v5 related to missing `noMargin` props, providing an escape hatch during the migration process. This variable should only be used in development builds and is a temporary workaround. ```shell UNSAFE_DISABLE_NO_MARGIN_ERRORS=true yarn dev # or yarn start ``` -------------------------------- ### Upgrade Circuit UI Linter Plugins - npm - sh Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Commands to upgrade the ESLint and Stylelint plugins specifically for Circuit UI using npm. ```sh # ESLint npm upgrade @sumup/eslint-plugin-circuit-ui # Stylelint npm upgrade @sumup/stylelint-plugin-circuit-ui ``` -------------------------------- ### Migrate Emotion 11 Dependencies (Shell) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Remove legacy Emotion packages and add the new ones required for Emotion 11. This includes core packages, Babel plugins, and Jest integration. ```Shell yarn remove @emotion/core jest-emotion babel-plugin-emotion # remove legacy dependencies yarn add @emotion/react # add new dependencies yarn add -D @emotion/babel-plugin @emotion/jest # add new dev dependencies yarn upgrade @emotion/styled --latest # upgrade existing packages ``` -------------------------------- ### Type Emotion Theme (Old Way - TypeScript) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Demonstrates the previous method of typing the Emotion theme using `CreateStyled` from `@emotion/styled` before Emotion 11's improved TypeScript support. ```TypeScript // utils/styled.ts import styled, { CreateStyled } from '@emotion/styled'; import { Theme } from '@sumup/design-tokens'; export default styled as CreateStyled; ``` -------------------------------- ### Upgrade Circuit UI and Dependencies - npm - sh Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Command to upgrade the main Circuit UI package along with its peer dependencies, `@sumup/design-tokens` and `@sumup/icons`, using npm. ```sh npm upgrade @sumup/circuit-ui @sumup/design-tokens @sumup/icons ``` -------------------------------- ### Use Typed Styled Component (Old Way - TSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Shows how a styled component was created using the custom `styled` instance typed with `CreateStyled` in the previous approach. ```TSX // components/RedCard.tsx import { css } from '@emotion/core'; import styled from 'util/styled'; const RedCard = styled(Card)( ({ theme }) => css` background-color: red; ` ); ``` -------------------------------- ### Upgrade Circuit UI Dependencies (v6) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Command to upgrade the core Circuit UI package and its peer dependencies (@sumup/design-tokens, @sumup/icons) to their latest versions using Yarn. ```sh yarn upgrade @sumup/circuit-ui @sumup/design-tokens @sumup/icons --latest ``` -------------------------------- ### Rendering Base Story Example Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/Checkbox/CheckboxInput.mdx Displays a specific story variant (the 'Base' story) of the CheckboxInput component within the documentation page. ```MDX ``` -------------------------------- ### Importing Popover Dependencies Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/Popover/Popover.mdx Imports necessary components (Meta, Props, Story) from the storybook setup and the component's own story definitions for use in the documentation file. ```TypeScript import { Meta, Props, Story } from '../../../../.storybook/components'; import * as Stories from './Popover.stories'; ``` -------------------------------- ### Importing ProgressBar Documentation Components and Stories Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/ProgressBar/ProgressBar.mdx Imports components (`Meta`, `Status`, `Props`, `Story`) used for generating documentation pages and imports all stories (`* as Stories`) from the ProgressBar stories file (`./ProgressBar.stories`). These imports are necessary for rendering the documentation page and interactive examples. ```javascript import { Meta, Status, Props, Story } from '../../../../.storybook/components'; import * as Stories from './ProgressBar.stories'; ``` -------------------------------- ### Example SVG Code for Correctly Aligned Icon Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/icons/CONTRIBUTING.md This SVG code represents an example icon that is correctly placed on the pixel grid, demonstrating the desired output after fixing alignment issues in Figma. It includes basic shape definitions and paths. ```svg `) to represent two-dimensional data like countries and their capitals, which is generally discouraged for this type of data. ```html
  • Germany (Capital: Berlin)
  • Ireland (Capital: Dublin)
  • Canada (Capital: Ottawa)
``` -------------------------------- ### Update InputElement Type - Circuit UI - diff Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Shows the necessary changes when the `InputElement` interface is deprecated. It demonstrates updating type references from `InputElement` to `HTMLInputElement` for `ChangeHandler` and `useRef`. ```diff diff -import { InputElement } from '@sumup-oss/circuit-ui'; -ChangeHandler +ChangeHandler -useRef() +useRef() ``` -------------------------------- ### Use Styled Component (New Way - TSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Shows how to use the standard `styled` import from `@emotion/styled` after the theme has been typed globally via module augmentation in Emotion 11. ```TSX // components/RedCard.tsx import { css } from '@emotion/core'; import styled from '@emotion/styled'; const RedCard = styled(Card)( ({ theme }) => css` background-color: red; ` ); ``` -------------------------------- ### Migrate CSS Color Tokens - CSS Diff Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Illustrates the migration path for CSS color usage, replacing legacy color tokens accessed via a JavaScript theme object with new semantic CSS variables provided by `@sumup/design-tokens`. ```CSS Diff -color: ${theme.colors.p500}; +color: var(--cui-fg-accent); ``` -------------------------------- ### Setting up New Project with Circuit UI + Next.js Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/nextjs/README.md Uses npx to create a new Next.js application based on the Circuit UI template from the SumUp OSS repository. Replace `my-app` with your desired project name. Requires Node.js v20.0.0 or higher. ```shell npx create-next-app --example "https://github.com/sumup-oss/circuit-ui/tree/main/templates/nextjs/template" my-app ``` -------------------------------- ### Replace BaseStyles with CSS Imports (tsx) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Shows how to replace the BaseStyles component with direct CSS imports for light theme and component styles when migrating from Emotion.js to CSS Modules. ```tsx // _app.tsx import { ThemeProvider } from '@emotion/react'; import { light } from '@sumup/design-tokens'; -import { BaseStyles } from '@sumup/circuit-ui'; +import '@sumup/design-tokens/light.css'; +import '@sumup/circuit-ui/styles.css'; function App({ Component, pageProps }) { return ( - ); } ``` -------------------------------- ### Illustrating Naming Conventions (TSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/contributing/2-code-conventions.mdx This snippet demonstrates the recommended naming conventions for Circuit UI components, props, and event handlers. It shows examples of using standard names and the `onVerb` pattern for handlers, contrasting them with less conventional alternatives. ```tsx // Do: Use standard component names and short prop names // Don't: Come up with unusual component names or name handlers without the `on` prefix ``` -------------------------------- ### Creating New Astro Project with Circuit UI Template Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/astro/README.md Initializes a new Astro project in the specified directory using the Circuit UI template from SumUp OSS. ```Shell npx create-astro@latest ./my-app --template sumup-oss/circuit-ui/templates/astro ``` -------------------------------- ### Run Circuit UI Codemod Directly with Node Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Provides an alternative command to run Circuit UI codemods directly using the node executable. This method can be used to resolve issues like 'node\r': No such file or directory that may occur when running with yarn. ```sh ./node_modules/.bin/circuit-ui migrate -l JavaScript -l TypeScript -t codemod-name ``` -------------------------------- ### Setting Icon Size Prop (React/JSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/icons/README.md Shows how to use the 'size' prop to specify a particular size for an icon component if multiple sizes are available. The example sets the 'CircleCheckmark' icon to size '24'. ```jsx import { CircleCheckmark } from '@sumup-oss/icons'; const SuccessMessage = ({ description }) => (
{description}
); ``` -------------------------------- ### Update Calendar Import - Circuit UI - diff Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Shows how to update the import path for the Calendar component from the experimental path to the stable path after the component became stable. This change is related to the `component-lifecycle-imports` update. ```diff diff - import { Calendar, type CalendarProps, type PlainDateRange } from '@sumup-oss/circuit-ui/experimental'; + import { Calendar, type CalendarProps, type PlainDateRange } from '@sumup-oss/circuit-ui'; ``` -------------------------------- ### Migrating Body Component Variants (JSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Replace legacy semantic variant names ('success', 'error') with new names ('confirm', 'alert') for the Body and BodyLarge components to align with updated design tokens. ```JSX ``` ```JSX ``` ```JSX ``` ```JSX ``` -------------------------------- ### Migrating Circuit UI Linter Plugins to @sumup-oss Scope (npm) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md These commands demonstrate how to update the Circuit UI ESLint and Stylelint plugins from the old @sumup scope to the new @sumup-oss scope using npm. This is part of the overall package scope migration in v9. ```sh # ESLint npm uninstall @sumup/eslint-plugin-circuit-ui npm install @sumup-oss/eslint-plugin-circuit-ui # Stylelint npm uninstall @sumup/stylelint-plugin-circuit-ui npm install @sumup-oss/stylelint-plugin-circuit-ui ``` -------------------------------- ### Migrating Badge Component Variants (JSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Replace legacy semantic variant names ('success', 'warning', 'danger') with new names ('confirm', 'notify', 'alert') for the Badge component to align with updated design tokens. ```JSX ``` ```JSX ``` ```JSX ``` ```JSX ``` ```JSX ``` ```JSX ``` -------------------------------- ### Migrating Input Component Styles v5 to v6 (labelStyles/css) Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Demonstrates how to update styling for the Input component in Circuit UI v6. The `labelStyles` prop is replaced by the `css` prop for wrapper styles, and the old `css` prop (for input styles) is replaced by the new `inputStyles` prop. ```diff ``` -------------------------------- ### Importing Storybook Components Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/introduction/1-welcome.mdx Imports necessary components (Meta, Image, Intro, Teaser) from a local Storybook components directory for use in the documentation page layout and structure. ```JavaScript import { Meta, Image, Intro, Teaser } from '../../.storybook/components'; ``` -------------------------------- ### Previewing Production Build Locally Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/astro/README.md Serves the production build locally, allowing you to preview the site before deployment. ```npm npm run preview ``` -------------------------------- ### Renaming Popover to ActionMenu Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md This diff shows the necessary code changes to migrate from the old Popover component to the new ActionMenu component, including updating imports, Jest mocks, and styled-components usage. The `no-renamed-components` ESLint rule can automate this. ```javascript -import { Popover, type PopoverProps } from '@sumup-oss/circuit-ui'; +import { ActionMenu, type ActionMenuProps } from '@sumup-oss/circuit-ui'; -jest.mock('@sumup-oss/circuit-ui', () => ({ - ...jest.requireActual('@sumup-oss/circuit-ui'), - Popover: jest.fn().mockImplementation(() =>
), - ), -})); +jest.mock('@sumup-oss/circuit-ui', () => ({ + ...jest.requireActual('@sumup-oss/circuit-ui'), + ActionMenu: jest.fn().mockImplementation(() =>
), + ), +})); - const StyledPopover = styled(Popover)` + const StyledPopover = styled(ActionMenu)` ``` -------------------------------- ### Migrating Input Component Optional Label v5 to v6 Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Shows the migration path for labels that included additional content like an 'Optional' indicator. In v6, the `label` prop only accepts a string, and the `optionalLabel` prop should be used for such indicators to improve accessibility. ```diff - const optionalStyles = (theme) => css` - color: ${theme.colors.n700}; - `; Address line 2 (Optional)} + label="Address line 2" + optionalLabel="Optional" />; ``` -------------------------------- ### Using Style Mixins with Emotion TSX Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/styles/style-mixins.mdx Demonstrates how to apply Circuit UI style mixins using Emotion's `css` prop and `styled` components. Shows examples of passing mixins directly, providing options, using them within style functions, and combining them with styled components. ```tsx import { clearfix, spacing } from '@sumup-oss/circuit-ui'; import styled from '@emotion/styled'; import { css } from '@emotion/react'; // Pass the style mixin directly to the `css` prop const Basic = () =>
; // Some style mixins accept options const Options = () =>
; // Style mixins can also be used in a style function... const someStyles = ({ theme }) => css` &:focus { ${focusOutline()}; } `; // ...or passed to a styled component directly const StyledComponent = styled.div(someStyles, clearfix); ``` -------------------------------- ### Using Utility Classes with clsx Helper in React Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Demonstrates how to use the new string utility classes exported by Circuit UI with the `clsx` helper function to conditionally apply multiple classes to a React component. This is useful for applications not using Emotion.js. ```tsx import { clsx, utilClasses } from '@sumup/circuit-ui'; function Component() { return
; } ``` -------------------------------- ### Using spacing Style Mixin TSX Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/styles/style-mixins.mdx Demonstrates practical examples of using the `spacing` style mixin. It shows how to apply uniform spacing to all sides, specify different spacing for individual sides using an object, and use the 'auto' value for horizontal centering. ```tsx // A single spacing string is applied to all sides const AllSides = () =>
; // Specify spacing for individual sides in an object const IndividualSides = () => (
); // The `spacing` mixin supports the special values `0` and `auto`, // this can be useful to horizontally center an element const HorizontallyCentered = () => (
); ``` -------------------------------- ### Replacing Tracking Prop with Event Handlers and Collector Hook Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Illustrates the migration from the deprecated `tracking` prop on Circuit UI components to using standard event handlers (`onClick`) and the `useClickTrigger` hook from `@sumup/collector` to dispatch tracking events. An ESLint rule can help identify deprecated prop usage. ```diff import { Button } from '@sumup/circuit-ui'; +import { useClickTrigger } from '@sumup/collector'; function Component() { + const dispatch = useClickTrigger(); + + const handleClick = () => { + dispatch({ + component: 'button', + label: 'track-button', + customParameters: { key: 'value' }, + }); + // ...other logic + } return ( ); } ``` -------------------------------- ### Using Dialog in Modal Mode (TSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/Dialog/Dialog.mdx Illustrates how to render the Dialog component as a modal overlay by setting the `isModal` prop to `true`. This example also uses React state to manage the dialog's visibility. ```tsx import { Dialog, Body, Button, Heading } from "@sumup-oss/circuit-ui"; import { useState } from "react"; function Component() { const [open, setOpen] = useState(false); return ( <> setOpen(false)} isModal > {() => ( Fun Fact: Bananas are berries, but strawberries aren't! )} ); } ``` -------------------------------- ### Updating Text Component Prop Usage Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md This snippet demonstrates the updated way to pass configuration values to components like Text after the removal of static properties. Instead of using static properties (e.g., Text.KILO), string literals are now used (e.g., "kilo"). This change is part of the migration to TypeScript, which provides type checking and autocomplete. ```diff import { Text } from '@sumup/circuit-ui'; const Hello = () => ( - Hello + Hello ); ``` -------------------------------- ### Migrating Design Tokens to CSS Custom Properties Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Shows the change from using the deprecated JavaScript `theme` object property for border radius to the new CSS custom property `--cui-border-radius.circle`. This migration is recommended and can be automated with an ESLint rule. ```diff -${theme.borderRadius.circle} +var(--cui-border-radius.circle) ``` -------------------------------- ### Creating Production Build Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/nextjs/README.md Generates an optimized production build of the Next.js application. The output is placed in the `.next/` folder and is ready for deployment. ```shell npm run build ``` -------------------------------- ### Building Production Site Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/astro/README.md Builds the Astro project for production, generating static assets in the ./dist/ directory. ```npm npm run build ``` -------------------------------- ### Using HTML Description Lists (`dl`) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/List/List.mdx Illustrates the usage of HTML description lists (`
`) for name-value pairs, such as terms and definitions, metadata, or questions and answers. ```html
Circuit
A closed, usually circular line that goes around an object or area.
Account number
12345
How do I find my account number?
You can find your account number under "Profile details".
``` -------------------------------- ### Enter Changeset Prerelease Mode (bash) Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/contributing/4-release-process.mdx To initiate a prerelease for a specific branch (`next` or `canary`), first switch to the desired branch, then run the `npx changeset pre enter` command with the channel name. This creates a `pre.json` file to signal prerelease mode. ```bash git checkout next # or `canary` npx changeset pre enter next # or `canary` ``` -------------------------------- ### Building Packages npm Shell Source: https://github.com/sumup-oss/circuit-ui/blob/main/CONTRIBUTING.md Runs the build script to build all packages once. ```Shell npm run build ``` -------------------------------- ### Preload Font File - HTML Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/design-tokens/README.md Add a preload link in the global `` element to speed up font loading. Choose the appropriate subset based on supported languages. ```html ``` -------------------------------- ### Running Linting and Formatting (bash) Source: https://github.com/sumup-oss/circuit-ui/blob/main/docs/contributing/3-testing.mdx Use these commands to manually run linting and formatting checks. The second command attempts to automatically fix identifiable issues using Prettier and ESLint. ```bash npm run lint # Automatically fix (some) issues npm run lint:fix ``` -------------------------------- ### Correct imports using new scope Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/eslint-plugin-circuit-ui/renamed-package-scope/README.md Examples of import statements that use the new `@sumup-oss` package scope, which is the correct usage according to this ESLint rule. ```TypeScript import { Input } from '@sumup-oss/circuit-ui'; import { Search } from '@sumup-oss/icons'; import '@sumup-oss/design-tokens/light.css'; ``` -------------------------------- ### Configuring Circuit UI Stylelint Rules (JSON) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/stylelint-plugin-circuit-ui/README.md This JSON snippet illustrates how to enable and configure specific rules provided by the @sumup-oss/stylelint-plugin-circuit-ui within the 'rules' section of your Stylelint configuration. ```json { "rules": { "circuit-ui/": true } } ``` -------------------------------- ### Loading Icon from URL (HTML) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/icons/README.md Demonstrates how to load an icon directly from the library's CDN using a standard HTML tag. The 'src' attribute points to the specific icon file URL. ```html checkmark ``` -------------------------------- ### Linting Code with ESLint Source: https://github.com/sumup-oss/circuit-ui/blob/main/templates/nextjs/README.md Runs the ESLint linter configured by Foundry to check the project's code for potential problems and style violations. Includes automatic fixes where possible. ```shell npm run lint ``` -------------------------------- ### Incorrect imports using old scope Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/eslint-plugin-circuit-ui/renamed-package-scope/README.md Examples of import statements that use the old `@sumup` package scope, which this ESLint rule flags as incorrect and can automatically fix. ```TypeScript import { Input } from '@sumup/circuit-ui'; import { Search } from '@sumup/icons'; import '@sumup/design-tokens/light.css'; ``` -------------------------------- ### Importing Documentation Components and Stories Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/ButtonGroup/ButtonGroup.mdx Imports necessary components from the Storybook documentation helper library and the component's stories file to render the documentation page. ```JavaScript import { Meta, Status, Props, Story } from '../../../../.storybook/components'; import * as Stories from './ButtonGroup.stories'; ``` -------------------------------- ### Importing Documentation Components (JavaScript) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/Hr/Hr.mdx Imports necessary components (`Meta`, `Status`, `Props`, `Story`) from the storybook documentation helper path for use in the documentation file. ```javascript import { Meta, Status, Props, Story } from '../../../../.storybook/components'; ``` -------------------------------- ### Importing Storybook Documentation Components Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/Select/Select.mdx Imports essential components (Meta, Status, Props, Story) from the Storybook components library, typically used for structuring and rendering documentation pages. ```JavaScript import { Meta, Status, Props, Story } from '../../../../.storybook/components'; ``` -------------------------------- ### Implementing Uncontrolled CheckboxGroup in React Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/CheckboxGroup/CheckboxGroup.mdx Shows how to use the CheckboxGroup component as an uncontrolled component in React. It utilizes `useRef` to potentially access checkbox elements directly, although the example primarily uses `defaultValue`. ```tsx import { useRef } from 'react'; import { CheckboxGroup } from '@sumup-oss/circuit-ui'; function Uncontrolled() { const checkboxRefs = useRef({}); const setCheckboxRef = (input: HTMLInputElement) => { checkboxRefs.current[input.value] = input; }; const options = [ { label: 'Apple', value: 'apple', ref: setCheckboxRef, }, ]; return ( ); } ``` -------------------------------- ### Triggering Notification Toast with Hook (TSX) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/NotificationToast/NotificationToast.mdx Illustrates how to use the `useNotificationToast` hook within a component to programmatically display a notification toast. It shows how to get the `setToast` function and call it with configuration options like `variant` and `body`. ```tsx import { useNotificationToast, Button } from '@sumup-oss/circuit-ui'; export function App({}) { const { setToast } = useNotificationToast(); const handleClick = () => { setToast({ variant: 'success', body: 'This is a toast message', }); }; return ; } ``` -------------------------------- ### Using Storybook Components in Documentation Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/circuit-ui/components/SkipLink/SkipLink.mdx Demonstrates how to use Storybook components like Meta, Status, Story, and Props within the documentation file to link to stories, display status, and render props tables. ```JSX ``` -------------------------------- ### Update PlainDateRange Selection - Calendar - TSX Source: https://github.com/sumup-oss/circuit-ui/blob/main/MIGRATION.md Demonstrates how to use the `updatePlainDateRange` helper function with the Calendar component's `onSelect` prop. This is necessary because the `PlainDateRange` type changed from an array to an object, affecting how selections are managed. ```tsx import { useState } from 'react'; import { Calendar, updatePlainDateRange } from '@sumup-oss/circuit-ui'; function Component() { const [selection, setSelection] = useState({}); return ( updatePlainDateRange(prevSelection, date) )} /> ); } ``` -------------------------------- ### Incorrect Usage of Invalid Circuit UI Custom Property (CSS) Source: https://github.com/sumup-oss/circuit-ui/blob/main/packages/eslint-plugin-circuit-ui/no-invalid-custom-properties/README.md This code snippet demonstrates an example of using an invalid Circuit UI custom property (`--cui-invalid-property`) which will be flagged as an error by the `no-invalid-custom-properties` lint rule. ```css color: var(--cui-invalid-property); ```