summaryrefslogtreecommitdiff
path: root/chromium/ui/webui/resources/cr_elements/cr_checkbox/cr_checkbox.html
blob: 66cbbbbef78429d3b03880fcf699fe5f57ad7f78 (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
    <style>
      :host {
        -webkit-tap-highlight-color: transparent;
        align-items: center;
        cursor: pointer;
        display: flex;
        outline: none;
        user-select: none;

        /* Sizes. */
        --cr-checkbox-border-size: 2px;
        --cr-checkbox-size: 16px;
        --cr-checkbox-ripple-size: 40px;

        /* Derived sizes (offsets). */
        --cr-checkbox-ripple-offset: calc(var(--cr-checkbox-size)/2 -
            var(--cr-checkbox-ripple-size)/2 - var(--cr-checkbox-border-size));

        /* --cr-checked-color automatically flips for light/dark mode. */
        --cr-checkbox-checked-box-color: var(--cr-checked-color);
        --cr-checkbox-ripple-checked-color: var(--cr-checked-color);

        /* Light mode colors. */
        --cr-checkbox-checked-ripple-opacity: .2;
        --cr-checkbox-mark-color: white;
        --cr-checkbox-ripple-unchecked-color: var(--google-grey-900);
        --cr-checkbox-unchecked-box-color: var(--google-grey-700);
        --cr-checkbox-unchecked-ripple-opacity: .15;
      }

      @media (prefers-color-scheme: dark) {
        :host {
          /* Dark mode colors. */
          --cr-checkbox-checked-ripple-opacity: .4;
          --cr-checkbox-mark-color: var(--google-grey-900);
          --cr-checkbox-ripple-unchecked-color: var(--google-grey-500);
          --cr-checkbox-unchecked-box-color: var(--google-grey-500);
          --cr-checkbox-unchecked-ripple-opacity: .4;
        }
      }

      :host([disabled]) {
        cursor: initial;
        opacity: var(--cr-disabled-opacity);
        pointer-events: none;
      }

      #checkbox {
        background: none;
        border: var(--cr-checkbox-border-size) solid
            var(--cr-checkbox-unchecked-box-color);
        border-radius: 2px;
        box-sizing: border-box;
        cursor: pointer;
        display: block;
        flex-shrink: 0;
        height: var(--cr-checkbox-size);
        margin: 0;
        outline: none;
        padding: 0;
        position: relative;
        transform: none;  /* Checkboxes shouldn't flip even in RTL. */
        width: var(--cr-checkbox-size);
      }

      @media (forced-colors: active) {
        /* paper-ripple is not showing in Windows HCM. Use outline instead. */
        :host(:focus) #checkbox {
          outline: var(--cr-focus-outline-hcm);
        }
      }

      #checkmark {
        border-color: var(--cr-checkbox-mark-color);
        border-style: solid;
        border-width: 0 2px 2px 0;
        content: '';
        display: block;
        height: 73%;
        transform: scale(0) rotate(45deg);
        transform-origin: 100% 80%;
        width: 36%;
      }

      :host-context([dir='rtl']) #checkmark {
        transform-origin: 50% 14%;
      }

      :host([checked]) #checkbox {
        background: var(--cr-checkbox-checked-box-background-color,
            var(--cr-checkbox-checked-box-color));
        border-color: var(--cr-checkbox-checked-box-color);
      }

      :host([checked]) #checkmark {
        transform: scale(1) rotate(45deg);
        /* Only animate when showing checkmark. */
        transition: transform 140ms ease-out;
      }

      paper-ripple {
        --paper-ripple-opacity: var(--cr-checkbox-ripple-opacity,
            var(--cr-checkbox-unchecked-ripple-opacity));
        color: var(--cr-checkbox-ripple-unchecked-color);
        height: var(--cr-checkbox-ripple-size);
        left: var(--cr-checkbox-ripple-offset);
        outline: var(--cr-checkbox-ripple-ring, none);
        pointer-events: none;
        top: var(--cr-checkbox-ripple-offset);
        transition: color linear 80ms;
        width: var(--cr-checkbox-ripple-size);
      }

      :host([checked]) paper-ripple {
        --paper-ripple-opacity: var(--cr-checkbox-ripple-opacity,
            var(--cr-checkbox-checked-ripple-opacity));
        color: var(--cr-checkbox-ripple-checked-color);
      }

      :host-context([dir=rtl]) paper-ripple {
        left: auto;
        right: var(--cr-checkbox-ripple-offset);
      }

      #label-container {
        color: var(--cr-checkbox-label-color, var(--cr-primary-text-color));
        padding-inline-start: var(--cr-checkbox-label-padding-start, 20px);
        white-space: normal;
      }

      :host(.no-label) #label-container {
        display: none;
      }

      /* Hidden from UI, but not screen readers. */
      #ariaDescription {
        height: 0;
        overflow: hidden;
        width: 0;
      }
    </style>
    <div id="checkbox" tabindex$="[[tabIndex]]" role="checkbox"
        on-keydown="onKeyDown_" on-keyup="onKeyUp_" aria-disabled="false"
        aria-checked="false" aria-labelledby="label-container"
        aria-describedby="ariaDescription">
      <span id="checkmark"></span>
    </div>
    <div id="label-container" aria-hidden="true" part="label-container">
      <slot></slot>
    </div>
    <div id="ariaDescription" aria-hidden="true">[[ariaDescription]]</div>