Giter Club home page Giter Club logo

react-with-styles-interface-aphrodite's Introduction

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';

or when you want to support automatic style flipping for an RTL (right-to-left) language page

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

Built-in RTL support

react-with-styles-interface-aphrodite now has built-in LTR/RTL context support in its with-rtl version. Specifically, it uses rtl-css-js to automatically flip styles (margin, padding, float, textAlign, etc.) that were written for an LTR page when the dir="rtl" attribute is applied. We recommend using react-with-direction's DirectionProvider at your top-level node to achieve best results.

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

import ThemedStyleSheet from 'react-with-styles/lib/ThemedStyleSheet';
import aphroditeInterfaceWithRTL from 'react-with-styles-interface-aphrodite/with-rtl';

ThemedStyleSheet.registerInterface(aphroditeInterfaceWithRTL);

...

import { withStyles, css } from react-with-styles`

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

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

The generated css would look like:

.container_r5r4of {
  background: #fff !important;
}

[dir="ltr"] .container_r5r4of {
  float: left !important;
}

[dir="rtl"] .container_r5r4of {
  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 default case, this would map to a style={{ background: '#fff', float: 'left' }} on the div in question. However, in the withRTL case, we would convert these styles into a unique classname (inlineStyles_emgbm1 in this instance) and generate the following css instead:

.inlineStyles_emgbm1 {
  background: #fff !important;
}

[dir="ltr"] .inlineStyles_emgbm1 {
  float: left !important;
}

[dir="rtl"] .inlineStyles_emgbm1 {
  float: right !important;
}

This behavior is due to some details of what is known at the time of style creation/resolution. Because of this, inline styles will always be converted to classnames when there is a flippable style. This may be slower than the default implementation and may be a poor choice if you are attempting to animate something using JS. If you do not want this behavior or if this behavior breaks your usage, react-with-styles-interface-aphrodite/with-rtl also exports a resolveNoRTL method which is exported by react-with-styles as cssNoRTL. cssNoRTL matches the behavior in the default implementation (no automatic style flipping).

react-with-styles-interface-aphrodite's People

Contributors

lencioni avatar gilbox avatar majapw avatar ljharb avatar greenkeeper[bot] avatar reklawnos avatar yzimet avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.