@1024pix/pix-ui 62.0.1 → 62.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { warn } from '@ember/debug';
|
|
2
|
+
import { on } from '@ember/modifier';
|
|
3
|
+
import { action } from '@ember/object';
|
|
4
|
+
import { guidFor } from '@ember/object/internals';
|
|
5
|
+
import Component from '@glimmer/component';
|
|
6
|
+
import { eq } from 'ember-truth-helpers';
|
|
7
|
+
|
|
8
|
+
import PixIcon from './pix-icon';
|
|
9
|
+
import PixLabel from './pix-label';
|
|
10
|
+
|
|
11
|
+
export default class PixToggle extends Component {
|
|
12
|
+
get id() {
|
|
13
|
+
return this.args.id || guidFor(this);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get cssClasses() {
|
|
17
|
+
const classes = ['pix-toggle'];
|
|
18
|
+
|
|
19
|
+
if (this.args.size) {
|
|
20
|
+
classes.push(`${classes[0]}--${this.args.size}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (this.args.class) {
|
|
24
|
+
classes.push(this.args.class);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return classes.join(' ');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get isDisabled() {
|
|
31
|
+
warn(
|
|
32
|
+
'PixToggle: @isDisabled attribute should be a boolean.',
|
|
33
|
+
[true, false, undefined, null].includes(this.args.isDisabled),
|
|
34
|
+
{
|
|
35
|
+
id: 'pix-ui.toggle.is-disabled.not-boolean',
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return this.args.isDisabled ? 'true' : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@action
|
|
43
|
+
avoidCheckedStateChangeIfIsDisabled(event) {
|
|
44
|
+
if (this.isDisabled) {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
<template>
|
|
50
|
+
<PixLabel
|
|
51
|
+
class={{this.cssClasses}}
|
|
52
|
+
for={{this.id}}
|
|
53
|
+
@size={{if (eq @size "large") "large" "small"}}
|
|
54
|
+
@inlineLabel={{true}}
|
|
55
|
+
@isDisabled={{this.isDisabled}}
|
|
56
|
+
>
|
|
57
|
+
{{#if (has-block)}}
|
|
58
|
+
<span class="pix-toggle__label">
|
|
59
|
+
{{yield}}
|
|
60
|
+
</span>
|
|
61
|
+
{{/if}}
|
|
62
|
+
<span class="pix-toggle__input">
|
|
63
|
+
{{! template-lint-disable require-mandatory-role-attributes }}
|
|
64
|
+
{{! Native checkbox checkedness conveys the switch state; aria-checked would be redundant and unreliable }}
|
|
65
|
+
<input
|
|
66
|
+
class="pix-toggle-input__checkbox"
|
|
67
|
+
role="switch"
|
|
68
|
+
type="checkbox"
|
|
69
|
+
id={{this.id}}
|
|
70
|
+
checked={{@checked}}
|
|
71
|
+
aria-disabled={{this.isDisabled}}
|
|
72
|
+
{{on "click" this.avoidCheckedStateChangeIfIsDisabled}}
|
|
73
|
+
...attributes
|
|
74
|
+
/>
|
|
75
|
+
<span class="pix-toggle-input__thumb">
|
|
76
|
+
<PixIcon class="pix-toggle-input__icon--checked" @name="check" @ariaHidden={{true}} />
|
|
77
|
+
<PixIcon class="pix-toggle-input__icon--unchecked" @name="close" @ariaHidden={{true}} />
|
|
78
|
+
</span>
|
|
79
|
+
</span>
|
|
80
|
+
</PixLabel>
|
|
81
|
+
</template>
|
|
82
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
.pix-toggle {
|
|
2
|
+
--thumb-width: 1rem;
|
|
3
|
+
|
|
4
|
+
display: inline-block;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
|
|
7
|
+
&--large {
|
|
8
|
+
--thumb-width: 1.375rem;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&:has(:disabled),
|
|
12
|
+
&:has([aria-disabled='true']) {
|
|
13
|
+
cursor: not-allowed;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.pix-toggle__label {
|
|
18
|
+
margin-right: var(--pix-spacing-4x);
|
|
19
|
+
font-weight: var(--pix-font-bold);
|
|
20
|
+
vertical-align: middle;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.pix-toggle__input {
|
|
24
|
+
position: relative;
|
|
25
|
+
display: inline-block;
|
|
26
|
+
width: calc(var(--thumb-width) * 2.375);
|
|
27
|
+
color: var(--pix-neutral-500);
|
|
28
|
+
vertical-align: middle;
|
|
29
|
+
background-color: currentcolor;
|
|
30
|
+
border: 2px solid currentcolor;
|
|
31
|
+
border-radius: 5rem;
|
|
32
|
+
outline: 1px solid transparent;
|
|
33
|
+
transition: outline-color 0.2s ease-in-out, background-color 0.2s ease-in-out;
|
|
34
|
+
|
|
35
|
+
&:has(:checked) {
|
|
36
|
+
color: var(--pix-primary-500);
|
|
37
|
+
|
|
38
|
+
.pix-toggle-input__thumb {
|
|
39
|
+
transform: translateX(calc(137.5% - 4px));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.pix-toggle-input__icon--checked {
|
|
43
|
+
display: block;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.pix-toggle-input__icon--unchecked {
|
|
47
|
+
display: none;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&:not(:has(:disabled), :has([aria-disabled='true'])) {
|
|
52
|
+
&:hover,
|
|
53
|
+
&:has(:focus) {
|
|
54
|
+
color: var(--pix-neutral-800);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&:has(:checked):hover,
|
|
58
|
+
&:has(:checked):has(:focus) {
|
|
59
|
+
color: var(--pix-primary-700);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&:has(:focus) {
|
|
64
|
+
outline-color: currentcolor;
|
|
65
|
+
outline-offset: 1px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Disabled state
|
|
69
|
+
&:has(:disabled),
|
|
70
|
+
&:has([aria-disabled='true']) {
|
|
71
|
+
color: var(--pix-neutral-100);
|
|
72
|
+
|
|
73
|
+
&:has(:checked) {
|
|
74
|
+
color: var(--pix-primary-300);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&:has(:focus) {
|
|
78
|
+
outline-color: var(--pix-neutral-800);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.pix-toggle-input__checkbox {
|
|
84
|
+
position: absolute;
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
opacity: 0;
|
|
87
|
+
inset: 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.pix-toggle-input__thumb {
|
|
91
|
+
display: flex;
|
|
92
|
+
align-items: center;
|
|
93
|
+
justify-content: center;
|
|
94
|
+
width: var(--thumb-width);
|
|
95
|
+
height: var(--thumb-width);
|
|
96
|
+
background-color: var(--pix-neutral-0);
|
|
97
|
+
border-radius: 50%;
|
|
98
|
+
transition: transform 0.2s ease-in-out;
|
|
99
|
+
|
|
100
|
+
svg {
|
|
101
|
+
transform: scale(0.8);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.pix-toggle-input__icon--checked {
|
|
106
|
+
display: none;
|
|
107
|
+
}
|
package/addon/styles/addon.scss
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@1024pix/pix-ui/components/pix-toggle';
|