Skip to content

update font #251

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

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Binary file added public/fonts/Figtree.woff
Binary file not shown.
Binary file added public/fonts/Figtree.woff2
Binary file not shown.
Binary file removed public/fonts/Inter-Bold.woff
Binary file not shown.
Binary file removed public/fonts/Inter-Bold.woff2
Binary file not shown.
Binary file removed public/fonts/Inter-Medium.woff
Binary file not shown.
Binary file removed public/fonts/Inter-Medium.woff2
Binary file not shown.
Binary file removed public/fonts/Inter-Regular.woff
Binary file not shown.
Binary file removed public/fonts/Inter-Regular.woff2
Binary file not shown.
Binary file removed public/fonts/Inter-SemiBold.woff
Binary file not shown.
Binary file removed public/fonts/Inter-SemiBold.woff2
Binary file not shown.
Binary file removed public/fonts/JetBrainsMono-Bold.woff
Binary file not shown.
Binary file removed public/fonts/JetBrainsMono-Bold.woff2
Binary file not shown.
Binary file removed public/fonts/JetBrainsMono-Medium.woff
Binary file not shown.
Binary file removed public/fonts/JetBrainsMono-Medium.woff2
Binary file not shown.
Binary file removed public/fonts/JetBrainsMono-Regular.woff
Binary file not shown.
Binary file removed public/fonts/JetBrainsMono-Regular.woff2
Binary file not shown.
Binary file removed public/fonts/SourceCodePro-Regular.woff
Binary file not shown.
Binary file removed public/fonts/SourceCodePro-Regular.woff2
Binary file not shown.
72 changes: 8 additions & 64 deletions src/components/GlobalStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,76 +19,20 @@ const BODY_STYLES = {
margin: '0',
padding: '0',
color: 'rgba(20, 20, 70, .75)',
'font-size': '14px',
'font-size': '15px',
'line-height': '20px',
'letter-spacing': '0.02em',
'font-weight': '400',
'font-variant': 'initial',
'font-feature-settings': 'initial',
};

const fontsProvider = ({ publicUrl = '' }) => `
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-family: 'Figtree';
font-display: swap;
src: url(${publicUrl}/fonts/Inter-Regular.woff2) format('woff2'),
url(${publicUrl}/fonts/Inter-Regular.woff) format('woff');
}
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(${publicUrl}/fonts/Inter-Medium.woff2) format('woff2'),
url(${publicUrl}/fonts/Inter-Medium.woff) format('woff');
}
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 600;
font-display: swap;
src: url(${publicUrl}/fonts/Inter-SemiBold.woff2) format('woff2'),
url(${publicUrl}/fonts/Inter-SemiBold.woff) format('woff');
}
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 700;
font-display: swap;
src: url(${publicUrl}/fonts/Inter-Bold.woff2) format('woff2'),
url(${publicUrl}/fonts/Inter-Bold.woff) format('woff');
}
@font-face {
font-family: 'Source Code Pro';
src: url('${publicUrl}/fonts/SourceCodePro-Regular.woff2') format('woff2'),
url('${publicUrl}/fonts/SourceCodePro-Regular.woff') format('woff');
font-weight: normal;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'JetBrains Mono';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url(${publicUrl}/fonts/JetBrainsMono-Regular.woff2) format('woff2'),
url(${publicUrl}/fonts/JetBrainsMono-Regular.woff) format('woff');
}

@font-face {
font-family: 'JetBrains Mono';
font-style: normal;
font-weight: 700;
font-display: swap;
src: url(${publicUrl}/fonts/JetBrainsMono-Bold.woff2) format('woff2'),
url(${publicUrl}/fonts/JetBrainsMono-Bold.woff) format('woff');
}

@font-face {
font-family: 'text-security-disc';
src: url(${publicUrl}/fonts/text-security-disc.woff2) format('woff2'),
url(${publicUrl}/fonts/text-security-disc.woff) format('woff');
src: url(${publicUrl}/fonts/Figtree.woff2) format('woff2'),
url(${publicUrl}/fonts/Figtree.woff) format('woff');
}
`;

Expand Down Expand Up @@ -121,7 +65,7 @@ export const GlobalStyles = createGlobalStyle`
html {
--font: ${({ font }: GlobalStylesProps) =>
font ||
'Inter'}, -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
'Figtree'}, -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
--monospace-font: ${({ monospaceFont }) =>
`${
monospaceFont ? `${monospaceFont}, ` : ''
Expand Down Expand Up @@ -201,7 +145,7 @@ export const GlobalStyles = createGlobalStyle`
pre[class*="language-"] {
color: var(--dark-color);
background: none;
font-family: "Source Code Pro", Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
font-weight: normal;
font-size: 14px;
Expand Down
4 changes: 4 additions & 0 deletions src/stories/Typography.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ There are many ways to create typography elements like text labels and headings.
<Block preset="h3">The quick brown fox jumps over the lazy dog - h3</Block>
<Block preset="h4">The quick brown fox jumps over the lazy dog - h4</Block>
<Block preset="h5">The quick brown fox jumps over the lazy dog - h5</Block>
<Block preset="h5s">The quick brown fox jumps over the lazy dog - h5m - Figtree SemiBold 36-44</Block>
<Block preset="h5m">The quick brown fox jumps over the lazy dog - h5m - Figtree Medium 36-44</Block>
<Block preset="h6">The quick brown fox jumps over the lazy dog - h6</Block>
<Block preset="t1">The quick brown fox jumps over the lazy dog - t1</Block>
<Block preset="t2">The quick brown fox jumps over the lazy dog - t2</Block>
<Block preset="t2m">The quick brown fox jumps over the lazy dog - t2m</Block>
<Block preset="t3">The quick brown fox jumps over the lazy dog - t3</Block>
<Block preset="t3m">The quick brown fox jumps over the lazy dog - t3m</Block>
<Block preset="t3s">The quick brown fox jumps over the lazy dog - t3s</Block>
<Block preset="t4">The quick brown fox jumps over the lazy dog - t4</Block>
<Block preset="t4m">The quick brown fox jumps over the lazy dog - t4m</Block>
<Block preset="p1">The quick brown fox jumps over the lazy dog - p1</Block>
<Block preset="p2">The quick brown fox jumps over the lazy dog - p2</Block>
<Block preset="p3">The quick brown fox jumps over the lazy dog - p3</Block>
Expand Down
26 changes: 26 additions & 0 deletions src/tasty/styles/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ function setCSSValue(
}
}

const SETTINGS_DEFAULT_MAP = {
wght: 400,
};
function setVariationSetting(
styles: Styles,
setting: string,
presetName: string,
isPropOnly = false,
) {
styles[
`--font-variation-${setting}`
] = `var(--${presetName}-font-variation-${setting}, var(--default-font-variation-${setting}, ${
SETTINGS_DEFAULT_MAP[setting] || 'initial'
}))`;

if (!isPropOnly) {
styles[
'font-variation-settings'
] = `'${setting}' var(--font-variation-${setting}, 400)`;
}
}

export function presetStyle({
preset,
fontSize,
Expand All @@ -41,6 +63,7 @@ export function presetStyle({
letterSpacing,
fontWeight,
fontStyle,
fontVariationWeight,
font,
}) {
if (!preset) return '';
Expand Down Expand Up @@ -81,6 +104,8 @@ export function presetStyle({
setCSSValue(styles, 'font-family', name);
}

setVariationSetting(styles, 'wght', name);

setCSSValue(styles, 'bold-font-weight', name, true);
setCSSValue(styles, 'icon-size', name, true);

Expand All @@ -94,6 +119,7 @@ presetStyle.__lookupStyles = [
'letterSpacing',
'textTransform',
'fontWeight',
'fontVariationWeight',
'fontStyle',
'font',
];
Loading