Skip to content

Commit

Permalink
✨🚧Enhanced TextEditorPlugin
Browse files Browse the repository at this point in the history
Now colors of texts can be modified!
  • Loading branch information
carefree0910 committed May 18, 2023
1 parent 89e695e commit 010d7e5
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions cfdraw/.web/src/plugins/_react/TextEditorPlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import type { ColorChangeHandler } from "react-color";
import { useEffect, useMemo, useState } from "react";
import { observer } from "mobx-react-lite";
import { Flex, Textarea } from "@chakra-ui/react";

import { getRandomHash } from "@carefree0910/core";
import { langStore, translate, useEditText } from "@carefree0910/business";
import { langStore, selectingNodesStore, translate, useEditText } from "@carefree0910/business";

import type { IPlugin } from "@/schema/plugins";
import { NodeEditor_Words } from "@/lang/nodeEditor";
import CFSlider from "@/components/CFSlider";
import CFDivider from "@/components/CFDivider";
import CFHeading from "@/components/CFHeading";
import CFColorPicker from "@/components/CFColorPicker";
import { drawboardPluginFactory } from "../utils/factory";
import Render from "../components/Render";

Expand All @@ -18,33 +20,53 @@ const TextEditorPlugin = ({ pluginInfo: { node }, ...props }: IPlugin) => {
const lang = langStore.tgt;
const [content, setContent] = useState("");
const [fontSize, setFontSize] = useState(0);
const { editContent, editFontSize } = useEditText();

const textParams = selectingNodesStore.info.textParams;
const { editColor, editContent, editFontSize } = useEditText();
useEffect(() => {
if (node?.type === "text") {
setContent(node.params.content);
setFontSize(node.params.fontSize);
}
}, [node]);

if (node?.type !== "text") return null;
const onChange: ColorChangeHandler = (color) => {
editColor({ trace: false })(color.hex);
};
const onChangeComplete: ColorChangeHandler = (color) => {
console.log(">>> onChangeComplete");
editColor({ trace: true })(color.hex);
};

if (node?.type !== "text" || !textParams) return null;

return (
<Render id={id} {...props}>
<CFHeading>{translate(NodeEditor_Words["text-editor-plugin-header"], lang)}</CFHeading>
<CFDivider />
<Flex direction="column" w="100%" h="100%">
<CFSlider
min={12}
max={1024}
precision={0}
value={fontSize}
scale="logarithmic"
onSliderChange={(value) => {
setFontSize(value);
editFontSize({ trace: false })(value);
}}
onBlur={() => editFontSize({ trace: true })(fontSize)}
/>
<Flex w="100%">
<CFSlider
flex={1}
min={12}
max={1024}
precision={0}
value={fontSize}
scale="logarithmic"
onSliderChange={(value) => {
setFontSize(value);
editFontSize({ trace: false })(value);
}}
onBlur={() => editFontSize({ trace: true })(fontSize)}
/>
<CFColorPicker
color={textParams.color}
onChange={onChange}
onChangeComplete={onChangeComplete}
disableAlpha
thumbnailProps={{ ml: "12px" }}
/>
</Flex>
<CFDivider />
<Textarea
flex={1}
Expand Down

0 comments on commit 010d7e5

Please sign in to comment.