123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- :root {
- --switch-checked-background-color: var(--switch-highlight-color); /* background color active */
- --switch-thumb-background-color: white;
- --switch-thumb-border-color: var(--border-color);
- --switch-thumb-border-color-active: var(--switch-highlight-color);
- --switch-height: 32px;
- --switch-width: 51px;
-
- --switch: {
- display: inline-block;
- vertical-align: top;
- @apply(--reset-box-model);
- @apply(--hide-input-parent);
- min-width: 51px;
- }
-
- --switch__toggle: {
- position: relative;
- display: inline-block;
- vertical-align: top;
- @apply(--reset-box-model);
- @apply(--reset-base);
- @apply(--reset-cursor);
- }
- }
-
- /*~
- name: Switch
- category: Switch
- elements: ons-switch
- markup: |
- <label class="switch">
- <input type="checkbox" class="switch__input">
- <div class="switch__toggle">
- <div class="switch__handle"></div>
- </div>
- </label>
- <label class="switch">
- <input type="checkbox" class="switch__input" checked>
- <div class="switch__toggle">
- <div class="switch__handle"></div>
- </div>
- </label>
- <label class="switch">
- <input type="checkbox" class="switch__input" disabled>
- <div class="switch__toggle">
- <div class="switch__handle"></div>
- </div>
- </label>
- */
-
- .switch {
- @apply(--switch);
- font-size: var(--font-size);
- padding: 0 20px;
- border: none;
- overflow: visible;
- width: var(--switch-width);
- height: var(--switch-height);
- z-index: 0;
- text-align: left;
- }
-
- .switch__input {
- @apply(--hide-input);
- z-index: 0;
- }
-
- /* switch toggle background */
- .switch__toggle {
- background-color: var(--switch-background-color);
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- border-radius: 30px;
- transition-property: all;
- transition-duration: 0.35s;
- transition-timing-function: ease-out;
- box-shadow: inset 0 0 0 2px var(--switch-border-color);
- }
-
- /* switch toggle circle */
- .switch__handle {
- @apply(--reset-box-model);
- position: absolute;
- content: '';
- border-radius: 28px;
- height: 28px;
- width: 28px;
- background-color: var(--switch-thumb-background-color);
- left: 1px;
- top: 2px;
- transition-property: all;
- transition-duration: 0.35s;
- transition-timing-function: cubic-bezier(.59, .01, .5, .99);
- box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.25), 0 3px 2px rgba(0, 0, 0, 0.25);
- }
-
- .switch--active__handle {
- transition: none;
- }
-
- :checked + .switch__toggle {
- box-shadow: inset 0 0 0 2px var(--switch-checked-background-color);
- background-color: var(--switch-checked-background-color);
- }
-
- :checked + .switch__toggle > .switch__handle {
- left: 21px;
- box-shadow: 0 3px 2px rgba(0, 0, 0, 0.25);
- }
-
- :disabled + .switch__toggle {
- @apply(--disabled);
- }
-
- .switch__touch {
- position: absolute;
- top: -5px;
- bottom: -5px;
- left: -10px;
- right: -10px;
- }
-
- /*~
- name: Material Switch
- category: Switch
- elements: ons-switch
- markup: |
- <label class="switch switch--material">
- <input type="checkbox" class="switch__input switch--material__input">
- <div class="switch__toggle switch--material__toggle">
- <div class="switch__handle switch--material__handle">
- </div>
- </div>
- </label>
- <label class="switch switch--material">
- <input type="checkbox" class="switch__input switch--material__input" checked>
- <div class="switch__toggle switch--material__toggle">
- <div class="switch__handle switch--material__handle">
- </div>
- </div>
- </label>
- <label class="switch switch--material">
- <input type="checkbox" class="switch__input switch--material__input" disabled>
- <div class="switch__toggle switch--material__toggle">
- <div class="switch__handle switch--material__handle">
- </div>
- </div>
- </label>
- */
-
- .switch--material {
- width: 36px;
- height: 24px;
- padding: 0 10px;
- min-width: 36px;
- }
-
- .switch--material__toggle {
- background-color: var(--material-switch-inactive-background-color);
- margin-top: 5px;
- height: 14px;
- box-shadow: none;
- }
-
- .switch--material__input {
- @apply(--hide-input);
- z-index: 0;
- }
-
- .switch--material__handle {
- background-color: var(--material-switch-inactive-thumb-color);
- left: 0;
- margin-top: -5px;
- width: 20px;
- height: 20px;
- @apply(--material-shadow-2);
- }
-
- :checked + .switch--material__toggle {
- background-color: var(--material-switch-active-background-color);
- box-shadow: none;
- }
-
- :checked + .switch--material__toggle > .switch--material__handle {
- left: 16px;
- background-color: var(--material-switch-active-thumb-color);
- @apply(--material-shadow-1);
- }
-
- :disabled + .switch--material__toggle {
- @apply(--disabled);
- }
-
- .switch--material__handle:before {
- background: transparent;
- content: '';
- display: block;
- width: 100%;
- height: 100%;
- border-radius: 50%;
- z-index: 0;
- box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.12);
- transition: box-shadow 0.1s linear;
- }
-
- .switch--material__toggle > .switch--active__handle:before {
- box-shadow: 0 0 0 14px rgba(0, 0, 0, 0.12);
- }
-
- :checked + .switch--material__toggle > .switch--active__handle:before {
- box-shadow: 0 0 0 14px color(var(--material-switch-active-thumb-color) alpha(20%));
- }
-
- .switch--material__touch {
- position: absolute;
- top: -10px;
- bottom: -10px;
- left: -15px;
- right: -15px;
- }
|