mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 14:27:02 +08:00
feat: add default title when pendant type change, resolved #616
This commit is contained in:
@@ -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 { Input, Option, Select, Tooltip } from '@toeverything/components/ui';
|
||||||
import { HelpCenterIcon } from '@toeverything/components/icons';
|
import { HelpCenterIcon } from '@toeverything/components/icons';
|
||||||
import { AsyncBlock } from '../../editor';
|
import { AsyncBlock } from '../../editor';
|
||||||
@@ -28,6 +29,9 @@ import {
|
|||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { usePendant } from '../use-pendant';
|
import { usePendant } from '../use-pendant';
|
||||||
|
|
||||||
|
const upperFirst = (str: string) => {
|
||||||
|
return `${str[0].toUpperCase()}${str.slice(1)}`;
|
||||||
|
};
|
||||||
export const CreatePendantPanel = ({
|
export const CreatePendantPanel = ({
|
||||||
block,
|
block,
|
||||||
onSure,
|
onSure,
|
||||||
@@ -38,10 +42,13 @@ export const CreatePendantPanel = ({
|
|||||||
const [selectedOption, setSelectedOption] = useState<PendantOptions>();
|
const [selectedOption, setSelectedOption] = useState<PendantOptions>();
|
||||||
const [fieldName, setFieldName] = useState<string>('');
|
const [fieldName, setFieldName] = useState<string>('');
|
||||||
const { addProperty, removeProperty } = useRecastBlockMeta();
|
const { addProperty, removeProperty } = useRecastBlockMeta();
|
||||||
// const { getValue, setValue, getAllValue } = getRecastItemValue(block);
|
|
||||||
const { createSelect } = useSelectProperty();
|
const { createSelect } = useSelectProperty();
|
||||||
const { setPendant } = usePendant(block);
|
const { setPendant } = usePendant(block);
|
||||||
const recastBlock = useRecastBlock();
|
|
||||||
|
useEffect(() => {
|
||||||
|
selectedOption &&
|
||||||
|
setFieldName(upperFirst(`${selectedOption.type}#${nanoid(4)}`));
|
||||||
|
}, [selectedOption]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledPopoverWrapper>
|
<StyledPopoverWrapper>
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ export const PendantRender = ({ block }: { block: AsyncBlock }) => {
|
|||||||
block={block}
|
block={block}
|
||||||
iconStyle={{ marginTop: 4 }}
|
iconStyle={{ marginTop: 4 }}
|
||||||
container={blockRenderContainerRef.current}
|
container={blockRenderContainerRef.current}
|
||||||
|
trigger="click"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</MuiZoom>
|
</MuiZoom>
|
||||||
|
|||||||
Reference in New Issue
Block a user