Refactor/display input part 2 (#1555)

* Email - Money - Number

* Date
This commit is contained in:
Lucas Bordeau
2023-09-12 20:04:26 +02:00
committed by GitHub
parent 9b495ae2e8
commit 9b5e24105b
33 changed files with 348 additions and 295 deletions

View File

@ -0,0 +1,9 @@
import { formatToHumanReadableDate } from '~/utils';
type OwnProps = {
value: Date | string | null | undefined;
};
export function DateDisplay({ value }: OwnProps) {
return <div>{value && formatToHumanReadableDate(value)}</div>;
}

View File

@ -0,0 +1,27 @@
import { MouseEvent } from 'react';
import { ContactLink } from '@/ui/link/components/ContactLink';
function validateEmail(email: string) {
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailPattern.test(email.trim());
}
type OwnProps = {
value: string | null;
};
export function EmailDisplay({ value }: OwnProps) {
return value && validateEmail(value) ? (
<ContactLink
href={`mailto:${value}`}
onClick={(event: MouseEvent<HTMLElement>) => {
event.stopPropagation();
}}
>
{value}
</ContactLink>
) : (
<ContactLink href="#">{value}</ContactLink>
);
}

View File

@ -0,0 +1,22 @@
import styled from '@emotion/styled';
import { formatNumber } from '~/utils/formatNumber';
const StyledTextInputDisplay = styled.div`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
`;
type OwnProps = {
value: number | null;
};
export function MoneyDisplay({ value }: OwnProps) {
return (
<StyledTextInputDisplay>
{value ? `$${formatNumber(value)}` : ''}
</StyledTextInputDisplay>
);
}