Skip to content

Commit f9c87be

Browse files
committed
Apply changes
1 parent 6e3da4e commit f9c87be

File tree

3 files changed

+17
-105
lines changed

3 files changed

+17
-105
lines changed

packages/components/src/icon/index.stories.tsx

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
/**
2-
* External dependencies
3-
*/
4-
5-
/**
6-
* WordPress dependencies
7-
*/
81
import { wordpress } from '@wordpress/icons';
92
import { SVG, Path } from '@wordpress/primitives';
10-
11-
/**
12-
* Internal dependencies
13-
*/
14-
import Icon from '..';
15-
import { VStack } from '../../v-stack';
3+
import { Icon } from '.';
164
import type { Meta, StoryFn } from '@storybook/react';
175

186
const meta: Meta< typeof Icon > = {
19-
title: 'Components/Icon',
7+
title: 'Still Internal/Icon',
208
component: Icon,
219
parameters: {
22-
controls: { expanded: true },
2310
docs: { canvas: { sourceState: 'shown' } },
2411
},
2512
};
@@ -120,21 +107,3 @@ WithAnSVG.args = {
120107
</SVG>
121108
),
122109
};
123-
124-
/**
125-
* Although it's preferred to use icons from the `@wordpress/icons` package, [Dashicons](https://developer.wordpress.org/resource/dashicons/) are still supported,
126-
* as long as you are in a context where the Dashicons stylesheet is loaded. To simulate that here,
127-
* use the Global CSS Injector in the Storybook toolbar at the top and select the "WordPress" preset.
128-
*/
129-
export const WithADashicon: StoryFn< typeof Icon > = ( args ) => {
130-
return (
131-
<VStack>
132-
<Icon { ...args } />
133-
<small>This won’t show an icon if the Dashicons stylesheet isn’t loaded.</small>
134-
</VStack>
135-
);
136-
};
137-
WithADashicon.args = {
138-
...Default.args,
139-
icon: 'wordpress',
140-
};
Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,36 @@
11
/**
2-
* External dependencies
2+
* Forked from `@wordpress/components`
3+
*
4+
* Only forked for CSS collision safety, in case styles or classnames are added upstream.
5+
*
6+
* - Removed Gridicons support (non-critical).
37
*/
48

5-
/**
6-
* WordPress dependencies
7-
*/
89
import { cloneElement, createElement, isValidElement } from '@wordpress/element';
910
import { SVG } from '@wordpress/primitives';
11+
import type { ComponentType } from 'react';
1012

11-
/**
12-
* Internal dependencies
13-
*/
14-
import Dashicon from '../dashicon';
15-
import type { IconKey as DashiconIconKey } from '../dashicon/types';
16-
import type { ComponentType, HTMLProps, SVGProps } from 'react';
17-
18-
export type IconType =
19-
| DashiconIconKey
13+
type IconType =
2014
| ComponentType< { size?: number } >
2115
| ( ( props: { size?: number } ) => JSX.Element )
2216
| JSX.Element;
2317

24-
type AdditionalProps< T > = T extends ComponentType< infer U >
25-
? U
26-
: T extends DashiconIconKey
27-
? SVGProps< SVGSVGElement >
28-
: {};
18+
type AdditionalProps< T > = T extends ComponentType< infer U > ? U : Record< string, unknown >;
2919

30-
export type Props = {
20+
type Props = {
3121
/**
3222
* The icon to render. In most cases, you should use an icon from
3323
* [the `@wordpress/icons` package](https://wordpress.github.io/gutenberg/?path=/story/icons-icon--library).
3424
*
35-
* Other supported values are: component instances, functions,
36-
* [Dashicons](https://developer.wordpress.org/resource/dashicons/)
37-
* (specified as strings), and `null`.
25+
* Other supported values are: component instances, functions, and `null`.
3826
*
3927
* The `size` value, as well as any other additional props, will be passed through.
4028
* @default null
4129
*/
4230
icon?: IconType | null;
4331
/**
4432
* The size (width and height) of the icon.
45-
*
46-
* Defaults to `20` when `icon` is a string (i.e. a Dashicon id), otherwise `24`.
47-
* @default `'string' === typeof icon ? 20 : 24`.
33+
* @default 24
4834
*/
4935
size?: number;
5036
} & AdditionalProps< IconType >;
@@ -53,32 +39,13 @@ export type Props = {
5339
* Renders a raw icon without any initial styling or wrappers.
5440
*
5541
* ```jsx
42+
* import { Icon } from '@automattic/ui';
5643
* import { wordpress } from '@wordpress/icons';
5744
*
5845
* <Icon icon={ wordpress } />
5946
* ```
6047
*/
61-
function Icon( {
62-
icon = null,
63-
size = 'string' === typeof icon ? 20 : 24,
64-
...additionalProps
65-
}: Props ) {
66-
if ( 'string' === typeof icon ) {
67-
return (
68-
<Dashicon
69-
icon={ icon }
70-
size={ size }
71-
{ ...( additionalProps as HTMLProps< HTMLSpanElement > ) }
72-
/>
73-
);
74-
}
75-
76-
if ( isValidElement( icon ) && Dashicon === icon.type ) {
77-
return cloneElement( icon, {
78-
...additionalProps,
79-
} );
80-
}
81-
48+
export function Icon( { icon = null, size = 24, ...additionalProps }: Props ) {
8249
if ( 'function' === typeof icon ) {
8350
return createElement( icon, {
8451
size,
@@ -107,5 +74,3 @@ function Icon( {
10774

10875
return icon;
10976
}
110-
111-
export default Icon;

packages/components/src/icon/test/index.tsx

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
/**
2-
* External dependencies
2+
* @jest-environment jsdom
33
*/
44
import { render, screen } from '@testing-library/react';
5-
6-
/**
7-
* WordPress dependencies
8-
*/
95
import { Path, SVG } from '@wordpress/primitives';
10-
11-
/**
12-
* Internal dependencies
13-
*/
14-
import Icon from '..';
6+
import { Icon } from '..';
157

168
describe( 'Icon', () => {
179
const testId = 'icon';
@@ -28,20 +20,6 @@ describe( 'Icon', () => {
2820
expect( screen.queryByTestId( testId ) ).not.toBeInTheDocument();
2921
} );
3022

31-
it( 'renders a dashicon by slug', () => {
32-
render( <Icon data-testid={ testId } icon="format-image" /> );
33-
34-
expect( screen.getByTestId( testId ) ).toHaveClass( 'dashicons-format-image' );
35-
} );
36-
37-
it( 'renders a dashicon with custom size', () => {
38-
render( <Icon data-testid={ testId } icon="format-image" size={ 10 } /> );
39-
40-
expect( screen.getByTestId( testId ) ).toHaveStyle( 'width:10px' );
41-
expect( screen.getByTestId( testId ) ).toHaveStyle( 'height:10px' );
42-
expect( screen.getByTestId( testId ) ).toHaveStyle( 'font-size:10px' );
43-
} );
44-
4523
it( 'renders a function', () => {
4624
render( <Icon icon={ () => <span data-testid={ testId } /> } /> );
4725

0 commit comments

Comments
 (0)