-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notification): Introduce components to color text and links for …
…error notifications. Add a Paragraph and ColoredText component to provide inherited color through React context.
- Loading branch information
1 parent
a2a5736
commit d228b29
Showing
13 changed files
with
232 additions
and
68 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
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 |
---|---|---|
|
@@ -53,3 +53,12 @@ | |
color: $color-white; | ||
} | ||
} | ||
|
||
.inheritColor { | ||
composes: underlineOnHover; | ||
|
||
&:link, | ||
&:visited { | ||
color: inherit; | ||
} | ||
} |
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
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,31 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
class ColoredText extends React.Component { | ||
getChildContext() { | ||
return { | ||
inheritColor: true | ||
} | ||
} | ||
|
||
render() { | ||
const { colorClassName, children } = this.props | ||
|
||
return ( | ||
<div className={colorClassName}> | ||
{children} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
ColoredText.propTypes = { | ||
colorClassName: PropTypes.string.isRequired, | ||
children: PropTypes.node.isRequired | ||
} | ||
|
||
ColoredText.childContextTypes = { | ||
inheritColor: PropTypes.bool | ||
} | ||
|
||
export default ColoredText |
21 changes: 21 additions & 0 deletions
21
src/components/Typography/ColoredText/__tests__/ColoredText.spec.jsx
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,21 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
|
||
import ColoredText from '../ColoredText' | ||
import Paragraph from '../../Paragraph/Paragraph' | ||
import Link from '../../../Link/Link' | ||
|
||
describe('ColoredText', () => { | ||
it('allows text components to inherit their color', () => { | ||
const coloredText = mount( | ||
<ColoredText colorClassName="some-class-name"> | ||
<Paragraph> | ||
Some content and a <Link>hyperlink</Link> | ||
</Paragraph> | ||
</ColoredText> | ||
) | ||
|
||
expect(coloredText.find('p')).toHaveClassName('inheritColor') | ||
expect(coloredText.find('a')).toHaveClassName('inheritColor') | ||
}) | ||
}) |
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,36 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import classnames from 'classnames' | ||
|
||
import styles from './Paragraph.modules.scss' | ||
|
||
const Paragraph = ({ bold, children }, context) => { | ||
const classes = classnames( | ||
styles.base, | ||
context.inheritColor ? styles.inheritColor : styles.color, | ||
{ | ||
[styles.bold]: bold | ||
} | ||
) | ||
|
||
return ( | ||
<p className={classes}> | ||
{children} | ||
</p> | ||
) | ||
} | ||
|
||
Paragraph.propTypes = { | ||
bold: PropTypes.bool, | ||
children: PropTypes.node.isRequired | ||
} | ||
|
||
Paragraph.defaultProps = { | ||
bold: false | ||
} | ||
|
||
Paragraph.contextTypes = { | ||
inheritColor: PropTypes.bool | ||
} | ||
|
||
export default Paragraph |
25 changes: 25 additions & 0 deletions
25
src/components/Typography/Paragraph/Paragraph.modules.scss
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,25 @@ | ||
$tds-style-typography-html-tags: false; | ||
|
||
@import '../../../scss/settings/colours'; | ||
@import '../../../scss/utility/responsive'; | ||
@import '../../../scss/settings/responsive-grid'; | ||
@import '../../../scss/settings/typography'; | ||
@import '../../../scss/foundation/typography'; | ||
|
||
.base { | ||
@extend %text--medium; | ||
|
||
margin: 0; | ||
} | ||
|
||
.bold { | ||
@extend %strong; | ||
} | ||
|
||
.color { | ||
color: $color-text; | ||
} | ||
|
||
.inheritColor { | ||
color: inherit; | ||
} |
Oops, something went wrong.