Skip to content

Commit

Permalink
feat(display-heading): add sup/sub components
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcabrera committed Sep 5, 2017
1 parent 6fde7e4 commit 892f9a6
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ module.exports = {
components() {
return [
path.resolve('src/components/Typography/DisplayHeading/DisplayHeading.jsx'),
path.resolve('src/components/Typography/DisplayHeading/DisplayHeadingSup/DisplayHeadingSup.jsx'),
path.resolve('src/components/Typography/DisplayHeading/DisplayHeadingSub/DisplayHeadingSub.jsx'),
path.resolve('src/components/Typography/Heading/Heading.jsx'),
path.resolve('src/components/Typography/Heading/HeadingSup/HeadingSup.jsx'),
path.resolve('src/components/Typography/Heading/HeadingSub/HeadingSub.jsx')
Expand Down
6 changes: 6 additions & 0 deletions src/components/Typography/DisplayHeading/DisplayHeading.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react'
import PropTypes from 'prop-types'
import safeRest from '../../../safeRest'

import DisplayHeadingSup from './DisplayHeadingSup/DisplayHeadingSup'
import DisplayHeadingSub from './DisplayHeadingSub/DisplayHeadingSub'

import styles from './DisplayHeading.modules.scss'

const getClassName = invert => (
Expand Down Expand Up @@ -32,4 +35,7 @@ DisplayHeading.defaultProps = {
invert: false
}

DisplayHeading.Sup = DisplayHeadingSup
DisplayHeading.Sub = DisplayHeadingSub

export default DisplayHeading
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
@import '../../../scss/settings/responsive-grid';
@import '../../../scss/utility/responsive';

.baseHeadingSupSubScripts {
@include telus-font-family;
position: relative;
vertical-align: baseline;
}

.sup {
composes: baseHeadingSupSubScripts;
}

.sub {
composes: baseHeadingSupSubScripts;
}

.displayHeading {
composes: noSpacing from '../../Spacing.modules.scss';

Expand All @@ -11,10 +25,26 @@
font-size: 2.75rem;
line-height: 1.14; // 48px

.sup, .sub {
font-size: 1.25rem;
}

.sup {
top: -1.2em;
}

.sub {
bottom: -.5em;
}

@include from-breakpoint(medium) {
font-size: 4.5rem;
line-height: 1.11; // 80px
letter-spacing: .2px;

.sup {
top: -2.2em;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import PropTypes from 'prop-types'
import safeRest from '../../../../safeRest'

import styles from '../DisplayHeading.modules.scss'

/**
* Subscript text for headings.
*/
const DisplayHeadingSub = ({ children, ...rest }) => (
<sub {...safeRest(rest)} className={styles.sub}>{children}</sub>
)

DisplayHeadingSub.propTypes = {
children: PropTypes.string.isRequired
}

export default DisplayHeadingSub
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```
<div>
<DisplayHeading>Great Deals<DisplayHeading.Sub>1</DisplayHeading.Sub></DisplayHeading>
</div>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'

import DisplayHeadingSub from '../DisplayHeadingSub'

describe('DisplayHeadingSub', () => {
const doShallow = props => (
shallow(<DisplayHeadingSub {...props}>Some content</DisplayHeadingSub>)
)

it('renders', () => {
const displayHeadingSub = doShallow()

expect(toJson(displayHeadingSub)).toMatchSnapshot()
})

it('renders an HTML sub tag', () => {
const displayHeadingSub = doShallow()

expect(displayHeadingSub).toHaveTagName('sub')
})

it('passes additional attributes to the sup element', () => {
const displayHeadingSub = doShallow({ id: 'the-sub-text' })

expect(displayHeadingSub).toHaveProp('id', 'the-sub-text')
})

it('does not allow custom CSS', () => {
const displayHeadingSub = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } })

expect(displayHeadingSub).not.toHaveProp('className', 'my-custom-class')
expect(displayHeadingSub).not.toHaveProp('style')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DisplayHeadingSub renders 1`] = `
<sub
className="sub"
>
Some content
</sub>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import PropTypes from 'prop-types'
import safeRest from '../../../../safeRest'

import styles from '../DisplayHeading.modules.scss'

/**
* Superscript text for headings.
*/
const DisplayHeadingSup = ({ children, ...rest }) => (
<sup {...safeRest(rest)} className={styles.sup}>{children}</sup>
)

DisplayHeadingSup.propTypes = {
children: PropTypes.string.isRequired
}

export default DisplayHeadingSup
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```
<div>
<DisplayHeading>Great Deals<DisplayHeading.Sup>1</DisplayHeading.Sup></DisplayHeading>
</div>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'

import DisplayHeadingSup from '../DisplayHeadingSup'

describe('DisplayHeadingSup', () => {
const doShallow = props => (
shallow(<DisplayHeadingSup {...props}>Some content</DisplayHeadingSup>)
)

it('renders', () => {
const displayHeadingSup = doShallow()

expect(toJson(displayHeadingSup)).toMatchSnapshot()
})

it('renders an HTML sub tag', () => {
const displayHeadingSup = doShallow()

expect(displayHeadingSup).toHaveTagName('sup')
})

it('passes additional attributes to the sup element', () => {
const displayHeadingSup = doShallow({ id: 'the-sup-text' })

expect(displayHeadingSup).toHaveProp('id', 'the-sup-text')
})

it('does not allow custom CSS', () => {
const displayHeadingSup = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } })

expect(displayHeadingSup).not.toHaveProp('className', 'my-custom-class')
expect(displayHeadingSup).not.toHaveProp('style')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DisplayHeadingSup renders 1`] = `
<sup
className="sup"
>
Some content
</sup>
`;

0 comments on commit 892f9a6

Please sign in to comment.