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 JSDoc to PostVisibility, PostVisibilityCheck, and PostVisibilityLabel #61735

Merged
merged 3 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1154,15 +1154,43 @@ Undocumented declaration.

### PostVisibility

Undocumented declaration.
PostVisibility component.

Allows users to set the visibility of a post.

_Parameters_

- _props_ `Object`: Component properties.
- _props.onClose_ `Function`: Function to call when the popover is closed.

_Returns_

- `JSX.Element`: The rendered component.

### PostVisibilityCheck

Undocumented declaration.
PostVisibilityCheck component.

Determines if the current post can be edited (published) and passes this information to the provided render function.

_Parameters_

- _props_ `Object`: - Component properties.
- _props.render_ `Function`: - Function to render the component. Receives an object with a `canEdit` property.

_Returns_

- `JSX.Element`: Rendered component.

### PostVisibilityLabel

Undocumented declaration.
PostVisibilityLabel component.

Returns the label for the current post visibility setting.

_Returns_

- `string`: Post visibility label.

### privateApis

Expand Down Expand Up @@ -1266,7 +1294,11 @@ Undocumented declaration.

### usePostVisibilityLabel

Undocumented declaration.
Get the label for the current post visibility setting.

_Returns_

- `string`: Post visibility label.

### userAutocompleter

Expand Down
11 changes: 11 additions & 0 deletions packages/editor/src/components/post-visibility/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import { useSelect } from '@wordpress/data';
*/
import { store as editorStore } from '../../store';

/**
* PostVisibilityCheck component.
*
* Determines if the current post can be edited (published)
* and passes this information to the provided render function.
*
* @param {Object} props - Component properties.
* @param {Function} props.render - Function to render the component.
* Receives an object with a `canEdit` property.
* @return {JSX.Element} Rendered component.
*/
export default function PostVisibilityCheck( { render } ) {
const canEdit = useSelect( ( select ) => {
return (
Expand Down
21 changes: 21 additions & 0 deletions packages/editor/src/components/post-visibility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '
import { visibilityOptions } from './utils';
import { store as editorStore } from '../../store';

/**
* PostVisibility component.
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to remove this PostVisibility component. from every component because the generated docs include the component's name, so it's kind of duplicate..

*
* Allows users to set the visibility of a post.
*
* @param {Object} props Component properties.
* @param {Function} props.onClose Function to call when the popover is closed.
* @return {JSX.Element} The rendered component.
*/
export default function PostVisibility( { onClose } ) {
const instanceId = useInstanceId( PostVisibility );

Expand Down Expand Up @@ -133,6 +142,18 @@ export default function PostVisibility( { onClose } ) {
);
}

/**
* PostVisibilityChoice component.
*
* Renders a visibility choice option.
*
* @param {Object} props - Component properties.
* @param {number} props.instanceId - Unique instance ID for the component.
* @param {string} props.value - The value of the visibility option.
* @param {string} props.label - The label for the visibility option.
* @param {string} props.info - Additional information about the visibility option.
* @return {JSX.Element} The rendered component.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not exported so we could leave it as is, though it doesn't hurt to have it 😄 .

function PostVisibilityChoice( { instanceId, value, label, info, ...props } ) {
return (
<div className="editor-post-visibility__choice">
Expand Down
12 changes: 12 additions & 0 deletions packages/editor/src/components/post-visibility/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ import { useSelect } from '@wordpress/data';
import { visibilityOptions } from './utils';
import { store as editorStore } from '../../store';

/**
* PostVisibilityLabel component.
*
* Returns the label for the current post visibility setting.
*
* @return {string} Post visibility label.
*/
export default function PostVisibilityLabel() {
return usePostVisibilityLabel();
}

/**
* Get the label for the current post visibility setting.
*
* @return {string} Post visibility label.
*/
export function usePostVisibilityLabel() {
const visibility = useSelect( ( select ) =>
select( editorStore ).getEditedPostVisibility()
Expand Down
Loading