@plaudit/gutenberg-api-extensions 1.5.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { BlockIcon } from "@wordpress/blocks";
|
|
1
2
|
import type { PickableOptions, SimpleBlockControlProps } from "./types";
|
|
2
3
|
import React from "react";
|
|
3
|
-
import { BlockIcon } from "@wordpress/blocks";
|
|
4
4
|
export declare function PickOneFromToggleGroup<T extends string>(props: SimpleBlockControlProps<T, string> & {
|
|
5
5
|
options: PickableOptions<{
|
|
6
6
|
icon: BlockIcon;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, ColorPalette, RadioControl, SelectControl } from "@wordpress/components";
|
|
1
|
+
import { __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, BaseControl, ColorPalette, RadioControl, SelectControl, useBaseControlProps } from "@wordpress/components";
|
|
2
2
|
import React from "react";
|
|
3
3
|
function makeSharedRadioAndSelectProps(props) {
|
|
4
4
|
return {
|
|
5
5
|
label: props.label,
|
|
6
|
-
onChange
|
|
7
|
-
|
|
6
|
+
onChange(value) {
|
|
7
|
+
props.setAttributes({ [props.attribute]: value });
|
|
8
|
+
},
|
|
9
|
+
options: props.options.map(([value, label]) => ({
|
|
8
10
|
value, label: typeof label === 'string' ? label : label.text
|
|
9
11
|
}))
|
|
10
12
|
};
|
|
11
13
|
}
|
|
12
14
|
export function PickOneFromToggleGroup(props) {
|
|
13
|
-
return React.createElement(ToggleGroupControl, { label: props.label, value: props.attributes[props.attribute], onChange: value => props.setAttributes({ [props.attribute]: value }), children:
|
|
15
|
+
return React.createElement(ToggleGroupControl, { label: props.label, value: props.attributes[props.attribute], onChange: value => props.setAttributes({ [props.attribute]: value }), children: props.options.map(([value, label]) => typeof label === 'string'
|
|
14
16
|
? React.createElement(ToggleGroupControlOption, { key: value, value: value, label: label })
|
|
15
17
|
: React.createElement(ToggleGroupControlOptionIcon, { key: value, value: value, label: label.text, icon: label.icon })) });
|
|
16
18
|
}
|
|
@@ -25,7 +27,7 @@ export function PickOneFromColors(props) {
|
|
|
25
27
|
const valueToColorMap = new Map();
|
|
26
28
|
const colorToValueMap = new Map();
|
|
27
29
|
const colors = [];
|
|
28
|
-
for (const [value, display] of
|
|
30
|
+
for (const [value, display] of props.options) {
|
|
29
31
|
if (typeof display === 'string') {
|
|
30
32
|
colors.push({ color: value, name: display });
|
|
31
33
|
}
|
|
@@ -39,8 +41,7 @@ export function PickOneFromColors(props) {
|
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
const currentColor = (_a = valueToColorMap.get(props.attributes[props.attribute])) !== null && _a !== void 0 ? _a : props.attributes[props.attribute];
|
|
42
|
-
const
|
|
43
|
-
return React.createElement(
|
|
44
|
-
React.createElement(
|
|
45
|
-
React.createElement(ColorPalette, { id: id, disableCustomColors: true, onChange: color => { var _a, _b; return props.setAttributes({ [props.attribute]: (_b = (_a = colorToValueMap.get(color !== null && color !== void 0 ? color : currentColor)) !== null && _a !== void 0 ? _a : color) !== null && _b !== void 0 ? _b : currentColor }); }, colors: colors, value: currentColor, clearable: false }));
|
|
44
|
+
const { baseControlProps, controlProps } = useBaseControlProps({ label: props.label });
|
|
45
|
+
return React.createElement(BaseControl, Object.assign({}, baseControlProps),
|
|
46
|
+
React.createElement(ColorPalette, Object.assign({}, controlProps, { disableCustomColors: true, onChange: color => { var _a, _b; return props.setAttributes({ [props.attribute]: (_b = (_a = colorToValueMap.get(color !== null && color !== void 0 ? color : currentColor)) !== null && _a !== void 0 ? _a : color) !== null && _b !== void 0 ? _b : currentColor }); }, colors: colors, value: currentColor, clearable: false })));
|
|
46
47
|
}
|
|
@@ -7,6 +7,6 @@ export type SpecificValueBlockProps<T extends string, V> = {
|
|
|
7
7
|
export type SimpleBlockControlProps<T extends string, V> = SpecificValueBlockProps<T, V> & {
|
|
8
8
|
label: string;
|
|
9
9
|
};
|
|
10
|
-
export type PickableOptions<T extends object = {}> =
|
|
10
|
+
export type PickableOptions<T extends object = {}> = Array<[string, string | ({
|
|
11
11
|
text: string;
|
|
12
|
-
} & T)>;
|
|
12
|
+
} & T)]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/gutenberg-api-extensions",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
"./blocks": "./build/blocks/index.js",
|
|
14
14
|
"./controls": "./build/controls/index.js"
|
|
15
15
|
},
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
"blocks": ["build/blocks/index.d.ts"],
|
|
19
|
+
"controls": ["build/controls/index.d.ts"],
|
|
20
|
+
"lib/plaudit-icons": ["build/lib/plaudit-icons.d.ts"]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
16
23
|
"dependencies": {
|
|
17
24
|
"@wordpress/block-editor": "^12.4.0",
|
|
18
25
|
"@wordpress/blocks": "^12.13.0",
|