feat: add default title when pendant type change, resolved #616

This commit is contained in:
qishaoxuan
2022-07-29 11:05:54 +08:00
parent 56998d07a1
commit 36d8c0493d
2 changed files with 11 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import React, { CSSProperties, useState } from 'react';
import React, { CSSProperties, useState, useEffect } from 'react';
import { nanoid } from 'nanoid';
import { Input, Option, Select, Tooltip } from '@toeverything/components/ui';
import { HelpCenterIcon } from '@toeverything/components/icons';
import { AsyncBlock } from '../../editor';
@@ -28,6 +29,9 @@ import {
} from '../utils';
import { usePendant } from '../use-pendant';
const upperFirst = (str: string) => {
return `${str[0].toUpperCase()}${str.slice(1)}`;
};
export const CreatePendantPanel = ({
block,
onSure,
@@ -38,10 +42,13 @@ export const CreatePendantPanel = ({
const [selectedOption, setSelectedOption] = useState<PendantOptions>();
const [fieldName, setFieldName] = useState<string>('');
const { addProperty, removeProperty } = useRecastBlockMeta();
// const { getValue, setValue, getAllValue } = getRecastItemValue(block);
const { createSelect } = useSelectProperty();
const { setPendant } = usePendant(block);
const recastBlock = useRecastBlock();
useEffect(() => {
selectedOption &&
setFieldName(upperFirst(`${selectedOption.type}#${nanoid(4)}`));
}, [selectedOption]);
return (
<StyledPopoverWrapper>

View File

@@ -106,6 +106,7 @@ export const PendantRender = ({ block }: { block: AsyncBlock }) => {
block={block}
iconStyle={{ marginTop: 4 }}
container={blockRenderContainerRef.current}
trigger="click"
/>
</div>
</MuiZoom>