a codebin widget for embeddable editable live demos built on top of CodeMirror
npm i @potch/html-bin
import { createBin } from "@potch/html-bin";
import { createBin } from "https://unpkg.com/@potch/html-bin/build/index.min.js";
create a bin component.
Options:
container(optional Element): will automatically append the bin if providedextraClasses: a string of extra CSS classes to append to the bin elementsources: object with optional{ js, css, html }strings of source to put in the corresponding editorssplitMode: (defaulttrue) whether to have the preview in split screen with code tabs.split: number from [0, 1] specifying the ratio between the editor and preview panes. defaults to0.5width: CSS string to override default--bin-widthvalue. defaults to100%height: CSS string to override default--bin-heightvalue. defaults to512px
Returns object with the following fields:
el: Element of the outermost HTML element of the bineditors: contains{ js, css, html }properties with the CodeMirror instances for each editor tabactiveTab: a signal representing the currently active editor tabstart: call this function if you did not provide thecontaineroption after attachingelto the DOMteardown: call this if you are removing and destroying the bin to disconnect all listeners