Skip to content

Commit 6d6a15a

Browse files
authored
add new recommendations for color and typography (#5350)
1 parent d7bbb94 commit 6d6a15a

File tree

10 files changed

+158
-329
lines changed

10 files changed

+158
-329
lines changed

documentation-site/examples/use-styletron/basic.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React from 'react';
2-
import {useStyletron} from 'baseui';
1+
import React from "react";
2+
import { useStyletron } from "baseui";
33

44
function UseStyletronExample() {
55
const [css, theme] = useStyletron();
66
return (
7-
<div className={css({color: theme.colors.accent})}>
7+
<div className={css({ color: theme.colors.backgroundAccent })}>
88
This is a blue div
99
</div>
1010
);

documentation-site/pages/components/typography.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Notification, KIND } from "baseui/notification";
2+
13
import Example from "../../components/example";
24
import Layout from "../../components/layout";
35
import Exports from "../../components/exports";
@@ -9,6 +11,15 @@ import Text from "examples/typography/text.tsx";
911

1012
export default Layout;
1113

14+
<Notification
15+
overrides={{ Body: { style: { width: "auto" } } }}
16+
kind={KIND.warning}
17+
>
18+
These typography components are built on top of the Block component, which we
19+
no longer recommend. Refer to the <a href="/guides/styling/">Styling</a> guide
20+
to understand how to use Base Web typography in your components.
21+
</Notification>
22+
1223
# Typography
1324

1425
A set of text block components for an out-of-the-box path to the BaseUI font standard.

documentation-site/pages/components/use-styletron.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ on the given component:
5050

5151
To understand overrides better, go [here](/guides/understanding-overrides/).
5252

53-
## Custom themes and Flow type
53+
## Custom themes and types
5454

55-
The `styled` and `withStyle` functions imported from `baseui` provide flow type support for the
55+
The `styled` and `withStyle` functions imported from `baseui` provide type support for the
5656
default [theme shape](/guides/theming/#theme-properties). However, if you create a custom theme with additional fields,
5757
flow will show an error. To help, baseui exports two utility functions `createThemedStyled` and
5858
`createThemedWithStyle`. These will return their respective functions with a provided theme type.
@@ -68,27 +68,27 @@ Doing so saves you from needing to import the custom theme type around. See belo
6868
+ createThemedUseStyletron,
6969
} from 'baseui';
7070

71-
type CustomThemeT = {myBlue: string, myRed: string};
71+
type CustomTheme = {myBlue: string, myRed: string};
7272

7373
// you'll likely want to import these functions from a relative path in your application
74-
+const themedStyled = createThemedStyled<CustomThemeT>();
75-
+const themedWithStyle = createThemedWithStyle<CustomThemeT>();
76-
+const themedUseStyletron = createThemedUseStyletron<CustomThemeT>();
74+
+const themedStyled = createThemedStyled<CustomTheme>();
75+
+const themedWithStyle = createThemedWithStyle<CustomTheme>();
76+
+const themedUseStyletron = createThemedUseStyletron<CustomTheme>();
7777

78-
type PropsT = {
78+
type Props = {
7979
$active: boolean
80-
- $theme: CustomThemeT
80+
- $theme: CustomTheme
8181
};
8282

83-
-const First = styled<PropsT>('div', props => {
84-
+const First = themedStyled<PropsT>('div', props => {
83+
-const First = styled<Props>('div', props => {
84+
+const First = themedStyled<Props>('div', props => {
8585
return {
8686
backgroundColor: props.$active ? props.$theme.colors.myBlue : props.$theme.colors.myRed,
8787
};
8888
});
8989

90-
-const Second = withStyle<PropsT>('div', props => {
91-
+const Second = themedWithStyle<PropsT>(First, props => {
90+
-const Second = withStyle<Props>('div', props => {
91+
+const Second = themedWithStyle<Props>(First, props => {
9292
return {
9393
color: props.$active ? props.$theme.colors.myBlue : props.$theme.colors.myRed,
9494
};
@@ -99,7 +99,7 @@ const Third = () => {
9999
+ const [css, theme] = themedUseStyletron();
100100

101101
return (
102-
- <div className={css({color: theme.colors.primary})}>
102+
- <div className={css({color: theme.colors.contentPrimary})}>
103103
+ <div className={css({color: theme.myBlue)}>
104104
test
105105
</div>

documentation-site/pages/getting-started/learn.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default () => {
2626
href="/my-link"
2727
className={css({
2828
fontSize: "20px",
29-
color: theme.colors.primary,
29+
color: theme.colors.contentPrimary,
3030
})}
3131
>
3232
Custom Link
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Layout from "../../components/layout";
2+
3+
export default Layout;
4+
5+
# Colors
6+
7+
There are three layers of color tokens in Base Web:
8+
9+
### 1) Primitive colors
10+
11+
These are the tokens that map directly to CSS hex values.
12+
13+
Examples: `green100`, `yellow600`, `magenta200`
14+
15+
### 2) Semantic colors
16+
17+
These tokens play a fundamental semantic role in the Base design language. They map to layer 1 primitive color tokens.
18+
19+
Examples: `contentPrimary`, `backgroundTeriary`, `borderWarning`
20+
21+
### 3) Component colors
22+
23+
These tokens are referenced inside Base Web styled components. They map both to primitive and semantic color tokens.
24+
25+
Examples: `buttonPrimaryText`, `linkHover`
26+
27+
### Deprecated colors
28+
29+
The foundation color tokens are deprecated. These tokens include `primaryA`, `primaryB`, `accent`, `positive`, `negative`, `warning`, and all of their variations. They are a legacy holdover from the previous theme creation API, intended to provide a quick way to "skin" our standard light and dark themes. They will be removed in a future version of Base Web.
30+
31+
## Using colors in your own components
32+
33+
All of the color tokens can be accessed via your application's theme object. It's rarely necessary to use primitive color tokens directly in your application. In most cases, semantic color tokens are the best choice. They are named according to the role they play in the design system, making them easier to use and understand in the context of your application. This helps assure that your components will be accessible and consistent with the rest of the design system. They also adjust between light and dark themes automatically. See the [Semantic tokens](/guides/styling/#semantic-tokens) section of the style guide for examples.
34+
35+
In some cases it may also make sense to use component color tokens. For example, if you create a custom button-like component, you can ensure consistency with other button components by using the collection of button-specific component color tokens that Base Web uses internally for styling its native button components.
36+
37+
## Customizing colors
38+
39+
To customize a specific instance of a component, use component overrides. For everything else, use the `overrides` argument of the [`createTheme`](./theming.mdx#createTheme) function.
40+
41+
As with using color tokens, it is usually best to customize your theme by targeting semantic color tokens and remapping them onto Base Web's primitive color tokens.

documentation-site/pages/guides/styling.mdx

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default function StyledFancyLink(props) {
202202
return (
203203
<StyledLink
204204
$style={({ $theme }) => ({
205-
color: $theme.colors.primary,
205+
color: $theme.colors.contentPrimary,
206206
})}
207207
{...props}
208208
/>
@@ -219,7 +219,7 @@ import { withStyle } from "baseui";
219219
import { StyledLink } from "./link";
220220

221221
export const StyledFancyLink = withStyle(StyledLink, ({ $theme }) => ({
222-
color: $theme.colors.primary,
222+
color: $theme.colors.contentPrimary,
223223
}));
224224
```
225225

@@ -359,37 +359,6 @@ There are three main techniques for styling Base Web components: the theme, `wit
359359

360360
The [theming guide](/guides/theming) is your best resource for understanding the nuances of theming Base Web components. Theming is the first strategy we would recommend trying out when styling Base Web components. You can modify spacing, border radii, colors, typography scales- a whole slew of systemic theme tokens which will change the look of Base Web.
361361

362-
```js
363-
import { createLightTheme } from "baseui";
364-
const primitives = {
365-
accent: "#F127E4", // hot pink
366-
accent50: "#FDEDFC",
367-
accent100: "#FCD3F9",
368-
accent200: "#F89FF3",
369-
accent300: "#F45AEA",
370-
accent400: "#F127E4",
371-
accent500: "#B71DAD",
372-
accent600: "#901788",
373-
accent700: "#600F5B",
374-
};
375-
376-
const overrides = {
377-
colors: {
378-
buttonSecondaryFill: primitives.accent100,
379-
buttonSecondaryText: primitives.accent,
380-
buttonSecondaryHover: primitives.accent200,
381-
buttonSecondaryActive: primitives.accent300,
382-
buttonSecondarySelectedFill: primitives.accent200,
383-
buttonSecondarySelectedText: primitives.accent,
384-
buttonSecondarySpinnerForeground: primitives.accent700,
385-
buttonSecondarySpinnerBackground: primitives.accent300,
386-
},
387-
};
388-
389-
export const lightTheme = createLightTheme(primitives, overrides);
390-
export const darkTheme = createDarkTheme(primitives, overrides);
391-
```
392-
393362
We think you can get pretty far with just the theming layer alone. When it isn’t enough there are a few more techniques available to you.
394363

395364
### withStyle
@@ -401,7 +370,7 @@ import { withStyle } from "baseui";
401370
import { StyledLink } from "baseui/link";
402371

403372
export const MyStyledLink = withStyle(StyledLink, ({ $theme }) => ({
404-
borderBottom: `solid 2px ${theme.colors.primary}`,
373+
borderBottom: `solid 2px ${theme.colors.contentPrimary}`,
405374
}));
406375
```
407376

0 commit comments

Comments
 (0)