Skip to content

Commit 9d407ec

Browse files
cursoragentskovhus
andcommitted
Extend theme-conditional test case with border-left template literal pattern
Add HighlightBox component testing the prop-based conditional with theme access in a border shorthand template literal: border-left: ${(props) => props.$isHighlighted ? `2px solid ${props.theme.color.greenBase}` : '2px solid transparent'}; Update test for complex theme+prop conditions to verify inline style emission with useTheme() instead of expecting bail. Co-authored-by: Kenneth Skovhus <skovhus@users.noreply.github.com>
1 parent 9b0049b commit 9d407ec

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

test-cases/theme-conditional.input.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,19 @@ const OptionLabel = styled.label<{ $disabled?: boolean }>`
1111
cursor: ${(props: any) => (props.$disabled ? "not-allowed" : "pointer")};
1212
`;
1313

14+
// Prop-based conditional with theme access in template literal (border shorthand)
15+
const HighlightBox = styled.div<{ $isHighlighted?: boolean }>`
16+
padding: 12px;
17+
background-color: ${(props: any) => props.theme.color.bgBase};
18+
border-left: ${(props: any) =>
19+
props.$isHighlighted ? `2px solid ${props.theme.color.greenBase}` : "2px solid transparent"};
20+
`;
21+
1422
export const App = () => (
15-
<div>
23+
<div style={{ display: "flex", flexDirection: "column", gap: 12, padding: 16 }}>
1624
<OptionLabel>Enabled</OptionLabel>
1725
<OptionLabel $disabled>Disabled</OptionLabel>
26+
<HighlightBox>Default box</HighlightBox>
27+
<HighlightBox $isHighlighted>Highlighted box</HighlightBox>
1828
</div>
1929
);

test-cases/theme-conditional.output.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,27 @@ function OptionLabel(props: OptionLabelProps) {
1414
);
1515
}
1616

17+
type HighlightBoxProps = React.PropsWithChildren<{
18+
isHighlighted?: boolean;
19+
}>;
20+
21+
// Prop-based conditional with theme access in template literal (border shorthand)
22+
function HighlightBox(props: HighlightBoxProps) {
23+
const { children, isHighlighted } = props;
24+
25+
return (
26+
<div sx={[styles.highlightBox, isHighlighted && styles.highlightBoxHighlighted]}>
27+
{children}
28+
</div>
29+
);
30+
}
31+
1732
export const App = () => (
18-
<div>
33+
<div style={{ display: "flex", flexDirection: "column", gap: 12, padding: 16 }}>
1934
<OptionLabel>Enabled</OptionLabel>
2035
<OptionLabel disabled>Disabled</OptionLabel>
36+
<HighlightBox>Default box</HighlightBox>
37+
<HighlightBox isHighlighted>Highlighted box</HighlightBox>
2138
</div>
2239
);
2340

@@ -34,4 +51,16 @@ const styles = stylex.create({
3451
color: $colors.labelMuted,
3552
cursor: "not-allowed",
3653
},
54+
highlightBox: {
55+
padding: 12,
56+
backgroundColor: $colors.bgBase,
57+
borderLeftWidth: "2px",
58+
borderLeftStyle: "solid",
59+
borderLeftColor: "transparent",
60+
},
61+
highlightBoxHighlighted: {
62+
borderLeftWidth: "2px",
63+
borderLeftStyle: "solid",
64+
borderLeftColor: $colors.greenBase,
65+
},
3766
});

0 commit comments

Comments
 (0)