1.0.2 • Published 6 months ago

svelte-super v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Svelte Super

This is a powerfull multicomponent. With it, you can create tabs, an accordion, step-by-step instructions, and everything you have enough imagination for.

Usage:

<script>
  import {Super, SuperControl, SuperContent} from 'svelte-super';
  // Also you can import as default object Super (or more smantic name)
  // And use it with fields: Super.Control and Super.Content
</script>

<Super let:select>

  <div class="tabs">
    <SuperControl let:id let:active>
      <button
        class:active
        on:click={() => select(id)}
      >{id}</button>
    </SuperControl>
  </div>

  <SuperContent id="TAB 1" opened>
    <h2>Tab 1</h2>
    <p>...</p>
  </SuperContent>

  <SuperContent id="TAB 2" opened>
    <h2>Tab 2</h2>
    <p>...</p>
  </SuperContent>

  <SuperContent id="TAB 3" opened>
    <h2>Tab 3</h2>
    <p>...</p>
  </SuperContent>

</Super>

Super

The component has four let: directives. These are methods that you can use inside the component. All methods take one or more arguments - the ID of the SuperContent or SuperControl components.

Directives:

  • let:open Return a method makes visible one or more SuperContent blocks whose IDs are passed as arguments.
  • let:close Return a method hides one or more SuperContent blocks whose IDs are passed as arguments.
  • let:toggle Returns a method that hides or shows (depending on the current state) one or more Supercontinent blocks whose IDs are passed as arguments.
  • let:switch Returns a method that makes visible one or more Supercontinent blocks whose IDs are passed as arguments. And makes other blocks hidden.

SuperContent (Super.Content)

Everything inside the component will be hidden or shown depending on the property opened

Props:

  • id (any) The ID of the block. Required.
  • opened (boolean) If true, the block will be shown, else - hidden. This property is bidirectional and can be binded. Default: false.

Directives:

  • let:id The ID of the block.
  • let:opened Value of the opened property.

SuperControl (Super.Control)

A component that is associated with the SuperContent block via the id property. But it is always visible.

Props:

  • id (any) The ID of the block. Optional*.
  • active (boolean) If true, the block will be shown, else - hidden. This property is bidirectional and can be binded. Default: false.

Directives:

  • let:id The ID of the block.
  • let:active Value of the active property.

Notes:

The id property is optional. If the id property is not passed to the component, then the contents of the component will be applied in a loop to each identifier of each SuperContent block. The identifier value can be accessed via the directive let:id.

<script> 
  import Tabs from 'svelte-super';
  
  const tabs = ['Home', 'Blog', 'Contact'];
</script>

<Tabs let:select>

  <Tabs.Control let:id let:active>
    <button class:active on:click={() => select(id)}>{id}</button>
  </Tabs.Control>

  {#each tabs as tab}
    <Tabs.Content id={tab} opened={tab === 'Home'}>
      <h2>{tab}</h2>
      <p>...</p>
    </Tabs.Content>
  {/each}

</Tabs>

If you pass the id parameter to SuperControl , then the contents of the block will relate only to this identifier. This is convenient, for example, for layout with SuperContent blocks.

<script> 
  import { slide } from 'svelte/transition';
  import Accordion from 'svelte-super';
  
  const faq = {
    'Q1': {
      question: 'Question 1',
      answer: 'Answer 1',
    },
    'Q2': {
      question: 'Question 2',
      answer: 'Answer 2',
    },
    'Q3': {
      question: 'Question 3',
      answer: 'Answer 3',
    },
  };
</script>

<Accordion let:toggle>

  {#each Object.keys(faq) as id}
    {@const item = faq[id]}

    <div>
      <Accordion.Control {id} active={id === 'Q1'} let:id let:active >
        <button class:active on:click={() => toggle(id)}>{item.question}</button>
      </Accordion.Control>
      <Accordion.Content id={id}>
        <p transition:slide>{item.answer}</p>
      </Accordion.Content>
    </div>

  {/each}

</Accordion>
1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago