Skip to content

Commit 9736c86

Browse files
skovhusclaude
andauthored
Support multiple interpolations in gradient values (#87)
* Support multiple interpolations in gradient values Previously, background values with interpolations (like `linear-gradient(${color1}, ${color2})`) would incorrectly use `backgroundColor` instead of `backgroundImage` because the gradient detection only ran for static values. This fix checks `valueRaw` for gradient patterns regardless of whether the value is static or interpolated, reusing the existing `resolveBackgroundStylexProp` helper. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Add more gradient types to test case Cover radial-gradient, conic-gradient, and repeating-linear-gradient with multiple interpolations. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 172accb commit 9736c86

3 files changed

Lines changed: 76 additions & 4 deletions

File tree

src/internal/css-prop-mapping.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ export function cssDeclarationToStylexDeclarations(decl: CssDeclarationIR): Styl
144144
}
145145

146146
if (prop === "background") {
147-
const stylexProp =
148-
decl.value.kind === "static" && isBackgroundImageValue(decl.valueRaw)
149-
? "backgroundImage"
150-
: "backgroundColor";
147+
const stylexProp = resolveBackgroundStylexProp(decl.valueRaw ?? "");
151148
return [{ prop: stylexProp, value: decl.value }];
152149
}
153150

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import styled from "styled-components";
2+
3+
const color1 = "#ff0000";
4+
const color2 = "#0000ff";
5+
const color3 = "#00ff00";
6+
7+
const LinearGradientBox = styled.div`
8+
background: linear-gradient(${color1}, ${color2});
9+
width: 200px;
10+
height: 100px;
11+
`;
12+
13+
const RadialGradientBox = styled.div`
14+
background: radial-gradient(${color1}, ${color2});
15+
width: 200px;
16+
height: 100px;
17+
`;
18+
19+
const ConicGradientBox = styled.div`
20+
background: conic-gradient(${color1}, ${color2}, ${color3});
21+
width: 200px;
22+
height: 100px;
23+
`;
24+
25+
const RepeatingLinearGradientBox = styled.div`
26+
background: repeating-linear-gradient(${color1} 0%, ${color2} 10%);
27+
width: 200px;
28+
height: 100px;
29+
`;
30+
31+
export const App = () => (
32+
<>
33+
<LinearGradientBox>Linear</LinearGradientBox>
34+
<RadialGradientBox>Radial</RadialGradientBox>
35+
<ConicGradientBox>Conic</ConicGradientBox>
36+
<RepeatingLinearGradientBox>Repeating</RepeatingLinearGradientBox>
37+
</>
38+
);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as stylex from "@stylexjs/stylex";
2+
3+
const color1 = "#ff0000";
4+
const color2 = "#0000ff";
5+
const color3 = "#00ff00";
6+
7+
export const App = () => (
8+
<>
9+
<div {...stylex.props(styles.linearGradientBox)}>Linear</div>
10+
<div {...stylex.props(styles.radialGradientBox)}>Radial</div>
11+
<div {...stylex.props(styles.conicGradientBox)}>Conic</div>
12+
<div {...stylex.props(styles.repeatingLinearGradientBox)}>Repeating</div>
13+
</>
14+
);
15+
16+
const styles = stylex.create({
17+
linearGradientBox: {
18+
backgroundImage: `linear-gradient(${color1}, ${color2})`,
19+
width: "200px",
20+
height: "100px",
21+
},
22+
radialGradientBox: {
23+
backgroundImage: `radial-gradient(${color1}, ${color2})`,
24+
width: "200px",
25+
height: "100px",
26+
},
27+
conicGradientBox: {
28+
backgroundImage: `conic-gradient(${color1}, ${color2}, ${color3})`,
29+
width: "200px",
30+
height: "100px",
31+
},
32+
repeatingLinearGradientBox: {
33+
backgroundImage: `repeating-linear-gradient(${color1} 0%, ${color2} 10%)`,
34+
width: "200px",
35+
height: "100px",
36+
},
37+
});

0 commit comments

Comments
 (0)