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

Convert _experimentalCreateInterpolateElement to a stable api. #20699

Merged
merged 3 commits into from
Mar 18, 2020
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
11 changes: 4 additions & 7 deletions packages/block-editor/src/components/inserter/tips.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
__experimentalCreateInterpolateElement,
useState,
} from '@wordpress/element';
import { createInterpolateElement, useState } from '@wordpress/element';
import { Tip } from '@wordpress/components';

const globalTips = [
__experimentalCreateInterpolateElement(
createInterpolateElement(
__(
'While writing, you can press <kbd>/</kbd> to quickly insert new blocks.'
),
{ kbd: <kbd /> }
),
__experimentalCreateInterpolateElement(
createInterpolateElement(
__(
'Indent a list by pressing <kbd>space</kbd> at the beginning of a line.'
),
{ kbd: <kbd /> }
),
__experimentalCreateInterpolateElement(
createInterpolateElement(
__(
'Outdent a list by pressing <kbd>backspace</kbd> at the beginning of a line'
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import classnames from 'classnames';
*/
import { __, sprintf } from '@wordpress/i18n';
import { Button, Icon } from '@wordpress/components';
import { __experimentalCreateInterpolateElement } from '@wordpress/element';
import { createInterpolateElement } from '@wordpress/element';

export const LinkControlSearchCreate = ( {
searchTerm,
Expand Down Expand Up @@ -38,7 +38,7 @@ export const LinkControlSearchCreate = ( {

<span className="block-editor-link-control__search-item-header">
<span className="block-editor-link-control__search-item-title">
{ __experimentalCreateInterpolateElement(
{ createInterpolateElement(
sprintf(
__( 'New page: <mark>%s</mark>' ),
searchTerm
Expand Down
11 changes: 4 additions & 7 deletions packages/components/src/text-highlight/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { escapeRegExp } from 'lodash';
/**
* WordPress dependencies
*/
import { __experimentalCreateInterpolateElement } from '@wordpress/element';
import { createInterpolateElement } from '@wordpress/element';

const TextHighlight = ( { text = '', highlight = '' } ) => {
if ( ! highlight.trim() ) {
Expand All @@ -15,12 +15,9 @@ const TextHighlight = ( { text = '', highlight = '' } ) => {

const regex = new RegExp( `(${ escapeRegExp( highlight ) })`, 'gi' );

return __experimentalCreateInterpolateElement(
text.replace( regex, '<mark>$&</mark>' ),
{
mark: <mark />,
}
);
return createInterpolateElement( text.replace( regex, '<mark>$&</mark>' ), {
mark: <mark />,
} );
};

export default TextHighlight;
4 changes: 2 additions & 2 deletions packages/edit-post/src/components/welcome-guide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { useSelect, useDispatch } from '@wordpress/data';
import { ExternalLink, Guide, GuidePage } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { __experimentalCreateInterpolateElement } from '@wordpress/element';
import { createInterpolateElement } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -67,7 +67,7 @@ export default function WelcomeGuide() {
</h1>
<BlockLibraryImage className="edit-post-welcome-guide__image" />
<p className="edit-post-welcome-guide__text">
{ __experimentalCreateInterpolateElement(
{ createInterpolateElement(
__(
'All of the blocks available to you live in the block library. You’ll find it wherever you see the <InserterIconImage /> icon.'
),
Expand Down
38 changes: 21 additions & 17 deletions packages/element/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
## Master

- Graduated `__experimentalCreateInterpolateElement` function to stable api: `createInterpolateElement` (see [20699](https://github.com/WordPress/gutenberg/pull/20699))

## 2.10.0 (2019-12-19)

### New Features

- Added `__experimentalCreateInterpolateElement` function (see [17376](https://github.com/WordPress/gutenberg/pull/17376))
- Added `__experimentalCreateInterpolateElement` function (see [17376](https://github.com/WordPress/gutenberg/pull/17376))
Comment on lines -5 to +9
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why all the extra spacing was added to the markdown. It happened on saving the file which leads me to believe there was a markdown linting change or prettier is affecting this maybe?


## 2.8.0 (2019-09-16)

### New Features

- The bundled `react` dependency has been updated from requiring `^16.8.4` to requiring `^16.9.0` ([#16982](https://github.com/WordPress/gutenberg/pull/16982)). It contains [new deprecations](https://reactjs.org/blog/2019/08/08/react-v16.9.0.html#new-deprecations) as well.
- The bundled `react-dom` dependency has been updated from requiring `^16.8.4` to requiring `^16.9.0` ([#16982](https://github.com/WordPress/gutenberg/pull/16982)).
- The bundled `react` dependency has been updated from requiring `^16.8.4` to requiring `^16.9.0` ([#16982](https://github.com/WordPress/gutenberg/pull/16982)). It contains [new deprecations](https://reactjs.org/blog/2019/08/08/react-v16.9.0.html#new-deprecations) as well.
- The bundled `react-dom` dependency has been updated from requiring `^16.8.4` to requiring `^16.9.0` ([#16982](https://github.com/WordPress/gutenberg/pull/16982)).

## 2.4.0 (2019-05-21)

### New Features

- Added `lazy` feautre (see: https://reactjs.org/docs/react-api.html#reactlazy).
- Added `Suspense` component (see: https://reactjs.org/docs/react-api.html#reactsuspense).
- Added `lazy` feautre (see: https://reactjs.org/docs/react-api.html#reactlazy).
- Added `Suspense` component (see: https://reactjs.org/docs/react-api.html#reactsuspense).

## 2.3.0 (2019-03-06)

### New Features

- Added `useCallback` hook (see: https://reactjs.org/docs/hooks-reference.html#usecallback).
- Added `useContext` hook (see: https://reactjs.org/docs/hooks-reference.html#usecontext).
- Added `useDebugValue` hook (see: https://reactjs.org/docs/hooks-reference.html#usedebugvalue).
- Added `useEffect` hook (see: https://reactjs.org/docs/hooks-reference.html#useeffect).
- Added `useImperativeHandle` hook (see: https://reactjs.org/docs/hooks-reference.html#useimperativehandle).
- Added `useLayoutEffect` hook (see: https://reactjs.org/docs/hooks-reference.html#uselayouteffect).
- Added `useMemo` hook (see: https://reactjs.org/docs/hooks-reference.html#usememo).
- Added `useReducer` hook (see: https://reactjs.org/docs/hooks-reference.html#usereducer).
- Added `useRef` hook (see: https://reactjs.org/docs/hooks-reference.html#useref).
- Added `useState` hook (see: https://reactjs.org/docs/hooks-reference.html#usestate).
- Added `useCallback` hook (see: https://reactjs.org/docs/hooks-reference.html#usecallback).
- Added `useContext` hook (see: https://reactjs.org/docs/hooks-reference.html#usecontext).
- Added `useDebugValue` hook (see: https://reactjs.org/docs/hooks-reference.html#usedebugvalue).
- Added `useEffect` hook (see: https://reactjs.org/docs/hooks-reference.html#useeffect).
- Added `useImperativeHandle` hook (see: https://reactjs.org/docs/hooks-reference.html#useimperativehandle).
- Added `useLayoutEffect` hook (see: https://reactjs.org/docs/hooks-reference.html#uselayouteffect).
- Added `useMemo` hook (see: https://reactjs.org/docs/hooks-reference.html#usememo).
- Added `useReducer` hook (see: https://reactjs.org/docs/hooks-reference.html#usereducer).
- Added `useRef` hook (see: https://reactjs.org/docs/hooks-reference.html#useref).
- Added `useState` hook (see: https://reactjs.org/docs/hooks-reference.html#usestate).

## 2.1.8 (2018-11-15)

Expand All @@ -47,10 +51,10 @@

## 2.1.0 (2018-09-30)

- New API method `isEmptyElement` was introduced ([9861](https://github.com/WordPress/gutenberg/pull/9681/)).
- New API method `isEmptyElement` was introduced ([9861](https://github.com/WordPress/gutenberg/pull/9681/)).

## 2.0.0 (2018-09-05)

### Breaking Change

- Change how required built-ins are polyfilled with Babel 7 ([#9171](https://github.com/WordPress/gutenberg/pull/9171)). If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods.
- Change how required built-ins are polyfilled with Babel 7 ([#9171](https://github.com/WordPress/gutenberg/pull/9171)). If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods.
32 changes: 32 additions & 0 deletions packages/element/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,38 @@ _Returns_

- `WPElement`: Element.

<a name="createInterpolateElement" href="#createInterpolateElement">#</a> **createInterpolateElement**

This function creates an interpolated element from a passed in string with
specific tags matching how the string should be converted to an element via
the conversion map value.

_Usage_

For example, for the given string:

"This is a <span>string</span> with <a>a link</a> and a self-closing
<CustomComponentB/> tag"

You would have something like this as the conversionMap value:

```js
{
span: <span />,
a: <a href={ 'https://github.com' } />,
CustomComponentB: <CustomComponent />,
}
```

_Parameters_

- _interpolatedString_ `string`: The interpolation string to be parsed.
- _conversionMap_ `Object`: The map used to convert the string to a react element.

_Returns_

- `WPElement`: A wp element.

<a name="createPortal" href="#createPortal">#</a> **createPortal**

Creates a portal into which a component can be rendered.
Expand Down
2 changes: 1 addition & 1 deletion packages/element/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as __experimentalCreateInterpolateElement } from './create-interpolate-element';
export { default as createInterpolateElement } from './create-interpolate-element';
export * from './react';
export * from './react-platform';
export * from './utils';
Expand Down