-
Notifications
You must be signed in to change notification settings - Fork 1
IBX-7899: Chip component #57
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4e90e43
IBX-7899: Chip component
albozek 221afec
Fix builds
albozek 4f2b1f6
Handled close chip button
albozek 22be8e4
After review
albozek bffc77d
Renamed button from close to delete
albozek 49afb63
after review pt 2
albozek 574ae1c
Changed access modifiers
albozek 0fa299e
Changed to more precise type
albozek 61eb1e9
Fixed aria-label
albozek 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { Base } from '../partials'; | ||
|
|
||
| interface ChipConfig { | ||
| onDelete?: (event: MouseEvent) => void; | ||
| } | ||
|
|
||
| export default class Chip extends Base { | ||
| private deleteButton: HTMLButtonElement | null; | ||
| private onDelete?: (event: MouseEvent) => void; | ||
|
|
||
| constructor(container: HTMLDivElement, config: ChipConfig = {}) { | ||
| super(container); | ||
|
|
||
| this.deleteButton = this._container.querySelector('.ids-chip__delete'); | ||
| this.onDelete = config.onDelete; | ||
| } | ||
|
|
||
| protected handleDelete(event: MouseEvent): void { | ||
| event.stopPropagation(); | ||
|
|
||
| if (this.onDelete) { | ||
| this.onDelete(event); | ||
| } | ||
| } | ||
|
|
||
| protected initDeleteButton(): void { | ||
| if (this.deleteButton) { | ||
| this.deleteButton.addEventListener('click', this.handleDelete.bind(this)); | ||
| } | ||
| } | ||
|
|
||
| public init(): void { | ||
| super.init(); | ||
| this.initDeleteButton(); | ||
| } | ||
| } | ||
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
29 changes: 29 additions & 0 deletions
29
src/bundle/Resources/views/themes/standard/design_system/components/chip.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,29 @@ | ||
| {% trans_default_domain 'ibexa_design_system_twig' %} | ||
|
|
||
| {% set chip_classes = | ||
| html_classes( | ||
| 'ids-chip', | ||
| { | ||
| 'ids-chip--error': error, | ||
| 'ids-chip--disabled': disabled, | ||
| }, | ||
| attributes.render('class') ?? '' | ||
| ) | ||
| %} | ||
| {% set delete_msg = 'ibexa.chip.delete-btn.label'|trans|desc('Delete') %} | ||
|
|
||
| <div tabIndex={{ disabled ? -1 : 0 }} class="{{ chip_classes }}" aria-disabled="{{ disabled ? 'true' : 'false' }}" {{ attributes }}> | ||
| <div class="ids-chip__content"> | ||
| {{ block('content') }} | ||
| </div> | ||
| {% if is_deletable %} | ||
| <twig:ibexa:button | ||
| type="tertiary-alt" | ||
| size="small" | ||
| icon="discard" | ||
| class="ids-chip__delete" | ||
| disabled="{{ disabled }}" | ||
| :aria-label="delete_msg" | ||
| /> | ||
| {% endif %} | ||
| </div> |
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,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; | ||
|
|
||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||
| use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; | ||
| use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate; | ||
| use Symfony\UX\TwigComponent\Attribute\PreMount; | ||
|
|
||
| #[AsTwigComponent('ibexa:chip')] | ||
| final class Chip | ||
konradoboza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| public bool $error = false; | ||
|
|
||
| #[ExposeInTemplate('is_deletable')] | ||
| public bool $isDeletable = true; | ||
|
|
||
| public bool $disabled = false; | ||
|
|
||
| /** | ||
| * @param array<string, mixed> $props | ||
| * | ||
| * @return array<string, mixed> | ||
| */ | ||
| #[PreMount] | ||
| public function validate(array $props): array | ||
| { | ||
| $resolver = new OptionsResolver(); | ||
| $resolver->setIgnoreUndefined(); | ||
| $resolver | ||
| ->define('error') | ||
| ->allowedTypes('bool') | ||
| ->default(false); | ||
| $resolver | ||
| ->define('isDeletable') | ||
| ->allowedTypes('bool') | ||
| ->default(true); | ||
| $resolver | ||
| ->define('disabled') | ||
| ->allowedTypes('bool') | ||
| ->default(false); | ||
|
|
||
| return $resolver->resolve($props) + $props; | ||
| } | ||
| } | ||
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.