Files
blitzkit/packages/website/src/components/Embeds/RichText.tsx
T

78 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-09-02 16:24:13 -05:00
import { FontBoldIcon, FontSizeIcon } from "@radix-ui/react-icons";
import { Flex, Slider, Text } from "@radix-ui/themes";
import type { EmbedPreviewControllerProps } from "../../pages/[...locale]/embed/[embed]/_index";
import { EmbedState, type RadixSizeWithout0 } from "../../stores/embedState";
2024-10-26 14:59:52 -05:00
import {
radixTextWeights,
type EmbedConfigItemType,
type EmbedItemType,
2025-09-02 16:24:13 -05:00
} from "../../stores/embedState/constants";
import { ColorControllerRaw } from "./ColorControllerRaw";
2024-10-26 14:33:04 -05:00
export function RichText({ configKey }: EmbedPreviewControllerProps) {
const state = EmbedState.use(
(state) =>
2025-09-02 16:24:13 -05:00
state[configKey] as EmbedConfigItemType<EmbedItemType.RichText>["default"]
2024-10-26 14:33:04 -05:00
);
return (
2024-10-26 14:59:52 -05:00
<Flex direction="column" flexGrow="1" gap="2">
<Flex gap="2" align="center">
<ColorControllerRaw
value={state.color}
onValueChange={(value) => {
2025-09-02 16:24:13 -05:00
EmbedState.mutate((draft) => {
2024-10-26 14:59:52 -05:00
(
draft[
configKey
2025-09-02 16:24:13 -05:00
] as EmbedConfigItemType<EmbedItemType.RichText>["default"]
2024-10-26 14:59:52 -05:00
).color = value;
});
}}
/>
</Flex>
<Flex align="center" gap="2" py="2">
<Text size="4" trim="both">
<FontSizeIcon width="1em" height="1em" />
</Text>
<Slider
2025-04-21 17:01:32 -05:00
variant="classic"
2024-10-26 14:59:52 -05:00
min={1}
max={9}
value={[Number(state.size)]}
onValueChange={([value]) => {
2025-09-02 16:24:13 -05:00
EmbedState.mutate((draft) => {
2024-10-26 14:59:52 -05:00
(
draft[
configKey
2025-09-02 16:24:13 -05:00
] as EmbedConfigItemType<EmbedItemType.RichText>["default"]
2024-10-26 14:59:52 -05:00
).size = `${value}` as RadixSizeWithout0;
});
}}
/>
</Flex>
<Flex align="center" gap="2" py="2">
<Text size="4" trim="both">
<FontBoldIcon width="1em" height="1em" />
</Text>
<Slider
2025-04-21 17:01:32 -05:00
variant="classic"
2024-10-26 14:59:52 -05:00
min={0}
max={radixTextWeights.length - 1}
value={[radixTextWeights.indexOf(state.weight)]}
onValueChange={([value]) => {
2025-09-02 16:24:13 -05:00
EmbedState.mutate((draft) => {
2024-10-26 14:59:52 -05:00
(
draft[
configKey
2025-09-02 16:24:13 -05:00
] as EmbedConfigItemType<EmbedItemType.RichText>["default"]
2024-10-26 14:59:52 -05:00
).weight = radixTextWeights[value];
});
}}
/>
</Flex>
</Flex>
2024-10-26 14:33:04 -05:00
);
}