Replies: 3 comments 6 replies
-
I'm not sure it's desirable but I'm pretty sure I could make it work if I used some wrapper contexts to detect the presence or non-presence of a container. 🤔 |
Beta Was this translation helpful? Give feedback.
-
Sorry if this is oversimplifying your problem here, but to me it seems like you just need to include const styles = stylex.create({
first: {
marginBlockStart: {
':first-child': 0,
default: 'unset',
},
},
}); This isn't optimal for css size because it adds the selector to the stylesheet, but if it's used frequently (like in markdown) I think it's the optimal solution here in terms of staying within StyleX. the code tag would also have something similar. Are components passed to ReactMarkdown going to be used elsewhere where they need to strictly be applied when they are a child of |
Beta Was this translation helpful? Give feedback.
-
In case anyone stumbles onto this, this is what I ended up doing. I don't like writing CSS like this but it seemed to solve the problem the most elegantly. This is in context to MDX. import stylex from "@stylexjs/stylex";
import React from "react";
import { Sx } from "../../../styles/sx";
import { Theme } from "../../../styles/tokens/theme.stylex";
import { dedent } from "../../../utils/dedent";
import { Contributes } from "./contributes";
// TODO: Probably use the line-height pattern here
const styles = stylex.create({
wrapper: {
color: "white",
fontSize: Theme.BASE_FONT_SIZE_PX,
lineHeight: 1.5,
},
});
type WrapperProps = Sx.ComponentProps<"div">;
const Wrapper = Sx.createComponent<WrapperProps>("div", styles.wrapper);
export const contributes: Contributes = {
wrapper: (props: React.ComponentProps<"div">) => (
<Wrapper
_nativeProps={{
...props,
// @ts-expect-error
"data-wrapper": true,
}}
_styles={styles.wrapper}
>
<style>
{dedent(`
:where([data-wrapper] > :not(style) + *) {
margin-block-start: ${Theme.SpacingLg};
}
/* Heading */
:where([data-wrapper] > :not(style) + :where(h1, h2, h3, h4, h5, h6)) {
margin-block-start: ${Theme.SpacingXl};
scroll-margin-block-start: ${Theme.SpacingXl};
}
/* List item */
:where([data-wrapper] li) {
margin-block: ${Theme.SpacingMd};
}
:where([data-wrapper] li:last-child) {
margin-block-end: ${Theme.SpacingMdHalfStep};
}
/* Preformatted text */
:where([data-wrapper] [data-pre]) {
margin-block: ${Theme.SpacingLg};
}
/* Horizontal rule */
:where([data-wrapper] > hr) {
margin-block: ${Theme.SpacingXl};
}
`)}
</style>
{props.children}
</Wrapper>
),
}; |
Beta Was this translation helpful? Give feedback.
-
Hi, I usually use StyleX for everything but I found there was this one specific case I couldn't seem to use StyleX so I reverted to plain CSS. Here is the code in question:
Which is being used as a side effect by the following:
What I don't understand is how to implement the following pattern using StyleX if possible:
Because I am deferring to
<ReactMarkdown>
, it's not obvious to me how to programmatically disable the firstmargin-block-start
or how to prevent<code>
from being duplicately styled by the<pre>
container.Am I missing something or is this a legitimate use case for when not to reach for StyleX?
Beta Was this translation helpful? Give feedback.
All reactions