Guide 是一个 React 组件,用于在模态框中渲染用户指南,支持多页面逐步浏览。指南通过关闭模态框或点击最后一页的 Finish 按钮完成。
function MyTutorial() {
const [ isOpen, setIsOpen ] = useState( true );
if ( ! isOpen ) {
return null;
}
return (
<Guide
onFinish={ () => setIsOpen( false ) }
pages={ [
{
content: <p>Welcome to the ACME Store!</p>,
},
{
image: <img src="https://acmestore.com/add-to-cart.png" />,
content: (
<p>
Click <i>Add to Cart</i> to buy a product.
</p>
),
},
] }
/>
);
}Guide is a React component that renders a user guide in a modal. The guide consists of several pages which the user can step through one by one. The guide is finished when the modal is closed or when the user clicks Finish on the last page of the guide.
function MyTutorial() {
const [ isOpen, setIsOpen ] = useState( true );
if ( ! isOpen ) {
return null;
}
return (
<Guide
onFinish={ () => setIsOpen( false ) }
pages={ [
{
content: <p>Welcome to the ACME Store!</p>,
},
{
image: <img src="https://acmestore.com/add-to-cart.png" />,
content: (
<p>
Click <i>Add to Cart</i> to buy a product.
</p>
),
},
] }
/>
);
}
The component accepts the following props:
A custom class to add to the modal.
stringThis property is used as the modal’s accessibility label. It is required for accessibility reasons.
stringUse this to customize the label of the Finish button shown at the end of the guide.
string'Finish'Use this to customize the label of the Next button shown on each page of the guide.
string'Next'Use this to customize the label of the Previous button shown on each page of the guide except the first.
string'Previous'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.
( event?: KeyboardEvent< HTMLDivElement > | SyntheticEvent ) => voidA list of objects describing each page in the guide. Each object must contain a 'content' property and may optionally contain a 'image' property.
{ content: ReactNode; image?: ReactNode; }[][]