0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-05-07 01:30:06 +00:00

Started attempt at formalising component system used in BookStack

Added a document to try to define things.
Updated the loading so components are registed dynamically.
Added some standardised ways to reference other elems & define options
This commit is contained in:
Dan Brown 2020-06-24 20:38:08 +01:00
parent 71e7dd5894
commit 76d02cd472
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
10 changed files with 213 additions and 116 deletions

56
dev/docs/components.md Normal file
View file

@ -0,0 +1,56 @@
# JavaScript Components
This document details the format for JavaScript components in BookStack.
#### Defining a Component in JS
```js
class Dropdown {
setup() {
}
}
```
#### Using a Component in HTML
A component is used like so:
```html
<div component="dropdown"></div>
<!-- or, for multiple -->
<div components="dropdown image-picker"></div>
```
The names will be parsed and new component instance will be created if a matching name is found in the `components/index.js` componentMapping.
#### Element References
Within a component you'll often need to refer to other element instances. This can be done like so:
```html
<div component="dropdown">
<span refs="dropdown@toggle othercomponent@handle">View more</span>
</div>
```
You can then access the span element as `this.$refs.toggle` in your component.
#### Component Options
```html
<div component="dropdown"
option:dropdown:delay="500"
option:dropdown:show>
</div>
```
Will result with `this.$opts` being:
```json
{
"delay": "500",
"show": ""
}
```