Skip to content

Commit db7561a

Browse files
committed
Update code block styling and syntax theme colors
Modernise apperance of code blocks by updating font, tweaking sizing, and introducing light/dark variants (aligned with react.dev). **Changes** - Remove the custom Source Code Pro web font in favor of the default Docusaurus system monospace font stack. - Add separate light and dark Prism syntax themes aligned to the react.dev Sandpack color palette, replacing the previous single dark-only custom theme. - Reduce code block font size and increase line height. - Update code block title backgrounds to match their code block, with a keyline separator. Syntax colors source: https://github.com/reactjs/react.dev/blob/6ec61348646040795fdaa9de14a9bec603260f87/src/styles/sandpack.css#L38-L78
1 parent f5bb54d commit db7561a

7 files changed

Lines changed: 146 additions & 80 deletions

File tree

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,20 @@ import type {ThemeConfig} from '@docusaurus/preset-classic';
99

1010
const theme: ThemeConfig['prism']['theme'] = {
1111
plain: {
12-
color: '#FFFFFF',
13-
backgroundColor: '#282C34',
12+
color: '#ffffff',
13+
backgroundColor: '#282c34',
1414
},
1515
styles: [
1616
{
17-
types: ['property'],
17+
types: ['comment', 'prolog', 'doctype', 'cdata'],
1818
style: {
19-
color: '#2aa198',
20-
},
21-
},
22-
{
23-
types: ['attr-name', 'comment', 'prolog', 'doctype', 'cdata'],
24-
style: {
25-
color: '#93a1a1',
19+
color: '#757575',
2620
},
2721
},
2822
{
2923
types: ['punctuation'],
3024
style: {
31-
color: '#657b83',
25+
color: '#ffffff',
3226
},
3327
},
3428
{
@@ -38,88 +32,69 @@ const theme: ThemeConfig['prism']['theme'] = {
3832
},
3933
},
4034
{
41-
types: ['selector', 'char', 'builtin', 'url'],
35+
types: ['keyword', 'attr-name'],
4236
style: {
43-
color: '#2aa198',
37+
color: '#77b7d7',
4438
},
4539
},
4640
{
47-
types: ['entity'],
41+
types: ['tag', 'operator'],
4842
style: {
49-
color: '#2aa198',
43+
color: '#dfab5c',
5044
},
5145
},
5246
{
53-
types: ['atrule', 'inserted'],
47+
types: ['function', 'class-name'],
5448
style: {
55-
color: '#859900',
49+
color: '#86d9ca',
5650
},
5751
},
5852
{
59-
types: ['important', 'variable', 'deleted'],
53+
types: ['property', 'selector', 'char', 'builtin', 'url', 'entity'],
6054
style: {
61-
color: '#cb4b16',
55+
color: '#77b7d7',
6256
},
6357
},
6458
{
65-
types: ['important', 'bold'],
59+
types: ['number', 'constant', 'symbol', 'boolean'],
6660
style: {
67-
fontWeight: 'bold',
68-
},
69-
},
70-
{
71-
types: ['italic'],
72-
style: {
73-
fontStyle: 'italic',
74-
},
75-
},
76-
{
77-
types: ['entity'],
78-
style: {
79-
cursor: 'help',
80-
},
81-
},
82-
// react-native theme
83-
{
84-
types: ['attr-name', 'keyword'],
85-
style: {
86-
color: '#c5a5c5',
61+
color: '#c64640',
8762
},
8863
},
8964
{
9065
types: ['string', 'regex', 'attr-value'],
9166
style: {
92-
color: '#8dc891',
67+
color: '#977cdc',
9368
},
9469
},
9570
{
96-
types: ['number', 'constant', 'symbol'],
71+
types: ['atrule', 'inserted'],
9772
style: {
98-
color: '#5a9bcf',
73+
color: '#86d9ca',
9974
},
10075
},
10176
{
102-
types: ['boolean'],
77+
types: ['important', 'variable', 'deleted'],
10378
style: {
104-
color: '#ff8b50',
79+
color: '#c64640',
10580
},
10681
},
10782
{
108-
types: ['class-name'],
83+
types: ['important', 'bold'],
10984
style: {
110-
color: '#fac863',
85+
fontWeight: 'bold',
11186
},
11287
},
11388
{
114-
types: ['function'],
89+
types: ['italic'],
11590
style: {
116-
color: '#79b6f2',
91+
fontStyle: 'italic',
11792
},
11893
},
11994
{
120-
types: ['operator', 'tag'],
95+
types: ['entity'],
12196
style: {
122-
color: '#fc929e',
97+
cursor: 'help',
12398
},
12499
},
125100
],

website/core/PrismThemeLight.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import type {ThemeConfig} from '@docusaurus/preset-classic';
9+
10+
const theme: ThemeConfig['prism']['theme'] = {
11+
plain: {
12+
color: '#24292e',
13+
backgroundColor: '#f6f8fa',
14+
},
15+
styles: [
16+
{
17+
types: ['comment', 'prolog', 'doctype', 'cdata'],
18+
style: {
19+
color: '#6a737d',
20+
},
21+
},
22+
{
23+
types: ['punctuation'],
24+
style: {
25+
color: '#24292e',
26+
},
27+
},
28+
{
29+
types: ['namespace'],
30+
style: {
31+
opacity: 0.7,
32+
},
33+
},
34+
{
35+
types: ['keyword', 'attr-name'],
36+
style: {
37+
color: '#d73a49',
38+
},
39+
},
40+
{
41+
types: ['tag', 'operator'],
42+
style: {
43+
color: '#22863a',
44+
},
45+
},
46+
{
47+
types: ['function', 'class-name'],
48+
style: {
49+
color: '#6f42c1',
50+
},
51+
},
52+
{
53+
types: ['property', 'selector', 'char', 'builtin', 'url', 'entity'],
54+
style: {
55+
color: '#005cc5',
56+
},
57+
},
58+
{
59+
types: ['number', 'constant', 'symbol', 'boolean'],
60+
style: {
61+
color: '#032f62',
62+
},
63+
},
64+
{
65+
types: ['string', 'regex', 'attr-value'],
66+
style: {
67+
color: '#032f62',
68+
},
69+
},
70+
{
71+
types: ['atrule', 'inserted'],
72+
style: {
73+
color: '#22863a',
74+
},
75+
},
76+
{
77+
types: ['important', 'variable', 'deleted'],
78+
style: {
79+
color: '#d73a49',
80+
},
81+
},
82+
{
83+
types: ['important', 'bold'],
84+
style: {
85+
fontWeight: 'bold',
86+
},
87+
},
88+
{
89+
types: ['italic'],
90+
style: {
91+
fontStyle: 'italic',
92+
},
93+
},
94+
{
95+
types: ['entity'],
96+
style: {
97+
cursor: 'help',
98+
},
99+
},
100+
],
101+
};
102+
103+
export default theme;

website/docusaurus.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import path from 'path';
1212

1313
import users from './showcase.json';
1414
import versions from './versions.json';
15-
import prismTheme from './core/PrismTheme';
15+
import prismThemeDark from './core/PrismThemeDark';
16+
import prismThemeLight from './core/PrismThemeLight';
1617

1718
import remarkSnackPlayer from '@react-native-website/remark-snackplayer';
1819
import remarkCodeblockLanguageTitle from '@react-native-website/remark-codeblock-language-as-title';
@@ -381,7 +382,8 @@ const config: Config = {
381382
},
382383
prism: {
383384
defaultLanguage: 'tsx',
384-
theme: prismTheme,
385+
theme: prismThemeLight,
386+
darkTheme: prismThemeDark,
385387
additionalLanguages: [
386388
'diff',
387389
'bash',

website/src/components/Home/Platforms/styles.module.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050
.codeEditorContentContainer code {
5151
background-color: var(--home-background);
5252
padding: 16px 48px 16px 24px;
53-
font-family:
54-
"Source Code Pro", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
55-
"Liberation Mono", "Courier New", monospace;
5653
color: var(--home-text);
5754
font-size: 14px;
5855
}

website/src/css/customTheme.scss

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,12 @@
4545

4646
--ifm-font-family-base:
4747
"Optimistic Display", system-ui, -apple-system, sans-serif;
48-
--ifm-font-family-monospace:
49-
"Source Code Pro", SFMono-Regular, Menlo, Monaco, Consolas,
50-
"Liberation Mono", "Courier New", monospace;
51-
5248
--ifm-background-color: white;
5349
--ifm-color-primary: #06bcee;
5450
--ifm-color-primary-75: #087ea4cc;
5551
--ifm-code-background: rgba(0, 0, 0, 0.06);
5652
--ifm-font-size-base: 17px;
57-
--ifm-code-font-size: 90%;
53+
--ifm-code-font-size: 85%;
5854
--ifm-code-padding-vertical: 0.05rem;
5955
--ifm-spacing-horizontal: 16px;
6056
--ifm-navbar-item-padding-horizontal: 18px;
@@ -69,7 +65,7 @@
6965
--ifm-table-head-color: var(--subtle);
7066
--ifm-link-hover-decoration: none;
7167
--ifm-navbar-background-color: var(--deepdark);
72-
--ifm-pre-line-height: 1.4;
68+
--ifm-pre-line-height: 1.6;
7369
--ifm-tabs-padding-vertical: 6px;
7470
--ifm-color-warning: #ffe564;
7571
--ifm-alert-color: var(--ifm-font-color-base);
@@ -247,20 +243,6 @@ html[data-theme="dark"] {
247243
font-style: normal;
248244
}
249245

250-
@font-face {
251-
font-family: "Source Code Pro";
252-
src: url("/static/fonts/Source-Code-Pro-Regular.woff2") format("woff2");
253-
font-weight: 400;
254-
font-style: normal;
255-
}
256-
257-
@font-face {
258-
font-family: "Source Code Pro";
259-
src: url("/static/fonts/Source-Code-Pro-Bold.woff2") format("woff2");
260-
font-weight: 700;
261-
font-style: normal;
262-
}
263-
264246
/* Content */
265247

266248
.main-wrapper {
@@ -527,15 +509,16 @@ hr {
527509
div[class*="codeBlockContainer"] {
528510
box-shadow: none;
529511
background: none;
512+
border: 1px solid var(--ifm-color-emphasis-300);
530513
border-radius: var(--ifm-global-radius);
531514

532515
pre {
533516
border-radius: 0 0 var(--ifm-global-radius) var(--ifm-global-radius);
534517
}
535518

536519
button {
537-
border-color: var(--light);
538-
background: var(--deepdark);
520+
border-color: var(--ifm-color-emphasis-300);
521+
background: var(--ifm-background-color);
539522
}
540523
}
541524

@@ -554,7 +537,8 @@ hr {
554537

555538
div[class*="codeBlockTitle"] {
556539
color: var(--subtle);
557-
background-color: var(--ifm-color-emphasis-300);
540+
background-color: #f6f8fa;
541+
border-bottom: 1px solid var(--ifm-color-emphasis-300);
558542
}
559543

560544
.tabs {
@@ -604,9 +588,14 @@ html[data-theme="dark"] {
604588
}
605589
}
606590

591+
div[class*="codeBlockContainer"] {
592+
border-color: rgba(225, 227, 230, 0.15);
593+
}
594+
607595
div[class*="codeBlockTitle"] {
608596
color: var(--docsearch-muted-color);
609-
background-color: var(--deepdark);
597+
background-color: #282c34;
598+
border-bottom-color: rgba(225, 227, 230, 0.15);
610599
}
611600
}
612601
}
-75.6 KB
Binary file not shown.
-74.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)