Skip to content

Commit e6058a6

Browse files
committed
After review
1 parent 0348ae1 commit e6058a6

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
import { Base } from '../partials';
22

3+
interface ChipConfig {
4+
onClose?: (event: Event) => void;
5+
}
6+
37
export default class Chip extends Base {
48
private closeButton: HTMLButtonElement | null;
5-
private onClose: (event: Event) => void;
9+
private onClose?: (event: Event) => void;
610

7-
constructor(container: HTMLDivElement, onClose: (event: Event) => void) {
11+
constructor(container: HTMLDivElement, config: ChipConfig = {}) {
812
super(container);
913

1014
this.closeButton = this._container.querySelector('.ids-chip__close');
11-
this.onClose = onClose;
12-
this.init();
15+
this.onClose = config.onClose;
1316
}
1417

15-
public init(): void {
16-
if (this.closeButton) {
17-
this.closeButton.addEventListener('click', this.handleClose.bind(this));
18+
private handleClose(event: MouseEvent): void {
19+
event.stopPropagation();
20+
if (this.onClose) {
21+
this.onClose(event);
1822
}
23+
}
1924

20-
super.init();
25+
private initCloseButton(closeButton: HTMLButtonElement): void {
26+
closeButton.addEventListener('click', this.handleClose.bind(this));
2127
}
2228

23-
private handleClose(event: Event): void {
24-
event.stopPropagation();
25-
this.onClose(event);
29+
public init(): void {
30+
if (this.closeButton) {
31+
this.initCloseButton(this.closeButton);
32+
}
33+
super.init();
2634
}
2735
}

src/bundle/Resources/translations/ibexa_design_system_twig.en.xliff

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
77
</header>
88
<body>
9+
<trans-unit id="0984281415afe479062f03d95efc14912bc27175" resname="ibexa.chip.close-btn.label">
10+
<source>Remove</source>
11+
<target state="new">Remove</target>
12+
<note>key: ibexa.chip.close-btn.label</note>
13+
</trans-unit>
914
<trans-unit id="61c7070a29f932eb0b1a343509d049aa52c92c09" resname="ibexa.clear-btn.label">
1015
<source>Clear</source>
1116
<target state="new">Clear</target>
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% trans_default_domain 'ibexa_design_system_twig' %}
2+
13
{% set chip_classes =
24
html_classes(
35
'ids-chip',
@@ -8,19 +10,20 @@
810
attributes.render('class') ?? ''
911
)
1012
%}
13+
{% set close_msg = 'ibexa.chip.close-btn.label'|trans|desc('Remove') %}
1114

12-
<div tabIndex={{ disabled ? -1 : 0 }} class="{{ chip_classes }}" {{ attributes }}>
15+
<div tabIndex={{ disabled ? -1 : 0 }} class="{{ chip_classes }}" aria-disabled="{{ disabled ? 'true' : 'false' }}" {{ attributes }}>
1316
<div class="ids-chip__content">
1417
{{ block('content') }}
1518
</div>
16-
{% if isClosable %}
19+
{% if is_closable %}
1720
<twig:ibexa:button
1821
type="tertiary-alt"
1922
size="small"
2023
icon="discard"
2124
class="ids-chip__close ids-chip-clear-btn"
2225
disabled="{{ disabled }}"
23-
aria-label="Remove"
26+
aria-label="close_msg"
2427
/>
2528
{% endif %}
2629
</div>

src/lib/Twig/Components/Chip.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010

1111
use Symfony\Component\OptionsResolver\OptionsResolver;
1212
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
13+
use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate;
1314
use Symfony\UX\TwigComponent\Attribute\PreMount;
1415

1516
#[AsTwigComponent('ibexa:chip')]
1617
final class Chip
1718
{
1819
public bool $error = false;
1920

20-
public bool $isClosable = true;
21+
#[ExposeInTemplate('is_closable')]
22+
public bool $is_closable = true;
2123

22-
public bool $disabled = true;
24+
public bool $disabled = false;
2325

2426
/**
2527
* @param array<string, mixed> $props

0 commit comments

Comments
 (0)