mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: copiers
This commit is contained in:
1 parent
1fcb60ab3f
commit
1359452f67
2 files changed
+80
-19
No files matched your search
@@ -1,9 +1,17 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { CopyIcon, ImageIcon } from '@radix-ui/react-icons';
|
import {
|
||||||
|
CodeIcon,
|
||||||
|
HeightIcon,
|
||||||
|
ImageIcon,
|
||||||
|
Link2Icon,
|
||||||
|
TimerIcon,
|
||||||
|
WidthIcon,
|
||||||
|
} from '@radix-ui/react-icons';
|
||||||
import { Box, Button, Flex, Heading, ScrollArea, Text } from '@radix-ui/themes';
|
import { Box, Button, Flex, Heading, ScrollArea, Text } from '@radix-ui/themes';
|
||||||
import { capitalize, startCase } from 'lodash';
|
import { capitalize, startCase } from 'lodash';
|
||||||
import { ReactNode, useEffect, useRef, useState } from 'react';
|
import { ReactNode, useEffect, useRef, useState } from 'react';
|
||||||
|
import { CopyButton } from '../../../../../components/CopyButton';
|
||||||
import { NAVBAR_HEIGHT } from '../../../../../components/Navbar';
|
import { NAVBAR_HEIGHT } from '../../../../../components/Navbar';
|
||||||
import PageWrapper from '../../../../../components/PageWrapper';
|
import PageWrapper from '../../../../../components/PageWrapper';
|
||||||
import { imgur } from '../../../../../core/blitzkit/imgur';
|
import { imgur } from '../../../../../core/blitzkit/imgur';
|
||||||
@@ -58,11 +66,11 @@ export default function Page({
|
|||||||
style={{ height: '100%', maxWidth: 320 }}
|
style={{ height: '100%', maxWidth: 320 }}
|
||||||
>
|
>
|
||||||
<Flex direction="column" gap="2" p="4">
|
<Flex direction="column" gap="2" p="4">
|
||||||
<Heading>Customize</Heading>
|
<Heading>Export</Heading>
|
||||||
|
|
||||||
<Flex mb="4" gap="2">
|
<Flex mb="6" gap="2" wrap="wrap">
|
||||||
<Button
|
<CopyButton
|
||||||
onClick={() => {
|
copy={() => {
|
||||||
const { wargaming } = appStore.getState().logins;
|
const { wargaming } = appStore.getState().logins;
|
||||||
|
|
||||||
if (!wargaming) return;
|
if (!wargaming) return;
|
||||||
@@ -82,27 +90,43 @@ export default function Page({
|
|||||||
state: JSON.stringify(shallowState),
|
state: JSON.stringify(shallowState),
|
||||||
});
|
});
|
||||||
|
|
||||||
navigator.clipboard.writeText(
|
return `${location.origin}/tools/embed/${params.embed}/host?${searchParams.toString()}`;
|
||||||
`${location.origin}/tools/embed/${params.embed}/host?${searchParams.toString()}`,
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CopyIcon />
|
<Link2Icon />
|
||||||
Copy URL
|
Copy URL
|
||||||
</Button>
|
</CopyButton>
|
||||||
<Button
|
<CopyButton
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => {
|
copy={() =>
|
||||||
navigator.clipboard.writeText(
|
'body { margin: 0; background-color: transparent; overflow: hidden; }'
|
||||||
'body { margin: 0; background-color: transparent; overflow: hidden; }',
|
}
|
||||||
);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<CopyIcon />
|
<CodeIcon />
|
||||||
Copy CSS
|
Copy CSS
|
||||||
</Button>
|
</CopyButton>
|
||||||
|
<CopyButton
|
||||||
|
variant="outline"
|
||||||
|
copy={() => `${embedStateStore.getState().width}`}
|
||||||
|
>
|
||||||
|
<WidthIcon />
|
||||||
|
Copy width
|
||||||
|
</CopyButton>
|
||||||
|
<CopyButton
|
||||||
|
variant="outline"
|
||||||
|
copy={() => `${embedStateStore.getState().height}`}
|
||||||
|
>
|
||||||
|
<HeightIcon />
|
||||||
|
Copy height
|
||||||
|
</CopyButton>
|
||||||
|
<CopyButton variant="outline" copy={() => '`'}>
|
||||||
|
<TimerIcon />
|
||||||
|
Copy framerate
|
||||||
|
</CopyButton>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
|
<Heading>Customize</Heading>
|
||||||
|
|
||||||
{Object.keys(config).map((configKey) => {
|
{Object.keys(config).map((configKey) => {
|
||||||
const item = config[configKey];
|
const item = config[configKey];
|
||||||
let control: ReactNode;
|
let control: ReactNode;
|
||||||
@@ -122,21 +146,25 @@ export default function Page({
|
|||||||
|
|
||||||
case EmbedItemType.Radius: {
|
case EmbedItemType.Radius: {
|
||||||
control = <Radius configKey={configKey} />;
|
control = <Radius configKey={configKey} />;
|
||||||
|
oneLiner = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EmbedItemType.Size: {
|
case EmbedItemType.Size: {
|
||||||
control = <Size configKey={configKey} />;
|
control = <Size configKey={configKey} />;
|
||||||
|
oneLiner = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EmbedItemType.SizeWithout0: {
|
case EmbedItemType.SizeWithout0: {
|
||||||
control = <SizeWithout0 configKey={configKey} />;
|
control = <SizeWithout0 configKey={configKey} />;
|
||||||
|
oneLiner = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EmbedItemType.Slider: {
|
case EmbedItemType.Slider: {
|
||||||
control = <Slider configKey={configKey} config={item} />;
|
control = <Slider configKey={configKey} config={item} />;
|
||||||
|
oneLiner = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +180,7 @@ export default function Page({
|
|||||||
|
|
||||||
case EmbedItemType.Enum: {
|
case EmbedItemType.Enum: {
|
||||||
control = <Enum configKey={configKey} config={item} />;
|
control = <Enum configKey={configKey} config={item} />;
|
||||||
|
oneLiner = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +194,12 @@ export default function Page({
|
|||||||
pb={item.pad ? '6' : undefined}
|
pb={item.pad ? '6' : undefined}
|
||||||
>
|
>
|
||||||
<Text>{capitalize(startCase(configKey as string))}</Text>
|
<Text>{capitalize(startCase(configKey as string))}</Text>
|
||||||
<Flex gap="2" align="center">
|
<Flex
|
||||||
|
gap="2"
|
||||||
|
align="center"
|
||||||
|
flexGrow="1"
|
||||||
|
justify={oneLiner ? 'end' : undefined}
|
||||||
|
>
|
||||||
{control}
|
{control}
|
||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { Button, ButtonProps, Tooltip } from '@radix-ui/themes';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
interface CopyButtonProps extends ButtonProps {
|
||||||
|
copy: () => string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CopyButton({ copy, ...props }: CopyButtonProps) {
|
||||||
|
const [tooltipOpen, setTooltipOpen] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip open={tooltipOpen} content="Copied!">
|
||||||
|
<Button
|
||||||
|
{...props}
|
||||||
|
onClick={() => {
|
||||||
|
const content = copy();
|
||||||
|
|
||||||
|
if (content === undefined) return;
|
||||||
|
|
||||||
|
navigator.clipboard.writeText(content);
|
||||||
|
setTooltipOpen(true);
|
||||||
|
setTimeout(() => setTooltipOpen(false), 2000);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user