react-codepen-prefill
Version:
React component to create a button/link to prefill codepen.io with supplied code
128 lines (117 loc) • 4.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _excluded = ["target", "className", "style", "label"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function CodepenPrefill(props) {
var target = props.target,
className = props.className,
style = props.style,
label = props.label,
send = _objectWithoutProperties(props, _excluded);
return /*#__PURE__*/_react["default"].createElement("span", {
style: {
display: 'inline-block'
}
}, /*#__PURE__*/_react["default"].createElement("form", {
style: {
display: 'inline-block'
},
action: "https://codepen.io/pen/define",
method: "POST",
target: target,
rel: "noopener noreferrer"
}, /*#__PURE__*/_react["default"].createElement("input", {
type: "hidden",
name: "data",
value: JSON.stringify(send)
}), /*#__PURE__*/_react["default"].createElement("button", {
type: "submit",
className: className,
style: style
}, label)));
}
CodepenPrefill.defaultProps = {
// https://blog.codepen.io/documentation/api/prefill/
title: '',
// The title of the pen.
description: '',
// The description of the pen.
tags: [],
// an array of strings
editors: '111',
// Which editors are open. 1 is open. order is: HTML, CSS, JS.
layout: 'left',
// Optional layouts: top || left || right
html: '',
// The HTML code to fill in the HTML pane.
html_pre_processor: 'none',
// Optional values: "none" || "slim" || "haml" || "markdown"
css: '',
// The CSS code to fill in the CSS pane.
css_pre_processor: 'none',
// Optional values: "none" || "less" || "scss" || "sass" || "stylus"
css_starter: 'neither',
// Optional values: "normalize" || "reset" || "neither",
css_prefix: 'neither',
// Optional values: "autoprefixer" || "prefixfree" || "neither"
js: '',
// The JavaScript code to fill in the JS pane.
js_pre_processor: 'none',
// Optional values: "none" || "coffeescript" || "babel" || "livescript" || "typescript"
html_classes: '',
// CSS class to apply to html tag.
head: '',
// Content to include inside the HTML head tag.
css_external: '',
// Use semi-colon to separate multiple files.
js_external: '',
// Use semi-colon to separate multiple files.
// Optional values: true || false -
// When the Pen is saved, it will save as Private if logged in user has that privilege,
// otherwise it will save as public
"private": false,
// If supplied, the Pen will save as a fork of this id.
// Note it's not the slug, but ID.
// You can find the ID of a Pen with `window.CP.pen.id` in the browser console.
parent: null,
// component internal
label: 'Prefill CodePen',
target: '',
className: '',
style: {}
};
CodepenPrefill.propTypes = {
title: _propTypes["default"].string,
description: _propTypes["default"].string,
tags: _propTypes["default"].arrayOf(_propTypes["default"].string),
editors: _propTypes["default"].string,
layout: _propTypes["default"].string,
html: _propTypes["default"].string,
html_pre_processor: _propTypes["default"].string,
css: _propTypes["default"].string,
css_pre_processor: _propTypes["default"].string,
css_starter: _propTypes["default"].string,
css_prefix: _propTypes["default"].string,
js: _propTypes["default"].string,
js_pre_processor: _propTypes["default"].string,
html_classes: _propTypes["default"].string,
head: _propTypes["default"].string,
css_external: _propTypes["default"].string,
js_external: _propTypes["default"].string,
"private": _propTypes["default"].bool,
parent: _propTypes["default"].number,
// component internal
label: _propTypes["default"].string,
target: _propTypes["default"].string,
className: _propTypes["default"].string,
style: _propTypes["default"].object // eslint-disable-line react/forbid-prop-types
};
var _default = CodepenPrefill;
exports["default"] = _default;