-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(studio-root): seperated repeated html on ContactPage to Reac…
…t Component (#14169)
- Loading branch information
1 parent
fa38b1b
commit d67600e
Showing
7 changed files
with
181 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ jobs: | |
resource-adm | ||
resource-registry | ||
settings | ||
studio-root | ||
subform | ||
testing | ||
text | ||
|
40 changes: 40 additions & 0 deletions
40
frontend/studio-root/components/ContactSection/ContactSection.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.section { | ||
background-color: var(--colors-grey-100); | ||
border-radius: 4px; | ||
display: flex; | ||
gap: var(--fds-spacing-6); | ||
padding: var(--fds-spacing-8); | ||
max-width: 735px; | ||
} | ||
|
||
.iconContainer { | ||
background-color: var(--primary-color-700); | ||
border-radius: 100%; | ||
color: var(--colors-white); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 60px; | ||
width: 60px; | ||
box-sizing: border-box; | ||
} | ||
|
||
.icon { | ||
font-size: var(--fds-sizing-7); | ||
} | ||
|
||
.textContainer { | ||
flex: 1; | ||
} | ||
|
||
@media (min-width: 768px) { | ||
.section { | ||
padding: var(--fds-spacing-12); | ||
} | ||
} | ||
|
||
@media (min-width: 960px) { | ||
.section { | ||
padding-right: var(--fds-spacing-22); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
frontend/studio-root/components/ContactSection/ContactSection.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { ContactSection, type ContactSectionProps } from './ContactSection'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { SlackIcon } from '@studio/icons'; | ||
|
||
const defaultContactSectionProps: ContactSectionProps = { | ||
title: '', | ||
description: '', | ||
link: { | ||
name: '', | ||
href: '', | ||
}, | ||
Icon: SlackIcon, | ||
}; | ||
|
||
describe('ContactSection', () => { | ||
it('should render with provided props', () => { | ||
const props: ContactSectionProps = { | ||
...defaultContactSectionProps, | ||
title: 'Get in touch', | ||
description: 'We are helpfull', | ||
Icon: SlackIcon, | ||
link: { | ||
name: 'Get in touch', | ||
href: 'mailto:[email protected]', | ||
}, | ||
additionalContent: 'additional content', | ||
}; | ||
renderContactSection(props); | ||
|
||
const icon = screen.getByTitle(props.title); | ||
expect(icon).toBeInTheDocument(); | ||
|
||
const heading = screen.getByRole('heading', { name: props.title, level: 2 }); | ||
expect(heading).toBeInTheDocument(); | ||
|
||
const description = screen.getByText(props.description); | ||
expect(description).toBeInTheDocument(); | ||
|
||
const additionalContent = screen.getByText(props.additionalContent as string); | ||
expect(additionalContent).toBeInTheDocument(); | ||
|
||
const link = screen.getByRole('link', { name: props.link.name }); | ||
expect(link).toBeInTheDocument(); | ||
expect(link).toHaveAttribute('href', props.link.href); | ||
}); | ||
}); | ||
|
||
function renderContactSection(props: ContactSectionProps = defaultContactSectionProps): void { | ||
render(<ContactSection {...props} />); | ||
} |
38 changes: 38 additions & 0 deletions
38
frontend/studio-root/components/ContactSection/ContactSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { type ComponentType, type ReactElement, type ReactNode } from 'react'; | ||
import { StudioHeading, StudioLink, StudioParagraph } from '@studio/components'; | ||
import { type IconProps } from '@studio/icons'; | ||
import classes from './ContactSection.module.css'; | ||
|
||
export type ContactSectionProps = { | ||
title: string; | ||
description: string; | ||
link: { | ||
name: string; | ||
href: string; | ||
}; | ||
Icon: ComponentType<IconProps>; | ||
additionalContent?: ReactNode; | ||
}; | ||
export const ContactSection = ({ | ||
title, | ||
description, | ||
link, | ||
Icon, | ||
additionalContent, | ||
}: ContactSectionProps): ReactElement => { | ||
return ( | ||
<section className={classes.section}> | ||
<div className={classes.iconContainer}> | ||
<Icon className={classes.icon} title={title} aria-hidden /> | ||
</div> | ||
<div className={classes.textContainer}> | ||
<StudioHeading level={2} size='xs' spacing> | ||
{title} | ||
</StudioHeading> | ||
<StudioParagraph spacing>{description}</StudioParagraph> | ||
{additionalContent && <span>{additionalContent}</span>} | ||
<StudioLink href={link.href}>{link.name}</StudioLink> | ||
</div> | ||
</section> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ContactSection, type ContactSectionProps } from './ContactSection'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters