210 lines
4.5 KiB
TypeScript
210 lines
4.5 KiB
TypeScript
import { cn } from "@/lib/utils"
|
|
|
|
export type SelectionRangePosition =
|
|
| "none"
|
|
| "only"
|
|
| "start"
|
|
| "middle"
|
|
| "end"
|
|
|
|
export function getSelectionRangePositions(
|
|
itemIds: string[],
|
|
selectedIds: Set<string>
|
|
): SelectionRangePosition[] {
|
|
const positions: SelectionRangePosition[] = itemIds.map((id) =>
|
|
selectedIds.has(id) ? "only" : "none"
|
|
)
|
|
|
|
let index = 0
|
|
while (index < itemIds.length) {
|
|
if (!selectedIds.has(itemIds[index])) {
|
|
index++
|
|
continue
|
|
}
|
|
|
|
const start = index
|
|
while (index < itemIds.length && selectedIds.has(itemIds[index])) {
|
|
index++
|
|
}
|
|
|
|
const end = index - 1
|
|
const count = end - start + 1
|
|
|
|
for (let position = start; position <= end; position++) {
|
|
if (count === 1) {
|
|
positions[position] = "only"
|
|
} else if (position === start) {
|
|
positions[position] = "start"
|
|
} else if (position === end) {
|
|
positions[position] = "end"
|
|
} else {
|
|
positions[position] = "middle"
|
|
}
|
|
}
|
|
}
|
|
|
|
return positions
|
|
}
|
|
|
|
export function selectionHighlightRadiusClass(
|
|
position: SelectionRangePosition
|
|
) {
|
|
switch (position) {
|
|
case "only":
|
|
return "rounded-lg"
|
|
case "start":
|
|
return "rounded-t-lg"
|
|
case "end":
|
|
return "rounded-b-lg"
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
export const TRACK_ROW_HIGHLIGHT_INSET = "absolute inset-y-0 left-2 right-2"
|
|
|
|
export function SelectionRangeHighlight({
|
|
position,
|
|
}: {
|
|
position: SelectionRangePosition
|
|
}) {
|
|
if (position === "none") {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div
|
|
aria-hidden
|
|
className={cn(
|
|
"pointer-events-none bg-primary",
|
|
TRACK_ROW_HIGHLIGHT_INSET,
|
|
selectionHighlightRadiusClass(position)
|
|
)}
|
|
/>
|
|
)
|
|
}
|
|
|
|
/** Inset rounded hover background matching the selection pill shape. */
|
|
export function TrackRowHoverHighlight() {
|
|
return (
|
|
<div
|
|
aria-hidden
|
|
className={cn(
|
|
"pointer-events-none rounded-lg bg-muted/60 opacity-0 transition-opacity group-hover:opacity-100",
|
|
TRACK_ROW_HIGHLIGHT_INSET
|
|
)}
|
|
/>
|
|
)
|
|
}
|
|
|
|
/** Inset rounded background for the active (now playing) row. */
|
|
export function TrackRowActiveHighlight() {
|
|
return (
|
|
<div
|
|
aria-hidden
|
|
className={cn(
|
|
"pointer-events-none rounded-lg bg-muted/60",
|
|
TRACK_ROW_HIGHLIGHT_INSET
|
|
)}
|
|
/>
|
|
)
|
|
}
|
|
|
|
/** Shared horizontal padding for track rows — same when selected or not. */
|
|
export const TRACK_ROW_PADDING = "pl-8 pr-10"
|
|
|
|
/** Centers the track list in the main content area. */
|
|
export const TRACK_LIST_CONTAINER = "mx-auto w-full max-w-3xl"
|
|
|
|
/** Full-width highlight for library song rows (no horizontal inset). */
|
|
export const SONGS_ROW_HIGHLIGHT_INSET = "absolute inset-0"
|
|
|
|
export function SongsSelectionRangeHighlight({
|
|
position,
|
|
}: {
|
|
position: SelectionRangePosition
|
|
}) {
|
|
if (position === "none") {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div
|
|
aria-hidden
|
|
className={cn(
|
|
"pointer-events-none bg-primary",
|
|
SONGS_ROW_HIGHLIGHT_INSET
|
|
)}
|
|
/>
|
|
)
|
|
}
|
|
|
|
/** Full-width hover background for library song rows (not rounded). */
|
|
export function SongsTrackRowHoverHighlight() {
|
|
return (
|
|
<div
|
|
aria-hidden
|
|
className={cn(
|
|
"pointer-events-none bg-muted/60 opacity-0 transition-opacity group-hover:opacity-100",
|
|
SONGS_ROW_HIGHLIGHT_INSET
|
|
)}
|
|
/>
|
|
)
|
|
}
|
|
|
|
/** Album track row: star, track #, title (flex), duration, menu. */
|
|
export const ALBUM_TRACK_ROW = "flex w-full min-w-0 items-center gap-x-3"
|
|
|
|
export const ALBUM_TRACK_TITLE = "min-w-0 flex-1 truncate font-normal"
|
|
|
|
export function isInSelectionRange(position: SelectionRangePosition) {
|
|
return position !== "none"
|
|
}
|
|
|
|
/** Full-width, square-corner highlights for the queue sidebar. */
|
|
export const QUEUE_ROW_HIGHLIGHT_INSET = "absolute inset-0"
|
|
|
|
export function QueueSelectionRangeHighlight({
|
|
position,
|
|
}: {
|
|
position: SelectionRangePosition
|
|
}) {
|
|
if (position === "none") {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div
|
|
aria-hidden
|
|
className={cn(
|
|
"pointer-events-none bg-primary",
|
|
QUEUE_ROW_HIGHLIGHT_INSET
|
|
)}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export function QueueTrackRowHoverHighlight() {
|
|
return (
|
|
<div
|
|
aria-hidden
|
|
className={cn(
|
|
"pointer-events-none bg-muted/60 opacity-0 transition-opacity group-hover:opacity-100",
|
|
QUEUE_ROW_HIGHLIGHT_INSET
|
|
)}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export function QueueTrackRowActiveHighlight() {
|
|
return (
|
|
<div
|
|
aria-hidden
|
|
className={cn(
|
|
"pointer-events-none bg-muted/60",
|
|
QUEUE_ROW_HIGHLIGHT_INSET
|
|
)}
|
|
/>
|
|
)
|
|
}
|