Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send props to Dashicon. #14631

Merged
merged 10 commits into from
Mar 27, 2019
3 changes: 1 addition & 2 deletions packages/components/src/dashicon/icon-class.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export const IconClass = ( props ) => {
const { icon, className } = props;
export const getIconClassName = ( icon, className ) => {
return [ 'dashicon', 'dashicons-' + icon, className ].filter( Boolean ).join( ' ' );
};
3 changes: 1 addition & 2 deletions packages/components/src/dashicon/icon-class.native.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export const IconClass = ( props ) => {
const { icon, className, ariaPressed } = props;
export const getIconClassName = ( icon, className, ariaPressed ) => {
return [ ariaPressed ? 'dashicon-active' : 'dashicon', 'dashicons-' + icon, className ].filter( Boolean ).join( ' ' );
};
16 changes: 4 additions & 12 deletions packages/components/src/dashicon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@ import { Component } from '@wordpress/element';
* Internal dependencies
*/
import { Path, SVG } from '../primitives';
import { IconClass } from './icon-class';
import { getIconClassName } from './icon-class';

export default class Dashicon extends Component {
shouldComponentUpdate( nextProps ) {
return (
this.props.icon !== nextProps.icon ||
this.props.size !== nextProps.size ||
this.props.className !== nextProps.className ||
this.props.ariaPressed !== nextProps.ariaPressed
);
}

render() {
const { icon, size = 20 } = this.props;
const { icon, size = 20, className, ariaPressed, ...extraProps } = this.props;
let path;

switch ( icon ) {
Expand Down Expand Up @@ -901,7 +892,7 @@ export default class Dashicon extends Component {
return null;
}

const iconClass = IconClass( this.props );
const iconClass = getIconClassName( icon, className, ariaPressed );

return (
<SVG
Expand All @@ -913,6 +904,7 @@ export default class Dashicon extends Component {
width={ size }
height={ size }
viewBox="0 0 20 20"
{ ...extraProps }
>
<Path d={ path } />
</SVG>
Expand Down