Animation List Control
Canonical Override
Provides a field to read and write from the _pmc_canonical_override meta.
TODO: Provide a value and callback setter to the component directly rather than relying on the component to do that work.
Usage
<CanonicalOverride />Card
A general Placeholder for elemenets using the core Placeholder component.
Usage
<Card
title="Title"
showHiddenIcon={ false }
/>Props
| prop | type | required | default | description |
|---|---|---|---|---|
| title | string | no | '' | Title to show in the placeholder element. |
| showHiddenIcon | bool | no | false | Whether or not to show the hidden dashicon. |
| className | string | no | '' | Classname, optional. |
Collapsable Wrapper
A simple wrapper component that provides the ability to toggle its contents open or closed.
Provides also the ability to remove the block from the closed state with a callback which returns an open/closed boolean, optional.
Usage
<CollapsableWrapper
canRemove
className={className}
clientId={clientId}
icon={icon}
isEditing={true}
isOpen={true}
isPreviewing={true}
onEdit={onEdit}
onPreview={onPreview}
onToggle={onToggle}
title={title}
>
{children}
</CollapsableWrapper>Props
| prop | type | required | default | description |
|---|---|---|---|---|
| canRemove | bool | no | false | Whether or not to allow removing the block by client id. |
| children | node | yes | Children to render inside the component wrapper. | |
| className | string | no | '' | Classname string. |
| clientId | string | yes | Root client id. | |
| icon | string|element | no | '' | Dashicon name or SVG element. |
| isEditing | bool | no | false | Whether or not the "edit" state should be visible. |
| isOpen | bool | no | false | Whether or not to set the default state to open. |
| isPreviewing | bool | no | false | Whether or not the "preview" state should be visible |
| onEdit | function | no | null | Callback triggered when "edit" BlockControl is clicked. |
| onPreview | function | no | null | Callback triggered when "preview" BlockControl is clicked. |
| onToggle | function | no | null | Callback that returns the state of the container, true or false |
| title | string | no | '' | Title string to display when the wrapper is collapsed. |
Custom Slotfill: PMCSidebarPanel
Creates a slot inside the PMC Sidebar panel for adding custom features.
Entity Selector
Displays a FormTokenField (Like the Tags flat term selector) to search for, display, and select taxonomy or post type entities.
Usage
<EntitySelector
entity="post"
label={ __( 'Related Story', 'pmc-gutenberg' ) }
onSelect={ ( next ) =>
setAttributes( {
related: next.map( ( term ) => ( {
post_id: term,
} ) ),
} )
}
placeholder={ __(
'Search for a story… ',
'pmc-gutenberg'
) }
query={ {
category: 'primetime-pilot-panic',
} }
type="postType"
value={
related?.length
? related.map( ( post ) => post?.post_id )
: []
}
maxValues={ 6 }
/>Props
| name | type | default | required | description |
|---|---|---|---|---|
| entity | string | 'post' | no | The post type slug or taxonomy slug to query. |
| label | string | 'Find Post Type' | no | The label to display above the FormTokenField. |
| max | int | 20 | no | The max number of results to display during search. |
| onSelect | function | yes | Callback returns array of selected ids. | |
| placeholder | string | 'Search for a post..." | no | The placeholder to display inside the FormTokenField input. |
| query | object | no | An object container rest field query values supported by rest or getEntityRecords. | |
| type | enum | 'postType' | no | Entity type, postType or taxonomy. |
| value | array | yes | Array if post or taxonomy ids. | |
| maxValues | int | 20 | no | The max number of values to get stored. |
postWithFeaturedImage
Return a post with a featured image.
props: Object — Props object.props.post: Object — Post object.props.getMedia: func — Callback to return media by id.- Reference (opens in a new tab)
LegacyTypography
A component that returns legacy typography output used for the heading, paragraph, and group blocks behind a feature flag.
NOTE: This hook should be removed once those features are migrated into WordPress core typography handling via theme.json.
Hook: useLegacyTypography
A hook to centralize the typography features and return necessary values.
useLegacyTypography
Return values for use in legacy typography component.
blockConfig: Object — Block config from localization.typographyFontFamily: string — Selected font family.
LockableFlatTermSelector
Similar to the PostTaxonomiesFlatTermSelector that comes with Gutenberg core, but is locked down to prevent creation of new post tags. Only allowed to select existing terms in this feature.
Usage
<LockableFlatTermSelector slug={ term } locked />Props
| name | type | required | description |
|---|---|---|---|
| slug | string | yes | The taxonomy slug to represent. |
| locked | boolean | no | Whether or not to lock down term creation. |
BulkTermCreator Component
Provides a TextControl field that supports auto-creation of terms by comma-separated string.
Usage
<BulkTermCreator onChange={ onChange } />
/>Props
| prop | type | required | description |
|---|---|---|---|
| onChange | function | yes | onChange handler for terms. |
| selectedTerms | array | yes | array of selected term strings. |
MostUsedTerms Component
Displaying a variety of most used terms by taxonomy.
Usage
<MostUsedTerms onSelect={() => null} taxonomy={ taxonomyObject } />Props
| name | type | required | description |
|---|---|---|---|
| onSelect | function | yes | Setter for a selected term. Returns a term object containing the id, name, and count. |
| taxonomy | object | yes | Taxonomy object. |
TermSelector Component
Displaying a FormTokenField for selecting and searching for taxonomy terms.
Usage
<TermSelector
canCreate={ ! isLocked && hasCreateAction }
max={ MAX_TERMS_SUGGESTIONS }
onChange={ onChange }
onInputChange={ debounce( searchTerms, 500 ) }
singularName={ singularName }
slug={ slug }
suggestions={ availableTerms.map(
( term ) => term.name
) }
taxonomy={ taxonomy }
value={ selectedTerms }
/>Props
| prop | type | required | description |
|---|---|---|---|
| canCreate | boolean | yes | Whether or not term creation is allowed. Displays different text and validation. |
| max | int | yes | Max number of suggestions to display during search. |
| onChange | function | yes | onChange handler for selection. |
| onInputChange | function | yes | onChange handler for search. |
| slug | string | yes | Taxonomy slug. only required to handle label for tags differntly. |
| suggestions | array | yes | Array of term objects. |
| taxonomy | object | yes | Taxonomy object. |
| value | array | yes | Array of selected term ids. |
isSameTermName
Compare two term names to determine if they are the same.
termA: string — Term name for comparison 1.termB: string — Term name for comparison 2.
termNamesToIds
For each term name, return an id.
names: Array — Array of names.terms: Array — Array of terms.
MediaPicker
Allows for a reusable media uploader, replacer, and remover for adding media to blocks.
See also https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/media-placeholder/README.md (opens in a new tab) for additional descriptions of shared props.
Usage
<MediaPicker
className="custom-class-name"
allowedType={ [ 'image' ] }
icon="format-image"
label={ __( 'Product Image', 'pmc-gutenberg' ) }
instructions={__(
'Upload an image file, pick one from your media library, or add one with a URL.',
'pmc-gutenberg'
)}
onReset={ () => setAttributes( { image: 0 } ) }
onSelect={ ( next ) => setAttributes( { image: next } ) }
size="thumbnail"
value={ image }
/>Props
| prop | type | required | default | description |
|---|---|---|---|---|
| allowedTypes | array | no | [ 'image' ] | Array of allowed types. |
| className | string | no | '' | Classname string. |
| icon | string | element | no | 'format-image' |
| imageClassName | string | no | 'pmc-component__image | Image classname around preview image. |
| label | string | no | 'Image' | Label that displays in the placeholder and in the media picker modal. |
| onReset | function | yes | Callback function that fires on reset. | |
| onSelect | function | yes | Callback function that returns a media id on media change/upload. | |
| size | string | no | 'medium' | Size of image thumbnail to return from REST. |
| value | int | yes | Media id. |
Nova Ad
Nova Button
Nova Card
Nova Cards
Nova Header
A component that provides a selectable image, link, and optional name.
Usage
<Header
headerImageId={ headerImageId }
headerText={ headerText }
isSelected={ isSelected }
onChange={ setAttributes }
displayFields
/>Props
| prop | type | required | description |
|---|---|---|---|
| isSelected | bool | yes | Whether or not the element is selected. |
| onChange | function | yes | Callback function. Returns and object with key/value pair. |
| headerImageId | int | yes | Header image id. Attachement image id. |
| headerText | string | yes | Header text string. |
| displayFields | bool | no | Whether to display input fields when image is selected. |
Nova Promotion
Nova Sponsor
A component that provides a selectable image, link, and optional name.
Usage
<Sponsor
isSelected={ isSelected }
onChange={ setAttributes }
sponsorImageId={ sponsorImageId }
sponsorLeadIn={ sponsorLeadIn }
sponsorLink={ sponsorLink }
sponsorName={ sponsorName }
displayFields
/>Props
| prop | type | required | description |
|---|---|---|---|
| isSelected | bool | yes | Whether or not the element is selected. |
| onChange | function | yes | Callback function. Returns and object with key/value pair. |
| sponsorImageId | int | yes | Sponsor image id. Attachement image id. |
| sponsorLeadIn | string | yes | Sponsor lead in text. |
| sponsorLink | string | yes | Sponsor link, links the image or name. |
| sponsorName | string | yes | Sponsor name string. |
| displayFields | bool | no | Whether to display input fields when image is selected. |
Nova Text
Search
Contains the search form, search list, and list card components for use in the Content Recirculation and Related Content blocks, but are brand and context-agnostic.
Export from the main index.js file is the search form and the search form modal components.
PostSearchForm and PostSearchModal respectively.
Components
Search Card
This component displays a single post with a minimal set of post object values.
Usage
<SearchCard
onChange={ (next) => onChange(next) }
value={ posts }
/>Component Props
| prop | type | required | default | description |
|---|---|---|---|---|
| value | array | yes | Array of post objects. | |
| onChange | func | yes | Callback function returns the post object value selected. |
Expected Value Shape
The below is the expected object shape. By default the global search endpoint wp/v2/search returns
everything below save the media and the post_type (which is the subtype).
The media object contains the thumbnail and featured image alt text. Easily cached rather than needing to make a REST request in browser.
The post_type is the Singular name of the current post type. The subtype is the post's post type slug.
{
id: PropTypes.number,
media: PropTypes.shape( {
alt: PropTypes.string,
url: PropTypes.string,
} ),
post_type: PropTypes.string,
status: PropTypes.string,
subtype: PropTypes.string,
title: PropTypes.string,
type: PropTypes.exact( 'post' ),
url: PropTypes.string,
}Search Form
A parent component containing a search form (core SearchControl component), search results, and
individual cards for selection.
The component also provides a "load more" feature which will load additional posts page by page upon request.
This component is exported to PostSearchForm at the root and used inside the PostSearchModal
which expects the same props.
Usage
<SearchForm
className="custom-class"
onChange={ () => null }
/>Props
| prop | type | required | default | description |
|---|---|---|---|---|
| className | string | no | '' | Classname to add to the parent form component. |
| help | string | no | Search for any post type content | Help text displays below the search input. |
| label | string | no | Search for content | Label text that appears above the search input. |
| maxPages | int | no | 5 | Max number of pages to return. If 100 pages of results, the max number of loadable pages is this value. |
| onChange | func | yes | Callback function returns selected post object. | |
| placeholder | string | no | Search for content | Placeholder text that appears inside the search input. |
| postTypes | array | no | [] | An array of post types to search by. Default all post types supported by REST or where show_in_rest is true. |
| threshold | int | no | 3 | Minimum number of characters required for search before a fetch is made. |
Search Modal
A parent component containing the SearchForm component.
This component is exported to PostSearchModal at the root and uses the PostSearchForm
component as a child which expects the same props.
Usage
<SearchModal
className="custom-class"
onChange={ () => null }
onDismiss={ () => null }
isVisible
/>Props
| prop | type | required | default | description |
|---|---|---|---|---|
| className | string | no | '' | Classname to add to the parent form component. |
| help | string | no | Search for any post type content | Help text displays below the search input. |
| isVisible | bool | yes | Whether or not to display the modal. | |
| label | string | no | Search for content | Label text that appears above the search input. |
| maxPages | int | no | 5 | Max number of pages to return. If 100 pages of results, the max number of loadable pages is this value. |
| onChange | func | yes | Callback function returns selected post object. | |
| onDismiss | func | yes | Callback when the dismiss "X" is pressed in the modal. | |
| placeholder | string | no | Search for content | Placeholder text that appears inside the search input. |
| postTypes | array | no | [] | An array of post types to search by. Default all post types supported by REST or where show_in_rest is true. |
| threshold | int | no | 3 | Minimum number of characters required for search before a fetch is made. |
Component Search Results
Utilizes the SearchCard component to output a list of search-for results. A load-more option is
available if there are enough pages of search results to support it via props.
Usage
<SearchResults
canLoadMore
isLoading={ loading }
isVisible
onChange={ ( next ) => console.log(next) }
onLoadMore={ () => null }
options={ [] }
page={ 1 }
query="search query"
/>Props
| prop | type | required | description |
|---|---|---|---|
| canLoadMore | bool | yes | Whether or not the "load more content" button is to be shown. |
| isLoading | bool | yes | Whether or not we should display the loading spinner or busy button. |
| isVisible | bool | yes | Whether or not the search results should be shown. |
| onChange | func | yes | Callback returning a selected post object. |
| onLoadMore | func | yes | Callback when the "load more content" is clicked. Increments page + 1. |
| options | array | yes | Array of post objects defined in the SearchCard component. |
| query | string | yes | Search string. |
| page | int | yes | Current page number of fetched results. Used by onLoadMore. |
Render Appender
A custom render appender for use with InnerBlocks allowing you to insert a block of your choice with props of your choice.
This allows you also to pass default attributes to the selected block type(s) and limit the max number of insertable items.
Usage
<RenderAppender
attributes={{ text: 'This is a test' }}
block="core/paragraph"
callback={(nextName, nextAttributes) => callback(nextName, nextAttributes)}
clientId={clientId}
icon="plus"
label={__('Add Block', 'pmc-gutenberg')}
max={4}
/>Props
| prop | type | required | default | description |
|---|---|---|---|---|
| attributes | object | no | An object container block attributes for the block defined. | |
| callback | function | no | () => null | Callback returns set block name and attributes. |
| block | string | yes | Block name, including namespace. eg. core/paragraph. | |
| clientId | string | yes | The parent block with InnerBlocks support. | |
| icon | string | element | no | null |
| label | string | no | 'Add Block' | The text for the button. |
| max | int | no | 2 | Max number of blocks you are allowed to insert. Allows you to limit insertion. |
SearchControl
A custom simple search select dropdown. Supply the options, the value, and you are provided a callback for select.
Usage
<SearchControl
isLoading={ isLoadingPosts }
label={ __(
'Start typing to search for a list to add this list item to.',
'pmc-gutenberg'
) }
placeholder={ __( 'Search for a list', 'pmc-gutenberg' ) }
onSelect={ setSelected }
onInputChange={ setSearch }
options={ listPosts }
value={ search }
/>Props
| prop | type | required | default | description |
|---|---|---|---|---|
| hideLabelFromVision | boolean | no | true | Whether or not to hide the label from vision. |
| isLoading | boolean | yes | Loading spinner should be displayed. | |
| label | string | no | Search | Input label. |
| onSelect | function | yes | Change handler when item is selected. | |
| onInputChange | function | yes | Change handler when input is changed. | |
| options | array | yes | Array of objects containing a value and label. | |
| placeholder | string | no | Search | Input placeholder. |
| value | string | yes | Current input value. |
SEO Prevent Index
Provides a field to read and write from the _mt_pmc_exclude_from_seo meta.
TODO: Provide a value and callback setter to the component directly rather than relying on the component to do that work.
Usage
<SeoPreventIndex />SEO Preview Edit
Provides an editable preview component with editable title and description.
- Title override:
mt_seo_title - Description override:
mt_seo_description
Usage
<SeoPreviewEdit
description="SEO Description"
isSelected={true}
link="https://pmc.com"
onChange={onChangeCallback}
published="2022-04-13T15:38:50"
title="SEO Title"
/>Props
| prop | type | required | default | description |
|---|---|---|---|---|
| description | string | yes | SEO description to display. | |
| isSelected | bool | yes | false | Shows editable fields when isSelected is true. |
| link | string | yes | Canonical url. | |
| onUpdate | function | yes | Callback function, returns object of edited title and description. | |
| published | string | yes | Post published date. | |
| title | string | yes | SEO title to display. |
Term List Control
Uses the core SelectControl to output a list of term objects.
See also https://github.com/WordPress/gutenberg/tree/trunk/packages/components/src/select-control (opens in a new tab), though not all props are supported in this component as they've been deemed unecessary.
Usage
<TermListControl
value={ 10 }
label={__( 'Select a term', 'pmc-gutenberg' ) }
terms={ [
{ id: 10, name: 'Test Category' },
{ id: 15, name: 'Test Category 2' }
] }
onChange={onChangeCallback}
/>Props
| prop | default | type | required | description |
|---|---|---|---|---|
| className | string | no | Classname. | |
| help | string | no | Help text shown under the select dropdown. | |
| defaultLabel | Select a term | string | no | Default label to display as default non-value select option. |
| hideLabelFromVision | false | bool | no | If true, the label will only be visible to screen readers. |
| label | string | no | Label which would display above the input. | |
| labelPosition | top | string | no | The position of the label (top, side, or bottom). |
| onChange | function | yes | Callback function, returns term id. | |
| terms | [] | array | yes | Array of term objects. |
| value | 0 | null|integer | yes | Term id selected. |
Use Timer
Simple count-up timer that returns minutes and seconds in a duple.
Usage
const App = () => {
return <Timer isActive={false} />
}Props
| prop | type | required | default | description |
|---|---|---|---|---|
| className | string | no | '' | Class name to append to the timer span. |
| isActive | boolean | yes | When the timer should kick off or stop. | |
| label | string | no | Timer | Aria label. |
| style | object | no | Style object. |
Word Count
Displays the number of words and characters given a string.
Usage
<WordCount
text="This is a string"
excludeCharSpaces={ true }
showRemainingAlert={ 70 }
/>Note
The showRemainingAlert prop will be used in order to show the visual indication for the remaining character count.
Props
| props | type | required | default | description |
|---|---|---|---|---|
| text | string | yes | String for which to determine word and character count. | |
| excludeCharSpaces | bool | no | false | Decide weather to exclude spaces from character count? |
| showRemainingAlert | number | no | Weather to show the visual indication of remaining character count ? |