diff --git a/packages/client/src/collection-manager/CollectionField.tsx b/packages/client/src/collection-manager/CollectionField.tsx index faa745c06..1ca072f76 100644 --- a/packages/client/src/collection-manager/CollectionField.tsx +++ b/packages/client/src/collection-manager/CollectionField.tsx @@ -10,7 +10,7 @@ import { useCollectionField } from './hooks'; const InternalField: React.FC = (props) => { const field = useField(); const fieldSchema = useFieldSchema(); - const { uiSchema } = useCollectionField(); + const { name, uiSchema } = useCollectionField(); const component = useComponent(uiSchema?.['x-component']); const compile = useCompile(); const setFieldProps = (key, value) => { @@ -34,9 +34,10 @@ const InternalField: React.FC = (props) => { setRequired(); // @ts-ignore field.dataSource = uiSchema.enum; - const originalProps = compile(uiSchema['x-component-props']); - const componentProps = field.componentProps; - field.component = [component, merge(originalProps, componentProps)]; + const originalProps = compile(uiSchema['x-component-props']) || {}; + const componentProps = merge(originalProps, field.componentProps || {}); + field.component = [component, componentProps]; + // console.log('componentProps', uiSchema?.title, field.componentProps); }, [uiSchema?.title, uiSchema?.description, uiSchema?.required]); if (!uiSchema) { return null; diff --git a/packages/client/src/schema-component/antd/input/EllipsisWithTooltip.tsx b/packages/client/src/schema-component/antd/input/EllipsisWithTooltip.tsx new file mode 100644 index 000000000..8a8ad6144 --- /dev/null +++ b/packages/client/src/schema-component/antd/input/EllipsisWithTooltip.tsx @@ -0,0 +1,40 @@ +import { Popover } from 'antd'; +import React, { CSSProperties, useState } from 'react'; + +const ellipsisDefaultStyle: CSSProperties = { + overflow: 'hidden', + overflowWrap: 'break-word', + textOverflow: 'ellipsis', + whiteSpace: 'nowrap', + wordBreak: 'break-all', +}; + +export const EllipsisWithTooltip = (props) => { + const [ellipsis, setEllipsis] = useState(false); + const [visible, setVisible] = useState(false); + if (!props.ellipsis) { + return <>{props.children}; + } + return ( + { + setVisible(ellipsis && visible); + }} + content={props.children} + overlayStyle={{ + width: 300, + }} + > +
{ + const el = e.target as any; + setEllipsis(el.scrollWidth > el.clientWidth); + }} + > + {props.children} +
+
+ ); +}; diff --git a/packages/client/src/schema-component/antd/input/ReadPretty.tsx b/packages/client/src/schema-component/antd/input/ReadPretty.tsx index 0ba4a87f4..3ccd356dc 100644 --- a/packages/client/src/schema-component/antd/input/ReadPretty.tsx +++ b/packages/client/src/schema-component/antd/input/ReadPretty.tsx @@ -1,9 +1,8 @@ import { usePrefixCls } from '@formily/antd/lib/__builtins__'; -import { Popover } from 'antd'; import { InputProps, TextAreaProps } from 'antd/lib/input'; import cls from 'classnames'; -import React, { useEffect, useState } from 'react'; -import { useCompile } from '../../hooks/useCompile'; +import React from 'react'; +import { EllipsisWithTooltip } from './EllipsisWithTooltip'; type Composed = { Input: React.FC; @@ -15,25 +14,11 @@ export const ReadPretty: Composed = () => null; ReadPretty.Input = (props) => { const prefixCls = usePrefixCls('description-input', props); - const domRef = React.useRef(null); - const compile = useCompile(); - const [ellipsis, setEllipsis] = useState(false); - const content = compile(props.value); - const ellipsisContent = ( - - {content} - - ); - useEffect(() => { - if (domRef.current?.scrollWidth > domRef.current?.clientWidth) { - setEllipsis(true); - } - }, []); return (
{props.addonBefore} {props.prefix} - {ellipsis ? ellipsisContent : content} + {props.value} {props.suffix} {props.addonAfter}
@@ -41,32 +26,13 @@ ReadPretty.Input = (props) => { }; ReadPretty.TextArea = (props) => { + console.log('EllipsisWithTooltip', props.ellipsis); const prefixCls = usePrefixCls('description-textarea', props); - const domRef = React.useRef(null); - const [ellipsis, setEllipsis] = useState(false); - const ellipsisProp = props.ellipsis === true ? {} : props.ellipsis; - const ellipsisContent = ( - - - {props.text || props.value} - - - ); - useEffect(() => { - if (domRef.current?.scrollWidth > domRef.current?.clientWidth) { - setEllipsis(true); - } - }, []); return (
{props.addonBefore} {props.prefix} - {ellipsis ? ellipsisContent : props.value} + {props.value} {props.suffix} {props.addonAfter}
diff --git a/packages/client/src/schema-component/antd/table/Table.Array.tsx b/packages/client/src/schema-component/antd/table/Table.Array.tsx index c396c4057..d9f85193b 100644 --- a/packages/client/src/schema-component/antd/table/Table.Array.tsx +++ b/packages/client/src/schema-component/antd/table/Table.Array.tsx @@ -87,6 +87,20 @@ export const components = { row: (props) => { return ; }, + cell: (props) => ( + + ), }, }; @@ -228,7 +242,14 @@ export const TableArray: React.FC = observer((props) => { }; return ( -
+
{ diff --git a/packages/client/src/schema-initializer/Initializers/utils.ts b/packages/client/src/schema-initializer/Initializers/utils.ts index ed48849f7..f35d11609 100644 --- a/packages/client/src/schema-initializer/Initializers/utils.ts +++ b/packages/client/src/schema-initializer/Initializers/utils.ts @@ -61,6 +61,28 @@ export const useTableColumnInitializerFields = () => { return fields .filter((field) => field?.interface && field?.interface !== 'subTable') .map((field) => { + const componentProps = {}; + if (field?.uiSchema['x-component']?.startsWith?.('Input')) { + componentProps['ellipsis'] = true; + } + if (field.interface === 'attachment') { + componentProps['size'] = 'small'; + return { + type: 'item', + title: field?.uiSchema?.title || field.name, + component: 'CollectionFieldInitializer', + find: findTableColumn, + remove: removeTableColumn, + schema: { + name: field.name, + 'x-collection-field': `${name}.${field.name}`, + 'x-component': 'CollectionField', + 'x-component-props': { + ...componentProps, + }, + }, + } as SchemaInitializerItemOptions; + } if (field.target) { return { field, @@ -73,13 +95,12 @@ export const useTableColumnInitializerFields = () => { name: field.name, 'x-collection-field': `${name}.${field.name}`, 'x-component': 'CollectionField', + 'x-component-props': { + ...componentProps, + }, }, } as SchemaInitializerItemOptions; } - const componentProps = {}; - if (field.interface === 'attachment') { - componentProps['size'] = 'small'; - } return { type: 'item', title: field?.uiSchema?.title || field.name,