Skip to content

Commit 797e6e1

Browse files
elissa-matsushitajraff
authored andcommitted
feat(community-callout-paragraph): add icon support
1 parent d191604 commit 797e6e1

5 files changed

Lines changed: 100 additions & 7 deletions

File tree

docs/setup/tds-core-globals.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Spinner from '@tds/core-spinner'
1818
import { Edit, Print } from '@tds/core-interactive-icon'
1919
import A11yContent from '@tds/core-a11y-content'
2020
import WebVideo from '@tds/core-web-video'
21+
import { Deals } from '@tds/core-decorative-icon'
2122

2223
Object.assign(global, {
2324
A11yContent,
@@ -41,4 +42,5 @@ Object.assign(global, {
4142
Edit,
4243
Print,
4344
WebVideo,
45+
Deals,
4446
})

packages/CalloutParagraph/CalloutParagraph.jsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
33
import styled from 'styled-components'
44

55
import { safeRest } from '@tds/util-helpers'
6+
import { componentWithName } from '@tds/util-prop-types'
67

78
import Paragraph from '@tds/core-paragraph'
89
import { colorTelusPurple } from '@tds/core-colours'
@@ -45,6 +46,7 @@ const TextWrapper = styled.div`
4546
}
4647
width: ${props => (props.roundedCorners ? '100%' : undefined)};
4748
p {
49+
position: relative;
4850
text-align: ${props => (props.roundedCorners ? 'center' : undefined)};
4951
font-size: ${props => (props.compact ? '14px' : '1rem')};
5052
line-height: ${props => (props.compact ? '20px' : undefined)};
@@ -59,17 +61,44 @@ const TextWrapper = styled.div`
5961
padding-left: ${props => paddingValue.mobile[props.spacing]};
6062
padding-right: ${props => paddingValue.mobile[props.spacing]};
6163
}
64+
> i {
65+
margin-right: 1rem;
66+
position: absolute;
67+
left: 10px;
68+
}
69+
> span {
70+
display: inline-block;
71+
margin-left: ${props => props.margin};
72+
}
6273
}
6374
`
6475

76+
const iconMargin = (spacingLevel, hasIcon) => {
77+
if (hasIcon) {
78+
if (spacingLevel === 'compact') {
79+
return '1.5rem'
80+
}
81+
return '1rem'
82+
}
83+
return undefined
84+
}
85+
6586
/**
6687
* @version ./package.json
6788
* @visibleName CalloutParagraph (beta)
6889
*/
69-
const CalloutParagraph = ({ children, spacing, roundedCorners, compact, ...rest }) => {
90+
const CalloutParagraph = ({ children, spacing, roundedCorners, compact, icon: Icon, ...rest }) => {
7091
return (
71-
<TextWrapper spacing={spacing} roundedCorners={roundedCorners} compact={compact}>
72-
<Paragraph {...safeRest(rest)}>{children}</Paragraph>
92+
<TextWrapper
93+
spacing={spacing}
94+
roundedCorners={roundedCorners}
95+
compact={compact}
96+
margin={iconMargin(spacing, Icon)}
97+
>
98+
<Paragraph {...safeRest(rest)}>
99+
{Icon && <Icon />}
100+
<span>{children}</span>
101+
</Paragraph>
73102
</TextWrapper>
74103
)
75104
}
@@ -92,12 +121,17 @@ CalloutParagraph.propTypes = {
92121
* Font size and padding around text will be smaller.
93122
*/
94123
compact: PropTypes.bool,
124+
/**
125+
* Provide an icon from the Dependent icon group in `@tds/core-interactive-icon`.
126+
*/
127+
icon: componentWithName('Decorative', true),
95128
}
96129

97130
CalloutParagraph.defaultProps = {
98131
spacing: 'default',
99132
roundedCorners: false,
100133
compact: false,
134+
icon: undefined,
101135
}
102136

103137
export default CalloutParagraph

packages/CalloutParagraph/CalloutParagraph.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@
4545
</FlexGrid>
4646
```
4747

48+
### Icons
49+
50+
- Icon will be displayed before text
51+
- Must be valid TDS SVGIcon name. Refer to TDS documentation for full list
52+
53+
```jsx
54+
<FlexGrid>
55+
<FlexGrid.Row>
56+
<FlexGrid.Col xs={12} md={7} lg={6} xl={5}>
57+
<FlexGrid.Row>
58+
<FlexGrid.Col xl={11}>
59+
<CalloutParagraph bold spacing="compact" icon={Deals}>
60+
Order online for a $300 bill credit.
61+
</CalloutParagraph>
62+
</FlexGrid.Col>
63+
</FlexGrid.Row>
64+
</FlexGrid.Col>
65+
</FlexGrid.Row>
66+
</FlexGrid>
67+
```
68+
4869
### Compact
4970

5071
```jsx

packages/CalloutParagraph/__tests__/CalloutParagraph.spec.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import { shallow } from 'enzyme'
3+
import { Deals } from '@tds/core-decorative-icon'
34

45
import CalloutParagraph from '../CalloutParagraph'
56

@@ -32,4 +33,10 @@ describe('CalloutParagraph', () => {
3233
expect(calloutParagraph).toMatchSnapshot()
3334
expect(calloutParagraph).toHaveProp('spacing', 'intermediate')
3435
})
36+
37+
it('renders an icon', () => {
38+
const calloutParagraph = doShallow({ icon: Deals })
39+
expect(calloutParagraph).toMatchSnapshot()
40+
expect(calloutParagraph.find('DecorativeIcon')).toExist()
41+
})
3542
})

packages/CalloutParagraph/__tests__/__snapshots__/CalloutParagraph.spec.jsx.snap

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,30 @@ exports[`CalloutParagraph renders 1`] = `
1212
invert={false}
1313
size="medium"
1414
>
15-
Text
15+
<span>
16+
Text
17+
</span>
18+
</Paragraph>
19+
</CalloutParagraph__TextWrapper>
20+
`;
21+
22+
exports[`CalloutParagraph renders an icon 1`] = `
23+
<CalloutParagraph__TextWrapper
24+
compact={false}
25+
margin="1rem"
26+
roundedCorners={false}
27+
spacing="default"
28+
>
29+
<Paragraph
30+
align="left"
31+
bold={false}
32+
invert={false}
33+
size="medium"
34+
>
35+
<DecorativeIcon />
36+
<span>
37+
Text
38+
</span>
1639
</Paragraph>
1740
</CalloutParagraph__TextWrapper>
1841
`;
@@ -29,7 +52,9 @@ exports[`CalloutParagraph renders with compact 1`] = `
2952
invert={false}
3053
size="medium"
3154
>
32-
Text
55+
<span>
56+
Text
57+
</span>
3358
</Paragraph>
3459
</CalloutParagraph__TextWrapper>
3560
`;
@@ -46,7 +71,9 @@ exports[`CalloutParagraph renders with intermediate 1`] = `
4671
invert={false}
4772
size="medium"
4873
>
49-
Text
74+
<span>
75+
Text
76+
</span>
5077
</Paragraph>
5178
</CalloutParagraph__TextWrapper>
5279
`;
@@ -63,7 +90,9 @@ exports[`CalloutParagraph renders with narrow 1`] = `
6390
invert={false}
6491
size="medium"
6592
>
66-
Text
93+
<span>
94+
Text
95+
</span>
6796
</Paragraph>
6897
</CalloutParagraph__TextWrapper>
6998
`;

0 commit comments

Comments
 (0)