@kynikos/react-components
Advanced tools
| // This file is part of react-components | ||
| // Copyright (C) 2018-present Dario Giovannetti <dev@dariogiovannetti.net> | ||
| // Licensed under MIT | ||
| // https://github.com/kynikos/lib.js.react-components/blob/master/LICENSE | ||
| import {createElement as h, useRef, useEffect} from 'react' | ||
| import SignaturePad_ from 'signature_pad' | ||
| export default function SignaturePad({ | ||
| defaultData, padRef, size, scale, style, readOnly, onBegin, | ||
| }) { | ||
| const canvas = useRef(null) | ||
| useEffect(() => { | ||
| if (!padRef.current) { | ||
| if (scale) { | ||
| const context = canvas.current.getContext('2d') | ||
| context.scale(...scale) | ||
| } | ||
| const pad = new SignaturePad_(canvas.current, { | ||
| onBegin, | ||
| }) | ||
| if (defaultData) pad.fromData(defaultData) | ||
| padRef.current = pad | ||
| } | ||
| }, [size, scale]) | ||
| useEffect(() => { | ||
| if (readOnly) padRef.current.off() | ||
| else padRef.current.on() | ||
| }, [readOnly]) | ||
| return h('canvas', { | ||
| ref: canvas, | ||
| width: size[0], | ||
| height: size[1], | ||
| style, | ||
| }) | ||
| } |
+9
-11
| { | ||
| "name": "@kynikos/react-components", | ||
| "version": "1.1.1", | ||
| "version": "1.2.0", | ||
| "author": "Dario Giovannetti", | ||
@@ -14,15 +14,13 @@ "description": "React components.", | ||
| ], | ||
| "scripts": { | ||
| "compile": "./node_modules/.bin/babel src --out-dir dist" | ||
| }, | ||
| "dependencies": { | ||
| "react": "^16.10.2", | ||
| "react-dom": "^16.10.2" | ||
| "react": "^16.13.1", | ||
| "react-dom": "^16.13.1", | ||
| "signature_pad": "^3.0.0-beta.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/cli": "^7.6.2", | ||
| "@babel/core": "^7.6.2", | ||
| "@babel/preset-env": "^7.6.2", | ||
| "eslint": "^6.5.1", | ||
| "eslint-plugin-babel": "^5.3.0" | ||
| "@babel/cli": "^7.10.5", | ||
| "@babel/core": "^7.11.4", | ||
| "@babel/preset-env": "^7.11.0", | ||
| "eslint": "^6.8.0", | ||
| "eslint-plugin-babel": "^5.3.1" | ||
| }, | ||
@@ -29,0 +27,0 @@ "babel": { |
@@ -6,6 +6,6 @@ // This file is part of react-components | ||
| const {createElement: h, Children} = require('react') | ||
| import {createElement as h, Children} from 'react' | ||
| module.exports = function GeoMapLink({ | ||
| export function GeoMapLink({ | ||
| query, | ||
@@ -12,0 +12,0 @@ lat = 0, |
+4
-4
@@ -6,8 +6,8 @@ // This file is part of react-components | ||
| const {Component, createElement} = require('react') | ||
| const ReactDOM = require('react-dom') | ||
| const ReactDOMServer = require('react-dom/server') | ||
| import {Component, createElement} from 'react' | ||
| import ReactDOM from 'react-dom' | ||
| import ReactDOMServer from 'react-dom/server' | ||
| module.exports = class Iframe extends Component { | ||
| export class Iframe extends Component { | ||
| render() { | ||
@@ -14,0 +14,0 @@ return createElement('iframe', { |
| "use strict"; | ||
| // This file is part of react-components | ||
| // Copyright (C) 2018-present Dario Giovannetti <dev@dariogiovannetti.net> | ||
| // Licensed under MIT | ||
| // https://github.com/kynikos/lib.js.react-components/blob/master/LICENSE | ||
| var _require = require('react'), | ||
| h = _require.createElement, | ||
| Children = _require.Children; | ||
| module.exports = function GeoMapLink(_ref) { | ||
| var query = _ref.query, | ||
| _ref$lat = _ref.lat, | ||
| lat = _ref$lat === void 0 ? 0 : _ref$lat, | ||
| _ref$lon = _ref.lon, | ||
| lon = _ref$lon === void 0 ? 0 : _ref$lon, | ||
| children = _ref.children; | ||
| var coords = [lat, lon].join(','); | ||
| return h('a', { | ||
| href: window.navigator.platform.match(/iPad|iPhone|iPod/i) == null ? "geo:".concat(coords, "?q=").concat(query || coords) // TODO: The "geo:" URI scheme doesn't work on Safari yet | ||
| // TODO: Apparently putting the coordinates in place of 0,0 doesn't work | ||
| : "maps:0,0?q=".concat(query || coords) | ||
| }, Children.toArray(children)); | ||
| }; |
| "use strict"; | ||
| function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
| function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
| function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
| function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
| function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
| function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
| function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
| // This file is part of react-components | ||
| // Copyright (C) 2018-present Dario Giovannetti <dev@dariogiovannetti.net> | ||
| // Licensed under MIT | ||
| // https://github.com/kynikos/lib.js.react-components/blob/master/LICENSE | ||
| var _require = require('react'), | ||
| Component = _require.Component, | ||
| createElement = _require.createElement; | ||
| var ReactDOM = require('react-dom'); | ||
| var ReactDOMServer = require('react-dom/server'); | ||
| module.exports = | ||
| /*#__PURE__*/ | ||
| function (_Component) { | ||
| _inherits(Iframe, _Component); | ||
| function Iframe() { | ||
| _classCallCheck(this, Iframe); | ||
| return _possibleConstructorReturn(this, _getPrototypeOf(Iframe).apply(this, arguments)); | ||
| } | ||
| _createClass(Iframe, [{ | ||
| key: "render", | ||
| value: function render() { | ||
| return createElement('iframe', { | ||
| // Setting display:none makes it unprintable in Chrome | ||
| style: { | ||
| width: '0', | ||
| height: '0', | ||
| border: 'none', | ||
| margin: '0' | ||
| } | ||
| }); | ||
| } | ||
| }, { | ||
| key: "componentDidMount", | ||
| value: function componentDidMount() { | ||
| this.componentDidUpdate(); | ||
| } | ||
| }, { | ||
| key: "componentDidUpdate", | ||
| value: function componentDidUpdate() { | ||
| // TODO: Use the following if browsers stop supporting document.write() | ||
| // The problem is that this won't render any external images | ||
| // embedded with <img> elements | ||
| // iframe = ReactDOM.findDOMNode(this) | ||
| // if iframe | ||
| // iframe.src = URL.createObjectURL(new Blob([ | ||
| // ReactDOMServer.renderToString(@props.html) | ||
| // ], {type: 'text/html'})) | ||
| var iframe = ReactDOM.findDOMNode(this); | ||
| var doc = iframe.contentDocument; | ||
| if (doc) { | ||
| doc.open(); | ||
| doc.write("<!doctype html>\n".concat(ReactDOMServer.renderToString(this.props.html))); | ||
| doc.close(); | ||
| } | ||
| } | ||
| }, { | ||
| key: "print", | ||
| value: function print() { | ||
| var iframe = ReactDOM.findDOMNode(this); | ||
| var win = iframe.contentWindow; | ||
| if (win) { | ||
| win.print(); | ||
| } | ||
| } | ||
| }]); | ||
| return Iframe; | ||
| }(Component); |
5094
-45.73%3
50%5
-16.67%103
-38.69%+ Added
+ Added
Updated
Updated