Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLAY-1436] Dark Mode Fix: Contact and DRI #3526

Merged
merged 10 commits into from
Jul 25, 2024
44 changes: 25 additions & 19 deletions playbook/app/pb_kits/playbook/pb_contact/_contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import Body from '../pb_body/_body'
import Caption from '../pb_caption/_caption'
import Icon from '../pb_icon/_icon'

const contactTypeMap: { [key: string]: string; } = {
const contactTypeMap: { [key: string]: string } = {
'cell': 'mobile',
'email': 'envelope',
'extension': 'phone-plus',
'home': 'phone',
'work': 'phone-office',
'work-cell': 'phone-laptop',
'wrong-phone': 'phone-slash',
'extension': 'phone-plus',
}

const formatContact = (contactString: string, contactType: string) => {
if (contactType == 'email') return contactString
if (contactType === 'email') return contactString

const cleaned = contactString.replace(/\D/g, '')
const phoneNumber = cleaned.match(/^(1|)?(\d{3})(\d{3})(\d{4})$/)

if(contactType == 'extension') {
if (contactType === 'extension') {
return cleaned.match(/^\d{4}$/)
}

Expand All @@ -40,19 +40,20 @@ const formatContact = (contactString: string, contactType: string) => {
phoneNumber[4],
].join('')
}

return null
}

type ContactProps = {
aria?: { [key: string]: string; },
className?: string | string[],
contactDetail?: string,
contactType?: string,
contactValue: string,
data?: {[key: string]: string},
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
id?: string,
aria?: { [key: string]: string }
className?: string | string[]
contactDetail?: string
contactType?: string
contactValue: string
data?: { [key: string]: string }
dark?: boolean
htmlOptions?: { [key: string]: string | number | boolean | (() => void) }
id?: string
}

const Contact = (props: ContactProps): React.ReactElement => {
Expand All @@ -63,8 +64,10 @@ const Contact = (props: ContactProps): React.ReactElement => {
contactType,
contactValue,
data = {},
dark = false,
htmlOptions = {},
id } = props
id,
} = props
const ariaProps = buildAriaProps(aria)
const dataProps = buildDataProps(data)
const htmlProps = buildHtmlProps(htmlOptions)
Expand All @@ -73,6 +76,7 @@ const Contact = (props: ContactProps): React.ReactElement => {
globalProps(props),
className
)

return (
<div
{...ariaProps}
Expand All @@ -83,25 +87,27 @@ const Contact = (props: ContactProps): React.ReactElement => {
>
<Body
className="pb_contact_kit"
color="light"
color={dark ? "light" : "default"}
anthonymig88 marked this conversation as resolved.
Show resolved Hide resolved
dark={dark}
tag="span"
>
<Icon
dark={dark}
fixedWidth
icon={contactTypeMap[contactType] || 'phone'}
/>
{` ${formatContact(contactValue, contactType)} `}
{
contactDetail &&
{contactDetail && (
<Caption
dark={dark}
size="xs"
tag="span"
text={contactDetail}
/>
}
)}
</Body>
</div>
)
}

export default Contact
export default Contact
9 changes: 6 additions & 3 deletions playbook/app/pb_kits/playbook/pb_contact/contact.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
<%= pb_rails("body", props: {
tag: "span",
classname: "pb_contact_kit",
color: "light"
color: "light",
dark: object.dark
}) do %>
<%= pb_rails("icon", props: {
icon: object.contact_icon,
fixed_width: true
fixed_width: true,
dark: object.dark
}) %>
<%= object.formatted_contact_value if object.contact_value %>

<%= pb_rails("caption", props: {
text: object.contact_detail,
tag: 'span',
size: 'xs'
size: 'xs',
dark: object.dark
}) if object.contact_detail %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import Caption from "../pb_caption/_caption";
import Icon from "../pb_icon/_icon";

type DateRangeInlineProps = {
className?: string;
id?: string;
data?: string;
align?: "left" | "center" | "vertical";
size?: "sm" | "xs";
className?: string;
dark?: boolean;
htmlOptions?: {[key: string]: string | number | boolean | (() => any)};
data?: string;
endDate?: Date;
htmlOptions?: { [key: string]: string | number | boolean | (() => any) };
icon?: boolean;
id?: string;
size?: "sm" | "xs";
startDate?: Date;
endDate?: Date;
};

const dateTimestamp = (dateValue: Date, includeYear: boolean) => {
Expand All @@ -36,59 +36,36 @@ const dateTimeIso = (dateValue: Date) => {

const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
const {
icon = false,
dark = false,
size = "sm",
align = "left",
className,
dark = false,
data = {},
endDate,
htmlOptions = {},
icon = false,
size = "sm",
startDate,
endDate,
className,
} = props;

const iconContent = () => {
nidaqg marked this conversation as resolved.
Show resolved Hide resolved
return (
<>
{icon && (
<>
<Body color="light"
key={Math.random()}
tag="span"
>
<Icon
className="pb_date_range_inline_icon"
dark={dark}
fixedWidth
icon="calendar-alt"
size={size}
tag="span"
/>
</Body>
</>
)}
</>
);
};

const dateInCurrentYear = () => {
const currentDate = new Date();
return (
startDate.getFullYear() == endDate.getFullYear() &&
startDate.getFullYear() == currentDate.getFullYear()
startDate?.getFullYear() === endDate?.getFullYear() &&
startDate?.getFullYear() === currentDate.getFullYear()
);
};

const dateRangeClasses = buildCss("pb_date_range_inline_kit", align);
const dataProps = buildDataProps(data)
const htmlProps = buildHtmlProps(htmlOptions)
const dataProps = buildDataProps(data);
const htmlProps = buildHtmlProps(htmlOptions);

const renderTime = (date: Date) => {
return (
<time dateTime={dateTimeIso(date)}>
{dateInCurrentYear() ? (
<>{` ${dateTimestamp(date, false)} `}</>
` ${dateTimestamp(date, false)} `
) : (
<>{` ${dateTimestamp(date, true)} `}</>
` ${dateTimestamp(date, true)} `
)}
</time>
);
Expand All @@ -101,54 +78,84 @@ const DateRangeInline = (props: DateRangeInlineProps): React.ReactElement => {
className={classnames(dateRangeClasses, globalProps(props), className)}
>
<div className="pb_date_range_inline_wrapper">
{size == "xs" && (
{size === "xs" && (
<>
{iconContent()}
<Caption dark={dark}
tag="span"
>
{renderTime(startDate)}
{icon && (
<Caption
dark={dark}
tag="span">
<Icon
className="pb_date_range_inline_icon"
dark={dark}
fixedWidth
icon="calendar-alt"
size={size}
tag="span"
/>
</Caption>
)}
<Caption
dark={dark}
tag="span">
{renderTime(startDate!)}
</Caption>
<Caption dark={dark}
tag="span"
>
<Caption
dark={dark}
tag="span">
<Icon
className="pb_date_range_inline_arrow"
dark={dark}
fixedWidth
icon="long-arrow-right"
tag="span"
/>
</Caption>
<Caption dark={dark}
tag="span"
>
{renderTime(endDate)}
<Caption
dark={dark}
tag="span">
{renderTime(endDate!)}
</Caption>
</>
)}

{size == "sm" && (
{size === "sm" && (
<>
{iconContent()}
<Body dark={dark}
tag="span"
>
{renderTime(startDate)}
{icon && (
<Body
color={"light"}
dark={dark}
tag="span">
<Icon
className="pb_date_range_inline_icon"
dark={dark}
fixedWidth
icon="calendar-alt"
size={size}
tag="span"
/>
</Body>
)}
<Body
dark={dark}
tag="span">
{renderTime(startDate!)}
</Body>
<Body color="light"
dark={dark}
tag="span"
>
<Body
color={"light"}
dark={dark}
tag="span">
<Icon
className="pb_date_range_inline_arrow"
dark={dark}
fixedWidth
icon="long-arrow-right"
tag="span"
/>
</Body>
<Body dark={dark}
tag="span"
>
{renderTime(endDate)}
<Body
dark={dark}
tag="span">
{renderTime(endDate!)}
</Body>
</>
)}
Expand Down
Loading