All Projects โ†’ nativew โ†’ nativeweb

nativew / nativeweb

Licence: ISC license
๐Ÿคณ Tiny library for simple web components. [1kB]

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to nativeweb

Diffhtml
diffHTML is a web framework that helps you build applications and other interactive content
Stars: โœญ 788 (+747.31%)
Mutual labels:  components, web-components
Stylable
Stylable - CSS for components
Stars: โœญ 1,109 (+1092.47%)
Mutual labels:  components, web-components
Contactlab Ui Components
DEPRECATED - Basic UI components for ContactLab UX design pattern library
Stars: โœญ 31 (-66.67%)
Mutual labels:  components, web-components
Base Components Recipes
A collection of base component recipes for Lightning Web Components on Salesforce Platform
Stars: โœญ 293 (+215.05%)
Mutual labels:  components, web-components
Panel
Web Components + Virtual DOM: web standards for powerful UIs
Stars: โœญ 206 (+121.51%)
Mutual labels:  components, web-components
Bem Components
Set of components for sites development
Stars: โœญ 318 (+241.94%)
Mutual labels:  components, web-components
Components
Example Components (Built with Tonic)
Stars: โœญ 42 (-54.84%)
Mutual labels:  components, web-components
uce-template
A Vue 3 inspired Custom Elements toolless alternative.
Stars: โœญ 96 (+3.23%)
Mutual labels:  components, web-components
Lulu
LuLu UI for PC web
Stars: โœญ 2,354 (+2431.18%)
Mutual labels:  components, web-components
Gwt Polymer Elements
Polymer Web Components for GWT. A collection of Material Design widgets for desktop and mobile.
Stars: โœญ 153 (+64.52%)
Mutual labels:  components, web-components
Weightless
High-quality web components with a small footprint
Stars: โœญ 284 (+205.38%)
Mutual labels:  components, web-components
blockml-component
A component-based virtual DOM system (similar to React) for blockml.
Stars: โœญ 23 (-75.27%)
Mutual labels:  components, web-components
Clarity
Clarity is a scalable, accessible, customizable, open source design system built with web components. Works with any JavaScript framework, built for enterprises, and designed to be inclusive.
Stars: โœญ 6,398 (+6779.57%)
Mutual labels:  components, web-components
Fast
The adaptive interface system for modern web experiences.
Stars: โœญ 6,532 (+6923.66%)
Mutual labels:  components, web-components
anywhere-webcomponents
A UI work in progress based on custom elements (web components) for use in anywhere.
Stars: โœญ 17 (-81.72%)
Mutual labels:  components, web-components
Webrix
Powerful building blocks for React-based web applications
Stars: โœญ 41 (-55.91%)
Mutual labels:  components, web-components
cwco
Powerful and Fast Web Component Library with a Simple API
Stars: โœญ 27 (-70.97%)
Mutual labels:  components, web-components
elements
Lovingly crafted ui components based on web components. Works well with all Frameworks - including Angular, React and Vue.
Stars: โœญ 42 (-54.84%)
Mutual labels:  components, web-components
Ebayui Core
Collection of Marko widgets; considered to be the core building blocks for all eBay components, pages & apps
Stars: โœญ 134 (+44.09%)
Mutual labels:  components, web-components
Storybook
๐Ÿ““ The UI component explorer. Develop, document, & test React, Vue, Angular, Web Components, Ember, Svelte & more!
Stars: โœญ 67,445 (+72421.51%)
Mutual labels:  components, web-components

Native Web

Tiny library for simple web components.
1kB



import { component, property, Element } from 'nativeweb';

@component('hey-internet')
class Component extends Element {
    @property() emoji;

    render() {
        return `
            <h1>Hey Internet ${this.emoji}</h1>
        `;
    }
}
<hey-internet emoji="๐Ÿ‘‹"></hey-internet>

Native web components

Encapsulated styles and scripts

Simplified with decorators

Tiny footprint


One command to start

npm init nativeweb

Or add to your existing project

npm install nativeweb

Decorators

@component

@property

@event

@customEvent

@query

@queryAll


@component

Define a custom element and add styles. From an external file or the same file. styles can be an array of styles.

import { component, Element } from 'nativeweb';
import styles from './hey-styles.css.js';

@component('some-styles', styles)
class Component extends Element {
    render() {
        return `
            <h1>Some Styles</h1>
        `;
    }
}
import { css } from 'nativeweb';

export default css`
    h1 {
        color: orange;
    }
`;
<hey-styles></hey-styles>

@property

Get an attribute converted to the specified type or define a property with an optional default value.
String, Boolean, Number, Array or Object.

import { component, property, Element } from 'nativeweb';

@component('cool-property')
class Component extends Element {
    @property() cool = 'Cool Prop';
    @property(String) title = 'Default Title';
    @property(Number) multiplier;

    render() {
        return `
            <h1>${this.title}</h1>
            <h2>${this.cool} โžก๏ธ ${2 * this.multiplier}</h2>
        `;
    }
}
<cool-property title="Cool Title ๐Ÿค™" multiplier="3"></cool-property>

@event

Add an event listener to a component, a child element named @name or an external component event.

import { component, event, Element } from 'nativeweb';

@component('easy-event')
class Component extends Element {
    @event() mouseenter = this.onHover();
    @event() click = {
        '@title': this.onClick(),
        '@button': this.onClick()
    };
    @event() ready = {
        'other-component': this.onReady()
    };

    onHover() {
        console.log('Hover Component');
    }
    onClick(e) {
        console.log(e.currentTarget);
    }
    onReady({ detail }) {
        console.log(detail);
    }

    render() {
        return `
            <h1 @title>Easy Event</h1>
            <button @button>Click Me</button>
        `;
    }
}
<easy-event></easy-event>

@customEvent

Create a custom global event, namespaced with the component name. Ready to be dispatched. The listener is in the component above.

import { component, customEvent, Element } from 'nativeweb';

@component('other-component')
class Component extends Element {
    @customEvent() ready = 'Ready ๐Ÿš€';

    connected() {
        dispatchEvent(this.ready);
    }

    render() {
        return `
            <h1>Other Component</h1>
        `;
    }
}
<other-component></other-component>

@query

Query selector an @name child element.

import { component, query, Element } from 'nativeweb';

@component('simple-query')
class Component extends Element {
    @query() title;

    connected() {
        this.title.innerText = 'Better Title ๐Ÿ’ฏ';
    }

    render() {
        return `
            <h1 @title>Good Title</h1>
        `;
    }
}
<simple-query></simple-query>

@queryAll

Query selector all @name child elements.

import { component, queryAll, Element } from 'nativeweb';

@component('all-query')
class Component extends Element {
    @queryAll() title;

    connected() {
        this.title.forEach(el => (el.style.color = 'lightgreen'));
    }

    render() {
        return `
            <h1 @title>One Title</h1>
            <h2 @title>Other Title</h2>
        `;
    }
}
<all-query></all-query>

Lifecycle

render()   โ†’   Renders the component.

connected()   โ†’   Called when the component is inserted in the DOM.

disconnected()   โ†’   Called when the component is removed from the DOM.

adopted()   โ†’   Called when the component is moved to a new document.

attributeChanged()   โ†’   Called when an observed attribute changes.


Methods

this.update()   โ†’   Rerenders the component.


Properties

this.properties   โ†’   Get all attributes.


Tips

Shared style

Composition

Conditional

Loop

Variable element


Shared style

Include global styles in a component.

import { css } from 'nativeweb';
import global from '../global-style.css.js';

export default [
    global,
    css`
        h1 {
            color: orange;
        }
    `
];

Composition

Component composition with default slot and named slot.

import { component, Element } from 'nativeweb';

@component('slot-example')
class Component extends Element {
    render() {
        return `
            <header>
                <h1><slot name="title"></slot></h1>
                <slot></slot>
            </header>
        `;
    }
}
<slot-example>
    <span slot="title">Named slot</span>
    <p>Default slot</p>
</slot-example>

Conditional

Conditional rendering in vanilla JS.

import { component, property, Element } from 'nativeweb';

@component('condition-example')
class Component extends Element {
    @property() isGood = false;

    render() {
        return `
            ${this.isGood ? `<h1>Good</h1>` : ``}
        `;
    }
}

Loop

Render loop in vanilla JS.

import { component, property, Element } from 'nativeweb';

@component('loop-example')
class Component extends Element {
    @property() emojis = ['๐Ÿคณ', '๐Ÿงจ', '๐Ÿงฑ'];

    render() {
        return `
            ${this.emojis.map(item => `<span>${item}</span>`).join('')}
        `;
    }
}

Variable element

Render an element from a property.

import { component, property, Element } from 'nativeweb';

@component('element-example')
class Component extends Element {
    @property() as = 'p';

    render() {
        return `
            <${this.as}>Heading 1</${this.as}>
        `;
    }
}
<element-example as="h1"></element-example>


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].