All Projects → i5ik → vanillaview

i5ik / vanillaview

Licence: MIT license
Easy to use views with vanilla JS semantics

Programming Languages

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

Projects that are alternatives of or similar to vanillaview

Codeview
Android Code Highlighter
Stars: ✭ 204 (+1600%)
Mutual labels:  view
Transition
Easy interactive interruptible custom ViewController transitions
Stars: ✭ 2,566 (+21283.33%)
Mutual labels:  view
Viewanimator
A fluent Android animation library
Stars: ✭ 2,656 (+22033.33%)
Mutual labels:  view
Artist
An artist creates views. Artist is a Gradle plugin that codegens a base set of Android Views.
Stars: ✭ 208 (+1633.33%)
Mutual labels:  view
Goview
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.
Stars: ✭ 213 (+1675%)
Mutual labels:  view
Laravel Tag Helper
Add powerful HTML tag helpers to your Laravel application
Stars: ✭ 227 (+1791.67%)
Mutual labels:  view
Pagemenulayout
【Android分页菜单控件】快速实现美团、饿了么、京东、淘宝首页分页菜单效果
Stars: ✭ 197 (+1541.67%)
Mutual labels:  view
CopyPasteJS
This a small JS library to execute clipboard functions in a fast and easy way.
Stars: ✭ 20 (+66.67%)
Mutual labels:  javascript-library
Customfloatingactionbutton
This view is for replacement of standard Floating Action Button from Google Support Library. It is easy to use, customizable and you can also add text to button
Stars: ✭ 222 (+1750%)
Mutual labels:  view
Slidemenulayout
🔥An android slide menu that supports left and right swipes and slides with parallax.(一个支持左右滑动并带有视差滑动效果的安卓侧滑菜单控件.仿[QQ/探探侧滑])
Stars: ✭ 235 (+1858.33%)
Mutual labels:  view
Revealbanner
🚀🚀🚀 滑动特效banner
Stars: ✭ 209 (+1641.67%)
Mutual labels:  view
Foregroundviews
Views that supports a foreground, like FrameLayout does
Stars: ✭ 215 (+1691.67%)
Mutual labels:  view
Riot
Simple and elegant component-based UI library
Stars: ✭ 14,596 (+121533.33%)
Mutual labels:  view
Weathericonview
Weather Icon View for Android applications
Stars: ✭ 206 (+1616.67%)
Mutual labels:  view
Android Stepsview
A more complete version of stepsViews in android
Stars: ✭ 244 (+1933.33%)
Mutual labels:  view
Android 3d Layout
Wow effect, transform your layout into 3D views
Stars: ✭ 199 (+1558.33%)
Mutual labels:  view
Flexml
🚀基于Litho的Android高性能动态业务容器。
Stars: ✭ 225 (+1775%)
Mutual labels:  view
angular-calendar-week-hours-view
This is an alternative week view for the angular calendar which allows the user to see all the week hours
Stars: ✭ 20 (+66.67%)
Mutual labels:  view
SABRE.js
Substation Alpha suBtitles REnderer -- A Gpu Accelerated Javascript Advanced SubStation (ASS) Alpha Subtitles Renderer. Renders .ass and .ssa files.
Stars: ✭ 58 (+383.33%)
Mutual labels:  javascript-library
Shadowimageview
🔥可以根据图片内容变阴影颜色,更加细腻的阴影效果 It can change color according to the picture, more delicate shadow effect
Stars: ✭ 2,560 (+21233.33%)
Mutual labels:  view

VanillaView · GitHub license npm version npm npm npm

VanillaView is a vanilla JS module for UI.

  • No build-step
  • DOM-based, mutates in place

Learn how to use VanillaView in your own project.

Why are there 3 names above in the NPM downloads badges? Because these are the 3 (so far) iterations of this project and their respective names. ;P ;)xx

Features

  • minimal updates with no vDOM overhead
  • zero dependencies
  • no toolchain required
  • no switching context, no switching conceptual model needed. Use the existing vanilla JavaScript semantics you already know and HTML semantics you're already familiar with
  • use as much or as little as you want

Learn

Now you can add a container to the HTML:

  <!-- ... existing HTML ... -->

  <div id=container></div>

  <!-- ... existing HTML ... -->

Second, add some <script> tags:

  <!-- Load VanillaView. -->
  <script src=https://unpkg.com/vanillaviewjs@latest/dist/vanillaview.js crossorigin></script>

  <!-- Load our VanillaView component. -->
  <script src=button.js></script>

Third, add code to button.js:

  const State = { clicked: false };
  const domContainer = document.querySelector('#container');

  Button().to(domContainer, 'innerhtml');

  function Button() {
    return vanillaview.s`
      <button click=${() => State.clicked = true}>
        Click
      </button>
    `;
  }

And you're done!

You'll notice that we added an event listener for the click event simply by adding a function to the click attribute in the HTML. All event handlers are added this way, using the events name, without any capitalization. If you want to add flags (like 'passive', or 'once') you can separate them with :, like

const PassiveScroller = () => c`
  <div scroll:passive:once=${ ev => console.log('I scrolled', ev) }></div>
`;

Installation

VanillaView has been designed for gradual adoption from the start, and you can use as little or as much VanillaView as you need

$ npm i --save vanillaviewjs

or use a CDN, like in the above Learn section.

Examples

Here is the first one to get you started:

function HelloMessage({ name }) {
  return s`<div>Hello ${name}</div>`;
}

HelloMessage({name:'Tay-anne'}).to(
  document.getElementById('container'),
  'afterbegin'
);

This example will render "Hello Tay-anne" into a container on the page.

You'll notice that we used an HTML syntax; we call it HTML. HTML is required to use VanillaView, it makes code more readable, and writing it feels like writing HTML. If you're using VanillaView as a <script> tag, you're all good; otherwise, and you'll never need a toolchain to handle it automatically.

The to function places your component where you want it on the page. It supports all the locations that insertAdjacentHTML does as well as 'replace' (which removes the location and replaces it with your component), and 'innerhtml' (which sets the .innerHTML property of the location to your component's HTML).

[Advanced Topic] s vs c

VanillaView provides two render functions: s and c.

s is for singleton components. These are things that you expect to have a single identity, and show up in only one location in your document. But note that these singletons can be keyed, a keyed singleton can show up in more than one location, but only where its keys are different. The singleton for each key will only exist in one place.

The benefits of singletons are effortless updates. Every time you call them, they will repaint their corresponding widget, with the minimal number of changes necessary. If you want to move a singleton to a new location in the document, you need to the to method on it again, like Button().to(newLocation).

With all these benefits why would you ever want to use c components? c components are for components (or clones). Every time you call a c component, it creates new nodes. You might want to use this where you need a lot of widgets but you don't need or want to add keys to them to keep track of them. You need to place those nodes in the document, either using to or via nesting, like,

const Child = count => c`<span>${count}</span>`;
const Parent = lastCount => s`<div>${Child(0)}, ${Child(lastCount)}</div>`;

Both s and c components can be arbitrarily nested inside each other. To add a key to an s component, simply do like so,

// add the key as the first slot in your component

const KeyedSingleton = (key, name) => s`
  ${{key}}
  <div>
    I'm unique. My name is now ${name}
  </div>
`;

// initial insert
KeyedSingleton('0', 'larry').to('body','afterbegin');
KeyedSingleton('1', 'laura').to('body','afterbegin');

// update
KeyedSingleton('0', 'laura');
KeyedSingleton('1', 'larry');

Keys always need to be strings. Any other type will throw an error.

Contributing

The main purpose of this repository is to continue evolving VanillaView core, making it faster and easier to use. Development of VanillaView happens in the common wealth of GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving VanillaView.

Code of Conduct

Dosyago has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Open a issue to propose a PR, get it approved, sign the CLA, and submit a PR.

License

VanillaView is MIT licensed.

Haiku

When you get around

To taking over the world

The humble vanillaview

Will be your steadfast friend

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].