@db-ux/react-core-components
v5.0.2
Published
React components for @db-ux/core-components
Downloads
5,905
Readme
@db-ux/react-core-components
A React library containing all styles & components of DB UX Design System (technical components). We also provide more information about specific components. This information is in our Design System documentation.
Install
pnpm add @db-ux/react-core-components @db-ux/core-components @db-ux/core-foundations --save-devStyling Dependencies
Vite Plugin
If you're using Vite, you can use the @db-ux/core-vite-plugin which simplifies the CSS setup to a single import.
pnpm add @db-ux/core-vite-plugin --save-devAdd the plugin to your vite.config.ts:
import { defineConfig } from "vite";
import dbUxPlugin from "@db-ux/core-vite-plugin";
export default defineConfig({
plugins: [dbUxPlugin()]
});Then import the plugin in your CSS file:
/* index.css */
@import "@db-ux/core-vite-plugin/index.css";📖 Learn more about @db-ux/core-vite-plugin node package
PostCSS Plugin (recommended)
We recommend using the @db-ux/core-postcss-plugin to reduce your bundle size. It flattens CSS custom properties by resolving var(), calc(), color-mix(), and light-dark() at build time, removing unused declarations.
pnpm add @db-ux/core-postcss-plugin --save-devConfigure it in vite.config.ts:
import { defineConfig } from "vite";
import { dbUxFlatten } from "@db-ux/core-postcss-plugin";
export default defineConfig({
css: {
transformer: "postcss", // required for Vite 8+ (default: 'lightningcss')
postcss: {
plugins: [dbUxFlatten()]
}
}
});📖 Learn more about @db-ux/core-postcss-plugin node package
Manual CSS Setup
If you're not using Vite or prefer manual setup, import the styles in your main CSS file:
/* index.css */
@layer whitelabel-theme, db-ux;
/* You may want to include another theme here, this is a whitelabel theme! So instead of including the following line of code, please have a look at the DB Theme section */
@import "@db-ux/core-foundations/build/styles/theme/rollup.css"
layer(whitelabel-theme);
@import "@db-ux/core-components/build/styles/bundle.css" layer(db-ux);Vite 8
Starting with Vite 8, the default CSS minifier was changed to LightningCSS, which provides buggy transformations for modern CSS features used by the DB UX Design System (e.g. light-dark() CSS function). To keep CSS output stable, configure vite.config.ts like this:
// vite.config.ts
export default defineConfig({
build: {
cssMinify: "esbuild"
}
});Alternatively, you could define a browserslist based on your individual browser support strategy — which might be totally different from the list Vite 8 defines by default (targeting browsers from the early 2020s):
// Note: You need to install the required packages first:
// npm install -D lightningcss browserslist
// vite.config.ts
import { browserslistToTargets } from "lightningcss";
import browserslist from "browserslist";
export default defineConfig({
css: {
lightningcss: {
targets: browserslistToTargets(
browserslist(
">= 0.5%, last 2 major versions, Firefox ESR, not dead"
)
)
}
}
});Next 16
Starting with Next 16, the default CSS minifier was changed to LightningCSS, which provides buggy transformations for modern CSS features used by the DB UX Design System (e.g. light-dark() CSS function). We might provide a specific configuration necessary to mitigate those problems in the near future. To keep CSS output stable in the meantime, configure next.config.ts like this:
// next.config.ts
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
experimental: {
useLightningcss: true,
lightningCssFeatures: {
exclude: ["light-dark"]
}
}
};
export default nextConfig;DB Theme
In case that you're building a website or application for Deutsche Bahn, you'll additionally have to install the DB Theme via the @db-ux/db-theme node package (even also available as an inner source node package, as described within that packages README).
Usage
import { DBButton } from "@db-ux/react-core-components";
<DBButton variant="brand" onClick={() => console.log("clicked")}>
Add item to cart
</DBButton>;AI Agent Support
For developers using AI coding assistants like GitHub Copilot or Amazon Q, we provide the @db-ux/agent-cli tool that automatically adds DB UX Design System documentation to your repository.
Quick Start
Run this command in your repository:
npx @db-ux/agent-cliThis will create or update .github/copilot-instructions.md with component documentation based on your installed @db-ux packages, helping AI agents provide better suggestions.
📖 Learn more about @db-ux/agent-cli node package
Code Quality
To enforce correct usage of DB UX Design System components in your React project, we provide the @db-ux/core-eslint-plugin ESLint plugin.
Installation
pnpm add eslint @db-ux/core-eslint-plugin @typescript-eslint/parser --save-devSetup
// eslint.config.js
import dbUx from "@db-ux/core-eslint-plugin";
import tsParser from "@typescript-eslint/parser";
export default [
{
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: { jsx: true }
}
},
plugins: {
"db-ux": dbUx
},
rules: dbUx.configs.recommended.rules
}
];📖 Learn more about @db-ux/core-eslint-plugin node package
Stylelint
To validate correct usage of DB UX Design System tokens in your CSS/SCSS, use the @db-ux/core-stylelint plugin.
Installation
pnpm add stylelint @db-ux/core-stylelint --save-devSetup
Add to your .stylelintrc.json:
{
"plugins": ["@db-ux/core-stylelint"],
"rules": {
"db-ux/use-spacings": [true],
"db-ux/use-sizing": [true],
"db-ux/use-border-width": [true],
"db-ux/use-border-radius": [true],
"db-ux/use-border-color": [true]
}
}📖 Learn more about @db-ux/core-stylelint node package
Deutsche Bahn brand
As we'd like to perfectly support our users and customers on their digital journey, the usage of Deutsche Bahn brand and trademarks are bound of clear guidelines and restrictions even if being used with the code that we're providing with this product; Deutsche Bahn fully reserves all rights regarding the Deutsche Bahn brand, even though that we're providing the code of DB UX Design System products free to use and release it under the Apache 2.0 license. Please have a look at our brand portal at https://marketingportal.extranet.deutschebahn.com/ for any further questions and whom to contact on any brand issues.
For any usage outside of Deutsche Bahn websites and applications you aren't allowed to use any Deutsche Bahn brand and design assets as well as protected characteristics and trademarks, that for not including the DB Theme.
Contributions
Contributions are very welcome, please refer to the contribution guide.
Code of conduct
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone – have a look at our Contributor Covenant Code of Conduct.
License
This project is licensed under Apache-2.0.
