@times-design-system/components-wordpress 1.5.3 → 1.6.0
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.
- package/dist/blocks/ad-container/block.json +10 -0
- package/dist/blocks/ad-container/edit.js +17 -1
- package/dist/blocks/ad-container/render.php +14 -0
- package/dist/blocks/button/block.json +19 -5
- package/dist/blocks/button/edit.js +33 -15
- package/dist/blocks/button/render.php +24 -2
- package/dist/blocks/button/style.css +63 -0
- package/dist/blocks/chip/block.json +12 -7
- package/dist/blocks/chip/edit.js +20 -17
- package/dist/blocks/chip/render.php +14 -2
- package/dist/blocks/dialog-box/block.json +10 -0
- package/dist/blocks/dialog-box/edit.js +17 -0
- package/dist/blocks/dialog-box/render.php +16 -4
- package/dist/blocks/divider/block.json +10 -0
- package/dist/blocks/divider/edit.js +18 -2
- package/dist/blocks/divider/render.php +14 -1
- package/dist/blocks/flag/block.json +10 -0
- package/dist/blocks/flag/edit.js +27 -2
- package/dist/blocks/flag/render.php +14 -0
- package/dist/blocks/icon/block.json +10 -0
- package/dist/blocks/icon/edit.js +17 -0
- package/dist/blocks/icon/render.php +16 -4
- package/dist/blocks/icon-button/block.json +15 -0
- package/dist/blocks/icon-button/edit.js +33 -1
- package/dist/blocks/icon-button/render.php +19 -0
- package/dist/blocks/icon-button/style.css +37 -3
- package/dist/blocks/input/block.json +10 -0
- package/dist/blocks/input/edit.js +27 -1
- package/dist/blocks/input/render.php +17 -1
- package/dist/blocks/input-helper-message/block.json +10 -0
- package/dist/blocks/input-helper-message/edit.js +17 -0
- package/dist/blocks/input-helper-message/render.php +16 -4
- package/dist/blocks/link/block.json +12 -7
- package/dist/blocks/link/edit.js +21 -18
- package/dist/blocks/link/render.php +14 -2
- package/dist/blocks/tab/block.json +10 -0
- package/dist/blocks/tab/edit.js +17 -0
- package/dist/blocks/tab/render.php +16 -4
- package/dist/blocks/tab-group/block.json +10 -0
- package/dist/blocks/tab-group/edit.js +17 -0
- package/dist/blocks/tab-group/render.php +16 -4
- package/dist/blocks/text/block.json +10 -0
- package/dist/blocks/text/edit.js +18 -2
- package/dist/blocks/text/render.php +14 -1
- package/dist/blocks/toast/block.json +10 -0
- package/dist/blocks/toast/edit.js +18 -1
- package/dist/blocks/toast/render.php +14 -0
- package/dist/index.cjs +389 -148
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +389 -148
- package/dist/index.js.map +1 -1
- package/dist/utils/DATA_ATTRIBUTES_USAGE.md +377 -0
- package/dist/utils/sanitize-data-attributes.php +109 -0
- package/package.json +9 -3
- package/BLOCK_CREATION_CHECKLIST.md +0 -385
- package/BUILD.md +0 -411
- package/CHANGELOG.md +0 -85
- package/SCSS_VARIABLES_REFERENCE.md +0 -316
- package/STYLING_SYNC_GUIDE.md +0 -306
- package/TESTING.md +0 -152
- package/TRANSFORMATION_GUIDE.md +0 -908
- package/dist/blocks/button/style-resolved.css +0 -153
- package/lib/wordpress.js +0 -7
- package/rollup.config.js +0 -75
- package/scripts/build-plugin.cjs +0 -121
- package/scripts/create-block.sh +0 -141
- package/scripts/create-wordpress-block-tests.cjs +0 -438
- package/scripts/create-wordpress-block.cjs +0 -681
- package/src/blocks/ad-container/block.json +0 -29
- package/src/blocks/ad-container/edit.js +0 -42
- package/src/blocks/ad-container/index.js +0 -10
- package/src/blocks/ad-container/render.php +0 -27
- package/src/blocks/ad-container/save.js +0 -16
- package/src/blocks/ad-container/style-editor.css +0 -4
- package/src/blocks/ad-container/style.css +0 -30
- package/src/blocks/button/block.json +0 -90
- package/src/blocks/button/edit.js +0 -187
- package/src/blocks/button/index.js +0 -11
- package/src/blocks/button/render.php +0 -71
- package/src/blocks/button/save.js +0 -52
- package/src/blocks/button/style-editor.css +0 -15
- package/src/blocks/button/style-resolved.css +0 -153
- package/src/blocks/button/style.css +0 -157
- package/src/blocks/chip/block.json +0 -58
- package/src/blocks/chip/edit.js +0 -113
- package/src/blocks/chip/index.js +0 -10
- package/src/blocks/chip/render.php +0 -40
- package/src/blocks/chip/save.js +0 -36
- package/src/blocks/chip/style-editor.css +0 -5
- package/src/blocks/chip/style.css +0 -87
- package/src/blocks/dialog-box/block.json +0 -24
- package/src/blocks/dialog-box/edit.js +0 -41
- package/src/blocks/dialog-box/index.js +0 -17
- package/src/blocks/dialog-box/render.php +0 -24
- package/src/blocks/dialog-box/save.js +0 -23
- package/src/blocks/dialog-box/style.css +0 -23
- package/src/blocks/divider/block.json +0 -32
- package/src/blocks/divider/edit.js +0 -42
- package/src/blocks/divider/index.js +0 -10
- package/src/blocks/divider/render.php +0 -31
- package/src/blocks/divider/save.js +0 -18
- package/src/blocks/divider/style-editor.css +0 -4
- package/src/blocks/divider/style.css +0 -37
- package/src/blocks/flag/block.json +0 -49
- package/src/blocks/flag/edit.js +0 -82
- package/src/blocks/flag/index.js +0 -10
- package/src/blocks/flag/render.php +0 -34
- package/src/blocks/flag/save.js +0 -25
- package/src/blocks/flag/style-editor.css +0 -5
- package/src/blocks/flag/style.css +0 -54
- package/src/blocks/icon/block.json +0 -24
- package/src/blocks/icon/edit.js +0 -41
- package/src/blocks/icon/index.js +0 -17
- package/src/blocks/icon/render.php +0 -24
- package/src/blocks/icon/save.js +0 -23
- package/src/blocks/icon/style.css +0 -23
- package/src/blocks/icon-button/block.json +0 -44
- package/src/blocks/icon-button/edit.js +0 -82
- package/src/blocks/icon-button/index.js +0 -10
- package/src/blocks/icon-button/render.php +0 -46
- package/src/blocks/icon-button/save.js +0 -29
- package/src/blocks/icon-button/style-editor.css +0 -5
- package/src/blocks/icon-button/style.css +0 -31
- package/src/blocks/input/block.json +0 -48
- package/src/blocks/input/edit.js +0 -78
- package/src/blocks/input/index.js +0 -10
- package/src/blocks/input/render.php +0 -39
- package/src/blocks/input/save.js +0 -27
- package/src/blocks/input/style-editor.css +0 -8
- package/src/blocks/input/style.css +0 -53
- package/src/blocks/input-helper-message/block.json +0 -24
- package/src/blocks/input-helper-message/edit.js +0 -42
- package/src/blocks/input-helper-message/index.js +0 -17
- package/src/blocks/input-helper-message/render.php +0 -24
- package/src/blocks/input-helper-message/save.js +0 -23
- package/src/blocks/input-helper-message/style.css +0 -23
- package/src/blocks/link/block.json +0 -72
- package/src/blocks/link/edit.js +0 -151
- package/src/blocks/link/index.js +0 -10
- package/src/blocks/link/render.php +0 -44
- package/src/blocks/link/save.js +0 -46
- package/src/blocks/link/style-editor.css +0 -5
- package/src/blocks/link/style.css +0 -119
- package/src/blocks/tab/block.json +0 -24
- package/src/blocks/tab/edit.js +0 -41
- package/src/blocks/tab/index.js +0 -17
- package/src/blocks/tab/render.php +0 -24
- package/src/blocks/tab/save.js +0 -23
- package/src/blocks/tab/style.css +0 -23
- package/src/blocks/tab-group/block.json +0 -24
- package/src/blocks/tab-group/edit.js +0 -41
- package/src/blocks/tab-group/index.js +0 -17
- package/src/blocks/tab-group/render.php +0 -24
- package/src/blocks/tab-group/save.js +0 -23
- package/src/blocks/tab-group/style.css +0 -23
- package/src/blocks/text/block.json +0 -33
- package/src/blocks/text/edit.js +0 -56
- package/src/blocks/text/index.js +0 -10
- package/src/blocks/text/render.php +0 -26
- package/src/blocks/text/save.js +0 -18
- package/src/blocks/text/style-editor.css +0 -4
- package/src/blocks/text/style.css +0 -7
- package/src/blocks/toast/block.json +0 -40
- package/src/blocks/toast/edit.js +0 -85
- package/src/blocks/toast/index.js +0 -10
- package/src/blocks/toast/render.php +0 -37
- package/src/blocks/toast/save.js +0 -29
- package/src/blocks/toast/style-editor.css +0 -4
- package/src/blocks/toast/style.css +0 -67
- package/src/index.js +0 -16
- package/src/utils/classBuilder.js +0 -53
- package/tsconfig.json +0 -116
- package/vitest.config.js +0 -28
- package/vitest.config.ts +0 -28
- package/vitest.setup.ts +0 -129
|
@@ -23,6 +23,16 @@
|
|
|
23
23
|
"slotID": {
|
|
24
24
|
"type": "string",
|
|
25
25
|
"default": ""
|
|
26
|
+
},
|
|
27
|
+
"classes": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"default": "",
|
|
30
|
+
"description": "Additional CSS classes applied to the rendered ad container element"
|
|
31
|
+
},
|
|
32
|
+
"dataAttributes": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"default": {},
|
|
35
|
+
"description": "Custom data-* attributes for extensibility (allowlisted server-side)"
|
|
26
36
|
}
|
|
27
37
|
},
|
|
28
38
|
"example": {}
|
|
@@ -2,7 +2,7 @@ import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
|
|
|
2
2
|
import { PanelBody, SelectControl, TextControl } from '@wordpress/components';
|
|
3
3
|
|
|
4
4
|
const edit = ({ attributes, setAttributes }) => {
|
|
5
|
-
const { type, slotID } = attributes;
|
|
5
|
+
const { type, slotID, classes, dataAttributes } = attributes;
|
|
6
6
|
const blockProps = useBlockProps();
|
|
7
7
|
|
|
8
8
|
return (
|
|
@@ -25,6 +25,22 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
25
25
|
placeholder="e.g., /123456789/section/article-top"
|
|
26
26
|
/>
|
|
27
27
|
</PanelBody>
|
|
28
|
+
|
|
29
|
+
<PanelBody title="Extensibility" initialOpen={false}>
|
|
30
|
+
<TextControl
|
|
31
|
+
label="Custom Classes"
|
|
32
|
+
value={classes}
|
|
33
|
+
onChange={(val) => setAttributes({ classes: val })}
|
|
34
|
+
placeholder="class-name-1 class-name-2"
|
|
35
|
+
help="Space-separated CSS classes added to the ad-container element"
|
|
36
|
+
/>
|
|
37
|
+
|
|
38
|
+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
|
|
39
|
+
<strong>Data Attributes:</strong> Custom data-* attributes are
|
|
40
|
+
typically set via block templates or PHP filters for analytics,
|
|
41
|
+
testing, and custom hooks. See the block documentation for examples.
|
|
42
|
+
</p>
|
|
43
|
+
</PanelBody>
|
|
28
44
|
</InspectorControls>
|
|
29
45
|
<div
|
|
30
46
|
{...blockProps}
|
|
@@ -10,13 +10,26 @@
|
|
|
10
10
|
* @var WP_Block $block Block instance
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
|
|
14
|
+
|
|
13
15
|
$type = isset($attributes['type']) ? sanitize_text_field($attributes['type']) : '';
|
|
14
16
|
$slot_id = isset($attributes['slotID']) ? sanitize_text_field($attributes['slotID']) : '';
|
|
17
|
+
$element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
|
|
18
|
+
|
|
19
|
+
// Sanitize and prepare data-* attributes
|
|
20
|
+
$sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'ad-container', $attributes);
|
|
21
|
+
$data_attrs_html = '';
|
|
22
|
+
foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
|
|
23
|
+
$data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
|
|
24
|
+
}
|
|
15
25
|
|
|
16
26
|
$class_name = 'tds-ad-container';
|
|
17
27
|
if ($type) {
|
|
18
28
|
$class_name .= ' tds-ad-container--' . sanitize_html_class($type);
|
|
19
29
|
}
|
|
30
|
+
if ($element_class_name) {
|
|
31
|
+
$class_name .= ' ' . $element_class_name;
|
|
32
|
+
}
|
|
20
33
|
|
|
21
34
|
$wrapper_attrs = get_block_wrapper_attributes(['class' => $class_name]);
|
|
22
35
|
?>
|
|
@@ -24,4 +37,5 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => $class_name]);
|
|
|
24
37
|
<div
|
|
25
38
|
<?php echo wp_kses_post($wrapper_attrs); ?>
|
|
26
39
|
<?php echo $slot_id ? 'data-slot-id="' . esc_attr($slot_id) . '"' : ''; ?>
|
|
40
|
+
<?php echo wp_kses_post($data_attrs_html); ?>
|
|
27
41
|
></div>
|
|
@@ -41,11 +41,15 @@
|
|
|
41
41
|
"default": "hug",
|
|
42
42
|
"description": "Controls the width behaviour"
|
|
43
43
|
},
|
|
44
|
-
"
|
|
45
|
-
"type": "
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
44
|
+
"isRounded": {
|
|
45
|
+
"type": "boolean",
|
|
46
|
+
"default": false,
|
|
47
|
+
"description": "Applies rounded corner styling to the button"
|
|
48
|
+
},
|
|
49
|
+
"isLoading": {
|
|
50
|
+
"type": "boolean",
|
|
51
|
+
"default": false,
|
|
52
|
+
"description": "Show loading state with spinner and disable interaction"
|
|
49
53
|
},
|
|
50
54
|
"disabled": {
|
|
51
55
|
"type": "boolean",
|
|
@@ -82,6 +86,16 @@
|
|
|
82
86
|
"ariaLabel": {
|
|
83
87
|
"type": "string",
|
|
84
88
|
"description": "Accessible name for icon-only buttons"
|
|
89
|
+
},
|
|
90
|
+
"classes": {
|
|
91
|
+
"type": "string",
|
|
92
|
+
"default": "",
|
|
93
|
+
"description": "Additional CSS classes applied to the rendered button/link element"
|
|
94
|
+
},
|
|
95
|
+
"dataAttributes": {
|
|
96
|
+
"type": "object",
|
|
97
|
+
"default": {},
|
|
98
|
+
"description": "Custom data-* attributes for extensibility (allowlisted server-side)"
|
|
85
99
|
}
|
|
86
100
|
},
|
|
87
101
|
"editorScript": "file:./index.js",
|
|
@@ -15,7 +15,8 @@ export default function Edit({ attributes, setAttributes }) {
|
|
|
15
15
|
intent,
|
|
16
16
|
size,
|
|
17
17
|
behaviour,
|
|
18
|
-
|
|
18
|
+
isRounded,
|
|
19
|
+
isLoading,
|
|
19
20
|
disabled,
|
|
20
21
|
href,
|
|
21
22
|
target,
|
|
@@ -23,7 +24,9 @@ export default function Edit({ attributes, setAttributes }) {
|
|
|
23
24
|
type,
|
|
24
25
|
iconLeft,
|
|
25
26
|
iconRight,
|
|
26
|
-
ariaLabel
|
|
27
|
+
ariaLabel,
|
|
28
|
+
classes,
|
|
29
|
+
dataAttributes
|
|
27
30
|
} = attributes;
|
|
28
31
|
|
|
29
32
|
const blockProps = useBlockProps({
|
|
@@ -34,7 +37,6 @@ export default function Edit({ attributes, setAttributes }) {
|
|
|
34
37
|
intent,
|
|
35
38
|
size,
|
|
36
39
|
behaviour,
|
|
37
|
-
state,
|
|
38
40
|
disabled
|
|
39
41
|
});
|
|
40
42
|
|
|
@@ -99,18 +101,18 @@ export default function Edit({ attributes, setAttributes }) {
|
|
|
99
101
|
onChange={(value) => setAttributes({ behaviour: value })}
|
|
100
102
|
/>
|
|
101
103
|
|
|
102
|
-
<
|
|
103
|
-
label="
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
<ToggleControl
|
|
105
|
+
label="Rounded Corners"
|
|
106
|
+
checked={isRounded}
|
|
107
|
+
onChange={(value) => setAttributes({ isRounded: value })}
|
|
108
|
+
help="Apply rounded corner styling"
|
|
109
|
+
/>
|
|
110
|
+
|
|
111
|
+
<ToggleControl
|
|
112
|
+
label="Loading"
|
|
113
|
+
checked={isLoading}
|
|
114
|
+
onChange={(value) => setAttributes({ isLoading: value })}
|
|
115
|
+
help="Show loading state with spinner"
|
|
114
116
|
/>
|
|
115
117
|
|
|
116
118
|
<ToggleControl
|
|
@@ -181,6 +183,22 @@ export default function Edit({ attributes, setAttributes }) {
|
|
|
181
183
|
placeholder="Icon name"
|
|
182
184
|
/>
|
|
183
185
|
</PanelBody>
|
|
186
|
+
|
|
187
|
+
<PanelBody title="Extensibility" initialOpen={false}>
|
|
188
|
+
<TextControl
|
|
189
|
+
label="Custom Classes"
|
|
190
|
+
value={classes}
|
|
191
|
+
onChange={(value) => setAttributes({ classes: value })}
|
|
192
|
+
placeholder="class-name-1 class-name-2"
|
|
193
|
+
help="Space-separated CSS classes added to the button element"
|
|
194
|
+
/>
|
|
195
|
+
|
|
196
|
+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
|
|
197
|
+
<strong>Data Attributes:</strong> Custom data-* attributes are
|
|
198
|
+
typically set via block templates or PHP filters for analytics,
|
|
199
|
+
testing, and custom hooks. See the block documentation for examples.
|
|
200
|
+
</p>
|
|
201
|
+
</PanelBody>
|
|
184
202
|
</InspectorControls>
|
|
185
203
|
</>
|
|
186
204
|
);
|
|
@@ -10,27 +10,47 @@
|
|
|
10
10
|
* @var WP_Block $block Block instance
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
|
|
14
|
+
|
|
13
15
|
$label = isset($attributes['label']) ? sanitize_text_field($attributes['label']) : 'Button label';
|
|
14
16
|
$intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : 'primary';
|
|
15
17
|
$size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : 'large';
|
|
16
18
|
$behaviour = isset($attributes['behaviour']) ? sanitize_text_field($attributes['behaviour']) : 'hug';
|
|
17
|
-
$
|
|
19
|
+
$isRounded = isset($attributes['isRounded']) ? (bool) $attributes['isRounded'] : false;
|
|
20
|
+
$isLoading = isset($attributes['isLoading']) ? (bool) $attributes['isLoading'] : false;
|
|
18
21
|
$disabled = isset($attributes['disabled']) ? (bool) $attributes['disabled'] : false;
|
|
19
22
|
$href = isset($attributes['href']) ? esc_url($attributes['href']) : '';
|
|
20
23
|
$target = isset($attributes['target']) ? sanitize_text_field($attributes['target']) : '';
|
|
21
24
|
$rel = isset($attributes['rel']) ? sanitize_text_field($attributes['rel']) : '';
|
|
22
25
|
$type = isset($attributes['type']) ? sanitize_text_field($attributes['type']) : 'button';
|
|
23
26
|
$aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
|
|
27
|
+
$element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
|
|
28
|
+
|
|
29
|
+
// Sanitize and prepare data-* attributes
|
|
30
|
+
$sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'button', $attributes);
|
|
31
|
+
$data_attrs_html = '';
|
|
32
|
+
foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
|
|
33
|
+
$data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
|
|
34
|
+
}
|
|
24
35
|
|
|
25
36
|
// Build button classes
|
|
26
37
|
$classes = ['tds-button'];
|
|
27
38
|
$classes[] = 'tds-button--intent-' . $intent;
|
|
28
39
|
$classes[] = 'tds-button--size-' . $size;
|
|
29
40
|
$classes[] = 'tds-button--behaviour-' . $behaviour;
|
|
30
|
-
$
|
|
41
|
+
if ($isRounded) {
|
|
42
|
+
$classes[] = 'tds-button--rounded';
|
|
43
|
+
}
|
|
44
|
+
if ($isLoading) {
|
|
45
|
+
$classes[] = 'tds-button--loading';
|
|
46
|
+
}
|
|
31
47
|
if ($disabled) {
|
|
32
48
|
$classes[] = 'tds-button--disabled';
|
|
33
49
|
}
|
|
50
|
+
// Add custom classes
|
|
51
|
+
if ($element_class_name) {
|
|
52
|
+
$classes[] = $element_class_name;
|
|
53
|
+
}
|
|
34
54
|
|
|
35
55
|
$button_class = implode(' ', $classes);
|
|
36
56
|
$element_tag = $href ? 'a' : 'button';
|
|
@@ -47,6 +67,7 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => 'tds-button-wrapper'])
|
|
|
47
67
|
<?php echo $target ? 'target="' . esc_attr($target) . '"' : ''; ?>
|
|
48
68
|
<?php echo $rel ? 'rel="' . esc_attr($rel) . '"' : ''; ?>
|
|
49
69
|
<?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
|
|
70
|
+
<?php echo wp_kses_post($data_attrs_html); ?>
|
|
50
71
|
>
|
|
51
72
|
<span class="tds-button__label-container">
|
|
52
73
|
<span class="tds-button__label"><?php echo wp_kses_post($label); ?></span>
|
|
@@ -60,6 +81,7 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => 'tds-button-wrapper'])
|
|
|
60
81
|
<?php echo $disabled ? 'disabled' : ''; ?>
|
|
61
82
|
type="<?php echo esc_attr($type); ?>"
|
|
62
83
|
<?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
|
|
84
|
+
<?php echo wp_kses_post($data_attrs_html); ?>
|
|
63
85
|
>
|
|
64
86
|
<span class="tds-button__label-container">
|
|
65
87
|
<span class="tds-button__label"><?php echo wp_kses_post($label); ?></span>
|
|
@@ -66,6 +66,10 @@
|
|
|
66
66
|
gap: 0;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
.tds-button--rounded {
|
|
70
|
+
border-radius: 9999px;
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
.tds-button--intent-primary {
|
|
70
74
|
--tds-button-bg: #005c8a;
|
|
71
75
|
--tds-button-fg: #ffffff;
|
|
@@ -127,6 +131,14 @@
|
|
|
127
131
|
--tds-button-label-inline-padding: 8px;
|
|
128
132
|
}
|
|
129
133
|
|
|
134
|
+
.tds-button--size-xlarge {
|
|
135
|
+
min-height: 80px;
|
|
136
|
+
min-width: 130px;
|
|
137
|
+
padding: 0 24px;
|
|
138
|
+
font-size: 1.8rem;
|
|
139
|
+
--tds-button-label-inline-padding: 8px;
|
|
140
|
+
}
|
|
141
|
+
|
|
130
142
|
.tds-button--behaviour-hug {
|
|
131
143
|
width: fit-content;
|
|
132
144
|
}
|
|
@@ -155,3 +167,54 @@
|
|
|
155
167
|
flex: 0 0 auto;
|
|
156
168
|
width: fit-content;
|
|
157
169
|
}
|
|
170
|
+
|
|
171
|
+
.tds-button__icon,
|
|
172
|
+
.tds-button__spinner {
|
|
173
|
+
display: inline-flex;
|
|
174
|
+
align-items: center;
|
|
175
|
+
justify-content: center;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.tds-button--size-small .tds-button__icon,
|
|
179
|
+
.tds-button--size-small .tds-button__spinner {
|
|
180
|
+
width: 20px;
|
|
181
|
+
height: 20px;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.tds-button--size-medium .tds-button__icon,
|
|
185
|
+
.tds-button--size-medium .tds-button__spinner {
|
|
186
|
+
width: 24px;
|
|
187
|
+
height: 24px;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.tds-button--size-large .tds-button__icon,
|
|
191
|
+
.tds-button--size-large .tds-button__spinner {
|
|
192
|
+
width: 28px;
|
|
193
|
+
height: 28px;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.tds-button--size-xlarge .tds-button__icon,
|
|
197
|
+
.tds-button--size-xlarge .tds-button__spinner {
|
|
198
|
+
width: 28px;
|
|
199
|
+
height: 28px;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.tds-button__icon svg {
|
|
203
|
+
width: 100%;
|
|
204
|
+
height: 100%;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.tds-button__spinner svg {
|
|
208
|
+
animation: tds-button-spin 1.8s linear infinite;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@keyframes tds-button-spin {
|
|
212
|
+
0% {
|
|
213
|
+
transform: rotate(0deg);
|
|
214
|
+
transform-origin: center;
|
|
215
|
+
}
|
|
216
|
+
100% {
|
|
217
|
+
transform: rotate(360deg);
|
|
218
|
+
transform-origin: center;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -21,17 +21,12 @@
|
|
|
21
21
|
"intent": {
|
|
22
22
|
"type": "string",
|
|
23
23
|
"default": "secondary",
|
|
24
|
-
"enum": ["primary", "secondary"
|
|
24
|
+
"enum": ["primary", "secondary"]
|
|
25
25
|
},
|
|
26
26
|
"size": {
|
|
27
27
|
"type": "string",
|
|
28
28
|
"default": "medium",
|
|
29
|
-
"enum": ["small", "
|
|
30
|
-
},
|
|
31
|
-
"state": {
|
|
32
|
-
"type": "string",
|
|
33
|
-
"default": "base",
|
|
34
|
-
"enum": ["base", "hover", "pressed", "disabled"]
|
|
29
|
+
"enum": ["small", "large"]
|
|
35
30
|
},
|
|
36
31
|
"channel": {
|
|
37
32
|
"type": "boolean",
|
|
@@ -52,6 +47,16 @@
|
|
|
52
47
|
"ariaLabel": {
|
|
53
48
|
"type": "string",
|
|
54
49
|
"default": ""
|
|
50
|
+
},
|
|
51
|
+
"classes": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"default": "",
|
|
54
|
+
"description": "Additional CSS classes applied to the rendered chip element"
|
|
55
|
+
},
|
|
56
|
+
"dataAttributes": {
|
|
57
|
+
"type": "object",
|
|
58
|
+
"default": {},
|
|
59
|
+
"description": "Custom data-* attributes for extensibility (allowlisted server-side)"
|
|
55
60
|
}
|
|
56
61
|
},
|
|
57
62
|
"example": {}
|
package/dist/blocks/chip/edit.js
CHANGED
|
@@ -15,12 +15,13 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
15
15
|
content,
|
|
16
16
|
intent,
|
|
17
17
|
size,
|
|
18
|
-
state,
|
|
19
18
|
channel,
|
|
20
19
|
toggle,
|
|
21
20
|
iconLeft,
|
|
22
21
|
iconRight,
|
|
23
|
-
ariaLabel
|
|
22
|
+
ariaLabel,
|
|
23
|
+
classes,
|
|
24
|
+
dataAttributes
|
|
24
25
|
} = attributes;
|
|
25
26
|
const blockProps = useBlockProps();
|
|
26
27
|
|
|
@@ -28,7 +29,6 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
28
29
|
const classes = ['tds-chip'];
|
|
29
30
|
classes.push(`tds-chip--intent-${intent}`);
|
|
30
31
|
classes.push(`tds-chip--size-${size}`);
|
|
31
|
-
classes.push(`tds-chip--state-${state}`);
|
|
32
32
|
if (channel) classes.push('tds-chip--channel');
|
|
33
33
|
if (toggle) classes.push('tds-chip--toggle');
|
|
34
34
|
return classes.join(' ');
|
|
@@ -43,8 +43,7 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
43
43
|
value={intent}
|
|
44
44
|
options={[
|
|
45
45
|
{ label: 'Primary', value: 'primary' },
|
|
46
|
-
{ label: 'Secondary', value: 'secondary' }
|
|
47
|
-
{ label: 'Negative', value: 'negative' }
|
|
46
|
+
{ label: 'Secondary', value: 'secondary' }
|
|
48
47
|
]}
|
|
49
48
|
onChange={(val) => setAttributes({ intent: val })}
|
|
50
49
|
/>
|
|
@@ -53,22 +52,10 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
53
52
|
value={size}
|
|
54
53
|
options={[
|
|
55
54
|
{ label: 'Small', value: 'small' },
|
|
56
|
-
{ label: 'Medium', value: 'medium' },
|
|
57
55
|
{ label: 'Large', value: 'large' }
|
|
58
56
|
]}
|
|
59
57
|
onChange={(val) => setAttributes({ size: val })}
|
|
60
58
|
/>
|
|
61
|
-
<SelectControl
|
|
62
|
-
label="State"
|
|
63
|
-
value={state}
|
|
64
|
-
options={[
|
|
65
|
-
{ label: 'Base', value: 'base' },
|
|
66
|
-
{ label: 'Hover', value: 'hover' },
|
|
67
|
-
{ label: 'Pressed', value: 'pressed' },
|
|
68
|
-
{ label: 'Disabled', value: 'disabled' }
|
|
69
|
-
]}
|
|
70
|
-
onChange={(val) => setAttributes({ state: val })}
|
|
71
|
-
/>
|
|
72
59
|
<ToggleControl
|
|
73
60
|
label="Channel"
|
|
74
61
|
checked={channel}
|
|
@@ -95,6 +82,22 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
95
82
|
onChange={(val) => setAttributes({ ariaLabel: val })}
|
|
96
83
|
/>
|
|
97
84
|
</PanelBody>
|
|
85
|
+
|
|
86
|
+
<PanelBody title="Extensibility" initialOpen={false}>
|
|
87
|
+
<TextControl
|
|
88
|
+
label="Custom Classes"
|
|
89
|
+
value={classes}
|
|
90
|
+
onChange={(val) => setAttributes({ classes: val })}
|
|
91
|
+
placeholder="class-name-1 class-name-2"
|
|
92
|
+
help="Space-separated CSS classes added to the chip element"
|
|
93
|
+
/>
|
|
94
|
+
|
|
95
|
+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
|
|
96
|
+
<strong>Data Attributes:</strong> Custom data-* attributes are
|
|
97
|
+
typically set via block templates or PHP filters for analytics,
|
|
98
|
+
testing, and custom hooks. See the block documentation for examples.
|
|
99
|
+
</p>
|
|
100
|
+
</PanelBody>
|
|
98
101
|
</InspectorControls>
|
|
99
102
|
<button {...blockProps} className={buildClass()} aria-label={ariaLabel}>
|
|
100
103
|
{iconLeft && <span className="tds-chip__icon-left">{iconLeft}</span>}
|
|
@@ -10,24 +10,35 @@
|
|
|
10
10
|
* @var WP_Block $block Block instance
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
|
|
14
|
+
|
|
13
15
|
$content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
|
|
14
16
|
$intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : '';
|
|
15
17
|
$size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : '';
|
|
16
|
-
$state = isset($attributes['state']) ? sanitize_text_field($attributes['state']) : '';
|
|
17
18
|
$channel = isset($attributes['channel']) ? (bool) $attributes['channel'] : false;
|
|
18
19
|
$toggle = isset($attributes['toggle']) ? (bool) $attributes['toggle'] : false;
|
|
19
20
|
$aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
|
|
21
|
+
$element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
|
|
22
|
+
|
|
23
|
+
// Sanitize and prepare data-* attributes
|
|
24
|
+
$sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'chip', $attributes);
|
|
25
|
+
$data_attrs_html = '';
|
|
26
|
+
foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
|
|
27
|
+
$data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
|
|
28
|
+
}
|
|
20
29
|
|
|
21
30
|
$classes = ['tds-chip'];
|
|
22
31
|
$classes[] = 'tds-chip--intent-' . $intent;
|
|
23
32
|
$classes[] = 'tds-chip--size-' . $size;
|
|
24
|
-
$classes[] = 'tds-chip--state-' . $state;
|
|
25
33
|
if ($channel) {
|
|
26
34
|
$classes[] = 'tds-chip--channel';
|
|
27
35
|
}
|
|
28
36
|
if ($toggle) {
|
|
29
37
|
$classes[] = 'tds-chip--toggle';
|
|
30
38
|
}
|
|
39
|
+
if ($element_class_name) {
|
|
40
|
+
$classes[] = $element_class_name;
|
|
41
|
+
}
|
|
31
42
|
|
|
32
43
|
$wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
|
|
33
44
|
?>
|
|
@@ -35,6 +46,7 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)
|
|
|
35
46
|
<button
|
|
36
47
|
<?php echo wp_kses_post($wrapper_attrs); ?>
|
|
37
48
|
<?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
|
|
49
|
+
<?php echo wp_kses_post($data_attrs_html); ?>
|
|
38
50
|
>
|
|
39
51
|
<span class="tds-chip__content"><?php echo wp_kses_post($content_text); ?></span>
|
|
40
52
|
</button>
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
"content": {
|
|
18
18
|
"type": "string",
|
|
19
19
|
"default": ""
|
|
20
|
+
},
|
|
21
|
+
"classes": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"default": "",
|
|
24
|
+
"description": "Additional CSS classes applied to the rendered dialog element"
|
|
25
|
+
},
|
|
26
|
+
"dataAttributes": {
|
|
27
|
+
"type": "object",
|
|
28
|
+
"default": {},
|
|
29
|
+
"description": "Custom data-* attributes for extensibility (allowlisted server-side)"
|
|
20
30
|
}
|
|
21
31
|
},
|
|
22
32
|
"render": "file:./render.php",
|
|
@@ -10,6 +10,7 @@ import { PanelBody, TextControl } from '@wordpress/components';
|
|
|
10
10
|
|
|
11
11
|
export function edit(props) {
|
|
12
12
|
const { attributes, setAttributes } = props;
|
|
13
|
+
const { content, classes, dataAttributes } = attributes;
|
|
13
14
|
const blockProps = useBlockProps();
|
|
14
15
|
|
|
15
16
|
// TODO: Implement editor UI based on component props
|
|
@@ -29,6 +30,22 @@ export function edit(props) {
|
|
|
29
30
|
/>
|
|
30
31
|
{/* TODO: Add more controls based on component variants */}
|
|
31
32
|
</PanelBody>
|
|
33
|
+
|
|
34
|
+
<PanelBody title="Extensibility" initialOpen={false}>
|
|
35
|
+
<TextControl
|
|
36
|
+
label="Custom Classes"
|
|
37
|
+
value={classes || ''}
|
|
38
|
+
onChange={(val) => setAttributes({ classes: val })}
|
|
39
|
+
placeholder="class-name-1 class-name-2"
|
|
40
|
+
help="Space-separated CSS classes added to the dialog-box element"
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
|
|
44
|
+
<strong>Data Attributes:</strong> Custom data-* attributes are
|
|
45
|
+
typically set via block templates or PHP filters for analytics,
|
|
46
|
+
testing, and custom hooks. See the block documentation for examples.
|
|
47
|
+
</p>
|
|
48
|
+
</PanelBody>
|
|
32
49
|
</InspectorControls>
|
|
33
50
|
<div {...blockProps}>
|
|
34
51
|
<p>📝 DialogBox block editor</p>
|
|
@@ -11,13 +11,25 @@
|
|
|
11
11
|
* @return string Rendered HTML
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
$element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
|
|
17
|
+
|
|
18
|
+
// Sanitize and prepare data-* attributes
|
|
19
|
+
$sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'dialog-box', $attributes);
|
|
20
|
+
$data_attrs_html = '';
|
|
21
|
+
foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
|
|
22
|
+
$data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
$wrapper_classes = [];
|
|
26
|
+
if ($element_class_name) {
|
|
27
|
+
$wrapper_classes[] = $element_class_name;
|
|
28
|
+
}
|
|
29
|
+
$wrapper_attributes = get_block_wrapper_attributes(['class' => implode(' ', $wrapper_classes)]);
|
|
18
30
|
|
|
19
31
|
?>
|
|
20
|
-
<div <?php echo wp_kses_post(
|
|
32
|
+
<div <?php echo wp_kses_post($wrapper_attributes); ?><?php echo wp_kses_post($data_attrs_html); ?>>
|
|
21
33
|
<!-- TODO: Render DialogBox component here -->
|
|
22
34
|
<!-- Use CSS custom properties from packages/tokens/data/resolved-hexes.json -->
|
|
23
35
|
<!-- Apply BEM naming: tds-dialog-box--{modifier} -->
|
|
@@ -26,6 +26,16 @@
|
|
|
26
26
|
"padding": {
|
|
27
27
|
"type": "boolean",
|
|
28
28
|
"default": false
|
|
29
|
+
},
|
|
30
|
+
"classes": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"default": "",
|
|
33
|
+
"description": "Additional CSS classes applied to the rendered divider element"
|
|
34
|
+
},
|
|
35
|
+
"dataAttributes": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"default": {},
|
|
38
|
+
"description": "Custom data-* attributes for extensibility (allowlisted server-side)"
|
|
29
39
|
}
|
|
30
40
|
},
|
|
31
41
|
"example": {}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
|
|
2
|
-
import { PanelBody, ToggleControl } from '@wordpress/components';
|
|
2
|
+
import { PanelBody, ToggleControl, TextControl } from '@wordpress/components';
|
|
3
3
|
|
|
4
4
|
const edit = ({ attributes, setAttributes }) => {
|
|
5
|
-
const { isDashed, isVertical, padding } = attributes;
|
|
5
|
+
const { isDashed, isVertical, padding, classes, dataAttributes } = attributes;
|
|
6
6
|
const blockProps = useBlockProps();
|
|
7
7
|
|
|
8
8
|
const buildDividerClass = () => {
|
|
@@ -33,6 +33,22 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
33
33
|
onChange={(val) => setAttributes({ padding: val })}
|
|
34
34
|
/>
|
|
35
35
|
</PanelBody>
|
|
36
|
+
|
|
37
|
+
<PanelBody title="Extensibility" initialOpen={false}>
|
|
38
|
+
<TextControl
|
|
39
|
+
label="Custom Classes"
|
|
40
|
+
value={classes}
|
|
41
|
+
onChange={(val) => setAttributes({ classes: val })}
|
|
42
|
+
placeholder="class-name-1 class-name-2"
|
|
43
|
+
help="Space-separated CSS classes added to the divider element"
|
|
44
|
+
/>
|
|
45
|
+
|
|
46
|
+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
|
|
47
|
+
<strong>Data Attributes:</strong> Custom data-* attributes are
|
|
48
|
+
typically set via block templates or PHP filters for analytics,
|
|
49
|
+
testing, and custom hooks. See the block documentation for examples.
|
|
50
|
+
</p>
|
|
51
|
+
</PanelBody>
|
|
36
52
|
</InspectorControls>
|
|
37
53
|
<div {...blockProps} className={buildDividerClass()} />
|
|
38
54
|
</>
|