Back

Motiflow-picker

Current version version 0.0.9

Important This version exposes your token. This will be resolved in the future

Installation

  1. You first need to acquire your token.
  2. Secondly you need to have or create a start-collection

If you do not have an account yet, you can apply here

Example

<script scr="../dist/motiflow-picker.min.js"></script> <motiflow-picker start-collection="1092" token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyQWNjb3VudElkIjo0NDcsInBhcnRuZXJTaG9wSWQiOiI0NDMiLCJpYXQiOjE2MTEyNDA2MjcsImV4cCI6MTYyNjk2NTQyN30.kcut2z3bKn6Byt2YN9dM4DQk6w6e6Fs6OV55PMfQt50"></motiflow-picker>

Events

Every time a pattern has been selected the event patternPickerPatternSelected is fired. You can use this data to update your own information.

Example

window.addEventListener('patternPickerPatternSelected', (event)=> { console.log(event.detail); });

Pop-up modus

When you applied the mode=popup you can trigger to open the define a CSS selector in the trigger-element='.button.openMotiflowTrigger' property or use a global js trigger

Example for js Trigger

//vanillaJS document.querySelector('button.openMotiflowTrigger').addEventListener('click',function(){ window.MotiflowPicker.openModal() }); //jQuery $('button.openMotiflowTrigger').on('click',function(){ window.MotiflowPicker.openModal() });

After a token is selected you might want the data pattern ID to be stored in a hidden field so you can use it later in the ordering flow. To do so you can apply a callback-element property with a CSS selector. For example a hidden input.

Full example

<h1>My awesome Product</h1> <form method=""> <div> <div>Size</div> <label> <input name="size" type="radio" value="s" /> Small </label> <label> <input name="size" type="radio" value="m" /> Medium </label> <label> <input name="size" type="radio" value="L" /> Large </label> </div> <div> <label> <div>Quantity</div> <input name="qty" type="number" value="1" /> </label> </div> <div> <input id="patternID" name="patternID" type="hidden" /> <button id="patternPicker"> Select Pattern </button> <hr /> <button type="submit"> Add to cart </button> </div> </form> <script scr="../dist/motiflow-picker.min.js"></script> <motiflow-picker start-collection="1092" token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyQWNjb3VudElkIjo0NDcsInBhcnRuZXJTaG9wSWQiOiI0NDMiLCJpYXQiOjE2MTEyNDA2MjcsImV4cCI6MTYyNjk2NTQyN30.kcut2z3bKn6Byt2YN9dM4DQk6w6e6Fs6OV55PMfQt50" mode="pop-up" callback-element="#patternID" trigger-element="#patternPicker" branding-color="#00a0e4" > </motiflow-picker>

Settings

You can customize the widget with the following parameters.

Parameter Usage
token (Required) Here you need to supply your Motiflow Partner token.
start-collection (Required) Supply the starting point, so with which collection/board should the picker start.
mode Pop-up or embed widget. Embed is default
language Here you can supply an (ISO 639-1) language code. Currently available NL, EN, DE. Default and fallback is EN
callback-element You can supply a dom element on which the pattern ID will be pushed into when a pattern is selected. <motiflow-picker token="..." start-boardId="..." callback-element="#patternId"> </motiflow>
callback-fuction You can supply a function which will be triggered after you confirm the selection. html <script> function testCallBackFunction(data){console.log(data);}</script> <motiflow-picker token="..." start-boardId="..." callback-function="testCallBackFunction"> </motiflow>
trigger-element You can supply trigger-element which will open the picker if in pop-up mode.
hide-select If you only want to show an inspirational widget, you can set the hide-select and the selection button is not available
hide-category-filter Removes the ability to filter on collection If both filters are hidden item is the filter bar is not shown
hide-color-filter Removes the ability to filter on color If both filters are hidden item is the filter bar is not shown
branding-color Allows you to change the primary color to any CSS-hex (6) color
background-color Allows you to change the background of the pattern grid to any CSS-hex (6) color

Methods

The Picker initializes a MotiflowPicker which is available via JS. For example console.log(window.MotiflowPicker)

Method Usage
closeModal Method to close modal
getSelected Method to get the selectedPattern
setSelected(:id) Method to set the selectedPattern
openModal Method to open modal

CSS Selectors

The picker operates in the shadow dom of the browser. This isolates the picker and therefore should not interfere with the working of your own platform/site/shop. (please report bugs if it does). This however has some drawbacks if you want to apply custom CSS to the picker. Therefore some elements can be target with the ::part() selector. Please note: You can change the color of the buttons and selected border via the property branding-color. Styling via this method is at your own risk

You can target the elements with the following CSS

motiflow-picker::part(pattern-filters) { background-color: red !important }
Selectors
pattern-picker motiflow-picker::part(pattern-picker
pattern-app motiflow-picker::part(pattern-app)
pattern-filters motiflow-picker::part(pattern-filters)
pattern-filters-category motiflow-picker::part(pattern-filters-category)
pattern-filters-color motiflow-picker::part(pattern-filters-color)
pattern motiflow-picker::part(pattern)
pattern-grid motiflow-picker::part(pattern-grid)
pattern-collection motiflow-picker::part(pattern-collection)
pattern-preview-modal motiflow-picker::part(pattern-preview-modal)
pattern-preview-modal-close motiflow-picker::part(pattern-preview-modal-close)
pattern-preview-modal-holder motiflow-picker::part(pattern-preview-modal-holder)
pattern-preview-modal-content motiflow-picker::part(pattern-preview-modal-content)
pattern-preview-ruler motiflow-picker::part(pattern-preview-ruler)
pattern-preview-ruler-width motiflow-picker::part(pattern-preview-ruler-width)
pattern-preview-ruler-height motiflow-picker::part(pattern-preview-ruler-height)
pattern-preview motiflow-picker::part(pattern-preview)
pattern-preview-scale motiflow-picker::part(pattern-preview-scale)
pattern-preview-information motiflow-picker::part(pattern-preview-information)

Release notes

v.0.0.1: First initial version for proof of concept

v.0.0.2: Added logic for callback element.

v.0.0.3: Added translations for Dutch. You can use a callback function to retrieve the data after confirming the selection.

v.0.0.4: Made some tweaks in interface to make it smoother, ability to hide filters, add German translations. Allow brand color

v.0.0.5: Some tweaks in external interactions.

v0.0.6: Updated z-index of modal. Button triggers work on more than one. Ability to set a pre-selected pattern.

v0.0.7: Fixed branding color update and updated readme

v0.0.8: Added background color. Allow to set the language via the method.

v0.0.9: Added part selectors for styling