Skip to content

Commit

Permalink
Icon: Improve icon prop usage docs in Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Nov 25, 2024
1 parent b76d9f0 commit 31cb1fc
Showing 1 changed file with 52 additions and 8 deletions.
60 changes: 52 additions & 8 deletions packages/components/src/icon/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,70 @@ 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: () => (
<SVG>
<Path d="M5 4v3h5.5v12h3V7H19V4z" />
</SVG>
icon: ( { size }: { size?: number } ) => (
<img
width={ size }
height={ size }
src="https://s.w.org/style/images/about/WordPress-logotype-wmark.png"
alt="WordPress"
/>
),
};
WithAFunction.parameters = {
docs: {
source: {
code: `
<Icon
icon={ ( { size } ) => (
<img
width={ size }
height={ size }
src="https://s.w.org/style/images/about/WordPress-logotype-wmark.png"
alt="WordPress"
/>
) }
/>;
`,
},
},
};

const MyIconComponent = () => (
<SVG>
const MyIconComponent = ( { size }: { size?: number } ) => (
<SVG width={ size } height={ size }>
<Path d="M5 4v3h5.5v12h3V7H19V4z" />
</SVG>
);

/**
* 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: <MyIconComponent />,
};
WithAComponent.parameters = {
docs: {
source: {
code: `
const MyIconComponent = ( { size } ) => (
<SVG width={ size } height={ size }>
<Path d="M5 4v3h5.5v12h3V7H19V4z" />
</SVG>
);
<Icon
icon={ <MyIconComponent /> }
/>;
`,
},
},
};

export const WithAnSVG = Template.bind( {} );
Expand All @@ -80,7 +124,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.
*/
Expand Down

0 comments on commit 31cb1fc

Please sign in to comment.