Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/preview options component readme #25104

Merged

Conversation

JustinyAhin
Copy link
Member

Description

Added documentation for the preview options component (see #22891)

How has this been tested?

N/A, documentation only

Types of changes

Documentation

Checklist:

  • [n/a] My code is tested.
  • [n/a] My code follows the WordPress code style.
  • [n/a] My code follows the accessibility standards.
  • [n/a] My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I've left a few comments below.

Renders the previews options of the editor in a dropdown menu.

```jsx
import { PreviewOptions } from '@wordpress/block-editor';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component is still being exported as __experimental; we should probably document its usage as import { __experimentalPreviewOptions as PreviewOptions } from '@wordpress/block-editor';. There is some precedent for this in other experimental component readmes, though we'll have to then remember to update the docs once it's moved out of experimental status 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it's fine to document experimental components I guess.

deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this component accepts children, should we have an example documenting that? We have one instance of its use in that format so far.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum 🤔, I guess we can do that. For the past docs PRs I sent, I tried to keep it short and only add examples for the component itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you happy to do this? Not a blocker, more of a nice-to-have 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing.
I can do something like

import { Icon, MenuGroup } from '@wordpress/components';
import { PostPreviewButton } from '@wordpress/editor';
import { __experimentalPreviewOptions as PreviewOptions } from '@wordpress/block-editor';

const MyPreviewOptions = () => (
    <PreviewOptions
        isEnabled={ true }
        className="edit-post-post-preview-dropdown"
        deviceType={ deviceType }
        setDeviceType={ setPreviewDeviceType }
        >
        <MenuGroup>
            <div className="edit-post-header-preview__grouping-external">
                <PostPreviewButton
                    className={
                        'edit-post-header-preview__button-external'
                    }
                    role="menuitem"
                    forceIsAutosaveable={ hasActiveMetaboxes }
                    forcePreviewLink={ isSaving ? null : undefined }
                    textContent={
                        <>
                            { __( 'Preview in new tab' ) }
                            <Icon icon={ external } />
                        </>
                    }
                />
            </div>
	</MenuGroup>
    >
);

using the DevicePreview example.
Looks good?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that works! One thing: the snippet above is missing the closing </PreviewOptions> tag; should add it in for clarity.


The CSS classes added to the component.

- Type: any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Type: String.


The device type in the preview options. It can be either Desktop or Tablet or Mobile among others.

- Type: `any`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Type: String.


Used to set the device type that will be used to display the preview inside the editor.

- Type: `any`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Type: func.

);
```

### Props
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to also add to each prop whether it is Required; in this case only deviceType and setDeviceType are required props; the rest are optional.

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick iteration, looks good!

Not sure why the Compressed Size check is failing, doesn't seem related to this changeset 🤔 Might be worth rebasing if we can't get it to pass by re-running the checks.

deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you happy to do this? Not a blocker, more of a nice-to-have 🙂

@JustinyAhin
Copy link
Member Author

Thanks for the quick iteration, looks good!

Not sure why the Compressed Size check is failing, doesn't seem related to this changeset thinking Might be worth rebasing if we can't get it to pass by re-running the checks.

Wiil see after the next commit if it'll pass.

@JustinyAhin JustinyAhin force-pushed the add/preview-options-component-readme branch from a6898a3 to 14a2c59 Compare September 9, 2020 11:29
@JustinyAhin JustinyAhin merged commit 99a1cba into WordPress:master Sep 9, 2020
@github-actions github-actions bot added this to the Gutenberg 9.0 milestone Sep 9, 2020
@JustinyAhin JustinyAhin deleted the add/preview-options-component-readme branch September 9, 2020 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants