Refactor icon rendering; update render_icon macro to accept extra_class parameter and adjust button icons in combobox for better state management
This commit is contained in:
parent
30d3cd7c45
commit
d3a9b6dbd5
6 changed files with 13 additions and 21 deletions
Binary file not shown.
|
@ -2,12 +2,10 @@ from typing import Any, List, Optional, TYPE_CHECKING
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .brands import Brand
|
from .brands import Brand
|
||||||
from .items import Item
|
from .items import Item
|
||||||
from .users import User
|
|
||||||
from .work_log import WorkLog
|
from .work_log import WorkLog
|
||||||
from .rooms import Room
|
from .rooms import Room
|
||||||
|
|
||||||
from sqlalchemy import Boolean, ForeignKeyConstraint, ForeignKey, Identity, Index, Integer, PrimaryKeyConstraint, String, Unicode, DateTime, text
|
from sqlalchemy import Boolean, ForeignKey, Identity, Index, Integer, Unicode, DateTime, text
|
||||||
from sqlalchemy.dialects.mssql import DATETIME2, MONEY
|
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,15 @@ const ComboBoxWidget = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateAddButtonIcon() {
|
function updateAddButtonIcon() {
|
||||||
addBtn.innerHTML = currentlyEditing ? icons.edit : icons.add;
|
const iconEl = addBtn.querySelector('.icon-state');
|
||||||
|
|
||||||
|
const iconClass = currentlyEditing ? 'bi-pencil' : 'bi-plus-lg';
|
||||||
|
iconEl.classList.forEach(cls => {
|
||||||
|
if (cls.startsWith('bi-') && cls !== 'icon-state') {
|
||||||
|
iconEl.classList.remove(cls);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
iconEl.classList.add(iconClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
input.addEventListener('input', () => {
|
input.addEventListener('input', () => {
|
||||||
|
@ -96,13 +104,6 @@ const ComboBoxWidget = (() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortOptions(selectElement) {
|
|
||||||
const sorted = Array.from(selectElement.options)
|
|
||||||
.sort((a, b) => a.text.localeCompare(b.text));
|
|
||||||
selectElement.innerHTML = '';
|
|
||||||
sorted.forEach(option => selectElement.appendChild(option));
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
initComboBox
|
initComboBox
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="text" class="form-control rounded-bottom-0" id="{{ id }}-input"{% if placeholder %} placeholder="{{ placeholder }}"{% endif %}>
|
<input type="text" class="form-control rounded-bottom-0" id="{{ id }}-input"{% if placeholder %} placeholder="{{ placeholder }}"{% endif %}>
|
||||||
<button type="button" class="btn btn-primary rounded-bottom-0" id="{{ id }}-add" disabled>
|
<button type="button" class="btn btn-primary rounded-bottom-0" id="{{ id }}-add" disabled>
|
||||||
{{ icons.render_icon('plus-lg', 16) }}
|
{{ icons.render_icon('plus-lg', 16, 'icon-state') }}
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn btn-danger rounded-bottom-0" id="{{ id }}-remove" disabled>
|
<button type="button" class="btn btn-danger rounded-bottom-0" id="{{ id }}-remove" disabled>
|
||||||
{{ icons.render_icon('dash-lg', 16) }}
|
{{ icons.render_icon('dash-lg', 16) }}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
{% macro render_icon(icon, size=24) %}
|
{% macro render_icon(icon, size=24, extra_class='') %}
|
||||||
<i class="bi bi-{{ icon }}" style="font-size: {{ size }}px;"></i>
|
<i class="bi bi-{{ icon }} {{ extra_class }}" style="font-size: {{ size }}px;"></i>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
|
@ -72,10 +72,3 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block script %}
|
|
||||||
const icons = {
|
|
||||||
add: `{{ icons.render_icon('plus', 16)|safe }}`,
|
|
||||||
edit: `{{ icons.render_icon('pencil', 16)|safe }}`,
|
|
||||||
};
|
|
||||||
{% endblock %}
|
|
Loading…
Add table
Add a link
Reference in a new issue