Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@odensc/react-custom-properties
Advanced tools
A React component for applying CSS Variables (Custom Properties)
A React component for declaratively applying CSS Variables or CSS Custom Properties as the are officially known. For CSS variable usage see https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables
To get started install via npm
npm install react-custom-properties
You can then import the component into your code using ES5 require
var CustomProperties = require('react-custom-properties');
or ES6 imports
import CustomProperties from 'react-custom-properties';
This module provides a <CustomProperties />
component. When mounted it will, by default, apply any CSS variables
passed to the properties
component to its children.
So for example, your stylesheet may contain CSS Variables like this.
.header {
background: var(--branding-color);
}
And you can apply values to those variables like this.
import React, { Component } from 'react';
import CustomProperties from 'react-custom-properties';
class App extends Component {
render() {
return (
<div>
<CustomProperties properties={{ '--branding-color': '#FF0000' }}>
<div className="header">
this will have the background color #FF0000
</div>
</CustomProperties>
</div>
);
}
}
The CustomProperties
component can be nested so that properties set by parent instances are overridden by ones set by child instances. So for example...
Using the same stylesheet as before
import React, { Component } from 'react';
import CustomProperties from 'react-custom-properties';
class App extends Component {
render() {
return (
<div>
<CustomProperties properties={{ '--branding-color': '#FF0000' }}>
<div className="header">
this will have the background color #FF0000
</div>
<CustomProperties properties={{ '--branding-color': '#555555' }}>
<div className="header">
this will have the background color #555555
</div>
</CustomProperties>
</CustomProperties>
</div>
);
}
}
The CustomProperties
component accepts a boolean global
prop. By default the CSS Variables will only apply to the
component's children. When the global
prop is passed the CSS Variables will be set on the document root and will
therefor be globally applied to all styles.
Using the same stylesheet as before
import React, { Component } from 'react';
import CustomProperties from 'react-custom-properties';
class App extends Component {
render() {
return (
<div>
<CustomProperties
global
properties={{ '--branding-color': '#FF0000' }}
/>
<div className="header">
this will have the background color #FF0000
</div>
</div>
);
}
}
Any properties set by a non-global instance will take precedence over properties set by a global instance
git checkout -b my-new-feature
)npm run test
)git commit -am 'Add some feature'
)git push origin my-new-feature
)MIT
FAQs
A React component for applying CSS Variables (Custom Properties)
The npm package @odensc/react-custom-properties receives a total of 0 weekly downloads. As such, @odensc/react-custom-properties popularity was classified as not popular.
We found that @odensc/react-custom-properties demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.