Skip to content

Commit 2d91f63

Browse files
authored
Merge pull request #1482 from interactivellama/icon-colors
Add Icon colors: Warning, error, light
2 parents 959b136 + 6ebbc68 commit 2d91f63

File tree

26 files changed

+508
-35
lines changed

26 files changed

+508
-35
lines changed

components/icon/__docs__/storybook-stories.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ColorBase from '../__examples__/color-base';
1919
import ColorDefault from '../__examples__/color-default';
2020
import ColorError from '../__examples__/color-error';
2121
import ColorWarning from '../__examples__/color-warning';
22+
import ColorLight from '../__examples__/color-light';
2223

2324
import SizesExtraSmall from '../__examples__/sizes-extra-small';
2425
import SizesSmall from '../__examples__/sizes-small';
@@ -47,6 +48,9 @@ storiesOf(ICON, module)
4748
</div>
4849
))
4950
.add('Color: Default', () => <ColorDefault />)
51+
.add('Color: Error', () => <ColorError />)
52+
.add('Color: Warning', () => <ColorWarning />)
53+
.add('Color: Light', () => <ColorLight />)
5054
.add('Base: Standard (custom styles)', () => (
5155
<Icon
5256
assistiveText={{ label: 'Account' }}
@@ -57,5 +61,9 @@ storiesOf(ICON, module)
5761
/>
5862
))
5963
.add('Base: Imported', () => (
60-
<Icon assistiveText={{ label: 'Download' }} category="utility" icon={download} />
64+
<Icon
65+
assistiveText={{ label: 'Download' }}
66+
category="utility"
67+
icon={download}
68+
/>
6169
));

components/icon/__examples__/color-default.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ const Example = createReactClass({
1111
<IconSettings iconPath="/assets/icons">
1212
<Icon
1313
assistiveText={{ label: 'Description of icon' }}
14-
category="standard"
15-
name="account"
14+
category="utility"
15+
name="announcement"
1616
title="This is a title"
17-
inverse
1817
/>
1918
</IconSettings>
2019
);
21-
}
20+
},
2221
});
2322

2423
export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime

components/icon/__examples__/color-error.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ const Example = createReactClass({
1111
<IconSettings iconPath="/assets/icons">
1212
<Icon
1313
assistiveText={{ label: 'Description of icon' }}
14-
category="standard"
15-
name="account"
14+
category="utility"
15+
colorVariant="error"
16+
name="announcement"
1617
title="description of icon"
1718
/>
1819
</IconSettings>
1920
);
20-
}
21+
},
2122
});
2223

2324
export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import createReactClass from 'create-react-class';
3+
import Icon from '~/components/icon'; // `~` is replaced with design-system-react at runtime
4+
import IconSettings from '~/components/icon-settings';
5+
6+
const Example = createReactClass({
7+
displayName: 'IconExample',
8+
9+
render () {
10+
return (
11+
<IconSettings iconPath="/assets/icons">
12+
<Icon
13+
assistiveText={{ label: 'Description of icon' }}
14+
category="utility"
15+
colorVariant="light"
16+
name="announcement"
17+
title="description of icon"
18+
/>
19+
</IconSettings>
20+
);
21+
},
22+
});
23+
24+
export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime

components/icon/__examples__/color-warning.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ const Example = createReactClass({
1111
<IconSettings iconPath="/assets/icons">
1212
<Icon
1313
assistiveText={{ label: 'Description of icon' }}
14-
category="standard"
15-
name="account"
14+
category="utility"
15+
colorVariant="warning"
16+
name="announcement"
1617
title="description of icon"
1718
/>
1819
</IconSettings>
1920
);
20-
}
21+
},
2122
});
2223

2324
export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime

components/icon/__examples__/colors.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ const Example = createReactClass({
2626
name="lock"
2727
/>
2828
</div>
29+
<div className="slds-col--padded">
30+
<Icon
31+
assistiveText={{ label: 'Lock' }}
32+
category="utility"
33+
colorVariant="light"
34+
name="lock"
35+
/>
36+
</div>
2937
<div className="slds-col--padded">
3038
<Icon
3139
assistiveText={{ label: 'Warning' }}
@@ -45,7 +53,7 @@ const Example = createReactClass({
4553
</div>
4654
</IconSettings>
4755
);
48-
}
56+
},
4957
});
5058

5159
export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime

components/icon/index.jsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
33

44
// # Icon Component
5-
6-
// Based on SLDS v2.1.0-rc.4
7-
8-
// ## Dependencies
9-
10-
// ### React
115
import React from 'react';
126
import PropTypes from 'prop-types';
137

@@ -21,13 +15,13 @@ import classNames from '../../utilities/class-names';
2115
// ## Children
2216
import UtilityIcon from '../utilities/utility-icon';
2317

24-
// ## Constants
2518
import { ICON } from '../../utilities/constants';
2619

2720
const defaultProps = {
2821
assistiveText: {},
2922
category: 'standard',
30-
size: 'medium'
23+
colorVariant: 'default',
24+
size: 'medium',
3125
};
3226

3327
/**
@@ -38,21 +32,23 @@ const Icon = (props) => {
3832
const {
3933
category,
4034
className,
35+
colorVariant,
4136
containerClassName,
4237
icon,
4338
inverse,
4439
name,
4540
path,
4641
size,
4742
style,
48-
title
43+
title,
4944
} = props;
50-
const assistiveText = typeof props.assistiveText === 'string'
51-
? props.assistiveText
52-
: {
53-
...defaultProps.assistiveText,
54-
...props.assistiveText,
55-
}.label;
45+
const assistiveText =
46+
typeof props.assistiveText === 'string'
47+
? props.assistiveText
48+
: {
49+
...defaultProps.assistiveText,
50+
...props.assistiveText,
51+
}.label;
5652

5753
const kababCaseName = name ? name.replace(/_/g, '-') : '';
5854

@@ -63,7 +59,7 @@ const Icon = (props) => {
6359
'slds-icon_container': category !== 'utility',
6460
'slds-icon_container--circle': category === 'action',
6561
[`slds-icon-${category}-${kababCaseName}`]:
66-
category !== 'utility' && category !== 'doctype' && !path
62+
category !== 'utility' && category !== 'doctype' && !path,
6763
},
6864
containerClassName
6965
)}
@@ -82,7 +78,13 @@ const Icon = (props) => {
8278
// if category is `utility` and `inverse` is true, icon will be light // return false
8379
// if category is NOT `utility` and `inverse` is false (default), icon will be light // return false
8480
// if category is NOT `utility` and `inverse` is true, icon will be dark // return true
85-
'slds-icon-text-default': category === 'utility' ? !inverse : inverse
81+
'slds-icon-text-default':
82+
colorVariant === 'default' && category === 'utility'
83+
? !inverse
84+
: inverse,
85+
'slds-icon-text-warning': colorVariant === 'warning',
86+
'slds-icon-text-error': colorVariant === 'error',
87+
'slds-icon-text-light': colorVariant === 'light',
8688
})}
8789
icon={icon}
8890
name={name}
@@ -120,28 +122,34 @@ Icon.propTypes = {
120122
'custom',
121123
'doctype',
122124
'standard',
123-
'utility'
125+
'utility',
124126
]).isRequired,
125127
/**
126128
* CSS classes that are applied to the SVG.
127129
*/
128130
className: PropTypes.oneOfType([
129131
PropTypes.array,
130132
PropTypes.object,
131-
PropTypes.string
133+
PropTypes.string,
132134
]),
133135
/**
134136
* CSS classes that are applied to the span.
135137
*/
136138
containerClassName: PropTypes.oneOfType([
137139
PropTypes.array,
138140
PropTypes.object,
139-
PropTypes.string
141+
PropTypes.string,
140142
]),
141143
/**
142144
* Icon color variants
143145
*/
144-
colorVariant: PropTypes.oneOf(['base', 'default', 'error', 'warning']),
146+
colorVariant: PropTypes.oneOf([
147+
'base',
148+
'default',
149+
'error',
150+
'light',
151+
'warning',
152+
]),
145153
/**
146154
* A custom SVG object to use instead of the supplied SLDS icons, look in `design-system-react/icons` for examples and syntax.
147155
*/
@@ -169,7 +177,7 @@ Icon.propTypes = {
169177
/**
170178
* Title attribute for the icon container
171179
*/
172-
title: PropTypes.string
180+
title: PropTypes.string,
173181
};
174182

175183
Icon.defaultProps = defaultProps;

components/story-based-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export DataTable from '../components/data-table/__docs__/storybook-stories';
3232
// export Input from '../components/input/__docs__/storybook-stories';
3333
// export Textarea from '../components/textarea/__docs__/storybook-stories';
3434
// export Search from '../components/input/__docs__/search/storybook-stories';
35-
// export Icon from '../components/icon/__docs__/storybook-stories';
35+
export Icon from '../components/icon/__docs__/storybook-stories';
3636
export Illustration from '../components/illustration/__docs__/storybook-stories';
3737
// export Lookup from '../components/lookup/__docs__/storybook-stories';
3838
// export MediaObject from '../components/media-object/__docs__/storybook-stories';

0 commit comments

Comments
 (0)