fix(striker-ui): make form summary entry value scrollable

main
Tsu-ba-me 2 years ago
parent 0edb8910c2
commit 43308a2e88
  1. 38
      striker-ui/components/FormSummary.tsx

@ -1,9 +1,10 @@
import { import {
Box,
List as MUIList, List as MUIList,
ListItem as MUIListItem, ListItem as MUIListItem,
capitalize, capitalize,
} from '@mui/material'; } from '@mui/material';
import { FC, ReactElement, createElement } from 'react'; import { FC, ReactElement } from 'react';
import FlexBox from './FlexBox'; import FlexBox from './FlexBox';
import { BodyText, MonoText, SensitiveText } from './Text'; import { BodyText, MonoText, SensitiveText } from './Text';
@ -15,13 +16,24 @@ const capEntryLabel: CapFormEntryLabel = (value) => {
return capitalize(lcased); return capitalize(lcased);
}; };
const renderEntryValueWithPassword: RenderFormValueFunction = ({ const renderEntryValueWithMono: RenderFormValueFunction = ({ entry }) => (
entry, <MonoText whiteSpace="nowrap">{String(entry)}</MonoText>
key, );
}) => {
const textElement = /passw/i.test(key) ? SensitiveText : MonoText;
return createElement(textElement, { monospaced: true }, String(entry)); const renderEntryValueWithPassword: RenderFormValueFunction = (args) => {
const { entry, key } = args;
return /passw/i.test(key) ? (
<SensitiveText
revealButtonProps={{ sx: { marginRight: 0, padding: 0 } }}
monospaced
textLineHeight={null}
>
{String(entry)}
</SensitiveText>
) : (
renderEntryValueWithMono(args)
);
}; };
const buildEntryList = ({ const buildEntryList = ({
@ -109,7 +121,9 @@ const FormSummary = <T extends FormEntries>({
renderEntry = ({ depth, entry, getLabel, key, nest, renderValue }) => ( renderEntry = ({ depth, entry, getLabel, key, nest, renderValue }) => (
<FlexBox fullWidth growFirst row maxWidth="100%"> <FlexBox fullWidth growFirst row maxWidth="100%">
<BodyText>{getLabel({ cap: capEntryLabel, depth, entry, key })}</BodyText> <BodyText>{getLabel({ cap: capEntryLabel, depth, entry, key })}</BodyText>
{!nest && renderValue({ depth, entry, key })} <Box sx={{ maxWidth: '100%', overflowX: 'scroll' }}>
{!nest && renderValue({ depth, entry, key })}
</Box>
</FlexBox> </FlexBox>
), ),
// Prop(s) that rely on other(s). // Prop(s) that rely on other(s).
@ -120,11 +134,9 @@ const FormSummary = <T extends FormEntries>({
return <BodyText>none</BodyText>; return <BodyText>none</BodyText>;
} }
return hasPassword ? ( return hasPassword
renderEntryValueWithPassword(args) ? renderEntryValueWithPassword(args)
) : ( : renderEntryValueWithMono(args);
<MonoText>{String(entry)}</MonoText>
);
}, },
}: FormSummaryProps<T>): ReturnType<FC<FormSummaryProps<T>>> => }: FormSummaryProps<T>): ReturnType<FC<FormSummaryProps<T>>> =>
buildEntryList({ buildEntryList({

Loading…
Cancel
Save