Skip to content

Commit 3f218bc

Browse files
authored
Merge pull request #205 from balena-io-modules/better-theme-integration
Better design token integration in the theme https://balena.fibery.io/Work/Project/Better-theme-integration-in-the-dashboard-1076
2 parents 6d700a5 + 62f5567 commit 3f218bc

45 files changed

Lines changed: 459 additions & 369 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.lintstagedrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"*.{ts,tsx}": ["balena-lint --fix"]
2+
"src/**/*.{ts,tsx}": ["balena-lint --fix"]
33
}

.storybook/global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ html {
1313

1414
html,
1515
body {
16-
font-family: var(--typography-fontfamily-body);
16+
font-family: var(--typography-fontFamily-body);
1717
height: 100%;
1818
margin: 0;
1919
padding: 0;

.storybook/manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { addons } from '@storybook/manager-api';
2-
import { create } from '@storybook/theming/create';
2+
import { create } from '@storybook/theming';
33
import { color, typography } from '@balena/design-tokens';
44

55
import '@balena/design-tokens/build/css/tokens.css';
@@ -12,7 +12,7 @@ export const balenaTheme = create({
1212
brandImage: '/images/logo.svg',
1313
brandTarget: '_blank',
1414

15-
fontBase: typography.fontfamily.body.value,
15+
fontBase: typography.fontFamily.body.value,
1616

1717
textColor: color.text.value,
1818

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"README.md"
1111
],
1212
"dependencies": {
13-
"@balena/design-tokens": "^0.11.0",
13+
"@balena/design-tokens": "^1.0.0",
1414
"@dnd-kit/core": "^6.3.1",
1515
"@dnd-kit/sortable": "^10.0.0",
1616
"@emotion/react": "^11.10.6",

src/components/AnimatedText/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const AnimatedText = ({
4747
if (animationType === 'grow') {
4848
return (
4949
<Grow in={showSlide} timeout={{ enter: 800, exit: 1200 }}>
50-
<Typography variant="inherit" component="div" color="hubYellow.main">
50+
<Typography variant="inherit" component="div">
5151
{words[wordIndex]}
5252
</Typography>
5353
</Grow>
@@ -56,7 +56,7 @@ export const AnimatedText = ({
5656
if (animationType === 'zoom') {
5757
return (
5858
<Zoom in={showSlide} timeout={{ enter: 800, exit: 1200 }}>
59-
<Typography variant="inherit" component="div" color="hubYellow.main">
59+
<Typography variant="inherit" component="div">
6060
{words[wordIndex]}
6161
</Typography>
6262
</Zoom>
@@ -69,7 +69,7 @@ export const AnimatedText = ({
6969
in={showSlide}
7070
timeout={{ enter: 800, exit: 1200 }}
7171
>
72-
<Typography variant="inherit" component="div" color="hubYellow.main">
72+
<Typography variant="inherit" component="div">
7373
{words[wordIndex]}
7474
</Typography>
7575
</Slide>
@@ -78,7 +78,7 @@ export const AnimatedText = ({
7878
if (animationType === 'fade') {
7979
return (
8080
<Fade in={showSlide} timeout={{ enter: 800, exit: 1200 }}>
81-
<Typography variant="inherit" component="div" color="hubYellow.main">
81+
<Typography variant="inherit" component="div">
8282
{words[wordIndex]}
8383
</Typography>
8484
</Fade>
@@ -93,7 +93,6 @@ export const AnimatedText = ({
9393
<Typography
9494
variant="inherit"
9595
component="div"
96-
color="hubYellow.main"
9796
sx={{ overflow: 'hidden', whiteSpace: 'nowrap' }}
9897
>
9998
{words[wordIndex]}

src/components/Announcement/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
} from '@mui/material';
1212
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
1313
import { faClose } from '@fortawesome/free-solid-svg-icons/faClose';
14-
import { shape } from '@balena/design-tokens';
1514
import { IconButtonWithTracking } from '../IconButtonWithTracking';
1615
import { useEffect } from 'react';
1716
import { useAnalyticsContext } from '../../contexts/AnalyticsContext';
1817
import type { SnackbarCloseReason } from '@mui/material/Snackbar/Snackbar';
18+
import { token } from '../../utils/token';
1919

2020
export type AnnouncementCloseReason =
2121
| SnackbarCloseReason
@@ -41,7 +41,7 @@ const AnnouncementRoot = styled(Box, {
4141
})(({ theme }) => ({
4242
alignItems: 'center',
4343
backgroundColor: 'white',
44-
borderRadius: shape.border_radius.md.value + 'px',
44+
borderRadius: token('shape.borderRadius.md'),
4545
boxShadow: '0px 0px 8px 0px rgba(35, 68, 94, 0.3)', // TODO add a design token for box shadows
4646
display: 'flex',
4747
gap: theme.spacing(3),
@@ -156,7 +156,7 @@ export const Announcement = React.forwardRef<HTMLDivElement, AnnouncementProps>(
156156
onClick={(e) => {
157157
onClose?.(e, 'closeButtonClick');
158158
}}
159-
sx={(theme) => ({ ml: 'auto', my: `-${theme.spacing(1)}` })}
159+
sx={{ ml: 'auto', my: -1 }}
160160
>
161161
<FontAwesomeIcon icon={faClose} />
162162
</IconButtonWithTracking>

src/components/Callout/index.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Box, styled, useThemeProps } from '@mui/material';
44
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
55
import type { Severity } from '../../theme';
66
import { severityIcons } from '../../theme';
7-
import { color } from '@balena/design-tokens';
7+
import { token } from '../../utils/token';
88

99
export interface CalloutProps {
1010
children: React.ReactNode;
@@ -24,24 +24,24 @@ const CalloutRoot = styled(Box, {
2424
borderLeft: 'solid 3px',
2525
borderLeftColor: 'var(--callout-border-color)',
2626
...(ownerState.variant === 'default' && {
27-
backgroundColor: color.bg.value,
27+
backgroundColor: token('color.bg'),
2828
}),
2929
...(ownerState.variant === 'subtle' && {
30-
backgroundColor: color.bg.subtlest.value,
30+
backgroundColor: token('color.bg.subtlest'),
3131
}),
32-
'--callout-border-color': color.border.info.value,
33-
'--callout-icon-color': color.icon.info.value,
32+
'--callout-border-color': token('color.border.info'),
33+
'--callout-icon-color': token('color.icon.info'),
3434
...(ownerState.severity === 'success' && {
35-
'--callout-border-color': color.border.success.value,
36-
'--callout-icon-color': color.icon.success.value,
35+
'--callout-border-color': token('color.border.success'),
36+
'--callout-icon-color': token('color.icon.success'),
3737
}),
3838
...(ownerState.severity === 'warning' && {
39-
'--callout-border-color': color.border.warning.value,
40-
'--callout-icon-color': color.icon.warning.value,
39+
'--callout-border-color': token('color.border.warning'),
40+
'--callout-icon-color': token('color.icon.warning'),
4141
}),
4242
...(ownerState.severity === 'danger' && {
43-
'--callout-border-color': color.border.danger.value,
44-
'--callout-icon-color': color.icon.danger.value,
43+
'--callout-border-color': token('color.border.danger'),
44+
'--callout-icon-color': token('color.icon.danger'),
4545
}),
4646
}));
4747

src/components/Code/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { TypographyProps } from '@mui/material';
22
import { Typography } from '@mui/material';
3-
import { color } from '@balena/design-tokens';
43
import { forwardRef } from 'react';
4+
import { token } from '../../utils/token';
55

66
/**
77
* This component will display a text as code.
@@ -12,9 +12,9 @@ export const Code = forwardRef<TypographyProps['ref'], TypographyProps>(
1212
<Typography
1313
sx={[
1414
{
15-
background: color.bg.code.value,
16-
color: color.text.code.value,
17-
borderRadius: 1,
15+
backgroundColor: token('color.bg.code'),
16+
color: token('color.text.code'),
17+
borderRadius: token('shape.borderRadius.sm'),
1818
px: 1,
1919
py: '2px',
2020
},

src/components/CollectionSummary/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { color } from '@balena/design-tokens';
21
import { faCaretDown } from '@fortawesome/free-solid-svg-icons/faCaretDown';
32
import { faCaretUp } from '@fortawesome/free-solid-svg-icons/faCaretUp';
43
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
54
import { Box, Button, Fade, Typography, Stack } from '@mui/material';
65
import { useMemo, useState } from 'react';
6+
import { token } from '../../utils/token';
77

88
export interface CollectionSummaryProps {
99
items: string[];
@@ -36,15 +36,17 @@ export const CollectionSummary = ({
3636
return (
3737
<Box>
3838
{items.length === 1 ? (
39-
<Typography color="text.secondary">{stringifyItems}</Typography>
39+
<Typography color={token('color.text.subtle')}>
40+
{stringifyItems}
41+
</Typography>
4042
) : (
4143
<Stack alignItems="start">
4244
<Button
4345
onClick={() => {
4446
setIsExpanded(!isExpanded);
4547
}}
4648
variant="text"
47-
sx={{ color: color.text.subtle.value, minWidth: 'unset' }}
49+
sx={{ color: token('color.text.subtle'), minWidth: 'unset' }}
4850
endIcon={
4951
isExpanded ? (
5052
<FontAwesomeIcon icon={faCaretUp} />
@@ -58,7 +60,7 @@ export const CollectionSummary = ({
5860
</Button>
5961

6062
<Fade in={isExpanded} appear={!isExpanded} unmountOnExit>
61-
<Typography variant="bodySm" color="text.secondary">
63+
<Typography variant="bodySm" color={token('color.text.subtle')}>
6264
{stringifyItems}
6365
</Typography>
6466
</Fade>

0 commit comments

Comments
 (0)