Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@anomen/rethemeable
Advanced tools
Rethemeable provides utilities for producing and consuming themeable React components.
It doesn't define the notion of theme. A theme can be a list of CSS class names or a set of inline style directives.
It doesn't define how components apply themes. It is up to component to decide what and when to apply CSS class names or inline styles.
Instead Rethemeable define a way to propagate theme through React component tree.
It's up to component authors to declare the theming contract for each component.
It's up to consumers to fulfil the theming contract for each component.
Install from npm:
% npm install rethemeable
Define a themeable component:
import { themeable } from 'rethemeable'
import React from 'react'
@themeable
class Button extends React.Component {
render() {
let theme = this.theme
return (
<button className={theme.self}>
<i className={theme.icon} />
{this.props.children}
</button>
)
}
}
Now define a theme as a collection of styles for a set of React components. Styles for each component are isolated by an unique key within the theme:
import Button from 'widgets/Button'
let BootstrapTheme = {
[Button.theme]: {
self: 'btn btn-xs'
}
}
And configure it via <ApplyTheme />
component:
import { ApplyTheme } from 'rethemeable'
import React from 'react'
React.render(
<ApplyTheme theme={BootstrapTheme}>
<div>
<h1>This is an app</h1>
<Button>See, I don't have theme prop passed explicitly</Button>
</div>
</ApplyTheme>
)
Component <Button />
will receive theme
implicitly.
You can also pass theme directly to component via props if you need a more fine-grained control:
<Button theme={BootstrapTheme} />
If you don't want to use <ApplyTheme />
component but just apply some theme on a
themeable component you can use theme
function:
import { theme } from 'rethemeable'
import ThemeableButton from 'third-party-themeable-button'
let MyButton = theme(ThemeableButton, BootstrapTheme);
React.render(<MyButton>Hello, I'm themed!</MyButton>)
Rethemeable approach works well with CSS modules, as you can compose your theme from a set of CSS modules:
import Button from 'widgets/Button'
import Modal from 'widgets/Button'
import ButtonTheme from './Button.css'
import ModalTheme from './Modal.css'
let Theme = {
[Button.theme]: ButtonTheme,
[ModalTheme.theme]: ModalTheme
}
It can be desirable to chunk (or split) bundled assets in production, especially when dealing with larger sites.
When chunking themeable
components, the theme and themeable
components must
to be able to be loaded independently in order for a build pipeline (like
Webpack) to properly optimize chunk size and contents.
Separating the definition of theme keys from a given themeable
component
allows the keys, theme, and components to be loaded if and whenever they are
needed.
./key-registry.js
/** List of theme keys to connect classmaps with component themes */
export {
Button: Symbol('Button'),
Modal: Symbol('Modal')
}
./theme.js
/** Map themeKey Symbols to theme classmaps */
import { Button, Modal } from './key-registry';
import ButtonTheme from './button.css';
import ModalTheme from 'some-module/with-modal-styles.css';
const theme = {
[Button]: ButtonTheme,
[Modal]: ModalTheme
}
export { theme }
./Button.jsx
import { themeable } from 'rethemeable';
import { compAKey as themeKey } from './key-registry';
class Button {}
export default themeable(Button, {themeKey});
./Modal.jsx
import { themeable } from 'rethemeable';
import { compBKey as themeKey } from './key-registry';
class Modal {}
export default themeable(Modal, {themeKey});
./Layout.jsx
/** Provide theme to themeable components via context */
import Helmet from 'react-helmet';
import { theme } from './theme.js';
import { ApplyTheme } from 'rethemeable';
// map of asset paths extracted during build
import assets from 'assets-map.json';
class App {
/*
render(
<ApplyTheme theme={theme}>
<Helmet link={assets.theme.css} />
{this.props.children}
</ApplyTheme>
)
}
Without chunks, all components are hard dependencies of a theme. Therefore they must be chunked together to preserve the link of Symbol to theme. This can result bloated chunks and/or tedious maintenance of themes.
FAQs
Themeable React component utilities
We found that @anomen/rethemeable 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.