lapikit 0.6.11 → 0.6.12
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.
|
@@ -10,41 +10,49 @@ function getCoords(e) {
|
|
|
10
10
|
return { x: e.clientX, y: e.clientY };
|
|
11
11
|
}
|
|
12
12
|
export function ripple(el, options = {}) {
|
|
13
|
-
|
|
13
|
+
// created on first interaction, removed once every ripple has faded out
|
|
14
|
+
let rippleContainer;
|
|
14
15
|
const activeRipples = new Set();
|
|
15
|
-
addClasses();
|
|
16
|
-
setOptions(options);
|
|
17
16
|
function isAriaDisabled() {
|
|
18
17
|
return el.getAttribute('aria-disabled') === 'true';
|
|
19
18
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
rippleContainer.classList.add('kit-ripple--effect');
|
|
19
|
+
function applyOptions(container) {
|
|
20
|
+
if (options.component) {
|
|
21
|
+
container.style.setProperty('--system-ripple-radius', `var(--kit-${options.component}-radius)`);
|
|
24
22
|
}
|
|
25
|
-
if (
|
|
26
|
-
|
|
23
|
+
if (options.color) {
|
|
24
|
+
container.style.setProperty('--system-ripple-color', options.color);
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const duration = resolveDuration(options);
|
|
27
|
+
if (duration) {
|
|
28
|
+
container.style.setProperty('--system-animation-ripple-duration', `${duration}ms`);
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
function
|
|
33
|
-
if (
|
|
34
|
-
rippleContainer.
|
|
31
|
+
function mountContainer(center) {
|
|
32
|
+
if (!rippleContainer) {
|
|
33
|
+
rippleContainer = document.createElement('div');
|
|
34
|
+
rippleContainer.classList.add('kit-ripple--effect');
|
|
35
|
+
applyOptions(rippleContainer);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
rippleContainer.classList.toggle('kit-ripple--center', !!(center || options.center));
|
|
38
|
+
if (!rippleContainer.isConnected) {
|
|
37
39
|
el.appendChild(rippleContainer);
|
|
38
40
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
return rippleContainer;
|
|
42
|
+
}
|
|
43
|
+
function unmountContainer() {
|
|
44
|
+
rippleContainer?.remove();
|
|
45
|
+
rippleContainer = undefined;
|
|
46
|
+
}
|
|
47
|
+
function setOptions(newOptions) {
|
|
48
|
+
options = newOptions;
|
|
49
|
+
if (newOptions.disabled || isAriaDisabled()) {
|
|
50
|
+
activeRipples.forEach((cleanup) => cleanup());
|
|
51
|
+
activeRipples.clear();
|
|
52
|
+
unmountContainer();
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
rippleContainer.style.setProperty('--system-animation-ripple-duration', `${duration}ms`);
|
|
54
|
+
else if (rippleContainer) {
|
|
55
|
+
applyOptions(rippleContainer);
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
function createRipple(e, center) {
|
|
@@ -60,7 +68,7 @@ export function ripple(el, options = {}) {
|
|
|
60
68
|
createRipple(click, true);
|
|
61
69
|
return;
|
|
62
70
|
}
|
|
63
|
-
|
|
71
|
+
const container = mountContainer(center);
|
|
64
72
|
const rect = el.getBoundingClientRect();
|
|
65
73
|
const { x: clientX, y: clientY } = getCoords(e);
|
|
66
74
|
const x = clientX - rect.left > el.offsetWidth / 2 ? 0 : el.offsetWidth;
|
|
@@ -71,7 +79,7 @@ export function ripple(el, options = {}) {
|
|
|
71
79
|
ripple.style.left = `${clientX - rect.left - radius}px`;
|
|
72
80
|
ripple.style.top = `${clientY - rect.top - radius}px`;
|
|
73
81
|
ripple.style.width = ripple.style.height = `${radius * 2}px`;
|
|
74
|
-
|
|
82
|
+
container.appendChild(ripple);
|
|
75
83
|
let timeoutId;
|
|
76
84
|
function cleanup() {
|
|
77
85
|
if (timeoutId) {
|
|
@@ -80,12 +88,18 @@ export function ripple(el, options = {}) {
|
|
|
80
88
|
cancelEvents.forEach((event) => el.removeEventListener(event, removeRipple));
|
|
81
89
|
ripple.remove();
|
|
82
90
|
}
|
|
91
|
+
function release() {
|
|
92
|
+
activeRipples.delete(cleanup);
|
|
93
|
+
if (activeRipples.size === 0) {
|
|
94
|
+
unmountContainer();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
83
97
|
function removeRipple() {
|
|
84
98
|
ripple.style.opacity = '0';
|
|
85
99
|
cancelEvents.forEach((event) => el.removeEventListener(event, removeRipple));
|
|
86
100
|
timeoutId = setTimeout(() => {
|
|
87
101
|
ripple.remove();
|
|
88
|
-
|
|
102
|
+
release();
|
|
89
103
|
}, resolveDuration(options) || 1000);
|
|
90
104
|
}
|
|
91
105
|
activeRipples.add(cleanup);
|
|
@@ -99,10 +113,9 @@ export function ripple(el, options = {}) {
|
|
|
99
113
|
});
|
|
100
114
|
activeRipples.forEach((cleanup) => cleanup());
|
|
101
115
|
activeRipples.clear();
|
|
102
|
-
|
|
116
|
+
unmountContainer();
|
|
103
117
|
},
|
|
104
118
|
update(newOptions) {
|
|
105
|
-
options = newOptions;
|
|
106
119
|
setOptions(newOptions);
|
|
107
120
|
}
|
|
108
121
|
};
|
|
@@ -158,9 +158,15 @@
|
|
|
158
158
|
--kit-list-item-hover-bg: color-mix(in oklab, var(--kit-list-item-fg), transparent 80%);
|
|
159
159
|
--kit-list-item-active-bg: color-mix(in oklab, var(--kit-list-item-fg), transparent 92%);
|
|
160
160
|
}
|
|
161
|
-
.kit-list[data-variant='
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
.kit-list[data-variant='outline'] :global(.kit-list-item::before) {
|
|
162
|
+
content: '';
|
|
163
|
+
position: absolute;
|
|
164
|
+
inset: 0;
|
|
165
|
+
border: 1px solid var(--kit-list-item-bd);
|
|
166
|
+
border-radius: inherit;
|
|
167
|
+
box-sizing: border-box;
|
|
168
|
+
z-index: 1;
|
|
169
|
+
pointer-events: none;
|
|
164
170
|
}
|
|
165
171
|
|
|
166
172
|
/**
|
|
@@ -81,7 +81,6 @@
|
|
|
81
81
|
}}
|
|
82
82
|
{...restProps}
|
|
83
83
|
>
|
|
84
|
-
<span class="outline"></span>
|
|
85
84
|
{#if prepend}
|
|
86
85
|
<span class="kit-list-item__prepend">
|
|
87
86
|
{@render prepend?.()}
|
|
@@ -189,8 +188,4 @@
|
|
|
189
188
|
text-overflow: ellipsis;
|
|
190
189
|
white-space: nowrap;
|
|
191
190
|
}
|
|
192
|
-
|
|
193
|
-
.kit-list-item .outline {
|
|
194
|
-
--outline-color: var(--kit-list-item-bd);
|
|
195
|
-
}
|
|
196
191
|
</style>
|