header component added (#3539)

* header component added

* fix css issues and date format issue

---------

Co-authored-by: bosiraphael <raphael.bosi@gmail.com>
This commit is contained in:
Suman Sahoo 2024-01-23 16:36:21 +05:30 committed by GitHub
parent 004c23768c
commit 096f005562
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 91 additions and 11 deletions

View File

@ -0,0 +1,54 @@
import styled from '@emotion/styled';
import { IconMail } from '@/ui/display/icon';
import { Tag } from '@/ui/display/tag/components/Tag';
import { beautifyPastDateRelativeToNow } from '~/utils/date-utils';
interface ThreadHeaderProps {
subject: string;
lastMessageSentAt: Date;
}
const StyledContainer = styled.div`
align-items: flex-start;
display: flex;
flex-direction: column;
padding: ${({ theme }) => theme.spacing(6)};
gap: ${({ theme }) => theme.spacing(6)};
border-bottom: 1px solid ${({ theme }) => theme.border.color.medium};
background: ${({ theme }) => theme.background.secondary};
`;
const StyledHead = styled.div`
width: 100%;
`;
const StyledHeading = styled.h2`
margin: 0;
margin-bottom: ${({ theme }) => theme.spacing(3)};
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;
const StyledContent = styled.span`
color: ${({ theme }) => theme.font.color.tertiary};
width: 100%;
`;
export const ThreadHeader = ({
subject,
lastMessageSentAt,
}: ThreadHeaderProps) => {
return (
<StyledContainer>
<Tag Icon={IconMail} color="gray" text="Email" onClick={() => {}} />
<StyledHead>
<StyledHeading>{subject}</StyledHeading>
<StyledContent>
Last message {beautifyPastDateRelativeToNow(lastMessageSentAt)}
</StyledContent>
</StyledHead>
</StyledContainer>
);
};

View File

@ -1,6 +1,8 @@
import React from 'react'; import React from 'react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { ThreadHeader } from '@/activities/emails/components/ThreadHeader';
const StyledContainer = styled.div` const StyledContainer = styled.div`
box-sizing: border-box; box-sizing: border-box;
display: flex; display: flex;
@ -12,9 +14,16 @@ const StyledContainer = styled.div`
`; `;
export const RightDrawerThread = () => { export const RightDrawerThread = () => {
const mockedThread = {
subject: 'Tes with long subject, very long subject, very long subject',
receivedAt: new Date(),
};
return ( return (
<StyledContainer> <StyledContainer>
<></> <ThreadHeader
subject={mockedThread.subject}
lastMessageSentAt={mockedThread.receivedAt}
/>
</StyledContainer> </StyledContainer>
); );
}; };

View File

@ -1,5 +1,7 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
import { ThemeColor } from '@/ui/theme/constants/colors'; import { ThemeColor } from '@/ui/theme/constants/colors';
import { themeColorSchema } from '@/ui/theme/utils/themeColorSchema'; import { themeColorSchema } from '@/ui/theme/utils/themeColorSchema';
@ -30,12 +32,18 @@ const StyledContent = styled.span`
white-space: nowrap; white-space: nowrap;
`; `;
const StyledIconContainer = styled.div`
display: flex;
margin-right: ${({ theme }) => theme.spacing(1)};
`;
type TagWeight = 'regular' | 'medium'; type TagWeight = 'regular' | 'medium';
type TagProps = { type TagProps = {
className?: string; className?: string;
color: ThemeColor; color: ThemeColor;
text: string; text: string;
Icon?: IconComponent;
onClick?: () => void; onClick?: () => void;
weight?: TagWeight; weight?: TagWeight;
}; };
@ -44,15 +52,24 @@ export const Tag = ({
className, className,
color, color,
text, text,
Icon,
onClick, onClick,
weight = 'regular', weight = 'regular',
}: TagProps) => ( }: TagProps) => {
<StyledTag const theme = useTheme();
className={className} return (
color={themeColorSchema.catch('gray').parse(color)} <StyledTag
onClick={onClick} className={className}
weight={weight} color={themeColorSchema.catch('gray').parse(color)}
> onClick={onClick}
<StyledContent>{text}</StyledContent> weight={weight}
</StyledTag> >
); {!!Icon && (
<StyledIconContainer>
<Icon size={theme.icon.size.sm} stroke={theme.icon.stroke.sm} />
</StyledIconContainer>
)}
<StyledContent>{text}</StyledContent>
</StyledTag>
);
};