mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: custom titles
This commit is contained in:
1 parent
ef8f0fd72d
commit
c6779a714b
1 file changed
+106
-58
@@ -1,6 +1,14 @@
|
|||||||
import { ContextMenu, DropdownMenu, Flex } from '@radix-ui/themes';
|
import {
|
||||||
|
Button,
|
||||||
|
ContextMenu,
|
||||||
|
Dialog,
|
||||||
|
DropdownMenu,
|
||||||
|
Flex,
|
||||||
|
Heading,
|
||||||
|
TextField,
|
||||||
|
} from '@radix-ui/themes';
|
||||||
import { createColors } from 'bepaint';
|
import { createColors } from 'bepaint';
|
||||||
import { useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
ACCENT_COLORS,
|
ACCENT_COLORS,
|
||||||
AccentColor,
|
AccentColor,
|
||||||
@@ -19,70 +27,110 @@ interface ContextMenuProps {
|
|||||||
export function Menu({ Builder, reset }: ContextMenuProps) {
|
export function Menu({ Builder, reset }: ContextMenuProps) {
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
const [showTitleEditor, setShowTitleEditor] = useState(false);
|
const [showTitleEditor, setShowTitleEditor] = useState(false);
|
||||||
|
const titleInput = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Builder.Content>
|
<>
|
||||||
<Builder.Sub>
|
<Dialog.Root open={showTitleEditor} onOpenChange={setShowTitleEditor}>
|
||||||
<Builder.SubTrigger>Accent color</Builder.SubTrigger>
|
<Dialog.Content>
|
||||||
|
<Flex direction="column" gap="4">
|
||||||
|
<Heading size="4">Edit title</Heading>
|
||||||
|
|
||||||
<Builder.SubContent>
|
<Flex gap="2" style={{ width: '100%' }}>
|
||||||
<Builder.RadioGroup
|
<TextField.Root style={{ flex: 1 }}>
|
||||||
value={session.color}
|
<TextField.Input
|
||||||
onValueChange={(value) =>
|
ref={titleInput}
|
||||||
useSession.setState({ color: value as AccentColor | GrayColor })
|
defaultValue={session.title}
|
||||||
}
|
placeholder="Enter title..."
|
||||||
>
|
onKeyDown={(event) => {
|
||||||
{[...ACCENT_COLORS, ...GRAY_COLORS].map((color) => (
|
if (event.key === 'Enter' && titleInput.current) {
|
||||||
<Builder.RadioItem value={color} key={color}>
|
setShowTitleEditor(false);
|
||||||
<Flex gap="2" align="center">
|
useSession.setState({ title: titleInput.current!.value });
|
||||||
<div
|
}
|
||||||
style={{
|
}}
|
||||||
backgroundColor: createColors(PALETTES[color])
|
/>
|
||||||
.solidBackground,
|
</TextField.Root>
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
borderRadius: '100%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{`${color.charAt(0).toUpperCase()}${color.slice(1)}`}
|
|
||||||
</Flex>
|
|
||||||
</Builder.RadioItem>
|
|
||||||
))}
|
|
||||||
</Builder.RadioGroup>
|
|
||||||
</Builder.SubContent>
|
|
||||||
</Builder.Sub>
|
|
||||||
|
|
||||||
<Builder.Separator />
|
<Dialog.Close>
|
||||||
|
<Button
|
||||||
|
onClick={() =>
|
||||||
|
useSession.setState({ title: titleInput.current!.value })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Set
|
||||||
|
</Button>
|
||||||
|
</Dialog.Close>
|
||||||
|
</Flex>
|
||||||
|
</Flex>
|
||||||
|
</Dialog.Content>
|
||||||
|
</Dialog.Root>
|
||||||
|
|
||||||
<CustomColumn Builder={Builder} column={0} />
|
<Builder.Content>
|
||||||
<CustomColumn Builder={Builder} column={1} />
|
<Builder.Sub>
|
||||||
<CustomColumn Builder={Builder} column={2} />
|
<Builder.SubTrigger>Accent color</Builder.SubTrigger>
|
||||||
<CustomColumn Builder={Builder} column={3} />
|
|
||||||
|
|
||||||
<Builder.Separator />
|
<Builder.SubContent>
|
||||||
|
<Builder.RadioGroup
|
||||||
|
value={session.color}
|
||||||
|
onValueChange={(value) =>
|
||||||
|
useSession.setState({ color: value as AccentColor | GrayColor })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{[...ACCENT_COLORS, ...GRAY_COLORS].map((color) => (
|
||||||
|
<Builder.RadioItem value={color} key={color}>
|
||||||
|
<Flex gap="2" align="center">
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
backgroundColor: createColors(PALETTES[color])
|
||||||
|
.solidBackground,
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
borderRadius: '100%',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{`${color.charAt(0).toUpperCase()}${color.slice(1)}`}
|
||||||
|
</Flex>
|
||||||
|
</Builder.RadioItem>
|
||||||
|
))}
|
||||||
|
</Builder.RadioGroup>
|
||||||
|
</Builder.SubContent>
|
||||||
|
</Builder.Sub>
|
||||||
|
|
||||||
<Builder.CheckboxItem
|
<Builder.Separator />
|
||||||
checked={session.showTotal}
|
|
||||||
onCheckedChange={(checked) =>
|
|
||||||
useSession.setState({ showTotal: checked })
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Show total
|
|
||||||
</Builder.CheckboxItem>
|
|
||||||
<Builder.CheckboxItem
|
|
||||||
checked={session.showCareer}
|
|
||||||
onCheckedChange={(checked) =>
|
|
||||||
useSession.setState({ showCareer: checked })
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Show career
|
|
||||||
</Builder.CheckboxItem>
|
|
||||||
|
|
||||||
<Builder.Separator />
|
<Builder.Item onClick={() => setShowTitleEditor(true)}>
|
||||||
|
Edit title...
|
||||||
|
</Builder.Item>
|
||||||
|
<CustomColumn Builder={Builder} column={0} />
|
||||||
|
<CustomColumn Builder={Builder} column={1} />
|
||||||
|
<CustomColumn Builder={Builder} column={2} />
|
||||||
|
<CustomColumn Builder={Builder} column={3} />
|
||||||
|
|
||||||
<Builder.Item color="red" onClick={reset}>
|
<Builder.Separator />
|
||||||
Reset
|
|
||||||
</Builder.Item>
|
<Builder.CheckboxItem
|
||||||
</Builder.Content>
|
checked={session.showTotal}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
useSession.setState({ showTotal: checked })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Show total
|
||||||
|
</Builder.CheckboxItem>
|
||||||
|
<Builder.CheckboxItem
|
||||||
|
checked={session.showCareer}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
useSession.setState({ showCareer: checked })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Show career
|
||||||
|
</Builder.CheckboxItem>
|
||||||
|
|
||||||
|
<Builder.Separator />
|
||||||
|
|
||||||
|
<Builder.Item color="red" onClick={reset}>
|
||||||
|
Reset
|
||||||
|
</Builder.Item>
|
||||||
|
</Builder.Content>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user