@martan-app/widgets-js
v1.1.23
Published
JavaScript client for using Martan widgets.
Downloads
10
Readme
@martan-app/widgets-js
JavaScript client for using Martan widgets.
Usage
You can use the library as a normal dependency by installing it via npm i @martan-app/widgets-js --save
.
Add CSS import "/node_modules/@martan-app/widgets-js/dist/style.css"
Examples
import Martan from '@martan-app/widgets-js'
import "/node_modules/@martan-app/widgets-js/dist/style.css"
// ID of the div that will receive the reviews widget
const $targetId = 'reviews_widget'
// Create widget instance
const martan = new Martan({
storeId: 124089,
widgetKey: 'WK_MY_WIDGET_KEY_UNIQUELY_GENERATED_IN_MARTAN_APP_ADMIN'
})
// Initialize reviews widget
const review = martan.reviews($targetId)
// start
review.start()
/*
// if you need to destroy the widget, like in react
useEffect(() => {
review.start()
// destroy after unmouting
return () => {
review.destroy()
}
}, [])
*/
reviews.destroy()
// Create widget instance for rating
const rating = martan.average({
color: '#4caf50',
fontSize: 20
})
// Initialize widget
rating.start()
// Destroy widget
rating.destroy()
Via CDN:
<script src="https://unpkg.com/@martan-app/[email protected]/dist/martan.umd.js">
Styles:
<link href="https://unpkg.com/@martan-app/[email protected]/dist/style.css">
<script type="module">
// ID of the div that will receive the reviews widget
const $targetId = 'reviews_widget'
// Create widget instance
const martan = new window.Martan({
storeId: 124089,
widgetKey: 'WK_MY_WIDGET_KEY_UNIQUELY_GENERATED_IN_MARTAN_APP_ADMIN',
})
// Initialize reviews widget
const reviews = martan.reviews($targetId)
reviews.start()
// Create widget instance for rating
const rating = martan.average({
color: '#4caf50',
fontSize: 20
})
// Initialize widget
rating.start()
// Destroy widget
rating.destroy()
</script>