redoc/src/components/Fields/FieldDetail.tsx
2022-11-10 15:13:02 -05:00

26 lines
632 B
TypeScript

import * as React from 'react';
import { ExampleValue, FieldLabel } from '../../common-elements/fields';
export interface FieldDetailProps {
value?: any;
label: string;
raw?: boolean;
}
function FieldDetailComponent({ value, label, raw }: FieldDetailProps) {
if (value === undefined) {
return null;
}
const stringifyValue = raw ? String(value) : JSON.stringify(value);
return (
<div>
<FieldLabel> {label} </FieldLabel>{' '}
<ExampleValue className="field-example">{stringifyValue}</ExampleValue>
</div>
);
}
export const FieldDetail = React.memo<FieldDetailProps>(FieldDetailComponent);