GithubHelp home page GithubHelp logo

ahutchings / custom-panel-zwave-graph Goto Github PK

View Code? Open in Web Editor NEW

This project forked from home-assistant/custom-panel-starter-kit-react

0.0 0.0 0.0 1.07 MB

A starter kit to start developing a React based custom panel

License: Apache License 2.0

JavaScript 93.63% CSS 6.37%

custom-panel-zwave-graph's Introduction

React-based custom panel starter kit for Home Assistant

This project will help you get started with building a custom panel for Home Assistant using the React framework.

๐Ÿšจ DEPRECATED

This repository is deprecated, unmaintained and archived.

Getting started

This guide expects NodeJS 8 or later and Yarn to be installed.

First, we're going to get a copy of this repo and install the dependencies:

npx degit home-assistant/custom-panel-starter-kit-react
cd custom-panel-starter-kit-react
yarn

For testing purporses, let's start a testing server:

yarn start

Keep the server running. Now add the following entry to your configuration.yaml file:

panel_custom:
    # This is the name of the web component that will be defined by the panel
  - name: react-panel
    sidebar_title: React Demo
    sidebar_icon: mdi:react
    # This is the url that will load the panel
    url_path: react-panel-demo
    # Location where the panel is hosted during development
    js_url: http://localhost:8080/main.js
    # We want to load in an iframe to work around limitations in React
    embed_iframe: true
    # This will be available as prop `panel.config`.
    config:
      name: World

Restart Home Assistant.

Sharing your work

To build a new version of your panel, run:

yarn build

This will generate a new build of the panel in the dist folder. Copy the content of this folder and place it in <home assistant config>/www/my-panel.

This will make it available from Home Assistant via the url /local/my-panel/main.js.

We then have to configure Home Assitant to use it:

panel_custom:
  - name: react-panel
    sidebar_title: React Prod
    sidebar_icon: mdi:react
    url_path: react-panel-prod
    js_url: /local/my-panel/main.js
    embed_iframe: true
    config:
      name: World

Sharing your work - advanced

Once your panel grows more complex and you need to load extra files (either CSS or JS), you will need to know in advance where your panel will be hosted. You can configure where it will be hosted by adjusting the panelServingUrl value in package.json.

You can use this url inside your code by using the variable __PUBLIC_PATH__.

ES5 support

If you need to support older browsers, you will have to enable transpilation to ES5 (out of scope for this tutorial). However, once you've done this, defining the web component to hook into Home Assistant will require a little bit of extra work. Open index.js and replace the call to customElements.define with the following:

window.loadES5Adapter().then(() =>
    customElements.define('react-panel', ReactPanelElement(Panel)));

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.