-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './switch'; |
146 changes: 146 additions & 0 deletions
146
packages/common/web/src/lib/elements/switch/switch.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
.devpr-switch { | ||
z-index: 0; | ||
position: relative; | ||
display: inline-block; | ||
color: rgba($devpr-primary-500, 0.87); | ||
font-size: 16px; | ||
line-height: 1.5; | ||
} | ||
|
||
/* Track */ | ||
.devpr-switch > input { | ||
appearance: none; | ||
-moz-appearance: none; | ||
-webkit-appearance: none; | ||
z-index: 1; | ||
position: relative; | ||
float: right; | ||
display: inline-block; | ||
margin: 0 0 0 5px; | ||
border: solid 5px transparent; | ||
border-radius: 12px; | ||
width: 46px; | ||
height: 24px; | ||
background-clip: padding-box; | ||
background-color: $devpr-primary-500; | ||
outline: none; | ||
cursor: pointer; | ||
transition: background-color 0.2s, opacity 0.2s; | ||
} | ||
|
||
/* Span */ | ||
.devpr-switch > input + span { | ||
display: inline-block; | ||
box-sizing: border-box; | ||
margin-right: -51px; | ||
padding-right: 51px; | ||
width: inherit; | ||
cursor: pointer; | ||
} | ||
|
||
/* Highlight */ | ||
.devpr-switch > input + span::before { | ||
content: ""; | ||
position: absolute; | ||
right: 11px; | ||
top: -8px; | ||
display: block; | ||
border-radius: 50%; | ||
width: 40px; | ||
height: 40px; | ||
background-color: $devpr-on-primary-focused; | ||
opacity: 0; | ||
transform: scale(1); | ||
pointer-events: none; | ||
transition: opacity 0.3s 0.1s, transform 0.2s 0.1s; | ||
} | ||
|
||
/* Thumb */ | ||
.devpr-switch > input + span::after { | ||
content: ""; | ||
z-index: 1; | ||
position: absolute; | ||
top: 2px; | ||
right: 21px; | ||
border-radius: 50%; | ||
width: 20px; | ||
height: 20px; | ||
background-color: $devpr-surface; | ||
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12); | ||
pointer-events: none; | ||
transition: background-color 0.2s, transform 0.2s; | ||
} | ||
|
||
/* Checked */ | ||
.devpr-switch > input:checked { | ||
background-color: rgba($devpr-primary-500, 0.6); | ||
} | ||
|
||
.devpr-switch > input:checked + span::before { | ||
right: -5px; | ||
background-color: $devpr-primary-500; | ||
} | ||
|
||
.devpr-switch > input:checked + span::after { | ||
background-color: $devpr-primary-500; | ||
transform: translateX(16px); | ||
} | ||
|
||
/* Hover, Focus */ | ||
.devpr-switch:hover > input + span::before { | ||
opacity: 0.04; | ||
} | ||
|
||
.devpr-switch > input:focus + span::before { | ||
opacity: 0.12; | ||
} | ||
|
||
.devpr-switch:hover > input:focus + span::before { | ||
opacity: 0.16; | ||
} | ||
|
||
/* Active */ | ||
.devpr-switch:active > input { | ||
background-color: rgba($devpr-primary-500, 0.6); | ||
} | ||
|
||
.devpr-switch:active > input:checked { | ||
background-color: $devpr-primary-500; | ||
} | ||
|
||
.devpr-switch:active > input + span::before { | ||
opacity: 1; | ||
transform: scale(0); | ||
transition: transform 0s, opacity 0s; | ||
} | ||
|
||
/* Disabled */ | ||
.devpr-switch > input:disabled { | ||
background-color: $devpr-primary-500; | ||
opacity: 0.38; | ||
cursor: default; | ||
} | ||
|
||
.devpr-switch > input:checked:disabled { | ||
background-color: rgba($devpr-primary-500, 0.6); | ||
} | ||
|
||
.devpr-switch > input:disabled + span { | ||
color: $devpr-on-primary-disabled; | ||
cursor: default; | ||
} | ||
|
||
.devpr-switch > input:disabled + span::before { | ||
z-index: 1; | ||
margin: 10px; | ||
width: 20px; | ||
height: 20px; | ||
background-color: $devpr-on-primary-disabled; | ||
transform: scale(1); | ||
opacity: 1; | ||
transition: none; | ||
} | ||
|
||
.devpr-switch > input:disabled + span::after { | ||
opacity: 0.38; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { BuiltInElement } from '../../decorators' | ||
|
||
@BuiltInElement('devpr-switch', 'label') | ||
export class SwitchElement extends HTMLLabelElement { | ||
connectedCallback() { | ||
this.classList.add('devpr-switch') | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'devpr-switch': SwitchElement | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@import 'packages/common/web/src/lib/elements/radio/radio.scss'; | ||
@import 'packages/common/web/src/lib/elements/switch/switch.scss'; | ||
@import 'packages/common/web/src/lib/elements/button/button.scss'; | ||
@import 'packages/common/web/src/lib/elements/checkbox/checkbox.scss'; | ||
@import 'packages/common/web/src/lib/elements/textfield/textfield.scss'; |