Git Product home page Git Product logo

granite-lit-bootstrap's Introduction

Published on webcomponents.org

granite-lit-bootstrap

granite-bootstrap is a wrapping of Bootstrap CSS CSS as LitElement lit-html CSS TemplateResult to be used in LitElement web components.

Using granite-lit-bootstrap

To use granite-lit-bootstrap in an element:

1. Install granite-lit-bootstrap

Install the component using npm:

$ npm i @granite-elements/granite-lit-bootstrap --save

2. Import granite-lit-bootstrap in the element where you want to use it

Once installed, import it in your application. Usually you will simply want to import granite-lit-bootstrap.js (wrap around bootstrap.css) or granite-lit-bootstrap-min.js (wrap around bootstrap.min.css).

Supossing you want to import granite-lit-bootstrap.js:

import {bootstrapStyles} from '@granite-elements/granite-lit-bootstrap/granite-lit-bootstrap.js';

3. Inside your component, use granite-lit-bootstrap in the static styles property

class GraniteSpectreExample extends LitElement {
  static get styles() {
    return [bootstrapStyles];
  }
  render() {
    return html`
      <div class="label label-rounded label-primary">Styled text</div>
    `;
  }

A complete example

import { html, LitElement } from 'lit-element';
import {bootstrapStyles} from '../granite-lit-bootstrap.js';

class GraniteSpectreExample extends LitElement {
  static get styles() {
    return [bootstrapStyles];
  }
  render() {
    return html`
      <table class="table  table-hover">
          <tr><th>Surname</th><th>Name</th></tr>
          ${this.people.map( (person) => {
            return html`
            <tr>
              <td>${person.lastname}</td>
              <td>${person.firstname}</td>
            </tr>
            `;
          })}
      </table>
    `;
  }

  static get properties() {
    return {
      people: { type: Array },
    };
  }

  constructor() {
    super();
    this.people = [
      { firstname: 'Jack', lastname: 'Aubrey' },
      { firstname: 'Anne', lastname: 'Elliot' },
      { firstname: 'Stephen', lastname: 'Maturin' },
      { firstname: 'Emma', lastname: 'Woodhouse' },
    ];
  }
}
customElements.define('granite-bootstrap-example', GraniteSpectreExample);

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Install dependencies and run the demo

  • Run npm install from the repo directory:

     npm install
    
  • Run the es-dev-server development server from the root project directory:

    npm run serve
    

Note on semver versioning

I'm aligning the versions of this element with Bootstrap version, in order to make easier to choose the right version

License

Apache 2.0

granite-lit-bootstrap's People

Contributors

lostinbrittany avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

granite-lit-bootstrap's Issues

how we can override the style

example, i have tried this, but not work, bootstrap CSS took over my css

import {LitElement, html, css} from 'lit';
import {bootstrapStyles} from '@granite-elements/granite-lit-bootstrap/granite-lit-bootstrap.js';

export class BtnKanel extends LitElement {
  static get styles() {
    return [bootstrapStyles,css];
  }
  static styles = css`
    .mybtn {
      font-size:80px;
    }
  `;
  render() {
    return html`
      <div class="label label-rounded label-primary">Styled text</div>
      <button class="btn btn-primary">BTN</button>
      <button class="mybtn">BTN</button>
    `;
  }
}

customElements.define('btn-kanel', BtnKanel);

Question: unsafeCSS vs granite-lit-bootstrap

Hello!
Great package.
Let me ask you, does this way of using Bootstrap provide advantages vs simply using unsafeCSS?

import bootstrapcss from "bootstrap/dist/css/bootstrap.min.css"
import {html, css, LitElement, TemplateResult, unsafeCSS} from "lit"
class BootBase extends LitElement {
  static styles = [unsafeCSS(bootstrapcss)]
}
...

Thank you so much

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.