Simple On/Off Slider Buttons

I needed to use the standard on/off ‘slider’ style switch to toggle a state in a table.
So I made a button that uses the icons for an on-switch and off-switch
and toggles the state when clicked

Thought others might find it useful

Max

11 Likes

I like this elegant and simple logic quite a bit:

WithName(30,N,
  If(thisRow.State,
    Image("https://cdn.coda.io/icons/svg/color/toggle-on.svg",N,N),
    Image("https://cdn.coda.io/icons/svg/color/toggle-off.svg",N,N)
  )
)

very well done!

4 Likes

thankyou @Christiaan_Huizer

the WithName() allows me to set the size of the buttons image in a single place
its set to 30 pixels in the above example

the number is used 4 times in the code, but this way, i only need to set the value once

(if you mistakenly set the height and width wrong, you get weird distorted images)

max

1 Like

It looks really great ! Well done ! I already want to implement it even though I have no idea as to where I’ll put it :smiley:

what about this (I am working on an invoicing template dealing with promotions):

thanks @Xyzor_Max ! for the inspiration.

1 Like