Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/bundle/Resources/public/ts/components/inputs/Checkbox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import BaseCheckbox from '../../shared/BaseCheckbox';

export default class Checkbox extends BaseCheckbox {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Base from '../../shared/Base';

export default class InpuText extends Base {
export default class InputText extends Base {
Copy link
Preview

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class name 'InpuText' was misspelled and has been correctly fixed to 'InputText'.

Copilot uses AI. Check for mistakes.

private _inputElement: HTMLInputElement;
private _actionsElement: HTMLDivElement;
private _clearBtnElement: HTMLButtonElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import BaseCheckbox from '../../shared/BaseCheckbox';

export default class ThreeStateCheckbox extends BaseCheckbox {
private _indeterminate = false;

constructor(container: HTMLDivElement) {
super(container);

this.indeterminate = this._inputElement.classList.contains('ids-input--indeterminate');
}

set indeterminate(value: boolean) {
this._indeterminate = value;
this._inputElement.indeterminate = value;
this._inputElement.classList.toggle('ids-input--indeterminate', value);

if (value) {
this._inputElement.checked = false;

this._inputElement.dispatchEvent(new Event('input', { bubbles: true }));
this._inputElement.dispatchEvent(new Event('change', { bubbles: true }));
}
}
}
18 changes: 18 additions & 0 deletions src/bundle/Resources/public/ts/init_components.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Accordion from './components/accordion';
import Checkbox from './components/inputs/Checkbox';
import InputText from './components/inputs/InputText';
import ThreeStateCheckbox from './components/inputs/ThreeStateCheckbox';

const accordionContainers = document.querySelectorAll<HTMLDivElement>('.ids-accordion:not([custom-init])');

Expand All @@ -9,10 +11,26 @@ accordionContainers.forEach((accordionContainer: HTMLDivElement) => {
accordionInstance.init();
});

const checkboxContainers = document.querySelectorAll<HTMLDivElement>('.ids-checkbox:not([custom-init])');

checkboxContainers.forEach((checkboxContainer: HTMLDivElement) => {
const checkboxInstance = new Checkbox(checkboxContainer);

checkboxInstance.init();
});

const inputTextContainers = document.querySelectorAll<HTMLDivElement>('.ids-input-text:not([custom-init])');

inputTextContainers.forEach((inputTextContainer: HTMLDivElement) => {
const inputTextInstance = new InputText(inputTextContainer);

inputTextInstance.init();
});

const threeStateCheckboxContainers = document.querySelectorAll<HTMLDivElement>('.ids-three-state-checkbox:not([custom-init])');

threeStateCheckboxContainers.forEach((threeStateCheckboxContainer: HTMLDivElement) => {
const threeStateCheckboxInstance = new ThreeStateCheckbox(threeStateCheckboxContainer);

threeStateCheckboxInstance.init();
});
17 changes: 17 additions & 0 deletions src/bundle/Resources/public/ts/shared/BaseCheckbox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Base from './Base';

export default abstract class BaseCheckbox extends Base {
protected _inputElement: HTMLInputElement;

constructor(container: HTMLDivElement) {
super(container);

const inputElement = container.querySelector<HTMLInputElement>('.ids-input');

if (!inputElement) {
throw new Error('Checkbox: Required elements are missing in the container.');
}

this._inputElement = inputElement;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% set input_classes =
html_classes(
'ids-input ids-input--checkbox ids-input--medium',
{
'ids-input--disabled': disabled,
'ids-input--error': error,
'ids-input--required': required
},
attributes.render('class') ?? ''
)
%}

<div class="ids-checkbox">
<input
class="{{ input_classes }}"
type="checkbox"
{{
attributes.defaults({
disabled,
required
})
}}
/>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% set input_classes =
html_classes(
'ids-input ids-input--checkbox ids-input--medium',
{
'ids-input--disabled': disabled,
'ids-input--error': error,
'ids-input--required': required,
'ids-input--indeterminate': indeterminate
},
attributes.render('class') ?? ''
)
%}

<div class="ids-three-state-checkbox">
<input
class="{{ input_classes }}"
type="checkbox"
{{
attributes.defaults({
disabled,
required
})
}}
/>
</div>
51 changes: 51 additions & 0 deletions src/lib/Twig/Components/inputs/AbstractCheckbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\DesignSystemTwig\Twig\Components\inputs;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\TwigComponent\Attribute\PreMount;

abstract class AbstractCheckbox
{
public bool $disabled = false;

public bool $error = false;

public bool $required = false;

/**
* @param array<string, mixed> $props
*
* @return array<string, mixed>
*/
#[PreMount]
public function validate(array $props): array
{
$resolver = new OptionsResolver();
$resolver->setIgnoreUndefined();
$resolver
->define('disabled')
->allowedTypes('bool')
->default(false);
$resolver
->define('error')
->allowedTypes('bool')
->default(false);
$resolver
->define('required')
->allowedTypes('bool')
->default(false);

$this->configurePropsResolver($resolver);

return $resolver->resolve($props) + $props;
}

abstract protected function configurePropsResolver(OptionsResolver $resolver): void;
}
20 changes: 20 additions & 0 deletions src/lib/Twig/Components/inputs/Checkbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\DesignSystemTwig\Twig\Components\inputs;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent]
final class Checkbox extends AbstractCheckbox
{
protected function configurePropsResolver(OptionsResolver $resolver): void
{
}
}
26 changes: 26 additions & 0 deletions src/lib/Twig/Components/inputs/ThreeStateCheckbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\DesignSystemTwig\Twig\Components\inputs;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent]
final class ThreeStateCheckbox extends AbstractCheckbox
{
public bool $indeterminate = false;

protected function configurePropsResolver(OptionsResolver $resolver): void
{
$resolver
->define('indeterminate')
->allowedTypes('bool')
->default(false);
}
}