Skip to content

Commit 864cbff

Browse files
authored
chore: Update font and line heights to latest design (#8464)
* chore: Update font and line heights to latest design * Include font loading in Provider * Add Hong Kong font and adjust weights for i18n fonts * Map CJK medium weight to bold instead of regular according to spectrum * update font URLs * Add fonts story to chromatic * fix chromatic * storybook is strange * Add CSS variable for font family * Update docs * add short selector keys
1 parent 4b07bd0 commit 864cbff

File tree

17 files changed

+593
-129
lines changed

17 files changed

+593
-129
lines changed

.chromatic/preview-head.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@
138138
<!--
139139
Load S2 adobe clean VF
140140
-->
141-
<link rel="preload" href="https://use.typekit.net/af/5e77d8/00000000000000007754d3a5/30/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n1&v=3" as="font" crossorigin="anonymous" />
142-
<link rel="stylesheet" href="https://use.typekit.net/yuq6kxz.css">
141+
<link rel="preload" href="https://use.typekit.net/af/b1226a/0000000000000000775c0485/31/l?primer=f592e0a4b9356877842506ce344308576437e4f677d7c9b78ca2162e6cad991a&fvd=n1&v=3" as="font" crossorigin="anonymous" />
143142

144143
<!--
145144
This web project loads adobe clean, adobe clean serif, myriad-arabic, myriad-hebrew, adobe-clean-han-japanese,

.storybook-s2/docs/Intro.jsx

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,41 +140,64 @@ export function Docs() {
140140
<P>You may also need to configure other tools such as TypeScript, Babel, ESLint, and Jest to support parsing import attributes. See <Link href="https://parceljs.org/features/macros/#usage-with-other-tools" target="_blank">these docs</Link> for details.</P>
141141
<P>See the <Link href="https://github.com/adobe/react-spectrum/tree/main/examples" target="_blank">examples folder</Link> in our repo for working setups with various build tools. For details on optimizing the output CSS, see the <Link href="?path=/docs/style-macro--docs#css-optimization" target="_top">style macro docs</Link>.</P>
142142
<H2>Setting up your app</H2>
143-
<P>Unlike React Spectrum v3, a <Code>Provider</Code> is not required. Instead, import <Code>@react-spectrum/s2/page.css</Code> in the entry component of your app to apply the background color and color scheme to the <Code>{'<html>'}</Code> element. This ensures that the entire page has the proper styles even before your JavaScript runs.</P>
144-
<Pre>{highlight(`import '@react-spectrum/s2/page.css';
145-
import {Button} from '@react-spectrum/s2';
143+
<P>Wrap your app in an S2 <Code>{'<Provider>'}</Code> component to load Spectrum 2 fonts for the user's locale and apply the appropriate Spectrum background layer for your app. When using S2 together with other versions of Spectrum, ensure that the S2 provider is the inner-most provider.</P>
144+
<Pre>{highlight(`import {Provider, Button} from '@react-spectrum/s2';
146145
147146
function App() {
148147
return (
149-
<Button
150-
variant="accent"
151-
onPress={() => alert('Hey there!')}>
152-
Hello Spectrum 2!
153-
</Button>
148+
// Wrap app in a <Provider> to load fonts, set background, set locale, etc.
149+
<Provider background="base">
150+
<Button
151+
variant="accent"
152+
onPress={() => alert('Hey there!')}>
153+
Hello Spectrum 2!
154+
</Button>
155+
</Provider>
154156
);
155157
}`)}</Pre>
156158
<Example>
157159
<Button variant="accent" onPress={() => alert('Hey there!')}>Hello Spectrum 2!</Button>
158160
</Example>
159-
<P><Strong>Note</Strong>: If you’re embedding Spectrum 2 as a section of a larger page rather than taking over the whole window, follow the <Link href="#embedded-sections" target="_self">directions below</Link> instead of using <Code>page.css</Code>.</P>
161+
<H3>Optimizing full-page apps</H3>
162+
<P>When building a full page S2 app that's not embedded within a larger page, import <Code>@react-spectrum/s2/page.css</Code> to apply the background color and color scheme to the <Code>{'<html>'}</Code> element instead of the <Code>{'<Provider>'}</Code>. This ensures that the page has styles even before your JavaScript loads. A <Code>{'<Provider>'}</Code> is still necessary in addition to <Code>page.css</Code> in order to include the fonts, set the locale, etc.</P>
163+
<Pre>{highlight(`// Apply S2 background to the <html> element
164+
import '@react-spectrum/s2/page.css';
165+
166+
function App() {
167+
return (
168+
<Provider>
169+
{/* ... */}
170+
</Provider>
171+
);
172+
}`)}</Pre>
173+
<P>By default, this uses the <Code>base</Code> background layer. This can be customized by setting the <Code>data-background</Code> attribute on the <Code>{'<html>'}</Code> element.</P>
174+
<Pre>{highlight(`<html data-background="layer-1">
175+
<!-- ... -->
176+
</html>`)}</Pre>
160177
<H3>Overriding the color scheme</H3>
161-
<P>By default, the page follows the user’s operating system color scheme setting, supporting both light and dark mode. The page background is set to the <Code>base</Code> Spectrum background layer by default. This can be configured by setting the <Code>data-color-scheme</Code> and <Code>data-background</Code> attributes on the <Code>{'<html>'}</Code> element. For example, to force the application to only render in light mode, set <Code>data-color-scheme="light"</Code>.</P>
178+
<P>By default, React Spectrum follows the operating system color scheme setting, supporting both light and dark mode. The <Code>colorScheme</Code> prop can be set on <Code>{'<Provider>'}</Code> to force the app to always render in a certain color scheme.</P>
179+
<Pre>{highlight(`import {Provider} from '@react-spectrum/s2';
180+
181+
<Provider colorScheme="light">
182+
{/* your app */}
183+
</Provider>`)}</Pre>
184+
<P>When using <Code>page.css</Code>, set the <Code>data-color-scheme</Code> attribute on the <Code>{'<html>'}</Code> element.</P>
162185
<Pre>{highlight(`<html data-color-scheme="light">
163186
<!-- ... -->
164187
</html>`)}</Pre>
165188
<H3>Overriding the locale</H3>
166-
<P>By default, React Spectrum uses the browser/operating system language setting for localized strings, date and number formatting, and to determine the layout direction (left-to-right or right-to-left). This can be overridden by rendering a <Code>{'<Provider>'}</Code> component at the root of your app, and setting the <Code>locale</Code> prop.</P>
189+
<P>By default, React Spectrum uses the browser/operating system language setting for localized strings, date and number formatting, and to determine the layout direction (left-to-right or right-to-left). This can be overridden by rendering setting the <Code>locale</Code> prop on the <Code>{'<Provider>'}</Code>.</P>
167190
<Pre>{highlight(`import {Provider} from '@react-spectrum/s2';
168191
169192
<Provider locale="en-US">
170193
{/* your app */}
171194
</Provider>`)}</Pre>
172-
<H3>Embedded sections</H3>
173-
<P>If you’re building an embedded section of a larger page using Spectrum 2, use the <Code>{'<Provider>'}</Code> component to set the background instead of importing <Code>page.css</Code>. The <Code>background</Code> prop should be set to the Spectrum background layer appropriate for your app, and the <Code>colorScheme</Code> can be overridden as well.</P>
174-
<Pre>{highlight(`import {Provider} from '@react-spectrum/s2';
175-
176-
<Provider background="base">
177-
{/* your app */}
195+
<H3>Server-side rendering</H3>
196+
<P>When using SSR, the <Code>{'<Provider>'}</Code> component can be rendered as the root <Code>{'<html>'}</Code> element. The <Code>locale</Code> prop should always be specified to avoid hydration errors. <Code>page.css</Code> is not needed in this case.</P>
197+
<Pre>{highlight(`<Provider elementType="html" locale="en-US">
198+
<body>
199+
{/* ... */}
200+
</body>
178201
</Provider>`)}</Pre>
179202
<H3>Usage with older React Spectrum versions</H3>
180203
<P>See Adobe internal documentation.</P>

.storybook-s2/preview-head.html

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +0,0 @@
1-
<!--
2-
This web project loads adobe clean, adobe clean serif, myriad-arabic, myriad-hebrew, adobe-clean-han-japanese,
3-
adobe-clean-han-korean, adobe-clean-han-simplified-c, and adobe-clean-han-traditional.
4-
These fonts and this web project are managed by a team account.
5-
-->
6-
<script>
7-
(function(d) {
8-
var config = {
9-
kitId: 'fqj0dxc',
10-
scriptTimeout: 3000,
11-
async: true
12-
},
13-
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
14-
})(document);
15-
</script>
16-
<style>
17-
@font-face {
18-
font-family: "Source Code Pro";
19-
src: url("https://use.typekit.net/af/398a64/00000000000000007735dc06/30/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3") format("woff2"),url("https://use.typekit.net/af/398a64/00000000000000007735dc06/30/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3") format("woff"),url("https://use.typekit.net/af/398a64/00000000000000007735dc06/30/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3") format("opentype");
20-
font-display: swap;
21-
font-style: normal;
22-
font-weight: 400;
23-
}
24-
</style>
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import type {Meta} from '@storybook/react';
14+
import {style} from '../style' with {type: 'macro'};
15+
import {useLocale} from 'react-aria';
16+
17+
const meta: Meta<any> = {
18+
title: 'S2 Chromatic/Fonts'
19+
};
20+
21+
export default meta;
22+
23+
const messages = {
24+
'en': {
25+
'button': 'Edit',
26+
'copy': 'Copy',
27+
'cut': 'Cut',
28+
'paste': 'Paste'
29+
},
30+
'ar': {
31+
'button': 'يحرر',
32+
'copy': 'ينسخ',
33+
'cut': 'يقطع',
34+
'paste': 'معجون'
35+
},
36+
'he': {
37+
'button': 'לַעֲרוֹך',
38+
'copy': 'עותק',
39+
'cut': 'גזירה',
40+
'paste': 'לְהַדבִּיק'
41+
},
42+
'ja': {
43+
'button': '編集',
44+
'copy': 'コピー',
45+
'cut': '切る',
46+
'paste': 'ペースト'
47+
},
48+
'ko': {
49+
'button': '편집하다',
50+
'copy': '복사',
51+
'cut': '자르다',
52+
'paste': '반죽'
53+
},
54+
'zh-Hans': {
55+
'button': '编辑',
56+
'copy': '复制',
57+
'cut': '切',
58+
'paste': '粘贴'
59+
},
60+
'zh-HK': {
61+
'button': '編輯',
62+
'copy': '複製',
63+
'cut': '切',
64+
'paste': '粘貼'
65+
},
66+
'zh-Hant': {
67+
'button': '編輯',
68+
'copy': '複製',
69+
'cut': '切',
70+
'paste': '粘貼'
71+
}
72+
};
73+
74+
function Example() {
75+
let {locale} = useLocale();
76+
let m = messages[locale] || messages.en;
77+
return (
78+
<div
79+
className={style({
80+
display: 'grid',
81+
width: 'full',
82+
gridTemplateColumns: {
83+
default: '1fr',
84+
sm: 'repeat(3, auto)',
85+
md: 'repeat(6, auto)'
86+
},
87+
justifyContent: 'space-between'
88+
})}>
89+
<ul className={style({padding: 0, listStyleType: 'none'})}>
90+
<li className={style({font: 'ui-xs'})}>{m.button}</li>
91+
<li className={style({font: 'ui-sm'})}>{m.button}</li>
92+
<li className={style({font: 'ui'})}>{m.button}</li>
93+
<li className={style({font: 'ui-lg'})}>{m.button}</li>
94+
<li className={style({font: 'ui-xl'})}>{m.button}</li>
95+
<li className={style({font: 'ui-2xl'})}>{m.button}</li>
96+
<li className={style({font: 'ui-3xl'})}>{m.button}</li>
97+
</ul>
98+
<ul className={style({padding: 0, listStyleType: 'none'})}>
99+
<li className={style({font: 'body-2xs'})}>{m.copy}</li>
100+
<li className={style({font: 'body-xs'})}>{m.copy}</li>
101+
<li className={style({font: 'body-sm'})}>{m.copy}</li>
102+
<li className={style({font: 'body'})}>{m.copy}</li>
103+
<li className={style({font: 'body-lg'})}>{m.copy}</li>
104+
<li className={style({font: 'body-xl'})}>{m.copy}</li>
105+
<li className={style({font: 'body-2xl'})}>{m.copy}</li>
106+
<li className={style({font: 'body-3xl'})}>{m.copy}</li>
107+
</ul>
108+
<ul className={style({padding: 0, listStyleType: 'none'})}>
109+
<li className={style({font: 'heading-2xs'})}>{m.cut}</li>
110+
<li className={style({font: 'heading-xs'})}>{m.cut}</li>
111+
<li className={style({font: 'heading-sm'})}>{m.cut}</li>
112+
<li className={style({font: 'heading'})}>{m.cut}</li>
113+
<li className={style({font: 'heading-lg'})}>{m.cut}</li>
114+
<li className={style({font: 'heading-xl'})}>{m.cut}</li>
115+
<li className={style({font: 'heading-2xl'})}>{m.cut}</li>
116+
<li className={style({font: 'heading-3xl'})}>{m.cut}</li>
117+
</ul>
118+
<ul className={style({padding: 0, listStyleType: 'none'})}>
119+
<li className={style({font: 'title-xs'})}>{m.paste}</li>
120+
<li className={style({font: 'title-sm'})}>{m.paste}</li>
121+
<li className={style({font: 'title'})}>{m.paste}</li>
122+
<li className={style({font: 'title-lg'})}>{m.paste}</li>
123+
<li className={style({font: 'title-xl'})}>{m.paste}</li>
124+
<li className={style({font: 'title-2xl'})}>{m.paste}</li>
125+
<li className={style({font: 'title-3xl'})}>{m.paste}</li>
126+
</ul>
127+
<ul className={style({padding: 0, listStyleType: 'none'})}>
128+
<li className={style({font: 'detail-sm'})}>{m.button}</li>
129+
<li className={style({font: 'detail'})}>{m.button}</li>
130+
<li className={style({font: 'detail-lg'})}>{m.button}</li>
131+
<li className={style({font: 'detail-xl'})}>{m.button}</li>
132+
</ul>
133+
<ul className={style({padding: 0, listStyleType: 'none'})}>
134+
<li className={style({font: 'code-sm'})}>{m.cut}</li>
135+
<li className={style({font: 'code'})}>{m.cut}</li>
136+
<li className={style({font: 'code-lg'})}>{m.cut}</li>
137+
<li className={style({font: 'code-xl'})}>{m.cut}</li>
138+
</ul>
139+
</div>
140+
);
141+
}
142+
143+
function SerifExample() {
144+
return (
145+
<div
146+
className={style({
147+
display: 'grid',
148+
width: 'full',
149+
gridTemplateColumns: {
150+
default: '1fr',
151+
sm: 'repeat(3, auto)',
152+
md: 'repeat(6, auto)'
153+
},
154+
justifyContent: 'space-between'
155+
})}>
156+
<ul className={style({padding: 0, listStyleType: 'none'})}>
157+
<li className={style({font: 'heading-xs', fontFamily: 'serif'})}>Heading</li>
158+
<li className={style({font: 'heading-sm', fontFamily: 'serif'})}>Heading</li>
159+
<li className={style({font: 'heading', fontFamily: 'serif'})}>Heading</li>
160+
<li className={style({font: 'heading-lg', fontFamily: 'serif'})}>Heading</li>
161+
<li className={style({font: 'heading-xl', fontFamily: 'serif'})}>Heading</li>
162+
<li className={style({font: 'heading-2xl', fontFamily: 'serif'})}>Heading</li>
163+
<li className={style({font: 'heading-3xl', fontFamily: 'serif'})}>Heading</li>
164+
</ul>
165+
<ul className={style({padding: 0, listStyleType: 'none'})}>
166+
<li className={style({font: 'body-2xs', fontFamily: 'serif'})}>Body</li>
167+
<li className={style({font: 'body-xs', fontFamily: 'serif'})}>Body</li>
168+
<li className={style({font: 'body-sm', fontFamily: 'serif'})}>Body</li>
169+
<li className={style({font: 'body', fontFamily: 'serif'})}>Body</li>
170+
<li className={style({font: 'body-lg', fontFamily: 'serif'})}>Body</li>
171+
<li className={style({font: 'body-xl', fontFamily: 'serif'})}>Body</li>
172+
<li className={style({font: 'body-2xl', fontFamily: 'serif'})}>Body</li>
173+
<li className={style({font: 'body-3xl', fontFamily: 'serif'})}>Body</li>
174+
</ul>
175+
</div>
176+
);
177+
}
178+
179+
export const Default = {
180+
render: () => <Example />,
181+
parameters: {
182+
chromaticProvider: {
183+
colorSchemes: ['light'],
184+
locales: ['en', 'ar', 'he', 'ja', 'ko', 'zh-Hans', 'zh-HK', 'zh-Hant']
185+
}
186+
}
187+
};
188+
189+
export const Serif = {
190+
render: () => <SerifExample />,
191+
parameters: {
192+
chromaticProvider: {
193+
colorSchemes: ['light'],
194+
// Only en because other locales don't have a serif font.
195+
locales: ['en']
196+
}
197+
}
198+
};

packages/@react-spectrum/s2/src/CoachMark.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ let description = style({
243243
let keyboard = style({
244244
gridArea: 'keyboard',
245245
font: 'ui',
246-
fontWeight: 'light',
247246
color: 'gray-600',
248247
background: 'gray-25',
249248
unicodeBidi: 'plaintext'

0 commit comments

Comments
 (0)