Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/components/Page/Web.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,19 @@ const PopoverTemplate: ComponentStory<typeof Page> = args => {
return (
<>
<Page
dataAttributes={{
title: {
"data-test-id": "title-test",
},
intro: {
"data-test-id": "intro-test",
},
}}
primaryAction={{
label: "Trigger Food Popover",
onClick: () => setShowPrimaryPopover(true),
ref: primaryDivRef,
"data-test-id": "primary-action",
}}
secondaryAction={{
label: "Trigger Drink Popover",
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useButtonStyles } from "./useButtonStyles";
// eslint-disable-next-line import/no-deprecated
import { ButtonContent, ButtonIcon, ButtonLabel } from "./ButtonInternals";
import { ButtonProvider } from "./ButtonProvider";
import { filterDataAttributes } from "../sharedHelpers/filterDataAttributes";

function Button(props: ButtonProps) {
const { size } = props;
Expand Down Expand Up @@ -38,13 +39,15 @@ function ButtonWrapper(props: ButtonProps) {
UNSAFE_className = {},
UNSAFE_style = {},
children,
...rest
} = props;

const { combined } = useButtonStyles(props);

const buttonType: HTMLButtonType = submit ? "submit" : "button";

const buttonClassNames = classnames(combined, UNSAFE_className.container);
const dataAttributes = filterDataAttributes(rest);

const tagProps = {
className: buttonClassNames,
Expand All @@ -66,6 +69,7 @@ function ButtonWrapper(props: ButtonProps) {
"aria-expanded": ariaExpanded,
"aria-label": ariaLabel,
role: role,
...dataAttributes,
};

const buttonInternals = children || <ButtonContent {...props} />;
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/Heading/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ReactNode } from "react";
import React from "react";
import type { TypographyOptions, TypographyProps } from "../Typography";
import { Typography } from "../Typography";
import { filterDataAttributes } from "../sharedHelpers/filterDataAttributes";

type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;

Expand Down Expand Up @@ -59,7 +60,9 @@ export function Heading({
maxLines = "unlimited",
UNSAFE_className,
UNSAFE_style,
...rest
}: HeadingProps) {
const dataAttributes = filterDataAttributes(rest);
const levelMap: LevelMap = {
1: {
element: "h1",
Expand Down Expand Up @@ -117,6 +120,7 @@ export function Heading({
numberOfLines={maxLineToNumber[maxLines]}
UNSAFE_className={UNSAFE_className}
UNSAFE_style={UNSAFE_style}
{...dataAttributes}
>
{children}
</Typography>
Expand Down
17 changes: 14 additions & 3 deletions packages/components/src/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Markdown } from "../Markdown";
import { Button, type ButtonProps } from "../Button";
import { Menu, type SectionProps } from "../Menu";
import { Emphasis } from "../Emphasis";
import type { CommonAtlantisProps } from "../sharedHelpers/types";

export type ButtonActionProps = ButtonProps & {
ref?: React.RefObject<HTMLDivElement>;
Expand Down Expand Up @@ -68,6 +69,11 @@ interface PageFoundationProps {
* Page title Action menu.
*/
readonly moreActionsMenu?: SectionProps[];

readonly dataAttributes?: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we would likely document either in the JSDoc, and on our main docs that this is a temporary/holdover pattern and that the preferred way is to simply use data attributes normally on components.

we would also want to include something either or on the props tables or descriptions for components and sub components stating that data attributes exist. maybe one day it would just be assumed they are available but while it's new and not readily available, having that noted would be nice.

title: CommonAtlantisProps["dataAttributes"];
intro: CommonAtlantisProps["dataAttributes"];
};
}

interface PageWithIntroProps extends PageFoundationProps {
Expand Down Expand Up @@ -101,6 +107,7 @@ export function Page({
primaryAction,
secondaryAction,
moreActionsMenu = [],
dataAttributes,
}: PageProps) {
const pageStyles = classnames(styles.page, styles[width]);
const [titleBarRef, { width: titleBarWidth = Breakpoints.large }] =
Expand Down Expand Up @@ -141,11 +148,15 @@ export function Page({
<div>
{typeof title === "string" && titleMetaData ? (
<div className={styles.titleRow}>
<Heading level={1}>{title}</Heading>
<Heading level={1} {...dataAttributes?.title}>
{title}
</Heading>
{titleMetaData}
</div>
) : typeof title === "string" ? (
<Heading level={1}>{title}</Heading>
<Heading level={1} {...dataAttributes?.title}>
{title}
</Heading>
) : (
title
)}
Expand Down Expand Up @@ -183,7 +194,7 @@ export function Page({
)}
</div>
{intro && (
<Text size="large">
<Text size="large" {...dataAttributes?.intro}>
<Markdown
content={intro}
basicUsage={true}
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { PropsWithChildren } from "react";
import React from "react";
import type { TypographyOptions, TypographyProps } from "../Typography";
import { Typography } from "../Typography";
import { filterDataAttributes } from "../sharedHelpers/filterDataAttributes";

type TextElement = Extract<
TypographyProps["element"],
Expand Down Expand Up @@ -62,7 +63,9 @@ export function Text({
maxLines = "unlimited",
UNSAFE_className,
UNSAFE_style,
...rest
}: PropsWithChildren<TextProps>) {
const dataAttributes = filterDataAttributes(rest);
const textColors = {
default: "text",
subdued: "textSecondary",
Expand Down Expand Up @@ -91,6 +94,7 @@ export function Text({
align={align}
UNSAFE_className={UNSAFE_className}
UNSAFE_style={UNSAFE_style}
{...dataAttributes}
>
{children}
</Typography>
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/Typography/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import alignment from "./css/TextAlignment.module.css";
import fontFamilies from "./css/FontFamilies.module.css";
import underlineStyles from "./css/Underline.module.css";
import type { UnderlineStyle, UnderlineStyleWithColor } from "./types";
import { filterDataAttributes } from "../sharedHelpers/filterDataAttributes";

export interface TypographyProps {
readonly id?: string;
Expand Down Expand Up @@ -94,7 +95,9 @@ export function Typography({
underline,
UNSAFE_className,
UNSAFE_style,
...rest
}: TypographyProps) {
const dataAttributes = filterDataAttributes(rest);
const shouldTruncateText = numberOfLines && numberOfLines > 0;
const className = classnames(
styles.base,
Expand Down Expand Up @@ -130,6 +133,7 @@ export function Typography({
...underlineInlineStyles,
...UNSAFE_style?.textStyle,
}}
{...dataAttributes}
>
{children}
</Tag>
Expand Down
Loading