feat(playlists): select rows with a box, Shift for a range, x and Esc
A box first in every row and one over the column for the rows shown, the selected row tinted. A filter keeps what it hides selected; another list starts over; a row that left the list drops out. Watch later has none. A box no longer counts as a typing target: a click on one left the focus there and the page's keys went dead.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import clsx from "clsx";
|
||||
import type { InputHTMLAttributes, ReactNode, Ref } from "react";
|
||||
import type { InputHTMLAttributes, ReactNode, RefObject } from "react";
|
||||
|
||||
// A6 (docs/DESIGN.md): checkbox, slider and colour well are the BROWSER's controls, tinted
|
||||
// with the chosen colour (the accent; the media amber on the player chrome) — keyboard, screen
|
||||
@@ -10,18 +10,30 @@ import type { InputHTMLAttributes, ReactNode, Ref } from "react";
|
||||
|
||||
type Native = Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "onChange">;
|
||||
|
||||
/** The bare checkbox: inside your own `<label>`, or with an `aria-label`. Prefer `CheckRow`. */
|
||||
/** The bare checkbox: inside your own `<label>`, or with an `aria-label`. Prefer `CheckRow`.
|
||||
* `onChange` also says whether Shift was held, for a range. `mixed` is the third state, some of what
|
||||
* it covers: the DOM has no attribute for it, only the property. */
|
||||
export function Checkbox({
|
||||
onChange,
|
||||
className,
|
||||
ref,
|
||||
mixed = false,
|
||||
...rest
|
||||
}: Native & { onChange?: (checked: boolean) => void; ref?: Ref<HTMLInputElement> }) {
|
||||
}: Native & {
|
||||
onChange?: (checked: boolean, shift: boolean) => void;
|
||||
ref?: RefObject<HTMLInputElement | null>;
|
||||
mixed?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<input
|
||||
ref={ref}
|
||||
ref={(el) => {
|
||||
if (ref) ref.current = el;
|
||||
if (el) el.indeterminate = mixed;
|
||||
}}
|
||||
type="checkbox"
|
||||
onChange={(e) => onChange?.(e.target.checked)}
|
||||
onChange={(e) =>
|
||||
onChange?.(e.target.checked, e.nativeEvent instanceof MouseEvent && e.nativeEvent.shiftKey)
|
||||
}
|
||||
className={clsx(
|
||||
"size-4 shrink-0 cursor-pointer accent-chosen disabled:cursor-not-allowed",
|
||||
className,
|
||||
@@ -54,7 +66,7 @@ export function CheckRow({
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<Checkbox checked={checked} onChange={onChange} disabled={disabled} />
|
||||
<Checkbox checked={checked} onChange={(on) => onChange(on)} disabled={disabled} />
|
||||
{children}
|
||||
</label>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user