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

Migrate Container and Content components to Typescript #1803

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
exports[`ColorSection > should render with required props 1`] = `
<React.Fragment>
<Content
className=""
columns={
[
<div>
Expand Down Expand Up @@ -31,12 +30,10 @@ exports[`ColorSection > should render with required props 1`] = `
]
}
hasTitleUnderline={true}
isFullViewportHeight={false}
theme="white"
title="Colors"
/>
<Content
className=""
columns={
[
<Swatch
Expand All @@ -49,8 +46,6 @@ exports[`ColorSection > should render with required props 1`] = `
/>,
]
}
hasTitleUnderline={false}
isFullViewportHeight={false}
theme="white"
title="Other On-Brand Colors"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`FontSection > should render with required props 1`] = `
<Content
className=""
columns={
[
<ul
Expand Down Expand Up @@ -60,7 +59,6 @@ exports[`FontSection > should render with required props 1`] = `
]
}
hasTitleUnderline={true}
isFullViewportHeight={false}
theme="gray"
title="Typography"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`LogoSection > should render with required props 1`] = `
<Content
className=""
columns={
[
<ul
Expand Down Expand Up @@ -338,7 +337,6 @@ exports[`LogoSection > should render with required props 1`] = `
]
}
hasTitleUnderline={true}
isFullViewportHeight={false}
theme="gray"
title="Logo"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
import { bool, node, number, oneOf, oneOfType, string } from 'prop-types';
// import { bool, node, number, oneOf, oneOfType, string } from 'prop-types';
import classNames from 'classnames';
recondesigns marked this conversation as resolved.
Show resolved Hide resolved
import { getDataAttributes } from 'common/utils/prop-utils';
import styles from './Container.module.css';

Container.propTypes = {
backgroundImageSource: string,
children: node,
className: string,
id: oneOfType([string, number]),
isFullViewportHeight: bool,
theme: oneOf(['gray', 'secondary', 'white']),
export type ContainerPropsType = {
/**
* Sets the path for an optional background image.
*/
backgroundImageSource?: string;
/**
* Content to be rendered in the Container.
*/
children?: React.ReactNode;
/**
* Applies style classes to the wrapping div.
*/
className?: string;
/**
* Applies an id to the container.
*/
id?: string;
/**
* Sets the height of the container to be full viewport height.
* @default false
*/
isFullViewportHeight?: boolean;
/**
* Applies the color theme.
* @default secondary
*/
theme?: 'gray' | 'secondary' | 'white';
};

Container.defaultProps = {
backgroundImageSource: undefined,
children: undefined,
className: undefined,
id: undefined,
isFullViewportHeight: false,
theme: 'secondary',
};

function Container(props) {
const { backgroundImageSource, children, className, id, isFullViewportHeight, theme } = props;
function Container(props: ContainerPropsType) {
const {
backgroundImageSource,
children,
className,
id,
isFullViewportHeight = false,
theme = 'secondary',
} = props;
// See https://css-tricks.com/tinted-images-multiple-backgrounds/ for explanation
const darkOverlay = 'linear-gradient(rgba(33, 48, 69, 0.65),rgba(33, 48, 69, 0.65))';
const dynamicBackgroundImage = backgroundImageSource
Expand Down
15 changes: 0 additions & 15 deletions components/Container/__stories__/Container.stories.js

This file was deleted.

19 changes: 19 additions & 0 deletions components/Container/__stories__/Container.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Meta, StoryObj } from '@storybook/react';
import { descriptions } from 'common/constants/descriptions';
import Container from '../Container';

type ContainerStoryType = StoryObj<typeof Container>;

const meta: Meta<typeof Container> = {
title: 'Container',
component: Container,
args: {
children: descriptions.long,
},
};

export default meta;

export const Default: ContainerStoryType = {
render: args => <Container {...args} />,
};
55 changes: 0 additions & 55 deletions components/Content/Content.js

This file was deleted.

70 changes: 70 additions & 0 deletions components/Content/Content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { cloneElement, ReactElement } from 'react';
import Container from 'components/Container/Container';
import Heading from 'components/Heading/Heading';

export type ContentPropsType = {
/**
* Elements to be rendered in the container.
*/
columns: React.ReactNode[];
/**
* Sets the path for an optional background image.
*/
backgroundImageSource?: string;
/**
* Applies style classes to the wrapping div.
*/
className?: string;
/**
* Displays an optional line under the title.
*/
hasTitleUnderline?: boolean;
/**
* Applies an id to the container.
*/
id?: string;
/**
* Sets the height of the container to be full viewport height.
* @default false
*/
isFullViewportHeight?: boolean;
/**
* Applies the color theme.
* @default secondary
*/
theme?: 'gray' | 'secondary' | 'white';
/**
* Applies an additional title element.
*/
title?: string;
};

function Content({
className,
columns,
hasTitleUnderline = false,
id,
isFullViewportHeight = false,
theme = 'secondary',
title,
backgroundImageSource,
}: ContentPropsType) {
return (
<Container
backgroundImageSource={backgroundImageSource}
className={className}
id={id}
isFullViewportHeight={isFullViewportHeight}
theme={theme}
>
{title && <Heading text={title} hasTitleUnderline={hasTitleUnderline} headingLevel={3} />}

<div className="flex justify-center items-center flex-wrap w-full [&>*]:m-4">
{/* eslint-disable-next-line react/no-array-index-key */}
{columns.map((column, index) => cloneElement(column as ReactElement<any>, { key: index }))}
</div>
</Container>
);
}

export default Content;
35 changes: 0 additions & 35 deletions components/Content/__stories__/Content.stories.js

This file was deleted.

45 changes: 45 additions & 0 deletions components/Content/__stories__/Content.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Meta, StoryObj } from '@storybook/react';
import Content from '../Content';

type ContentStoryType = StoryObj<typeof Content>;

const multiColumnArray = [
<div>
<p>Column 1</p>
</div>,
<div>
<p>Column 2</p>
</div>,
<div>
<p>Column 3</p>
</div>,
];

const meta: Meta<typeof Content> = {
title: 'Content',
component: Content,
args: {
columns: multiColumnArray.slice(0, 1),
title: 'One column content',
},
};

export default meta;

/**
* Default Content supplied with only one column
*/
export const Default: ContentStoryType = {
render: args => <Content {...args} />,
};

/**
* Content supplied with multiple columns
*/
export const MultipleColumns: ContentStoryType = {
...Default,
args: {
columns: multiColumnArray,
title: 'Multiple column content',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
exports[`DonateSection > should render with no props passed passed 1`] = `
<Container
backgroundImageSource="https://operation-code-assets.s3.us-east-2.amazonaws.com/background_flag.jpg"
isFullViewportHeight={false}
theme="secondary"
>
<Heading
hasHashLink={true}
Expand Down
Loading