mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 19:19:52 +02:00
feat: float
This commit is contained in:
1 parent
6984794be1
commit
6a18abf17f
6 files changed
+550
-135
No files matched your search
@@ -1,14 +1,37 @@
|
||||
import { Flex, Select, Text, TextField } from '@radix-ui/themes';
|
||||
import * as radixColors from '@radix-ui/colors';
|
||||
import { DragHandleDots2Icon } from '@radix-ui/react-icons';
|
||||
import {
|
||||
Box,
|
||||
Card,
|
||||
Flex,
|
||||
ScrollArea,
|
||||
Select,
|
||||
Text,
|
||||
TextField,
|
||||
} from '@radix-ui/themes';
|
||||
import { produce } from 'immer';
|
||||
import { capitalize, startCase, times } from 'lodash';
|
||||
import { Dispatch, SetStateAction, useCallback } from 'react';
|
||||
import {
|
||||
Dispatch,
|
||||
ReactNode,
|
||||
SetStateAction,
|
||||
useCallback,
|
||||
useRef,
|
||||
} from 'react';
|
||||
import {
|
||||
EmbedConfig,
|
||||
EmbedConfigType,
|
||||
ExtractEmbedConfigType,
|
||||
RadixColor,
|
||||
RadixColorBase,
|
||||
RadixColorVariant,
|
||||
RadixColorVariantRaw,
|
||||
radixGrays,
|
||||
RadixRadius,
|
||||
RadixSize,
|
||||
RadixTextColor,
|
||||
} from '../app/tools/embed/types';
|
||||
import { toColorVar, toRadiusVar } from '../app/tools/embed/utilities';
|
||||
|
||||
interface EmbedConfigInputsProps {
|
||||
config: EmbedConfig;
|
||||
@@ -27,89 +50,354 @@ export function EmbedConfigInputs({
|
||||
},
|
||||
[],
|
||||
);
|
||||
const wrapper = useRef<HTMLDivElement>(null);
|
||||
const handlePointerMove = useCallback((event: PointerEvent) => {
|
||||
event.preventDefault();
|
||||
|
||||
if (!wrapper.current) return;
|
||||
|
||||
wrapper.current.style.top = `${parseFloat(wrapper.current.style.top) + event.movementY}px`;
|
||||
wrapper.current.style.right = `${parseFloat(wrapper.current.style.right) - event.movementX}px`;
|
||||
}, []);
|
||||
|
||||
const handlePointerUp = useCallback((event: PointerEvent) => {
|
||||
window.removeEventListener('pointermove', handlePointerMove);
|
||||
window.removeEventListener('pointerup', handlePointerUp);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Flex direction="column" gap="2" align="end">
|
||||
{Object.entries(config).map(([key, setting]) => {
|
||||
const name = capitalize(startCase(key));
|
||||
<Card
|
||||
style={{ position: 'fixed', top: 0, right: 0, minWidth: 320 }}
|
||||
ref={wrapper}
|
||||
>
|
||||
<Flex
|
||||
align="center"
|
||||
justify="center"
|
||||
p="2"
|
||||
mb="2"
|
||||
style={{
|
||||
backgroundColor: 'var(--color-panel-translucent)',
|
||||
borderRadius: 'var(--radius-2)',
|
||||
cursor: 'grab',
|
||||
}}
|
||||
onPointerDown={(event) => {
|
||||
window.addEventListener('pointermove', handlePointerMove);
|
||||
window.addEventListener('pointerup', handlePointerUp);
|
||||
}}
|
||||
>
|
||||
<DragHandleDots2Icon style={{ transform: 'rotate(90deg)' }} />
|
||||
</Flex>
|
||||
|
||||
switch (setting.type) {
|
||||
case EmbedConfigType.Number: {
|
||||
return (
|
||||
<Flex align="center" gap="2">
|
||||
<Text>{name}</Text>
|
||||
<TextField.Root
|
||||
style={{ width: 96 }}
|
||||
type="number"
|
||||
value={state[key]}
|
||||
onChange={(event) => {
|
||||
mutateState((draft) => {
|
||||
draft[key] = (
|
||||
event.target as HTMLInputElement
|
||||
).valueAsNumber;
|
||||
});
|
||||
}}
|
||||
>
|
||||
{setting.unit && (
|
||||
<TextField.Slot side="right">px</TextField.Slot>
|
||||
)}
|
||||
</TextField.Root>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
<ScrollArea
|
||||
scrollbars="vertical"
|
||||
style={{ height: '100%', maxHeight: 640 }}
|
||||
>
|
||||
<Flex direction="column" gap="2">
|
||||
{Object.entries(config).map(([key, setting]) => {
|
||||
let control: ReactNode;
|
||||
|
||||
case EmbedConfigType.Size: {
|
||||
return (
|
||||
<Flex align="center" gap="2">
|
||||
<Text>{name}</Text>
|
||||
<Select.Root
|
||||
value={state[key] as RadixSize}
|
||||
onValueChange={(value) => {
|
||||
mutateState((draft) => {
|
||||
draft[key] = value as RadixSize;
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Select.Trigger />
|
||||
<Select.Content>
|
||||
{times(10, (index) => (
|
||||
<Select.Item key={index} value={`${index}`}>
|
||||
{index}
|
||||
switch (setting.type) {
|
||||
case EmbedConfigType.Number: {
|
||||
control = (
|
||||
<TextField.Root
|
||||
size="1"
|
||||
style={{ width: 64 }}
|
||||
type="number"
|
||||
value={state[key] as number}
|
||||
onChange={(event) => {
|
||||
mutateState((draft) => {
|
||||
draft[key] = (
|
||||
event.target as HTMLInputElement
|
||||
).valueAsNumber;
|
||||
});
|
||||
}}
|
||||
>
|
||||
{setting.unit && (
|
||||
<TextField.Slot side="right">px</TextField.Slot>
|
||||
)}
|
||||
</TextField.Root>
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case EmbedConfigType.String: {
|
||||
control = (
|
||||
<TextField.Root
|
||||
placeholder="Empty"
|
||||
size="1"
|
||||
style={{ width: 64 }}
|
||||
value={state[key] as string}
|
||||
onChange={(event) => {
|
||||
mutateState((draft) => {
|
||||
draft[key] = (event.target as HTMLInputElement).value;
|
||||
});
|
||||
}}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case EmbedConfigType.SizeNo0:
|
||||
case EmbedConfigType.Size: {
|
||||
control = (
|
||||
<Select.Root
|
||||
size="1"
|
||||
value={state[key] as RadixSize}
|
||||
onValueChange={(value) => {
|
||||
mutateState((draft) => {
|
||||
draft[key] = value as RadixSize;
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Select.Trigger />
|
||||
<Select.Content>
|
||||
{times(10, (index) =>
|
||||
setting.type === EmbedConfigType.SizeNo0 &&
|
||||
index === 0 ? null : (
|
||||
<Select.Item key={index} value={`${index}`}>
|
||||
{index}
|
||||
</Select.Item>
|
||||
),
|
||||
)}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case EmbedConfigType.Radius: {
|
||||
control = (
|
||||
<Select.Root
|
||||
size="1"
|
||||
value={state[key] as RadixRadius}
|
||||
onValueChange={(value) => {
|
||||
mutateState((draft) => {
|
||||
draft[key] = value as RadixRadius;
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Select.Trigger />
|
||||
<Select.Content>
|
||||
{times(5, (index) => (
|
||||
<Select.Item key={index} value={`${index}`}>
|
||||
{index}
|
||||
</Select.Item>
|
||||
))}
|
||||
<Select.Item value="full">Full</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case EmbedConfigType.Color: {
|
||||
control = (
|
||||
<>
|
||||
<Select.Root
|
||||
size="1"
|
||||
value={(state[key] as RadixColor).base}
|
||||
onValueChange={(value) => {
|
||||
mutateState((draft) => {
|
||||
(draft[key] as RadixColor).base =
|
||||
value as RadixColorBase;
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Select.Trigger />
|
||||
<Select.Content>
|
||||
{Object.entries(radixColors)
|
||||
.filter(
|
||||
([key]) =>
|
||||
!key.endsWith('A') &&
|
||||
!key.endsWith('P3') &&
|
||||
!key.endsWith('Dark'),
|
||||
)
|
||||
.map(([key]) => (
|
||||
<Select.Item key={key} value={key}>
|
||||
<Box
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: '1em',
|
||||
height: '1em',
|
||||
verticalAlign: 'text-top',
|
||||
borderRadius: toRadiusVar('full'),
|
||||
backgroundColor: toColorVar({
|
||||
base: key as RadixColorBase,
|
||||
variant: '9',
|
||||
}),
|
||||
}}
|
||||
/>{' '}
|
||||
{capitalize(key)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
|
||||
<Select.Root
|
||||
size="1"
|
||||
value={(state[key] as RadixColor).variant}
|
||||
onValueChange={(value) => {
|
||||
mutateState((draft) => {
|
||||
(draft[key] as RadixColor).variant =
|
||||
value as RadixColorVariant;
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Select.Trigger />
|
||||
<Select.Content>
|
||||
{times(12, (index) => {
|
||||
const variant =
|
||||
`${index + 1}` as RadixColorVariantRaw;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Select.Item key={key} value={variant}>
|
||||
<Box
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: '1em',
|
||||
height: '1em',
|
||||
verticalAlign: 'text-top',
|
||||
borderRadius: toRadiusVar('full'),
|
||||
backgroundColor: toColorVar({
|
||||
base: (state[key] as RadixColor).base,
|
||||
variant,
|
||||
}),
|
||||
}}
|
||||
/>{' '}
|
||||
{variant}
|
||||
</Select.Item>
|
||||
<Select.Item key={key} value={`a${variant}`}>
|
||||
<Box
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
overflow: 'hidden',
|
||||
width: '1em',
|
||||
height: '1em',
|
||||
verticalAlign: 'text-top',
|
||||
borderRadius: toRadiusVar('full'),
|
||||
backgroundColor: toColorVar({
|
||||
base: (state[key] as RadixColor).base,
|
||||
variant: `a${variant}`,
|
||||
}),
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
style={{
|
||||
width: '50%',
|
||||
height: '100%',
|
||||
backgroundColor: toColorVar({
|
||||
base: (state[key] as RadixColor).base,
|
||||
variant,
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
</Box>{' '}
|
||||
{variant} translucent
|
||||
</Select.Item>
|
||||
</>
|
||||
);
|
||||
})}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</>
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case EmbedConfigType.TextColor: {
|
||||
control = (
|
||||
<Select.Root
|
||||
size="1"
|
||||
value={`${state[key]}`}
|
||||
onValueChange={(value) => {
|
||||
mutateState((draft) => {
|
||||
draft[key] = value as RadixTextColor;
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Select.Trigger />
|
||||
<Select.Content>
|
||||
<Select.Item value="undefined">
|
||||
<Box
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: '1em',
|
||||
height: '1em',
|
||||
verticalAlign: 'text-top',
|
||||
borderRadius: toRadiusVar('full'),
|
||||
backgroundColor: 'white',
|
||||
}}
|
||||
/>{' '}
|
||||
White
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
|
||||
case EmbedConfigType.Radius: {
|
||||
return (
|
||||
<Flex align="center" gap="2">
|
||||
<Text>Card radius</Text>
|
||||
<Select.Root
|
||||
value={state[key] as RadixRadius}
|
||||
onValueChange={(value) => {
|
||||
mutateState((draft) => {
|
||||
draft[key] = value as RadixRadius;
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Select.Trigger />
|
||||
<Select.Content>
|
||||
{times(5, (index) => (
|
||||
<Select.Item key={index} value={`${index}`}>
|
||||
{index}
|
||||
<Select.Item value="gray">
|
||||
<Box
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: '1em',
|
||||
height: '1em',
|
||||
verticalAlign: 'text-top',
|
||||
borderRadius: toRadiusVar('full'),
|
||||
backgroundColor: 'gray',
|
||||
}}
|
||||
/>{' '}
|
||||
Gray
|
||||
</Select.Item>
|
||||
))}
|
||||
<Select.Item value="full">Full</Select.Item>
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
{Object.entries(radixColors)
|
||||
.filter(
|
||||
([key]) =>
|
||||
!key.endsWith('A') &&
|
||||
!key.endsWith('P3') &&
|
||||
!key.endsWith('Dark') &&
|
||||
!radixGrays.includes(key),
|
||||
)
|
||||
.map(([key]) => (
|
||||
<Select.Item key={key} value={key}>
|
||||
<Box
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
width: '1em',
|
||||
height: '1em',
|
||||
verticalAlign: 'text-top',
|
||||
borderRadius: toRadiusVar('full'),
|
||||
backgroundColor: toColorVar({
|
||||
base: key as RadixColorBase,
|
||||
variant: '9',
|
||||
}),
|
||||
}}
|
||||
/>{' '}
|
||||
{capitalize(key)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Flex
|
||||
direction="column"
|
||||
gap="1"
|
||||
mb="1"
|
||||
pb={setting.pad ? '6' : undefined}
|
||||
>
|
||||
<Text color="gray" size="2">
|
||||
{capitalize(startCase(key))}
|
||||
</Text>
|
||||
{control && <Flex gap="1">{control}</Flex>}
|
||||
{!control && (
|
||||
<Text color="red" size="1">
|
||||
Immutable
|
||||
</Text>
|
||||
)}
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
}
|
||||
})}
|
||||
</Flex>
|
||||
})}
|
||||
</Flex>
|
||||
</ScrollArea>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,12 @@
|
||||
import { Flex } from '@radix-ui/themes';
|
||||
import { Flex, Text } from '@radix-ui/themes';
|
||||
import { times } from 'lodash';
|
||||
import { ReactNode } from 'react';
|
||||
import { TanksEmbedState } from '../app/tools/embed/customize/tanks/page';
|
||||
import {
|
||||
toColorVar,
|
||||
toRadiusVar,
|
||||
toWidthVar,
|
||||
} from '../app/tools/embed/utilities';
|
||||
import { TankDefinition } from '../core/blitzkit/tankDefinitions';
|
||||
|
||||
interface TanksEmbedWrapperProps {
|
||||
@@ -10,7 +16,11 @@ interface TanksEmbedWrapperProps {
|
||||
|
||||
export function TanksEmbedWrapper({ children, state }: TanksEmbedWrapperProps) {
|
||||
return (
|
||||
<Flex direction="column" gap={state.listGap} width={`${state.listWidth}px`}>
|
||||
<Flex
|
||||
direction="column"
|
||||
gap={state.listGap}
|
||||
width={toWidthVar(state.listWidth)}
|
||||
>
|
||||
{children}
|
||||
</Flex>
|
||||
);
|
||||
@@ -26,21 +36,42 @@ export function TanksEmbedCard({ tank, state }: TanksEmbedCardProps) {
|
||||
<Flex
|
||||
direction="column"
|
||||
style={{
|
||||
borderRadius: `var(--radius-${state.cardRadius})`,
|
||||
borderRadius: toRadiusVar(state.cardRadius),
|
||||
overflow: 'hidden',
|
||||
backgroundColor: 'var(--color-panel-solid)',
|
||||
backgroundColor: toColorVar(state.cardBodyBackgroundColor),
|
||||
}}
|
||||
>
|
||||
<Flex
|
||||
justify="center"
|
||||
style={{
|
||||
backgroundColor: 'var(--color-panel-translucent)',
|
||||
backgroundColor: toColorVar(state.cardHeaderBackgroundColor),
|
||||
}}
|
||||
p={state.cardHeaderPadding}
|
||||
>
|
||||
{tank.name}
|
||||
</Flex>
|
||||
<Flex>asd</Flex>
|
||||
|
||||
<Flex p={state.cardBodyPadding}>
|
||||
{times(4, (index) => {
|
||||
const column = (index + 1) as 1 | 2 | 3 | 4;
|
||||
|
||||
return (
|
||||
<Flex
|
||||
direction="column"
|
||||
align="center"
|
||||
gap={state.columnGap}
|
||||
flexGrow="1"
|
||||
>
|
||||
<Text size={state.columnValueSize} color={state.columnValueColor}>
|
||||
70{state[`column${column}Unit`]}
|
||||
</Text>
|
||||
<Text size={state.columnLabelSize} color={state.columnLabelColor}>
|
||||
{state[`column${column}Label`]}
|
||||
</Text>
|
||||
</Flex>
|
||||
);
|
||||
})}
|
||||
</Flex>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user