Custom SelectEntryFactory to allow optgroups

I am using a properties panel with extended properties. Some properties are dropdown lists (select). For that I am using entryFactory.selectBox, which works fine, but I would like to use optgroups inside my select elements to categorize my select options like in this example:

<label for="cars">Choose a car:</label>
<select name="cars" id="cars">
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>

How can I either extend SelectEntryFactory to be able to do this, or extend EntryFactory to use a custom GroupedSelectEntryFactory?

As you already said, creating your own custom entry factory with the existing SelectEntryFactory as an inspiration would be the best way to achieve what you want.

So far, I don’t know about any examples for optgroups factories.