Skip to content

Commit 7b6df80

Browse files
authored
feat(mistica-css): switch (#1364)
WEB-2190
1 parent 29eddbb commit 7b6df80

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

css/mistica-common.css

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
--vcolor-controlActivated: var(--mistica-color-controlActivatedInverse);
4444
--vcolor-checkbox-tick: var(--mistica-color-controlKnobInverse);
4545
--vcolor-checkbox-background: transparent;
46+
47+
--vcolor-switch-trackBackground: transparent;
48+
--vcolor-switch-handleChecked: var(--mistica-color-controlKnobInverse);
49+
--vcolor-switch-handleHover: var(--mistica-color-inverse);
4650
}
4751

4852
[data-mistica-skin] > *,
@@ -92,6 +96,10 @@
9296
--vcolor-controlActivated: var(--mistica-color-controlActivated);
9397
--vcolor-checkbox-tick: var(--mistica-color-inverse);
9498
--vcolor-checkbox-background: var(--mistica-color-background);
99+
100+
--vcolor-switch-trackBackground: var(--mistica-color-backgroundAlternative);
101+
--vcolor-switch-handleChecked: var(--mistica-color-inverse);
102+
--vcolor-switch-handleHover: var(--mistica-color-neutralHigh);
95103
}
96104

97105
@media (prefers-color-scheme: dark) {
@@ -931,6 +939,10 @@ button.mistica-display-card:has(.mistica-card__media):active:after {
931939
transition: background-color 0.1s ease-in-out;
932940
}
933941

942+
.mistica-accordion-item__summary::-webkit-details-marker {
943+
display: none;
944+
}
945+
934946
.mistica-accordion-item__summary-body {
935947
display: flex;
936948
flex-direction: column;
@@ -1200,6 +1212,88 @@ button.mistica-display-card:has(.mistica-card__media):active:after {
12001212
}
12011213
}
12021214

1215+
/* Switch */
1216+
.mistica-switch {
1217+
--switch-border-width: 2px;
1218+
--switch-transition: 300ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
1219+
appearance: none;
1220+
position: relative;
1221+
width: 52px;
1222+
height: 32px;
1223+
border-radius: 16px;
1224+
background-color: var(--vcolor-switch-trackBackground);
1225+
border: var(--switch-border-width) solid var(--vcolor-control);
1226+
padding: 0;
1227+
margin: 0;
1228+
box-sizing: border-box;
1229+
cursor: pointer;
1230+
transition:
1231+
background-color var(--switch-transition),
1232+
border-color var(--switch-transition);
1233+
}
1234+
1235+
/* :after is the switch handle (bolita) */
1236+
.mistica-switch:after {
1237+
content: '';
1238+
position: absolute;
1239+
top: calc(8px - var(--switch-border-width));
1240+
left: calc(8px - var(--switch-border-width));
1241+
width: 16px;
1242+
height: 16px;
1243+
border-radius: 50%;
1244+
background-color: var(--vcolor-control);
1245+
transition:
1246+
transform var(--switch-transition),
1247+
background-color var(--switch-transition);
1248+
}
1249+
1250+
.mistica-switch:hover:after {
1251+
background-color: var(--vcolor-switch-handleHover);
1252+
}
1253+
1254+
.mistica-switch:checked {
1255+
background-color: var(--vcolor-controlActivated);
1256+
border-color: var(--vcolor-controlActivated);
1257+
}
1258+
.mistica-switch:checked:after {
1259+
background-color: var(--vcolor-switch-handleChecked);
1260+
transform: translateX(20px) scale(1.5);
1261+
}
1262+
1263+
.mistica-switch:active:after {
1264+
transform: scale(1.75);
1265+
}
1266+
.mistica-switch:checked:active:after {
1267+
transform: translateX(20px) scale(1.75);
1268+
}
1269+
1270+
/* :before is the ripple effect overlay on hover */
1271+
.mistica-switch:before {
1272+
content: '';
1273+
position: absolute;
1274+
top: calc(-8px + var(--switch-border-width));
1275+
left: calc(-8px + var(--switch-border-width));
1276+
width: 40px;
1277+
height: 40px;
1278+
border-radius: 50%;
1279+
background-color: transparent;
1280+
transition:
1281+
transform var(--switch-transition),
1282+
background-color var(--switch-transition);
1283+
}
1284+
1285+
.mistica-switch:checked:before {
1286+
transform: translateX(20px);
1287+
}
1288+
1289+
.mistica-switch:hover:before {
1290+
background-color: var(--mistica-color-backgroundContainerHover);
1291+
}
1292+
1293+
.mistica-switch:active:before {
1294+
background-color: var(--mistica-color-backgroundContainerPressed);
1295+
}
1296+
12031297
/* Checkbox */
12041298
.mistica-checkbox {
12051299
appearance: none;

examples/css/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ <h3 class="mistica-text-title2">Tag</h3>
8989
<div class="mistica-tag-error">Error</div>
9090
</div>
9191

92+
<h3 class="mistica-text-title2">Switch</h3>
93+
<input type="checkbox" class="mistica-switch" />
9294
<h3 class="mistica-text-title2">Checkbox</h3>
9395
<h4 class="mistica-text-title1">Without label</h4>
9496
<input type="checkbox" class="mistica-checkbox" />

0 commit comments

Comments
 (0)