Skip to content

Commit 6342f8e

Browse files
committed
Add docs
1 parent 51968c3 commit 6342f8e

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

README.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,33 @@ custom_elements/hello_element.js // will register <app-hello> automatically
4949

5050
Your `*_element.js` files have to `export default` custom elements for this to work properly.
5151

52-
> [!WARNING]
53-
> Only single word elements are supported currently. See https://github.com/codergeek121/custom_elements-rails/issues/1
52+
### Naming Convention for Custom Elements
53+
54+
When defining custom elements from files, their filenames are used to generate the element names automatically. The following rules and examples clarify how file paths are converted to custom element names:
55+
56+
#### Usage
57+
58+
Register all files in the `custom_elements` folder as custom elements using a prefix (e.g., `app`):
59+
60+
```js
61+
eagerDefineCustomElementsFrom("custom_elements", { prefix: "app" });
62+
```
63+
64+
#### Conversion Rules
65+
66+
- Filenames are transformed into kebab-case (lowercase with hyphens).
67+
- Words are separated by underscores (`_`) or hyphens (`-`) in the filename.
68+
- The folder structure is reflected in the name using double hyphens (`--`) to separate folder names from the file name.
69+
- A prefix (e.g., `app`) is added to the beginning of each custom element name.
70+
71+
#### Examples
72+
73+
| Filepath | Generated Custom Element Name |
74+
|-------------------------------------|--------------------------------|
75+
| `custom_elements/demo_element.js` | `<app-demo>` |
76+
| `custom_elements/demo-element.js` | `<app-demo>` |
77+
| `custom_elements/foo_bar_element.js`| `<app-foo-bar>` |
78+
| `custom_elements/folder/foo_bar_element.js` | `<app-folder--foo-bar>` |
5479

5580
## Add a custom element with the built-in generator
5681

0 commit comments

Comments
 (0)