There is already a custom widget available in the gallery
Not sure if this what you are looking for. Maybe this helps.