Skip to content

Is there a way to access the final font-size values for use elsewhere in CSS? #10

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

Closed
drdogbot7 opened this issue May 27, 2022 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@drdogbot7
Copy link

For instance with the core fontSize plugin, I can do this:

:root {
 --foo: theme('fontSize.lg');
}

...but since the fluid type plugin calculates the final values at build time, that doesn't work.

I realize I could use @apply in a lot of cases, but it would be useful to have direct access to the values.

@davidhellmann
Copy link
Owner

I think that's not really possible and may be a downside.
But I'm not 100% sure what's your use case. Within your CSS I think there is no really needed to specify the TailwindCSS stuff again as CSS Vars. When you need the stuff within JS I think you must calculate it on your own but it’s simple.

But maybe you can tell me more about the use case and it's a bit more clear for me.

@drdogbot7
Copy link
Author

The specific use case here is some Wordpress BS. The block editor does some weird stuff with inline styles and variables.

I agree; I can't think of a lot of use cases for this except when need to override something in a code base you don't control.

@davidhellmann
Copy link
Owner

I'll close that issue. If you have any questions let me know.

@davidhellmann davidhellmann closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2022
@davidhellmann
Copy link
Owner

@drdogbot7 good news :)
I looked into this topic yesterday and pushed a v2 branch.
It works but you have to set it up a bit differently. But it's just a copy/paste thing.
Maybe I found a bit extra time this evening then I will update the readme and a live example.

@davidhellmann davidhellmann reopened this Aug 17, 2022
@davidhellmann davidhellmann self-assigned this Aug 17, 2022
@davidhellmann davidhellmann added the enhancement New feature or request label Aug 17, 2022
@davidhellmann
Copy link
Owner

You can try it out: npm i tailwindcss-fluid-type@next

And under plugins in your tailwind.config.js:

 plugins: [
    require('tailwindcss-fluid-type')({
      settings: {
        fontSizeMin: 1.125, // 1.125rem === 18px
        fontSizeMax: 1.25, // 1.25rem === 20px
        ratioMin: 1.125, // Multiplicator Min
        ratioMax: 1.2, // Multiplicator Max
        screenMin: 20, // 20rem === 320px
        screenMax: 96, // 96rem === 1536px
        unit: 'rem', // default is rem but it's also possible to use 'px'
        prefix: '', // set a prefix to use it alongside the default font sizes
      },
      values: {
        xs: [-2, 1.6],
        sm: [-1, 1.6],
        base: [0, 1.6],
        lg: [1, 1.6],
        xl: [2, 1.2],
        '2xl': [3, 1.2],
        '3xl': [4, 1.2],
        '4xl': [5, 1.1],
        '5xl': [6, 1.1],
        '6xl': [7, 1.1],
        '7xl': [8, 1],
        '8xl': [9, 1],
        '9xl': [10, 1],
      },
    }),
  ],

@davidhellmann
Copy link
Owner

@drdogbot7
Copy link
Author

This looks great, thank you!

@davidhellmann
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants