Git Product home page Git Product logo

bootstrap-grid-card's Introduction

hacs_badge Stable Community Forum

bootstrap-grid-card

Are you looking for a way to get control over your lovelace layout on all your platforms with a small configuration footprint? Or maybe just a fan of booststrap grid system? Then this card is for you.

I wanted a very specific layout on my wall-mounted tablet to fit everything I needed without having to scroll too much. When I had made that, the same layout became unusable on my phone and very unoptimal on my big PC screen. I did not want to maintain multiple views that basically provided the same things but with a different layouts and I could not find any existing solution that was simple and enough customizable.

This card loads bootstrap-grid.css into lovelace and provides an easy way of configuring cards with different bootstrap grid classes in yaml. With bootstrap you can configure cards to take up different size depending on screen size:

Installation

HACS (recommended)

This card is available in HACS (Home Assistant Community Store). HACS is a third party community store and is not included in Home Assistant out of the box.

This card should pop up if you search for "bootstrap-grid-card" in HACS.

Manual install

  1. Download and copy bootstrap-grid-card.js from latest release into your config/www directory.

  2. Add card to resources:

    resources:
      - type: module
        url: /local/bootstrap-grid-card.js

Alternatively follow instructions further down under "Development".

Usage

First of all, if you don't know how to use booststrap grid system, I strongly suggest you to read about it before continuing. This guide will assume the reader has basic knowledge of bootstrap grids.

Simple example configuration:

title: My view
panel: true  # !!!!!
cards:
  - type: "custom:bootstrap-grid-card"
    cards:
       - type: row
         cards:
            - type: button
              class: "col-3"
              <...>
            - type: button
              class: "col-9"
              <...>
       - type: row
         class: "justify-content-md-center"
         cards:
            - type: entity
              class: "col-6"
              <...>

Note: panel: false is not tested and probably not what you want.

Options

# [Required, type: string]
type: custom:bootstrap-grid-card

# List of cards.
#
# [required, type: list]
cards:

# Class of the div that surrounds the grid.
#
# [optional, type: string, default: 'container-fluid']
class: "container-fluid"

# Use paddings and margins on rows and columns that looks like Lovelace default
# style. If set to *False*, you'll get whatever bootstrap uses as default.
#
# [optional, type: bool, default: True]
use_hass_style_gutter: True

# Custom space between cards. Only used if 'use_hass_style_gutter' is enabled.
#
# [optional, type: string, default: "4px"]
hass_style_gutter_size: "4px"

# Custom padding of the container (panel).
#
# [optional, type: string, default: Whatever bootstrap sets]
container_padding:

# String that will be appended to all rows class attribute.
#
# [optional, type: string, default: ""]
global_row_class: ""

# String that will be appended to all columns class attribute.
#
# [optional, type: string, default: ""]
global_col_class: ""

Rows and columns

The bootstrap-grid-card provides two custom card types: row and col to be used in the cards list of bootstrap-grid-card, row and col card.

The type: row and type: col card will wrap their cards list in a div with the row and col class respectively.

A normal card (e.g. type: button) in the cards list of row or col, will always get the class col*. So there is no need of adding a type: col around a single card.

Row options

# [required, type: string]
type: row

# Class attribute of this column. Will always have the 'row' class which can't
# be overridden.
#
# Example: "justify-content-center"
#
# [optional, type: string]
class:

# List of cards.
#
# [required, type: list]
cards:

Column options

# [required, type: string]
type: col

# Class attribute of this column.
#
# Example: "col-xs-12 col-sm-5 col-md-4 col-lg-3"
#
# [optional, type: string]
class:

# List of cards.
#
# [required, type: list]
cards:

Nesting rows and columns

It is possible to nest rows and columns any number of times as long there are no non-bootstrap-grid-card´s in between. For example, it will not work if you put a row card in a horizontal-stack card.

More advanced example:

  # ...
  - type: row
    class: justify-content-md-center
    cards:
      - type: button
        class: "col-12 col-sm-12 col-md-6 col-lg-5"
        # ...
      - type: button
        class: "col-12 col-sm-12 col-md-3 col-lg-3"
        # ...
      - type: col # Nesting start
        class: "col-12 col-sm-12 col-md-3 col-lg-3"
        cards:
          - type: row
            cards:
              - type: thermostat
                # Use default class "col".
                # ...
              - type: markdown
                # Use default class "col".
                # ...

Development

# First time to install all deps
npm install

# Build card
npm run build

# Copy to home assistance www folder
cp dist/bootstrap-grid-card.js <home_assistant>/config/www/bootstrap-grid-card.js

# In lovelace UI: clear cache, reload resources and reload page

bootstrap-grid-card's People

Contributors

mjedal avatar ownbee avatar

Watchers

 avatar

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.