single-switch-widget.component.scss 4.37 KB
/**
 * Copyright © 2016-2024 The Thingsboard Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
$tumblerColorOn: var(--tb-single-switch-tumbler-color-on, #fff);
$tumblerColorOff: var(--tb-single-switch-tumbler-color-off, #fff);
$tumblerColorDisabled: var(--tb-single-switch-tumbler-color-disabled, #fff);

$switchColorOn: var(--tb-single-switch-color-on, #5469FF);
$switchColorOff: var(--tb-single-switch-color-off, rgba(84, 105, 255, 0.30));
$switchColorDisabled: var(--tb-single-switch-color-disabled, #D5D7E5);

.tb-single-switch-panel {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 24px;
  &.auto-scale {
    padding: 0;
  }
  > div:not(.tb-single-switch-overlay), > tb-icon {
    z-index: 1;
  }
  .tb-single-switch-overlay {
    position: absolute;
    inset: 12px;
  }
  > div.tb-single-switch-title-panel {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    z-index: 2;
  }
  .tb-single-switch-content {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    &.right {
      flex-direction: row;
      justify-content: space-between;
    }
    &.no-label.right {
      justify-content: flex-end;
    }
    &.left {
      flex-direction: row-reverse;
      justify-content: flex-end;
    }
    &.centered {
      flex-direction: row;
      justify-content: center;
    }
    .tb-single-switch-label-row {
      display: flex;
      flex-direction: row;
      align-items: center;
      gap: 8px;
      .tb-single-switch-label {
        white-space: nowrap;
      }
    }
    &:not(.auto-scale) {
      .tb-single-switch-label-row {
        overflow: hidden;
        .tb-single-switch-label {
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
    .tb-single-switch-slide-toggle-row {
      display: flex;
      flex-direction: row;
      align-items: center;
      gap: 8px;
    }
    .mat-mdc-slide-toggle {
      &.tb-single-switch-toggle {
        .mdc-switch {
          width: 42px;
          height: 22px;
          .mdc-switch__track {
            height: 22px;
            border-radius: 11px;
            &::after, &::before {
              border: none;
            }
          }
          .mdc-switch__handle-track {
            width: calc(100% - 22px);
            left: 2px;
          }
          .mdc-switch__handle {
            border-radius: 9px;
            width: 18px;
            height: 18px;
          }
          .mdc-switch__ripple {
            width: 36px;
            height: 36px;
          }
          .mdc-switch__icons {
            display: none;
          }
          &:disabled {
            .mdc-switch__track {
              opacity: 1;
              &::after, &::before {
                background: $switchColorDisabled;
              }
            }
            .mdc-switch__handle::after {
              opacity: 1;
              background: $tumblerColorDisabled;
            }
          }
          &:enabled, &:enabled:hover {
            .mdc-switch__track {
              &::after {
                background: $switchColorOn;
              }
              &::before {
                background: $switchColorOff;
              }
            }
            &.mdc-switch--selected {
              .mdc-switch__handle::after {
                background: $tumblerColorOn;
              }
              .mdc-switch__ripple::after {
                background-color: $switchColorOn;
              }
            }
            &.mdc-switch--unselected {
              .mdc-switch__handle::after {
                background: $tumblerColorOff;
              }
              .mdc-switch__ripple::after {
                background-color: $switchColorOff;
              }
            }
          }
        }
        .mdc-form-field > label {
          display: none;
        }
      }
    }
  }
}