Conditionally change an SVG

Is there a best practice for toggling between two SVGs?

I currently have two buttons and just us "hide" to only show the correct one (see below).

I have other simpler cases where all I want to do is change the color, but there doesn't seem to be a conditional way to set a button_icon color (can set the fill and make it bold, but can't change the color or change the SVG).

image

If I can, I use a button bar and hide one of the 2 segments. Just size the button bar to the dimension of one button (size is preserved when hiding other segments).

Button bars can make it easier if you want to calculate a label. Just know that styling options are not exactly the same as the ones for buttons.

Button bars avoid overlapping elements, something I like, but getting the display to refresh can be problematic sometimes.

Of course, you can always make distinct layout objects, overlap them and make sure their hide conditions are mutually exclusive.

Not sure if I would define any of that as "best practice", just available options.

Curious to see of someone will suggest something else...

4 Likes

Conditional Formatting will handle that for you.

5 Likes

@JasonMark :
@Malcolm is right, if the svg has the fmfill class inserted. Look at this thread: SVG image format for button icons

1 Like

Re: using a 2-segment button bar and conditionally hiding one or the other, I recently noticed that WebDirect does not always honor the segment resizing. I don't remember the exact situation, but it's one thing to keep an eye out for when you use this technique. If deploying to WD, test this specifically.

3 Likes

if you only have these two forms, one the outline, one outline plus fill, in my opinion the 2-layer approach is fastest:

  1. make the outline a background layer with lines and/or fills as shown on your left side.
  2. Now add a layer with the fmfill - class for the yellow fill.
  3. This can be shown/hidden via conditional formatting as mentioned by @Malcolm

this keeps it just one svg, no hiding via object settings in the inspector

1 Like

Why don’t you just use a simple star symbol without outline. Use light grey and yellow for conditional formatting. Easy and pretty.

1 Like

if you have users with a disability to distinguish between certain colours outline vs. filled is really helpful :slight_smile:

4 Likes

Ya'll are awesome!