Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

Commit

Permalink
remove bower and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Nov 2, 2017
1 parent 97a8b0e commit 4be0519
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 38 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 wikibus
Copyright (c) 2016-2017 Tomasz Pluskiewicz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
108 changes: 107 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,107 @@
# augeas
# lit-any

Building late-bound User Interface with `lit-html` without actually creating (too many) custom elements

## Quick guide

### 1. Install

``` bash
yarn add lit-any
```

### 2. Set up how to render your content

You want to display an object which represents a person but the avatar comes in two flavors. Of course,
it's possible to keep abusing `if` statements or drop in a `<template is="dom-if">` (old syntax, I know).

With `lit-any` you can deconstruct your HTML by defining partial templates which will be rendered when
they are really needed.

```javascript
import { ViewTemplates } from 'lit-any';
import { html } from 'lit-html';

ViewTemplates.when
.value(isPerson)
.renders((renderFunc, person) => html`
<person-element name="${person.name}">
<span slot="avatar">
${renderFunc(person.avatar, 'person-element-avatar')}
</span>
</person-element>
`);

ViewTemplates.when
.scope('person-element-avatar')
.value(v => v.url)
.renders((_, image) => html`
<img src="${image.url}" alt="avatar" />
`);

ViewTemplates.when
.scope('person-element-avatar')
.value(v => v.large)
.renders((_, image) => html`
<a href="${image.url}">
<img src="${image.large}" alt="avatar" />
</a>
`);

function isPerson(value) {
return value.type === 'Person';
}
```

This will set up the rendering so that `<person-element>` is displayed for a person but the avatar will
be rendered based on the presence of the `large` property.

### 3a. Render anywhere

To do actual rendering you don't really need a dedicated custom element. Any container will be fine

```html
<div id="personCoontainer"></div>
```

```javascript
import { render } from 'lit-any';

const person = {
type: 'Person',
image: {
url: 'https://s.gravatar.com/avatar/1497654c2d1af3cef4987234d1aced57?s=80',
large: 'https://s.gravatar.com/avatar/1497654c2d1af3cef4987234d1aced57?s=800'
}
};

const personContainer = document.querySelector('#personContainer');

render({ value: person }, personContainer);
```

### 3b. Render element

Alternatively you can use the `lit-view` instead of rendering directly to any node.

```html
<lit-view id="personCoontainer"></lit-view>
```

```javascript
const person = {
type: 'Person',
image: {
url: 'https://s.gravatar.com/avatar/1497654c2d1af3cef4987234d1aced57?s=80',
large: 'https://s.gravatar.com/avatar/1497654c2d1af3cef4987234d1aced57?s=800'
}
};

const personContainer = document.querySelector('#personContainer');

personContainer.value = person;
```

## To Do

1. `lit-form` element to build forms with individual input controls
1 change: 0 additions & 1 deletion augeas.html

This file was deleted.

8 changes: 0 additions & 8 deletions bower.json

This file was deleted.

27 changes: 0 additions & 27 deletions index.html

This file was deleted.

0 comments on commit 4be0519

Please sign in to comment.