Skip to content
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

IBX-5673: Submodels management dropdowns with placeholder #804

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions src/bundle/Resources/public/js/scripts/core/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
if (checkbox) {
checkbox.checked = false;
}

if (option.classList.contains('ibexa-dropdown__item--placeholder')) {
option.setAttribute('hidden', 'hidden');
}
});
this.selectedItemsContainer.innerHTML = '';
this.selectedItemsContainer.insertAdjacentHTML('beforeend', this.selectedItemsContainer.dataset.placeholderTemplate);
Expand Down
40 changes: 34 additions & 6 deletions src/bundle/Resources/public/scss/_dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@

.ibexa-input-text-wrapper {
width: 100%;
padding: calculateRem(8px) calculateRem(12px);
padding: calculateRem(8px) calculateRem(8px) 0;

&__actions {
right: calculateRem(16px);
Expand All @@ -196,7 +196,7 @@

&__items-list {
list-style: none;
padding: calculateRem(8.5px);
padding: calculateRem(8px);
margin: 0;
overflow-y: auto;
}
Expand All @@ -214,11 +214,12 @@
}

&__item {
padding: calculateRem(9px) calculateRem(15px);
margin-top: calculateRem(8px);
padding: calculateRem(9.5px) calculateRem(16px);
line-height: calculateRem(21px);
min-height: calculateRem(40px);
transition: background $ibexa-admin-transition-duration $ibexa-admin-transition;
border-radius: $ibexa-border-radius;
border-radius: calculateRem(4px);
cursor: pointer;
display: flex;
align-items: center;
Expand All @@ -227,6 +228,14 @@
display: none;
}

&:first-child {
margin-top: 0;

&[hidden] + li {
margin-top: 0;
}
}

&--selected {
position: relative;
padding-right: calculateRem(36px);
Expand All @@ -236,6 +245,10 @@
}
}

&--placeholder {
pointer-events: none;
}

.ibexa-input {
margin: 0 calculateRem(16px) 0 0;
}
Expand All @@ -245,7 +258,12 @@
}

&:hover {
background-color: $ibexa-color-light-300;
background-color: $ibexa-color-light-400;
color: $ibexa-color-primary;
}

&:active {
color: initial;
}

&[disabled] {
Expand All @@ -272,13 +290,23 @@
}

&__item-group {
padding-bottom: calculateRem(8px);
border-bottom: calculateRem(1px) solid $ibexa-color-light;

&--hidden {
display: none;
}

&:last-child {
border-bottom: none;
padding-bottom: 0;
}
}

&__item-group-label {
font-weight: bold;
color: $ibexa-color-dark-400;
font-size: calculateRem(10px);
padding: calculateRem(8px) calculateRem(16px);
}

&__item-group-list {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<ul
class="ibexa-dropdown__items-list"
data-template="{{ include('@ibexadesign/ui/component/dropdown/dropdown_item.html.twig', {
value,
multiple,
translation_domain,
custom_form: true,
icon: item_icon,
icon_class: item_icon_class,
Expand All @@ -161,16 +164,39 @@
label: _self.get_translated_label(placeholder, translation_domain)|trim|default(default_label),
} %}

{% include '@ibexadesign/ui/component/dropdown/dropdown_item.html.twig' with { choice: placeholder_choice, custom_form: true } %}
{% include '@ibexadesign/ui/component/dropdown/dropdown_item.html.twig' with {
choice: placeholder_choice,
value,
multiple,
translation_domain,
custom_form: true
} only %}
{% endif %}
{% for choice in preferred_choices %}
{% include '@ibexadesign/ui/component/dropdown/dropdown_item.html.twig' with { choice, preferred_choice: true, custom_form, icon: item_icon, icon_class: item_icon_class } %}
{% include '@ibexadesign/ui/component/dropdown/dropdown_item.html.twig' with {
choice,
value,
multiple,
translation_domain,
preferred_choice: true,
custom_form,
icon: item_icon,
icon_class: item_icon_class
} only %}
{% endfor %}
{% if preferred_choices|length > 0 %}
<hr class="ibexa-dropdown__separator" />
{% endif %}
{% for choice in choices %}
{% include '@ibexadesign/ui/component/dropdown/dropdown_item.html.twig' with { choice, custom_form, icon: item_icon, icon_class: item_icon_class } %}
{% include '@ibexadesign/ui/component/dropdown/dropdown_item.html.twig' with {
choice,
value,
multiple,
translation_domain,
custom_form,
icon: item_icon,
icon_class: item_icon_class
} only %}
{% endfor %}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
{% trans_default_domain 'dropdown' %}
{% import "@ibexadesign/ui/component/macros.html.twig" as html %}

{% set item_label = translation_domain is same as(false) ? choice.label : choice.label|trans({}, translation_domain) %}
{% set preferred_choice = preferred_choice|default(false) %}
{% set placeholder_choice = choice.placeholder|default(false) %}

{% if choice.choices is defined %}
<li class="ibexa-dropdown__item-group">
<label class="ibexa-dropdown__item-group-label">{{ item_label }}</label>
<ul class="ibexa-dropdown__item-group-list">
{% for child in choice.choices %}
{% include '@ibexadesign/ui/component/dropdown/dropdown_item.html.twig' with { choice: child, preferred_choice, custom_form } %}
{% include '@ibexadesign/ui/component/dropdown/dropdown_item.html.twig' with {
value,
multiple,
translation_domain,
choice: child,
preferred_choice,
custom_form
} only %}
{% endfor %}
</ul>
</li>
{% else %}
{% set is_selected = custom_form ? choice.value == value : choice is selectedchoice(value) %}
<li
data-value="{{ choice.value }}"
data-filter-value="{{ item_label }}"
{% if choice.icon is defined %}
data-choice-icon="{{ choice.icon }}"
{% endif %}
class="ibexa-dropdown__item
{% if preferred_choice %}ibexa-dropdown__item--preferred-choice{% endif %}
{% if is_selected %}ibexa-dropdown__item--selected{% endif %}"
>
{% set dropdown_item_attr = dropdown_item_attr|default({})|merge({
'data-value': choice.value,
'data-filter-value': item_label,
'data-choice-icon': choice.icon is defined ? choice.icon : null,
class: ('ibexa-dropdown__item '
~ (preferred_choice ? 'ibexa-dropdown__item--preferred-choice ')
~ (is_selected ? 'ibexa-dropdown__item--selected ')
~ (placeholder_choice ? 'ibexa-dropdown__item--placeholder '))|trim,
}) %}

{% if placeholder_choice %}
{% set dropdown_item_attr = dropdown_item_attr|merge({
hidden: 'hidden'
}) %}
{% endif %}

<li {{ html.attributes(dropdown_item_attr)}}>
{% if multiple is defined and multiple %}
<input type="checkbox" name="dropdown-checkbox" class="ibexa-input ibexa-input--checkbox" {% if is_selected %}checked{% endif %} />
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
{% set close_btn %}
<button {{ html.attributes(attr_close_btn) }}>
<svg
class="ibexa-icon ibexa-icon--small-medium"
class="ibexa-icon ibexa-icon--small"
aria-hidden="true"
>
<use xlink:href="{{ ibexa_icon_path('discard') }}"></use>
Expand Down