Skip to content

Commit

Permalink
Document LuigiElement feature on docu website (#4020)
Browse files Browse the repository at this point in the history
* #3881 - Document LuigiElement feature on docu website

* Edit script

* Update docs/luigi-element-api.md

Co-authored-by: Johannes Doberer <johannes.doberer@sap.com>

* Fix for missing styles in the function name headers

* Remove enter

* Remove duplicate

* Remove sentence

---------

Co-authored-by: Anna Milewska <anna.milewska@sap.com>
Co-authored-by: Waldemar Mazurek <waldemar.mazurek@sap.com>
Co-authored-by: Johannes Doberer <johannes.doberer@sap.com>
  • Loading branch information
4 people authored Nov 13, 2024
1 parent 57b6118 commit 3262bdd
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 2 deletions.
112 changes: 112 additions & 0 deletions docs/luigi-element-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<!-- meta
{
"node": {
"label": "Luigi Element API",
"category": {
"label": "API Reference",
"collapsible": true
},
"metaData": {
"categoryPosition": 6,
"position": 5
}
}
}
meta -->

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

## 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);
}
}
```

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`

### 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
3 changes: 2 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "luigi-scripts-private",
"private": true,
"scripts": {
"docu": "npm run docu:container && npm run docu:client && npm run docu:core",
"docu": "npm run docu:container && npm run docu:client && npm run docu:core && npm run docu:element",
"docu:generate:section": "npm run docu:client:generate:section && npm run docu:core:generate:sections",
"docu:container": "npm run docu:container:validate && npm run docu:container:generate:sections",
"docu:container:validate": "documentation lint ../container/typings/LuigiContainer.svelte.d.ts ../container/typings/LuigiCompoundContainer.svelte.d.ts",
Expand All @@ -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",
"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
3 changes: 2 additions & 1 deletion website/docs/src/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ body {

// API Function names
&.page-luigi-core-api,
&.page-luigi-client-api {
&.page-luigi-client-api,
&.page-luigi-element-api {
h4 {
margin-top: 35px;
display: inline-block;
Expand Down

0 comments on commit 3262bdd

Please sign in to comment.