Backpack UI
Theming
Integrations

Integrations

You can theme backpack UI components in several ways:

Global theming

Many EF products have their own set of colours for primary action buttons, form focus and suchlike. These can be set at the top level in whatever global css your site has, i.e:


_10
:root {
_10
--color-system-primary-accessible: teal;
_10
}

Now your buttons will look like this:

In case you don't want this override to apply to all components, we have added global classnames to all our components too. The classnames follow the convention ef-{COMPONENTNAME}, so if you just wanted to change the primary accessible colour for buttons you could target:


_10
.ef-button {
_10
--color-system-primary-accessible: teal;
_10
}

Using CSS modules

If using CSS modules in your product, you can do something similar:

CustomButton.tsx
css-modules-example.module.scss

_18
import { Button, ButtonGroup } from '@ef-global/backpack/Button';
_18
import styles from './css-modules-example.module.scss';
_18
_18
export const CssModules = () => {
_18
return (
_18
<ButtonGroup className={`u-mt-m ${styles.customButton}`}>
_18
<Button as={'button'} variant='primary'>
_18
Primary
_18
</Button>
_18
<Button as={'button'} variant='secondary'>
_18
Secondary
_18
</Button>
_18
<Button as={'button'} variant='link'>
_18
Link
_18
</Button>
_18
</ButtonGroup>
_18
);
_18
};

Using styled components


_21
import styled from "styled-components";
_21
import {Button, ButtonGroup as BackpackButtonGroup} from "@ef-global/backpack/lib/components/Button";
_21
_21
export const StyledComponents = () => {
_21
const ButtonGroup = styled(BackpackButtonGroup)`
_21
--color-system-primary-accessible: navy;
_21
`
_21
return (
_21
<ButtonGroup>
_21
<Button as={'button'} variant='primary'>
_21
Primary
_21
</Button>
_21
<Button as={'button'} variant='secondary'>
_21
Secondary
_21
</Button>
_21
<Button as={'button'} variant='link'>
_21
Link
_21
</Button>
_21
</ButtonGroup>
_21
)
_21
}

Using tailwind

You can also easily theme backpack components with a tailwind setup.

Inline

Due to css modules specificity, we advise that you use a prefix in your tailwind config. For example, in nextjs, you can add the __next ID added to the <main> tag to provide further specificity.

Since our Button component has child components for the background and content (to ensure the button text is on a different layer to the background and the scale transitions look clean), in this case we can target the classes to the bgClassName and contentClassName props

nextjs

_10
// tailwind.config.js
_10
module.exports = {
_10
...
_10
important: '#__next'
_10
}


_10
<Button
_10
as={'button'}
_10
bgClassName={`bg-slate-600`}
_10
contentClassName={'text-slate-100'}
_10
variant="primary"
_10
>
_10
Content
_10
</Button>

@apply


CustomButton.tsx
customButton.module.scss

_10
import styles from './customButton.module.scss'
_10
<Button
_10
as={'button'}
_10
bgClassName={styles.customButtonBg}
_10
contentClassName={styles.customButtonContent}
_10
variant="primary"
_10
>
_10
Content
_10
</Button>