@bloomreach/react-banana-ui
v2.0.0
Published
A TypeScript React component library of primitive and common UI components used across Bloomreach apps.
Maintainers
Keywords
Readme
React Banana UI
A TypeScript React component library of primitive and common UI components used across Bloomreach apps.
Table of Contents
- Viewing Available Components
- Guide from Figma Design to the React Banana UI Components
- Using library in a project
- Development
- Branching types
- Commit Message Format
- Creating a new component
- Storybook
- Autogen
- Testing
- Releasing
- Contributing Guidelines
- Code Quality Standards
Viewing Available Components
Visit the library Storybook to view the latest available components.
Guide from Figma Design to the React Banana UI Components
Use the following guide to translate a Figma design into a functional page using RBUI components.
Using library in a project
Install the library as a dependency in the project
npm i --save --save-exact @bloomreach/react-banana-uiThis package supports React 18 and 19 as peer dependencies:
- react (peer) -
^18.0.0 || ^19.0.0 - react-dom (peer) -
^18.0.0 || ^19.0.0 - @types/react (optional peer in TS projects)
Both ES module and CommonJS entry points are published, so import and require
both work:
import { Button } from '@bloomreach/react-banana-ui'; // dist/bloomreach-react-banana-ui.es.js
const { Button } = require('@bloomreach/react-banana-ui'); // dist/bloomreach-react-banana-ui.cjsComponents
To use components in your application, import them as named exports:
import { Button } from '@bloomreach/react-banana-ui';
function MyComponent() {
return <Button onClick={() => console.log('Button clicked!')}>Click Me</Button>;
}Prefer named imports for effective tree shaking.
Styles & Fonts
To make the library's styles and fonts available in your project, follow these steps:
Import the main stylesheet: Add the following line to your main application's style file (e.g.,
main.scssorindex.css):/* main.scss */ @import '@bloomreach/react-banana-ui/style.css'; /* ... other styles ... */Font Family: The library components set their own font family, but the stylesheet no longer styles
htmlorbody, so text outside the library components uses your application's font. Set it in your global stylesheet; seehtmlandbodyno longer get the library font.Webfonts (opt-in): The Bloomreach webfont files are not bundled into
style.css. Inlining them as base64 data URIs added roughly 636 KB to every consumer's CSS, whether or not they used the fonts. If your application should ship the Bloomreach webfonts, import the dedicated stylesheet as well:/* main.scss */ @import '@bloomreach/react-banana-ui/style.css'; @import '@bloomreach/react-banana-ui/fonts.css';fonts.cssre-exports the@font-facerules from@bloomreach/banana-theme, so your bundler resolves and emits the woff2 files itself (one copy, cacheable, and only the weights you actually reference). If you already load the same typefaces from your own application or a CDN, skip this import.
IMPORTANT
Avoid directly using --rbui-... and/or --banana-... CSS custom properties in your application styles. These variables are intended for internal library use only. Always use the library components to ensure proper styling and adherence to the design system.
Development
This section outlines the necessary steps and commands for developing with the React Banana UI library.
Prerequisites
Ensure you have the following installed:
- pnpm: >=12 - install any pnpm 12 once (installation, for example
npm install -g pnpm). It switches to the exact version in thepackageManagerfield ofpackage.jsonby itself. - Node.js: 26.13.1.
devEngines.runtimeinpackage.jsonmakes pnpm download and lock it, and everypnpm runscript uses it..nvmrcpins the same version for editors and plainnodecommands. Applications that install the package need Node >=20 (engines.node)
Getting Started
Install Dependencies: Run the following command to install all project dependencies:
pnpm install --frozen-lockfileThis command installs exactly what
pnpm-lock.yamlrecords and fails ifpackage.jsonand the lockfile disagree, ensuring consistency across environments.Run Storybook: Start the Storybook development server (alias of
pnpm run storybook) to view and develop components in isolation:pnpm run startStorybook will open at http://localhost:6006, and any changes saved in the source code will automatically reflect in the Storybook UI.
Create New Components: Follow the file structure in the Creating a new component section.
Build
To build the library for production, run the following command:
pnpm run buildThis command compiles the TypeScript code, bundles the components, and generates the necessary output files for distribution. The built files will be located in the dist/ directory.
To build the Storybook for deployment, run the following command:
pnpm run storybook:buildThis command compiles the Storybook stories and generates a static Storybook build, which can be deployed to a web server. The output will be in the storybook-static/ directory.
To build and publish the Storybook to the same S3 location used by GitLab CI, run:
pnpm run storybook:publishThis command first runs a quiet Storybook build, then uploads storybook-static/ to s3://brp-design-web/storybooks/react-banana-ui/<branch-name> and deletes files that no longer exist locally. Before publishing locally, make sure your AWS credentials are configured and the AWS CLI is authenticated. You can override the defaults with AWS_DEFAULT_REGION, S3_BUCKET, STORYBOOK_S3_PREFIX, and STORYBOOK_S3_BRANCH. For a dry run, use pnpm run storybook:publish --dry-run. If you already have a fresh storybook-static/ build, use pnpm run storybook:upload to skip the build step. The uploader keeps terminal output concise by showing a single colorized progress bar and a small summary instead of the full aws s3 sync log.
Docker Services
We use Docker Compose to manage various services required for local development and testing. The docker-compose.yml file defines these services.
- Playwright E2E Testing: The
playwright-e2eservice indocker-compose.ymlsets up a Playwright test environment within a Docker container, ensuring consistent end-to-end test execution across different environments. You can run these tests usingpnpm run e2e.
Branching types
To manage and automate complex release workflow based on multiple Git branches and distribution channels, we utilize the semantic-release library. Refer to the documentation for comprehensive details. Our current setup is streamlined but designed for future extensibility.
The current branch types are explained below.
- The
mainbranch - is a permanent branch, where releases happen for the latest versions. All versions from that branch will be published to the npm registry with alatestdist-tag; - The
nextbranch should be used when we want to develop an important feature, which is a breaking change. Considering the scope of this feature we want to make it available, at first, only to a limited amount of users in order to get feedback or run tests. Once we get that feedback we can make improvements and ultimately make the new feature available to all users by merging changes into themainbranch; Releases from thenextbranch will be published to the npm registry with anextdist-tag; - The maintenance branches (i.e.
2.xto maintain releasev2). The maintenance branch is a type of branch that allows publishing releases with a semantic version on top of the codebase of an old release. This is useful when you need to provide fixes or features to users who cannot upgrade to the last version of the package; - Feature branches (like
feature/BR-XX-my-awesome-feature,fix/BR-XX-that-is-life) or any other kind of branch to commit small units of work that do not produce releases (until merged into one of the branches above). These branches are ignored from now on as they don’t have to trigger releases;
The following changes should be done to change or extend the current setup:
- Add a new release/maintenance/pre-release branch to the
semantic-releaseconfiguration in./release.config.cjs, check the documentation for more details; - Update the GitLab pipeline
releasejob to allow running it with the new branch, check./.gitlab-ci.yml; - Verify that the new branch is marked as
protectedin the repository settings.
Find more examples of possible release workflows in the official semantic-release documentation.
Commit Message Format
To have an automated release process the git commit messages must follow the following format. This specification following Conventional Commits. It provides an easy set of rules for creating an explicit commit history. This convention dovetails with semantic version, by describing the features, fixes, and breaking changes made in commit messages.
Each commit message consists of a header, a body, and a footer.
<header>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>The header is mandatory and must conform to the Commit Message Header format.
The body is optional. When the body is present it must conform to the Commit Message Body format.
The footer is optional. The Commit Message Footer format describes what the footer is used for and the structure it must have.
The commit contains the following structural elements:
fix: a commit of the type fix patches a bug in your codebase (this correlates withPATCHin Semantic Versioning).feat: a commit of the type feat introduces a new feature to the codebase (this correlates withMINORin Semantic Versioning).BREAKING CHANGE: a commit that has a footer BREAKING CHANGE:, or appends a!after thetype/scope, introduces a breaking API change (correlating withMAJORin Semantic Versioning). A BREAKING CHANGE can be part of commits of any type.- types other than
fix: andfeat: are allowed, see types. - footers other than BREAKING CHANGE: may be provided and follow a convention similar to git trailer format.
Additional types are not mandated by the Conventional Commits specification, and have no implicit effect in Semantic Versioning (unless they include a BREAKING CHANGE).
Commit Message Header
<type>(<scope>): <short summary>
│ │ │
│ │ └─⫸ Summary in present tense. Not capitalized. No period at the end.
│ │
│ └─⫸ Commit Scope: Right now not used but will be expanded in the near future.
│
└─⫸ Commit Type: build|chore|ci|docs|feat|fix|perf|refactor|style|test.The <type> and <summary> fields are mandatory, the (<scope>) field is optional and not used now.
Type
Must be one of the following:
build- changes that affect the build system or external dependencies; Hidden from the release notes;chore- changes which are not fit to the rest of the types. Hidden from the release notes;ci- changes to our CI configuration files and scripts. Hidden from the release notes;docs- documentation only changes. Hidden from the release notes;feat- a new feature. Appeared in the release notes under sectionFeatures;fix- a bug fix. Appeared in the release notes under sectionBug Fixes;perf- a code change that improves performance. Appeared in the release notes under sectionPerformance Improvements;refactor- a code change that neither fixes a bug nor adds a feature. Hidden from the release notes;revert- revert of the previous changes. Appeared in the release notes under sectionReverts;style- changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc). Hidden from the release notes;test- adding missing tests or correcting existing tests. Hidden from the release notes.
If the prefix is feat, fix, perf or revert, it will appear in the release notes. However if there is any BREAKING CHANGE, the commit will always appear in the changelog.
Other prefixes are up to your discretion. Suggested prefixes are build, ci, docs ,style, refactor, style, test and chore for non-changelog related tasks.
Scope
Not used currently.
Summary
Use the summary field to provide a succinct description of the change:
- use the imperative, present tense: "change" not "changed" nor "changes"
- don't capitalize the first letter
- no dot (.) at the end
Commit Message Body
Just as in the summary, use the imperative, present tense: "fix" not "fixed" nor "fixes".
Explain the motivation for the change in the commit message body. This commit message should explain why you are making the change. You can include a comparison of the previous behavior with the new behavior in order to illustrate the impact of the change.
Commit Message Footer
The footer can contain information about breaking changes and is also the place to reference Jira tickets, and other MRs that this commit closes or is related to.
For example:
BREAKING CHANGE: <breaking change summary>
<BLANK LINE>
<breaking change description + migration instructions>
<BLANK LINE>
<BLANK LINE>
<Closes|Fixes> BR-<issue number>Breaking Change section should start with the phrase BREAKING CHANGE: followed by a summary of the breaking change, a blank line, and a detailed description of the breaking change that also includes migration instructions.
Similarly, a Deprecation section should start with DEPRECATED: followed by a short description of what is deprecated, a blank line, and a detailed description of the deprecation that also mentions the recommended update path.
Revert commits
If the commit reverts a previous commit, it should begin with revert: , followed by the header of the reverted commit.
The content of the commit message body should contain:
- information about the SHA of the commit being reverted in the following format:
This reverts commit <SHA>, - a clear description of the reason for reverting the commit message.
Creating a new component
Create a folder for the new component in its group with the following files:
component-name.tsx // Main component file
component-name.types.ts // Props types
component-name.scss // Component styles
component-name.spec.tsx // Unit tests
component-name.stories.tsx // Storybook stories
component-name.qa.stories.tsx // E2E tests stories
component-name.test.tsx // E2E tests
index.ts // Exports the component and its props typeThen export the new component from the group's index.ts file (./src/components/<group>/index.ts).
Storybook
The Storybook is used to develop and view components in isolation. The storybook files should end with *.stories.tsx and be placed close to the component or module which is going to be documented for all new or rewritten components. The ./stories folder should locate only generic information about the library itself and additionally, complex stories involving multiple components.
The ./stories folder holds the MDX documentation pages (getting started, design tokens) and their assets; component stories live next to each component as *.stories.tsx.
Autogen
Icons
The icon files and exports are auto-generated using the script at scripts/gen-icons. If new icons are added in the banana-theme project, run pnpm run generate:icons to regenerate the icon exports.
Note: running the generator deletes and recreates src/components/foundations/icon/icons/.
Testing
Comprehensive testing is crucial for maintaining the quality and stability of the React Banana UI library. We employ a two-level testing strategy: unit tests for isolated logic and end-to-end (E2E) tests for overall component behavior in a real browser environment, including visual regression. Each new or modified component is expected to have thorough test coverage.
Unit tests
We use the Vitest framework for unit testing. Unit test files should end with *.spec.ts(x) and be co-located with the component or module being tested. When writing unit tests:
- Focus on isolated logic: Test individual functions, components, or modules in isolation, mocking dependencies as needed.
- Cover edge cases: Ensure your tests cover boundary conditions, invalid inputs, and error states.
- Assert component behavior: Verify that components render correctly, respond to user interactions, and manage their state as expected.
Common unit test commands:
pnpm test
pnpm run test:watch
pnpm run test:ui
pnpm run test:coverageEnd-to-end tests
We utilize the Playwright framework for end-to-end testing. These tests are co-located with their respective components (files ending with *.test.ts(x)) and run against dedicated Storybook stories (*.qa.stories.ts(x)). The primary goal of E2E tests is to eliminate manual QA efforts and ensure high-quality components for end-users. Key aspects of our E2E testing strategy include:
- Comprehensive Scenarios: Each component should be covered with E2E tests that simulate various user interactions, component states, and different scenarios.
- Visual Regression Testing: This is a critical part of our E2E suite, ensuring that visual changes are intentional and do not introduce unexpected regressions. When visual failures occur and are deemed correct, update the snapshots using
pnpm run e2e:update. - Balancing Coverage and Performance: While extensive coverage is vital, E2E tests can be slow. Strive for a balance between comprehensive test scenarios and efficient test execution. Prioritize the quality of components, and always consider performance optimizations for CI.
Run e2e tests
- Use the command
pnpm run e2eto start end-to-end tests inside the Docker container (thedockeranddocker composeshould be installed on your machine). - When tests are done check the Playwright output in the console if some of the tests failed use the following command to open the Playwright report:
pnpm run e2e:report - For a local run without Docker, use
pnpm run e2e:internal(builds Storybook then runs Playwright).
Update failed visual regression tests
- If the failure appeared in the visual regression tests and those changes are correct, please update the existing reference images with the following command:
pnpm run e2e:update. The Playwright will generate new correct reference images which should be committed to the repository. - Important: Playwright snapshots should always be generated within the Docker environment (
pnpm run e2e:updatewill use Docker by default). This ensures consistency with the Linux environment used in the GitLab pipeline, preventing discrepancies caused by operating system-specific rendering differences.
The e2e tests configuration for CI and local development
E2E tests are executed in a Docker container, both locally and in CI, leveraging the official Playwright Docker image. This approach ensures a consistent and predictable testing environment across all development and integration stages. The CI setup mirrors the local docker-compose.yml configuration.
Configuration Synchronization
It is crucial to keep the CI setup for the e2e tests job (defined in .gitlab-ci.yml) synchronized with the local Docker Compose configuration (docker-compose.yml). Any changes made to one should be carefully applied to the other to maintain environment consistency and avoid unexpected test failures.
Contributing Guidelines
We welcome contributions to the React Banana UI library! To ensure a smooth and collaborative development process, please adhere to the following guidelines:
- Commit Message Format: All commit messages must follow the Conventional Commits specification. This helps automate releases and generate accurate changelogs. Please review the Commit Message Format section for detailed instructions.
- Testing: Before submitting any changes, ensure your code is thoroughly tested. This includes both Unit Tests for isolated logic and End-to-end Tests for comprehensive component behavior and visual regression. Refer to the Testing section for detailed guidance on writing and running tests.
- Code Quality: Maintain high code quality by adhering to the project's linting, formatting, and security best practices. (See
CLAUDE.mdfor the project conventions.) - Development Workflow: Follow the established Development workflow for installing dependencies, running Storybook, and generating new components.
- Branching: Understand and follow our Branching types for feature development, bug fixes, and releases.
Releasing
The release of the new version is going to be done automatically when the changes reach one of the release branches and commit messages contain one of the structural elements.
To preview the possible release version and release notes based on already existing commits run the following command
pnpm run release:dry-runSee MIGRATION.md for migration guidance and RELEASE_NOTES.md for detailed changes between versions.
GitLab Pipeline
The GitLab pipeline automates the build, test, and deployment processes for the React Banana UI library. It consists of several stages, each designed to ensure code quality, functionality, and proper release management.
- build: Compiles the TypeScript code, bundles the library, builds Storybook and verifies the artifacts, the bundle-size budget and the tree-shaking budgets.
- validate: Runs linting, TypeScript type checking, the production dependency audit and commit-message linting in parallel.
- test: Runs the unit tests with coverage thresholds, and the Playwright E2E suites sharded across browsers.
- deploy: Publishes Storybook for every branch to
s3://brp-design-web/storybooks/react-banana-ui/<branch>, the per-branch preview linked from the merge request template. - release: semantic-release publishes the new version to npm and updates the release notes, provided all previous stages pass.
The GitLab pipeline runs all the checks and if the library is in good order, the following automated steps occur:
- The release notes will be updated according to commit messages history;
- The library version will be bumped;
- A new commit will be created with the updated version and release notes;
- A new Git tag will be created in the repository;
- The new version of the library will be published to npm;
After these automated steps, a few manual actions are required:
- Announce the new release in the slack channel #react-banana-ui-component-library :tada:;
- Mark the new version as
releasedin the releases section in Jira once the ticket is merged and closed; - Take a break and then pick up the next challenge :muscle:!
Code Quality Standards
This section outlines the code quality standards enforced in the React Banana UI library, covering linting, formatting, security, and performance. Adhering to these standards ensures maintainable, secure, and performant code.
Linting & Formatting
- Linting: oxlint enforces code quality and consistency, with
eslint-plugin-perfectionistand@eslint-react/eslint-pluginloaded as JS plugins. Refer to the.oxlintrc.jsonfile for detailed rules. - Import Organization:
pnpm run lint:fixsorts imports into blocks: side-effect imports that are not stylesheets, packages, internal modules, relative modules, and finally stylesheets. Type imports sit next to the value imports from the same kind of source. - Formatting: oxfmt formats the codebase (
.oxfmtrc.json). Ensure your code is formatted using the provided scripts (pnpm run format/pnpm run format:check). - Quality Scripts: Utilize
pnpm run lint(pnpm run lint:fixfor auto-fixing),pnpm run format(pnpm run format:checkfor checking), andpnpm run check:typesfor type validation.
Git Hooks (Husky)
We utilize Husky to manage Git hooks, ensuring that certain scripts are run automatically before commits or pushes. This helps maintain code quality and consistency across the repository.
- Pre-commit hook: Runs
lint-staged, which lints the staged JavaScript and TypeScript files with oxlint (fixing what it can) and formats the staged files with oxfmt, so only properly formatted and linted code is committed. - Pre-push hook: Runs
pnpm run check:typesto perform TypeScript type checking before code is pushed to the remote repository. This helps catch type-related issues early in the development cycle.
Security Best Practices
- Input Validation: Use specific types (avoid
any), union types for variants (e.g.,primary | secondary), and avoiddangerouslySetInnerHTML. SanitizeclassNameinputs to allow only trusted class combinations. - Event Handler Security: Prevent default actions when components are loading or disabled. Safely call optional callbacks using optional chaining (e.g.,
onClick?.(event)). - XSS Prevention: Avoid
dangerouslySetInnerHTML, leverage React's built-in escaping, validate SVG props, and use trusted sources for assets. - Dependency Security: Regularly run
pnpm run security-audit, adhere to the specified Node.js and pnpm version requirements, control React peer dependencies, and commitpnpm-lock.yaml.
Performance Guidelines
- Component Optimization: Memoize expensive components (
memo) and calculations (useMemo), and useCallback for event handlers to prevent unnecessary re-renders. - Bundle Optimization: Prefer named imports (e.g.,
import { Button } from ...) for effective tree shaking and modular utility imports. - Efficient Patterns: Memoize class computations with
useMemo, avoid inline object creation for styles, and use controlled value hooks. - Memory Management: Implement cleanup functions in
useEffectfor subscriptions and event listeners to prevent memory leaks.
CSS Performance
- Efficient Selectors: Favor single-class selectors (e.g.,
.rbui-button-primary) over complex, nested selectors. Use design tokens (e.g.,var(--banana-color-text-primary)) and avoid deep nesting (max 3 levels).
Performance Budgets
- Bundle size: Aim for minimal bundle sizes, typically <50KB per component and <100KB for core components.
- Build Optimization: Externalize peer dependencies to reduce bundle size.
- Asset Optimization: Optimize SVG assets for efficient loading.
Common Pitfalls to Avoid
Avoid inline arrow functions for onClick, inline style objects, and unmemoized expensive calculations.
