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

Documentation: Add PostURL component docs #61737

Merged
merged 6 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 40 additions & 5 deletions packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1138,19 +1138,50 @@ _Returns_

### PostURL

Undocumented declaration.
Renders the `PostURL` component.

_Usage_

```jsx
<PostURL />
```

_Parameters_

- _onClose_ `Function`: Callback function to be executed when the popover is closed.

_Returns_

- `Component`: The rendered PostURL component.

### PostURLCheck

Undocumented declaration.
Check if the post URL is valid and visible.

_Parameters_

- _props_ `Object`: The component props.
- _props.children_ `Element`: The child components.

_Returns_

- `Component|null`: The child components if the post URL is valid and visible, otherwise null.

### PostURLLabel

Undocumented declaration.
Represents a label component for a post URL.

_Returns_

- `Component`: The PostURLLabel component.

### PostURLPanel

Undocumented declaration.
Renders the `PostURLPanel` component.

_Returns_

- `JSX.Element`: The rendered PostURLPanel component.

### PostVisibility

Expand Down Expand Up @@ -1262,7 +1293,11 @@ Undocumented declaration.

### usePostURLLabel

Undocumented declaration.
Custom hook to get the label for the post URL.

_Returns_

- `string`: The filtered and decoded post URL label.

### usePostVisibilityLabel

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

/**
* Check if the post URL is valid and visible.
*
* @param {Object} props The component props.
* @param {Element} props.children The child components.
*
* @return {Component|null} The child components if the post URL is valid and visible, otherwise null.
*/
export default function PostURLCheck( { children } ) {
const isVisible = useSelect( ( select ) => {
const postTypeSlug = select( editorStore ).getCurrentPostType();
Expand Down
12 changes: 12 additions & 0 deletions packages/editor/src/components/post-url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ import { useCopyToClipboard } from '@wordpress/compose';
import { usePostURLLabel } from './label';
import { store as editorStore } from '../../store';

/**
* Renders the `PostURL` component.
*
* @example
* ```jsx
* <PostURL />
* ```
*
* @param {Function} onClose Callback function to be executed when the popover is closed.
*
* @return {Component} The rendered PostURL component.
*/
export default function PostURL( { onClose } ) {
const { isEditable, postSlug, postLink, permalinkPrefix, permalinkSuffix } =
useSelect( ( select ) => {
Expand Down
10 changes: 10 additions & 0 deletions packages/editor/src/components/post-url/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ import { filterURLForDisplay, safeDecodeURIComponent } from '@wordpress/url';
*/
import { store as editorStore } from '../../store';

/**
* Represents a label component for a post URL.
*
* @return {Component} The PostURLLabel component.
*/
export default function PostURLLabel() {
return usePostURLLabel();
}

/**
* Custom hook to get the label for the post URL.
*
* @return {string} The filtered and decoded post URL label.
*/
export function usePostURLLabel() {
const postLink = useSelect(
( select ) => select( editorStore ).getPermalink(),
Expand Down
5 changes: 5 additions & 0 deletions packages/editor/src/components/post-url/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import PostURL from './index';
import PostPanelRow from '../post-panel-row';
import { store as editorStore } from '../../store';

/**
* Renders the `PostURLPanel` component.
*
* @return {JSX.Element} The rendered PostURLPanel component.
*/
export default function PostURLPanel() {
// Use internal state instead of a ref to make sure that the component
// re-renders when the popover's anchor updates.
Expand Down
Loading