@times-design-system/components-wordpress 1.7.0 → 1.8.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.
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
14
+ require_once __DIR__ . '/../../utils/render-icon.php';
14
15
 
15
16
  $label = isset($attributes['label']) ? sanitize_text_field($attributes['label']) : 'Button label';
16
17
  $intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : 'primary';
@@ -25,6 +26,15 @@ $rel = isset($attributes['rel']) ? sanitize_text_field($attributes['rel']) : '';
25
26
  $type = isset($attributes['type']) ? sanitize_text_field($attributes['type']) : 'button';
26
27
  $icon_left = isset($attributes['iconLeft']) ? sanitize_text_field($attributes['iconLeft']) : '';
27
28
  $icon_right = isset($attributes['iconRight']) ? sanitize_text_field($attributes['iconRight']) : '';
29
+
30
+ // Derive icon size from button size
31
+ $icon_size_map = [
32
+ 'small' => 'small',
33
+ 'medium' => 'medium',
34
+ 'large' => 'large',
35
+ 'xlarge' => 'large'
36
+ ];
37
+ $icon_size = $icon_size_map[$size] ?? 'medium';
28
38
  $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
29
39
  $element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
30
40
 
@@ -73,11 +83,11 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => 'tds-button-wrapper'])
73
83
  >
74
84
  <span class="tds-button__label-container">
75
85
  <?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; ?>
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>
86
+ <span class="tds-button__icon tds-button__icon--left"><?php echo wp_kses_post(tds_render_icon($icon_left, $icon_size)); ?></span>
87
+ <?php endif; ?>
88
+ <span class="tds-button__label"><?php echo wp_kses_post($label); ?></span>
89
+ <?php if ($icon_right) : ?>
90
+ <span class="tds-button__icon tds-button__icon--right"><?php echo wp_kses_post(tds_render_icon($icon_right, $icon_size)); ?></span>
81
91
  <?php endif; ?>
82
92
  </span>
83
93
  </a>
@@ -93,11 +103,11 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => 'tds-button-wrapper'])
93
103
  >
94
104
  <span class="tds-button__label-container">
95
105
  <?php if ($icon_left) : ?>
96
- <span class="tds-button__icon tds-button__icon--left"><?php echo wp_kses_post($icon_left); ?></span>
106
+ <span class="tds-button__icon tds-button__icon--left"><?php echo wp_kses_post(tds_render_icon($icon_left, $icon_size)); ?></span>
97
107
  <?php endif; ?>
98
108
  <span class="tds-button__label"><?php echo wp_kses_post($label); ?></span>
99
109
  <?php if ($icon_right) : ?>
100
- <span class="tds-button__icon tds-button__icon--right"><?php echo wp_kses_post($icon_right); ?></span>
110
+ <span class="tds-button__icon tds-button__icon--right"><?php echo wp_kses_post(tds_render_icon($icon_right, $icon_size)); ?></span>
101
111
  <?php endif; ?>
102
112
  </span>
103
113
  </button>
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
14
+ require_once __DIR__ . '/../../utils/render-icon.php';
14
15
 
15
16
  $content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
16
17
  $intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : '';
@@ -19,6 +20,13 @@ $channel = isset($attributes['channel']) ? (bool) $attributes['channel'] : false
19
20
  $toggle = isset($attributes['toggle']) ? (bool) $attributes['toggle'] : false;
20
21
  $icon_left = isset($attributes['iconLeft']) ? sanitize_text_field($attributes['iconLeft']) : '';
21
22
  $icon_right = isset($attributes['iconRight']) ? sanitize_text_field($attributes['iconRight']) : '';
23
+
24
+ // Derive icon size from chip size
25
+ $icon_size_map = [
26
+ 'small' => 'xsmall',
27
+ 'large' => 'small'
28
+ ];
29
+ $icon_size = $icon_size_map[$size] ?? 'xsmall';
22
30
  $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
23
31
  $element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
24
32
 
@@ -52,11 +60,11 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)
52
60
  >
53
61
  <span class="tds-chip__content">
54
62
  <?php if ($icon_left) : ?>
55
- <span class="tds-chip__icon tds-chip__icon--left"><?php echo wp_kses_post($icon_left); ?></span>
63
+ <span class="tds-chip__icon tds-chip__icon--left"><?php echo wp_kses_post(tds_render_icon($icon_left, $icon_size)); ?></span>
56
64
  <?php endif; ?>
57
65
  <?php echo wp_kses_post($content_text); ?>
58
66
  <?php if ($icon_right) : ?>
59
- <span class="tds-chip__icon tds-chip__icon--right"><?php echo wp_kses_post($icon_right); ?></span>
67
+ <span class="tds-chip__icon tds-chip__icon--right"><?php echo wp_kses_post(tds_render_icon($icon_right, $icon_size)); ?></span>
60
68
  <?php endif; ?>
61
69
  </span>
62
70
  </button>
@@ -85,3 +85,24 @@
85
85
  align-items: center;
86
86
  justify-content: center;
87
87
  }
88
+
89
+ .tds-chip__icon {
90
+ display: inline-flex;
91
+ align-items: center;
92
+ justify-content: center;
93
+ }
94
+
95
+ .tds-chip--size-small .tds-chip__icon {
96
+ width: 16px;
97
+ height: 16px;
98
+ }
99
+
100
+ .tds-chip--size-large .tds-chip__icon {
101
+ width: 20px;
102
+ height: 20px;
103
+ }
104
+
105
+ .tds-chip__icon svg {
106
+ width: 100%;
107
+ height: 100%;
108
+ }
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
14
+ require_once __DIR__ . '/../../utils/render-icon.php';
14
15
 
15
16
  $label = isset($attributes['label']) ? sanitize_text_field($attributes['label']) : '';
16
17
  $content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
@@ -18,6 +19,14 @@ $intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent
18
19
  $size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : '';
19
20
  $icon_left = isset($attributes['iconLeft']) ? sanitize_text_field($attributes['iconLeft']) : '';
20
21
  $icon_right = isset($attributes['iconRight']) ? sanitize_text_field($attributes['iconRight']) : '';
22
+
23
+ // Derive icon size from flag size
24
+ $icon_size_map = [
25
+ 'small' => 'xsmall',
26
+ 'medium' => 'small',
27
+ 'large' => 'medium'
28
+ ];
29
+ $icon_size = $icon_size_map[$size] ?? 'small';
21
30
  $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
22
31
  $element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
23
32
 
@@ -46,11 +55,11 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)
46
55
  <?php if ($label) : ?>
47
56
  <div class="tds-flag__label">
48
57
  <?php if ($icon_left) : ?>
49
- <span class="tds-flag__icon tds-flag__icon--left"><?php echo wp_kses_post($icon_left); ?></span>
58
+ <span class="tds-flag__icon tds-flag__icon--left"><?php echo wp_kses_post(tds_render_icon($icon_left, $icon_size)); ?></span>
50
59
  <?php endif; ?>
51
60
  <?php echo wp_kses_post($label); ?>
52
61
  <?php if ($icon_right) : ?>
53
- <span class="tds-flag__icon tds-flag__icon--right"><?php echo wp_kses_post($icon_right); ?></span>
62
+ <span class="tds-flag__icon tds-flag__icon--right"><?php echo wp_kses_post(tds_render_icon($icon_right, $icon_size)); ?></span>
54
63
  <?php endif; ?>
55
64
  </div>
56
65
  <?php endif; ?>
@@ -52,3 +52,24 @@
52
52
  display: inline-flex;
53
53
  align-items: center;
54
54
  }
55
+
56
+ .tds-flag__icon {
57
+ display: inline-flex;
58
+ align-items: center;
59
+ justify-content: center;
60
+ }
61
+
62
+ .tds-flag--size-small .tds-flag__icon {
63
+ width: 16px;
64
+ height: 16px;
65
+ }
66
+
67
+ .tds-flag--size-large .tds-flag__icon {
68
+ width: 24px;
69
+ height: 24px;
70
+ }
71
+
72
+ .tds-flag__icon svg {
73
+ width: 100%;
74
+ height: 100%;
75
+ }
@@ -14,9 +14,24 @@
14
14
  },
15
15
  "textdomain": "times-blocks",
16
16
  "attributes": {
17
- "content": {
17
+ "iconName": {
18
18
  "type": "string",
19
- "default": ""
19
+ "default": "",
20
+ "description": "The name of the icon to display"
21
+ },
22
+ "size": {
23
+ "type": "string",
24
+ "enum": [
25
+ "2xsmall",
26
+ "xsmall",
27
+ "small",
28
+ "medium",
29
+ "large",
30
+ "xlarge",
31
+ "2xlarge"
32
+ ],
33
+ "default": "medium",
34
+ "description": "Size of the icon"
20
35
  },
21
36
  "classes": {
22
37
  "type": "string",
@@ -1,35 +1,50 @@
1
1
  <?php
2
2
  /**
3
- * Block Rendering: Icon
3
+ * Icon Block Render Callback
4
4
  *
5
- * Server-side rendering for the Icon block.
6
- * Reference: packages/components-react/src/Icon/
5
+ * Renders the Icon block with inline SVG content.
6
+ * Supports sizing parity with components-react Icon component.
7
7
  *
8
- * @param array $attributes Block attributes
9
- * @param string $content Saved block content
10
- * @param WP_Block $block The block instance
11
- * @return string Rendered HTML
8
+ * @package TimesDesignSystem\ComponentsWordPress
9
+ * @var array $attributes Block attributes
10
+ * @var string $content Block content
11
+ * @var WP_Block $block Block instance
12
12
  */
13
13
 
14
- require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
14
+ require_once __DIR__ . '/../../utils/render-icon.php';
15
15
 
16
- $content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
17
- $element_class_name = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
16
+ $icon_name = isset($attributes['iconName']) ? sanitize_text_field($attributes['iconName']) : '';
17
+ $size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : 'medium';
18
+ $classes = isset($attributes['classes']) ? sanitize_text_field($attributes['classes']) : '';
18
19
 
19
20
  // Sanitize and prepare data-* attributes
21
+ require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
20
22
  $sanitized_data_attributes = tds_sanitize_data_attributes($attributes['dataAttributes'] ?? [], 'icon', $attributes);
21
23
  $data_attrs_html = '';
22
24
  foreach ($sanitized_data_attributes as $attr_name => $attr_value) {
23
25
  $data_attrs_html .= ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '"';
24
26
  }
25
27
 
26
- $wrapper_classes = ['tds-icon'];
27
- if ($element_class_name) {
28
- $wrapper_classes[] = $element_class_name;
28
+ // Build wrapper classes
29
+ $wrapper_classes = ['tds-icon-wrapper'];
30
+ if ($classes) {
31
+ $wrapper_classes[] = $classes;
29
32
  }
30
- $wrapper_attributes = get_block_wrapper_attributes(['class' => implode(' ', $wrapper_classes)]);
33
+ $wrapper_class = implode(' ', $wrapper_classes);
34
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => $wrapper_class]);
31
35
 
36
+ // Render icon
37
+ $svg_content = tds_render_icon($icon_name, $size);
32
38
  ?>
33
- <span <?php echo wp_kses_post($wrapper_attributes); ?><?php echo wp_kses_post($data_attrs_html); ?>>
34
- <?php echo wp_kses_post($content_text); ?>
35
- </span>
39
+
40
+ <div <?php echo wp_kses_post($wrapper_attrs); ?><?php echo wp_kses_post($data_attrs_html); ?>>
41
+ <?php if ($svg_content) : ?>
42
+ <div class="tds-icon">
43
+ <?php echo wp_kses_post($svg_content); ?>
44
+ </div>
45
+ <?php else : ?>
46
+ <div class="tds-icon tds-icon--error">
47
+ <span class="tds-icon__placeholder"><?php esc_html_e('Icon not found', 'times-design-system'); ?></span>
48
+ </div>
49
+ <?php endif; ?>
50
+ </div>
@@ -18,6 +18,20 @@
18
18
  "type": "string",
19
19
  "default": ""
20
20
  },
21
+ "iconSize": {
22
+ "type": "string",
23
+ "enum": [
24
+ "2xsmall",
25
+ "xsmall",
26
+ "small",
27
+ "medium",
28
+ "large",
29
+ "xlarge",
30
+ "2xlarge"
31
+ ],
32
+ "default": "medium",
33
+ "description": "Size of the icon"
34
+ },
21
35
  "round": {
22
36
  "type": "boolean",
23
37
  "default": false
@@ -11,8 +11,10 @@
11
11
  */
12
12
 
13
13
  require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
14
+ require_once __DIR__ . '/../../utils/render-icon.php';
14
15
 
15
16
  $icon_name = isset($attributes['iconName']) ? sanitize_text_field($attributes['iconName']) : '';
17
+ $icon_size = isset($attributes['iconSize']) ? sanitize_text_field($attributes['iconSize']) : 'medium';
16
18
  $round = isset($attributes['round']) ? (bool) $attributes['round'] : false;
17
19
  $isLoading = isset($attributes['isLoading']) ? (bool) $attributes['isLoading'] : false;
18
20
  $href = isset($attributes['href']) ? esc_url($attributes['href']) : '';
@@ -52,7 +54,7 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)
52
54
  <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
53
55
  <?php echo wp_kses_post($data_attrs_html); ?>
54
56
  >
55
- <span class="tds-icon-button__icon"><?php echo wp_kses_post($icon_name); ?></span>
57
+ <span class="tds-icon-button__icon"><?php echo wp_kses_post(tds_render_icon($icon_name, $icon_size)); ?></span>
56
58
  </a>
57
59
  <?php else : ?>
58
60
  <button
@@ -60,6 +62,6 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)
60
62
  <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
61
63
  <?php echo wp_kses_post($data_attrs_html); ?>
62
64
  >
63
- <span class="tds-icon-button__icon"><?php echo wp_kses_post($icon_name); ?></span>
65
+ <span class="tds-icon-button__icon"><?php echo wp_kses_post(tds_render_icon($icon_name, $icon_size)); ?></span>
64
66
  </button>
65
67
  <?php endif; ?>
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  require_once __DIR__ . '/../../utils/sanitize-data-attributes.php';
14
+ require_once __DIR__ . '/../../utils/render-icon.php';
14
15
 
15
16
  $href = isset($attributes['href']) ? esc_url($attributes['href']) : '';
16
17
  $content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
@@ -19,6 +20,15 @@ $sentiment = isset($attributes['sentiment']) ? sanitize_text_field($attributes['
19
20
  $size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : '';
20
21
  $icon_left = isset($attributes['iconLeft']) ? sanitize_text_field($attributes['iconLeft']) : '';
21
22
  $icon_right = isset($attributes['iconRight']) ? sanitize_text_field($attributes['iconRight']) : '';
23
+
24
+ // Derive icon size from link size
25
+ $icon_size_map = [
26
+ 'xsmall' => 'xsmall',
27
+ 'small' => 'xsmall',
28
+ 'medium' => 'small',
29
+ 'large' => 'medium'
30
+ ];
31
+ $icon_size = $icon_size_map[$size] ?? 'small';
22
32
  $inline = isset($attributes['inline']) ? (bool) $attributes['inline'] : true;
23
33
  $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
24
34
  $target = isset($attributes['target']) ? sanitize_text_field($attributes['target']) : '_self';
@@ -56,11 +66,11 @@ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)
56
66
  >
57
67
  <span class="tds-link__content">
58
68
  <?php if ($icon_left) : ?>
59
- <span class="tds-link__icon tds-link__icon--left"><?php echo wp_kses_post($icon_left); ?></span>
69
+ <span class="tds-link__icon tds-link__icon--left"><?php echo wp_kses_post(tds_render_icon($icon_left, $icon_size)); ?></span>
60
70
  <?php endif; ?>
61
71
  <?php echo wp_kses_post($content_text); ?>
62
72
  <?php if ($icon_right) : ?>
63
- <span class="tds-link__icon tds-link__icon--right"><?php echo wp_kses_post($icon_right); ?></span>
73
+ <span class="tds-link__icon tds-link__icon--right"><?php echo wp_kses_post(tds_render_icon($icon_right, $icon_size)); ?></span>
64
74
  <?php endif; ?>
65
75
  </span>
66
76
  </a>