Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
knowler committed Feb 5, 2025
1 parent d4cb2a3 commit 5d30f41
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,38 @@

[![JSR](https://jsr.io/badges/@knowler/log-form-element)](https://jsr.io/@knowler/log-form-element)

Wrap a `<form>` element with this `<log-form-element>` and it’ll prevent the
default submission and log the form data to the console instead. [See the demo on CodePen](https://codepen.io/knowler/pen/zYembKY).
Wrap a `<form>` element with this `<log-form>` and it’ll prevent the
default submission and log the form data to the console instead.

```js
import { LogFormElement } from "https://esm.sh/gh/knowler/log-form-element/log-form-element.js?raw";
[See the demo](https://knowler.github.io/log-form-element/demo).

## Usage

The element is published on JSR (which can be used as an NPM registry) or you
can use a CDN like esm.sh to import the module.

By default, the module exports the class for you to define yourself. The class
has a `define()` method which can be used to easily define the element either
using a default tag name of `log-form` or whatever one you pass it.

```javascript
import { LogFormElement } from "https://esm.sh/jsr/@knowler/log-form-element";

LogFormElement.define();
```

You can also add a `?define` search param to the module’s URL which it’ll use to
automatically register the custom element using the default tag name. If you are
using a CDN, you might need to add a `?raw` param so that the `define` param
applies to module URL itself.

```html
<script type=module src="https://esm.sh/jsr/@knowler/log-form-element?raw&define"></script>
```

Once the element is registered. You can wrap `<form>` elements with it and then
open your console to debug submission.

```html
<log-form>
<form>
Expand Down
2 changes: 1 addition & 1 deletion demo-define-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark light">
<script type="module" src="./log-form-element.js?define"></script>
<script type="module" src="https://esm.sh/jsr/@knowler/log-form-element?raw&define"></script>
</head>
<body>
<h1><code>&lt;log-form&gt;</code> element demonstration</h1>
Expand Down
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark light">
<script type="module">
import { LogFormElement } from "./log-form-element.js";
import { LogFormElement } from "https://esm.sh/jsr/@knowler/log-form-element?raw";

LogFormElement.define();
</script>
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@knowler/log-form-element",
"version": "1.0.0",
"version": "1.0.1",
"exports": "./log-form-element.js",
"license": "Unlicense",
"publish": {
Expand Down

0 comments on commit 5d30f41

Please sign in to comment.