An icon snippet takes a name and returns the matching SVG. The switch is {% case name %} with a {% when 'leaf' %} branch per icon.
Make the size optional with a fallback so call sites that don't pass one still work: assign px = width | default: 24, then use {{ px }} for the width and height (icons are square).
{# call sites stay one line #}
{% render 'icon', name: 'cart', width: 20 %}
{% render 'icon', name: 'search' %} {# uses the default width #}
We use width, not size. In Liquid size is reserved for list length (like cart.items.size), so it's a bad parameter name.