@times-design-system/components-wordpress 1.5.3 → 1.7.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.
Files changed (175) hide show
  1. package/dist/blocks/ad-container/block.json +10 -0
  2. package/dist/blocks/ad-container/edit.js +17 -1
  3. package/dist/blocks/ad-container/render.php +14 -0
  4. package/dist/blocks/button/block.json +19 -5
  5. package/dist/blocks/button/edit.js +33 -15
  6. package/dist/blocks/button/render.php +38 -2
  7. package/dist/blocks/button/style.css +63 -0
  8. package/dist/blocks/chip/block.json +12 -7
  9. package/dist/blocks/chip/edit.js +20 -17
  10. package/dist/blocks/chip/render.php +25 -3
  11. package/dist/blocks/dialog-box/block.json +10 -0
  12. package/dist/blocks/dialog-box/edit.js +17 -0
  13. package/dist/blocks/dialog-box/render.php +18 -7
  14. package/dist/blocks/divider/block.json +10 -0
  15. package/dist/blocks/divider/edit.js +18 -2
  16. package/dist/blocks/divider/render.php +14 -1
  17. package/dist/blocks/flag/block.json +10 -0
  18. package/dist/blocks/flag/edit.js +27 -2
  19. package/dist/blocks/flag/render.php +25 -1
  20. package/dist/blocks/icon/block.json +10 -0
  21. package/dist/blocks/icon/edit.js +17 -0
  22. package/dist/blocks/icon/render.php +19 -8
  23. package/dist/blocks/icon-button/block.json +15 -0
  24. package/dist/blocks/icon-button/edit.js +33 -1
  25. package/dist/blocks/icon-button/render.php +19 -0
  26. package/dist/blocks/icon-button/style.css +37 -3
  27. package/dist/blocks/input/block.json +10 -0
  28. package/dist/blocks/input/edit.js +27 -1
  29. package/dist/blocks/input/render.php +17 -1
  30. package/dist/blocks/input-helper-message/block.json +10 -0
  31. package/dist/blocks/input-helper-message/edit.js +17 -0
  32. package/dist/blocks/input-helper-message/render.php +18 -7
  33. package/dist/blocks/link/block.json +12 -7
  34. package/dist/blocks/link/edit.js +21 -18
  35. package/dist/blocks/link/render.php +25 -3
  36. package/dist/blocks/tab/block.json +10 -0
  37. package/dist/blocks/tab/edit.js +17 -0
  38. package/dist/blocks/tab/render.php +18 -7
  39. package/dist/blocks/tab-group/block.json +10 -0
  40. package/dist/blocks/tab-group/edit.js +17 -0
  41. package/dist/blocks/tab-group/render.php +18 -7
  42. package/dist/blocks/text/block.json +10 -0
  43. package/dist/blocks/text/edit.js +18 -2
  44. package/dist/blocks/text/render.php +14 -1
  45. package/dist/blocks/toast/block.json +10 -0
  46. package/dist/blocks/toast/edit.js +18 -1
  47. package/dist/blocks/toast/render.php +14 -0
  48. package/dist/index.cjs +389 -148
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.js +389 -148
  51. package/dist/index.js.map +1 -1
  52. package/dist/utils/DATA_ATTRIBUTES_USAGE.md +377 -0
  53. package/dist/utils/sanitize-data-attributes.php +109 -0
  54. package/package.json +9 -3
  55. package/BLOCK_CREATION_CHECKLIST.md +0 -385
  56. package/BUILD.md +0 -411
  57. package/CHANGELOG.md +0 -85
  58. package/SCSS_VARIABLES_REFERENCE.md +0 -316
  59. package/STYLING_SYNC_GUIDE.md +0 -306
  60. package/TESTING.md +0 -152
  61. package/TRANSFORMATION_GUIDE.md +0 -908
  62. package/dist/blocks/button/style-resolved.css +0 -153
  63. package/lib/wordpress.js +0 -7
  64. package/rollup.config.js +0 -75
  65. package/scripts/build-plugin.cjs +0 -121
  66. package/scripts/create-block.sh +0 -141
  67. package/scripts/create-wordpress-block-tests.cjs +0 -438
  68. package/scripts/create-wordpress-block.cjs +0 -681
  69. package/src/blocks/ad-container/block.json +0 -29
  70. package/src/blocks/ad-container/edit.js +0 -42
  71. package/src/blocks/ad-container/index.js +0 -10
  72. package/src/blocks/ad-container/render.php +0 -27
  73. package/src/blocks/ad-container/save.js +0 -16
  74. package/src/blocks/ad-container/style-editor.css +0 -4
  75. package/src/blocks/ad-container/style.css +0 -30
  76. package/src/blocks/button/block.json +0 -90
  77. package/src/blocks/button/edit.js +0 -187
  78. package/src/blocks/button/index.js +0 -11
  79. package/src/blocks/button/render.php +0 -71
  80. package/src/blocks/button/save.js +0 -52
  81. package/src/blocks/button/style-editor.css +0 -15
  82. package/src/blocks/button/style-resolved.css +0 -153
  83. package/src/blocks/button/style.css +0 -157
  84. package/src/blocks/chip/block.json +0 -58
  85. package/src/blocks/chip/edit.js +0 -113
  86. package/src/blocks/chip/index.js +0 -10
  87. package/src/blocks/chip/render.php +0 -40
  88. package/src/blocks/chip/save.js +0 -36
  89. package/src/blocks/chip/style-editor.css +0 -5
  90. package/src/blocks/chip/style.css +0 -87
  91. package/src/blocks/dialog-box/block.json +0 -24
  92. package/src/blocks/dialog-box/edit.js +0 -41
  93. package/src/blocks/dialog-box/index.js +0 -17
  94. package/src/blocks/dialog-box/render.php +0 -24
  95. package/src/blocks/dialog-box/save.js +0 -23
  96. package/src/blocks/dialog-box/style.css +0 -23
  97. package/src/blocks/divider/block.json +0 -32
  98. package/src/blocks/divider/edit.js +0 -42
  99. package/src/blocks/divider/index.js +0 -10
  100. package/src/blocks/divider/render.php +0 -31
  101. package/src/blocks/divider/save.js +0 -18
  102. package/src/blocks/divider/style-editor.css +0 -4
  103. package/src/blocks/divider/style.css +0 -37
  104. package/src/blocks/flag/block.json +0 -49
  105. package/src/blocks/flag/edit.js +0 -82
  106. package/src/blocks/flag/index.js +0 -10
  107. package/src/blocks/flag/render.php +0 -34
  108. package/src/blocks/flag/save.js +0 -25
  109. package/src/blocks/flag/style-editor.css +0 -5
  110. package/src/blocks/flag/style.css +0 -54
  111. package/src/blocks/icon/block.json +0 -24
  112. package/src/blocks/icon/edit.js +0 -41
  113. package/src/blocks/icon/index.js +0 -17
  114. package/src/blocks/icon/render.php +0 -24
  115. package/src/blocks/icon/save.js +0 -23
  116. package/src/blocks/icon/style.css +0 -23
  117. package/src/blocks/icon-button/block.json +0 -44
  118. package/src/blocks/icon-button/edit.js +0 -82
  119. package/src/blocks/icon-button/index.js +0 -10
  120. package/src/blocks/icon-button/render.php +0 -46
  121. package/src/blocks/icon-button/save.js +0 -29
  122. package/src/blocks/icon-button/style-editor.css +0 -5
  123. package/src/blocks/icon-button/style.css +0 -31
  124. package/src/blocks/input/block.json +0 -48
  125. package/src/blocks/input/edit.js +0 -78
  126. package/src/blocks/input/index.js +0 -10
  127. package/src/blocks/input/render.php +0 -39
  128. package/src/blocks/input/save.js +0 -27
  129. package/src/blocks/input/style-editor.css +0 -8
  130. package/src/blocks/input/style.css +0 -53
  131. package/src/blocks/input-helper-message/block.json +0 -24
  132. package/src/blocks/input-helper-message/edit.js +0 -42
  133. package/src/blocks/input-helper-message/index.js +0 -17
  134. package/src/blocks/input-helper-message/render.php +0 -24
  135. package/src/blocks/input-helper-message/save.js +0 -23
  136. package/src/blocks/input-helper-message/style.css +0 -23
  137. package/src/blocks/link/block.json +0 -72
  138. package/src/blocks/link/edit.js +0 -151
  139. package/src/blocks/link/index.js +0 -10
  140. package/src/blocks/link/render.php +0 -44
  141. package/src/blocks/link/save.js +0 -46
  142. package/src/blocks/link/style-editor.css +0 -5
  143. package/src/blocks/link/style.css +0 -119
  144. package/src/blocks/tab/block.json +0 -24
  145. package/src/blocks/tab/edit.js +0 -41
  146. package/src/blocks/tab/index.js +0 -17
  147. package/src/blocks/tab/render.php +0 -24
  148. package/src/blocks/tab/save.js +0 -23
  149. package/src/blocks/tab/style.css +0 -23
  150. package/src/blocks/tab-group/block.json +0 -24
  151. package/src/blocks/tab-group/edit.js +0 -41
  152. package/src/blocks/tab-group/index.js +0 -17
  153. package/src/blocks/tab-group/render.php +0 -24
  154. package/src/blocks/tab-group/save.js +0 -23
  155. package/src/blocks/tab-group/style.css +0 -23
  156. package/src/blocks/text/block.json +0 -33
  157. package/src/blocks/text/edit.js +0 -56
  158. package/src/blocks/text/index.js +0 -10
  159. package/src/blocks/text/render.php +0 -26
  160. package/src/blocks/text/save.js +0 -18
  161. package/src/blocks/text/style-editor.css +0 -4
  162. package/src/blocks/text/style.css +0 -7
  163. package/src/blocks/toast/block.json +0 -40
  164. package/src/blocks/toast/edit.js +0 -85
  165. package/src/blocks/toast/index.js +0 -10
  166. package/src/blocks/toast/render.php +0 -37
  167. package/src/blocks/toast/save.js +0 -29
  168. package/src/blocks/toast/style-editor.css +0 -4
  169. package/src/blocks/toast/style.css +0 -67
  170. package/src/index.js +0 -16
  171. package/src/utils/classBuilder.js +0 -53
  172. package/tsconfig.json +0 -116
  173. package/vitest.config.js +0 -28
  174. package/vitest.config.ts +0 -28
  175. 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
- "state": {
45
- "type": "string",
46
- "enum": ["base", "hover", "pressed", "loading", "disabled", "focus"],
47
- "default": "base",
48
- "description": "The interaction state"
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
- state,
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
- <SelectControl
103
- label="State"
104
- value={state}
105
- options={[
106
- { label: 'Base', value: 'base' },
107
- { label: 'Hover', value: 'hover' },
108
- { label: 'Pressed', value: 'pressed' },
109
- { label: 'Loading', value: 'loading' },
110
- { label: 'Disabled', value: 'disabled' },
111
- { label: 'Focus', value: 'focus' }
112
- ]}
113
- onChange={(value) => setAttributes({ state: value })}
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,49 @@
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
- $state = isset($attributes['state']) ? sanitize_text_field($attributes['state']) : 'base';
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';
26
+ $icon_left = isset($attributes['iconLeft']) ? sanitize_text_field($attributes['iconLeft']) : '';
27
+ $icon_right = isset($attributes['iconRight']) ? sanitize_text_field($attributes['iconRight']) : '';
23
28
  $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
29
+ $element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
30
+
31
+ // Sanitize and prepare data-* attributes
32
+ $sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'button', $attributes);
33
+ $data_attrs_html = '';
34
+ foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
35
+ $data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
36
+ }
24
37
 
25
38
  // Build button classes
26
39
  $classes = ['tds-button'];
27
40
  $classes[] = 'tds-button--intent-' . $intent;
28
41
  $classes[] = 'tds-button--size-' . $size;
29
42
  $classes[] = 'tds-button--behaviour-' . $behaviour;
30
- $classes[] = 'tds-button--state-' . $state;
43
+ if ($isRounded) {
44
+ $classes[] = 'tds-button--rounded';
45
+ }
46
+ if ($isLoading) {
47
+ $classes[] = 'tds-button--loading';
48
+ }
31
49
  if ($disabled) {
32
50
  $classes[] = 'tds-button--disabled';
33
51
  }
52
+ // Add custom classes
53
+ if ($element_class_name) {
54
+ $classes[] = $element_class_name;
55
+ }
34
56
 
35
57
  $button_class = implode(' ', $classes);
36
58
  $element_tag = $href ? 'a' : 'button';
@@ -47,9 +69,16 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => 'tds-button-wrapper'])
47
69
  <?php echo $target ? 'target="' . esc_attr($target) . '"' : ''; ?>
48
70
  <?php echo $rel ? 'rel="' . esc_attr($rel) . '"' : ''; ?>
49
71
  <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
72
+ <?php echo wp_kses_post($data_attrs_html); ?>
50
73
  >
51
74
  <span class="tds-button__label-container">
75
+ <?php if ($icon_left) : ?>
76
+ <span class="tds-button__icon tds-button__icon--left"><?php echo wp_kses_post($icon_left); ?></span>
77
+ <?php endif; ?>
52
78
  <span class="tds-button__label"><?php echo wp_kses_post($label); ?></span>
79
+ <?php if ($icon_right) : ?>
80
+ <span class="tds-button__icon tds-button__icon--right"><?php echo wp_kses_post($icon_right); ?></span>
81
+ <?php endif; ?>
53
82
  </span>
54
83
  </a>
55
84
  <?php
@@ -60,9 +89,16 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => 'tds-button-wrapper'])
60
89
  <?php echo $disabled ? 'disabled' : ''; ?>
61
90
  type="<?php echo esc_attr($type); ?>"
62
91
  <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
92
+ <?php echo wp_kses_post($data_attrs_html); ?>
63
93
  >
64
94
  <span class="tds-button__label-container">
95
+ <?php if ($icon_left) : ?>
96
+ <span class="tds-button__icon tds-button__icon--left"><?php echo wp_kses_post($icon_left); ?></span>
97
+ <?php endif; ?>
65
98
  <span class="tds-button__label"><?php echo wp_kses_post($label); ?></span>
99
+ <?php if ($icon_right) : ?>
100
+ <span class="tds-button__icon tds-button__icon--right"><?php echo wp_kses_post($icon_right); ?></span>
101
+ <?php endif; ?>
66
102
  </span>
67
103
  </button>
68
104
  <?php
@@ -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", "negative"]
24
+ "enum": ["primary", "secondary"]
25
25
  },
26
26
  "size": {
27
27
  "type": "string",
28
28
  "default": "medium",
29
- "enum": ["small", "medium", "large"]
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": {}
@@ -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,37 @@
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;
20
+ $icon_left = isset($attributes['iconLeft']) ? sanitize_text_field($attributes['iconLeft']) : '';
21
+ $icon_right = isset($attributes['iconRight']) ? sanitize_text_field($attributes['iconRight']) : '';
19
22
  $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
23
+ $element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
24
+
25
+ // Sanitize and prepare data-* attributes
26
+ $sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'chip', $attributes);
27
+ $data_attrs_html = '';
28
+ foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
29
+ $data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
30
+ }
20
31
 
21
32
  $classes = ['tds-chip'];
22
33
  $classes[] = 'tds-chip--intent-' . $intent;
23
34
  $classes[] = 'tds-chip--size-' . $size;
24
- $classes[] = 'tds-chip--state-' . $state;
25
35
  if ($channel) {
26
36
  $classes[] = 'tds-chip--channel';
27
37
  }
28
38
  if ($toggle) {
29
39
  $classes[] = 'tds-chip--toggle';
30
40
  }
41
+ if ($element_class_name) {
42
+ $classes[] = $element_class_name;
43
+ }
31
44
 
32
45
  $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
33
46
  ?>
@@ -35,6 +48,15 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)
35
48
  <button
36
49
  <?php echo wp_kses_post($wrapper_attrs); ?>
37
50
  <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
51
+ <?php echo wp_kses_post($data_attrs_html); ?>
38
52
  >
39
- <span class="tds-chip__content"><?php echo wp_kses_post($content_text); ?></span>
53
+ <span class="tds-chip__content">
54
+ <?php if ($icon_left) : ?>
55
+ <span class="tds-chip__icon tds-chip__icon--left"><?php echo wp_kses_post($icon_left); ?></span>
56
+ <?php endif; ?>
57
+ <?php echo wp_kses_post($content_text); ?>
58
+ <?php if ($icon_right) : ?>
59
+ <span class="tds-chip__icon tds-chip__icon--right"><?php echo wp_kses_post($icon_right); ?></span>
60
+ <?php endif; ?>
61
+ </span>
40
62
  </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,14 +11,25 @@
11
11
  * @return string Rendered HTML
12
12
  */
13
13
 
14
- $wrapper_attributes = get_block_wrapper_attributes();
14
+ require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
15
15
 
16
- // TODO: Render the DialogBox component
17
- // Extract attributes and render appropriate HTML with BEM classes
16
+ $content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
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'] ?? [], 'dialog-box', $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
+ }
25
+
26
+ $wrapper_classes = ['tds-dialog-box'];
27
+ if ($element_class_name) {
28
+ $wrapper_classes[] = $element_class_name;
29
+ }
30
+ $wrapper_attributes = get_block_wrapper_attributes(['class' => implode(' ', $wrapper_classes)]);
18
31
 
19
32
  ?>
20
- <div <?php echo wp_kses_post( $wrapper_attributes ); ?>>
21
- <!-- TODO: Render DialogBox component here -->
22
- <!-- Use CSS custom properties from packages/tokens/data/resolved-hexes.json -->
23
- <!-- Apply BEM naming: tds-dialog-box--{modifier} -->
33
+ <div <?php echo wp_kses_post($wrapper_attributes); ?><?php echo wp_kses_post($data_attrs_html); ?>>
34
+ <?php echo wp_kses_post($content_text); ?>
24
35
  </div>
@@ -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": {}