This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Radium: Updating Button Styles via Props

    Phil HoldenPhil Holden

    In a CSS library like Bootstrap we can set a button's style to be "primary" or "secondary" by appending classes. For React components we want to be able to do this via props. Radium enables this by composing styles via an array. This mimicks the cascade of CSS.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:00 Let's say we want to make our button blue, only if it's a primary button. Otherwise, it will be gray. First, we rename our style object to styles and nest our existing rules into the base property. Then, update the style prop.

    00:13 Now, we can add a primary property and set the background color to blue and the base color to gray. Radium allows us to compose styles using array. It does this by doing a deep merge of properties. Because primary comes after base and the array, its properties will have precedence over those in base.

    00:30 In this case, our button turns from gray to blue. Now, we want to make the color conditional on the kind of button. Add in the kind prop, define the condition. Now, we can toggle the button's color via the props.

    Discuss

    Discuss