Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Lilpay331/7bf6b9b89a941328518983b7b7358b66 to your computer and use it in GitHub Desktop.
Save Lilpay331/7bf6b9b89a941328518983b7b7358b66 to your computer and use it in GitHub Desktop.
Focus table rows with :not(:focus-within) πŸ”¦
<h1>edit name/email</h1>
<div class="members">
<table role="grid">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Email</th>
<th>Subscription</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img
src="https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/40.jpg"
alt=""
/>
</td>
<td>
<input aria-label="name" type="text" value="Emily Hoffman" />
</td>
<td>
<input
aria-label="email"
type="email"
value="[email protected]"
/>
</td>
<td>Paid</td>
</tr>
<tr>
<td>
<img
src="https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/512/96.jpg"
alt=""
/>
</td>
<td>
<input aria-label="name" type="text" value="Michel Lewin" />
</td>
<td>
<input aria-label="email" type="email" value="[email protected]" />
</td>
<td>Unconfirmed</td>
</tr>
<tr>
<td>
<img
src="https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/49.jpg"
alt=""
/>
</td>
<td>
<input aria-label="name" type="text" value="Tessa Dietrich" />
</td>
<td>
<input
aria-label="email"
type="email"
value="[email protected]"
/>
</td>
<td>Confirmed</td>
</tr>
<tr>
<td>
<img
src="https://assets.codepen.io/605876/cropped-headshot--saturated-low-res.jpg"
alt=""
/>
</td>
<td><input aria-label="name" type="text" value="John Doe" /></td>
<td>
<input
aria-label="email"
type="email"
value="[email protected]"
/>
</td>
<td>Paid</td>
</tr>
<tr>
<td>
<img
src="https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/male/512/72.jpg"
alt=""
/>
</td>
<td><input aria-label="name" type="text" value="Niels Grau" /></td>
<td>
<input aria-label="email" type="email" value="[email protected]" />
</td>
<td>Pending</td>
</tr>
<tr>
<td>
<img
src="https://cdn.jsdelivr.net/gh/faker-js/assets-person-portrait/female/512/64.jpg"
alt=""
/>
</td>
<td><input aria-label="name" type="text" value="Nadine Dare" /></td>
<td>
<input
aria-label="email"
type="email"
value="[email protected]"
/>
</td>
<td>Unconfirmed</td>
</tr>
</tbody>
</table>
</div>
<a
aria-label="Follow Jhey"
class="bear-link"
href="https://twitter.com/intent/follow?screen_name=jh3yy"
target="_blank"
rel="noreferrer noopener"
>
<svg
class="w-9"
viewBox="0 0 969 955"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle
cx="161.191"
cy="320.191"
r="133.191"
stroke="currentColor"
stroke-width="20"
></circle>
<circle
cx="806.809"
cy="320.191"
r="133.191"
stroke="currentColor"
stroke-width="20"
></circle>
<circle
cx="695.019"
cy="587.733"
r="31.4016"
fill="currentColor"
></circle>
<circle
cx="272.981"
cy="587.733"
r="31.4016"
fill="currentColor"
></circle>
<path
d="M564.388 712.083C564.388 743.994 526.035 779.911 483.372 779.911C440.709 779.911 402.356 743.994 402.356 712.083C402.356 680.173 440.709 664.353 483.372 664.353C526.035 664.353 564.388 680.173 564.388 712.083Z"
fill="currentColor"
></path>
<rect
x="310.42"
y="448.31"
width="343.468"
height="51.4986"
fill="#FF1E1E"
></rect>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M745.643 288.24C815.368 344.185 854.539 432.623 854.539 511.741H614.938V454.652C614.938 433.113 597.477 415.652 575.938 415.652H388.37C366.831 415.652 349.37 433.113 349.37 454.652V511.741L110.949 511.741C110.949 432.623 150.12 344.185 219.845 288.24C289.57 232.295 384.138 200.865 482.744 200.865C581.35 200.865 675.918 232.295 745.643 288.24Z"
fill="currentColor"
></path>
</svg>
</a>
import { Pane } from 'https://cdn.skypack.dev/[email protected]'
const config = {
theme: 'system',
color: 'hsl(200,80%,50%)',
}
const ctrl = new Pane({
title: 'Config',
expanded: true,
})
const update = () => {
document.documentElement.dataset.theme = config.theme
document.documentElement.style.setProperty('--accent', config.color)
}
const sync = (event) => {
if (
!document.startViewTransition ||
event.target.controller.view.labelElement.innerText !== 'Theme'
)
return update()
document.startViewTransition(() => update())
}
ctrl.addBinding(config, 'color', {
label: 'accent',
})
ctrl.addBinding(config, 'theme', {
label: 'Theme',
options: {
System: 'system',
Light: 'light',
Dark: 'dark',
},
})
ctrl.on('change', sync)
update()
@import url('https://unpkg.com/normalize.css') layer(normalize);
@layer normalize, base, demo;
@layer demo {
:root {
--accent: hsl(200 80% 50%);
--border: color-mix(in oklch, canvas, canvasText 15%);
--background: color-mix(in oklch, canvas, canvasText 2%);
--head: light-dark(hsl(0 0% 98%), canvas);
--selected: color-mix(in oklch, var(--accent), canvas 85%);
--color: color-mix(in hsl, canvasText, #0000 50%);
--hover-background: light-dark(hsl(0 0% 92%), hsl(0 0% 10%));
--sibling-hover: red;
--hover-color: green;
}
.members {
background: light-dark(#fff, #000);
overflow: auto;
border: 1px solid var(--border);
border-radius: 6px;
}
table {
font-size: 0.875rem;
border-collapse: collapse;
background: #0000;
color: var(--color);
}
input {
color: var(--color);
}
table:focus-within tbody tr:not(:focus-within) {
filter: blur(4px) saturate(0.2);
pointer-events: none;
opacity: 0.5;
}
tr:focus-within {
background: var(--selected);
td,
input {
color: canvasText;
}
}
thead {
background: var(--head);
}
th,
td:first-of-type {
padding: 0.25rem 1rem;
}
:is(td, th) {
height: 40px;
}
td {
font-weight: 300;
}
tr {
transition-property: filter, background, opacity;
transition-duration: 0.2s;
transition-timing-function: ease-out;
&:not(:last-of-type) {
border-bottom: 1px solid var(--head);
}
}
table :is(td, th) {
white-space: nowrap;
font-weight: 400;
font-size: 0.875rem;
}
table th {
text-align: left;
font-weight: 500;
color: color-mix(in hsl, canvasText, #0000 35%);
}
thead {
background: var(--head);
}
td:not(:has(input)) {
padding: 0.5rem 1rem;
}
tr:focus-within input:hover:not(:focus-visible) {
background: color-mix(in oklch, var(--accent), #0000 75%);
}
table input {
font-size: inherit;
height: 40px;
font-weight: inherit;
border: 0;
padding: 0.5rem 1rem;
height: 100%;
background: #0000;
border-radius: 0;
caret-color: var(--accent);
transition: color 0.26s ease-out;
&:hover:not(:focus-visible) {
background: var(--hover-background);
}
&::selection {
background: var(--accent);
color: white;
}
&:focus-visible {
background: light-dark(#fff, #000);
outline: 2px solid var(--accent);
}
}
input:not(:focus, :focus-visible) {
cursor: pointer;
}
table img {
border-radius: 50%;
width: 24px;
aspect-ratio: 1;
}
}
@layer base {
:root {
--font-size-min: 16;
--font-size-max: 20;
--font-ratio-min: 1.2;
--font-ratio-max: 1.33;
--font-width-min: 375;
--font-width-max: 1500;
}
html {
color-scheme: light dark;
}
[data-theme='light'] {
color-scheme: light only;
}
[data-theme='dark'] {
color-scheme: dark only;
}
:where(.fluid) {
--fluid-min: calc(
var(--font-size-min) * pow(var(--font-ratio-min), var(--font-level, 0))
);
--fluid-max: calc(
var(--font-size-max) * pow(var(--font-ratio-max), var(--font-level, 0))
);
--fluid-preferred: calc(
(var(--fluid-max) - var(--fluid-min)) /
(var(--font-width-max) - var(--font-width-min))
);
--fluid-type: clamp(
(var(--fluid-min) / 16) * 1rem,
((var(--fluid-min) / 16) * 1rem) -
(((var(--fluid-preferred) * var(--font-width-min)) / 16) * 1rem) +
(var(--fluid-preferred) * var(--variable-unit, 100vi)),
(var(--fluid-max) / 16) * 1rem
);
font-size: var(--fluid-type);
}
*,
*:after,
*:before {
box-sizing: border-box;
}
body {
background: light-dark(#fff, #000);
display: grid;
place-items: center;
min-height: 100vh;
font-family: 'SF Pro Text', 'SF Pro Icons', 'AOS Icons', 'Helvetica Neue',
Helvetica, Arial, sans-serif, system-ui;
}
body::before {
--size: 45px;
--line: color-mix(in hsl, canvasText, transparent 80%);
content: '';
height: 100vh;
width: 100vw;
position: fixed;
background: linear-gradient(
90deg,
var(--line) 1px,
transparent 1px var(--size)
)
calc(var(--size) * 0.36) 50% / var(--size) var(--size),
linear-gradient(var(--line) 1px, transparent 1px var(--size)) 0%
calc(var(--size) * 0.32) / var(--size) var(--size);
mask: linear-gradient(-20deg, transparent 50%, white);
top: 0;
transform-style: flat;
pointer-events: none;
z-index: -1;
}
.bear-link {
color: canvasText;
position: fixed;
top: 1rem;
left: 1rem;
width: 48px;
aspect-ratio: 1;
display: grid;
place-items: center;
opacity: 0.8;
}
:where(.x-link, .bear-link):is(:hover, :focus-visible) {
opacity: 1;
}
.bear-link svg {
width: 75%;
}
/* Utilities */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
}
h1 {
margin: 0;
font-size: 1.25rem;
position: fixed;
bottom: 1rem;
right: 1rem;
font-family: monospace;
opacity: .5;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment