Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document LuigiElement feature on docu website #4020

Merged
merged 10 commits into from
Nov 13, 2024
158 changes: 158 additions & 0 deletions docs/luigi-element-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<!-- meta
{
"node": {
"label": "Luigi Element API",
"category": {
"label": "API Reference",
"collapsible": true
},
"metaData": {
"categoryPosition": 6,
"position": 5
}
}
}
meta -->

# Luigi Element

This document outlines the parameters provided by the Luigi Luigi Element. The `LuigiElement` class is a base class for building web component micro frontends within the Luigi framework. It provides essential functionality for rendering and managing the lifecycle of web components.
amilewskaa marked this conversation as resolved.
Show resolved Hide resolved

## Example Usage

To create a custom web component, extend `LuigiElement` and implement the required methods such as `render()`, `afterInit()`, and `onContextUpdate()`.

```js
class MyComponent extends LuigiElement {
render(ctx) {
return `<div>Hello, ${ctx.user.name}!</div>`;
}

afterInit(ctx) {
console.log('MyComponent initialized with context:', ctx);
}

onContextUpdate(ctx) {
console.log('Context updated:', ctx);
}
}

customElements.define('my-component', MyComponent);
amilewskaa marked this conversation as resolved.
Show resolved Hide resolved
```

The html function allows for creating HTML templates with interpolated values.

```js
const name = 'World';
const template = html`<p>Hello, ${name}!</p>`;
console.log(template); // Output: <p>Hello, World!</p>
```

## API Reference

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### LuigiElement

**Extends HTMLElement**

Base class for Luigi web component micro frontends.

#### Parameters

* `options`

#### afterInit

Override to execute logic after initialization of the web component, i.e.
after internal rendering and all context data set.

##### Parameters

* `ctx` **any** The context object passed by luigi core

#### render

Override to return the html template string defining the web component view.

##### Parameters

* `ctx` **any** The context object passed by luigi core

#### update

Override to execute logic after an attribute of this web component has changed.

#### onContextUpdate

Override to execute logic when a new context object is set.

##### Parameters

* `ctx` **any** The new context object passed by luigi core

#### querySelector

* **See**: ParentNode.querySelector

Query selector operating on shadow root.

##### Parameters

* `selector`

### LuigiElement

LuigiElement
Base class for Luigi web component micro frontends.

#### afterInit

Override to execute logic after initialization of the web component, i.e.
after internal rendering and all context data set.

##### Parameters

* `ctx` **any** The context object passed by luigi core

#### render

Override to return the html template string defining the web component view.

##### Parameters

* `ctx` **any** The context object passed by luigi core

#### update

Override to execute logic after an attribute of this web component has changed.

#### onContextUpdate

Override to execute logic when a new context object is set.

##### Parameters

* `ctx` **any** The new context object passed by luigi core

#### querySelector

* **See**: ParentNode.querySelector

Query selector operating on shadow root.

##### Parameters

* `selector`

### html

Html string processing according to luigi functionality.
Also useful in combination with LitElement VS Code plugins.

#### Parameters

* `literal` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The literal to process.
* `keys` **...any**

Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returns the processed literal.
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ nav:
- API Reference:
- Luigi Core API: luigi-core-api.md
- Luigi Client API: luigi-client-api.md
- Luigi Element API: luigi-element-api.md
- Advanced:
- Advanced scenarios: advanced-scenarios.md
- Core/Client Communication: communication.md
Expand Down
1 change: 1 addition & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"docu:container:generate:compound-container-api": "documentation readme ../container/typings/LuigiCompoundContainer.svelte.d.ts --parse-extension ts -f md --readme-file=../docs/luigi-compound-container-api.md --section=\"API Reference\" --markdown-toc=false --quiet --github false",
"docu:client": "npm run docu:client:validate && npm run docu:client:generate:section",
"docu:client:generate:section": "documentation readme ../client/src/luigi-client.js ../client/luigi-client-wc-docu-mixin.js -f md --readme-file=../docs/luigi-client-api.md --section=\"API Reference\" --markdown-toc=false --quiet --github false",
"docu:element": "documentation readme ../client/src/luigi-element.js -f md --readme-file=../docs/luigi-element-api.md --section=\"API Reference\" --markdown-toc=false --quiet --github false",
amilewskaa marked this conversation as resolved.
Show resolved Hide resolved
"docu:client:validate": "documentation lint ../client/src/luigi-client.js",
"docu:core": "npm run docu:core:validate && npm run docu:core:generate:sections",
"docu:core:validate": "documentation lint --shallow ../core/src/core-api/config.js ../core/src/core-api/elements.js ../core/src/core-api/auth.js ../core/src/core-api/navigation.js ../core/src/core-api/i18n.js ../core/src/core-api/custom-messages.js ../core/src/core-api/ux.js ../core/src/core-api/globalsearch.js ../core/src/core-api/theming.js ../core/src/core-api/featuretoggles.js",
Expand Down