Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Maulik
Maulik

Posted on

     

Develop pluggable widgets for fun

Development is easy and fun with the proper development tools, less manual work and some fancy things we love.

This article is about creating our own widget and integrate it into a website that helps us in the development or looks cool or does both.

The idea here is unlike components, widgets will be rendered automatically, floats on the UI and can be movable and resizable like the desktop or the mobile widgets.

Here is the sample template of the widget that I have created to create widgets.

// IFFE for scoping(function () {    let html = ``;    let styles = ``;    // Do not use window.onload as it will override other mehtods instead adding new listner    window.addEventListener('load', function () {        // Create container div and append it to body        // Code to make the div resizable        // Code to make the div movable        // Widget specific javascript code    });})();
Enter fullscreen modeExit fullscreen mode

Let's see an example of such a widget- a Todo widget

I have cloned a sample dashboard from a codepen pen and imported the widget file in it. You can see a floating todo widget floating at top right that shows a list of todo tasks. This widget uses local storage so even on reload, you can see your previously added todo list.

Here is the git repo for that todo widget. You also will find a sample template where you can put your html, css and JS code and try your idea.

GitHub logo Maulikdes / JS-Widgets

This repo consists of single file widget written in pure JS, HTML and CSS

We can create any kind of widget that we want. Here are some other examples

  • clock

  • or a music player

What else you want as a widget? please comment

Also, if you see the code, you will find it a bit ugly and you have to keep in mind that the style of your widget should not affect the existing application and also need to think about scope... which is a bit difficult in vanilla javascript as you have to write code for it. But, it would be easy for us to write the same code in angular or other frameworks, right?

Angular has the functionality of creating a single file web-element which can be used in any site developed in any framework or even in simple HTML after exporting the angular component and importing it in any project.

These widgets also have an advantage over plugins that they have more access to plugins. My next article will be creating this type of widgets using angular.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

An ever-smiling full-stack developer, specializing in the rapid development of custom web applications. Always eager to learn new technologies and concepts and share knowledge.
  • Location
    Ahmedabad
  • Education
    BE in Information Technology
  • Work
    Software Architect at Yali Technologies Private Limtied
  • Joined

More fromMaulik

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp