Skip to content

Instantly share code, notes, and snippets.

@msaraiva
Last active May 20, 2021 18:05
Show Gist options
  • Save msaraiva/94ee665449195b054d587220bfa4c784 to your computer and use it in GitHub Desktop.
Save msaraiva/94ee665449195b054d587220bfa4c784 to your computer and use it in GitHub Desktop.

Interpolation

<div class={@class}>
  {@value}
</div>

Dynamic props/attrs

<div {...@attrs}>
  {@value}
</div>

<Component id="1" {...@props}/>

Attribute assignment shorthand

<div {=@class} {=@style}>
  {@value}
</div>

Note: Equivalent to <div class={@class} style={@style}>

Slots shorthand notation

<Card>
  <:header>
    Some head text
  </:header>
  Some text for the body
  <:footer>
    Some head text
  </:footer>
</Card>

Note: <:header> is equivalent to <template slot="header">

Constructs

  <!-- #if -->
  
  {#if @value == 0}
    <div class="equal">
      Value {@value} is 0
    </div>
  {#elseif @value > 0}
    <div class="greater">
      Value {@value} is greater than 0
    </div>
  {#else}
    <div class="lower">
      Value {@value} is lower than 0
    </div>
  {/if}
 
  <!-- #case --> 
  
  {#case @value}
    {#match [first|_]}
      <div class={@class}>
        First {first}
      </div>
    {#match []}
      <div {=@class}>
        Value is empty
      </div>
    {#match _}
      Value is something else
  {/case}
 
  <!-- #for -->
  
  {#for item <- @items}
    Item: {item}
  {#else}
    No items
  {/for}

Comments

<!-- HTML public comment (hits the browser) -->

{!-- Surface private comment (does not hit the browser) --}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment