MagicComponents is a JavaScript library that allows you to easily create custom elements
- Reusable Components: Create modular and reusable UI components.
- Lightweight: Minimal dependencies for fast performance.
You can install MagicComponents via
npm install @mindemangou/magiccomponents
or
pnpm install @mindemangou/magiccomponents
Here’s a quick example of how to use MagicComponents:
import { define} from "@mindemangou/magiccomponents"
define({tagname:'app-app'},async ({element})=> {
console.log(element)
})
Each data-*
attribute you add to the component becomes a property accessible via props
Use the refreshProps
function to refresh data attributes retrieved from the server
<app-app
data-name="doe"
data-isAdmin='false'
data-json='{"country":"benin"}'>
</app-app>
import { define} from "@mindemangou/magiccomponents"
define({tagname:'app-app'},async ({element,props,refreshProps})=> {
console.log(props) //{ tagName:'app-app',isAdmin:'false',json:{country:"benin"} }
refreshProps()
})
<app-app
data-key='key1'></app-app>
<app-app
data-key='key2'></app-app>
To enable component isolation using the Shadow DOM, set the allowShadowDom property to true.
import { define} from "@mindemangou/magiccomponents"
import stylecontent from './css/style.css?raw'
define({tagname:'app-app',allowShadowDom:true,stylecontent},async ({element})=> {
element.innerHTML="<h1 class='name' >John Doe</h1>"
})
For detailed documentation and examples, visit the official documentation.
MagicComponents is licensed under the MIT License.
Happy coding with MagicComponents!