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

class="$$props.class" is not working, but would be good to have a function to solve this: #422

Open
moisesbites opened this issue Jan 7, 2022 · 6 comments
Labels
has workaround help wanted Extra attention is needed question Further information is requested
Milestone

Comments

@moisesbites
Copy link

Describe the bug

When using $$props.class in a component, the windicss classes is not working inside the component:

Fo example, in the page:

<SomeComponent class="text-blue-700" />

In the SomeComponent:

<span class="{$$props.class}">some text</span>

The text would be blue-700 but is not working.
But if I put inside the component the same windicss class I'm passing into in another snippet of page , the classes work correctly in both texts. For example:

In the SomeComponent:

<span class="{$$props.class}">some text</span>
<span class="text-blue-700">another text</span>

System Info

System:
    OS: Linux 5.13 Linux Mint 20.2 (Uma)
    CPU: (4) x64 Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
    Memory: 9.42 GB / 23.37 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.11.0 - ~/.nvm/versions/node/v16.11.0/bin/node
    npm: 8.3.0 - ~/.nvm/versions/node/v16.11.0/bin/npm
  IDEs:
    Nano: 4.8 - /usr/bin/nano
    VSCode: 1.63.2 - /usr/bin/code
  Browsers:
    Chrome: 97.0.4692.71
    Chromium: 96.0.4664.110
    Firefox: 95.0.1

Used Package Manager

npm

@moisesbites moisesbites added bug Something isn't working pending triage labels Jan 7, 2022
@moisesbites
Copy link
Author

I solved using this:

<script>
  import Processor from 'windicss';
  const processor = new Processor();
  function windi(strings, ...values) {
    const str = strings.reduce((query, queryPart, i) => {
      const valueExists = i < values.length;
      const text = query + queryPart;

      return valueExists ? text + values[i] : text;
    }, '');

    const result = processor.interpret(str);
    return result.styleSheet.children
      .map((child) => {
        return child.property.map((p) => `${p.name}: ${p.value}${p.important ? '!important' : ''};`).join('');
      })
      .join('');
  }
</script>

<span style="{windi`${$$props.class}`}">some text</span>

@moisesbites moisesbites changed the title class="$$props.class" is not working class="$$props.class" is not working, but would be good to have a function to solve this: Jan 7, 2022
@alexanderniebuhr alexanderniebuhr added question Further information is requested help wanted Extra attention is needed has workaround and removed bug Something isn't working pending triage labels Jan 7, 2022
@alexanderniebuhr
Copy link
Member

That is actually the expected behavior.

I can see if i can improve that in an future update, but no promise!

@moisesbites
Copy link
Author

@alexanderniebuhr Thank you very much.

For while, I'm using that function to solve this Issue, but if there was a more elegant way to solve this automatically, it would be much appreciated.

@jacob-8
Copy link

jacob-8 commented Apr 4, 2022

@moisesbites I wrote a preprocessor to overcome this challenge: https://www.npmjs.com/package/svelte-deep-wind-preprocess

@moisesbites
Copy link
Author

@moisesbites I wrote a preprocessor to overcome this challenge: https://www.npmjs.com/package/svelte-deep-wind-preprocess

Thank you. I will try. Please, it would be interesting to correct the github project reference in the https://www.npmjs.com/package/svelte-deep-wind-preprocess.

@jacob-8
Copy link

jacob-8 commented Apr 7, 2022

@moisesbites I wrote a preprocessor to overcome this challenge: https://www.npmjs.com/package/svelte-deep-wind-preprocess

Thank you. I will try. Please, it would be interesting to correct the github project reference in the https://www.npmjs.com/package/svelte-deep-wind-preprocess.

Sorry about that. I had to do some refactoring first - the code now lives at https://github.com/jacob-8/svelte-deep-wind-preprocess

@alexanderniebuhr alexanderniebuhr added this to the next milestone Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants