Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

radium

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

radium - npm Package Compare versions

Comparing version 0.10.0 to 0.10.1

.eslintrc

32

docs/api/README.md

@@ -151,2 +151,34 @@ # Radium API

**Note**: `getBrowserStateEvents` uses the following React event listeners:
- `onMouseEnter`
- `onMouseLeave`
- `onMouseDown`
- `onMouseUp`
- `onFocus`
- `onBlur`
If you need to use Radium to style browser states but also need to add your own event listeners matching any of the 6 previously listed, simply call the corresponding Radium event handler in your own event handler:
React | Radium
------|-------
`onMouseEnter` | `radiumMouseEnter`
`onMouseLeave` | `radiumMouseLeave`
`onMouseDown` | `radiumMouseDown`
`onMouseUp` | `radiumMouseUp`
`onFocus` | `radiumFocus`
`onBlur` | `radiumBlur`
Example:
```js
handleFocus: function () {
this.radiumFocus();
// Your custom event behavior.
}
```
Event listeners passed in as props from another component are handled automatically.
#### Signature

@@ -153,0 +185,0 @@

26

examples/app.jsx

@@ -11,3 +11,4 @@ var React = require('react');

md: '(min-width: 992px)',
lg: '(min-width: 1200px)'
lg: '(min-width: 1200px)',
smallOnly: '(max-width: 600px)'
};

@@ -49,2 +50,25 @@

}
},
{
mediaQueries: {
smallOnly: [
{
body: {
background: "gray"
}
}
],
"(max-width: 500px)": [
{
body: {
background: "blue"
}
},
{
"p, h1": {
color: "white"
}
}
]
}
}

@@ -51,0 +75,0 @@ ]}

var React = require('react');
var CSSPropertyOperations = require('react/lib/CSSPropertyOperations');
var reduce = require('lodash/collection/reduce');
var MatchMediaItem = require('../mixins/match-media-item');

@@ -10,8 +11,10 @@ function buildCssString (selector, rules) {

return selector + "{" +
return selector + '{' +
CSSPropertyOperations.createMarkupForStyles(rules) +
"}";
'}';
}
var Style = React.createClass({
mixins: [ MatchMediaItem ],
propTypes: {

@@ -24,4 +27,52 @@ scopeSelector: React.PropTypes.string,

return {
scopeSelector: ""
scopeSelector: ''
};
},
_buildStyles: function (stylesArr) {
var styles = reduce(stylesArr, function (accumulator, item) {
var selector = Object.keys(item)[0];
var rules = item[selector];
if (selector === 'mediaQueries') {
accumulator += this._buildMediaQueryString(rules);
} else {
var completeSelector = (this.props.scopeSelector ?
this.props.scopeSelector + ' ' :
'') +
selector;
accumulator += buildCssString(completeSelector, rules);
}
return accumulator;
}, '', this);
return styles;
},
_buildMediaQueryString: function (mediaQueryObj) {
var contextMediaQueries = this._getContextMediaQueries();
var mediaQueryString = '';
Object.keys(mediaQueryObj).forEach(function (query) {
var completeQuery = contextMediaQueries[query] ?
contextMediaQueries[query] :
query;
mediaQueryString += '@media ' + completeQuery + '{' +
this._buildStyles(mediaQueryObj[query]) +
'}';
}.bind(this));
return mediaQueryString;
},
_getContextMediaQueries: function () {
var contextMediaQueries = {};
if (this.context && this.context.mediaQueries) {
Object.keys(this.context.mediaQueries).forEach(function (query) {
contextMediaQueries[query] = this.context.mediaQueries[query].media;
}.bind(this));
}
return contextMediaQueries;
},

@@ -34,12 +85,6 @@

var styles = reduce(this.props.rules, function (s, item) {
var selector = Object.keys(item)[0];
var rules = item[selector];
var completeSelector = this.props.scopeSelector + " " + selector;
var styles = this._buildStyles(this.props.rules);
return s += buildCssString(completeSelector, rules);
}, "", this);
return React.createElement(
"style",
'style',
{dangerouslySetInnerHTML: {__html: styles}}

@@ -46,0 +91,0 @@ );

57

modules/mixins/browser-state.js

@@ -0,2 +1,13 @@

var mouseUpListener = require('./util/mouse-up-listener');
var BrowserStateMixin = {
componentDidMount: function () {
this.mouseUpListener = mouseUpListener.subscribe(this.radiumMouseUp);
},
componentWillUnmount: function () {
this.mouseUpListener.remove();
},
getInitialState: function () {

@@ -12,8 +23,7 @@ return {

return {
onMouseEnter: this._handleMouseEnter,
onMouseLeave: this._handleMouseLeave,
onMouseDown: this._handleMouseDown,
onMouseUp: this._handleMouseUp,
onFocus: this._handleFocus,
onBlur: this._handleBlur
onMouseEnter: this.radiumMouseEnter,
onMouseLeave: this.radiumMouseLeave,
onMouseDown: this.radiumMouseDown,
onFocus: this.radiumFocus,
onBlur: this.radiumBlur
};

@@ -30,4 +40,4 @@ },

_handleMouseEnter: function (ev) {
this._callRadiumHandler("onMouseEnter", ev);
radiumMouseEnter: function (ev) {
this._callRadiumHandler('onMouseEnter', ev);

@@ -39,13 +49,12 @@ this.setState({

_handleMouseLeave: function (ev) {
this._callRadiumHandler("onMouseLeave", ev);
radiumMouseLeave: function (ev) {
this._callRadiumHandler('onMouseLeave', ev);
this.setState({
hover: false,
active: false
hover: false
});
},
_handleMouseDown: function (ev) {
this._callRadiumHandler("onMouseDown", ev);
radiumMouseDown: function (ev) {
this._callRadiumHandler('onMouseDown', ev);

@@ -57,12 +66,12 @@ this.setState({

_handleMouseUp: function (ev) {
this._callRadiumHandler("onMouseUp", ev);
this.setState({
active: false
});
radiumMouseUp: function () {
if (this.state.active) {
this.setState({
active: false
});
}
},
_handleFocus: function (ev) {
this._callRadiumHandler("onFocus", ev);
radiumFocus: function (ev) {
this._callRadiumHandler('onFocus', ev);

@@ -74,4 +83,4 @@ this.setState({

_handleBlur: function (ev) {
this._callRadiumHandler("onBlur", ev);
radiumBlur: function (ev) {
this._callRadiumHandler('onBlur', ev);

@@ -78,0 +87,0 @@ this.setState({

@@ -5,2 +5,3 @@ var React = require('react');

var matchers = {};
var matchedQueries = {};

@@ -25,10 +26,10 @@ var mediaChangeCallback;

init: function (mediaQueryOpts) {
if (!mediaQueryOpts || typeof window === "undefined") {
if (!mediaQueryOpts || typeof window === 'undefined') {
return;
}
for (var key in mediaQueryOpts) {
Object.keys(mediaQueryOpts).forEach(function (key) {
matchers[key] = window.matchMedia(mediaQueryOpts[key]);
matchers[key].addListener(onMediaChange);
}
});
},

@@ -47,18 +48,8 @@

for (var key in matchers) {
matchers[key].removeListener(handleMediaChange);
}
Object.keys(matchers).forEach(function (key) {
matchers[key].removeListener(onMediaChange);
});
},
getMatchedMedia: function () {
if (!matchers) {
return;
}
var matchedQueries = {};
for (var key in matchers) {
matchedQueries[key] = matchers[key].matches;
}
return matchedQueries;

@@ -68,2 +59,9 @@ },

handleMediaChange: debounce(function () {
Object.keys(matchers).forEach(function (key) {
matchedQueries[key] = {
matches: matchers[key].matches,
media: matchers[key].media
};
});
this.forceUpdate();

@@ -70,0 +68,0 @@ }, 10, {

@@ -35,13 +35,15 @@ var merge = require('lodash/object/merge');

if (componentMediaQueries && componentMediaQueries[key]) {
var activeMediaQuery = mediaQuery;
if (componentMediaQueries &&
componentMediaQueries[key] &&
componentMediaQueries[key].matches) {
var activeMediaQuery = mediaQuery;
if (!activeMediaQuery) {
return;
}
if (!activeMediaQuery) {
return;
}
merge(
mediaQueryStyles,
activeMediaQuery
);
merge(
mediaQueryStyles,
activeMediaQuery
);
}

@@ -115,5 +117,5 @@ });

} else {
for (var key in styles.computed) {
Object.keys(styles.computed).forEach(function (key) {
computedStyles[key] = styles.computed[key](styles);
}
});
}

@@ -120,0 +122,0 @@

{
"name": "radium",
"version": "0.10.0",
"version": "0.10.1",
"description": "A set of tools to manage inline styles on React elements",

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

"peerDependencies": {
"react": "0.12.x"
"react": ">=0.12.0 <0.14.0"
},

@@ -31,4 +31,6 @@ "dependencies": {

"devDependencies": {
"gulp": "^3.8.11",
"gulp-eslint": "^0.6.0",
"jsx-loader": "^0.12.2",
"react": "0.12.x",
"react": ">=0.12.0 <0.14.0",
"webpack": "^1.5.3",

@@ -35,0 +37,0 @@ "webpack-dev-server": "^1.7.0"

@@ -105,1 +105,5 @@ # Radium

```
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md)

Sorry, the diff of this file is too big to display

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