Styling

Restyle Bunny's React components to match your brand with the appearance prop, using variables, rules and fonts, on BunnyProvider or on a single component.

Every Bunny component is styled through one prop, appearance. Set it on BunnyProvider to restyle every component inside it, or on any component to restyle just that one on top of the provider’s. style and className on a component are for positioning only.

appearance has three parts:

  • variables: colors, font, radius and spacing the default look is built from. Change one and everything built from it follows.
  • rules: per-selector overrides such as .Input, .Label or .Button, merged over the defaults.
  • fonts: web fonts for variables.fontFamily, loaded onto the page and into the payment fields.
import { BunnyProvider, Checkout } from "@bunnyapp/components";

<BunnyProvider
  apiHost={apiHost}
  token={token}
  appearance={{
    variables: {
      colorPrimary: "#14532d",
      colorBackgroundSecondary: "#f6f1e7",
      fontFamily: "Inter, sans-serif",
    },
    rules: {
      ".Input:focus": { borderColor: "#14532d" },
    },
    fonts: [
      { cssSrc: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" },
    ],
  }}
>
  <Checkout priceListCode="business-monthly" />
</BunnyProvider>

ExamplesLink to Examples section

Two looks built only with appearance, shown on Checkout. The same object restyles every other component, including the card fields.

Editorial and print-like: warm paper, ink hairlines, square corners and a serif face.

Checkout in the Ledger style: cream background, serif type, square black-bordered inputs, a black selected Card tab and a black Pay button with spaced lettering

Checkout with the Ledger appearance.

const ledger = {
  variables: {
    colorPrimary: "#14532d",
    colorBackground: "#fffdf8",
    colorBackgroundSecondary: "#f6f1e7",
    colorText: "#1c1917",
    colorTextSecondary: "#6b635a",
    colorTextPlaceholder: "#a8a096",
    colorDanger: "#9f1239",
    colorSuccess: "#14532d",
    colorBorder: "#1c1917",
    borderWidth: "1px",
    borderRadius: "0px",
    fontFamily: '"Source Serif 4", Georgia, serif',
    fontSizeBase: "16px",
    focusBoxShadow: "none",
    gridRowSpacing: "24px",
  },
  rules: {
    ".Label": { fontSize: "14px", fontWeight: "600", color: "#6b635a", marginBottom: "8px" },
    ".Input": { padding: "11px 12px" },
    ".Input:hover": { borderColor: "#1c1917" },
    ".Input:focus": { borderColor: "#14532d", boxShadow: "0 0 0 1px #14532d" },
    ".Input--invalid": { borderColor: "#9f1239", boxShadow: "0 0 0 1px #9f1239" },
    ".Error": { fontSize: "13px" },
    ".Tab": { fontWeight: "500" },
    ".Tab:hover": { borderColor: "#1c1917" },
    ".Tab--selected": { backgroundColor: "#1c1917", color: "#fffdf8", borderColor: "#1c1917" },
    ".Tab:focus": { boxShadow: "0 0 0 1px #14532d" },
    ".Button": {
      backgroundColor: "#1c1917",
      color: "#fffdf8",
      letterSpacing: "0.1em",
      fontSize: "13px",
      fontWeight: "600",
      padding: "14px 16px",
    },
    ".Button:hover": { backgroundColor: "#14532d" },
    ".Button:active": { backgroundColor: "#052e16" },
    ".Tag": { fontWeight: "600", textTransform: "uppercase", letterSpacing: "0.06em", fontSize: "11px" },
    ".Card": { border: "1px solid #1c1917", boxShadow: "none" },
    ".Switch--checked": { backgroundColor: "#14532d" },
    ".Heading": { letterSpacing: "-0.01em" },
    ".Amount": { fontWeight: "600" },
    ".Overline": { color: "#1c1917", letterSpacing: "0.08em" },
    ".Document": { border: "1px solid #1c1917", boxShadow: "none" },
  },
  fonts: [
    { cssSrc: "https://fonts.googleapis.com/css2?family=Source+Serif+4:wght@400;500;600&display=swap" },
  ],
};

Learning the APILink to Learning the API section

The Appearance type is the reference. Type appearance={{ in your editor and use autocomplete and hover: every variable documents its default, and most selectors do too.

For the full styling guide (fonts, payment fields, CSP) and upgrading from 1.x, see the Styling components and Migrating to 2.0 sections of the README in the installed package, node_modules/@bunnyapp/components/README.md. The README shown on npmjs.com is the 1.x one until 2.0.0 is released.

The bunny-components agent skill can write an appearance object for you.