Skip to content

Premade components? #379

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
shawnhwei opened this issue Mar 16, 2017 · 11 comments
Closed

Premade components? #379

shawnhwei opened this issue Mar 16, 2017 · 11 comments

Comments

@shawnhwei
Copy link

Does anyone know of any premade component sets or ports of existing frameworks to Svelte (Bootstrap, UIkit, etc.)?

@Rich-Harris
Copy link
Member

I don't think so yet. That would be a great thing to have though. We'd have to have a bit of a think about how to handle things like theming — maybe that would be solved if we had a way of linking to stylesheets from components (as opposed to just having <style> tags — see #65) and had control over the resolution process...

<div class='accordion'>
  <!-- ... -->
</div>

<link rel='stylesheet' href='./themes/__USER_THEME__/accordion.css'>

<!-- or... -->
<div class='accordion'>
  <!-- ... -->
</div>

<style>
  @import ./themes/__USER_THEME__/accordion.css';
</style>

@bestguy
Copy link

bestguy commented Mar 18, 2017

@shawnhwei I've a start of Bootstrap 4 components, but not released yet. If you are still looking in a week or two please remind and I can share what I have, and perhaps collaborate on this.

@bestguy
Copy link

bestguy commented Mar 20, 2017

I've added the project start here: https://github.com/bestguy/sveltestrap, and published to npm as 'sveltestrap'. Happy to collaborate with anyone on this if they have a need for this.

@praneybehl
Copy link

@Rich-Harris Is the @import css option available?

@Rich-Harris
Copy link
Member

@praneybehl no, not yet — but if it was, it could be useful for theming

@DylanPiercey
Copy link

DylanPiercey commented May 16, 2017

@Rich-Harris what are your thoughts on adopting css-modules into svelte? If this were to be implemented you could do so via post-css and allow more control over css preprocessing via postcss config.

@jslegers
Copy link

jslegers commented Aug 3, 2017

@Rich-Harris

We'd have to have a bit of a think about how to handle things like theming

It seems to me that Svelte already supports most features one would need for theming out-of-the-box.

Take the following HTML :

<!doctype html>
<html>
<head>
  <meta charset='utf8'>
  <meta name='viewport' content='width=device-width'>
  <title>Svelte app</title>
  <link rel='stylesheet' href='global.css'>
  <link rel='stylesheet' href='bundle.css'>
  <link rel='stylesheet' href='theme.css'>
</head>
<body class="christmas">
  <script src='bundle.js'></script>
</body>
</html>

Suppose your bundle has one component named App.html :

<div class="app">Hello {{name}}</div>
<div class="lines">
  {{#each lines as line}}
    <Line value={{line}}/>
  {{/each}}
</div>

<script>
  import Line from './Line.html';

  export default {
    components: {
      Line
    }
  };
</script>

And that component imports a component named Line.html :

<div class="line">{{value}}</div>
<style>
  .line {
    background: #222;
    color: #ddd;
  }
</style>
<script>
  export default {}
</script>

Now, suppose global.css has the following CSS :

.line {
  background : #ccc;
  color : #000;
}

And suppose theme.css has the following CSS :

.christmas .line {
  background : #9c9;
  color : #e22;
}

What's gonna happen, here, is that the selector sets the default for your .line selector in your global.css . In a real life project, it could be a CSS framework like Bootstrap that's found there.

Next, the .line selector in your Line.html will overwrite those properties, only for instances of that specific component, because of the the svelte-myuniqueid property. Other components also using the .line selector would not be impacted.

Finally, the .christmas .line selector in your theme.css will overwrite your component-specific CSS. All components using the .line selector would be impacted.

The only thing missing, really, is a way to overwrite only the .line selector of the Line.html component from within your theme. One possible way to implement this, would be to allow developers assign a custom value for myuniqueid of their own choosing that would be used instead of an autogenerated value.

For example, assigning the value line to the id property of my Line.html component would add the property svelte-line instead of something like svelte-2428848546 to the DOM representing that component.

I would then be able to use the .christmas .line[svelte-line] selector to only overwrite the properties of the .line selector for my Line.html component without impacting any of the other components.

This, I believe, is the only necessary addition to allow theming both at a global level and a component level. As a nice bonus, your DOM also would look prettier and more readable when consistently using semantic names as the id value of your components ;-)

See also #570 (comment)!

@arxpoetica
Copy link
Member

Aside from the discussion about css modules and global scoping of css, how is this issue different from #1070?

@c0bra
Copy link
Contributor

c0bra commented Jun 6, 2019

Since a google search brought me here, I thought I'd share:

Svelma is a Bulma component framework for Svelte 3. A work-in-progress but new components are being added fast. It's very similar to Buefy for Vue.

@telemmaite
Copy link

Bootstrap 4 components for Svelte v3 : https://github.com/bestguy/sveltestrap

@YogliB
Copy link

YogliB commented Feb 16, 2020

Check out svelte-community for a bunch if them.

@antony antony closed this as completed Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests