Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into disabled-qr
Browse files Browse the repository at this point in the history
  • Loading branch information
kwinto committed Dec 12, 2023
2 parents 7b5a7ac + 454c82e commit a69f0df
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 54 deletions.
15 changes: 0 additions & 15 deletions src/common/ActionButtons/ActionButton.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ a.button {
outline: none;
}

button.button span,
a.button span {
font-weight: 600;
font-size: 14px;
line-height: 160%;
font-family: inherit;
}

button.button.large span,
a.button.large span {
font-size: 16px;
font-style: normal;
line-height: 140%;
}

button.button svg,
a.button svg,
button.button path,
Expand Down
9 changes: 6 additions & 3 deletions src/common/ActionButtons/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { sanitizeHTML } from "src/sanitize";
import { sanitizeUrl } from "@braintree/sanitize-url";
import classes from "./ActionButton.module.css";
import { LinkIcon } from "src/assets/svg";
import { MessageProps } from "src/index";
import { MessageProps, Typography } from "src/index";

interface ActionButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
action?: ActionButtonsProps["action"];
Expand Down Expand Up @@ -116,15 +116,18 @@ const ActionButton: FC<ActionButtonProps> = props => {
className={classnames(
classes.button,
isWebURL && classes.url,
size === "large" && classes.large,
props.className,
disabled && classes.disabled,
)}
aria-label={ariaLabel}
aria-disabled={disabled}
role={isWebURL ? "link" : undefined}
>
<span dangerouslySetInnerHTML={{ __html }} />
<Typography
variant={size === "large" ? "title1-regular" : "cta-semibold"}
component="span"
dangerouslySetInnerHTML={{ __html }}
/>
{renderIcon()}
</Component>
);
Expand Down
2 changes: 0 additions & 2 deletions src/common/MessageHeader.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ article .header.ongoing {
}

article .header .headerMeta {
font-size: 12px;
line-height: 140%;
display: flex;
gap: 8px;
align-items: center;
Expand Down
5 changes: 3 additions & 2 deletions src/common/MessageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classnames from "classnames";
import { useMessageContext } from "src/messages/hooks";
import Avatar from "./Avatar";
import { HeaderEllipsis } from "src/assets/svg";
import Typography from "./Typography/Typography";

interface MessageHeaderProps {
enableAvatar?: boolean;
Expand Down Expand Up @@ -32,7 +33,7 @@ const MessageHeader: FC<MessageHeaderProps> = props => {
return (
<header className={className} data-testid="message-header">
{props.enableAvatar && <Avatar />}
<div className={classes.headerMeta}>
<Typography variant="title2-regular" component="div" className={classes.headerMeta}>
{!isUserMessage && (
<>
<span className={classes["avatar-name"]}>
Expand All @@ -49,7 +50,7 @@ const MessageHeader: FC<MessageHeaderProps> = props => {
})}
</time>
</span>
</div>
</Typography>
</header>
);
};
Expand Down
23 changes: 19 additions & 4 deletions src/common/Typography/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { CSSProperties, FC, ReactNode } from "react";
import classes from "./Typography.module.css";
import classnames from "classnames";

interface TypographyProps extends CSSProperties {
export interface TypographyProps extends CSSProperties {
variant?: TagVariants;
children: ReactNode;
children?: ReactNode;
className?: string;
style?: CSSProperties;
component?: keyof JSX.IntrinsicElements;
dangerouslySetInnerHTML?: { __html: string | TrustedHTML } | undefined;
id?: string;
}

type TagVariants =
Expand Down Expand Up @@ -45,14 +48,26 @@ const colorsMapping: Record<ColorVariants, string> = {
};

const Typography: FC<TypographyProps> = props => {
const { variant = "body-regular", children, component, className, color, ...restProps } = props;
const {
variant = "body-regular",
children,
component,
className,
style,
color,
dangerouslySetInnerHTML,
id,
...restProps
} = props;
const Component = component ?? variantsMapping[variant];
const typographyColor = colorsMapping[color as ColorVariants] ?? color;

return (
<Component
className={classnames(classes[variant], className, color)}
style={{ color: typographyColor, ...restProps }}
style={{ color: typographyColor, ...style, ...restProps }}
dangerouslySetInnerHTML={dangerouslySetInnerHTML}
id={id}
>
{children}
</Component>
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { match } from "./matcher";
import ActionButtons from "./common/ActionButtons/ActionButtons";
import Message, { MessageProps } from "./messages/Message";
import TypingIndicator from "./common/TypingIndicator";
import Typography from "./common/Typography/Typography";
import Typography, { TypographyProps } from "./common/Typography/Typography";

import "@fontsource/figtree/400.css";
import "@fontsource/figtree/400-italic.css";
Expand All @@ -15,4 +15,4 @@ import "@fontsource/figtree/700-italic.css";

export { Message, match, ActionButtons, TypingIndicator, Typography };

export type { MessageProps };
export type { MessageProps, TypographyProps };
6 changes: 0 additions & 6 deletions src/messages/Gallery/Gallery.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,12 @@
margin: 0px;
left: 8px;
bottom: 10px;
font-size: 14px;
font-weight: 600;
line-height: 130%;
color: var(--white);
}

.slideItem .bottom p {
padding: 0px;
margin: 0px;
font-size: 14px;
font-weight: 400;
line-height: 140%;
}

/*
Expand Down
8 changes: 6 additions & 2 deletions src/messages/Gallery/GalleryItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ActionButtons from "src/common/ActionButtons/ActionButtons";
import { sanitizeHTML } from "src/sanitize";
import { getRandomId } from "src/utils";
import { sanitizeUrl } from "@braintree/sanitize-url";
import { Typography } from "src/index";

export interface GallerySlideProps {
slide: IWebchatAttachmentElement;
Expand Down Expand Up @@ -50,7 +51,9 @@ const GalleryItem: FC<GallerySlideProps> = props => {
return (
<div className={classnames("webchat-carousel-template-frame", classes.slideItem)}>
<div className={classnames(classes.top, hasExtraInfo && classes.hasExtraInfo)}>
<h2
<Typography
variant="body-semibold"
component="h2"
dangerouslySetInnerHTML={{ __html: titleHtml }}
className="webchat-carousel-template-title"
id={titleId}
Expand Down Expand Up @@ -78,7 +81,8 @@ const GalleryItem: FC<GallerySlideProps> = props => {
aria-label={default_action?.url ? `${titleHtml}. Opens in new tab` : undefined}
>
{subtitle && (
<p
<Typography
variant="body-regular"
dangerouslySetInnerHTML={{ __html: subtitleHtml }}
id={subtitleId}
className="webchat-carousel-template-subtitle"
Expand Down
15 changes: 1 addition & 14 deletions src/messages/List/List.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,19 @@ article .wrapper {
color: var(--white);
}

.itemTitleHeader {
margin-top: 0px;
margin-bottom: 0px;
font-size: 18px;
font-weight: 600;
line-height: 130%;
}

.itemTitle {
margin-top: 0px;
margin-bottom: 0px;
font-size: 16px;
font-weight: 600;
line-height: 140%;
}

.itemTitleWithSubtitle {
margin-top: 0px;
margin-bottom: 8px;
}

.itemSubtitle {
margin-top: 0px;
margin-bottom: 0px;
font-size: 14px;
font-weight: 400;
line-height: 140%;
}

.itemSubtitle.ignoreWS {
Expand Down
11 changes: 7 additions & 4 deletions src/messages/List/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PrimaryButton, SecondaryButton } from "src/common/ActionButtons";
import classnames from "classnames";
import { sanitizeUrl } from "@braintree/sanitize-url";
import { IWebchatAttachmentElement } from "@cognigy/socket-client";
import { Typography } from "src/index";

const ListItem: FC<{ element: IWebchatAttachmentElement; isHeaderElement?: boolean }> = props => {
const { action, config } = useMessageContext();
Expand Down Expand Up @@ -62,19 +63,21 @@ const ListItem: FC<{ element: IWebchatAttachmentElement; isHeaderElement?: boole
return (
<>
{titleHtml && (
<h2
<Typography
variant={isHeaderElement ? "h2-semibold" : "title1-semibold"}
component="h2"
dangerouslySetInnerHTML={{ __html: titleHtml }}
className={classnames(
isHeaderElement
? "webchat-list-template-header-title"
: "webchat-list-template-element-title",
isHeaderElement ? classes.itemTitleHeader : classes.itemTitle,
subtitleHtml && classes.itemTitleWithSubtitle,
subtitleHtml ? classes.itemTitleWithSubtitle : classes.itemTitle,
)}
/>
)}
{subtitleHtml && (
<p
<Typography
variant="body-regular"
dangerouslySetInnerHTML={{ __html: subtitleHtml }}
id={subtitleId}
className={classnames(
Expand Down

0 comments on commit a69f0df

Please sign in to comment.