-
-
Notifications
You must be signed in to change notification settings - Fork 1
Create component with dynamic style
Vetrivel edited this page Jan 24, 2020
·
4 revisions
-
Select
Components panel -> "HelloWorldComponent"
. -
Edit
Editor panel -> Component markup field
from<h1 id="header">{state.content}</h1>
to<h1 className={state.status} id="header">{state.content}</h1>
. This creates a new class attribute and fetches status value from the state. -
Edit state in
Editor panel -> Component state field
from{"content":"Hello world"}
to{"content":"Hello world", "status":"valid"}
. This will create a new state property in the name of status. -
Type
.valid{border: 1px solid green;}
inEditor panel -> Component css field
. -
Click
Editor panel -> Save button
. - Reload.
-
Click
Components panel -> HelloWorldComponent
. Notice preview has "Hello world" with green border. This means the class is getting applied successfully. -
Select
Settings panel -> h1-header check box
. This will open up all existing events bound to h1-header element. -
Edit
Settings panel -> Events -> Existing -> onClick -> reducer
fromstate.content = "Hi World"
tostate.content = "Hi World"; state.status = "invalid"
. What we are doing is, updating the state to contain a modified status value. -
Click
Settings panel -> Save button
. -
Edit
Editor panel -> Component css field
from.valid{border: 1px solid green;}
to.valid{border: 1px solid green;} .invalid{border: 1px solid red;}
. Now we have two classes created. The class names are fetched from the state of the component. -
Click
Editor panel -> Save button
. - Reload.
-
Click
Components panel -> HelloWorldComponent
. Preview panel should show "Hello World". -
Click
Preview panel -> "Hello World"
. "Hello world" with green border should change to "Hi World" with red border. This is because, when "Hello World" is clicked, state gets modified values of content and status. Preview re-renders the component with the new state.
Sidebar