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

about dynamic attributify mode #1915

Closed
pawover opened this issue Nov 25, 2022 · 9 comments · Fixed by #1921
Closed

about dynamic attributify mode #1915

pawover opened this issue Nov 25, 2022 · 9 comments · Fixed by #1921

Comments

@pawover
Copy link

pawover commented Nov 25, 2022

Hello guys,

I have a class need to use attributify mode,

pos="!fixed" it's working

pos={isSideFixed ? '!fixed' : 'relative'} it's not working

How do I get the corresponding css generated in advance? using the safelist ?

@zyyv
Copy link
Member

zyyv commented Nov 25, 2022

I don't think it's a problem, UnoCSS will extract fixed and relative.
Playground

Of course you can use safelist, you don't have to worry about this problem.

@antfu
Copy link
Member

antfu commented Nov 25, 2022

We temporarily close this due to the lack of enough information.
Please provide a minimal reproduction to reopen the issue.
Thanks.

Why reproduction is required

@antfu antfu closed this as completed Nov 25, 2022
@pawover
Copy link
Author

pawover commented Nov 25, 2022

image

fixed and relative has extracted but not working like other attributify

minimal reproduction

@pawover
Copy link
Author

pawover commented Nov 25, 2022

It doesn't seem to be antd5 problem either

@pawover
Copy link
Author

pawover commented Nov 25, 2022

@zyyv

@zyyv
Copy link
Member

zyyv commented Nov 25, 2022

This does not affect anything, because unocss is a static analysis, and extracts the token to generate css.

@pawover
Copy link
Author

pawover commented Nov 25, 2022

I don't understand how this could be invalid, it's working in windicss..

@sibbng
Copy link
Member

sibbng commented Nov 26, 2022

@Handpear I made a PR to fix this issue: #1921

In the meantime, you could use this roughly written extractor:

Test it in playground

export default defineConfig({
  extractors: [{
  name: 'ternary-extractor',
  extract(ctx) {
    let s = ctx.code
    const results = []
    const re = /<[\w.]+[^>]*?:?(?:([\w-]+)=[{'"](.+?(?:.)*?\?+(?:.)*?(?:['"]([^'"]+)['"]?(?:.)*?:(?:.)*?['"]([^'"]+)['"]?))[}'"](?:.)*?)+/gms
    let match
    while (match = re.exec(s)) {
      s = s.replace(match[2], '')
      re.lastIndex = 0
      const attr = match[1]
      if(attr === 'class' || attr === 'className') continue
      const left = match[3]
      left.split(' ').forEach(i => results.push(`[${attr}~="${i}"]`))
      const right = match[4]
      right.split(' ').forEach(i => results.push(`[${attr}~="${i}"]`))
      console.log(results)
    }
    return results
  },
}],

@pawover
Copy link
Author

pawover commented Nov 28, 2022

@sibbng Thank you

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

Successfully merging a pull request may close this issue.

4 participants