@@ -3,7 +3,7 @@ import React from 'react';
33import { Label , Text } from '@gravity-ui/uikit' ;
44import cloneDeep from 'lodash/cloneDeep' ;
55
6- import { StringIndependentInputProps } from '../../../../core' ;
6+ import { StringIndependentInput , StringSpec } from '../../../../core' ;
77import { block } from '../../../utils' ;
88import { LazyLoader } from '../../LazyLoader' ;
99
@@ -13,11 +13,16 @@ import './TextContent.scss';
1313
1414const b = block ( 'text-content' ) ;
1515
16- export const TextContent : React . FC < StringIndependentInputProps > = ( {
16+ export interface TextContentComponentProps {
17+ spec : StringSpec ;
18+ value ?: string ;
19+ Layout ?: React . FC < { spec : StringSpec ; children : React . ReactElement } > ;
20+ }
21+
22+ export const TextContentComponent : React . FC < TextContentComponentProps > = ( {
1723 spec,
24+ value,
1825 Layout,
19- input,
20- ...restProps
2126} ) => {
2227 const { textContentParams, layoutDescription} = spec . viewSpec ;
2328
@@ -42,7 +47,7 @@ export const TextContent: React.FC<StringIndependentInputProps> = ({
4247 size = "m"
4348 theme = { textContentParams . themeLabel }
4449 className = { b ( ) }
45- value = { input . value }
50+ value = { value }
4651 icon = { iconLib }
4752 >
4853 { content }
@@ -57,10 +62,10 @@ export const TextContent: React.FC<StringIndependentInputProps> = ({
5762 </ Text >
5863 ) : null }
5964 { content }
60- { input . value ? (
65+ { value ? (
6166 < React . Fragment >
6267 < Text className = { b ( 'separator' ) } > :</ Text >
63- < Text color = "secondary" > { input . value } </ Text >
68+ < Text color = "secondary" > { value } </ Text >
6469 </ React . Fragment >
6570 ) : null }
6671 </ div >
@@ -74,12 +79,41 @@ export const TextContent: React.FC<StringIndependentInputProps> = ({
7479 _spec . viewSpec . layoutDescription = undefined ;
7580 }
7681
77- return (
78- < Layout spec = { _spec } input = { input } { ...restProps } >
79- { content }
80- </ Layout >
81- ) ;
82+ return < Layout spec = { _spec } > { content } </ Layout > ;
8283 }
8384
8485 return content ;
8586} ;
87+
88+ export const TextContent : StringIndependentInput = ( {
89+ name,
90+ spec,
91+ Layout,
92+ input,
93+ arrayInput,
94+ meta,
95+ layoutProps,
96+ } ) => {
97+ const WrappedLayout = React . useMemo ( ( ) => {
98+ if ( Layout ) {
99+ const Component : TextContentComponentProps [ 'Layout' ] = ( props ) => {
100+ return (
101+ < Layout
102+ name = { name }
103+ input = { input }
104+ layoutProps = { layoutProps }
105+ arrayInput = { arrayInput }
106+ meta = { meta }
107+ { ...props }
108+ />
109+ ) ;
110+ } ;
111+
112+ return Component ;
113+ }
114+
115+ return undefined ;
116+ } , [ Layout , layoutProps , input , arrayInput , meta , name ] ) ;
117+
118+ return < TextContentComponent spec = { spec } value = { input . value } Layout = { WrappedLayout } /> ;
119+ } ;
0 commit comments