Skip to content

Commit dcaa990

Browse files
authored
Relative color syntax (#238)
* init * sturdy base * img nit * adds focus zoom component
1 parent 19c1d31 commit dcaa990

13 files changed

+3304
-2
lines changed

.github/workflows/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ jobs:
106106

107107
- name: Adaptive Typography
108108
run: cd adaptive-typography && npm install && npm run build
109+
110+
- name: Relative Colors
111+
run: cd relative-colors && npm install && npm run build
109112

110113
- name: Deploy to Firebase
111114
uses: w9jds/firebase-action@master

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,13 @@ and expand the diversity of our skills.**
119119
30. okLCH Color Palettes
120120
[`Demo`](https://gui-challenges.web.app/color-palettes/dist/)
121121
[`YouTube`](https://www.youtube.com/watch?v=6aCsAMgwnjE)
122-
30. Morphing Button
122+
31. Morphing Button
123123
[`Demo`](https://gui-challenges.web.app/morphing-button/dist/)
124124
[`YouTube`](https://www.youtube.com/watch?v=N2BKAKwGP6M)
125-
30. Adaptive Typography
125+
32. Adaptive Typography
126126
[`Demo`](https://gui-challenges.web.app/adaptive-typography/dist/)
127127
[`YouTube`](https://www.youtube.com/watch?v=8B7xOgp5Aow)
128128
[`Article`](https://web.dev/adapting-typography-to-user-preferences-with-css/)
129+
33. Relative Colors
130+
[`Demo`](https://gui-challenges.web.app/relative-colors/dist/)
131+
[`YouTube`](#)(coming soon)

relative-colors/favicon.ico

15 KB
Binary file not shown.

relative-colors/favicon.svg

+28
Loading

relative-colors/focus-zoom.css

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@property --top {
2+
syntax: '<length>';
3+
initial-value: 0;
4+
inherits: false;
5+
}
6+
7+
@property --right {
8+
syntax: '<length>';
9+
initial-value: 0;
10+
inherits: false;
11+
}
12+
13+
@property --bottom {
14+
syntax: '<length>';
15+
initial-value: 0;
16+
inherits: false;
17+
}
18+
19+
@property --left {
20+
syntax: '<length>';
21+
initial-value: 0;
22+
inherits: false;
23+
}
24+
25+
focus-zoom {
26+
--backdrop-color: hsl(0 0% 0% / 30%); /* can't be opaque */
27+
--backdrop-blur-strength: 10px;
28+
29+
position: fixed;
30+
touch-action: none;
31+
pointer-events: none;
32+
inset: 0;
33+
background-color: var(--backdrop-color);
34+
backdrop-filter: blur(var(--backdrop-blur-strength));
35+
36+
mask-image:
37+
linear-gradient(to bottom, black var(--top), black 0%, transparent 0%),
38+
linear-gradient(to right, black var(--left), black 0%, transparent 0%),
39+
linear-gradient(to top, black var(--bottom), black 0%, transparent 0%),
40+
linear-gradient(to left, black var(--right), black 0%, transparent 0%);
41+
42+
transition:
43+
--top .3s ease,
44+
--right .3s ease,
45+
--bottom .3s ease,
46+
--left .3s ease;
47+
}

relative-colors/focus-zoom.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const zoom = document.querySelector('focus-zoom')
2+
3+
const state = {}
4+
5+
const toggleSpotlight = show_effect => {
6+
if (show_effect) {
7+
zoom.style.setProperty('--top', `${state.top}px`)
8+
zoom.style.setProperty('--right', `${state.right}px`)
9+
zoom.style.setProperty('--bottom', `${state.bottom}px`)
10+
zoom.style.setProperty('--left', `${state.left}px`)
11+
} else {
12+
zoom.style.setProperty('--top', `0px`)
13+
zoom.style.setProperty('--right', `0px`)
14+
zoom.style.setProperty('--bottom', `0px`)
15+
zoom.style.setProperty('--left', `0px`)
16+
}
17+
}
18+
19+
window.addEventListener('mouseover', e => {
20+
let { top, right, bottom, left } = e.target.getBoundingClientRect()
21+
22+
state.top = top - 2
23+
state.right = window.innerWidth-right - 2
24+
state.bottom = window.innerHeight-bottom - 2
25+
state.left = left - 2
26+
})
27+
28+
window.addEventListener('keydown', e =>
29+
toggleSpotlight(e.altKey))
30+
window.addEventListener('keyup', e =>
31+
toggleSpotlight(e.altKey))
32+
window.addEventListener('touchstart', e =>
33+
toggleSpotlight(true))
34+
window.addEventListener('touchend', e =>
35+
toggleSpotlight(false))

0 commit comments

Comments
 (0)