@studiometa/ui 0.2.48 → 0.2.50
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/atoms/Button/Button.twig
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @param string $href
|
|
9
9
|
* @param array $attr
|
|
10
10
|
* @param string $icon
|
|
11
|
+
* @param array $icon_attr
|
|
11
12
|
* @param array|string $icon_classes
|
|
12
13
|
* @param 'start'|'end' $icon_position
|
|
13
14
|
* @param boolean $icon_only
|
|
@@ -39,12 +40,21 @@
|
|
|
39
40
|
|
|
40
41
|
{% set rendered_icon %}
|
|
41
42
|
{% block icon %}
|
|
42
|
-
{
|
|
43
|
+
{# @TODO: Breaking change -> Delete icon_classes to use only icon_attr #}
|
|
44
|
+
{% include '@ui/atoms/Icon/IconInline.twig' with {
|
|
43
45
|
name: icon ?? '',
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
attr: merge_html_attributes(
|
|
47
|
+
icon_attr ?? null,
|
|
48
|
+
{
|
|
49
|
+
class: {
|
|
50
|
+
'mr-3': not icon_only and icon_position == 'start',
|
|
51
|
+
'ml-3': not icon_only and icon_position == 'end',
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
class: icon_classes,
|
|
56
|
+
},
|
|
57
|
+
)
|
|
48
58
|
} %}
|
|
49
59
|
{% endblock %}
|
|
50
60
|
{% endset %}
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* @file
|
|
4
4
|
* Icon component
|
|
5
5
|
*
|
|
6
|
-
* @param string
|
|
7
|
-
* @param
|
|
6
|
+
* @param string $name The file name of the icon.
|
|
7
|
+
* @param boolean $ignore_missing Avoid empty <span> printing
|
|
8
|
+
* @param array $attr Custom attributes.
|
|
8
9
|
*/
|
|
9
10
|
#}
|
|
10
11
|
|
|
@@ -21,6 +22,12 @@
|
|
|
21
22
|
}
|
|
22
23
|
) %}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
{%- set icon -%}
|
|
25
26
|
{{ source('@svg/%s.svg'|format(name), ignore_missing = true) }}
|
|
26
|
-
|
|
27
|
+
{%- endset -%}
|
|
28
|
+
|
|
29
|
+
{% if icon is not empty or not ignore_missing %}
|
|
30
|
+
<span {{ html_attributes(attributes) }}>
|
|
31
|
+
{{ icon }}
|
|
32
|
+
</span>
|
|
33
|
+
{% endif %}
|
|
@@ -4,54 +4,57 @@
|
|
|
4
4
|
* Icon Image component
|
|
5
5
|
* Use `<img>` instead of injecting the SVG file.
|
|
6
6
|
*
|
|
7
|
-
* @param string
|
|
8
|
-
* @param
|
|
9
|
-
* @param array
|
|
10
|
-
* @param
|
|
7
|
+
* @param string $name The file name of the icon.
|
|
8
|
+
* @param boolean $ignore_missing Avoid empty <img> printing
|
|
9
|
+
* @param array $attr Custom attributes.
|
|
10
|
+
* @param array $css_vars Custom CSS variables to pass to the SVG.
|
|
11
|
+
* @param string $current_color Custom color for the `currentColor` CSS variable in the SVG.
|
|
11
12
|
*/
|
|
12
13
|
#}
|
|
13
14
|
{%- set svg -%}
|
|
14
15
|
{{ source('@svg/%s.svg'|format(name), ignore_missing = true) }}
|
|
15
16
|
{%- endset -%}
|
|
16
17
|
|
|
17
|
-
{% if
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{%
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
{% if svg is not empty or not ignore_missing %}
|
|
19
|
+
{% if current_color is defined or css_vars is defined %}
|
|
20
|
+
{%- set style -%}
|
|
21
|
+
<style>
|
|
22
|
+
:root {
|
|
23
|
+
{% if current_color is defined %}
|
|
24
|
+
color: {{ current_color }};
|
|
25
|
+
{% endif %}
|
|
26
|
+
{% if css_vars is defined %}
|
|
27
|
+
{% for var, value in css_vars %}
|
|
28
|
+
--{{ var }}: {{ value }};
|
|
29
|
+
{% endfor %}
|
|
30
|
+
{% endif %}
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
33
|
+
{%- endset -%}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
{% endif %}
|
|
35
|
+
{% set svg = svg|replace({ '</svg>': '%s</svg>'|format(style) }) %}
|
|
36
|
+
{% endif %}
|
|
35
37
|
|
|
36
|
-
{% if not 'xmlns="http://www.w3.org/2000/svg"' in svg %}
|
|
37
|
-
|
|
38
|
-
{% endif %}
|
|
38
|
+
{% if not 'xmlns="http://www.w3.org/2000/svg"' in svg %}
|
|
39
|
+
{% set svg = svg|replace({ '<svg': '<svg %s'|format('xmlns="http://www.w3.org/2000/svg"') }) %}
|
|
40
|
+
{% endif %}
|
|
39
41
|
|
|
40
|
-
{% set attributes = merge_html_attributes(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
) %}
|
|
42
|
+
{% set attributes = merge_html_attributes(
|
|
43
|
+
attr ?? null,
|
|
44
|
+
{
|
|
45
|
+
width: '',
|
|
46
|
+
height: '',
|
|
47
|
+
alt: ' ',
|
|
48
|
+
aria_hidden: 'true'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
src: svg ? 'data:image/svg+xml,%s'|format(svg|url_encode) : '',
|
|
52
|
+
class: [
|
|
53
|
+
'icon-img',
|
|
54
|
+
'icon-img--%s'|format(name),
|
|
55
|
+
],
|
|
56
|
+
}
|
|
57
|
+
) %}
|
|
56
58
|
|
|
57
|
-
<img {{ html_attributes(attributes) }}>
|
|
59
|
+
<img {{ html_attributes(attributes) }}>
|
|
60
|
+
{% endif %}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{#
|
|
2
|
+
/**
|
|
3
|
+
* @file
|
|
4
|
+
* Icon list component.
|
|
5
|
+
*
|
|
6
|
+
* @param array $attr Shorthand of $list_attr.
|
|
7
|
+
* @param array $list_attr List attributes.
|
|
8
|
+
* @param array $item_attr List item attributes.
|
|
9
|
+
* @param array $icon_attr Icon attibutes.
|
|
10
|
+
* @param array $action_attr Action attributes.
|
|
11
|
+
* @param string $action_tag Action tag.
|
|
12
|
+
* @param array $items Items:
|
|
13
|
+
* - Use the icon name in key and the url in value for each entry of this array.
|
|
14
|
+
* - You can pass an array instead of the url to pass custom attributes to the action.
|
|
15
|
+
*
|
|
16
|
+
* @block $item
|
|
17
|
+
* Use this block to override the component behavior inside the list items.
|
|
18
|
+
* @block $icon
|
|
19
|
+
* Use this block to override the icons.
|
|
20
|
+
*/
|
|
21
|
+
#}
|
|
22
|
+
|
|
23
|
+
{% set list_attributes =
|
|
24
|
+
merge_html_attributes(
|
|
25
|
+
attr ?? list_attr ?? null,
|
|
26
|
+
{ class: ['flex justify-start items-center gap-3'] }
|
|
27
|
+
)
|
|
28
|
+
%}
|
|
29
|
+
|
|
30
|
+
{% set item_attributes = merge_html_attributes(item_attr ?? null, {}) %}
|
|
31
|
+
|
|
32
|
+
{% set icon_attributes = merge_html_attributes(icon_attr ?? null, { class: 'flex items-center' }) %}
|
|
33
|
+
|
|
34
|
+
<ul {{ html_attributes(list_attributes) }}>
|
|
35
|
+
{% for name, value in items %}
|
|
36
|
+
{%- set rendered_icon -%}
|
|
37
|
+
{%- block icon -%}
|
|
38
|
+
{%- include '@ui/atoms/Icon/IconInline.twig' with {
|
|
39
|
+
name: name,
|
|
40
|
+
attr: icon_attributes,
|
|
41
|
+
ignore_missing: true
|
|
42
|
+
} only -%}
|
|
43
|
+
{%- endblock -%}
|
|
44
|
+
{%- endset -%}
|
|
45
|
+
|
|
46
|
+
{% if rendered_icon is not empty %}
|
|
47
|
+
{% if value is iterable %}
|
|
48
|
+
{% set href = value.attr.href ?? value.href ?? null %}
|
|
49
|
+
{% set label = value.attr.label ?? value.label ?? (name|capitalize) %}
|
|
50
|
+
{% set title = value.attr.title ?? value.title %}
|
|
51
|
+
{% set tag = value.tag
|
|
52
|
+
?? (action_tag|default(href is defined and href is not null ? 'a' : 'button'))
|
|
53
|
+
%}
|
|
54
|
+
{% set current_attr = merge_html_attributes(value.attr ?? {}, action_attr) %}
|
|
55
|
+
{% else %}
|
|
56
|
+
{% set href = value %}
|
|
57
|
+
{% set label = name|capitalize %}
|
|
58
|
+
{% set tag = action_tag|default('a') %}
|
|
59
|
+
{% set current_attr = action_attr %}
|
|
60
|
+
{% endif %}
|
|
61
|
+
|
|
62
|
+
{% set action_attributes =
|
|
63
|
+
merge_html_attributes(
|
|
64
|
+
current_attr ?? null,
|
|
65
|
+
{
|
|
66
|
+
title: title ?? label,
|
|
67
|
+
aria_label: label,
|
|
68
|
+
class: 'block p-1 hover:opacity-80 cursor-pointer'
|
|
69
|
+
}|merge(tag == 'button' ? { type: 'button' } : { href: href })
|
|
70
|
+
)
|
|
71
|
+
%}
|
|
72
|
+
|
|
73
|
+
<li {{ html_attributes(item_attributes) }}>
|
|
74
|
+
{% block item %}
|
|
75
|
+
{% html_element tag with action_attributes %}
|
|
76
|
+
{{ rendered_icon }}
|
|
77
|
+
<span class="sr-only">{{ label }}</span>
|
|
78
|
+
{% end_html_element %}
|
|
79
|
+
{% endblock %}
|
|
80
|
+
</li>
|
|
81
|
+
{% endif %}
|
|
82
|
+
{% endfor %}
|
|
83
|
+
</ul>
|