Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 15, 2024
1 parent 07f6118 commit cdf4078
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions solara/lib/core/dashboard/brand/BrandDetailController.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ class BrandDetailController {
if (input.classList.contains('array-input')) {
const arrayItemsContainer = input.closest('.input-wrapper').querySelector('.array-items-container');
current[lastKey] = this.getArrayValue(arrayItemsContainer);
} else if (input.type === 'checkbox') {
current[lastKey] = input.checked;
} else {
let value = input.value;
if (input.type === 'color') {
Expand Down
24 changes: 22 additions & 2 deletions solara/lib/core/dashboard/brand/BrandDetailView.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ class BrandDetailView {
sectionElement.appendChild(this.createInputField(sectionItem, key, value, 'array'));
} else if (typeof value === 'object' && value !== null) {
for (const [subKey, subValue] of Object.entries(value)) {
sectionElement.appendChild(this.createInputField(sectionItem, `${key}.${subKey}`, subValue, inputType));
const subInputType = subValue === true || subValue === false ? 'boolean' : inputType;
sectionElement.appendChild(this.createInputField(sectionItem, `${key}.${subKey}`, subValue, subInputType));
}
} else {
sectionElement.appendChild(this.createInputField(sectionItem, key, value, inputType));
const fieldInputType = value === true || value === false ? 'boolean' : inputType;
sectionElement.appendChild(this.createInputField(sectionItem, key, value, fieldInputType));
}
}
}
Expand Down Expand Up @@ -150,6 +152,24 @@ class BrandDetailView {
input.value = '';
});

} else if (inputType === 'boolean') {
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.id = key;
checkbox.checked = value;

const checkboxLabel = document.createElement('label');
checkboxLabel.className = 'checkbox-label';
checkboxLabel.htmlFor = key;
checkboxLabel.textContent = value ? 'True' : 'False';

checkbox.addEventListener('change', () => {
checkboxLabel.textContent = checkbox.checked ? 'True' : 'False';
this.onSectionChanged(sectionItem, container.closest('.section'));
});

inputWrapper.appendChild(checkbox);
inputWrapper.appendChild(checkboxLabel);
} else {
const input = document.createElement('input');
input.type = inputType;
Expand Down
20 changes: 15 additions & 5 deletions solara/lib/core/dashboard/brand/brand.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,28 @@
.input-group:hover {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}
.input-wrapper {
display: flex;
align-items: center;
flex-grow: 1;
}
.input-wrapper input[type="checkbox"] {
margin-right: 10px;
flex-grow: 0;
}
.checkbox-label {
flex-grow: 1;
}
.input-wrapper label[for] {
margin-right: 10px;
}
label {
display: inline-block;
margin-right: 10px;
font-weight: bold;
min-width: 250px;
flex-shrink: 0;
}
.input-wrapper {
display: flex;
align-items: center;
flex-grow: 1;
}
input, select {
flex-grow: 1;
padding: 10px;
Expand Down

0 comments on commit cdf4078

Please sign in to comment.