Skip to content

Commit

Permalink
feat: add localized fonts to support i18n (#2298)
Browse files Browse the repository at this point in the history
* feat: add paste-theme-provider class

* feat: add i18n fontFamily aliases and tokens

* feat: add font families based on html lang

* fix: set font to inherit

* feat: add font family stories for VRT

* feat: add react-helmet to change lang

* chore: update yarnlock

* fix: remove all english

* chore: add changeset

* chore: update react-helmet

* fix: remove extra selectors

* fix: rename aliases/tokens

* chore: update snapshots

* chore: update snapshots

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
shleewhite and kodiakhq[bot] committed Mar 18, 2022
1 parent 3044506 commit 8e5dfe1
Show file tree
Hide file tree
Showing 21 changed files with 172 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .changeset/calm-badgers-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@twilio-paste/design-tokens': minor
'@twilio-paste/core': minor
---

[Tokens] add i18n font family tokens
10 changes: 10 additions & 0 deletions .changeset/clean-birds-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@twilio-paste/button': patch
'@twilio-paste/form-pill-group': patch
'@twilio-paste/menu': patch
'@twilio-paste/pagination': patch
'@twilio-paste/select': patch
'@twilio-paste/core': patch
---

[Button, FormPillGroup, Menu, Pagination, Select] inherit fontFamily for i18n
6 changes: 6 additions & 0 deletions .changeset/modern-turtles-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@twilio-paste/theme': patch
'@twilio-paste/core': patch
---

[ThemeProvider] use non-latin fonts based on the HTML lang attribute to support i18n.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
"react-dom": "^17.0.2",
"react-dom-16": "npm:react-dom@^16.8.6",
"react-ga": "^3.3.0",
"react-helmet": "^6.1.0",
"react-router-dom": "6.2.1",
"react-test-renderer": "^16.8.6",
"regenerator-runtime": "^0.13.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-core/components/button/src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ResetStyles: BoxStyleProps = {
border: 'none',
outline: 'none',
transition: 'background-color 100ms ease-in, box-shadow 100ms ease-in, color 100ms ease-in',
fontFamily: 'fontFamilyText',
fontFamily: 'inherit',
fontWeight: 'fontWeightSemibold',
textDecoration: 'none',
position: 'relative',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const FormPillStyles = React.forwardRef<HTMLElement, FormPillStylesProps>(
columnGap="space20"
cursor="default"
display="flex"
fontFamily="fontFamilyText"
fontFamily="inherit"
fontSize="fontSize20"
fontWeight="fontWeightSemibold"
lineHeight="lineHeight10"
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-core/components/menu/src/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const StyledMenuItem = React.forwardRef<HTMLDivElement | HTMLAnchorElemen
color={props['aria-disabled'] ? 'colorTextWeaker' : 'colorText'}
display="block"
textAlign="left"
fontFamily="fontFamilyText"
fontFamily="inherit"
fontSize="fontSize30"
fontWeight="fontWeightNormal"
lineHeight="lineHeight30"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const PaginationArrowButton = React.forwardRef<HTMLButtonElement, PaginationArro
borderRadius={visibleLabel ? 'borderRadius10' : 'borderRadiusCircle'}
color="colorText"
display="flex"
fontFamily="fontFamilyText"
fontFamily="inherit"
fontVariantNumeric="tabular-nums"
fontWeight="fontWeightNormal"
lineHeight="lineHeight30"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const PaginationNumber = React.forwardRef<HTMLButtonElement, PaginationNumberPro
borderWidth="borderWidth10"
color={isCurrent ? 'colorTextWeakest' : 'colorText'}
display="inline-block"
fontFamily="fontFamilyText"
fontFamily="inherit"
fontSize="fontSize30"
fontVariantNumeric="tabular-nums"
fontWeight="fontWeightNormal"
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-core/components/select/src/Option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Option = React.forwardRef<HTMLOptionElement, OptionProps>(({children, elem
width={undefined}
backgroundColor="inherit"
color="inherit"
fontFamily="fontFamilyText"
fontFamily="inherit"
lineHeight="lineHeight50"
paddingTop="space30"
paddingBottom="space30"
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-core/components/select/src/OptionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const OptionGroup = React.forwardRef<HTMLOptGroupElement, OptionGroupProps>(
as="optgroup"
backgroundColor="inherit"
color="inherit"
fontFamily="fontFamilyText"
fontFamily="inherit"
fontWeight="fontWeightMedium"
fontStyle="normal"
margin="space20"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports[`Separator Render should set horizontal margins 1`] = `
}
<div
class="emotion-1"
class="paste-theme-provider emotion-1"
>
<hr
aria-orientation="horizontal"
Expand Down Expand Up @@ -74,7 +74,7 @@ exports[`Separator Render should set responsive horizontal margins 1`] = `
}
<div
class="emotion-1"
class="paste-theme-provider emotion-1"
>
<hr
aria-orientation="horizontal"
Expand Down Expand Up @@ -124,7 +124,7 @@ exports[`Separator Render should set responsive vertical margins 1`] = `
}
<div
class="emotion-1"
class="paste-theme-provider emotion-1"
>
<hr
aria-orientation="vertical"
Expand Down Expand Up @@ -160,7 +160,7 @@ exports[`Separator Render should set vertical margins 1`] = `
}
<div
class="emotion-1"
class="paste-theme-provider emotion-1"
>
<hr
aria-orientation="vertical"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ exports[`Design Tokens matches the Dark theme 1`] = `
\\"shadow-border-inverse-strongest\\": \\"0 0 0 1px #ffffff\\",
\\"font-family-text\\": \\"'Inter var experimental', 'Inter var', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif\\",
\\"font-family-code\\": \\"'Fira Mono', 'Courier New', Courier, monospace\\",
\\"font-family-text-japanese\\": \\"'Inter var experimental', 'Inter var', Hiragino Sans, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', 'メイリオ', Meiryo, Osaka, 'MS PGothic', sans-serif\\",
\\"font-family-text-korean\\": \\"'Inter var experimental', 'Inter var', 'Microsoft JhengHei', 微軟正黑體, 'Microsoft JhengHei UI', 'Microsoft YaHei', 微軟雅黑, 宋体, SimSun, sans-serif\\",
\\"font-family-text-chinese-traditional\\": \\"'Inter var experimental', 'Inter var', 'Microsoft JhengHei', 微軟正黑體, 'Microsoft JhengHei UI', 'Microsoft YaHei', 微軟雅黑, 宋体, SimSun, sans-serif\\",
\\"font-family-text-chinese-simplified\\": \\"'Inter var experimental', 'Inter var', 'Microsoft YaHei New', 微软雅黑, 'Microsoft Yahei', 'Microsoft JhengHei', 宋体, SimSun, sans-serif\\",
\\"font-size-110\\": \\"3rem\\",
\\"font-size-100\\": \\"2.5rem\\",
\\"font-size-90\\": \\"2rem\\",
Expand Down Expand Up @@ -562,6 +566,10 @@ exports[`Design Tokens matches the Global theme 1`] = `
\\"shadow-border-inverse-strongest\\": \\"0 0 0 1px #ffffff\\",
\\"font-family-text\\": \\"'Inter var experimental', 'Inter var', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif\\",
\\"font-family-code\\": \\"'Fira Mono', 'Courier New', Courier, monospace\\",
\\"font-family-text-japanese\\": \\"'Inter var experimental', 'Inter var', Hiragino Sans, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', 'メイリオ', Meiryo, Osaka, 'MS PGothic', sans-serif\\",
\\"font-family-text-korean\\": \\"'Inter var experimental', 'Inter var', 'Microsoft JhengHei', 微軟正黑體, 'Microsoft JhengHei UI', 'Microsoft YaHei', 微軟雅黑, 宋体, SimSun, sans-serif\\",
\\"font-family-text-chinese-traditional\\": \\"'Inter var experimental', 'Inter var', 'Microsoft JhengHei', 微軟正黑體, 'Microsoft JhengHei UI', 'Microsoft YaHei', 微軟雅黑, 宋体, SimSun, sans-serif\\",
\\"font-family-text-chinese-simplified\\": \\"'Inter var experimental', 'Inter var', 'Microsoft YaHei New', 微软雅黑, 'Microsoft Yahei', 'Microsoft JhengHei', 宋体, SimSun, sans-serif\\",
\\"font-size-110\\": \\"3rem\\",
\\"font-size-100\\": \\"2.5rem\\",
\\"font-size-90\\": \\"2rem\\",
Expand Down Expand Up @@ -920,6 +928,10 @@ exports[`Design Tokens matches the Sendgrid theme 1`] = `
\\"shadow-border-inverse-strongest\\": \\"0 0 0 1px #ffffff\\",
\\"font-family-text\\": \\"'Colfax', Helvetica, Arial, sans-serif\\",
\\"font-family-code\\": \\"'Fira Mono', 'Courier New', Courier, monospace\\",
\\"font-family-text-japanese\\": \\"'Inter var experimental', 'Inter var', Hiragino Sans, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', 'メイリオ', Meiryo, Osaka, 'MS PGothic', sans-serif\\",
\\"font-family-text-korean\\": \\"'Inter var experimental', 'Inter var', 'Microsoft JhengHei', 微軟正黑體, 'Microsoft JhengHei UI', 'Microsoft YaHei', 微軟雅黑, 宋体, SimSun, sans-serif\\",
\\"font-family-text-chinese-traditional\\": \\"'Inter var experimental', 'Inter var', 'Microsoft JhengHei', 微軟正黑體, 'Microsoft JhengHei UI', 'Microsoft YaHei', 微軟雅黑, 宋体, SimSun, sans-serif\\",
\\"font-family-text-chinese-simplified\\": \\"'Inter var experimental', 'Inter var', 'Microsoft YaHei New', 微软雅黑, 'Microsoft Yahei', 'Microsoft JhengHei', 宋体, SimSun, sans-serif\\",
\\"font-size-110\\": \\"3rem\\",
\\"font-size-100\\": \\"2.5rem\\",
\\"font-size-90\\": \\"2rem\\",
Expand Down
4 changes: 4 additions & 0 deletions packages/paste-design-tokens/tokens/aliases/font-family.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
aliases:
font-family-10: "'Inter var experimental', 'Inter var', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif"
font-family-20: "'Fira Mono', 'Courier New', Courier, monospace"
font-family-30: "'Inter var experimental', 'Inter var', Hiragino Sans, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', 'メイリオ', Meiryo, Osaka, 'MS PGothic', sans-serif"
font-family-40: "'Inter var experimental', 'Inter var', 'Microsoft JhengHei', 微軟正黑體, 'Microsoft JhengHei UI', 'Microsoft YaHei', 微軟雅黑, 宋体, SimSun, sans-serif"
font-family-50: "'Inter var experimental', 'Inter var', 'Microsoft JhengHei', 微軟正黑體, 'Microsoft JhengHei UI', 'Microsoft YaHei', 微軟雅黑, 宋体, SimSun, sans-serif"
font-family-60: "'Inter var experimental', 'Inter var', 'Microsoft YaHei New', 微软雅黑, 'Microsoft Yahei', 'Microsoft JhengHei', 宋体, SimSun, sans-serif"
8 changes: 8 additions & 0 deletions packages/paste-design-tokens/tokens/global/font-family.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ props:
value: "{!font-family-10}"
font-family-code:
value: "{!font-family-20}"
font-family-text-japanese:
value: "{!font-family-30}"
font-family-text-korean:
value: "{!font-family-40}"
font-family-text-chinese-traditional:
value: "{!font-family-50}"
font-family-text-chinese-simplified:
value: "{!font-family-60}"
3 changes: 2 additions & 1 deletion packages/paste-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@twilio-paste/styling-library": "^0.3.7",
"@twilio-paste/types": "^3.1.5",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react-dom": "^17.0.2",
"react-helmet": "^6.1.0"
}
}
21 changes: 21 additions & 0 deletions packages/paste-theme/src/styles/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ import {css} from '@twilio-paste/styling-library';
export const pasteGlobalStyles = css({
html: {
fontSize: '100%',
fontFamily: 'fontFamilyText',
},
'html:lang(ja), html:lang(ja-JP)': {
'.paste-theme-provider': {
fontFamily: 'fontFamilyTextJapanese',
},
},
'html:lang(zh-CN)': {
'.paste-theme-provider': {
fontFamily: 'fontFamilyTextChineseSimplified',
},
},
'html:lang(zh-TW), html:lang(zh-HK)': {
'.paste-theme-provider': {
fontFamily: 'fontFamilyTextChineseTraditional',
},
},
'html:lang(ko)': {
'.paste-theme-provider': {
fontFamily: 'fontFamilyTextKorean',
},
},
body: {
backgroundColor: 'colorBackgroundBody',
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-theme/src/themeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ThemeProvider: React.FunctionComponent<ThemeProviderProps> = ({
<StyledThemeProvider theme={providerThemeProps}>
<StylingGlobals styles={pasteGlobalStyles({theme: providerThemeProps})} />
<StylingGlobals styles={pasteFonts} />
<StyledBase {...props} />
<StyledBase className="paste-theme-provider" {...props} />
</StyledThemeProvider>
);
};
Expand Down
70 changes: 70 additions & 0 deletions packages/paste-theme/stories/themeProvider.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as React from 'react';
import {Helmet} from 'react-helmet';
import {Box} from '@twilio-paste/box';
import {Button} from '@twilio-paste/button';
import {Input} from '@twilio-paste/input';
import {Paragraph} from '@twilio-paste/paragraph';
import {Select, Option} from '@twilio-paste/select';
import {Stack} from '@twilio-paste/stack';
import {TextArea} from '@twilio-paste/textarea';

import {ThemeProvider} from '../src/themeProvider';

// eslint-disable-next-line import/no-default-export
export default {
title: 'Theme/ThemeProvider',
component: ThemeProvider,
};

export const EnglishFontFamily = (): React.ReactNode => (
<Box>
<Paragraph>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Nisi porta lorem mollis aliquam ut porttitor leo. Hendrerit gravida rutrum quisque non. A arcu
cursus vitae congue mauris rhoncus aenean vel elit. Tortor dignissim convallis aenean et tortor at risus.
Vestibulum lorem sed risus ultricies. Tempor nec feugiat nisl pretium fusce id. Morbi tempus iaculis urna id
volutpat lacus laoreet non curabitur. In ante metus dictum at. Sit amet risus nullam eget felis eget nunc
lobortis.
</Paragraph>
<Stack orientation="vertical" spacing="space50">
<Button variant="primary" onClick={() => {}}>
Click me
</Button>
<Input aria-label="Search" placeholder="Search options..." type="text" />
<Select aria-label="Options">
<Option value="option1">Option 1</Option>
</Select>
<TextArea aria-label="Feedback" value="Lorem ipsum dolor sit amet, consectetur adipiscing elit" />
</Stack>
</Box>
);

export const JapaneseFontFamily = (): React.ReactNode => (
<>
<Helmet>
<html lang="ja" />
</Helmet>
<Box>
<Paragraph>
「ヒラギノ角ゴシック体」は、「ヒラギノ明朝体」との混植を意識してデザインした角ゴシック体です。モダンでカウンターが広く明るいだけではなく、少しフトコロを締め気味にして、現代的な明るさを残しつつもオーソドックスなデザインになっています。文字のすき間を均等に配置することと画線両端のアクセントにより、可読性と存在感を両立させた角ゴシック体です。極小サイズの本文から、特大サイズの見出しまで、広い範囲をカバーできます。
</Paragraph>
<Paragraph>
あ い う え お ア イ ウ エ オ 安 以 宇 衣 於 か き く け こ カ キ ク ケ コ 加 幾 久 計 己 さ し す せ そ サ シ
ス セ ソ 左 之 寸 世 曽 た ち つ て と タ チ ツ テ ト 太 知 川 天 止 A B C D a b c d 1 2 3 4 、 。 ! ? 「 」
</Paragraph>
<Stack orientation="vertical" spacing="space50">
<Button variant="primary" onClick={() => {}}>
ダミーテキスト
</Button>
<Input aria-label="ダミーテキスト" placeholder="ダミーテキスト" type="text" />
<Select aria-label="ダミーテキスト">
<Option value="option1">ダミーテキスト</Option>
</Select>
<TextArea
aria-label="ダミーテキスト"
value="「ヒラギノ角ゴシック体」は、「ヒラギノ明朝体」との混植を意識してデザインした角ゴシック体です。モダンでカウンターが広く明るいだけではなく、少しフトコロを締め気味にして、現代的な明るさを残しつつもオーソドックスなデザインになっています。文字のすき間を均等に配置することと画線両端のアクセントにより、可読性と存在感を両立させた角ゴシック体です。極小サイズの本文から、特大サイズの見出しまで、広い範囲をカバーできます。"
/>
</Stack>
</Box>
</>
);
2 changes: 1 addition & 1 deletion packages/paste-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"react-color": "^2.19.3",
"react-dom": "^17.0.2",
"react-github-button": "^0.1.11",
"react-helmet": "^5.2.1",
"react-helmet": "^6.1.0",
"react-live": "^2.2.2",
"react-scrollspy": "^3.4.0",
"react-visibility-sensor": "5.1.1",
Expand Down
Loading

0 comments on commit 8e5dfe1

Please sign in to comment.