-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel.html
More file actions
199 lines (175 loc) · 6.74 KB
/
Copy pathlabel.html
File metadata and controls
199 lines (175 loc) · 6.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible Pill List — @wix/interact</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400&display=swap" rel="stylesheet">
<style>
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; list-style: none; }
body {
font-family: 'Inter', sans-serif;
font-weight: 400;
background-color: #0b0b0b;
color: #ffffff;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
overflow-x: hidden;
padding: 20px;
}
interact-element { display: inline-flex; }
.pill-container {
max-width: 820px;
width: 100%;
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 24px 16px;
justify-content: center;
}
@media (min-width: 640px) {
.pill-container { gap: 12px; padding: 40px; }
}
.pill-wrapper {
display: flex;
flex: 0 0 auto;
}
.hidden-checkbox {
position: absolute;
opacity: 0;
pointer-events: none;
width: 0;
height: 0;
}
.pill {
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
height: 48px;
padding: 0 30px;
border-radius: 9999px;
position: relative;
user-select: none;
border: 1.5px solid transparent;
background-color: #1a1a1a;
color: #a3a3a3;
transform-style: preserve-3d;
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
outline: none;
}
.pill:focus-visible { box-shadow: 0 0 0 3px #fff; }
@media (min-width: 640px) {
.pill { height: 56px; padding: 0 40px; }
}
.hidden-checkbox:checked + interact-element .pill {
border-color: #ffd7823f;
border-width: 0.5px;
background-color: #ffd78202;
color: #ffd782;
}
.pill-inner {
display: flex;
align-items: center;
justify-content: center;
gap: 0;
font-size: 14px;
font-weight: 400;
white-space: nowrap;
}
@media (min-width: 640px) {
.pill-inner { font-size: 16px; }
}
.check-icon {
width: 0;
height: 13px;
opacity: 0;
overflow: hidden;
flex-shrink: 0;
transition: width 0.3s ease, opacity 0.25s ease, margin 0.3s ease;
}
.hidden-checkbox:checked + interact-element .check-icon {
width: 13px;
opacity: 1;
margin-right: 6px;
transition-delay: 0.08s;
}
@media (prefers-reduced-motion: reduce) {
.pill, .check-icon { transition: none !important; }
}
</style>
</head>
<body>
<nav aria-label="Skill selection" class="pill-container" id="pill-container"></nav>
<script type="module">
import { Interact } from 'https://esm.sh/@wix/interact@2.1.2/web?bundle';
const skills = [
'Web Design', 'App Development', 'UI/UX', 'Branding & Logo',
'Illustration', 'Motion Graphics', 'Photography', '3D Modeling',
'Copywriting', 'Digital Marketing', 'SEO Optimization', 'Cyber Security'
];
const container = document.getElementById('pill-container');
skills.forEach((skill, i) => {
const isChecked = i === 0 || i === 4 || i === 7;
const wrapper = document.createElement('div');
wrapper.className = 'pill-wrapper';
wrapper.innerHTML = `
<input type="checkbox" id="pill-${i}" class="hidden-checkbox" ${isChecked ? 'checked' : ''} aria-hidden="true">
<interact-element data-interact-key="pill-${i}">
<label for="pill-${i}" class="pill" tabindex="0" role="button" aria-pressed="${isChecked}" aria-label="Toggle ${skill}">
<span class="pill-inner">
<svg class="check-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<polyline points="20 6 9 17 4 12" />
</svg>
${skill}
</span>
</label>
</interact-element>
`;
container.appendChild(wrapper);
});
// Reserve expanded width on each pill so layout never reflows
document.querySelectorAll('.pill').forEach(pill => {
const expandedWidth = pill.offsetWidth + 19; // 13px checkmark + 6px margin
pill.style.minWidth = expandedWidth + 'px';
});
// Keyboard and aria-pressed sync
document.querySelectorAll('.pill').forEach((pill) => {
const cb = document.getElementById(pill.getAttribute('for'));
pill.addEventListener('keydown', (e) => {
if (e.key === ' ' || e.key === 'Enter') {
e.preventDefault();
cb.checked = !cb.checked;
pill.setAttribute('aria-pressed', cb.checked);
}
});
pill.addEventListener('click', () => setTimeout(() => pill.setAttribute('aria-pressed', cb.checked), 0));
});
// Interact: hover highlight + 3D tilt on pointer move
Interact.create({
interactions: skills.flatMap((_, i) => [
{
key: `pill-${i}`,
trigger: 'hover',
params: { method: 'toggle' },
effects: [{
transition: {
duration: 250,
easing: 'ease-out',
styleProperties: [
{ name: 'background-color', value: '#2a2a2a' },
{ name: 'color', value: '#ffffff' },
{ name: 'transform', value: 'scale(1.04)' }
]
}
}]
},
])
});
</script>
</body>
</html>