diff --git a/packages/components/CONTRIBUTING.md b/packages/components/CONTRIBUTING.md index 989fe32e8f491..306d711bf33c4 100644 --- a/packages/components/CONTRIBUTING.md +++ b/packages/components/CONTRIBUTING.md @@ -531,58 +531,7 @@ Given a component folder (e.g. `packages/components/src/unit-control`): ) { /* ... */ } ``` - 7. If the component doesn't forwards its ref yet, wrap the component in a `forwardRed` call. Alternatively, if you want to take advantage of the [Context system](#context-system), you can use the `contextConnect` utility function (which also takes care of adding ref forwarding) - - ```tsx - // With `forwardRef` - import type { ForwardedRef } from 'react'; - import { forwardRef } from '@wordpress/element'; - import type { WordPressComponentProps } from '../ui/context'; - import type { ComponentOwnProps } from './types'; - - function UnforwardedMyComponent( - props: WordPressComponentProps< ComponentOwnProps, 'div', true >, - forwardedRef: ForwardedRef< any > - ) { /* ... */ } - - - /** - * MyComponent JSDoc - */ - export const MyComponent = forwardRef( UnforwardedMyComponent ); - - export default MyComponent; - ``` - - ```tsx - // With `contextConnect` - import type { ForwardedRef } from 'react'; - import { - contextConnect, - useContextSystem, - WordPressComponentProps, - } from '../ui/context'; - import type { ComponentOwnProps } from './types'; - - function UnconnectedMyComponent( - props: WordPressComponentProps< ComponentOwnProps, 'div', true >, - forwardedRef: ForwardedRef< any > - ) { - const contextProps = useContextSystem( props, 'MyComponent' ); - - /* ... */ - } - - - /** - * MyComponent JSDoc - */ - export const MyComponent = contextConnect( UnconnectedMyComponent, 'MyComponent' ); - - export default MyComponent; - ``` - - 8. As shown in the previous examples, make sure you have a **named** export for the component, not just the default export ([example](https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/divider/component.tsx)). This ensures that the docgen can properly extract the types data. The naming should be so that the connected/forwarded component has the plain component name (`MyComponent`), and the raw component is prefixed (`UnconnectedMyComponent` or `UnforwardedMyComponent`). This makes the component's `displayName` look nicer in React devtools and in the autogenerated Storybook code snippets. + 7. As shown in the previous examples, make sure you have a **named** export for the component, not just the default export ([example](https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/divider/component.tsx)). This ensures that the docgen can properly extract the types data. The naming should be so that the connected/forwarded component has the plain component name (`MyComponent`), and the raw component is prefixed (`UnconnectedMyComponent` or `UnforwardedMyComponent`). This makes the component's `displayName` look nicer in React devtools and in the autogenerated Storybook code snippets. ```jsx function UnconnectedMyComponent() { /* ... */ } @@ -592,8 +541,8 @@ Given a component folder (e.g. `packages/components/src/unit-control`): export default MyComponent; ``` - 9. Use JSDocs syntax for each TypeScript property that is part of the public API of a component. The docs used here should be aligned with the component’s README. Add `@default` values where appropriate. - 10. Prefer `unknown` to `any`, and in general avoid it when possible. + 8. Use JSDocs syntax for each TypeScript property that is part of the public API of a component. The docs used here should be aligned with the component’s README. Add `@default` values where appropriate. + 9. Prefer `unknown` to `any`, and in general avoid it when possible. 8. On the component's main named export, add a JSDoc comment that includes the main description and the example code snippet from the README ([example](https://github.com/WordPress/gutenberg/blob/43d9c82922619c1d1ff6b454f86f75c3157d3de6/packages/components/src/date-time/date-time/index.tsx#L193-L217)). _At the time of writing, the `@example` JSDoc keyword is not recognized by StoryBook's docgen, so please avoid using it_. 9. Make sure that: 1. tests still pass; diff --git a/packages/components/src/card/test/__snapshots__/index.tsx.snap b/packages/components/src/card/test/__snapshots__/index.tsx.snap index 10083db050517..8004af489ee7c 100644 --- a/packages/components/src/card/test/__snapshots__/index.tsx.snap +++ b/packages/components/src/card/test/__snapshots__/index.tsx.snap @@ -8,8 +8,8 @@ Snapshot Diff: @@ -1,8 +1,8 @@
@@ -25,8 +25,8 @@ Snapshot Diff: @@ -1,8 +1,8 @@
@@ -42,8 +42,8 @@ Snapshot Diff: @@ -1,8 +1,8 @@