|
|
@ -8,7 +8,17 @@ import { FC, ReactElement, createElement } from 'react'; |
|
|
|
import FlexBox from './FlexBox'; |
|
|
|
import FlexBox from './FlexBox'; |
|
|
|
import { BodyText, MonoText, SensitiveText } from './Text'; |
|
|
|
import { BodyText, MonoText, SensitiveText } from './Text'; |
|
|
|
|
|
|
|
|
|
|
|
const renderEntryValueWithPassword: RenderFormValueFunction = (key, entry) => { |
|
|
|
const capEntryLabel: CapFormEntryLabel = (value) => { |
|
|
|
|
|
|
|
const spaced = value.replace(/([a-z\d])([A-Z])/g, '$1 $2'); |
|
|
|
|
|
|
|
const lcased = spaced.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return capitalize(lcased); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const renderEntryValueWithPassword: RenderFormValueFunction = ({ |
|
|
|
|
|
|
|
entry, |
|
|
|
|
|
|
|
key, |
|
|
|
|
|
|
|
}) => { |
|
|
|
const textElement = /passw/i.test(key) ? SensitiveText : MonoText; |
|
|
|
const textElement = /passw/i.test(key) ? SensitiveText : MonoText; |
|
|
|
|
|
|
|
|
|
|
|
return createElement(textElement, { monospaced: true }, String(entry)); |
|
|
|
return createElement(textElement, { monospaced: true }, String(entry)); |
|
|
@ -46,10 +56,17 @@ const buildEntryList = ({ |
|
|
|
result.push( |
|
|
|
result.push( |
|
|
|
<MUIListItem |
|
|
|
<MUIListItem |
|
|
|
key={itemId} |
|
|
|
key={itemId} |
|
|
|
sx={{ paddingLeft: `.${depth * 2}em` }} |
|
|
|
sx={{ paddingLeft: `${depth}em` }} |
|
|
|
{...getListItemProps?.call(null, itemKey, value, depth)} |
|
|
|
{...getListItemProps?.call(null, { depth, entry: value, key: itemKey })} |
|
|
|
> |
|
|
|
> |
|
|
|
{renderEntry(itemKey, value, getEntryLabel, renderEntryValue)} |
|
|
|
{renderEntry({ |
|
|
|
|
|
|
|
depth, |
|
|
|
|
|
|
|
entry: value, |
|
|
|
|
|
|
|
getLabel: getEntryLabel, |
|
|
|
|
|
|
|
key: itemKey, |
|
|
|
|
|
|
|
nest, |
|
|
|
|
|
|
|
renderValue: renderEntryValue, |
|
|
|
|
|
|
|
})} |
|
|
|
</MUIListItem>, |
|
|
|
</MUIListItem>, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -73,8 +90,9 @@ const buildEntryList = ({ |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<MUIList |
|
|
|
<MUIList |
|
|
|
dense |
|
|
|
dense |
|
|
|
|
|
|
|
disablePadding |
|
|
|
key={listId} |
|
|
|
key={listId} |
|
|
|
{...getListProps?.call(null, listKey, entries, depth)} |
|
|
|
{...getListProps?.call(null, { depth, entries, key: listKey })} |
|
|
|
> |
|
|
|
> |
|
|
|
{result} |
|
|
|
{result} |
|
|
|
</MUIList> |
|
|
|
</MUIList> |
|
|
@ -83,26 +101,31 @@ const buildEntryList = ({ |
|
|
|
|
|
|
|
|
|
|
|
const FormSummary = <T extends FormEntries>({ |
|
|
|
const FormSummary = <T extends FormEntries>({ |
|
|
|
entries, |
|
|
|
entries, |
|
|
|
getEntryLabel = (key) => { |
|
|
|
getEntryLabel = ({ cap, key }) => cap(key), |
|
|
|
const spaced = key.replace(/([a-z\d])([A-Z])/g, '$1 $2'); |
|
|
|
|
|
|
|
const lcased = spaced.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return capitalize(lcased); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getListProps, |
|
|
|
getListProps, |
|
|
|
getListItemProps, |
|
|
|
getListItemProps, |
|
|
|
hasPassword, |
|
|
|
hasPassword, |
|
|
|
maxDepth = 3, |
|
|
|
maxDepth = 3, |
|
|
|
renderEntry = (key, entry, getLabel, renderValue) => ( |
|
|
|
renderEntry = ({ depth, entry, getLabel, key, nest, renderValue }) => ( |
|
|
|
<FlexBox fullWidth growFirst row> |
|
|
|
<FlexBox fullWidth growFirst row maxWidth="100%"> |
|
|
|
<BodyText>{getLabel(key, entry)}</BodyText> |
|
|
|
<BodyText>{getLabel({ cap: capEntryLabel, depth, entry, key })}</BodyText> |
|
|
|
{renderValue(key, entry)} |
|
|
|
{!nest && renderValue({ depth, entry, key })} |
|
|
|
</FlexBox> |
|
|
|
</FlexBox> |
|
|
|
), |
|
|
|
), |
|
|
|
// Prop(s) that rely on other(s).
|
|
|
|
// Prop(s) that rely on other(s).
|
|
|
|
renderEntryValue = hasPassword |
|
|
|
renderEntryValue = (args) => { |
|
|
|
? renderEntryValueWithPassword |
|
|
|
const { entry } = args; |
|
|
|
: (key, entry) => <MonoText>{String(entry)}</MonoText>, |
|
|
|
|
|
|
|
|
|
|
|
if (['', null, undefined].some((bad) => entry === bad)) { |
|
|
|
|
|
|
|
return <BodyText>none</BodyText>; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return hasPassword ? ( |
|
|
|
|
|
|
|
renderEntryValueWithPassword(args) |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
<MonoText>{String(entry)}</MonoText> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
}: FormSummaryProps<T>): ReturnType<FC<FormSummaryProps<T>>> => |
|
|
|
}: FormSummaryProps<T>): ReturnType<FC<FormSummaryProps<T>>> => |
|
|
|
buildEntryList({ |
|
|
|
buildEntryList({ |
|
|
|
entries, |
|
|
|
entries, |
|
|
|