Skip to content

Commit 8c029dc

Browse files
authored
IBX-7844: Tag component (#50)
1 parent 94c25e7 commit 8c029dc

File tree

2 files changed

+116
-0
lines changed
  • src
    • bundle/Resources/views/themes/standard/design_system/components
    • lib/Twig/Components

2 files changed

+116
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{% set tag_classes =
2+
html_cva(
3+
base: html_classes(
4+
'ids-tag',
5+
{
6+
'ids-tag--dark': isDark,
7+
},
8+
),
9+
variants: {
10+
type: {
11+
primary: 'ids-tag--primary',
12+
success: 'ids-tag--success',
13+
info: 'ids-tag--info',
14+
warning: 'ids-tag--warning',
15+
error: 'ids-tag--error',
16+
neutral: 'ids-tag--neutral',
17+
'icon-tag': 'ids-tag--icon-tag',
18+
'primary-alt': 'ids-tag--primary-alt',
19+
'success-ghost': 'ids-tag--success-ghost',
20+
'error-ghost': 'ids-tag--error-ghost',
21+
'neutral-ghost': 'ids-tag--neutral-ghost',
22+
},
23+
size: {
24+
medium: 'ids-tag--medium',
25+
small: 'ids-tag--small',
26+
},
27+
},
28+
)
29+
%}
30+
31+
<div
32+
class="{{
33+
tag_classes.apply(
34+
{
35+
type,
36+
size
37+
},
38+
attributes.render('class')
39+
)
40+
}}"
41+
>
42+
{% if is_ghost_type %}
43+
<div class="ids-tag__ghost-dot"></div>
44+
{% endif %}
45+
{% if icon %}
46+
<div class="ids-tag__icon">
47+
<twig:ibexa:icon name="{{ icon }}" size="small" />
48+
</div>
49+
{% endif %}
50+
<div className="ids-tag__content">
51+
{{ block('content') }}
52+
</div>
53+
</div>

src/lib/Twig/Components/Tag.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\DesignSystemTwig\Twig\Components;
10+
11+
use Symfony\Component\OptionsResolver\OptionsResolver;
12+
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
13+
use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate;
14+
use Symfony\UX\TwigComponent\Attribute\PreMount;
15+
16+
#[AsTwigComponent('ibexa:tag')]
17+
final class Tag
18+
{
19+
public string $size = 'medium';
20+
21+
public string $type = 'primary';
22+
23+
public bool $isDark = false;
24+
25+
public string $icon = '';
26+
27+
/** @var string[] */
28+
private static array $ghostTypes = ['success-ghost', 'error-ghost', 'neutral-ghost'];
29+
30+
/**
31+
* @param array<string, mixed> $props
32+
*
33+
* @return array<string, mixed>
34+
*/
35+
#[PreMount]
36+
public function validate(array $props): array
37+
{
38+
$resolver = new OptionsResolver();
39+
$resolver->setIgnoreUndefined();
40+
$resolver
41+
->define('size')
42+
->allowedValues('small', 'medium')
43+
->default('medium');
44+
$resolver
45+
->define('type')
46+
->allowedValues('primary', 'primary-alt', 'info', 'success', 'warning', 'error', 'neutral', 'icon-tag', ...self::$ghostTypes);
47+
$resolver
48+
->define('icon')
49+
->allowedTypes('string');
50+
$resolver
51+
->define('isDark')
52+
->allowedTypes('bool')
53+
->default(false);
54+
55+
return $resolver->resolve($props) + $props;
56+
}
57+
58+
#[ExposeInTemplate('is_ghost_type')]
59+
public function isGhostType(): bool
60+
{
61+
return in_array($this->type, self::$ghostTypes);
62+
}
63+
}

0 commit comments

Comments
 (0)