Package detail

react-with-styles-interface-aphrodite

airbnb72kMIT6.0.1

react-with-styles interface for Aphrodite

react-with-styles, aphrodite

readme

react-with-styles-interface-aphrodite Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

Interface to use react-with-styles with Aphrodite.

Import

import aphroditeInterface from 'react-with-styles-interface-aphrodite';

or when you need to disable !important:

import aphroditeInterface from 'react-with-styles-interface-aphrodite/no-important';

Built-in RTL support

react-with-styles-interface-aphrodite has built-in LTR/RTL context support. Specifically, it uses rtl-css-js to automatically flip styles (margin, padding, float, textAlign, etc.) that were written for an LTR page when your app is wrapped in react-with-direction's DirectionProvider with direction set to DIRECTIONS.RTL.

It accomplishes this by providing a directional create and resolve method. react-with-styles automatically uses the correct create method based on the direction value set in context and then passes down the appropriate resolve method as a prop named css.

For instance, if you were to write your styles as follows:

import ThemedStyleSheet from 'react-with-styles/lib/ThemedStyleSheet';
import aphroditeInterface from 'react-with-styles-interface-aphrodite';
import { withStyles, css } from 'react-with-styles';

ThemedStyleSheet.registerInterface(aphroditeInterface);

...

function MyComponent({ css }) {
  return <div {...css(styles.container)}>Hello World</div>;
}

export default withStyles(() => ({
  container: {
    background: '#fff',
    float: 'left',
  },
}))(MyComponent);

The generated css for an app where you set <DirectionProvider direction={DIRECTIONS.LTR}> at the top would look like:

.container_r5r4of {
  background: #fff !important;
  float: 'left' !important;
}

whereas if you had set <DirectionProvider direction={DIRECTIONS.RTL}>, the generated css would be:

.container_kui6s4 {
  background: #fff !important;
  float: 'right' !important;
}

If you used an inline style instead:

import { css } from 'react-with-styles';

export default function MyComponent() {
  return <div {...css({ background: '#fff', float: 'left' })}>Hello World</div>;
}

In the case where <DirectionProvider direction={DIRECTIONS.LTR}> is wrapping your component, this would map to a style={{ background: '#fff', float: 'left' }} on the div in question. If <DirectionProvider direction={DIRECTIONS.RTL}> is present instead, this would simply apply style={{ background: '#fff', float: 'right' }} to the div.

changelog

Changelog

v6.0.1

  • [fix] Update rtl-css-js ^1.13.0 -> ^1.13.1

v6.0.0

  • [Deps] Include react-with-styles v4.0.0 in peer deps
  • [breaking] [Dev Deps] Update @babel*, airbnb-js-shims, aphrodite, babel-plugin-transform-replace-object-assign, babel-preset-airbnb, chai, eslint*, prop-types, react, react-dom, sinon-sandbox and drop support for node < 6
  • [Deps] update object.entries, rtl-css-js
  • [Dev Deps] update eslint, eslint-config-airbnb, eslint-plugin-import, eslint-plugin-jsx-a11y, eslint-plugin-react, rimraf, safe-publish-latest, airbnb-js-shims

v5.0.1

  • [Deps] Replace array-flatten with array.prototype.flat
  • [Deps] Update has and rtl-css-js
  • [Dev] Update devDependencies

v5.0.0

  • Remove support for Aphrodite v1 and earlier

v4.0.2

  • Add support for Aphrodite v2

v4.0.1

  • Fix this reference in create and resolve methods

v4.0.0

  • Remove with-rtl interface in favor of separate LTR/RTL create and resolve methods

v3.1.1

  • Allow boolean values for styles to run without failure

v3.1.0

  • Add RTL support for linear-gradient

v3.0.1

  • Fix for with-rtl interface when an aphrodite style is called multiple times

v3.0.0

  • Revert default export to v1 version and export with-rtl interface in addition

v2.1.0

  • Add RTL support for borderLeftWidth, translateX, translate, and translate3d

v2.0.1

  • Fix RTL support for pseudoselectors and match media queries

v2.0.0

  • Add RTL support in the resolve method

v1.2.0

  • Add support for using Aphrodite in no-important mode, which disables adding !important to every style.

v1.1.1

  • This release reverts all of the changes from 1.1.0, so inline styles no longer include vendor prefixes.

v1.1.0

  • Inline styles will now automatically include vendor prefixes.

v1.0.0

  • Initial release.