New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-cosmos-background-proxy

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cosmos-background-proxy - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.idea/watcherTasks.xml

75

dist/index.js

@@ -7,3 +7,3 @@ 'use strict';

var _templateObject = _taggedTemplateLiteral(['\n body {\n ', '\n }\n '], ['\n body {\n ', '\n }\n ']);
var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -18,25 +18,72 @@ var _react = require('react');

function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
exports.default = function (setupFunction) {
var BackgroundProxy = function BackgroundProxy(props) {
var nextProxy = props.nextProxy,
rest = _objectWithoutProperties(props, ['nextProxy']);
if (setupFunction) setupFunction();
var NextProxy = nextProxy.value,
next = nextProxy.next;
var BackgroundProxy = function (_React$Component) {
_inherits(BackgroundProxy, _React$Component);
function BackgroundProxy(props) {
_classCallCheck(this, BackgroundProxy);
if (setupFunction) setupFunction();
var _this = _possibleConstructorReturn(this, (BackgroundProxy.__proto__ || Object.getPrototypeOf(BackgroundProxy)).call(this, props));
if (rest.fixture.background) {
// eslint-disable-next-line no-unused-expressions
(0, _emotion.injectGlobal)(_templateObject, (0, _emotion.css)(rest.fixture.background));
_this.state = {
classname: (0, _emotion.css)(props.fixture.background)
};
return _this;
}
return _react2.default.createElement(NextProxy, Object.assign({}, rest, { nextProxy: next() }));
};
_createClass(BackgroundProxy, [{
key: 'componentDidMount',
value: function componentDidMount() {
document.body.classList.add(this.state.classname);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
document.body.classList.remove(this.state.classname);
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
if (prevState.classname !== this.state.classname) {
var body = document.body;
body.classList.remove(prevState.classname);
body.classList.add(this.state.classname);
}
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
nextProxy = _props.nextProxy,
rest = _objectWithoutProperties(_props, ['nextProxy']);
var NextProxy = nextProxy.value,
next = nextProxy.next;
return _react2.default.createElement(NextProxy, Object.assign({}, rest, { nextProxy: next() }));
}
}], [{
key: 'getDerivedStateFromProps',
value: function getDerivedStateFromProps(props) {
return {
classname: (0, _emotion.css)(props.fixture.background)
};
}
}]);
return BackgroundProxy;
}(_react2.default.Component);
return BackgroundProxy;
};

3

package.json
{
"name": "react-cosmos-background-proxy",
"version": "1.0.0",
"version": "1.0.1",
"description": "Easily apply a background for a fixture's playground and load global css",

@@ -24,2 +24,3 @@ "main": "dist/index.js",

"dependencies": {
"emotion": "^9.2.6",
"react": "^16.4.0",

@@ -26,0 +27,0 @@ "react-dom": "^16.4.0"

@@ -5,2 +5,8 @@ # react-cosmos-background-proxy

#### Installation
```
npm install --save-dev react-cosmos-background-proxy
```
## Usage

@@ -12,7 +18,5 @@

// cosmos.proxies.js
import createBackgroundProxy from "react-cosmos-background-proxy";
import createBackgroundProxy from 'react-cosmos-background-proxy';
export default [
createBackgroundProxy()
];
export default [createBackgroundProxy()];
```

@@ -26,3 +30,3 @@

background: {
backgroundColor: 'white'
backgroundColor: 'white'
}

@@ -36,12 +40,12 @@ };

// cosmos.proxies.js
import createBackgroundProxy from "react-cosmos-background-proxy";
import createBackgroundProxy from 'react-cosmos-background-proxy';
export default [
createBackgroundProxy(() => {
// this will be invoked for every fixture
require('node_modules/some-css-framework/dist/styles.css');
})
createBackgroundProxy(() => {
// this will be invoked once when the playground is loaded
require('node_modules/some-css-framework/dist/styles.css');
})
];
```
_Contributions are more than welcome! :beers:_
_Contributions are more than welcome! :beers:_
import React from 'react';
import { injectGlobal, css } from 'emotion';
import { css } from 'emotion';
export default (setupFunction) => {
const BackgroundProxy = (props) => {
const { nextProxy, ...rest } = props;
const { value: NextProxy, next } = nextProxy;
if (setupFunction) setupFunction();
if (setupFunction) setupFunction();
class BackgroundProxy extends React.Component {
constructor(props) {
super(props);
if (rest.fixture.background) {
// eslint-disable-next-line no-unused-expressions
injectGlobal`
body {
${css(rest.fixture.background)}
}
`;
this.state = {
classname: css(props.fixture.background)
};
}
return <NextProxy {...rest} nextProxy={next()} />;
};
componentDidMount() {
document.body.classList.add(this.state.classname);
}
componentWillUnmount() {
document.body.classList.remove(this.state.classname);
}
static getDerivedStateFromProps(props) {
return {
classname: css(props.fixture.background)
};
}
componentDidUpdate(prevProps, prevState) {
if (prevState.classname !== this.state.classname) {
const body = document.body;
body.classList.remove(prevState.classname);
body.classList.add(this.state.classname);
}
}
render() {
const { nextProxy, ...rest } = this.props;
const { value: NextProxy, next } = nextProxy;
return <NextProxy {...rest} nextProxy={next()} />;
}
}
return BackgroundProxy;
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc