Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/lib/kit/components/Inputs/CardOneOf/CardOneOf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Row} from '../../Layouts';
import {RemoveButton} from '../../RemoveButton';

export const CardOneOf: ObjectIndependentInput = (props) => {
const {input, meta, spec, name} = props;
const {input, meta, spec, name, Layout} = props;

const [open, setOpen] = React.useState(true);

Expand All @@ -27,14 +27,19 @@ export const CardOneOf: ObjectIndependentInput = (props) => {
onTogglerChange: onOpen,
});

const toggler = React.useMemo(
() => (
<Row {...props} name="__stub-name">
{togglerInput}
</Row>
),
[togglerInput, props],
);
const toggler = React.useMemo(() => {
const togglerProps = {
...props,
name: '__stub-name',
children: togglerInput,
} as const;

if (Layout) {
return <Layout {...togglerProps} />;
}

return <Row {...togglerProps} />;
}, [togglerInput, props, Layout]);

const actions = React.useMemo(() => {
if (isArrayItem(name)) {
Expand Down
24 changes: 15 additions & 9 deletions src/lib/kit/components/Views/CardOneOfView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Card, ViewRow} from '../';
import {ObjectIndependentView, StringSpec, ViewController} from '../../../core';

export const CardOneOfView: ObjectIndependentView = (props) => {
const {value = {}, spec, name} = props;
const {value = {}, spec, name, Layout} = props;

const [open, setOpen] = React.useState(true);

Expand All @@ -27,14 +27,20 @@ export const CardOneOfView: ObjectIndependentView = (props) => {
);
}, [valueKey, spec.description, specProperties]);

const title = React.useMemo(
() => (
<ViewRow spec={spec as unknown as StringSpec} value={valueName} name={name}>
<>{valueName}</>
</ViewRow>
),
[spec, name, valueName],
);
const title = React.useMemo(() => {
const titleProps = {
spec: spec as unknown as StringSpec,
value: valueName,
name: name,
children: <>{valueName}</>,
} as const;

if (Layout) {
return <Layout {...titleProps} />;
}

return <ViewRow {...titleProps} />;
}, [spec, name, valueName, Layout]);

if (!value || !Object.keys(value).length) {
return null;
Expand Down
Loading