Skip to content

Commit 2c3ccc6

Browse files
Merge pull request #22 from NxtLvLSoftware/dev-to-dist
Merge dev changes to dist
2 parents 7573600 + 1c2cdb2 commit 2c3ccc6

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,48 @@ The component parameters prototype is checked for inheritance from the [AlpineCo
399399
class and handled accordingly.
400400
401401
#### Using Components
402-
Guide
402+
Using components works the same way as registering with the normal [`alpine.data()`](https://alpinejs.dev/globals/alpine-data),
403+
just provide the component name to the `x-data` attribute in a HTML element. The name
404+
provided to the `AlpineComponents.register()` call is forwarded to Alpine and your
405+
component will work as if you were using in-line JavaScript objects.
406+
407+
Here's the contrived `dropdown` example re-written to use a class:
408+
```html
409+
<div x-data="dropdown">
410+
<button @click="toggle">...</button>
411+
412+
<div x-show="open">...</div>
413+
</div>
414+
415+
<script>
416+
import Alpine from 'alpinejs';
417+
418+
window.Alpine = Alpine;
419+
420+
import { AlpineComponents, AlpineComponent } from '@nxtlvlsoftware/alpine-typescript';
421+
422+
class ToggleComponent extends AlpineComponent {
423+
constructor(
424+
open: boolean = false
425+
) { super(); }
426+
427+
toggle() { this.open = !open; }
428+
}
429+
430+
window.addEventListener('alpine-components:init', () => {
431+
window.Alpine.Components.register(ToggleComponent, 'toggle');
432+
});
433+
434+
AlpineComponents.bootstrap({
435+
logErrors: true
436+
});
437+
</script>
438+
```
439+
The main drawback of using this library is the added compilation step needed to use TypeScript.
440+
Alpine is an elegant library that provides a thin layer on-top of vanilla JavaScript. Using
441+
Alpine the way it was intended is the way to go until your list of components grows and you
442+
need a way to organise them. If you're not already using a bundler in your project (webpack,
443+
Vite, Rollup, etc) then this probably isn't for you.
403444

404445
## Contributing
405446

@@ -424,6 +465,8 @@ __A full copy of the license is available [here](https://github.com/NxtLvlSoftwa
424465
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
425466
> SOFTWARE.
426467
427-
#
468+
<br>
469+
<hr>
470+
<br>
428471

429472
__A [NxtLvL Software Solutions](https://github.com/NxtLvLSoftware) product.__

typedoc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"GitHub": "https://github.com/NxtLvlSoftware/alpine-typescript",
44
"Twitter": "https://twitter.com/NxtLvlSoftware",
55
"Home": "/index.html",
6-
"Example": "/example/"
6+
"Example": "https://nxtlvlsoftware.github.io/alpine-typescript/example/"
77
}
88
}

0 commit comments

Comments
 (0)