@times-design-system/components-wordpress 1.13.0 → 1.16.1-alpha.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 (83) hide show
  1. package/dist/STYLE_HANDLES.md +3 -1
  2. package/dist/blocks/ad-container/block.json +5 -0
  3. package/dist/blocks/ad-container/render.php +10 -1
  4. package/dist/blocks/ad-container/style.css +1 -1
  5. package/dist/blocks/ad-container/style.scss +4 -3
  6. package/dist/blocks/button/block.json +5 -0
  7. package/dist/blocks/button/init.js +1 -1
  8. package/dist/blocks/button/render.php +12 -2
  9. package/dist/blocks/button/style.css +1 -1
  10. package/dist/blocks/button/style.scss +33 -33
  11. package/dist/blocks/chip/block.json +15 -0
  12. package/dist/blocks/chip/render.php +54 -21
  13. package/dist/blocks/chip/style.css +1 -1
  14. package/dist/blocks/chip/style.scss +137 -77
  15. package/dist/blocks/dialog-box/block.json +5 -0
  16. package/dist/blocks/dialog-box/render.php +9 -1
  17. package/dist/blocks/dialog-box/style.css +1 -1
  18. package/dist/blocks/dialog-box/style.scss +8 -6
  19. package/dist/blocks/divider/block.json +21 -1
  20. package/dist/blocks/divider/render.php +9 -1
  21. package/dist/blocks/divider/style.css +1 -1
  22. package/dist/blocks/divider/style.scss +5 -4
  23. package/dist/blocks/icon/block.json +5 -0
  24. package/dist/blocks/icon/render.php +10 -12
  25. package/dist/blocks/icon/style.css +1 -1
  26. package/dist/blocks/icon/style.scss +5 -1
  27. package/dist/blocks/icon-button/block.json +5 -0
  28. package/dist/blocks/icon-button/render.php +16 -6
  29. package/dist/blocks/icon-button/style.css +1 -1
  30. package/dist/blocks/icon-button/style.scss +34 -33
  31. package/dist/blocks/input/block.json +5 -0
  32. package/dist/blocks/input/render.php +10 -1
  33. package/dist/blocks/input/style.css +1 -1
  34. package/dist/blocks/input/style.scss +16 -14
  35. package/dist/blocks/input-helper-message/block.json +5 -0
  36. package/dist/blocks/input-helper-message/render.php +9 -1
  37. package/dist/blocks/input-helper-message/style.css +1 -1
  38. package/dist/blocks/input-helper-message/style.scss +7 -6
  39. package/dist/blocks/label/block.json +68 -0
  40. package/dist/blocks/label/edit.js +79 -0
  41. package/dist/blocks/label/index.js +11 -0
  42. package/dist/blocks/label/render.php +56 -0
  43. package/dist/blocks/label/save.js +21 -0
  44. package/dist/blocks/label/style.css +1 -0
  45. package/dist/blocks/label/style.scss +39 -0
  46. package/dist/blocks/link/block.json +5 -0
  47. package/dist/blocks/link/render.php +3 -1
  48. package/dist/blocks/link/style.css +1 -1
  49. package/dist/blocks/link/style.scss +20 -19
  50. package/dist/blocks/tab/block.json +5 -0
  51. package/dist/blocks/tab/render.php +9 -1
  52. package/dist/blocks/tab/style.css +1 -1
  53. package/dist/blocks/tab/style.scss +17 -16
  54. package/dist/blocks/tab-group/block.json +5 -0
  55. package/dist/blocks/tab-group/render.php +9 -1
  56. package/dist/blocks/tab-group/style.css +1 -1
  57. package/dist/blocks/tab-group/style.scss +4 -2
  58. package/dist/blocks/tag/block.json +5 -0
  59. package/dist/blocks/tag/render.php +10 -1
  60. package/dist/blocks/tag/style.css +1 -1
  61. package/dist/blocks/tag/style.scss +24 -26
  62. package/dist/blocks/text/block.json +5 -0
  63. package/dist/blocks/text/render.php +9 -1
  64. package/dist/blocks/text/style.scss +1 -1
  65. package/dist/blocks/toast/block.json +5 -0
  66. package/dist/blocks/toast/render.php +10 -1
  67. package/dist/blocks/toast/style.css +1 -1
  68. package/dist/blocks/toast/style.scss +14 -13
  69. package/dist/icon-data.json +1 -1
  70. package/dist/index.cjs +485 -177
  71. package/dist/index.cjs.map +1 -1
  72. package/dist/index.css +1 -1
  73. package/dist/index.css.map +1 -1
  74. package/dist/index.js +485 -177
  75. package/dist/index.js.map +1 -1
  76. package/dist/plugin.php +1 -0
  77. package/dist/style-handles.json +5 -0
  78. package/dist/utils/render-icon.php +129 -117
  79. package/dist/utils/sanitize-aria-attributes.php +109 -0
  80. package/package.json +4 -4
  81. package/plugin.php +1 -0
  82. package/dist/blocks/utils/render-icon.php +0 -106
  83. package/dist/blocks/utils/sanitize-data-attributes.php +0 -37
package/dist/plugin.php CHANGED
@@ -40,6 +40,7 @@ function tds_register_block_styles() {
40
40
  'icon-button' => 'tds-icon-button-style',
41
41
  'input' => 'tds-input-style',
42
42
  'input-helper-message' => 'tds-input-helper-message-style',
43
+ 'label' => 'tds-label-style',
43
44
  'link' => 'tds-link-style',
44
45
  'tab' => 'tds-tab-style',
45
46
  'tab-group' => 'tds-tab-group-style',
@@ -44,6 +44,11 @@
44
44
  "cssFile": "blocks/input-helper-message/style.css",
45
45
  "phpPath": "blocks/input-helper-message/style.css"
46
46
  },
47
+ "label": {
48
+ "handle": "tds-label-style",
49
+ "cssFile": "blocks/label/style.css",
50
+ "phpPath": "blocks/label/style.css"
51
+ },
47
52
  "link": {
48
53
  "handle": "tds-link-style",
49
54
  "cssFile": "blocks/link/style.css",
@@ -15,15 +15,17 @@
15
15
  *
16
16
  * @var array
17
17
  */
18
- const ICON_SIZE_MAP = [
19
- '2xsmall' => ['width' => 12, 'height' => 12],
20
- 'xsmall' => ['width' => 16, 'height' => 16],
21
- 'small' => ['width' => 20, 'height' => 20],
22
- 'medium' => ['width' => 24, 'height' => 24],
23
- 'large' => ['width' => 28, 'height' => 28],
24
- 'xlarge' => ['width' => 32, 'height' => 32],
25
- '2xlarge' => ['width' => 40, 'height' => 40],
26
- ];
18
+ if (!defined('ICON_SIZE_MAP')) {
19
+ define('ICON_SIZE_MAP', [
20
+ '2xsmall' => ['width' => 12, 'height' => 12],
21
+ 'xsmall' => ['width' => 16, 'height' => 16],
22
+ 'small' => ['width' => 20, 'height' => 20],
23
+ 'medium' => ['width' => 24, 'height' => 24],
24
+ 'large' => ['width' => 28, 'height' => 28],
25
+ 'xlarge' => ['width' => 32, 'height' => 32],
26
+ '2xlarge' => ['width' => 40, 'height' => 40],
27
+ ]);
28
+ }
27
29
 
28
30
  /**
29
31
  * Load icon data from JSON file
@@ -32,31 +34,30 @@ const ICON_SIZE_MAP = [
32
34
  *
33
35
  * @return array|false Icon data array with 'icons' key, or false on failure
34
36
  */
35
- function tds_load_icon_data() {
36
- static $icon_data = null;
37
+ if (!function_exists('tds_load_icon_data')) {
38
+ function tds_load_icon_data() {
39
+ static $icon_data = null;
37
40
 
38
- if ($icon_data !== null) {
39
- return $icon_data;
40
- }
41
+ if ($icon_data !== null) {
42
+ return $icon_data;
43
+ }
41
44
 
42
- $plugin_dir = dirname(dirname(__DIR__));
43
- $icon_data_path = $plugin_dir . '/dist/icon-data.json';
45
+ $plugin_dir = dirname(dirname(__DIR__));
46
+ $icon_data_path = $plugin_dir . '/dist/icon-data.json';
44
47
 
45
- if (!file_exists($icon_data_path)) {
46
- // If icon data hasn't been extracted yet, log a warning and return false
47
- // This is normal during first install or if build hasn't been run
48
- return false;
49
- }
48
+ if (!file_exists($icon_data_path)) {
49
+ // If icon data hasn't been extracted yet, log a warning and return false
50
+ // This is normal during first install or if build hasn't been run
51
+ return false;
52
+ }
50
53
 
51
- $json_content = file_get_contents($icon_data_path);
52
- $icon_data = json_decode($json_content, true);
54
+ $json_content = file_get_contents($icon_data_path);
55
+ $icon_data = json_decode($json_content, true);
53
56
 
54
- return $icon_data ?: false;
57
+ return $icon_data ?: false;
58
+ }
55
59
  }
56
60
 
57
- /**
58
- * Get icon SVG by name and optional variant
59
- *
60
61
  /**
61
62
  * Get icon SVG content from icon data store
62
63
  *
@@ -65,25 +66,27 @@ function tds_load_icon_data() {
65
66
  * @param string $icon_name Icon name with variant (e.g., 'filled_arrow_left', 'outlined_check')
66
67
  * @return string|false SVG content or false if not found
67
68
  */
68
- function tds_get_icon_svg($icon_name) {
69
- if (empty($icon_name)) {
70
- return false;
71
- }
69
+ if (!function_exists('tds_get_icon_svg')) {
70
+ function tds_get_icon_svg($icon_name) {
71
+ if (empty($icon_name)) {
72
+ return false;
73
+ }
72
74
 
73
- $icon_data = tds_load_icon_data();
74
- if (!$icon_data || !isset($icon_data['icons'])) {
75
- return false;
76
- }
75
+ $icon_data = tds_load_icon_data();
76
+ if (!$icon_data || !isset($icon_data['icons'])) {
77
+ return false;
78
+ }
77
79
 
78
- // Sanitize the icon name (includes variant prefix)
79
- $icon_name = sanitize_key($icon_name);
80
-
81
- // Look up icon directly (icon name already includes variant)
82
- if (isset($icon_data['icons'][$icon_name])) {
83
- return $icon_data['icons'][$icon_name];
80
+ // Sanitize the icon name (includes variant prefix)
81
+ $icon_name = sanitize_key($icon_name);
82
+
83
+ // Look up icon directly (icon name already includes variant)
84
+ if (isset($icon_data['icons'][$icon_name])) {
85
+ return $icon_data['icons'][$icon_name];
86
+ }
87
+
88
+ return false;
84
89
  }
85
-
86
- return false;
87
90
  }
88
91
 
89
92
  /**
@@ -96,28 +99,30 @@ function tds_get_icon_svg($icon_name) {
96
99
  * @param string $class Optional CSS class to add to the SVG
97
100
  * @return string HTML SVG string or empty string if icon not found
98
101
  */
99
- function tds_render_icon($icon_name, $size_name = 'medium', $class = '') {
100
- if (empty($icon_name)) {
101
- return '';
102
- }
102
+ if (!function_exists('tds_render_icon')) {
103
+ function tds_render_icon($icon_name, $size_name = 'medium', $class = '') {
104
+ if (empty($icon_name)) {
105
+ return '';
106
+ }
103
107
 
104
- $svg_content = tds_get_icon_svg($icon_name);
105
- if (!$svg_content) {
106
- // Icon not found - log debug info if WP_DEBUG is enabled
107
- if (defined('WP_DEBUG') && WP_DEBUG) {
108
- error_log("Icon not found: {$variant}-{$icon_name}");
108
+ $svg_content = tds_get_icon_svg($icon_name);
109
+ if (!$svg_content) {
110
+ // Icon not found - log debug info if WP_DEBUG is enabled
111
+ if (defined('WP_DEBUG') && WP_DEBUG) {
112
+ error_log("Icon not found: {$variant}-{$icon_name}");
113
+ }
114
+ return '';
109
115
  }
110
- return '';
111
- }
112
116
 
113
- // Get dimensions for the size
114
- $size_name = sanitize_key($size_name ?? 'medium');
115
- $dimensions = ICON_SIZE_MAP[$size_name] ?? ICON_SIZE_MAP['medium'];
117
+ // Get dimensions for the size
118
+ $size_name = sanitize_key($size_name ?? 'medium');
119
+ $dimensions = ICON_SIZE_MAP[$size_name] ?? ICON_SIZE_MAP['medium'];
116
120
 
117
- // Parse SVG to add width/height attributes
118
- $svg_content = tds_inject_svg_dimensions($svg_content, $dimensions['width'], $dimensions['height'], $class);
121
+ // Parse SVG to add width/height attributes
122
+ $svg_content = tds_inject_svg_dimensions($svg_content, $dimensions['width'], $dimensions['height'], $class);
119
123
 
120
- return $svg_content;
124
+ return $svg_content;
125
+ }
121
126
  }
122
127
 
123
128
  /**
@@ -132,51 +137,53 @@ function tds_render_icon($icon_name, $size_name = 'medium', $class = '') {
132
137
  * @param string $class Optional CSS class
133
138
  * @return string Modified SVG
134
139
  */
135
- function tds_inject_svg_dimensions($svg, $width, $height, $class = '') {
136
- // Remove or replace existing width/height attributes, then add the correct ones
137
- // Match width="...", width='...' or width=... patterns and replace with new value
138
- $svg = preg_replace('/width="[^"]*"/', sprintf('width="%d"', $width), $svg);
139
- $svg = preg_replace('/width=\'[^\']*\'/', sprintf('width="%d"', $width), $svg);
140
-
141
- // Same for height
142
- $svg = preg_replace('/height="[^"]*"/', sprintf('height="%d"', $height), $svg);
143
- $svg = preg_replace('/height=\'[^\']*\'/', sprintf('height="%d"', $height), $svg);
144
-
145
- // If SVG still doesn't have width/height (fallback for edge cases), inject them
146
- if (strpos($svg, 'width=') === false || strpos($svg, 'height=') === false) {
147
- $svg = str_replace('<svg', sprintf('<svg width="%d" height="%d"', $width, $height), $svg);
148
- }
140
+ if (!function_exists('tds_inject_svg_dimensions')) {
141
+ function tds_inject_svg_dimensions($svg, $width, $height, $class = '') {
142
+ // Remove or replace existing width/height attributes, then add the correct ones
143
+ // Match width="...", width='...' or width=... patterns and replace with new value
144
+ $svg = preg_replace('/width="[^"]*"/', sprintf('width="%d"', $width), $svg);
145
+ $svg = preg_replace('/width=\'[^\']*\'/', sprintf('width="%d"', $width), $svg);
146
+
147
+ // Same for height
148
+ $svg = preg_replace('/height="[^"]*"/', sprintf('height="%d"', $height), $svg);
149
+ $svg = preg_replace('/height=\'[^\']*\'/', sprintf('height="%d"', $height), $svg);
150
+
151
+ // If SVG still doesn't have width/height (fallback for edge cases), inject them
152
+ if (strpos($svg, 'width=') === false || strpos($svg, 'height=') === false) {
153
+ $svg = str_replace('<svg', sprintf('<svg width="%d" height="%d"', $width, $height), $svg);
154
+ }
149
155
 
150
- // Replace fill attributes with currentcolor
151
- $svg = preg_replace('/fill="[^"]*"/i', 'fill="currentcolor"', $svg);
152
-
153
- // Replace stroke attributes with currentcolor
154
- $svg = preg_replace('/stroke="[^"]*"/i', 'stroke="currentcolor"', $svg);
155
-
156
- // Handle fill in style attributes: style="fill: #xxx" or style="...fill: #xxx..."
157
- $svg = preg_replace('/style="([^"]*)fill:\s*[^;}"]+/i', 'style="$1fill: currentcolor', $svg);
158
-
159
- // Handle stroke in style attributes: style="stroke: #xxx" or style="...stroke: #xxx..."
160
- $svg = preg_replace('/style="([^"]*)stroke:\s*[^;}"]+/i', 'style="$1stroke: currentcolor', $svg);
156
+ // Replace fill attributes with currentcolor
157
+ $svg = preg_replace('/fill="[^"]*"/i', 'fill="currentcolor"', $svg);
158
+
159
+ // Replace stroke attributes with currentcolor
160
+ $svg = preg_replace('/stroke="[^"]*"/i', 'stroke="currentcolor"', $svg);
161
+
162
+ // Handle fill in style attributes: style="fill: #xxx" or style="...fill: #xxx..."
163
+ $svg = preg_replace('/style="([^"]*)fill:\s*[^;}"]+/i', 'style="$1fill: currentcolor', $svg);
164
+
165
+ // Handle stroke in style attributes: style="stroke: #xxx" or style="...stroke: #xxx..."
166
+ $svg = preg_replace('/style="([^"]*)stroke:\s*[^;}"]+/i', 'style="$1stroke: currentcolor', $svg);
161
167
 
162
- // Add class if provided
163
- if (!empty($class)) {
164
- $class_attr = sanitize_html_class($class);
165
- if (preg_match('/class="([^"]*)"/', $svg, $matches)) {
166
- // Class already exists, append to it
167
- $existing_class = $matches[1];
168
- $svg = str_replace(
169
- sprintf('class="%s"', $existing_class),
170
- sprintf('class="%s %s"', $existing_class, $class_attr),
171
- $svg
172
- );
173
- } else {
174
- // No class attribute, add one
175
- $svg = str_replace('<svg', sprintf('<svg class="%s"', $class_attr), $svg);
168
+ // Add class if provided
169
+ if (!empty($class)) {
170
+ $class_attr = sanitize_html_class($class);
171
+ if (preg_match('/class="([^"]*)"/', $svg, $matches)) {
172
+ // Class already exists, append to it
173
+ $existing_class = $matches[1];
174
+ $svg = str_replace(
175
+ sprintf('class="%s"', $existing_class),
176
+ sprintf('class="%s %s"', $existing_class, $class_attr),
177
+ $svg
178
+ );
179
+ } else {
180
+ // No class attribute, add one
181
+ $svg = str_replace('<svg', sprintf('<svg class="%s"', $class_attr), $svg);
182
+ }
176
183
  }
177
- }
178
184
 
179
- return $svg;
185
+ return $svg;
186
+ }
180
187
  }
181
188
 
182
189
  /**
@@ -226,23 +233,25 @@ function tds_render_icon_wrapper($icon_name, $size_name = 'medium', $position =
226
233
  * @param string $svg SVG HTML string to sanitize
227
234
  * @return string Sanitized SVG safe for output
228
235
  */
229
- function tds_kses_svg($svg) {
230
- if (empty($svg)) {
231
- return '';
232
- }
236
+ if (!function_exists('tds_kses_svg')) {
237
+ function tds_kses_svg($svg) {
238
+ if (empty($svg)) {
239
+ return '';
240
+ }
233
241
 
234
- $allowed_tags = array(
235
- 'svg' => array(
236
- 'xmlns' => true,
237
- 'viewBox' => true,
238
- 'width' => true,
239
- 'height' => true,
240
- 'class' => true,
241
- 'style' => true,
242
- 'aria-hidden' => true,
243
- 'role' => true,
244
- 'data-*' => true,
245
- ),
242
+ $allowed_tags = array(
243
+ 'svg' => array(
244
+ 'xmlns' => true,
245
+ 'viewBox' => true,
246
+ 'viewbox' => true,
247
+ 'width' => true,
248
+ 'height' => true,
249
+ 'class' => true,
250
+ 'style' => true,
251
+ 'aria-hidden' => true,
252
+ 'role' => true,
253
+ 'data-*' => true,
254
+ ),
246
255
  'g' => array(
247
256
  'class' => true,
248
257
  'id' => true,
@@ -337,9 +346,12 @@ function tds_kses_svg($svg) {
337
346
  'y' => true,
338
347
  'width' => true,
339
348
  'height' => true,
349
+ 'viewBox' => true,
350
+ 'viewbox' => true,
340
351
  'class' => true,
341
352
  ),
342
353
  );
343
354
 
344
355
  return wp_kses($svg, $allowed_tags);
356
+ }
345
357
  }
@@ -0,0 +1,109 @@
1
+ <?php
2
+ /**
3
+ * ARIA Attributes Sanitization Utility
4
+ *
5
+ * Provides shared sanitization logic for block aria-* attributes.
6
+ * Ensures consistent security and validation across all blocks.
7
+ *
8
+ * @package TimesDesignSystem\ComponentsWordPress
9
+ */
10
+
11
+ /**
12
+ * Sanitize and validate custom aria-* attributes
13
+ *
14
+ * Applies a whitelist filter to determine which aria-* attributes are allowed,
15
+ * then validates and sanitizes each attribute before output.
16
+ *
17
+ * @param array $aria_attributes Raw aria attributes from block attributes
18
+ * @param string $block_name Block name without 'tds/' prefix (e.g., 'button', 'chip')
19
+ * @param array $attributes Full block attributes array (for filter context)
20
+ *
21
+ * @return array Sanitized and validated aria attributes ready for HTML output
22
+ *
23
+ * @example
24
+ * // In render.php:
25
+ * $sanitized_aria_attributes = tds_sanitize_aria_attributes(
26
+ * $attributes['ariaAttributes'] ?? [],
27
+ * 'button',
28
+ * $attributes
29
+ * );
30
+ *
31
+ * $aria_attrs_html = '';
32
+ * foreach ($sanitized_aria_attributes as $key => $value) {
33
+ * $aria_attrs_html .= ' ' . esc_attr($key) . '="' . esc_attr($value) . '"';
34
+ * }
35
+ *
36
+ * // Then in HTML:
37
+ * // <button <?php echo $aria_attrs_html; ?>>...</button>
38
+ */
39
+ function tds_sanitize_aria_attributes($aria_attributes, $block_name, $attributes = []) {
40
+ // Validate inputs
41
+ if (!is_array($aria_attributes)) {
42
+ return [];
43
+ }
44
+
45
+ if (!is_string($block_name)) {
46
+ return [];
47
+ }
48
+
49
+ if (!is_array($attributes)) {
50
+ $attributes = [];
51
+ }
52
+
53
+ // Get allowed aria attribute keys from filter
54
+ $allowed_aria_attribute_keys = apply_filters(
55
+ "tds_{$block_name}_allowed_aria_attributes",
56
+ [],
57
+ $attributes
58
+ );
59
+
60
+ // Ensure it's an array
61
+ if (!is_array($allowed_aria_attribute_keys)) {
62
+ $allowed_aria_attribute_keys = [];
63
+ }
64
+
65
+ // Limits for DoS prevention
66
+ $max_aria_attributes = 10;
67
+ $max_aria_value_length = 200;
68
+ $sanitized_aria_attributes = [];
69
+
70
+ // Regex for valid aria attribute names: aria-*, case-insensitive, allows numbers/hyphens/underscores
71
+ $valid_aria_attr_pattern = '/^aria-[a-z0-9_-]+$/i';
72
+
73
+ foreach ($aria_attributes as $key => $value) {
74
+ // Enforce maximum attribute count
75
+ if (count($sanitized_aria_attributes) >= $max_aria_attributes) {
76
+ break;
77
+ }
78
+
79
+ // Validate key and value are scalar types
80
+ if (!is_string($key) || !is_scalar($value)) {
81
+ continue;
82
+ }
83
+
84
+ // Must start with 'aria-'
85
+ if (strpos($key, 'aria-') !== 0) {
86
+ continue;
87
+ }
88
+
89
+ // Must match valid aria attribute pattern
90
+ if (!preg_match($valid_aria_attr_pattern, $key)) {
91
+ continue;
92
+ }
93
+
94
+ // Must be in allowed list (set via filter)
95
+ if (!in_array($key, $allowed_aria_attribute_keys, true)) {
96
+ continue;
97
+ }
98
+
99
+ // Sanitize and truncate value
100
+ $sanitized_value = sanitize_text_field((string) $value);
101
+ if (strlen($sanitized_value) > $max_aria_value_length) {
102
+ $sanitized_value = substr($sanitized_value, 0, $max_aria_value_length);
103
+ }
104
+
105
+ $sanitized_aria_attributes[$key] = $sanitized_value;
106
+ }
107
+
108
+ return $sanitized_aria_attributes;
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@times-design-system/components-wordpress",
3
- "version": "1.13.0",
3
+ "version": "1.16.1-alpha.0+91f353d4",
4
4
  "type": "module",
5
5
  "description": "Times Design System Gutenberg blocks for WordPress Full Site Editing",
6
6
  "keywords": [
@@ -70,7 +70,7 @@
70
70
  "access": "public"
71
71
  },
72
72
  "dependencies": {
73
- "@times-design-system/theme-scss": "^2.8.0",
73
+ "@times-design-system/theme-scss": "^2.10.2-alpha.0+91f353d4",
74
74
  "@wordpress/block-editor": "^12.0.0",
75
75
  "@wordpress/blocks": "^12.0.0",
76
76
  "@wordpress/components": "^25.0.0",
@@ -88,7 +88,7 @@
88
88
  "@testing-library/jest-dom": "^6.1.5",
89
89
  "@testing-library/react": "^14.1.2",
90
90
  "@testing-library/user-event": "^14.5.1",
91
- "@times-design-system/icons": "^1.2.0",
91
+ "@times-design-system/icons": "^1.2.2-alpha.0+91f353d4",
92
92
  "@types/react": "19.2.5",
93
93
  "@vitest/ui": "^1.0.4",
94
94
  "jsdom": "^23.0.0",
@@ -101,5 +101,5 @@
101
101
  "typescript": "^5.0.0",
102
102
  "vitest": "^1.0.4"
103
103
  },
104
- "gitHead": "f9727178862bd195ed3d45505e1f4be0b61df26e"
104
+ "gitHead": "91f353d41d06d1066d2345a933d6e9b58ae54a1d"
105
105
  }
package/plugin.php CHANGED
@@ -40,6 +40,7 @@ function tds_register_block_styles() {
40
40
  'icon-button' => 'tds-icon-button-style',
41
41
  'input' => 'tds-input-style',
42
42
  'input-helper-message' => 'tds-input-helper-message-style',
43
+ 'label' => 'tds-label-style',
43
44
  'link' => 'tds-link-style',
44
45
  'tab' => 'tds-tab-style',
45
46
  'tab-group' => 'tds-tab-group-style',
@@ -1,106 +0,0 @@
1
- <?php
2
- /**
3
- * Icon Rendering Utility
4
- *
5
- * Renders icon SVG markup from icon names.
6
- *
7
- * @package TimesDesignSystem\ComponentsWordPress
8
- */
9
-
10
- if (!function_exists('tds_resolve_icon_size')) {
11
- /**
12
- * Size map matching React Icon component
13
- * Maps named sizes to pixel dimensions
14
- */
15
- $icon_size_map = [
16
- '2xsmall' => ['width' => 12, 'height' => 12],
17
- 'xsmall' => ['width' => 16, 'height' => 16],
18
- 'small' => ['width' => 20, 'height' => 20],
19
- 'medium' => ['width' => 24, 'height' => 24],
20
- 'large' => ['width' => 28, 'height' => 28],
21
- 'xlarge' => ['width' => 32, 'height' => 32],
22
- '2xlarge' => ['width' => 40, 'height' => 40],
23
- ];
24
-
25
- /**
26
- * Resolve size to width and height dimensions
27
- *
28
- * @param mixed $size Named size string ('small', 'medium', etc) or numeric pixel value
29
- * @return array Array with 'width' and 'height' keys
30
- */
31
- function tds_resolve_icon_size($size) {
32
- $size_map = [
33
- '2xsmall' => ['width' => 12, 'height' => 12],
34
- 'xsmall' => ['width' => 16, 'height' => 16],
35
- 'small' => ['width' => 20, 'height' => 20],
36
- 'medium' => ['width' => 24, 'height' => 24],
37
- 'large' => ['width' => 28, 'height' => 28],
38
- 'xlarge' => ['width' => 32, 'height' => 32],
39
- '2xlarge' => ['width' => 40, 'height' => 40],
40
- ];
41
-
42
- if (is_numeric($size)) {
43
- // Numeric size: return as both width and height
44
- $pixels = (int) $size;
45
- return ['width' => $pixels, 'height' => $pixels];
46
- }
47
-
48
- // Named size: look up in size map
49
- if (isset($size_map[$size])) {
50
- return $size_map[$size];
51
- }
52
-
53
- // Default to medium if unrecognized
54
- return $size_map['medium'];
55
- }
56
- }
57
-
58
- if (!function_exists('tds_render_icon')) {
59
- /**
60
- * Render an icon by name with size and variant support
61
- *
62
- * @param string $icon Icon identifier (e.g., 'filled_search', 'outline_close')
63
- * @param mixed $size Icon size: named string ('small', 'medium', 'large') or numeric pixels
64
- * @return string SVG markup for the icon
65
- */
66
- function tds_render_icon($icon, $size = 'medium') {
67
- if (!$icon) {
68
- return '';
69
- }
70
-
71
- // Sanitize icon name
72
- $icon = sanitize_text_field($icon);
73
-
74
- // Resolve size to dimensions
75
- $dimensions = tds_resolve_icon_size($size);
76
- $width = $dimensions['width'];
77
- $height = $dimensions['height'];
78
-
79
- // Build SVG class list
80
- $classes = ['tds-icon'];
81
- // Add size class if it's a named size
82
- $size_map = [
83
- '2xsmall' => true,
84
- 'xsmall' => true,
85
- 'small' => true,
86
- 'medium' => true,
87
- 'large' => true,
88
- 'xlarge' => true,
89
- '2xlarge' => true,
90
- ];
91
- if (is_string($size) && isset($size_map[$size])) {
92
- $classes[] = 'tds-icon--' . sanitize_text_field($size);
93
- }
94
-
95
- // Return SVG with width/height attributes
96
- // In production, this would use an actual icon library
97
- // For static preview purposes, return a simple SVG placeholder
98
- return sprintf(
99
- '<svg class="%s" width="%d" height="%d" aria-hidden="true"><use href="#icon-%s"></use></svg>',
100
- esc_attr(implode(' ', $classes)),
101
- (int) $width,
102
- (int) $height,
103
- esc_attr($icon)
104
- );
105
- }
106
- }
@@ -1,37 +0,0 @@
1
- <?php
2
- /**
3
- * Data Attributes Sanitization Utility
4
- *
5
- * Sanitizes and prepares data-* attributes for blocks.
6
- *
7
- * @package TimesDesignSystem\ComponentsWordPress
8
- */
9
-
10
- if (!function_exists('tds_sanitize_data_attributes')) {
11
- /**
12
- * Sanitize data-* attributes for a block
13
- *
14
- * @param array $attributes Data attributes to sanitize
15
- * @param string $block_name Name of the block
16
- * @param array $full_attributes Full block attributes array
17
- * @return array Sanitized data attributes
18
- */
19
- function tds_sanitize_data_attributes($attributes = [], $block_name = '', $full_attributes = []) {
20
- if (!is_array($attributes)) {
21
- return [];
22
- }
23
-
24
- $sanitized = [];
25
- foreach ($attributes as $key => $value) {
26
- // Sanitize the key and value
27
- $safe_key = 'data-' . sanitize_html_class($key);
28
- $safe_value = sanitize_text_field($value);
29
-
30
- if ($safe_key && $safe_value) {
31
- $sanitized[$safe_key] = $safe_value;
32
- }
33
- }
34
-
35
- return $sanitized;
36
- }
37
- }