Add Empty as value of empty fields inputs #1042 (#1243)

* Add Empty as value of empty fields inputs #1042

* rebase
This commit is contained in:
Weiko
2023-08-22 16:46:15 +02:00
committed by GitHub
parent 242c73ed81
commit 22dbe21bcd

View File

@ -16,17 +16,11 @@ const StyledEditableFieldNormalModeOuterContainer = styled.div<
height: ${({ isDisplayModeFixHeight }) => height: ${({ isDisplayModeFixHeight }) =>
isDisplayModeFixHeight ? '16px' : 'auto'}; isDisplayModeFixHeight ? '16px' : 'auto'};
min-height: 16px; min-height: 16px;
overflow: hidden; overflow: hidden;
padding: ${({ theme }) => theme.spacing(1)}; padding: ${({ theme }) => theme.spacing(1)};
${(props) => { ${(props) => {
if (props.isDisplayModeContentEmpty) { if (!props.isDisplayModeContentEmpty) {
return css`
min-width: 50px;
`;
} else {
return css` return css`
width: fit-content; width: fit-content;
`; `;
@ -65,6 +59,10 @@ const StyledEditableFieldNormalModeInnerContainer = styled.div`
white-space: nowrap; white-space: nowrap;
`; `;
const StyledEmptyField = styled.div`
color: ${({ theme }) => theme.font.color.light};
`;
type OwnProps = { type OwnProps = {
disableClick?: boolean; disableClick?: boolean;
onClick?: () => void; onClick?: () => void;
@ -73,6 +71,16 @@ type OwnProps = {
isDisplayModeFixHeight?: boolean; isDisplayModeFixHeight?: boolean;
}; };
function displayEmptyIfNothingToShow(
children: React.ReactNode,
isDisplayModeContentEmpty?: boolean,
): React.ReactNode {
if (isDisplayModeContentEmpty || !children) {
return <StyledEmptyField>{'Empty'}</StyledEmptyField>;
}
return children;
}
export function EditableFieldDisplayMode({ export function EditableFieldDisplayMode({
children, children,
disableClick, disableClick,
@ -90,7 +98,7 @@ export function EditableFieldDisplayMode({
isDisplayModeFixHeight={isDisplayModeFixHeight} isDisplayModeFixHeight={isDisplayModeFixHeight}
> >
<StyledEditableFieldNormalModeInnerContainer> <StyledEditableFieldNormalModeInnerContainer>
{children} {displayEmptyIfNothingToShow(children, isDisplayModeContentEmpty)}
</StyledEditableFieldNormalModeInnerContainer> </StyledEditableFieldNormalModeInnerContainer>
</StyledEditableFieldNormalModeOuterContainer> </StyledEditableFieldNormalModeOuterContainer>
); );