Skip to content

Commit

Permalink
Create TextWithIcon component (#3590)
Browse files Browse the repository at this point in the history
  • Loading branch information
ingraso committed Feb 22, 2023
1 parent b4b43eb commit ac747ac
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 131 deletions.
31 changes: 9 additions & 22 deletions app/components/EventItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Pill from 'app/components/Pill';
import Tag from 'app/components/Tags/Tag';
import Time from 'app/components/Time';
import Tooltip from 'app/components/Tooltip';
import type { Event, EventTime } from 'app/models';
import type { Event } from 'app/models';
import { colorForEvent } from 'app/routes/events/utils';
import { eventAttendanceAbsolute } from 'app/utils/eventStatus';
import styles from './styles.css';
Expand Down Expand Up @@ -69,10 +69,9 @@ const Attendance = ({ event }) => {

type TimeStampProps = {
event: Event;
loggedIn: boolean;
};

const TimeStamp = ({ event }) => {
const TimeStamp = ({ event }: TimeStampProps) => {
return (
<div className={styles.eventTime}>
<Flex alignItems="center">
Expand All @@ -95,8 +94,8 @@ const TimeStamp = ({ event }) => {
);
};

const RegistrationIcon = ({ event, loggedIn }: TimeStampProps) => {
const iconStyle = eventStatusObject(event, loggedIn);
const RegistrationIcon = ({ event }: TimeStampProps) => {
const iconStyle = eventStatusObject(event);
return (
<Flex justifyContent="center" alignItems="center">
<Tooltip content={iconStyle.tooltip}>
Expand All @@ -112,17 +111,13 @@ const RegistrationIcon = ({ event, loggedIn }: TimeStampProps) => {

type EventItemProps = {
event: Event;
field?: EventTime;
showTags?: boolean;
loggedIn: boolean;
eventStyle?: EventStyle;
};

const EventItem = ({
event,
field,
showTags = true,
loggedIn = false,
eventStyle,
}: EventItemProps): ReactNode => {
switch (eventStyle) {
Expand Down Expand Up @@ -170,27 +165,19 @@ const EventItem = ({
<Image
src={event.cover}
placeholder={event.coverPlaceholder}
alt={`Event cover image - ${event.title}`}
/>
</Link>
)}
</Flex>
</Flex>
<Flex
display="flex"
justifyContent="flex-start"
column="true"
width="25%"
>
<Flex justifyContent="flex-start" column={true} width="25%">
<Flex width="100%" justifyContent="flex-start">
<RegistrationIcon
event={event}
field={field}
loggedIn={loggedIn}
/>
<RegistrationIcon event={event} />
<Attendance event={event} />
</Flex>

<TimeStamp event={event} field={field} loggedIn={loggedIn} />
<TimeStamp event={event} />
</Flex>
</Flex>
{showTags && (
Expand All @@ -216,7 +203,7 @@ const EventItem = ({
<h3 className={styles.eventItemTitle}>{event.title}</h3>
{event.totalCapacity > 0 && <Attendance event={event} />}
</Link>
<TimeStamp event={event} loggedIn={loggedIn} />
<TimeStamp event={event} />
{showTags && (
<Flex wrap>
{event.tags.map((tag, index) => (
Expand Down
5 changes: 5 additions & 0 deletions app/components/TextWithIcon/TextWithIcon.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.infoIcon {
min-width: 26px;
justify-content: center;
padding-right: 0.2em;
}
48 changes: 48 additions & 0 deletions app/components/TextWithIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Icon from '../Icon';
import { Flex } from '../Layout';
import Tooltip from '../Tooltip';
import styles from './TextWithIcon.css';
import type { ReactElement } from 'react';

type Props = {
iconName: string;
className?: string;
content: ReactElement | string;
tooltipContentIcon?: ReactElement;
iconRight?: boolean;
size?: number;
};

const TextWithIcon = ({
iconName,
className,
content,
tooltipContentIcon,
iconRight = false,
size,
}: Props) => {
return (
<Flex alignItems="center" className={className}>
{iconRight ? <>{content}</> : <></>}
{tooltipContentIcon ? (
<Tooltip content={tooltipContentIcon}>
<Icon
name={iconName}
className={styles.infoIcon}
size={size ? size : undefined}
/>
</Tooltip>
) : (
<Icon
name={iconName}
className={styles.infoIcon}
size={size ? size : undefined}
/>
)}

{iconRight ? <></> : <>{content}</>}
</Flex>
);
};

export default TextWithIcon;
7 changes: 0 additions & 7 deletions app/routes/company/components/Company.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
@import url('~app/styles/variables.css');

.infoIcon {
min-width: 26px;
display: flex;
justify-content: center;
padding-right: 0.2em;
}

.sectionHeader {
font-size: 20px;
margin-top: 20px;
Expand Down
20 changes: 12 additions & 8 deletions app/routes/company/components/CompanyDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import JoblistingItem from 'app/components/JoblistingItem';
import { Flex } from 'app/components/Layout';
import LoadingIndicator from 'app/components/LoadingIndicator';
import NavigationTab from 'app/components/NavigationTab';
import TextWithIcon from 'app/components/TextWithIcon';
import type { Event } from 'app/models';
import type { DetailedCompany } from 'app/store/models/Company';
import type { ListJoblisting } from 'app/store/models/Joblisting';
Expand Down Expand Up @@ -147,14 +148,17 @@ const CompanyDetail = ({
{companyInfo.map(
(info) =>
info.text && (
<Flex key={info.text}>
<Icon name={info.icon} className={styles.infoIcon} />
{info.link ? (
<a href={info.text}>{company.name}</a>
) : (
info.text
)}
</Flex>
<TextWithIcon
key={info.text}
iconName={info.icon}
content={
info.link ? (
<a href={info.text}>{company.name}</a>
) : (
info.text
)
}
/>
)
)}
</ContentSidebar>
Expand Down
11 changes: 1 addition & 10 deletions app/routes/events/components/Calendar.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,8 @@
line-height: 1.3;
}

.iconWithText {
.textWithIcon {
font-size: 14px;
display: flex;
align-items: center;
}

.infoIcon {
width: 25px;
display: flex;
justify-content: center;
padding-right: 0.2em;
}

.weekdayHeading {
Expand Down
42 changes: 23 additions & 19 deletions app/routes/events/components/CalendarCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import moment from 'moment-timezone';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { createSelector } from 'reselect';
import Icon from 'app/components/Icon';
import Pill from 'app/components/Pill';
import Popover from 'app/components/Popover';
import TextWithIcon from 'app/components/TextWithIcon';
import { FromToTime } from 'app/components/Time';
import type { Event } from 'app/models';
import { colorForEvent, textColorForEvent } from '../utils';
Expand Down Expand Up @@ -57,24 +57,28 @@ const renderEvent = (event: Event) => {
)}
</h3>
<p className={styles.popoverEventDescription}>{description}</p>
<div className={styles.iconWithText}>
<Icon name="time-outline" className={styles.infoIcon} />
<strong>
{moment.duration(endTime.diff(startTime)) <
moment.duration(1, 'days') ? (
<span>
<time>{startTime.format('HH:mm')}</time> -{' '}
<time>{endTime.format('HH:mm')}</time>
</span>
) : (
<FromToTime from={event.startTime} to={event.endTime} />
)}
</strong>
</div>
<div className={styles.iconWithText}>
<Icon name="location-outline" className={styles.infoIcon} />
<strong>{event.location}</strong>
</div>
<TextWithIcon
iconName="time-outline"
content={
<strong>
{moment.duration(endTime.diff(startTime)) <
moment.duration(1, 'days') ? (
<span>
<time>{startTime.format('HH:mm')}</time> -{' '}
<time>{endTime.format('HH:mm')}</time>
</span>
) : (
<FromToTime from={event.startTime} to={event.endTime} />
)}
</strong>
}
className={styles.textWithIcon}
/>
<TextWithIcon
iconName="location-outline"
content={<strong>{event.location}</strong>}
className={styles.textWithIcon}
/>
</Popover>
);
};
Expand Down
12 changes: 0 additions & 12 deletions app/routes/events/components/EventDetail/EventDetail.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@
}
}

.iconWithText {
display: flex;
align-items: center;
}

.infoIcon {
min-width: 26px;
display: flex;
justify-content: center;
padding-right: 0.2em;
}

.infoIconLocation {
display: flex;
flex-wrap: wrap;
Expand Down

0 comments on commit ac747ac

Please sign in to comment.