summaryrefslogtreecommitdiff
path: root/app/assets/stylesheets/framework/toggle.scss
blob: f635de63d5e244a99be5b9d1336cf5e930a2c79c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Toggle button
*
* @usage
*  ### Active and Inactive text should be provided as data attributes:
*  <button type="button" class="project-feature-toggle" data-enabled-text="Enabled" data-disabled-text="Disabled">
*  <i class="fa fa-spinner fa-spin loading-icon hidden"></i>
*  </button>

*  ### Checked should have `is-checked` class
*  <button type="button" class="project-feature-toggle is-checked" data-enabled-text="Enabled" data-disabled-text="Disabled">
*  <i class="fa fa-spinner fa-spin loading-icon hidden"></i>
*  </button>

*  ### Disabled should have `is-disabled` class
*  <button type="button" class="project-feature-toggle is-disabled" data-enabled-text="Enabled" data-disabled-text="Disabled" disabled="true">
*  <i class="fa fa-spinner fa-spin loading-icon hidden"></i>
*  </button>

*  ### Loading should have `is-loading` and an icon with `loading-icon` class
*  <button type="button" class="project-feature-toggle is-loading" data-enabled-text="Enabled" data-disabled-text="Disabled">
*  <i class="fa fa-spinner fa-spin loading-icon"></i>
*  </button>
*/
.project-feature-toggle {
  position: relative;
  border: 0;
  outline: 0;
  display: block;
  width: 50px;
  height: 24px;
  cursor: pointer;
  user-select: none;
  background: $gl-gray-400;
  border-radius: 12px;
  padding: 3px;
  transition: all 0.4s ease;

  &::selection,
  &::before::selection,
  &::after::selection {
    background: none;
  }

  &:focus {
    outline: none;
  }

  .toggle-icon {
    position: relative;
    display: block;
    left: 0;
    border-radius: 9px;
    background: $feature-toggle-color;
    transition: all 0.2s ease;

    &,
    .toggle-icon-svg {
      width: $default-icon-size;
      height: $default-icon-size;
    }

    .toggle-icon-svg {
      fill: $gl-gray-400;
    }

    .toggle-status-checked {
      display: none;
    }

    .toggle-status-unchecked {
      display: inline;
    }
  }

  .loading-icon {
    display: none;
    font-size: 12px;
    color: $white-light;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  &.is-loading {
    .toggle-icon {
      display: none;
    }

    .loading-icon {
      display: block;

      &::before {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
    }
  }

  &.is-checked {
    background: $feature-toggle-color-enabled;

    .toggle-icon {
      left: calc(100% - 18px);

      .toggle-icon-svg {
        fill: $feature-toggle-color-enabled;
      }

      .toggle-status-checked {
        display: inline;
      }

      .toggle-status-unchecked {
        display: none;
      }
    }
  }

  &.is-disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  @include media-breakpoint-down(xs) {
    width: 50px;

    &::before,
    &.is-checked::before {
      display: none;
    }
  }

  @keyframes animate-enabled {
    0%,
    35% {
      opacity: 0;
    }
    100% {
      opacity: 1;
    }
  }

  @keyframes animate-disabled {
    0%,
    35% {
      opacity: 0;
    }
    100% {
      opacity: 1;
    }
  }
}