railmapgen / rmp

Design your own rail map by freely dragging stations from different cities and connecting them with 135-degree rounded corners or perpendicular lines!
https://railmapgen.org/?app=rmp
GNU General Public License v3.0
94 stars 19 forks source link

#528 Change multiple selection color in batch #535

Closed langonginc closed 10 months ago

thekingofcity commented 10 months ago

More explanation on why batch operations should be done in color-field.tsx. ColorField is a convenient way for elements(nodes/stations/lines) to change their attributes in the Specific Attributes section. With this as the primary goal, it should only provide ways to change the attributes in that particular element. And no matter what the element contributor does, it should never touch attributes in other elements. The suggestion for the ColorField overhaul aligns with other <RmgFields /> by requiring only currentTheme and handleColorChange. When using, it should look like the following:

const someStationAttrsComponents = (props: AttrsProps<SomeBasicStationAttributes>) => {
    const { id, attrs, handleAttrsUpdate } = props;
    const { t } = useTranslation();

    const fields: RmgFieldsField[] = [
        {
            type: 'custom',
            label: t('color'),
            component: (
                <ColorField
                    currentTheme={attrs.color}
                    handleColorChange={color => {
                        attrs.color = color;
                        handleAttrsUpdate(id, attrs);
                    }}
                />
            ),
        },
    ];

    return <RmgFields fields={fields} />;
};