-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
816314a
commit efca465
Showing
5 changed files
with
313 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## Bragi | ||
|
||
Bragi is a templating engine, allowing to express rendered content by objects, arrays and primitive types. | ||
|
||
```js | ||
[ | ||
'section', | ||
{ | ||
class: 'rectangle', | ||
style: { | ||
backgroundColor: 'white', | ||
height: [120, 'px'], | ||
width: [80, 'px'], | ||
}, | ||
}, | ||
] | ||
``` | ||
|
||
```js | ||
[ | ||
'a', | ||
{ | ||
class: ['link', { | ||
'highlighted': highlighted, | ||
}], | ||
href: 'https://www.opera.com', | ||
}, | ||
'Opera', | ||
] | ||
``` | ||
|
||
```js | ||
[ | ||
'ul', | ||
[ | ||
'li', | ||
'First item', | ||
], | ||
[ | ||
'li', | ||
'Second item', | ||
], | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
## Examples | ||
|
||
Toggle rendered within a custom element: | ||
|
||
```js | ||
class Toggle extends opr.Toolkit.WebComponent { | ||
|
||
static elementName = 'opr-toogle'; | ||
|
||
static styles = [ | ||
'styles/toggle.css', | ||
]; | ||
|
||
getInitialState(props) { | ||
return { | ||
id: props.id, | ||
value: Settings.getValue(props.id), | ||
}; | ||
} | ||
|
||
onAttached() { | ||
this.connectTo(Settings, { | ||
[this.props.id]: this.onValueChanged, | ||
}); | ||
} | ||
|
||
onValueChanged(value) { | ||
this.commands.update({ | ||
value, | ||
}); | ||
} | ||
|
||
render() { | ||
return [ | ||
'input', | ||
{ | ||
type: 'checkbox', | ||
class: 'toggle', | ||
checked: this.props.value === true, | ||
}, | ||
]; | ||
} | ||
} | ||
``` | ||
|
||
Impression reporter wrapper: | ||
|
||
```js | ||
class ImpressionReporter extends opr.Toolkit.WebComponent { | ||
|
||
onVisible() { | ||
// called by the intersection observer plugin | ||
Stats.reportImpression(this.props.id); | ||
} | ||
|
||
render() { | ||
return this.children[0]; | ||
} | ||
} | ||
``` | ||
|
||
Animation decorator: | ||
|
||
```js | ||
class Animation extends opr.Toolkit.WebComponent { | ||
|
||
getInitialState(props) { | ||
return { | ||
...props, | ||
animation: 'fade-in', | ||
}; | ||
} | ||
|
||
getUpdatedState(props, state) { | ||
return { | ||
...props, | ||
animation: 'shake', | ||
}; | ||
}; | ||
} | ||
``` | ||
|
||
Image details information with asynchronous state update: | ||
|
||
```js | ||
class ImageDetails extends opr.Toolkit.WebComponent { | ||
|
||
static elementName = 'image-details'; | ||
|
||
async getInitialState({url}) { | ||
const metadata = await Service.getImageMetadata(url); | ||
return { | ||
url, | ||
metadata, | ||
}; | ||
} | ||
|
||
render() { | ||
return [ | ||
'section', | ||
[ | ||
'img', | ||
url: this.props.url, | ||
], | ||
[ | ||
'span', | ||
`Width: ${this.props.metadata.width}`, | ||
] | ||
[ | ||
'span', | ||
`Height: ${this.props.metadata.height}`, | ||
], | ||
[ | ||
'span', | ||
`File size: ${format(this.props.metadata.size)}`, | ||
], | ||
]; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.