Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apac, seekBusiness: Use strong weight instead of medium for Thai characters #1331

Merged
merged 7 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changeset/afraid-birds-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'braid-design-system': patch
---

---
updated:
- apac
- seekBusiness
---

michaeltaranto marked this conversation as resolved.
Show resolved Hide resolved
**apac, seekBusiness:** Use `strong` weight instead of `medium` for Thai characters

The unicode range of Thai characters is not satisfied by the preferred fonts specified for the `apac` theme, resulting in these characters falling through and being rendered by `sans-serif` — which applies a platform specific font.
michaeltaranto marked this conversation as resolved.
Show resolved Hide resolved
On Mac this is `Thonburi`, on Windows it is `Tahoma`, neither of which have support for the semi-bold weight chosen for `medium`.
The result is the visual weight of `medium` text being rounded down to `regular`, and hence having no differentiation against standard text in the UI.

To work around this, we are creating a font alias that coerces the semi-bold weight to the bold weight of the previously mentioned platform specific Thai fonts.
michaeltaranto marked this conversation as resolved.
Show resolved Hide resolved

This is only applied for themes that inherit the `apac` typography definition (currently `apac` and `seekBusiness`), and will only affect characters that fall through — unsatisfied by the preferred fonts in the specified `font-family`.
michaeltaranto marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions fixtures/consumer/__snapshots__/build.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ exports[`build side-effects from dist 1`] = `
"dist/styles/lib/css/atoms/atoms.mjs",
"dist/styles/lib/themes/apac/tokens.cjs",
"dist/styles/lib/themes/apac/tokens.mjs",
"dist/styles/lib/themes/baseTokens/mediumWeightPatch.cjs",
"dist/styles/lib/themes/baseTokens/mediumWeightPatch.mjs",
"dist/styles/lib/themes/docs/tokens.cjs",
"dist/styles/lib/themes/docs/tokens.mjs",
"dist/styles/lib/themes/makeBraidTheme.cjs",
Expand Down Expand Up @@ -78,6 +80,7 @@ exports[`build side-effects from src 1`] = `
"src/lib/themes/apac/index.ts",
"src/lib/themes/apac/tokens.ts",
"src/lib/themes/baseTokens/apac.ts",
"src/lib/themes/baseTokens/mediumWeightPatch.ts",
"src/lib/themes/docs/index.ts",
"src/lib/themes/docs/tokens.ts",
"src/lib/themes/index.ts",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"jest": "^29.0.0",
"jest-environment-jsdom": "^29.0.0",
"jest-watch-typeahead": "^2.1.0",
"js-yaml": "^4.1.0",
"nx": "^15.6.3",
"prettier": "^2.8.2",
"renovate-config-seek": "0.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { darken, lighten, rgba, saturate } from 'polished';
import merge from 'lodash/merge';
import { palette } from '../../color/palette';
import { type BraidTokens, extractFontMetricsForTheme } from '../tokenType';
import { semiBoldWeight, thaiPatchFamilyName } from './mediumWeightPatch';

import './mediumWeightPatch.css';

interface MakeTokensOptions {
name: string;
Expand Down Expand Up @@ -55,13 +58,12 @@ export const makeTokens = ({
displayName,
legacy: true,
typography: {
fontFamily:
'Roboto, "Helvetica Neue", HelveticaNeue, Helvetica, Arial, sans-serif',
fontFamily: `Roboto, "Helvetica Neue", HelveticaNeue, Helvetica, Arial, ${thaiPatchFamilyName}, sans-serif`,
webFont: null,
fontMetrics: extractFontMetricsForTheme(robotoMetrics),
fontWeight: {
regular: 400,
medium: 500,
medium: semiBoldWeight,
strong: 700,
},
heading: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { globalFontFace } from '@vanilla-extract/css';
import { semiBoldWeight, thaiPatchFamilyName } from './mediumWeightPatch';

/*
This patch is designed to co-erce the semi-bold font weight
michaeltaranto marked this conversation as resolved.
Show resolved Hide resolved
to bold for fonts that do not handle weights between regular
and bold.

This is relevant for Thai character ranges, which are not
available in the `apac` font stack, so we map the semi-bold
weight to the bold sans-serif system font — Thonburi on Mac,
Tahoma on Windows.
*/

globalFontFace(thaiPatchFamilyName, {
fontWeight: semiBoldWeight,
src: "local('Thonburi Bold'), local('Tahoma Bold')",
unicodeRange: 'U+0E01-0E5B, U+200C-200D, U+25CC',
});

globalFontFace(thaiPatchFamilyName, {
src: "local('Thonburi'), local('Tahoma')",
unicodeRange: 'U+0E01-0E5B, U+200C-200D, U+25CC',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const thaiPatchFamilyName = 'ThaiSemiBoldPatch';
export const semiBoldWeight = 500;
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.