diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 12c454459a198..de726e6106e9b 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Internal + +- `Guide`: Convert to TypeScript ([#47493](https://github.com/WordPress/gutenberg/pull/47493)). + ## 23.5.0 (2023-03-01) ### Enhancements diff --git a/packages/components/src/guide/README.md b/packages/components/src/guide/README.md index 061332234cdbc..01b1182338005 100644 --- a/packages/components/src/guide/README.md +++ b/packages/components/src/guide/README.md @@ -37,20 +37,6 @@ function MyTutorial() { The component accepts the following props: -### onFinish - -A function which is called when the guide is finished. The guide is finished when the modal is closed or when the user clicks _Finish_ on the last page of the guide. - -- Type: `function` -- Required: Yes - -### pages - -A list of objects describing each page in the guide. Each object **must** contain a `'content'` property and may optionally contain a `'image'` property. - -- Type: `array` -- Required: Yes - ### className A custom class to add to the modal. @@ -62,7 +48,7 @@ A custom class to add to the modal. This property is used as the modal's accessibility label. It is required for accessibility reasons. -- Type: `String` +- Type: `string` - Required: Yes ### finishButtonText @@ -71,3 +57,19 @@ Use this to customize the label of the _Finish_ button shown at the end of the g - Type: `string` - Required: No +- Default: `'Finish'` + +### onFinish + +A function which is called when the guide is finished. The guide is finished when the modal is closed or when the user clicks _Finish_ on the last page of the guide. + +- Type: `( event?: KeyboardEvent< HTMLDivElement > | SyntheticEvent ) => void` +- Required: Yes + +### pages + +A list of objects describing each page in the guide. Each object **must** contain a `'content'` property and may optionally contain a `'image'` property. + +- Type: `{ content: ReactNode; image?: ReactNode; }[]` +- Required: No +- Default: `[]` diff --git a/packages/components/src/guide/icons.js b/packages/components/src/guide/icons.tsx similarity index 76% rename from packages/components/src/guide/icons.js rename to packages/components/src/guide/icons.tsx index 1f9713d6fdd8c..1c47180ae0b11 100644 --- a/packages/components/src/guide/icons.js +++ b/packages/components/src/guide/icons.tsx @@ -3,7 +3,7 @@ */ import { SVG, Circle } from '@wordpress/primitives'; -export const PageControlIcon = ( { isSelected } ) => ( +export const PageControlIcon = ( { isSelected }: { isSelected: boolean } ) => (
}, { content:Page 2
}, @@ -33,6 +39,7 @@ describe( 'Guide', () => { it( 'hides back button and shows forward button on the first page', () => { render(Page 2
}, @@ -55,6 +62,7 @@ describe( 'Guide', () => { const user = userEvent.setup(); render(Page 2
}, @@ -78,7 +86,12 @@ describe( 'Guide', () => { } ); it( "doesn't display the page control if there is only one page", () => { - render(Page 2
}, @@ -154,6 +170,7 @@ describe( 'Guide', () => { render(Page 2
}, @@ -196,6 +213,7 @@ describe( 'Guide', () => { render(Page 2
}, diff --git a/packages/components/src/guide/types.ts b/packages/components/src/guide/types.ts new file mode 100644 index 0000000000000..62c1816a5c672 --- /dev/null +++ b/packages/components/src/guide/types.ts @@ -0,0 +1,68 @@ +/** + * External dependencies + */ +import type { ReactNode } from 'react'; + +/** + * Internal dependencies + */ +import type { ModalProps } from '../modal/types'; + +export type Page = { + /** + * Content of the page. + */ + content: ReactNode; + /** + * Image displayed above the page content. + */ + image?: ReactNode; +}; + +export type GuideProps = { + /** + * Deprecated. Use `pages` prop instead. + * + * @deprecated since 5.5 + */ + children?: ReactNode; + /** + * A custom class to add to the modal. + */ + className?: string; + /** + * Used as the modal's accessibility label. + */ + contentLabel: ModalProps[ 'contentLabel' ]; + /** + * Use this to customize the label of the _Finish_ button shown at the end of the guide. + * + * @default 'Finish' + */ + finishButtonText?: string; + /** + * A function which is called when the guide is finished. + */ + onFinish: ModalProps[ 'onRequestClose' ]; + /** + * A list of objects describing each page in the guide. Each object **must** contain a `'content'` property and may optionally contain a `'image'` property. + * + * @default [] + */ + pages?: Page[]; +}; + +export type PageControlProps = { + /** + * Current page index. + */ + currentPage: number; + /** + * Total number of pages. + */ + numberOfPages: number; + /** + * Called when user clicks on a `PageControlIcon` button. + */ + setCurrentPage: ( page: number ) => void; +}; diff --git a/packages/components/tsconfig.json b/packages/components/tsconfig.json index 860b6f3ca36cc..005ddd0b4c568 100644 --- a/packages/components/tsconfig.json +++ b/packages/components/tsconfig.json @@ -49,7 +49,6 @@ "src/dimension-control", "src/duotone-picker", "src/gradient-picker", - "src/guide", "src/higher-order/navigate-regions", "src/higher-order/with-fallback-styles", "src/higher-order/with-filters",