-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathCopyToClipboard.css
More file actions
174 lines (147 loc) · 4.92 KB
/
Copy pathCopyToClipboard.css
File metadata and controls
174 lines (147 loc) · 4.92 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
/* ── CopyToClipboard ─────────────────────────────────────────────────────── */
/* ----- Keyframes ----------------------------------------------------------- */
/**
* Scale-pop used when the button enters the `copied` success state.
* Grows slightly above 1 then settles back to natural size, giving a
* satisfying "stamp" feel without displacing surrounding layout.
*/
@keyframes copy-success-pop {
0% { transform: scale(1); }
40% { transform: scale(1.14); }
70% { transform: scale(0.97); }
100% { transform: scale(1); }
}
/**
* Horizontal micro-shake used when the copy operation fails.
* Amplitude is intentionally small (3 px) so it reads as "something went
* wrong" without being disorienting for vestibular-sensitive users.
*/
@keyframes copy-error-shake {
0%, 100% { transform: translateX(0); }
20% { transform: translateX(-3px); }
40% { transform: translateX(3px); }
60% { transform: translateX(-3px); }
80% { transform: translateX(2px); }
}
/* ----- Layout -------------------------------------------------------------- */
.copy-affordance {
display: inline-flex;
align-items: center;
gap: 0.5rem;
min-width: 0;
max-width: 100%;
}
.copy-affordance--surface {
min-height: 44px;
padding: 0.625rem 0.75rem;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 6px;
}
/* ----- Value label --------------------------------------------------------- */
.copy-affordance__value {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--muted);
}
/* ----- Copy button — base -------------------------------------------------- */
.copy-affordance__button {
min-height: 32px;
padding: 0.375rem 0.625rem;
display: inline-flex;
align-items: center;
gap: 0.375rem;
border: 1px solid transparent;
border-radius: var(--radius-pill, 9999px);
background: rgba(88, 166, 255, 0.12);
color: var(--accent);
font: inherit;
font-weight: 600;
cursor: pointer;
/*
* `transform` participates in the animations declared above.
* Including it in the transition list means both animated and
* non-animated state changes feel smooth.
*/
transition:
background 0.15s ease,
border-color 0.15s ease,
color 0.15s ease,
transform 0.15s ease;
flex-shrink: 0;
}
.copy-affordance__button:hover {
background: rgba(88, 166, 255, 0.18);
border-color: rgba(88, 166, 255, 0.35);
}
.copy-affordance__button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
/* ----- Copied state -------------------------------------------------------- */
.copy-affordance__button[data-copy-state='copied'] {
background: rgba(63, 185, 80, 0.14);
border-color: rgba(63, 185, 80, 0.35);
color: var(--success);
animation: copy-success-pop 0.35s ease both;
}
/* Hover on copied state keeps the success colour so the button doesn't flicker */
.copy-affordance__button[data-copy-state='copied']:hover {
background: rgba(63, 185, 80, 0.22);
border-color: rgba(63, 185, 80, 0.5);
}
/* Focus ring adapts to success colour for visual coherence */
.copy-affordance__button[data-copy-state='copied']:focus-visible {
outline-color: var(--success);
}
/* ----- Error state --------------------------------------------------------- */
.copy-affordance__button[data-copy-state='error'] {
background: rgba(248, 81, 73, 0.12);
border-color: rgba(248, 81, 73, 0.35);
color: var(--error);
animation: copy-error-shake 0.4s ease both;
}
.copy-affordance__button[data-copy-state='error']:hover {
background: rgba(248, 81, 73, 0.18);
border-color: rgba(248, 81, 73, 0.5);
}
.copy-affordance__button[data-copy-state='error']:focus-visible {
outline-color: var(--error);
}
/* ----- Icon + label -------------------------------------------------------- */
.copy-affordance__button-label {
line-height: 1;
}
.copy-affordance__icon {
width: 0.9rem;
height: 0.9rem;
}
/* ----- Reduced-motion override --------------------------------------------- */
/*
* When the user has requested reduced motion (OS-level preference or the
* repo's custom [data-motion="reduced"] attribute), collapse the keyframe
* animations and transform transitions to an instant colour-only swap.
* The state still changes — only the motion is removed, not the feedback.
*/
@media (prefers-reduced-motion: reduce) {
.copy-affordance__button[data-copy-state='copied'],
.copy-affordance__button[data-copy-state='error'] {
animation: none;
transform: none;
transition:
background 0.01ms,
border-color 0.01ms,
color 0.01ms;
}
}
[data-motion='reduced'] .copy-affordance__button[data-copy-state='copied'],
[data-motion='reduced'] .copy-affordance__button[data-copy-state='error'] {
animation: none;
transform: none;
transition:
background 0.01ms,
border-color 0.01ms,
color 0.01ms;
}