Git Product home page Git Product logo

custom-widget-templates's Introduction

Happeo Custom Widget templates

Templates to start building custom widgets in Happeo.

This repository contains starting code for pure web component -widget and React widget. You can also find example implementations under the examples folder.

More details on how to run the code can be found in the folders of the different widget types.

Getting started

Creating your own Custom Widget

  1. You first need to sign in to Happeo as an administrator and create new custom widget.
  2. From the custom widget, select Web Component, give it a name and copy the generated slug.
  3. Then you can save the widget and it will be created and is by default in DEVELOPMENT -mode.
  4. Check the instructions below: "Running locally", "Running inside Happeo" && "Testing built code"

Running locally

Start by cloning this Repository and using the technology you want to use. We currently offer 2 templates, VanillaJS and React.

VanillaJS

TODO: Finalise this

React

The react template for the widget sits very nicely inside Happeo. Since we use React in our frontend, it also shares bunch of libraries with our main app, but you can of course npm install whatever libraries you want to your widget.

Start by opening the React -folder, opening the index.js -file and replace the "my-widget-slug" with the slug you got from step 2.

Running npm install && npm start. That will start the dev server and serve the bundle.js -file from localhost:8080/bundle.js.

Note that this will only serve the JS -file and no html is being served. So next we need to run this inside Happeo.

Lit

Lit is a small (about 5KB) helper library for creating standard Web components. This option is quite close to vanilla JS, but is much easier to read and write since it uses a React-like syntax for component templates.

Start by opening either a Lit-JavaScript or a Lit-TypeScript folder, opening the src/index.js-file and replace "my-widget-slug" with the slug you got from step 2.

Running npm install && npm start. That will start the dev server and serve the bundle.js -file from localhost:8080/bundle.js.

Running inside Happeo

Now that you have your custom widget created and it is in DEVELOPMENT -mode, you can add it to Pages. Note that the widget is only visible to administrators when in DEVELOPMENT and TESTING -modes.

  1. Create a new page (or edit a new one)
  2. Click to add new widget
  3. Select your widget on the list (it has "IN DEVELOPMENT" -tag next to it)
  4. That's it. You are now seeing your local widget inside Happeo.

Testing build code

Once you have your custom widget created in the admin panel and you have your code, you can analyse the code in the admin panel. To do that:

  1. build the code bundle npm run build
  2. Open admin panel, custom widgets and your custom widget
  3. Upload your code in the "Upload code" -section
  4. Scroll down to analysis to see if the widget runs successfully

Using Widget SDK

For advanced usage of widgets, please refer to @happeo/widget-sdk.

Props received by the Web Component

When the web component is rendered inside Happeo, we inject the following properties to it. You can access more data through our @happeo/widget-sdk, and you can check what's available from the readme.

Prop Description
uniqueId This is the widget instance's unique id. Use this to initiate the @happeo/widget-sdk
mode This indicates if the widget is displayed in edit or view -mode. Consider this when developing widgets for pages, since you most likely don't want page viewers to see all the editing controls.
location This indicates where the widget is being rendered. Currently this can only page "pages".

custom-widget-templates's People

Contributors

ankero avatar bhorkarg avatar loicmasson2 avatar lopezvit avatar mikamaunula avatar steelfinger avatar zaepoj avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

custom-widget-templates's Issues

npm registry not found

My issue:
I am having an issue when attempting to run 'npm install && npm start' to run react locally.
I get the following 404 error:

npm ERR! 404 Not Found - GET https://registry.npmjs.org/@happeouikit/menus/-/menus-1.2.41-loic.3.tgz - Not found

My workaround:
Checking the package-lock.js file in the react directory this request appears on line 2743.

Changing the resolved value to 'https://registry.npmjs.org/@happeouikit/menus/-/menus-1.2.41.tgz' and the integrity value to the corresponding value in the npm registry, the issue was resolved.

npm install fails at React template

npm install fails with dependency errors:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@universe%2ffrontend-utils - Not found
npm ERR! 404 
npm ERR! 404  '@universe/frontend-utils@^0.35.1' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of '@happeouikit/content-renderer'

Same problem exists with package @happeouikit/copy-to-clipboard-button

Reading a shared file

Hello,
Not a bug, but I was checking to see if there is an option to have a google file picker that upload a file from google drive .

I have custom widget and want the upload a file containing some data from google drive, read the content and use it in my custom widget .

In the constant.js file you can define text widget settings. is there an option to have a file picker as setting parameter?

if not, do you any option available to read a google shared file and display in a widget?

Also, is there a limit to value field in a text widget

{
placeholder: "Another setting",
key: "anotherUniqueKey",
value: "this is text",
type: "text",
},

Thanks for your help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.