Skip to content

[CLOV-1372]BpkBox supporting more properties#4287

Open
IrinaWei wants to merge 1 commit intomainfrom
bpkBox-property-support
Open

[CLOV-1372]BpkBox supporting more properties#4287
IrinaWei wants to merge 1 commit intomainfrom
bpkBox-property-support

Conversation

@IrinaWei
Copy link
Contributor

New files

packages/bpk-component-layout/src/BpkBox.module.scss

SCSS module for BpkBox color props. Background colors use the bpk-surface-bg-colors mixin (shared with BpkPanel) plus explicit status fill and canvas classes. Text colors use compound selectors (.bpk-box.bpk-box--text-*) to beat Chakra emotion specificity, matching BpkText's pattern.

packages/bpk-component-layout/src/backgroundColors.ts

Defines BACKGROUND_COLORS (all-caps, matching TEXT_COLORS convention). Extends SURFACE_COLORS from bpk-react-utils and adds statusSuccessFill, statusDangerFill, statusWarningFill, canvas, and canvasContrast. Exports BpkBoxBackgroundColor type.


Modified files

packages/bpk-component-layout/src/BpkBox.tsx

  • Added backgroundColor and color props handled via SCSS class approach with eslint-disable-next-line (same pattern as BpkText)
  • Wrapped with React.forwardRef<HTMLElement> to expose the underlying DOM node

packages/bpk-component-layout/src/commonProps.ts

Added to BpkCommonLayoutProps (shared across all layout components):

Category Props added
HTML attributes id, role
ARIA All aria-* via extends AriaAttributes
Structural layout position, zIndex
Overflow overflow, overflowX, overflowY

packages/bpk-component-layout/src/types.ts

Added to BpkBoxProps only (interaction / visual, not shared):

Prop Type
backgroundColor BpkBoxBackgroundColor
color TextColor (from TEXT_COLORS)
cursor 'auto' | 'default' | 'pointer' | 'not-allowed'
opacity number
tabIndex number
onKeyDown / onKeyUp BoxProps event types

packages/bpk-component-layout/index.ts

Exported BACKGROUND_COLORS and BpkBoxBackgroundColor.

examples/bpk-component-layout/box-examples.tsx

Added SurfaceBackgroundColorExample, StatusFillBackgroundColorExample, CanvasBackgroundColorExample, and ColorExample.

examples/bpk-component-layout/box.stories.tsx

Added SurfaceBackgroundColor, StatusFillBackgroundColor, CanvasBackgroundColor, and Color stories.


Design decisions

  • backgroundColor and color use SCSS classes, not Chakra semantic tokens, to keep token usage within the Backpack boundary
  • display: none was already supported via BoxProps['display'] — no change needed
  • Props that remain intentionally excluded: className, style, transform, boxShadow, transition, border shorthands, and raw CSS custom properties

Copilot AI review requested due to automatic review settings March 17, 2026 07:50
@IrinaWei IrinaWei added DON'T MERGE minor Non breaking change labels Mar 17, 2026
@skyscanner-backpack-bot
Copy link

Visit https://backpack.github.io/storybook-prs/4287 to see this build running in a browser.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds additional visual and interaction capabilities to BpkBox in bpk-component-layout, primarily by introducing token-backed background/text color props (via SCSS modules) and expanding the common layout prop surface (ARIA/HTML attributes and a few structural layout controls).

Changes:

  • Introduces BACKGROUND_COLORS + BpkBoxBackgroundColor and wires BpkBox backgroundColor to SCSS module classes.
  • Adds color support on BpkBox using TEXT_COLORS-compatible class names (compound selectors to beat Chakra specificity).
  • Expands shared layout props (BpkCommonLayoutProps) to include id, role, aria-*, position, zIndex, and overflow props; updates examples/stories accordingly.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/bpk-component-layout/src/backgroundColors.ts Adds BACKGROUND_COLORS constant and BpkBoxBackgroundColor type to define allowed background tokens.
packages/bpk-component-layout/src/BpkBox.module.scss Implements the SCSS-module classes for background and text color modifiers used by BpkBox.
packages/bpk-component-layout/src/BpkBox.tsx Adds backgroundColor/color class handling and forwards refs to the underlying Chakra Box.
packages/bpk-component-layout/src/commonProps.ts Expands shared layout props with ARIA/HTML attributes and structural layout props.
packages/bpk-component-layout/src/types.ts Extends BpkBoxProps with background/text color types and additional interaction/visual props.
packages/bpk-component-layout/src/BpkBox-test.tsx Adds initial tests for backgroundColor rendering (currently not asserting class behavior).
packages/bpk-component-layout/index.ts Exposes BACKGROUND_COLORS + BpkBoxBackgroundColor from the package entrypoint.
examples/bpk-component-layout/examples.module.scss Tweaks example styling (tokenised background-size, ordering, outline block styling).
examples/bpk-component-layout/box-examples.tsx Adds new swatch examples for surface/status/canvas background tokens and text colors.
examples/bpk-component-layout/box.stories.tsx Adds new Storybook stories to surface the new examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +69 to +71
describe('backgroundColor', () => {
it('renders with a surface color token', () => {
const { container } = render(
expect(container.querySelector('div')).toBeInTheDocument();
});
});

Comment on lines 199 to 201
type BoxEventProps = Pick<BoxProps,
'onClick' | 'onFocus' | 'onBlur'
'onClick' | 'onFocus' | 'onBlur' | 'onKeyDown' | 'onKeyUp'
>;
Comment on lines 82 to 83
* - BpkBox reintroduces a minimal set of events (onClick, onFocus, onBlur)
* on its own props type.
Comment on lines +19 to +20
// backgroundColor keys must stay in sync with backgroundColors.ts
// color keys must stay in sync with TEXT_COLORS in bpk-component-text
@skyscanner-backpack-bot
Copy link

Warnings
⚠️

Package source files (e.g. packages/package-name/src/Component.js) were updated, but snapshots weren't. Have you checked that the tests still pass?

Browser support

If this is a visual change, make sure you've tested it in multiple browsers.

Generated by 🚫 dangerJS against c362073

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DON'T MERGE minor Non breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants