@times-design-system/components-wordpress 1.2.1 → 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.
- package/BLOCK_CREATION_CHECKLIST.md +39 -16
- package/README.md +4 -4
- package/TRANSFORMATION_GUIDE.md +3 -3
- package/block.json +1 -1
- package/dist/block.json +1 -1
- package/dist/blocks/ad-container/block.json +2 -1
- package/dist/blocks/ad-container/render.php +27 -0
- package/dist/blocks/button/block.json +2 -1
- package/dist/blocks/button/render.php +71 -0
- package/dist/blocks/chip/block.json +2 -1
- package/dist/blocks/chip/render.php +40 -0
- package/dist/blocks/divider/block.json +2 -1
- package/dist/blocks/divider/render.php +31 -0
- package/dist/blocks/flag/block.json +2 -1
- package/dist/blocks/flag/render.php +34 -0
- package/dist/blocks/icon-button/block.json +2 -1
- package/dist/blocks/icon-button/render.php +46 -0
- package/dist/blocks/input/block.json +2 -1
- package/dist/blocks/input/render.php +39 -0
- package/dist/blocks/link/block.json +2 -1
- package/dist/blocks/link/render.php +44 -0
- package/dist/blocks/text/block.json +2 -1
- package/dist/blocks/text/render.php +26 -0
- package/dist/blocks/toast/block.json +2 -1
- package/dist/blocks/toast/render.php +37 -0
- package/dist/index.cjs +30 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/scripts/create-block.sh +1 -1
- package/src/blocks/ad-container/block.json +2 -1
- package/src/blocks/ad-container/render.php +27 -0
- package/src/blocks/button/block.json +2 -1
- package/src/blocks/button/render.php +71 -0
- package/src/blocks/chip/block.json +2 -1
- package/src/blocks/chip/render.php +40 -0
- package/src/blocks/divider/block.json +2 -1
- package/src/blocks/divider/render.php +31 -0
- package/src/blocks/flag/block.json +2 -1
- package/src/blocks/flag/render.php +34 -0
- package/src/blocks/icon-button/block.json +2 -1
- package/src/blocks/icon-button/render.php +46 -0
- package/src/blocks/input/block.json +2 -1
- package/src/blocks/input/render.php +39 -0
- package/src/blocks/link/block.json +2 -1
- package/src/blocks/link/render.php +44 -0
- package/src/blocks/text/block.json +2 -1
- package/src/blocks/text/render.php +26 -0
- package/src/blocks/toast/block.json +2 -1
- package/src/blocks/toast/render.php +37 -0
|
@@ -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>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
3
|
"apiVersion": 3,
|
|
4
|
-
"name": "
|
|
4
|
+
"name": "tds/chip",
|
|
5
5
|
"title": "Chip",
|
|
6
6
|
"category": "common",
|
|
7
7
|
"description": "Small component for displaying labels, tags, or filter options",
|
|
@@ -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>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
3
|
"apiVersion": 3,
|
|
4
|
-
"name": "
|
|
4
|
+
"name": "tds/divider",
|
|
5
5
|
"title": "Divider",
|
|
6
6
|
"category": "common",
|
|
7
7
|
"description": "A horizontal line divider component",
|
|
@@ -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>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
3
|
"apiVersion": 3,
|
|
4
|
-
"name": "
|
|
4
|
+
"name": "tds/flag",
|
|
5
5
|
"title": "Flag",
|
|
6
6
|
"category": "common",
|
|
7
7
|
"description": "Badge or status indicator component",
|
|
@@ -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>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
3
|
"apiVersion": 3,
|
|
4
|
-
"name": "
|
|
4
|
+
"name": "tds/icon-button",
|
|
5
5
|
"title": "Icon Button",
|
|
6
6
|
"category": "common",
|
|
7
7
|
"description": "Button component displaying only an icon",
|
|
@@ -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; ?>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
3
|
"apiVersion": 3,
|
|
4
|
-
"name": "
|
|
4
|
+
"name": "tds/input",
|
|
5
5
|
"title": "Input",
|
|
6
6
|
"category": "common",
|
|
7
7
|
"description": "Form input field component",
|
|
@@ -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>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
3
|
"apiVersion": 3,
|
|
4
|
-
"name": "
|
|
4
|
+
"name": "tds/link",
|
|
5
5
|
"title": "Link",
|
|
6
6
|
"category": "common",
|
|
7
7
|
"description": "Styled link component with variants and states",
|
|
@@ -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>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
3
|
"apiVersion": 3,
|
|
4
|
-
"name": "
|
|
4
|
+
"name": "tds/text",
|
|
5
5
|
"title": "Text",
|
|
6
6
|
"category": "common",
|
|
7
7
|
"description": "Typography component for displaying text with style variants",
|
|
@@ -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); ?>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
3
|
"apiVersion": 3,
|
|
4
|
-
"name": "
|
|
4
|
+
"name": "tds/toast",
|
|
5
5
|
"title": "Toast",
|
|
6
6
|
"category": "common",
|
|
7
7
|
"description": "Notification toast component",
|
|
@@ -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>
|