Source Directory
Components

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

proptyperequireddefaultdescription
titlestringno''Title to show in the placeholder element.
showHiddenIconboolnofalseWhether or not to show the hidden dashicon.
classNamestringno''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

proptyperequireddefaultdescription
canRemoveboolnofalseWhether or not to allow removing the block by client id.
childrennodeyesChildren to render inside the component wrapper.
classNamestringno''Classname string.
clientIdstringyesRoot client id.
iconstring|elementno''Dashicon name or SVG element.
isEditingboolnofalseWhether or not the "edit" state should be visible.
isOpenboolnofalseWhether or not to set the default state to open.
isPreviewingboolnofalseWhether or not the "preview" state should be visible
onEditfunctionnonullCallback triggered when "edit" BlockControl is clicked.
onPreviewfunctionnonullCallback triggered when "preview" BlockControl is clicked.
onTogglefunctionnonullCallback that returns the state of the container, true or false
titlestringno''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

nametypedefaultrequireddescription
entitystring'post'noThe post type slug or taxonomy slug to query.
labelstring'Find Post Type'noThe label to display above the FormTokenField.
maxint20noThe max number of results to display during search.
onSelectfunctionyesCallback returns array of selected ids.
placeholderstring'Search for a post..."noThe placeholder to display inside the FormTokenField input.
queryobjectnoAn object container rest field query values supported by rest or getEntityRecords.
typeenum'postType'noEntity type, postType or taxonomy.
valuearrayyesArray if post or taxonomy ids.
maxValuesint20noThe 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

nametyperequireddescription
slugstringyesThe taxonomy slug to represent.
lockedbooleannoWhether 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

proptyperequireddescription
onChangefunctionyesonChange handler for terms.
selectedTermsarrayyesarray of selected term strings.

MostUsedTerms Component

Displaying a variety of most used terms by taxonomy.

Usage

<MostUsedTerms onSelect={() => null} taxonomy={ taxonomyObject } />

Props

nametyperequireddescription
onSelectfunctionyesSetter for a selected term. Returns a term object containing the id, name, and count.
taxonomyobjectyesTaxonomy 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

proptyperequireddescription
canCreatebooleanyesWhether or not term creation is allowed. Displays different text and validation.
maxintyesMax number of suggestions to display during search.
onChangefunctionyesonChange handler for selection.
onInputChangefunctionyesonChange handler for search.
slugstringyesTaxonomy slug. only required to handle label for tags differntly.
suggestionsarrayyesArray of term objects.
taxonomyobjectyesTaxonomy object.
valuearrayyesArray 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

proptyperequireddefaultdescription
allowedTypesarrayno[ 'image' ]Array of allowed types.
classNamestringno''Classname string.
iconstringelementno'format-image'
imageClassNamestringno'pmc-component__imageImage classname around preview image.
labelstringno'Image'Label that displays in the placeholder and in the media picker modal.
onResetfunctionyesCallback function that fires on reset.
onSelectfunctionyesCallback function that returns a media id on media change/upload.
sizestringno'medium'Size of image thumbnail to return from REST.
valueintyesMedia 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

proptyperequireddescription
isSelectedboolyesWhether or not the element is selected.
onChangefunctionyesCallback function. Returns and object with key/value pair.
headerImageIdintyesHeader image id. Attachement image id.
headerTextstringyesHeader text string.
displayFieldsboolnoWhether 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

proptyperequireddescription
isSelectedboolyesWhether or not the element is selected.
onChangefunctionyesCallback function. Returns and object with key/value pair.
sponsorImageIdintyesSponsor image id. Attachement image id.
sponsorLeadInstringyesSponsor lead in text.
sponsorLinkstringyesSponsor link, links the image or name.
sponsorNamestringyesSponsor name string.
displayFieldsboolnoWhether 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

proptyperequireddefaultdescription
valuearrayyesArray of post objects.
onChangefuncyesCallback 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

proptyperequireddefaultdescription
classNamestringno''Classname to add to the parent form component.
helpstringnoSearch for any post type contentHelp text displays below the search input.
labelstringnoSearch for contentLabel text that appears above the search input.
maxPagesintno5Max number of pages to return. If 100 pages of results, the max number of loadable pages is this value.
onChangefuncyesCallback function returns selected post object.
placeholderstringnoSearch for contentPlaceholder text that appears inside the search input.
postTypesarrayno[]An array of post types to search by. Default all post types supported by REST or where show_in_rest is true.
thresholdintno3Minimum 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

proptyperequireddefaultdescription
classNamestringno''Classname to add to the parent form component.
helpstringnoSearch for any post type contentHelp text displays below the search input.
isVisibleboolyesWhether or not to display the modal.
labelstringnoSearch for contentLabel text that appears above the search input.
maxPagesintno5Max number of pages to return. If 100 pages of results, the max number of loadable pages is this value.
onChangefuncyesCallback function returns selected post object.
onDismissfuncyesCallback when the dismiss "X" is pressed in the modal.
placeholderstringnoSearch for contentPlaceholder text that appears inside the search input.
postTypesarrayno[]An array of post types to search by. Default all post types supported by REST or where show_in_rest is true.
thresholdintno3Minimum 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

proptyperequireddescription
canLoadMoreboolyesWhether or not the "load more content" button is to be shown.
isLoadingboolyesWhether or not we should display the loading spinner or busy button.
isVisibleboolyesWhether or not the search results should be shown.
onChangefuncyesCallback returning a selected post object.
onLoadMorefuncyesCallback when the "load more content" is clicked. Increments page + 1.
optionsarrayyesArray of post objects defined in the SearchCard component.
querystringyesSearch string.
pageintyesCurrent 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

proptyperequireddefaultdescription
attributesobjectnoAn object container block attributes for the block defined.
callbackfunctionno() => nullCallback returns set block name and attributes.
blockstringyesBlock name, including namespace. eg. core/paragraph.
clientIdstringyesThe parent block with InnerBlocks support.
iconstringelementnonull
labelstringno'Add Block'The text for the button.
maxintno2Max 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

proptyperequireddefaultdescription
hideLabelFromVisionbooleannotrueWhether or not to hide the label from vision.
isLoadingbooleanyesLoading spinner should be displayed.
labelstringnoSearchInput label.
onSelectfunctionyesChange handler when item is selected.
onInputChangefunctionyesChange handler when input is changed.
optionsarrayyesArray of objects containing a value and label.
placeholderstringnoSearchInput placeholder.
valuestringyesCurrent 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

proptyperequireddefaultdescription
descriptionstringyesSEO description to display.
isSelectedboolyesfalseShows editable fields when isSelected is true.
linkstringyesCanonical url.
onUpdatefunctionyesCallback function, returns object of edited title and description.
publishedstringyesPost published date.
titlestringyesSEO 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

propdefaulttyperequireddescription
classNamestringnoClassname.
helpstringnoHelp text shown under the select dropdown.
defaultLabelSelect a termstringnoDefault label to display as default non-value select option.
hideLabelFromVisionfalseboolnoIf true, the label will only be visible to screen readers.
labelstringnoLabel which would display above the input.
labelPositiontopstringnoThe position of the label (top, side, or bottom).
onChangefunctionyesCallback function, returns term id.
terms[]arrayyesArray of term objects.
value0null|integeryesTerm id selected.

Use Timer

Simple count-up timer that returns minutes and seconds in a duple.

Usage

const App = () => {
	return <Timer isActive={false} />
}

Props

proptyperequireddefaultdescription
classNamestringno''Class name to append to the timer span.
isActivebooleanyesWhen the timer should kick off or stop.
labelstringnoTimerAria label.
styleobjectnoStyle 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

propstyperequireddefaultdescription
textstringyesString for which to determine word and character count.
excludeCharSpacesboolnofalseDecide weather to exclude spaces from character count?
showRemainingAlertnumbernoWeather to show the visual indication of remaining character count ?