Multimaterial: trim strings, skip empties

This commit is contained in:
ochafik 2024-12-31 16:20:34 +00:00 • committed by Olivier Chafik
commit 6a9529aab7

View file

@ -40,11 +40,11 @@ export default function MultimaterialColorsDialog() {
<Button <Button
label={state.view.extruderPickerVisibility == 'exporting' ? "Export" : "Save"} label={state.view.extruderPickerVisibility == 'exporting' ? "Export" : "Save"}
icon="pi pi-check" icon="pi pi-check"
disabled={!tempExtruderColors.every(c => chroma.valid(c))} disabled={!tempExtruderColors.every(c => chroma.valid(c) || c.trim() === '')}
autoFocus autoFocus
onClick={e => { onClick={e => {
model!.mutate(s => { model!.mutate(s => {
s.params.extruderColors = tempExtruderColors; s.params.extruderColors = tempExtruderColors.filter(c => c.trim() !== '');
s.view.extruderPickerVisibility = undefined; s.view.extruderPickerVisibility = undefined;
}); });
if (state.view.extruderPickerVisibility === 'exporting') { if (state.view.extruderPickerVisibility === 'exporting') {
@ -84,9 +84,9 @@ export default function MultimaterialColorsDialog() {
} }
}} }}
onChange={(e) => { onChange={(e) => {
let color = e.target.value; let color = e.target.value.trim();
try { try {
color = chroma(e.target.value).name(); color = chroma(color).name();
console.log(`color: ${e.target.value} -> ${color}`); console.log(`color: ${e.target.value} -> ${color}`);
} catch (e) { } catch (e) {
// ignore // ignore