@times-design-system/components-wordpress 1.2.2-alpha.0 → 1.2.2-alpha.1

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 (46) hide show
  1. package/BLOCK_CREATION_CHECKLIST.md +37 -14
  2. package/dist/blocks/ad-container/block.json +1 -0
  3. package/dist/blocks/ad-container/render.php +27 -0
  4. package/dist/blocks/button/block.json +1 -0
  5. package/dist/blocks/button/render.php +71 -0
  6. package/dist/blocks/chip/block.json +1 -0
  7. package/dist/blocks/chip/render.php +40 -0
  8. package/dist/blocks/divider/block.json +1 -0
  9. package/dist/blocks/divider/render.php +31 -0
  10. package/dist/blocks/flag/block.json +1 -0
  11. package/dist/blocks/flag/render.php +34 -0
  12. package/dist/blocks/icon-button/block.json +1 -0
  13. package/dist/blocks/icon-button/render.php +46 -0
  14. package/dist/blocks/input/block.json +1 -0
  15. package/dist/blocks/input/render.php +39 -0
  16. package/dist/blocks/link/block.json +1 -0
  17. package/dist/blocks/link/render.php +44 -0
  18. package/dist/blocks/text/block.json +1 -0
  19. package/dist/blocks/text/render.php +26 -0
  20. package/dist/blocks/toast/block.json +1 -0
  21. package/dist/blocks/toast/render.php +37 -0
  22. package/dist/index.cjs +20 -0
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.js +20 -0
  25. package/dist/index.js.map +1 -1
  26. package/package.json +3 -3
  27. package/src/blocks/ad-container/block.json +1 -0
  28. package/src/blocks/ad-container/render.php +27 -0
  29. package/src/blocks/button/block.json +1 -0
  30. package/src/blocks/button/render.php +71 -0
  31. package/src/blocks/chip/block.json +1 -0
  32. package/src/blocks/chip/render.php +40 -0
  33. package/src/blocks/divider/block.json +1 -0
  34. package/src/blocks/divider/render.php +31 -0
  35. package/src/blocks/flag/block.json +1 -0
  36. package/src/blocks/flag/render.php +34 -0
  37. package/src/blocks/icon-button/block.json +1 -0
  38. package/src/blocks/icon-button/render.php +46 -0
  39. package/src/blocks/input/block.json +1 -0
  40. package/src/blocks/input/render.php +39 -0
  41. package/src/blocks/link/block.json +1 -0
  42. package/src/blocks/link/render.php +44 -0
  43. package/src/blocks/text/block.json +1 -0
  44. package/src/blocks/text/render.php +26 -0
  45. package/src/blocks/toast/block.json +1 -0
  46. package/src/blocks/toast/render.php +37 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@times-design-system/components-wordpress",
3
- "version": "1.2.2-alpha.0+21580795",
3
+ "version": "1.2.2-alpha.1+9cbea6d2",
4
4
  "type": "module",
5
5
  "description": "Times Design System Gutenberg blocks for WordPress Full Site Editing",
6
6
  "keywords": [
@@ -48,7 +48,7 @@
48
48
  "access": "public"
49
49
  },
50
50
  "dependencies": {
51
- "@times-design-system/theme-scss": "^2.0.2-alpha.0+21580795",
51
+ "@times-design-system/theme-scss": "^2.0.2-alpha.1+9cbea6d2",
52
52
  "@wordpress/block-editor": "^12.0.0",
53
53
  "@wordpress/blocks": "^12.0.0",
54
54
  "@wordpress/components": "^25.0.0",
@@ -71,5 +71,5 @@
71
71
  "rollup-plugin-postcss": "^4.0.2",
72
72
  "typescript": "^5.0.0"
73
73
  },
74
- "gitHead": "21580795555c759c56388a9aadd9d21562a9a0d6"
74
+ "gitHead": "9cbea6d2ce4e4370d1894cdad4f4603ff65d8dda"
75
75
  }
@@ -13,6 +13,7 @@
13
13
  "padding": true
14
14
  }
15
15
  },
16
+ "render": "file:./render.php",
16
17
  "attributes": {
17
18
  "type": {
18
19
  "type": "string",
@@ -0,0 +1,27 @@
1
+ <?php
2
+ /**
3
+ * Ad Container Block Render Callback
4
+ *
5
+ * Renders the Ad Container block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $type = isset($attributes['type']) ? sanitize_text_field($attributes['type']) : '';
14
+ $slot_id = isset($attributes['slotID']) ? sanitize_text_field($attributes['slotID']) : '';
15
+
16
+ $class_name = 'tds-ad-container';
17
+ if ($type) {
18
+ $class_name .= ' tds-ad-container--' . sanitize_html_class($type);
19
+ }
20
+
21
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => $class_name]);
22
+ ?>
23
+
24
+ <div
25
+ <?php echo wp_kses_post($wrapper_attrs); ?>
26
+ <?php echo $slot_id ? 'data-slot-id="' . esc_attr($slot_id) . '"' : ''; ?>
27
+ ></div>
@@ -16,6 +16,7 @@
16
16
  "customClassName": true
17
17
  },
18
18
  "textdomain": "times-design-system",
19
+ "render": "file:./render.php",
19
20
  "attributes": {
20
21
  "label": {
21
22
  "type": "string",
@@ -0,0 +1,71 @@
1
+ <?php
2
+ /**
3
+ * Button Block Render Callback
4
+ *
5
+ * Renders the Button block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $label = isset($attributes['label']) ? sanitize_text_field($attributes['label']) : 'Button label';
14
+ $intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : 'primary';
15
+ $size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : 'large';
16
+ $behaviour = isset($attributes['behaviour']) ? sanitize_text_field($attributes['behaviour']) : 'hug';
17
+ $state = isset($attributes['state']) ? sanitize_text_field($attributes['state']) : 'base';
18
+ $disabled = isset($attributes['disabled']) ? (bool) $attributes['disabled'] : false;
19
+ $href = isset($attributes['href']) ? esc_url($attributes['href']) : '';
20
+ $target = isset($attributes['target']) ? sanitize_text_field($attributes['target']) : '';
21
+ $rel = isset($attributes['rel']) ? sanitize_text_field($attributes['rel']) : '';
22
+ $type = isset($attributes['type']) ? sanitize_text_field($attributes['type']) : 'button';
23
+ $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
24
+
25
+ // Build button classes
26
+ $classes = ['tds-button'];
27
+ $classes[] = 'tds-button--intent-' . $intent;
28
+ $classes[] = 'tds-button--size-' . $size;
29
+ $classes[] = 'tds-button--behaviour-' . $behaviour;
30
+ $classes[] = 'tds-button--state-' . $state;
31
+ if ($disabled) {
32
+ $classes[] = 'tds-button--disabled';
33
+ }
34
+
35
+ $button_class = implode(' ', $classes);
36
+ $element_tag = $href ? 'a' : 'button';
37
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => 'tds-button-wrapper']);
38
+ ?>
39
+
40
+ <div <?php echo wp_kses_post($wrapper_attrs); ?>>
41
+ <?php
42
+ if ($element_tag === 'a') {
43
+ ?>
44
+ <a
45
+ class="<?php echo esc_attr($button_class); ?>"
46
+ href="<?php echo esc_attr($href); ?>"
47
+ <?php echo $target ? 'target="' . esc_attr($target) . '"' : ''; ?>
48
+ <?php echo $rel ? 'rel="' . esc_attr($rel) . '"' : ''; ?>
49
+ <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
50
+ >
51
+ <span class="tds-button__label-container">
52
+ <span class="tds-button__label"><?php echo wp_kses_post($label); ?></span>
53
+ </span>
54
+ </a>
55
+ <?php
56
+ } else {
57
+ ?>
58
+ <button
59
+ class="<?php echo esc_attr($button_class); ?>"
60
+ <?php echo $disabled ? 'disabled' : ''; ?>
61
+ type="<?php echo esc_attr($type); ?>"
62
+ <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
63
+ >
64
+ <span class="tds-button__label-container">
65
+ <span class="tds-button__label"><?php echo wp_kses_post($label); ?></span>
66
+ </span>
67
+ </button>
68
+ <?php
69
+ }
70
+ ?>
71
+ </div>
@@ -12,6 +12,7 @@
12
12
  "margin": true
13
13
  }
14
14
  },
15
+ "render": "file:./render.php",
15
16
  "attributes": {
16
17
  "content": {
17
18
  "type": "string",
@@ -0,0 +1,40 @@
1
+ <?php
2
+ /**
3
+ * Chip Block Render Callback
4
+ *
5
+ * Renders the Chip block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
14
+ $intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : '';
15
+ $size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : '';
16
+ $state = isset($attributes['state']) ? sanitize_text_field($attributes['state']) : '';
17
+ $channel = isset($attributes['channel']) ? (bool) $attributes['channel'] : false;
18
+ $toggle = isset($attributes['toggle']) ? (bool) $attributes['toggle'] : false;
19
+ $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
20
+
21
+ $classes = ['tds-chip'];
22
+ $classes[] = 'tds-chip--intent-' . $intent;
23
+ $classes[] = 'tds-chip--size-' . $size;
24
+ $classes[] = 'tds-chip--state-' . $state;
25
+ if ($channel) {
26
+ $classes[] = 'tds-chip--channel';
27
+ }
28
+ if ($toggle) {
29
+ $classes[] = 'tds-chip--toggle';
30
+ }
31
+
32
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
33
+ ?>
34
+
35
+ <button
36
+ <?php echo wp_kses_post($wrapper_attrs); ?>
37
+ <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
38
+ >
39
+ <span class="tds-chip__content"><?php echo wp_kses_post($content_text); ?></span>
40
+ </button>
@@ -13,6 +13,7 @@
13
13
  },
14
14
  "align": ["wide", "full"]
15
15
  },
16
+ "render": "file:./render.php",
16
17
  "attributes": {
17
18
  "isDashed": {
18
19
  "type": "boolean",
@@ -0,0 +1,31 @@
1
+ <?php
2
+ /**
3
+ * Divider Block Render Callback
4
+ *
5
+ * Renders the Divider block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $is_dashed = isset($attributes['isDashed']) ? (bool) $attributes['isDashed'] : false;
14
+ $is_vertical = isset($attributes['isVertical']) ? (bool) $attributes['isVertical'] : false;
15
+ $padding = isset($attributes['padding']) ? (bool) $attributes['padding'] : false;
16
+
17
+ $classes = ['tds-divider'];
18
+ if ($is_dashed) {
19
+ $classes[] = 'tds-divider--dashed';
20
+ }
21
+ if ($is_vertical) {
22
+ $classes[] = 'tds-divider--vertical';
23
+ }
24
+ if ($padding) {
25
+ $classes[] = 'tds-divider--padding';
26
+ }
27
+
28
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
29
+ ?>
30
+
31
+ <div <?php echo wp_kses_post($wrapper_attrs); ?>></div>
@@ -12,6 +12,7 @@
12
12
  "margin": true
13
13
  }
14
14
  },
15
+ "render": "file:./render.php",
15
16
  "attributes": {
16
17
  "label": {
17
18
  "type": "string",
@@ -0,0 +1,34 @@
1
+ <?php
2
+ /**
3
+ * Flag Block Render Callback
4
+ *
5
+ * Renders the Flag block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $label = isset($attributes['label']) ? sanitize_text_field($attributes['label']) : '';
14
+ $content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
15
+ $intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : '';
16
+ $size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : '';
17
+ $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
18
+
19
+ $classes = ['tds-flag'];
20
+ $classes[] = 'tds-flag--intent-' . $intent;
21
+ $classes[] = 'tds-flag--size-' . $size;
22
+
23
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
24
+ ?>
25
+
26
+ <div
27
+ <?php echo wp_kses_post($wrapper_attrs); ?>
28
+ <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
29
+ >
30
+ <?php if ($label) : ?>
31
+ <div class="tds-flag__label"><?php echo wp_kses_post($label); ?></div>
32
+ <?php endif; ?>
33
+ <div class="tds-flag__content"><?php echo wp_kses_post($content_text); ?></div>
34
+ </div>
@@ -12,6 +12,7 @@
12
12
  "margin": true
13
13
  }
14
14
  },
15
+ "render": "file:./render.php",
15
16
  "attributes": {
16
17
  "iconName": {
17
18
  "type": "string",
@@ -0,0 +1,46 @@
1
+ <?php
2
+ /**
3
+ * Icon Button Block Render Callback
4
+ *
5
+ * Renders the Icon Button block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $icon_name = isset($attributes['iconName']) ? sanitize_text_field($attributes['iconName']) : '';
14
+ $round = isset($attributes['round']) ? (bool) $attributes['round'] : false;
15
+ $href = isset($attributes['href']) ? esc_url($attributes['href']) : '';
16
+ $target = isset($attributes['target']) ? sanitize_text_field($attributes['target']) : '';
17
+ $rel = isset($attributes['rel']) ? sanitize_text_field($attributes['rel']) : '';
18
+ $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
19
+
20
+ $classes = ['tds-icon-button'];
21
+ if ($round) {
22
+ $classes[] = 'tds-icon-button--round';
23
+ }
24
+
25
+ $element_tag = $href ? 'a' : 'button';
26
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
27
+ ?>
28
+
29
+ <?php if ($element_tag === 'a') : ?>
30
+ <a
31
+ <?php echo wp_kses_post($wrapper_attrs); ?>
32
+ href="<?php echo esc_attr($href); ?>"
33
+ <?php echo $target ? 'target="' . esc_attr($target) . '"' : ''; ?>
34
+ <?php echo $rel ? 'rel="' . esc_attr($rel) . '"' : ''; ?>
35
+ <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
36
+ >
37
+ <span class="tds-icon-button__icon"><?php echo wp_kses_post($icon_name); ?></span>
38
+ </a>
39
+ <?php else : ?>
40
+ <button
41
+ <?php echo wp_kses_post($wrapper_attrs); ?>
42
+ <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
43
+ >
44
+ <span class="tds-icon-button__icon"><?php echo wp_kses_post($icon_name); ?></span>
45
+ </button>
46
+ <?php endif; ?>
@@ -12,6 +12,7 @@
12
12
  "margin": true
13
13
  }
14
14
  },
15
+ "render": "file:./render.php",
15
16
  "attributes": {
16
17
  "label": {
17
18
  "type": "string",
@@ -0,0 +1,39 @@
1
+ <?php
2
+ /**
3
+ * Input Block Render Callback
4
+ *
5
+ * Renders the Input block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $label = isset($attributes['label']) ? sanitize_text_field($attributes['label']) : '';
14
+ $placeholder = isset($attributes['placeholder']) ? sanitize_text_field($attributes['placeholder']) : '';
15
+ $type = isset($attributes['type']) ? sanitize_text_field($attributes['type']) : 'text';
16
+ $disabled = isset($attributes['disabled']) ? (bool) $attributes['disabled'] : false;
17
+ $required = isset($attributes['required']) ? (bool) $attributes['required'] : false;
18
+ $name = isset($attributes['name']) ? sanitize_text_field($attributes['name']) : '';
19
+ $id = isset($attributes['id']) ? sanitize_text_field($attributes['id']) : '';
20
+
21
+ $wrapper_attrs = get_block_wrapper_attributes();
22
+ ?>
23
+
24
+ <div <?php echo wp_kses_post($wrapper_attrs); ?>>
25
+ <?php if ($label) : ?>
26
+ <label for="<?php echo esc_attr($id); ?>" class="tds-input__label">
27
+ <?php echo wp_kses_post($label); ?>
28
+ </label>
29
+ <?php endif; ?>
30
+ <input
31
+ type="<?php echo esc_attr($type); ?>"
32
+ <?php echo $placeholder ? 'placeholder="' . esc_attr($placeholder) . '"' : ''; ?>
33
+ <?php echo $disabled ? 'disabled' : ''; ?>
34
+ <?php echo $required ? 'required' : ''; ?>
35
+ <?php echo $name ? 'name="' . esc_attr($name) . '"' : ''; ?>
36
+ <?php echo $id ? 'id="' . esc_attr($id) . '"' : ''; ?>
37
+ class="tds-input"
38
+ />
39
+ </div>
@@ -12,6 +12,7 @@
12
12
  "margin": true
13
13
  }
14
14
  },
15
+ "render": "file:./render.php",
15
16
  "attributes": {
16
17
  "href": {
17
18
  "type": "string",
@@ -0,0 +1,44 @@
1
+ <?php
2
+ /**
3
+ * Link Block Render Callback
4
+ *
5
+ * Renders the Link block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $href = isset($attributes['href']) ? esc_url($attributes['href']) : '';
14
+ $content_text = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
15
+ $intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : '';
16
+ $sentiment = isset($attributes['sentiment']) ? sanitize_text_field($attributes['sentiment']) : '';
17
+ $size = isset($attributes['size']) ? sanitize_text_field($attributes['size']) : '';
18
+ $state = isset($attributes['state']) ? sanitize_text_field($attributes['state']) : '';
19
+ $inline = isset($attributes['inline']) ? (bool) $attributes['inline'] : true;
20
+ $aria_label = isset($attributes['ariaLabel']) ? sanitize_text_field($attributes['ariaLabel']) : '';
21
+ $target = isset($attributes['target']) ? sanitize_text_field($attributes['target']) : '_self';
22
+ $rel = isset($attributes['rel']) ? sanitize_text_field($attributes['rel']) : '';
23
+
24
+ $classes = ['tds-link'];
25
+ $classes[] = 'tds-link--intent-' . $intent;
26
+ $classes[] = 'tds-link--sentiment-' . $sentiment;
27
+ $classes[] = 'tds-link--size-' . $size;
28
+ $classes[] = 'tds-link--state-' . $state;
29
+ if (!$inline) {
30
+ $classes[] = 'tds-link--block';
31
+ }
32
+
33
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
34
+ ?>
35
+
36
+ <a
37
+ <?php echo wp_kses_post($wrapper_attrs); ?>
38
+ href="<?php echo esc_attr($href); ?>"
39
+ <?php echo $aria_label ? 'aria-label="' . esc_attr($aria_label) . '"' : ''; ?>
40
+ <?php echo ($target !== '_self') ? 'target="' . esc_attr($target) . '"' : ''; ?>
41
+ <?php echo $rel ? 'rel="' . esc_attr($rel) . '"' : ''; ?>
42
+ >
43
+ <span class="tds-link__content"><?php echo wp_kses_post($content_text); ?></span>
44
+ </a>
@@ -13,6 +13,7 @@
13
13
  "padding": false
14
14
  }
15
15
  },
16
+ "render": "file:./render.php",
16
17
  "attributes": {
17
18
  "as": {
18
19
  "type": "string",
@@ -0,0 +1,26 @@
1
+ <?php
2
+ /**
3
+ * Text Block Render Callback
4
+ *
5
+ * Renders the Text typography block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $as = isset($attributes['as']) ? sanitize_text_field($attributes['as']) : 'p';
14
+ $typography_style = isset($attributes['typographyStyle']) ? sanitize_text_field($attributes['typographyStyle']) : '';
15
+ $text_content = isset($attributes['content']) ? wp_kses_post($attributes['content']) : '';
16
+
17
+ $tag_name = in_array($as, ['p', 'span', 'h1', 'h2', 'h3', 'h4', 'h5'], true) ? $as : 'p';
18
+ $class_name = 'tds-text';
19
+ if ($typography_style) {
20
+ $class_name .= ' tds-text--' . sanitize_html_class($typography_style);
21
+ }
22
+
23
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => $class_name]);
24
+ ?>
25
+
26
+ <?php echo wp_sprintf('<%s %s>%s</%s>', $tag_name, wp_kses_post($wrapper_attrs), wp_kses_post($text_content), $tag_name); ?>
@@ -12,6 +12,7 @@
12
12
  "margin": true
13
13
  }
14
14
  },
15
+ "render": "file:./render.php",
15
16
  "attributes": {
16
17
  "label": {
17
18
  "type": "string",
@@ -0,0 +1,37 @@
1
+ <?php
2
+ /**
3
+ * Toast Block Render Callback
4
+ *
5
+ * Renders the Toast notification block on the frontend.
6
+ *
7
+ * @package TimesDesignSystem\ComponentsWordPress
8
+ * @var array $attributes Block attributes
9
+ * @var string $content Block content
10
+ * @var WP_Block $block Block instance
11
+ */
12
+
13
+ $label = isset($attributes['label']) ? wp_kses_post($attributes['label']) : '';
14
+ $intent = isset($attributes['intent']) ? sanitize_text_field($attributes['intent']) : '';
15
+ $link = isset($attributes['link']) ? esc_url($attributes['link']) : '';
16
+ $link_label = isset($attributes['linkLabel']) ? sanitize_text_field($attributes['linkLabel']) : '';
17
+ $timeout = isset($attributes['timeout']) ? intval($attributes['timeout']) : 0;
18
+
19
+ $classes = ['tds-toast'];
20
+ $classes[] = 'tds-toast--intent-' . $intent;
21
+
22
+ $wrapper_attrs = get_block_wrapper_attributes(['class' => implode(' ', $classes)]);
23
+ ?>
24
+
25
+ <div
26
+ <?php echo wp_kses_post($wrapper_attrs); ?>
27
+ role="status"
28
+ aria-live="polite"
29
+ <?php echo $timeout ? 'data-timeout="' . esc_attr($timeout) . '"' : ''; ?>
30
+ >
31
+ <div class="tds-toast__content">
32
+ <div class="tds-toast__label"><?php echo wp_kses_post($label); ?></div>
33
+ </div>
34
+ <?php if ($link && $link_label) : ?>
35
+ <a href="<?php echo esc_attr($link); ?>" class="tds-toast__link"><?php echo wp_kses_post($link_label); ?></a>
36
+ <?php endif; ?>
37
+ </div>