This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
3,449 additions
and
3,722 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
15 changes: 7 additions & 8 deletions
15
src/components/Page/Content.js → src/components/Page/Content.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from 'react' | ||
import getValidProps from '@helpscout/react-utils/dist/getValidProps' | ||
import { COMPONENT_KEY } from './utils' | ||
import { classNames } from '../../utilities/classNames' | ||
import { namespaceComponent } from '../../utilities/component' | ||
import { HeadingUI, SecondaryHeadingUI } from './styles/Heading.css' | ||
|
||
export interface Props { | ||
children?: any | ||
className?: string | ||
secondary?: boolean | ||
} | ||
|
||
class Heading extends React.PureComponent<Props> { | ||
static defaultProps = { | ||
secondary: false | ||
} | ||
|
||
render() { | ||
const { children, secondary, className, ...rest } = this.props | ||
|
||
const componentClassName = classNames( | ||
'c-PageHeader__titleHeading', | ||
secondary && 'c-PageHeader__titleHeading--secondary', | ||
className | ||
) | ||
|
||
return !secondary ? ( | ||
<HeadingUI {...getValidProps(rest)} | ||
selector="h1" | ||
size="md" | ||
className={componentClassName}> | ||
{children} | ||
</HeadingUI> | ||
) : ( | ||
<SecondaryHeadingUI {...getValidProps(rest)} | ||
selector="h2" | ||
size="h4" | ||
className={componentClassName}> | ||
{children} | ||
</SecondaryHeadingUI> | ||
); | ||
} | ||
} | ||
namespaceComponent(COMPONENT_KEY.Heading)(Heading) | ||
|
||
export default Heading |
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
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,42 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import Heading from '../Heading' | ||
|
||
describe('ClassName', () => { | ||
test('Has default className', () => { | ||
const wrapper = mount(<Heading>Heisenberg shop</Heading>) | ||
|
||
expect(wrapper.hasClass('c-PageHeader__titleHeading')).toBe(true) | ||
}) | ||
|
||
test('Has Secondary className', () => { | ||
const wrapper = mount(<Heading secondary>Beakers</Heading>) | ||
|
||
expect(wrapper.hasClass('c-PageHeader__titleHeading--secondary')).toBe(true) | ||
}) | ||
|
||
test('Applies custom className if specified', () => { | ||
const className = 'baby-blue' | ||
const wrapper = mount( | ||
<Heading className={className}>Heisenberg shop</Heading> | ||
) | ||
|
||
expect(wrapper.hasClass(className)).toBe(true) | ||
}) | ||
}) | ||
|
||
describe('Primary: h1', () => { | ||
test('Default is primary heading (h1)', () => { | ||
const wrapper = mount(<Heading>Heisenberg Shop</Heading>) | ||
|
||
expect(wrapper.find('h1').length).toBe(1) | ||
}) | ||
}) | ||
|
||
describe('Secondary: h2', () => { | ||
test('Secondary renders an h2', () => { | ||
const wrapper = mount(<Heading secondary>Beakers</Heading>) | ||
|
||
expect(wrapper.find('h2').length).toBe(1) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Heading | ||
|
||
This component leverages `<Heading>` for use inside [`Page`](./Page.md) components. | ||
|
||
Pages usually have one [`Header`](./Header.md), whose contents are always a title and sometimes a subtitle, for the title `<Page.Header>` uses this component in _primary_ mode, which means the heading will be an `<h1>` element. | ||
|
||
_Secondary_ mode is for additional headings within a page and will be rendered as `<h2>` elements. | ||
|
||
Styles (spacing and font sizes) are handled specifically for use within Pages. | ||
|
||
## Example | ||
|
||
```jsx | ||
<Page> | ||
<Page.Card> | ||
<Page.Header | ||
title="Contact Form" | ||
subtitle="Fill out everything please. K thx." | ||
/> | ||
<Page.Heading secondary>Contact Details</Page.Heading> | ||
... | ||
<Page.Heading secondary>Address Details</Page.Heading> | ||
... | ||
</Page.Card> | ||
</Page> | ||
``` | ||
|
||
## Props | ||
|
||
| Prop | Type | Description | | ||
| ---------------- | --------- | --------------------------------------------------- | | ||
| className | `string` | Custom class names to be added to the component. | | ||
| secondary | `boolean` | Signals a secondary (h2) heading. Default `false`. | |
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
Oops, something went wrong.