Skip to content

Commit

Permalink
Try coconut state + storybook control
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinresol committed Mar 3, 2021
1 parent 19c9ace commit 37557c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/coconut/storybook/Setup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Setup {

for (field in builder)
switch [field.kind, field.metaNamed(':story'), field.metaNamed(':state')] {
case [FFun(func), stories, v] if (stories.length > 0):
case [FFun(func), stories, states] if (stories.length > 0):
// wrap with Isolated, so changes will trigger re-render
function subst(e:Expr)
return switch e {
Expand All @@ -31,7 +31,7 @@ class Setup {
var init = [];

// add states
for (states in v)
for (states in states)
for (state in states.params)
switch state.expr {
case EVars(vars):
Expand Down
11 changes: 11 additions & 0 deletions tests/Demo.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ class Controls extends Component {
<p>Number Array: ${haxe.Json.stringify(args.narray)}</p>
</div>
';

@:story
@:state(var value:Int = 0)
function withState(args:Args) '
<div>
<p>Text: ${args.text}</p>
<button onclick=${value++}>
Clicked ${value} time(s)
</button>
</div>
';
// @formatter:on
}

Expand Down

0 comments on commit 37557c3

Please sign in to comment.