From c7959cfc3308034bfa1763cc35317f065cfbcb7e Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Fri, 26 Oct 2018 16:49:54 +0300 Subject: [PATCH] Default Dashicons to 20x20, the rest to 24x24 --- .../embed/test/__snapshots__/index.js.snap | 4 ++-- packages/components/src/icon/README.md | 2 +- packages/components/src/icon/index.js | 19 +++++++++++++------ packages/components/src/icon/test/index.js | 13 +++++++++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/packages/block-library/src/embed/test/__snapshots__/index.js.snap b/packages/block-library/src/embed/test/__snapshots__/index.js.snap index 6bddefd1b492e..b1f124507649b 100644 --- a/packages/block-library/src/embed/test/__snapshots__/index.js.snap +++ b/packages/block-library/src/embed/test/__snapshots__/index.js.snap @@ -14,10 +14,10 @@ exports[`core/embed block edit matches snapshot 1`] = ` aria-hidden="true" class="dashicon dashicons-embed-generic" focusable="false" - height="24" + height="20" role="img" viewBox="0 0 20 20" - width="24" + width="20" xmlns="http://www.w3.org/2000/svg" > ; + // Dashicons should be 20x20 by default + iconSize = size || 20; + return ; } + // Any other icons should be 24x24 by default + iconSize = size || 24; + if ( 'function' === typeof icon ) { if ( icon.prototype instanceof Component ) { - return createElement( icon, { className, size } ); + return createElement( icon, { className, size: iconSize } ); } return icon(); @@ -20,8 +27,8 @@ function Icon( { icon = null, size = 24, className } ) { if ( icon && ( icon.type === 'svg' || icon.type === SVG ) ) { const appliedProps = { className, - width: size, - height: size, + width: iconSize, + height: iconSize, ...icon.props, }; @@ -31,7 +38,7 @@ function Icon( { icon = null, size = 24, className } ) { if ( isValidElement( icon ) ) { return cloneElement( icon, { className, - size, + size: iconSize, } ); } diff --git a/packages/components/src/icon/test/index.js b/packages/components/src/icon/test/index.js index a94630c818218..a7fea71cb9fac 100644 --- a/packages/components/src/icon/test/index.js +++ b/packages/components/src/icon/test/index.js @@ -36,6 +36,12 @@ describe( 'Icon', () => { expect( wrapper.find( 'Dashicon' ).prop( 'className' ) ).toBe( 'example-class' ); } ); + it( 'renders a dashicon and with a default size of 20', () => { + const wrapper = shallow( ); + + expect( wrapper.find( 'Dashicon' ).prop( 'size' ) ).toBe( 20 ); + } ); + it( 'renders a dashicon and passes the size to it', () => { const wrapper = shallow( ); @@ -78,6 +84,13 @@ describe( 'Icon', () => { expect( wrapper.prop( 'className' ) ).toBe( 'example-class' ); } ); + it( 'renders an svg element with a default width and height of 24', () => { + const wrapper = shallow( ); + + expect( wrapper.prop( 'width' ) ).toBe( 24 ); + expect( wrapper.prop( 'height' ) ).toBe( 24 ); + } ); + it( 'renders an svg element and passes the size as its width and height', () => { const wrapper = shallow( } size={ 32 } /> );