Git Product home page Git Product logo

Comments (19)

snrbrnjna avatar snrbrnjna commented on May 24, 2024 12

@KyleAMathews @TylerBarnes any updates on this?

from typography.js.

davidprae avatar davidprae commented on May 24, 2024 10

Wanting to use Typography.js in a production website but I need breakpoints. Are breakpoints a feature that we can expect soon?

from typography.js.

mlukaszczyk avatar mlukaszczyk commented on May 24, 2024 9

Hey there! Any news on the breakpoints?

Cheers,

Michael

from typography.js.

TylerBarnes avatar TylerBarnes commented on May 24, 2024 5

@Siyfion I'm guessing he's been busy with Gatsby V2. Responsive generated typography would be an awesome addition to Gatsby V2 though ;)

from typography.js.

fjcalzado avatar fjcalzado commented on May 24, 2024 3

+1 for breakpoints. It is really helpful in responsive design. Otherwise, this could be a serious stopper in real production.

from typography.js.

hdoro avatar hdoro commented on May 24, 2024 2

In search of using typography.js for production, I've found a silly and not-so-useful-but-better-than-nothing hack to declare media queries:

overrideStyles: ({ adjustFontSizeTo, rhythm }, options, styles) => ({
        'h1, h2, h3, h4, h5': {
            color: '#0f092b'
        },
        '@media screen and (min-width: 760px){h1{font-size:200px}}': {},
    })

However, this doesn't allow me to use variables such as rhythm and I'm still not able to change the scaleRatio between breakpoints... @KyleAMathews I'd gladly try to implement breakpoints to Typography.js, but I'm a bit lost with the repo and I'm still a bit raw with JS, any directions you could give us?

from typography.js.

Siyfion avatar Siyfion commented on May 24, 2024 2

@KyleAMathews Is there any update on this?

from typography.js.

johncmunson avatar johncmunson commented on May 24, 2024 2

Hey guys, it appears that @hcavalieri's clever hack is no longer necessary and that Typography.js now at least partially supports media queries inside of the overrideStyles property. Checkout where @KyleAMathews has used this feature in one of the Gatsby demonstration sites. I have tested it out myself and it's working just fine.

from typography.js.

TylerBarnes avatar TylerBarnes commented on May 24, 2024 2

@johncmunson while that method is super useful, it's not the same as having actual breakpoint support. Breakpoints inside override styles wont allow you to set up different ratios across media queries. I have a PR open (#157) that adds this functionality to typography.js but I think Kyle is too busy with Gatsby to merge it (understandably). I'm thinking soon I'll publish a wrapper library around typographyjs because I want this functionality but I also want to work out an easy way to integrate typographyjs with styled components / styled systems

from typography.js.

TylerBarnes avatar TylerBarnes commented on May 24, 2024 2

@johncmunson the solution in the PR is different than the hack posted above.

I've published a temporary package for myself and anyone else that wants breakpoints until they're officially supported.

You can install it with npm i tyjs or yarn add tyjs. It should be exactly the same as typographyjs except for the added breakpoints option. You should import Typography from 'tyjs' and it probably doesn't play nice with the typography gatsby plugin so probably you'll need to use typography.toString() and add the string to your site somewhere.

from typography.js.

PMudra avatar PMudra commented on May 24, 2024 2

I was able to solve this missing option with a workaround by overriding the font-size of the html tag.
Typography config: baseFontSize: "16px" this will result in font-size: 100%.
Then I added this in a global css:

@media (min-width: 480px) {
  html {
    font-size: 112.5%; /* --> 18px base size */
  }
}
@media (min-width: 600px) {
  html {
    font-size: 125%; /* --> 20px base size */
  }
}

from typography.js.

chaance avatar chaance commented on May 24, 2024 2

Another workaround here is to update the typography object when your key breakpoints change (assuming you're using React here, but this is probably adaptable to other frameworks). May also need some adjustments for SSR.

function useTypography() {
  // I have a hook that updates when one of my theme breakpoints change
  // modify based on whatever solution you use here
  let breakpoint = useBreakpoint();
  let typography = React.useMemo(() => {
    let baseFontSize = breakpoint === 'small' ? defaultOpts.baseFontSize : '22px';
    let scaleRatio = breakpoint === 'small' ? defaultOpts.scaleRatio : 2;
    return new Typography({
      ...defaultOpts,
      baseFontSize,
      scaleRatio,
    });
  }, [breakpoint]);

  // layout effect prevents a flash if your first load doesn't match your default styles
  useLayoutEffect(() => {
    typography.injectStyles();
  }, [typography]);
  return typography;
}

// I can now stick this in my theme provider to get dynamic scale and rhythm
// values elsewhere in the app
const ThemeProvider = ({ children }) => {
  let { value: isDark } = useDarkMode(false);
  let typography = useTypography();

  return (
    <ThemeContext.Provider
      value={{
        theme: isDark ? darkTheme : lightTheme,
        typography,
      }}
    >
      {children}
    </ThemeContext.Provider>
  );
};

from typography.js.

richardvanbergen avatar richardvanbergen commented on May 24, 2024 1

@TylerBarnes Thank you so much, it works beautifully. I hope that @KyleAMathews sees it as something that should be in the main repo because otherwise, you're stuck trying to find a middle ground between smaller and larger devices.

from typography.js.

KyleAMathews avatar KyleAMathews commented on May 24, 2024

CSS Locks are cool. We should support them by default.

from typography.js.

ooloth avatar ooloth commented on May 24, 2024

Overriding the default scaleRatio at various breakpoints would be very helpful!

from typography.js.

TylerBarnes avatar TylerBarnes commented on May 24, 2024

Heres a hacky solution for this using the object structure you've suggested.
I create a new instance of typography js for every breakpoint, combine the css strings and wrap some of them in breakpoints based on the breakpoint object.
I then use purgeCss to remove duplicate lines.

https://gist.github.com/tyler-barnes/efa5970d3ae56e4d2af4664fe8f90e7a#file-typographyjs-gulp-breakpoints-js

from typography.js.

muhajirdev avatar muhajirdev commented on May 24, 2024

any updates on this?

from typography.js.

TylerBarnes avatar TylerBarnes commented on May 24, 2024

I forked this and added breakpoint support if anyone wants to test it out. As far as I can tell it's working great with toJSON and toString. #157 https://github.com/tyler-barnes/typography.js/tree/breakpoints

from typography.js.

johncmunson avatar johncmunson commented on May 24, 2024

@TylerBarnes while maybe a little hacky, I love the solution you came up with. I think a wrapper library is a great idea, as it will allow Kyle to revisit this at a later date and decide if this is the correct approach or there is a better path

from typography.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.