Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lit-directive-switch-part

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lit-directive-switch-part

Lit HTML directive for switch content part in your template

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Switch Part Social Media Photo by pure julia on Unsplash

Switch Part

Export format: ESM Distribution: Npm, Unpackage License: GPL 3.0

This is a directive for lit-html for switch parts of your template. Change any part of your template without re-rendering.

Installation

Install from NPM or use from Unpkg CDN

Npm

npm install --save lit-directive-switch-part

Unpkg

import {switchPart} from 'https://unpkg.com/lit-directive-switch-part?module'

# switchPart(store, options)

Arguments

  • store: Key value store. The Value can by a function for a lazy rendering; the function recibe previus key used. If cache is enabled, the function is called once and cache result for next setter.
  • options:
    • default: Default key for first rendering. Default value is "default"
    • cache: Enable/Disable cache for lazy rendering. Default value is "true"
    • resolver(store, key): Resolver function

API

case(key)

Switch to another content associated to key.

clear()

Set empty content in content part.

Common example

import {render, html} from 'lit-html'
import {switchPart} from 'lit-directive-switch-part';

const content = switchPart({
  a: html`Lorem ipsum dolor sit amet, consectetur adipiscing elit.`,
  b: html`Ut tempor tellus at nibh blandit rutrum.`,
  c: html`Nam vitae diam consequat, tristique lectus sed, ultricies erat.`
}, {default: 'a'});

render(html`
  <h1>Sw</h1>
  <ul>
    <li><button type="button" @click=${_ => content.case('a')}>Lorem</buttom></li>
    <li><button type="button" @click=${_ => content.case('b')}>Ut</buttom></li>
    <li><button type="button" @click=${_ => content.case('c')}>Nam</buttom></li>
    <li><button type="button" @click=${_ => content.clear()}>Clear</buttom></li>
  </ul>
  <hr>
  ${tab}
  `, document.querySelector('#mainbox'));

Lazy render example

import {render, html} from 'lit-html'
import {switchPart} from 'lit-directive-switch-part';

const content = switchPart({
  a: () => html`Lorem ipsum dolor sit amet, consectetur adipiscing elit.`,
  b: () => html`Ut tempor tellus at nibh blandit rutrum.`,
  c: () => html`Nam vitae diam consequat, tristique lectus sed, ultricies erat.`
}, {default: 'a', cache: true});

render(html`
  <h1>Sw</h1>
  <ul>
    <li><button type="button" @click=${_ => content.case('a')}>Lorem</buttom></li>
    <li><button type="button" @click=${_ => content.case('b')}>Ut</buttom></li>
    <li><button type="button" @click=${_ => content.case('c')}>Nam</buttom></li>
    <li><button type="button" @click=${_ => content.clear()}>Clear</buttom></li>
  </ul>
  <hr>
  ${tab}
  `, document.querySelector('#mainbox'));

Keywords

FAQs

Package last updated on 27 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc