From 1dd2f0c5d3567941079233a3f6bf36aba174bca4 Mon Sep 17 00:00:00 2001 From: Falkan Date: Wed, 18 Mar 2026 23:00:07 -0400 Subject: [PATCH] feat: optgroup dividers in unit dropdown, matching group order and visibility --- data/units.json | 29 ++++++++++------ src/components/ConverterCard.svelte | 2 +- src/components/UnitDropdown.svelte | 52 ++++++++++++++++++++++++++--- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/data/units.json b/data/units.json index 611f881..59543be 100644 --- a/data/units.json +++ b/data/units.json @@ -98,13 +98,14 @@ "hidden": false }, { - "id": "asdf", - "label": "asdf", - "labelPlural": "asdf", - "symbol": "asdf", - "group": "another-group", + "id": "mm", + "label": "millimeter", + "labelPlural": "millimeters", + "symbol": "mm", + "group": "lengths-and-distance", "toBase": 1, - "hidden": true + "hidden": false, + "description": "It's so tiny and kawaii (♡‿♡)." }, { "id": "pound", @@ -138,6 +139,14 @@ "symbol": "t", "group": "dickloads", "toBase": 76 + }, + { + "id": "cm", + "label": "centimeter", + "labelPlural": "centimeters", + "symbol": "cm", + "group": "lengths-and-distance", + "toBase": 10 } ], "groups": [ @@ -151,12 +160,12 @@ "alwaysShowLabel": true }, { - "id": "another-group", - "label": "Another Group", - "baseUnitId": "", + "id": "lengths-and-distance", + "label": "Lengths and Distance", + "baseUnitId": "mm", "toUniversal": 1, "alwaysShowLabel": false, - "hidden": true + "hidden": false } ] } diff --git a/src/components/ConverterCard.svelte b/src/components/ConverterCard.svelte index a84f7e6..29ea1f5 100644 --- a/src/components/ConverterCard.svelte +++ b/src/components/ConverterCard.svelte @@ -42,7 +42,7 @@
- +
{#each orderedResults as section} diff --git a/src/components/UnitDropdown.svelte b/src/components/UnitDropdown.svelte index 5405303..2fc3d87 100644 --- a/src/components/UnitDropdown.svelte +++ b/src/components/UnitDropdown.svelte @@ -1,17 +1,21 @@ - + {#each sections as section} + {#if section.label} + + {#each section.units as unit (unit.id)} + + {/each} + + {:else} + {#each section.units as unit (unit.id)} + + {/each} + {/if} {/each}