question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Responsive typography

See original GitHub issue

I have created a functionality in my theme file to make the typography styles responsive:

Feature description

const mediaSizes = {
  smallPhone: 320,
  bigPhone: 480,
  tablet: 600,
  bigTablet: 801,
  tabletLaptop: 1025,
  desktop: 1281
}

const makeFontSizeResponsive = fontSize => {
  const fontNumber = fontSize.slice(0, -2)
  const result = {
    [mediaQueries['smallPhone']]: { fontSize: `${fontNumber * 0.7}px` },
    [mediaQueries['bigPhone']]: { fontSize: `${fontNumber * 0.75}px` },
    [mediaQueries['tablet']]: { fontSize: `${fontNumber * 0.8}px` },
    [mediaQueries['bigTablet']]: { fontSize: `${fontNumber * 0.85}px` },
    [mediaQueries['tabletLaptop']]: { fontSize: `${fontNumber * 0.9}px` },
    [mediaQueries['desktop']]: { fontSize: `${fontNumber}px` }
  }
  return result
}
const newTheme = createTheme({
  ...,
  'typography': {
    'font100': {
      'fontFamily': 'Helvetica, Arial, sans-serif',
      'fontSize': '11px',
      'fontWeight': 'normal',
      'lineHeight': '1.45em',
      ...makeFontSizeResponsive('11px')
    },
  ...
}

However these do not work with the baseui typography classes because the fonts prop is filtered by individual keys, and I believe that the styles are also not deep merged. I could create my own custom typography components and probably will due to time, but I think it would be good to allow this. If there is a better way please advise?

See: https://github.com/uber-web/baseui/blob/master/src/block/styled-components.js#L86

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sandgrahamcommented, Sep 22, 2020

@asherccohen Ah okay, they are exported in Flow, but not Typescript. Opened #3779.

1reaction
sandgrahamcommented, Sep 18, 2020

Hey guys, how would you type custom media queries?I’ve added some to my theme overrides but I get type errors saying my properties don’t exist.

This section of the theming guide focuses on extending the default theme with new properties: https://baseweb.design/guides/theming/#customizing-the-theme-type

Read more comments on GitHub >

github_iconTop Results From Across the Web

A guide to responsive typography - UX Collective
Responsive web design is a methodology to create websites that scales and adapts depending up the size of the screen and capabilities of...
Read more >
Modern Fluid Typography Using CSS Clamp
Usually, when we implement responsive typography, values change on specific breakpoints. They are explicitly defined.
Read more >
Simple solutions to responsive typography - YouTube
In this one, I look at two simple ways to make maintaining your site's typography much simpler!
Read more >
Typography - web.dev
Good typography on the web isn't just about the type choices that you make as a designer. Responsive typography is also about respecting...
Read more >
How To Create a Responsive Text - W3Schools
Responsive Font Size. The text size can be set with a vw unit, which means the "viewport width". That way the text size...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found