summaryrefslogtreecommitdiffstats
path: root/src/components/molecules/forms/toggle.module.scss
blob: 2e8a49f6d09735704a46e1dba728354f73600fb9 (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
@use "@styles/abstracts/functions" as fun;

.label {
  --toggle-width: #{fun.convert-px(45)};
  --toggle-height: calc(var(--toggle-width) / 2);

  display: inline-flex;
  align-items: center;
  width: 100%;
}

.title {
  margin-right: var(--spacing-2xs);
}

.toggle {
  display: inline-flex;
  align-items: center;
  width: var(--toggle-width);
  height: var(--toggle-height);
  background: var(--color-shadow-light);
  border: fun.convert-px(1) solid var(--color-primary);
  border-radius: fun.convert-px(32);
  box-shadow: inset 0 0 fun.convert-px(3) 0 var(--color-shadow-dark);
  margin: 0 var(--spacing-2xs);
  position: relative;

  &::after {
    content: "";
    display: block;
    width: calc((var(--toggle-width) / 2) - 1px);
    height: calc((var(--toggle-width) / 2) - 1px);
    background: var(--color-primary-light);
    border: fun.convert-px(1) solid var(--color-primary);
    border-radius: 50%;
    box-shadow: inset 0 0 fun.convert-px(1) fun.convert-px(1)
        var(--color-shadow),
      0 0 fun.convert-px(2) fun.convert-px(1) var(--color-shadow-light);
    position: absolute;
    left: fun.convert-px(-2);
    transition: all 0.3s ease-in-out 0s;
  }
}

.checkbox {
  position: absolute;
  opacity: 0;
  cursor: pointer;

  &:checked ~ .label {
    .toggle::after {
      position: absolute;
      left: calc(100% - (var(--toggle-width) / 2) + #{fun.convert-px(2)});
    }
  }

  &:hover,
  &:focus {
    ~ .label {
      .toggle::after {
        background: var(--color-primary-lighter);
      }
    }
  }

  &:focus ~ .label {
    .title {
      text-decoration: underline solid var(--color-primary) fun.convert-px(2);
    }

    .toggle {
      outline: var(--color-border) solid fun.convert-px(5);
    }
  }
}