Git Product home page Git Product logo

litteral's Introduction

Litteral

Use lit-html templates in vue and vice-versa. See test/index.js for details on usage. For litHTMLWrapper, it can be used in three different ways.

  1. Use a template directly
[litHTMLWrapper, html`<h1>Hello, world</h1>`];
  1. Use a function that returns a template
[litHTMLWrapper, () => html`<h1>Hello, world</h1>`]
  1. Use an array to pass values to a function that returns a template
[litHTMLWrapper, [({ name }) => html`<h1>Hello, ${name}</h1>`, { name: 'Alice' }]]

For using litHTMLWrapper in SFCs, prefix the name with v when importing.

<script setup>
import { litHTMLWrapper as vWrapper } from 'litteral'; // Or some other name.
import litTemplate from 'a-different-file.js';
</script>

<template>
    <div vWrapper="litTemplate"></div>
</template>

With litHTMLWrapperComponent:

<script setup>
    import { litHTMLWrapperComponent } from 'litteral';
    import content from './content.js';
</script>
<template>
    <!-- Optional is prop to control what element to create to render into. Defaults to div -->
    <litHTMLWrapperComponent is="main" :template="content" />
</template>

Facade

The exported Facade function takes a component definition that is the same as the object-based one used by Vue, except with 2 differences:

  1. Requirement to use render method, not to return render function from setup,
  2. Return a lit-html template from render, and
  3. Optionally, set the is prop to change what element is created to render into.

The Facade function simply wraps around render and returns a component definition object that is usable by vue.

This currently is a simple working version.

// litComponent.js
import { Facade } from 'litteral';
import { html } from 'lit-html';

export const litComponent = Facade({
    props: {
        name: {
            type: String,
            default: 'World'
        }
    },
    render(data) {
        return html`<h1>Hello, ${data.name}!</h1>`
    }
})

// vueComponent.js
import { h } from 'vue';
import { litComponent } from './litComponent.js';

export const vueComponent = {
    render() {
        return h(Facade, { name: 'Alice' })
    }
}

litteral's People

Contributors

tagaroggu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.