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

Scoped styling? #45

Open
Gildedter opened this issue Jun 27, 2022 · 2 comments
Open

Scoped styling? #45

Gildedter opened this issue Jun 27, 2022 · 2 comments

Comments

@Gildedter
Copy link

Gildedter commented Jun 27, 2022

I have multiple instances on my route, a main one, and a wrapped version, the wrapped version has a different look, but the styles of the main version is being overwritten by the wrapped version, I'm using this for targeting:

/// main version
<style lang="postcss">
  :global([data-svelte-search] label) {
    @apply hidden;
  }
  :global([data-svelte-search] input) {
    @apply rounded-none rounded-r-lg bg-none;
  }
  :global([data-svelte-search] form) {
    @apply rounded-none rounded-r-lg;
  }
  :global([data-svelte-typeahead]) {
    @apply bg-none rounded-none rounded-r-lg;
  }
  select {
    @apply rounded-none rounded-l-lg w-fit pr-8;
  }
</style>

/// scoped version
<style lang="postcss">
  :global([data-svelte-search] label) {
    @apply hidden;
  }
  :global([data-svelte-search] input) {
    @apply bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500;
  }
  :global([data-svelte-search] form) {
    @apply rounded-lg;
  }
  :global([data-svelte-typeahead]) {
    @apply bg-none rounded;
  }
</style>
@metonym
Copy link
Owner

metonym commented Jun 27, 2022

$$restProps is spread to the Search component, so you can pass a unique attribute to only style the targeted element:

<Typeahead data-search-id="1" />

<style>
  :global([data-search-id="1"]) {
    /* ... */
  }
</style>

@Gildedter
Copy link
Author

Didn't work for me, I just stuck with one style...

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

2 participants