generated from ibexa/bundle-template
-
Notifications
You must be signed in to change notification settings - Fork 0
IBX-10850: AltRadio List Field #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0ad976a
IBX-10850: AltRadio List Field
GrabowskiM 10f6e95
Enhanced ListField component with additional item properties and vali…
mikadamczyk 70a6955
Refactored ListField and ListFieldTrait to streamline item options co…
mikadamczyk 12a381f
Added comment to clarify purpose of configureListFieldItemOptions method
mikadamczyk 762dbf3
fix to check
GrabowskiM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/bundle/Resources/public/ts/components/alt_radio/alt_radios_list_field.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { AltRadioInput } from './alt_radio_input'; | ||
| import { BaseInputsList } from '../../partials'; | ||
|
|
||
| export enum AltRadiosListFieldAction { | ||
| Check = 'check', | ||
| Uncheck = 'uncheck', | ||
| } | ||
|
|
||
| export class AltRadiosListField extends BaseInputsList<string> { | ||
| private itemsContainer: HTMLDivElement; | ||
| private itemsMap = new Map<string, AltRadioInput>(); | ||
| protected value?: string; | ||
|
|
||
| static EVENTS = { | ||
| ...BaseInputsList.EVENTS, | ||
| CHANGE: 'ids:alt-radio-list-field:change', | ||
| }; | ||
|
|
||
| constructor(container: HTMLDivElement) { | ||
| super(container); | ||
|
|
||
| const itemsContainer = container.querySelector<HTMLDivElement>('.ids-choice-inputs-list__items'); | ||
|
|
||
| if (!itemsContainer) { | ||
| throw new Error('AltRadiosListField: Required elements are missing in the container.'); | ||
| } | ||
|
|
||
| this.itemsContainer = itemsContainer; | ||
|
|
||
| this.onItemClick = this.onItemClick.bind(this); | ||
|
|
||
| this.saveItemsInstancesToMap(); | ||
| } | ||
|
|
||
| protected saveItemsInstancesToMap() { | ||
| const itemsButtons = this.getItemsButtons(); | ||
|
|
||
| this.itemsMap.clear(); | ||
|
|
||
| itemsButtons.forEach((button) => { | ||
| const buttonInstance = new AltRadioInput(button, { onTileClick: this.onItemClick }); | ||
| const buttonId = buttonInstance.getInputElement().id; | ||
|
|
||
| this.itemsMap.set(buttonId, buttonInstance); | ||
| }); | ||
| } | ||
|
|
||
| getItemsButtons() { | ||
| const itemsButtons = [...this.itemsContainer.querySelectorAll<HTMLDivElement>('.ids-alt-radio')]; | ||
|
|
||
| return itemsButtons; | ||
| } | ||
|
|
||
| protected onItemClick(_event: MouseEvent, itemValue: string) { | ||
| if (this.value === itemValue) { | ||
| return; | ||
| } | ||
|
|
||
| const changeEvent = new CustomEvent(AltRadiosListField.EVENTS.CHANGE, { | ||
| bubbles: true, | ||
| detail: itemValue, | ||
| }); | ||
|
|
||
| if (this.value) { | ||
| const currentValueInstance = this.itemsMap.get(this.value); | ||
|
|
||
| if (currentValueInstance) { | ||
| currentValueInstance.toggleChecked(false); | ||
| } | ||
| } | ||
|
|
||
| this.value = itemValue; | ||
| this._container.dispatchEvent(changeEvent); | ||
| } | ||
|
|
||
| protected initButtons() { | ||
| this.itemsMap.forEach((itemInstance) => { | ||
| itemInstance.init(); | ||
| }); | ||
| } | ||
|
|
||
| public init() { | ||
| super.init(); | ||
|
|
||
| this.initButtons(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './alt_radio_input'; | ||
| export * from './alt_radios_list_field'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...e/Resources/views/themes/standard/design_system/components/alt_radio/list_field.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| {% extends '@IbexaDesignSystemTwig/themes/standard/design_system/partials/base_inputs_list.html.twig' %} | ||
|
|
||
| {% set class = html_classes('ids-alt-radio-list-field', attributes.render('class') ?? '') %} | ||
|
|
||
| {% block item %} | ||
| <twig:ibexa:alt_radio:input {{ ...item }} data-ids-custom-init="true"> | ||
| {{ item.label }} | ||
| </twig:ibexa:alt_radio:input> | ||
| {% endblock item %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <?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\AltRadio; | ||
|
|
||
| use Ibexa\DesignSystemTwig\Twig\Components\AbstractField; | ||
| use Ibexa\DesignSystemTwig\Twig\Components\ListFieldTrait; | ||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||
| use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; | ||
|
|
||
| /** | ||
| * @phpstan-type AltRadioItem array{ | ||
| * id: non-empty-string, | ||
| * value: string|int, | ||
| * label: string, | ||
| * disabled?: bool, | ||
| * tileClass?: string, | ||
| * attributes?: array<string, mixed>, | ||
| * label_attributes?: array<string, mixed>, | ||
| * inputWrapperClassName?: string, | ||
| * labelClassName?: string, | ||
| * name?: string, | ||
| * required?: bool | ||
| * } | ||
| * @phpstan-type AltRadioItems list<AltRadioItem> | ||
| */ | ||
| #[AsTwigComponent('ibexa:alt_radio:list_field')] | ||
| final class ListField extends AbstractField | ||
| { | ||
| use ListFieldTrait; | ||
|
|
||
| public string $value = ''; | ||
|
|
||
| protected function configurePropsResolver(OptionsResolver $resolver): void | ||
| { | ||
| $this->validateListFieldProps($resolver); | ||
|
|
||
| $resolver->setDefault('direction', self::HORIZONTAL); | ||
| $resolver->setDefault('value', ''); | ||
| $resolver->setAllowedTypes('value', 'string'); | ||
| } | ||
|
|
||
| protected function configureListFieldItemOptions(OptionsResolver $itemsResolver): void | ||
| { | ||
| $itemsResolver | ||
| ->define('tileClass') | ||
| ->allowedTypes('string') | ||
| ->default(''); | ||
|
|
||
| $itemsResolver->setDefault('disabled', false); | ||
| $itemsResolver->setDefault('attributes', []); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.