styled-components / stylis-plugin-rtl

↔️ stylis RTL plugin based on CSSJanus
MIT License
37 stars 18 forks source link

noflip in JavaScript object #24

Closed oliviertassinari closed 1 year ago

oliviertassinari commented 3 years ago

I have noticed the existence of a /* @noflip */ comment that can be used with the CSS template string syntax. It's implemented in https://github.com/cssjanus/cssjanus#preventing-flipping.

However, it seems that there is no way to do the same with the JavaScript object. I wonder about this syntax:

import styled, { StyleSheetManager } from "styled-components";
import rtlPlugin from "stylis-plugin-rtl";

const Box = styled('div')({
  noflip: true,
  paddingLeft: 10,
});

or

import styled, { StyleSheetManager } from "styled-components";
import rtlPlugin from "stylis-plugin-rtl";

const Box = styled('div')({
  paddingLeft: 10,
}).withConfig({ noflip: true });
import styled from "@emotion/styled";
import rtlPlugin from "stylis-plugin-rtl";

const Box = styled('div', { noflip: true })({
  paddingLeft: 10,
});
quantizor commented 3 years ago

Hmm, so the JS style object is actually converted into a string before it's passed into CSSJanus. I'm not sure how we would accomplish this in a way that makes sense because stylis plugins aren't aware of the React component.

quantizor commented 3 years ago

I guess inside of stylis.js in styled components if noflip is specified in some way we could dynamically-inject the code comment...

nicholasglazer commented 2 years ago
const El = styled(div)(() => ({
  marginLeft: '10px /*! @noflip */'
}));
oliviertassinari commented 1 year ago

@nicholasglazer's suggestion works