Skip to content

Commit 6f2f767

Browse files
authored
Merge pull request #114 from jverneaut/113-implement-contentpicker-from-10upblock-components
113 Implement ContentPicker from 10up/block components
2 parents 0e28af4 + 35a65f0 commit 6f2f767

17 files changed

Lines changed: 166 additions & 189 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useBlockProps } from "@wordpress/block-editor";
2+
import { ContentPicker } from "@10up/block-components/components/content-picker";
3+
4+
export default ({ attributes, setAttributes }) => {
5+
return (
6+
<section {...useBlockProps()}>
7+
<ContentPicker
8+
content={attributes.posts}
9+
onPickChange={(posts) => setAttributes({ posts })}
10+
contentTypes={["post", "page"]}
11+
maxContentItems={5}
12+
></ContentPicker>
13+
</section>
14+
);
15+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "custom/input",
3+
"title": "Input",
4+
"textdomain": "input",
5+
"$schema": "https://schemas.wp.org/trunk/block.json",
6+
"apiVersion": 3,
7+
"version": "0.1.0",
8+
"category": "theme",
9+
"example": {},
10+
"attributes": {
11+
"align": { "type": "string", "default": "full" },
12+
"posts": { "type": "array" }
13+
},
14+
"supports": { "html": false, "align": ["full"] },
15+
"editorScript": "file:./index.js",
16+
"render": "file:./render.php"
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<section <?php echo get_block_wrapper_attributes(); ?>>
2+
</section>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<section>
2+
<content-picker
3+
data-bind="posts"
4+
content-types="post page"
5+
max-content-items="5"
6+
></content-picker>
7+
</section>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import CodeExample from "@site/src/components/CodeExample";
2+
3+
# Using the ContentPicker component
4+
5+
**HTML To Gutenberg** supports integration with the `ContentPicker` component from [@10up/block-components](https://github.com/10up/block-components) through the custom element `<content-picker>`.
6+
7+
Currently, this component supports [data binding](data-binding.mdx) only to attributes via the `data-bind` attribute (e.g., `data-bind="attributeName"`). Additionally, you can control how many posts can be selected by setting the `max-content-items` attribute.
8+
9+
## Typical Use Case
10+
11+
A common scenario for using this component is to let editors select posts directly within the editor interface, and then render those posts server-side in your block’s `render.php` file using [file overrides](overrides.mdx).
12+
13+
<CodeExample>
14+
```
15+
<section>
16+
<inspector-controls>
17+
<panel-body title="Settings">
18+
<content-picker data-bind="posts"></content-picker>
19+
</panel-body>
20+
</inspector-controls>
21+
22+
<server-block name="custom/posts-slider"></server-block>
23+
24+
</section>
25+
```
26+
</CodeExample>

docs/src/pages/new-live-editor.js

Lines changed: 0 additions & 186 deletions
This file was deleted.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jverneaut/html-to-gutenberg",
3-
"version": "2.2.1",
3+
"version": "2.3.0",
44
"main": "index.js",
55
"engines": {
66
"node": ">=20.0.0"

src/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ export const DATA_BIND_WITH_OPTIONS_ELEMENTS = [
1818
"toolbar-dropdown-menu",
1919
];
2020

21+
export const DATA_BIND_CONTENT_PICKER_ELEMENT = "content-picker";
22+
2123
export const DATA_BIND_NON_RICH_TEXT_ELEMENTS = [
2224
...DATA_BIND_INPUT_ELEMENTS,
2325
...DATA_BIND_IMAGE_ELEMENTS,
2426
...DATA_BIND_CONTROLS_ELEMENTS,
27+
DATA_BIND_CONTENT_PICKER_ELEMENT,
2528
];
2629

2730
export const DATA_BIND_TYPES = {

src/getDefaultBlockData.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const defaultBlockData = {
1818
_hasToolbarButtonImport: false,
1919
_hasToolbarDropdownMenuImport: false,
2020
_hasBlockControlsImport: false,
21+
_hasContentPickerImport: false,
2122

2223
_hasWordPressComponents: false,
2324
_hasInspectorControlsImport: false,

0 commit comments

Comments
 (0)