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

How do I use plugins to set default list style? #120

Closed
tettoffensive opened this issue Aug 6, 2020 · 6 comments
Closed

How do I use plugins to set default list style? #120

tettoffensive opened this issue Aug 6, 2020 · 6 comments

Comments

@tettoffensive
Copy link

tettoffensive commented Aug 6, 2020

I'm using a third-party component which renders <ul><li>Stuff in here</li></ul> with no classes or id associated. I wanted to set the default list style that tailwind erases in base style to disc.

I tried doing this:

plugins: [({ addUtilities }) => addUtilities({ 'ul > li': { listStyleType: 'disc' } })],

But I must be misunderstanding how to use these methods because this and everything I've tried have not worked.

Am I on the right track or way off? What am I missing? (using 1.7.0)

@ben-rogerson
Copy link
Owner

Try something like this:

module.exports = {
  // theme: {},
  plugins: [discChildren],
}

function discChildren({ addComponents }) {
  addComponents({
    '.my-class': {
      'ul > li': {
        listStyleType: 'disc',
      },
    },
  })
}

You'd add the class (tw="my-class") either on the component or a parent of the component.

@tettoffensive
Copy link
Author

tettoffensive commented Aug 6, 2020

@ben-rogerson This worked, but something funny is happening. I tried to add:

'ol > li': {
  listStyleType: 'decimal',
}

However, it wasn't showing up. Inspecting the CSS in the browser for some reason it's not there. It feels like a caching issue, but with very peculiar behavior because if I change the 'ul' to be decimal it still shows up as disc.

I'm restarting my server and I've also tried clearing the browser cache. But I haven't been able to get the 'ol' rule to show up.

EDIT: If I create a new class, then it works. something is caching the rule somewhere.

this works:

function discChildren({ addComponents }) {
  addComponents({
    '.my-class': {
      'ul > li': {
        listStyleType: 'disc',
      },
    '.my-class-2': {
      'ol > li': {
        listStyleType: 'decimal',
      },
    },
  })
}

does not work:

function discChildren({ addComponents }) {
  addComponents({
    '.my-class': {
      'ul > li': {
        listStyleType: 'disc', // try changing to decimal and it will stay disc
      },
      'ol > li': {
        listStyleType: 'decimal',
      },
    },
  })
}

@ben-rogerson
Copy link
Owner

There's some Gatsby sized caching happening by the sounds, try making a change in the code to force a recompile if that doesn't work, delete your .cache and restart the server. #11

@tettoffensive
Copy link
Author

Turns out to be an import issue. I had never used the syntax tw="my-class" before. Always did css={tw`my-class`} (because I didn't know about the former).

In either case, I must import tw from 'twin.macro'; for the classes to be applied. I didn't notice because there's no complaint of missing import when using tw=

But when using tw= and import tw from 'twin.macro'; TypeScript does complain that 'tw' is declared but its value is never read.ts(6133).

(Hope that wasn't too confusing)

@fvanwijk
Copy link
Contributor

fvanwijk commented Aug 7, 2020

You can do import 'twin.macro'; if you are using tw as prop instead of template function

@ben-rogerson
Copy link
Owner

I recommend having a quick read through the examples in the readme. I'm also working on some guides for the css prop and the styled import.

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

No branches or pull requests

3 participants