npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

styled-bidi

v1.0.0

Published

A styled-components wrapper with automatic RTL/LTR directional CSS flipping and theme token merging.

Readme

styled-bidi

A lightweight wrapper around styled-components that adds automatic RTL/LTR directional CSS flipping and theme token merging — so you write styles once and they just work in both directions.

Features

  • Automatic BiDi flippingmargin-left becomes margin-right in LTR, and vice versa. Covers margins, paddings, borders, border-radii, positioning, and text alignment.
  • Theme token merging — Deep-merges component-level design tokens from your theme with instance styles.
  • $style prop — Override styles per-instance without creating a new component.
  • Zero config — Works with your existing styled-components theme provider.
  • Tiny — No dependencies beyond styled-components.

Install

npm install styled-bidi styled-components

Quick Start

import { styledBidi } from 'styled-bidi';

const Card = styledBidi('Card', 'div', ({ theme }) => ({
  padding: '16px',
  marginRight: '12px',           // ← flipped to marginLeft in LTR
  borderLeft: '3px solid blue',  // ← flipped to borderRight in LTR
  borderTopLeftRadius: '8px',    // ← flipped to borderTopRightRadius in LTR
  backgroundColor: theme.colors?.surface || '#fff',
}));

That's it. Render <Card /> inside a <ThemeProvider> and directional properties are handled automatically based on theme.direction.

How It Works

1. Direction Flipping

Set direction in your theme to control the behavior:

| theme.direction | Behavior | |---|---| | 'rtl' (default) | Styles are used as-is (RTL is the base direction) | | 'ltr' | Directional properties are flipped | | 'single' | No flipping — styles pass through unchanged |

import { ThemeProvider } from 'styled-components';

// RTL app — styles used as written
<ThemeProvider theme={{ direction: 'rtl' }}>
  <Card />
</ThemeProvider>

// LTR app — directional props auto-flipped
<ThemeProvider theme={{ direction: 'ltr' }}>
  <Card />
</ThemeProvider>

Properties That Flip

| RTL (as written) | LTR (auto-flipped) | |---|---| | left / right | right / left | | marginLeft / marginRight | marginRight / marginLeft | | paddingLeft / paddingRight | paddingRight / paddingLeft | | borderLeft / borderRight | borderRight / borderLeft | | borderLeftColor / borderRightColor | borderRightColor / borderLeftColor | | borderLeftWidth / borderRightWidth | borderRightWidth / borderLeftWidth | | borderLeftStyle / borderRightStyle | borderRightStyle / borderLeftStyle | | borderTopLeftRadius / borderTopRightRadius | borderTopRightRadius / borderTopLeftRadius | | borderBottomLeftRadius / borderBottomRightRadius | borderBottomRightRadius / borderBottomLeftRadius | | text-align: left / right | text-align: right / left |

Both camelCase and kebab-case properties are supported.

2. Theme Token Merging

Define component-level tokens in your theme under theme.components[tokenName]. They are deep-merged with the styles returned by your style function:

const theme = {
  direction: 'rtl',
  components: {
    Card: {
      backgroundColor: '#f5f5f5',
      borderRadius: '12px',
    },
  },
};

// The Card component's styles are merged with theme.components.Card
const Card = styledBidi('Card', 'div', ({ theme }) => ({
  padding: '16px',
  backgroundColor: '#fff', // ← overridden by theme token '#f5f5f5'
}));

3. Per-Instance Overrides

Use the $style transient prop to override styles on a specific instance:

<Card $style={{ padding: '24px', border: '1px solid red' }} />

API

styledBidi(tokenName, component, styles)

| Parameter | Type | Description | |---|---|---| | tokenName | string | Key to look up in theme.components for token merging | | component | React.ComponentType \| string | Base component or HTML tag to style | | styles | (props) => object | Function receiving { theme, ...props }, returns a CSS-in-JS object |

Returns: A styled-component with BiDi support and theme token merging.

Full Example

import { ThemeProvider } from 'styled-components';
import { styledBidi } from 'styled-bidi';

const theme = {
  direction: 'ltr',
  colors: { primary: '#0066ff', surface: '#ffffff' },
  components: {
    Alert: {
      borderRadius: '8px',
    },
  },
};

const Alert = styledBidi('Alert', 'div', ({ theme }) => ({
  padding: '12px 16px',
  borderRight: `4px solid ${theme.colors.primary}`,  // flipped to borderLeft in LTR
  paddingRight: '20px',                               // flipped to paddingLeft in LTR
  backgroundColor: theme.colors.surface,
  borderTopRightRadius: '8px',                        // flipped to borderTopLeftRadius in LTR
}));

function App() {
  return (
    <ThemeProvider theme={theme}>
      <Alert>This alert adapts to text direction automatically.</Alert>
      <Alert $style={{ backgroundColor: '#fff3cd' }}>Custom background.</Alert>
    </ThemeProvider>
  );
}

License

MIT