mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-04 23:32:54 +01:00
migrate tier list
This commit is contained in:
108 files changed
+1238
-922
No files matched your search
@@ -0,0 +1,35 @@
|
||||
/* A plain cell, since a row header's own background would cover the accent */
|
||||
.header {
|
||||
vertical-align: middle;
|
||||
|
||||
background-color: var(--accent-9);
|
||||
cursor: pointer;
|
||||
|
||||
/* Table cells ignore max-width, so the content carries the size: the widest name, within limits */
|
||||
.content {
|
||||
width: max-content;
|
||||
min-width: 5rem;
|
||||
max-width: 12rem;
|
||||
min-height: 8rem;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
}
|
||||
|
||||
.swatches {
|
||||
/* Adds no width of its own, filling and wrapping within what the rest of the popover sets */
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
width: 0;
|
||||
min-width: 100%;
|
||||
|
||||
/* Every swatch keeps its check so the buttons stay the same size; only the selected one shows it */
|
||||
.swatch[data-selected="false"] svg {
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import {
|
||||
CheckIcon,
|
||||
Cross1Icon,
|
||||
Pencil2Icon,
|
||||
TrashIcon,
|
||||
} from "@radix-ui/react-icons";
|
||||
import { useState, type KeyboardEvent } from "react";
|
||||
import { tierListColors } from "../../config/tierList";
|
||||
import { useStrings } from "../../hooks/useStrings";
|
||||
import { TierList, type TierListRowState } from "../../stores/tierList";
|
||||
import { Button } from "../Button";
|
||||
import { Heading } from "../Heading";
|
||||
import { IconButton } from "../IconButton";
|
||||
import { Popover } from "../Popover";
|
||||
import { Table } from "../Table";
|
||||
import { TextField } from "../TextField";
|
||||
import styles from "./index.module.css";
|
||||
|
||||
interface TierListRowHeaderProps {
|
||||
index: number;
|
||||
row: TierListRowState;
|
||||
}
|
||||
|
||||
export function TierListRowHeader({ index, row }: TierListRowHeaderProps) {
|
||||
const strings = useStrings();
|
||||
const rowCount = TierList.useDeferred(
|
||||
(state) => state.rows.length,
|
||||
TierList.initial.rows.length,
|
||||
);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [name, setName] = useState(row.name);
|
||||
const [color, setColor] = useState(row.color);
|
||||
|
||||
function apply() {
|
||||
TierList.mutate((draft) => {
|
||||
draft.rows[index].name = name;
|
||||
draft.rows[index].color = color;
|
||||
});
|
||||
|
||||
setOpen(false);
|
||||
}
|
||||
|
||||
function remove() {
|
||||
TierList.mutate((draft) => {
|
||||
draft.rows.splice(index, 1);
|
||||
});
|
||||
|
||||
setOpen(false);
|
||||
}
|
||||
|
||||
function handleKeyDown(event: KeyboardEvent<HTMLDivElement>) {
|
||||
if (event.key === "Enter") apply();
|
||||
}
|
||||
|
||||
return (
|
||||
<Popover.Root
|
||||
open={open}
|
||||
onOpenChange={(open) => {
|
||||
if (open) {
|
||||
setName(row.name);
|
||||
setColor(row.color);
|
||||
}
|
||||
|
||||
setOpen(open);
|
||||
}}
|
||||
>
|
||||
<Popover.Trigger asChild>
|
||||
<Table.Cell className={styles.header} data-accent={row.color}>
|
||||
<div className={styles.content}>
|
||||
<Heading size="5" weight="bold">
|
||||
{row.name}
|
||||
</Heading>
|
||||
|
||||
<IconButton variant="solid" color="gray" highContrast size="minor">
|
||||
<Pencil2Icon />
|
||||
</IconButton>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
</Popover.Trigger>
|
||||
|
||||
<Popover.Portal>
|
||||
<Popover.Content>
|
||||
<Popover.Field label={strings.tier_list.edit.label}>
|
||||
<TextField
|
||||
autoFocus="always"
|
||||
placeholder={strings.tier_list.edit.placeholder}
|
||||
value={name}
|
||||
onChange={(event) =>
|
||||
setName((event.target as HTMLInputElement).value)
|
||||
}
|
||||
onKeyDown={handleKeyDown}
|
||||
/>
|
||||
</Popover.Field>
|
||||
|
||||
<Popover.Field label={strings.tier_list.edit.color}>
|
||||
<div className={styles.swatches}>
|
||||
{tierListColors.map((swatch) => (
|
||||
<IconButton
|
||||
key={swatch}
|
||||
color={swatch}
|
||||
size="minor"
|
||||
className={styles.swatch}
|
||||
data-selected={swatch === color}
|
||||
onClick={() => setColor(swatch)}
|
||||
>
|
||||
<CheckIcon />
|
||||
</IconButton>
|
||||
))}
|
||||
</div>
|
||||
</Popover.Field>
|
||||
|
||||
<Popover.Actions>
|
||||
<Popover.Close asChild>
|
||||
<Button variant="outline" color="red">
|
||||
<Cross1Icon />
|
||||
{strings.tier_list.edit.cancel}
|
||||
</Button>
|
||||
</Popover.Close>
|
||||
|
||||
<Button
|
||||
variant="soft"
|
||||
color="red"
|
||||
disabled={rowCount === 1}
|
||||
onClick={remove}
|
||||
>
|
||||
<TrashIcon />
|
||||
{strings.tier_list.edit.remove}
|
||||
</Button>
|
||||
|
||||
<Button onClick={apply}>
|
||||
<CheckIcon />
|
||||
{strings.tier_list.edit.apply}
|
||||
</Button>
|
||||
</Popover.Actions>
|
||||
</Popover.Content>
|
||||
</Popover.Portal>
|
||||
</Popover.Root>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user