@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
package/dist/blocks/link/edit.js
CHANGED
|
@@ -17,13 +17,14 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
17
17
|
intent,
|
|
18
18
|
sentiment,
|
|
19
19
|
size,
|
|
20
|
-
state,
|
|
21
20
|
iconLeft,
|
|
22
21
|
iconRight,
|
|
23
22
|
inline,
|
|
24
23
|
ariaLabel,
|
|
25
24
|
target,
|
|
26
|
-
rel
|
|
25
|
+
rel,
|
|
26
|
+
classes,
|
|
27
|
+
dataAttributes
|
|
27
28
|
} = attributes;
|
|
28
29
|
const blockProps = useBlockProps();
|
|
29
30
|
|
|
@@ -32,7 +33,6 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
32
33
|
classes.push(`tds-link--intent-${intent}`);
|
|
33
34
|
classes.push(`tds-link--sentiment-${sentiment}`);
|
|
34
35
|
classes.push(`tds-link--size-${size}`);
|
|
35
|
-
classes.push(`tds-link--state-${state}`);
|
|
36
36
|
if (!inline) classes.push('tds-link--block');
|
|
37
37
|
return classes.join(' ');
|
|
38
38
|
};
|
|
@@ -61,9 +61,8 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
61
61
|
label="Sentiment"
|
|
62
62
|
value={sentiment}
|
|
63
63
|
options={[
|
|
64
|
-
{ label: '
|
|
65
|
-
{ label: '
|
|
66
|
-
{ label: 'Negative', value: 'negative' }
|
|
64
|
+
{ label: 'Brand', value: 'brand' },
|
|
65
|
+
{ label: 'Utility', value: 'utility' }
|
|
67
66
|
]}
|
|
68
67
|
onChange={(val) => setAttributes({ sentiment: val })}
|
|
69
68
|
/>
|
|
@@ -78,18 +77,6 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
78
77
|
onChange={(val) => setAttributes({ size: val })}
|
|
79
78
|
/>
|
|
80
79
|
<SelectControl
|
|
81
|
-
label="State"
|
|
82
|
-
value={state}
|
|
83
|
-
options={[
|
|
84
|
-
{ label: 'Base', value: 'base' },
|
|
85
|
-
{ label: 'Hover', value: 'hover' },
|
|
86
|
-
{ label: 'Visited', value: 'visited' },
|
|
87
|
-
{ label: 'Focus', value: 'focus' },
|
|
88
|
-
{ label: 'Disabled', value: 'disabled' }
|
|
89
|
-
]}
|
|
90
|
-
onChange={(val) => setAttributes({ state: val })}
|
|
91
|
-
/>
|
|
92
|
-
<TextControl
|
|
93
80
|
label="Left Icon"
|
|
94
81
|
value={iconLeft}
|
|
95
82
|
onChange={(val) => setAttributes({ iconLeft: val })}
|
|
@@ -126,6 +113,22 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
126
113
|
onChange={(val) => setAttributes({ ariaLabel: val })}
|
|
127
114
|
/>
|
|
128
115
|
</PanelBody>
|
|
116
|
+
|
|
117
|
+
<PanelBody title="Extensibility" initialOpen={false}>
|
|
118
|
+
<TextControl
|
|
119
|
+
label="Custom Classes"
|
|
120
|
+
value={classes}
|
|
121
|
+
onChange={(val) => setAttributes({ classes: val })}
|
|
122
|
+
placeholder="class-name-1 class-name-2"
|
|
123
|
+
help="Space-separated CSS classes added to the link element"
|
|
124
|
+
/>
|
|
125
|
+
|
|
126
|
+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
|
|
127
|
+
<strong>Data Attributes:</strong> Custom data-* attributes are
|
|
128
|
+
typically set via block templates or PHP filters for analytics,
|
|
129
|
+
testing, and custom hooks. See the block documentation for examples.
|
|
130
|
+
</p>
|
|
131
|
+
</PanelBody>
|
|
129
132
|
</InspectorControls>
|
|
130
133
|
<a
|
|
131
134
|
{...blockProps}
|
|
@@ -10,25 +10,36 @@
|
|
|
10
10
|
* @var WP_Block $block Block instance
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
|
|
14
|
+
|
|
13
15
|
$href = isset($attributes['href']) ? esc_url($attributes['href']) : '';
|
|
14
16
|
$content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
|
|
15
17
|
$intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : '';
|
|
16
18
|
$sentiment = isset($attributes['sentiment']) ? sanitize_text_field($attributes['sentiment']) : '';
|
|
17
19
|
$size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : '';
|
|
18
|
-
$state = isset($attributes['state']) ? sanitize_text_field($attributes['state']) : '';
|
|
19
20
|
$inline = isset($attributes['inline']) ? (bool) $attributes['inline'] : true;
|
|
20
21
|
$aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
|
|
21
22
|
$target = isset($attributes['target']) ? sanitize_text_field($attributes['target']) : '_self';
|
|
22
23
|
$rel = isset($attributes['rel']) ? sanitize_text_field($attributes['rel']) : '';
|
|
24
|
+
$element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
|
|
25
|
+
|
|
26
|
+
// Sanitize and prepare data-* attributes
|
|
27
|
+
$sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'link', $attributes);
|
|
28
|
+
$data_attrs_html = '';
|
|
29
|
+
foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
|
|
30
|
+
$data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
|
|
31
|
+
}
|
|
23
32
|
|
|
24
33
|
$classes = ['tds-link'];
|
|
25
34
|
$classes[] = 'tds-link--intent-' . $intent;
|
|
26
35
|
$classes[] = 'tds-link--sentiment-' . $sentiment;
|
|
27
36
|
$classes[] = 'tds-link--size-' . $size;
|
|
28
|
-
$classes[] = 'tds-link--state-' . $state;
|
|
29
37
|
if (!$inline) {
|
|
30
38
|
$classes[] = 'tds-link--block';
|
|
31
39
|
}
|
|
40
|
+
if ($element_class_name) {
|
|
41
|
+
$classes[] = $element_class_name;
|
|
42
|
+
}
|
|
32
43
|
|
|
33
44
|
$wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
|
|
34
45
|
?>
|
|
@@ -39,6 +50,7 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)
|
|
|
39
50
|
<?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
|
|
40
51
|
<?php echo ($target !== '_self') ? 'target="' . esc_attr($target) . '"' : ''; ?>
|
|
41
52
|
<?php echo $rel ? 'rel="' . esc_attr($rel) . '"' : ''; ?>
|
|
53
|
+
<?php echo wp_kses_post($data_attrs_html); ?>
|
|
42
54
|
>
|
|
43
55
|
<span class="tds-link__content"><?php echo wp_kses_post($content_text); ?></span>
|
|
44
56
|
</a>
|
|
@@ -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 tab 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",
|
package/dist/blocks/tab/edit.js
CHANGED
|
@@ -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 tab 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>📝 Tab 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'] ?? [], 'tab', $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 Tab component here -->
|
|
22
34
|
<!-- Use CSS custom properties from packages/tokens/data/resolved-hexes.json -->
|
|
23
35
|
<!-- Apply BEM naming: tds-tab--{modifier} -->
|
|
@@ -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 tab group 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 tab-group 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>📝 TabGroup 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'] ?? [], 'tab-group', $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 TabGroup component here -->
|
|
22
34
|
<!-- Use CSS custom properties from packages/tokens/data/resolved-hexes.json -->
|
|
23
35
|
<!-- Apply BEM naming: tds-tab-group--{modifier} -->
|
|
@@ -27,6 +27,16 @@
|
|
|
27
27
|
"content": {
|
|
28
28
|
"type": "string",
|
|
29
29
|
"default": ""
|
|
30
|
+
},
|
|
31
|
+
"classes": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"default": "",
|
|
34
|
+
"description": "Additional CSS classes applied to the rendered text element"
|
|
35
|
+
},
|
|
36
|
+
"dataAttributes": {
|
|
37
|
+
"type": "object",
|
|
38
|
+
"default": {},
|
|
39
|
+
"description": "Custom data-* attributes for extensibility (allowlisted server-side)"
|
|
30
40
|
}
|
|
31
41
|
},
|
|
32
42
|
"example": {}
|
package/dist/blocks/text/edit.js
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
RichText,
|
|
4
4
|
InspectorControls
|
|
5
5
|
} from '@wordpress/block-editor';
|
|
6
|
-
import { PanelBody, SelectControl } from '@wordpress/components';
|
|
6
|
+
import { PanelBody, SelectControl, TextControl } from '@wordpress/components';
|
|
7
7
|
|
|
8
8
|
const edit = ({ attributes, setAttributes }) => {
|
|
9
|
-
const { as, typographyStyle, content } = attributes;
|
|
9
|
+
const { as, typographyStyle, content, classes, dataAttributes } = attributes;
|
|
10
10
|
const blockProps = useBlockProps();
|
|
11
11
|
|
|
12
12
|
const tagName = as || 'p';
|
|
@@ -40,6 +40,22 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
40
40
|
onChange={(val) => setAttributes({ typographyStyle: val })}
|
|
41
41
|
/>
|
|
42
42
|
</PanelBody>
|
|
43
|
+
|
|
44
|
+
<PanelBody title="Extensibility" initialOpen={false}>
|
|
45
|
+
<TextControl
|
|
46
|
+
label="Custom Classes"
|
|
47
|
+
value={classes}
|
|
48
|
+
onChange={(val) => setAttributes({ classes: val })}
|
|
49
|
+
placeholder="class-name-1 class-name-2"
|
|
50
|
+
help="Space-separated CSS classes added to the text element"
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
|
|
54
|
+
<strong>Data Attributes:</strong> Custom data-* attributes are
|
|
55
|
+
typically set via block templates or PHP filters for analytics,
|
|
56
|
+
testing, and custom hooks. See the block documentation for examples.
|
|
57
|
+
</p>
|
|
58
|
+
</PanelBody>
|
|
43
59
|
</InspectorControls>
|
|
44
60
|
<RichText
|
|
45
61
|
{...blockProps}
|
|
@@ -10,17 +10,30 @@
|
|
|
10
10
|
* @var WP_Block $block Block instance
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
|
|
14
|
+
|
|
13
15
|
$as = isset($attributes['as']) ? sanitize_text_field($attributes['as']) : 'p';
|
|
14
16
|
$typography_style = isset($attributes['typographyStyle']) ? sanitize_text_field($attributes['typographyStyle']) : '';
|
|
15
17
|
$text_content = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
|
|
18
|
+
$element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
|
|
19
|
+
|
|
20
|
+
// Sanitize and prepare data-* attributes
|
|
21
|
+
$sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'text', $attributes);
|
|
22
|
+
$data_attrs_html = '';
|
|
23
|
+
foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
|
|
24
|
+
$data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
|
|
25
|
+
}
|
|
16
26
|
|
|
17
27
|
$tag_name = in_array($as, ['p', 'span', 'h1', 'h2', 'h3', 'h4', 'h5'], true) ? $as : 'p';
|
|
18
28
|
$class_name = 'tds-text';
|
|
19
29
|
if ($typography_style) {
|
|
20
30
|
$class_name .= ' tds-text--' . sanitize_html_class($typography_style);
|
|
21
31
|
}
|
|
32
|
+
if ($element_class_name) {
|
|
33
|
+
$class_name .= ' ' . $element_class_name;
|
|
34
|
+
}
|
|
22
35
|
|
|
23
36
|
$wrapper_attrs = get_block_wrapper_attributes(['class' => $class_name]);
|
|
24
37
|
?>
|
|
25
38
|
|
|
26
|
-
<?php echo wp_sprintf('<%s %s>%s</%s>', $tag_name, wp_kses_post($wrapper_attrs), wp_kses_post($text_content), $tag_name); ?>
|
|
39
|
+
<?php echo wp_sprintf('<%s %s%s>%s</%s>', $tag_name, wp_kses_post($wrapper_attrs), wp_kses_post($data_attrs_html), wp_kses_post($text_content), $tag_name); ?>
|
|
@@ -34,6 +34,16 @@
|
|
|
34
34
|
"timeout": {
|
|
35
35
|
"type": "number",
|
|
36
36
|
"default": 5000
|
|
37
|
+
},
|
|
38
|
+
"classes": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"default": "",
|
|
41
|
+
"description": "Additional CSS classes applied to the rendered toast element"
|
|
42
|
+
},
|
|
43
|
+
"dataAttributes": {
|
|
44
|
+
"type": "object",
|
|
45
|
+
"default": {},
|
|
46
|
+
"description": "Custom data-* attributes for extensibility (allowlisted server-side)"
|
|
37
47
|
}
|
|
38
48
|
},
|
|
39
49
|
"example": {}
|
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
} from '@wordpress/components';
|
|
13
13
|
|
|
14
14
|
const edit = ({ attributes, setAttributes }) => {
|
|
15
|
-
const { label, intent, link, linkLabel, timeout } =
|
|
15
|
+
const { label, intent, link, linkLabel, timeout, classes, dataAttributes } =
|
|
16
|
+
attributes;
|
|
16
17
|
const blockProps = useBlockProps();
|
|
17
18
|
|
|
18
19
|
const buildClass = () => {
|
|
@@ -61,6 +62,22 @@ const edit = ({ attributes, setAttributes }) => {
|
|
|
61
62
|
step={1000}
|
|
62
63
|
/>
|
|
63
64
|
</PanelBody>
|
|
65
|
+
|
|
66
|
+
<PanelBody title="Extensibility" initialOpen={false}>
|
|
67
|
+
<TextControl
|
|
68
|
+
label="Custom Classes"
|
|
69
|
+
value={classes}
|
|
70
|
+
onChange={(val) => setAttributes({ classes: val })}
|
|
71
|
+
placeholder="class-name-1 class-name-2"
|
|
72
|
+
help="Space-separated CSS classes added to the toast element"
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
<p style={{ fontSize: '12px', color: '#666', marginTop: '8px' }}>
|
|
76
|
+
<strong>Data Attributes:</strong> Custom data-* attributes are
|
|
77
|
+
typically set via block templates or PHP filters for analytics,
|
|
78
|
+
testing, and custom hooks. See the block documentation for examples.
|
|
79
|
+
</p>
|
|
80
|
+
</PanelBody>
|
|
64
81
|
</InspectorControls>
|
|
65
82
|
<div
|
|
66
83
|
{...blockProps}
|
|
@@ -10,14 +10,27 @@
|
|
|
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']) ? wp_kses_post($attributes['label']) : '';
|
|
14
16
|
$intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : '';
|
|
15
17
|
$link = isset($attributes['link']) ? esc_url($attributes['link']) : '';
|
|
16
18
|
$link_label = isset($attributes['linkLabel']) ? sanitize_text_field($attributes['linkLabel']) : '';
|
|
17
19
|
$timeout = isset($attributes['timeout']) ? intval($attributes['timeout']) : 0;
|
|
20
|
+
$element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
|
|
21
|
+
|
|
22
|
+
// Sanitize and prepare data-* attributes
|
|
23
|
+
$sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'toast', $attributes);
|
|
24
|
+
$data_attrs_html = '';
|
|
25
|
+
foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
|
|
26
|
+
$data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
|
|
27
|
+
}
|
|
18
28
|
|
|
19
29
|
$classes = ['tds-toast'];
|
|
20
30
|
$classes[] = 'tds-toast--intent-' . $intent;
|
|
31
|
+
if ($element_class_name) {
|
|
32
|
+
$classes[] = $element_class_name;
|
|
33
|
+
}
|
|
21
34
|
|
|
22
35
|
$wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
|
|
23
36
|
?>
|
|
@@ -27,6 +40,7 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)
|
|
|
27
40
|
role="status"
|
|
28
41
|
aria-live="polite"
|
|
29
42
|
<?php echo $timeout ? 'data-timeout="' . esc_attr($timeout) . '"' : ''; ?>
|
|
43
|
+
<?php echo wp_kses_post($data_attrs_html); ?>
|
|
30
44
|
>
|
|
31
45
|
<div class="tds-toast__content">
|
|
32
46
|
<div class="tds-toast__label"><?php echo wp_kses_post($label); ?></div>
|