All Projects → airbnb → React With Direction

airbnb / React With Direction

Licence: mit
Components to provide and consume RTL or LTR direction in React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React With Direction

react-table-hoc-draggable-columns
ReactTable HOC for draggable columns
Stars: ✭ 27 (-84.66%)
Mutual labels:  higher-order-component, hoc
Next Nprogress
Next.js HOC to integrate NProgress inside your app
Stars: ✭ 145 (-17.61%)
Mutual labels:  higher-order-component, hoc
react-animation-frame
A React higher-order component that invokes a callback in a wrapped component via requestAnimationFrame
Stars: ✭ 47 (-73.3%)
Mutual labels:  higher-order-component, hoc
react-drip-form
☕ HoC based React forms state manager, Support for validation and normalization.
Stars: ✭ 66 (-62.5%)
Mutual labels:  higher-order-component, hoc
Flagged
Feature Flags for React made easy with hooks, HOC and Render Props
Stars: ✭ 97 (-44.89%)
Mutual labels:  higher-order-component, hoc
rrx
⚛️ Minimal React router using higher order components
Stars: ✭ 69 (-60.8%)
Mutual labels:  higher-order-component, hoc
addhoc
Handy little helper to create proper React HOC functions complete with hoisted statics and forwarded refs
Stars: ✭ 40 (-77.27%)
Mutual labels:  higher-order-component, hoc
react-app-loader
Production ready library for handling Microfrontends
Stars: ✭ 75 (-57.39%)
Mutual labels:  higher-order-component, hoc
Incompose
A inferno utility belt for function components and higher-order components
Stars: ✭ 76 (-56.82%)
Mutual labels:  higher-order-component, hoc
React Bps
🔱 Create breakpoints to your component props
Stars: ✭ 64 (-63.64%)
Mutual labels:  higher-order-component, hoc
Recompact
⚛ A set of React higher-order components utilities. Drop-in replacement for recompose.
Stars: ✭ 419 (+138.07%)
Mutual labels:  higher-order-component, hoc
React Nprogress
⌛️ A React primitive for building slim progress bars.
Stars: ✭ 173 (-1.7%)
Mutual labels:  higher-order-component, hoc
Hocs
🍱 Higher-Order Components for React
Stars: ✭ 1,784 (+913.64%)
Mutual labels:  higher-order-component, hoc
Neoform
✅ React form state management and validation
Stars: ✭ 162 (-7.95%)
Mutual labels:  higher-order-component, hoc
Pinlayout
Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]
Stars: ✭ 1,870 (+962.5%)
Mutual labels:  rtl
Rtlmd
rtl markdown editor
Stars: ✭ 152 (-13.64%)
Mutual labels:  rtl
React Spatial Navigation
HOC-based Spatial Navigation (key navigation) solution for React
Stars: ✭ 128 (-27.27%)
Mutual labels:  hoc
Bootstrap 3 Arabic
bootstrap 3 arabic
Stars: ✭ 124 (-29.55%)
Mutual labels:  rtl
Dana
Dynamically Allocated Neural Network Accelerator for the RISC-V Rocket Microprocessor in Chisel
Stars: ✭ 160 (-9.09%)
Mutual labels:  rtl
Logic
CMake, SystemVerilog and SystemC utilities for creating, building and testing RTL projects for FPGAs and ASICs.
Stars: ✭ 149 (-15.34%)
Mutual labels:  rtl

react-with-direction Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

Components to support both right-to-left (RTL) and left-to-right (LTR) layouts in React.

Supporting RTL or switching between different directions can be tricky. Most browsers have built-in support for displaying markup like paragraphs, lists, and tables. But what about interactive or complex custom UI components? In a right-to-left layout, a photo carousel should advance in the opposite direction, and the primary tab in a navigation control should the rightmost, for example.

This package provides components to simplify that effort.

withDirection

Use withDirection when your component needs to change based on the layout direction. withDirection is an HOC that consumes the direction from React context and passes it as a direction prop to the wrapped component. The wrapped component can then pivot its logic to accommodate each direction.

Usage example:

import withDirection, { withDirectionPropTypes, DIRECTIONS } from 'react-with-direction';

function ForwardsLabel({ direction }) {
  return (
    <div>
      Forwards
      {direction === DIRECTIONS.LTR && <img src="arrow-right.png" />}
      {direction === DIRECTIONS.RTL && <img src="arrow-left.png" />}
    </div>
  );
}
ForwardsLabel.propTypes = {
  ...withDirectionPropTypes,
};

export default withDirection(ForwardsLabel);

DirectionProvider

Use DirectionProvider at the top of your app to set the direction context, which can then be consumed by components using withDirection.

You should set the direction prop based on the language of the content being rendered; for example, DIRECTIONS.RTL (right-to-left) for Arabic or Hebrew, or DIRECTIONS.LTR (left-to-right) for English or most other languages.

DirectionProvider components can also be nested, so that the direction can be overridden for certain branches of the React tree.

DirectionProvider will render its children inside of a <div> element with a dir attribute set to match the direction prop, for example: <div dir="rtl">. This maintains consistency when being rendered in a browser. To render inside of a <span> instead of a div, set the inline prop to true.

Usage example:

import DirectionProvider, { DIRECTIONS } from 'react-with-direction/dist/DirectionProvider';
<DirectionProvider direction={DIRECTIONS.RTL}>
  <div>
    <ForwardsLabel />
  </div>
</DirectionProvider>

AutoDirectionProvider

Use AutoDirectionProvider around, for example, user-generated content where the text direction is unknown or may change. This renders a DirectionProvider with the direction prop automatically set based on the text prop provided.

Direction will be determined based on the first strong LTR/RTL character in the text string. Strings with no strong direction (e.g., numbers) will inherit the direction from its nearest DirectionProvider ancestor or default to LTR.

Usage example:

import AutoDirectionProvider from 'react-with-direction/dist/AutoDirectionProvider';
<AutoDirectionProvider text={userGeneratedContent}>
  <ExampleComponent>
    {userGeneratedContent}
  </ExampleComponent>
</AutoDirectionProvider>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].