Advertisement
314ma

sidebar-minimal-changes

Jan 20th, 2023 (edited)
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {css, html, LitElement} from "https://unpkg.com/lit-element@2.0.1/lit-element.js?module";
  2.  
  3. class LeftSideBarCard extends LitElement {
  4.  
  5.     static get properties() {
  6.         return {
  7.             hass: {},
  8.             config: {},
  9.             _showoption: {}
  10.         };
  11.     }
  12.  
  13.     constructor() {
  14.         super();
  15.         this._showoption = false
  16.     }
  17.  
  18.     render() {
  19.         const url = window.location.href.split("/").pop()
  20.  
  21.         return html`
  22.             <div class="main">
  23.                 <aside style="width: ${this._showoption == true ? '50px' : '90px'}" ;>
  24.                     <div class="empty"></div>
  25.                     ${this.config.entities.map(ent => {
  26.  
  27.                         return html`
  28.                             <a href="${ent.url}" class="${ent.url === url ? 'active' : 'deactive'}">
  29.                                 <i aria-hidden="true">
  30.                                     <ha-icon icon="${ent.icon}"/>
  31.                                 </i>
  32.                             </a>
  33.                         `;
  34.  
  35.                     })}
  36.                     ${this.config.option_menu ? html`
  37.                         <a style="border-right: 1px solid #dad7d7;">
  38.                             <i @click=${() => {
  39.                                 this._showoption = !this._showoption
  40.                             }}>
  41.                                 <ha-icon icon="mdi:cog-outline"/>
  42.                             </i>
  43.                         </a>
  44.                     ` : html``}
  45.                     <div class="empty"></div>
  46.                 </aside>
  47.                 <div class="sub_menu" style="display: ${this._showoption == true ? 'flex' : 'none'}">
  48.                     ${this.config.option_menu.map(sub => {
  49.                         return html`
  50.                             <a class="button_option_menu ${sub.url === url ? 'button_option_menu_active' : ' '}"
  51.                                href="${sub.url}">
  52.                                 <ha-icon class="icon" icon="${sub.icon}"/>
  53.                                 </ha-icon>
  54.                             </a
  55.                         `;
  56.                     })}
  57.                 </div>
  58.             </div>
  59.  
  60.         `;
  61.     }
  62.  
  63.     connectedCallback() {
  64.         const url = window.location.href.split("/").pop()
  65.         this._showoption = this.config.option_menu.map(v => v["url"]).includes(url);
  66.  
  67.         super.connectedCallback()
  68.     }
  69.  
  70.     disconnectedCallback() {
  71.         super.disconnectedCallback()
  72.     }
  73.  
  74.     setConfig(config) {
  75.         if (!config.entities) {
  76.             throw new Error("You need to define entities");
  77.         }
  78.  
  79.         this.config = config;
  80.     }
  81.  
  82.     getCardSize() {
  83.         return this.config.entities.length + 1;
  84.     }
  85.  
  86.     static get styles() {
  87.         return css`
  88.  
  89.     :host {
  90.       --layout-margin: 4px 4px 0px 4px;
  91.  
  92.     }
  93.  
  94.     .main {
  95.       // width: 80px;
  96.       height: 99.6vh;
  97.       display: flex;
  98.       flex-direction:rows;
  99.       justify-content: center;
  100.       text-align: center;
  101.       vertical-align: middle;
  102.       // margin: 2vh 0 2vh 10px;
  103.  
  104.     }
  105.  
  106.     .empty {
  107.       background-color: transparent;
  108.       height: 100%;
  109.       border-right: 1px solid #dad7d7;
  110.     }
  111.    
  112.     aside {
  113.       color: #fff;
  114.      
  115.       height: 100%;
  116.       background-image: linear-gradient(270deg, #f6f5fa, transparent);
  117.       // background-image: linear-gradient(30deg, #0048bd, #44a7fd);
  118.       // background-color: var(--deactive-background-button-color);
  119.       // border-radius: 15px;
  120.       display: flex;
  121.       flex-direction: column;
  122.       justify-content: center;
  123.       text-align: center;
  124.       vertical-align: middle;
  125.     }
  126.    
  127.     aside a {
  128.       // color: #fff;
  129.       color: var(--sidebar-icon-color);
  130.       display: block;
  131.       padding: 20px 0px 20px 5px;
  132.       margin-left: 10px;
  133.       text-decoration: none;
  134.       -webkit-tap-highlight-color: transparent;
  135.       // border-right: 1px solid rgba(128, 128, 128, 0.2);
  136.     }
  137.     .deactive {
  138.       border-right: 1px solid #dad7d7;
  139.     }
  140.     .active {
  141.       color: #3f5efb;
  142.       background: #fff;
  143.       outline: none;
  144.       position: relative;
  145.       background-color: #fff;
  146.       border-top-left-radius: 15px;
  147.       border-bottom-left-radius: 15px;
  148.       border-left: 1px solid #dad7d7;
  149.       border-top: 1px solid #dad7d7;
  150.       border-bottom: 1px solid #dad7d7;
  151.       border-right-color: #dad7d7;
  152.       border-right-width: 1px;
  153.       // box-shadow: 0 -4px 3px -4px, 0 4px 3px -4px, -4px 0px 3px -4px;
  154.     }
  155.    
  156.     aside a i {
  157.       margin-right: 15px;
  158.     }
  159.    
  160.     .active:after{
  161.       content: "";
  162.       position: absolute;
  163.       background-color: transparent;
  164.       bottom: 100%;
  165.       right: 0px;
  166.       height: 100%;
  167.       width: 25px;
  168.       border-bottom-right-radius: 15px;
  169.       border-right-color: #dad7d7;
  170.       border-bottom: 1px solid #dad7d7;
  171.       box-shadow: rgb(255 255 255) 0px 15px 0px 0px;
  172.     }
  173.    
  174.     .active:before {
  175.       content: "";
  176.       position: absolute;
  177.       background-color: transparent;
  178.       top: 64px;
  179.       right: 0px;
  180.       height: 100%;
  181.       width: 25px;
  182.       border-top-right-radius: 15px;
  183.       border-right: 1px solid #dad7d7;
  184.       border-top: 1px solid #dad7d7;
  185.       box-shadow: 0 -15px 0 0 #fff;
  186.     }
  187.    
  188.     aside p {
  189.       margin: 0;
  190.       padding: 40px 0;
  191.     }
  192.    
  193.     body {
  194.       font-family: "Roboto";
  195.       width: 100%;
  196.       height: 100vh;
  197.       margin: 0;
  198.     }
  199.    
  200.     i:before {
  201.       width: 14px;
  202.       height: 14px;
  203.       font-size: 14px;
  204.       position: fixed;
  205.       color: #fff;
  206.       background: #0077b5;
  207.       padding: 10px;
  208.       border-radius: 50%;
  209.       top: 5px;
  210.       right: 5px;
  211.     }
  212.     .sub_menu {
  213.      
  214.       flex-direction: column;
  215.       justify-content: center;
  216.       text-align: center;
  217.       vertical-align: middle;
  218.       cursor: pointer;
  219.       width: 45px;
  220.  
  221.     }
  222.     .button_option_menu {
  223.       padding: 15px;
  224.       border-right: 2px solid var(--sidebar-border-color);
  225.       background-color: transparent;
  226.     }
  227.     .button_option_menu_active {
  228.       border-right: 4px solid var(--state-icon-active-color);
  229.     }
  230.  
  231.     .icon {
  232.       color: var(--sidebar-icon-color)
  233.     }
  234.    
  235.     `;
  236.     }
  237.  
  238. }
  239.  
  240. customElements.define('leftside-card', LeftSideBarCard);
  241.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement