Skip to content

Commit

Permalink
perf(extend): allow for custom component registration + extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Izook committed Apr 12, 2023
1 parent e415680 commit 3839c9d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
26 changes: 26 additions & 0 deletions demo/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,29 @@ This feature should only to be used within environments where the REM values can
```

</auro-accordion>

## Recommended Use and Version Control

There are two important parts of every Auro component. The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes">class</a> and the custom clement. The class is exported and then used as part of defining the Web Component. When importing this component as described in the <a href="#install">install</a> section, the class is imported and the `auro-header` custom element is defined automatically.

To protect from versioning conflicts with other instances of the component being loaded, it is recommended to use our `registerComponent(name)` method and pass in a unique name.

```js
import './node_modules/@alaskaairux/auro-header';
registerComponent('custom-header');
```

This will create a new custom element that you can use in your HTML that will function identically to the `auro-header` element.

<div class="exampleWrapper">
<custom-header display="display">Salutations World!</custom-header>
</div>

<auro-accordion lowProfile justifyRight>
<span slot="trigger">See code</span>

```html
<custom-header display="display">Salutations World!</custom-header>
```

</auro-accordion>
5 changes: 5 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
});
</script>
<script type="module" src="../src/auro-header.js"></script>
<script type="module">
import { registerComponent } from "../index.js"
registerComponent('custom-header');
</script>

<script src="https://unpkg.com/@alaskaairux/auro-accordion@latest/dist/auro-accordion__bundled.js" type="module"></script>
</body>
</html>
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
export * from './dist/auro-header';
import { AuroHeader } from './src/auro-header';

/**
* Register Custom Element.
* @param {Object} name - Name to use for custom element.
* @returns {void}
*/
const registerComponent = (name = 'custom-header') => {
// alias definition
if (!customElements.get(name)) {
customElements.define(name, class extends AuroHeader {});
}
}

export { registerComponent }
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getSharedPlugins = (isLegacy) => [
];

const modernConfig = {
input: 'src/auro-header.js',
input: 'index.js',
output: {
format: 'esm',
file: 'dist/auro-header__bundled.js'
Expand Down
2 changes: 1 addition & 1 deletion src/auro-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import styleCssFixed from './style-fixed-css.js';
*/

// build the component class
class AuroHeader extends LitElement {
export class AuroHeader extends LitElement {
constructor() {
super();

Expand Down
2 changes: 1 addition & 1 deletion test/auro-header.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fixture, html, expect } from '@open-wc/testing';
import '../src/auro-header.js';
import '../src/auro-header';

describe('auro-header', () => {
it('sets the CSS class on auro-header', async () => {
Expand Down

0 comments on commit 3839c9d

Please sign in to comment.