From de7b09b2faa72d462736bf562962540450982522 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Wed, 27 Nov 2024 01:46:43 +0900 Subject: [PATCH] Icon: Improve `icon` prop usage docs in Storybook (#67280) * Icon: Improve `icon` prop usage docs in Storybook * Fixup Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: tyxla --- .../src/icon/stories/index.story.tsx | 58 ++++++++++++++++--- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/packages/components/src/icon/stories/index.story.tsx b/packages/components/src/icon/stories/index.story.tsx index 7d61be8df7f3c..d1eabf2e98b77 100644 --- a/packages/components/src/icon/stories/index.story.tsx +++ b/packages/components/src/icon/stories/index.story.tsx @@ -47,26 +47,68 @@ FillColor.args = { ...Default.args, }; +/** + * When `icon` is a function, it will be passed the `size` prop and any other additional props. + */ export const WithAFunction = Template.bind( {} ); WithAFunction.args = { ...Default.args, - icon: () => ( - - - + icon: ( { size }: { size?: number } ) => ( + WordPress ), }; +WithAFunction.parameters = { + docs: { + source: { + code: ` + ( + WordPress + ) } +/> + `, + }, + }, +}; -const MyIconComponent = () => ( - +const MyIconComponent = ( { size }: { size?: number } ) => ( + ); +/** + * When `icon` is a component, it will be passed the `size` prop and any other additional props. + */ export const WithAComponent = Template.bind( {} ); WithAComponent.args = { ...Default.args, - icon: MyIconComponent, + icon: , +}; +WithAComponent.parameters = { + docs: { + source: { + code: ` +const MyIconComponent = ( { size } ) => ( + + + +); + + } /> + `, + }, + }, }; export const WithAnSVG = Template.bind( {} ); @@ -80,7 +122,7 @@ WithAnSVG.args = { }; /** - * Although it's preferred to use icons from the `@wordpress/icons` package, Dashicons are still supported, + * Although it's preferred to use icons from the `@wordpress/icons` package, [Dashicons](https://developer.wordpress.org/resource/dashicons/) are still supported, * as long as you are in a context where the Dashicons stylesheet is loaded. To simulate that here, * use the Global CSS Injector in the Storybook toolbar at the top and select the "WordPress" preset. */