Skip to content

Commit 171898f

Browse files
authored
Fix css prop in exported component (#253)
1 parent d4379a2 commit 171898f

File tree

5 files changed

+55
-16
lines changed

5 files changed

+55
-16
lines changed

.changeset/friendly-chefs-heal.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"next-yak": patch
3+
"yak-swc": patch
4+
---
5+
6+
Fix issue with the css prop where it wouldn't be generated when used inside an exported component

packages/yak-swc/yak_swc/src/yak_transforms.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,19 @@ impl YakTransform for TransformCssMixin {
217217
.into(),
218218
);
219219
}
220-
let css_prefix = match (self.is_exported, self.is_within_jsx_attribute) {
221-
(true, _) => Some(format!(
220+
let css_prefix = if self.is_within_jsx_attribute {
221+
// Add the class name to the arguments, to be created by the CSS loader
222+
arguments.push(
223+
Expr::Member(MemberExpr {
224+
span: DUMMY_SP,
225+
obj: Box::new(Expr::Ident(css_module_identifier.clone())),
226+
prop: create_member_prop_from_string(self.generated_class_name.clone().unwrap()),
227+
})
228+
.into(),
229+
);
230+
Some("YAK Extracted CSS:".to_string())
231+
} else if self.is_exported {
232+
Some(format!(
222233
"YAK EXPORTED MIXIN:{}",
223234
self
224235
.export_name
@@ -228,21 +239,11 @@ impl YakTransform for TransformCssMixin {
228239
.iter()
229240
.map(|atom| encode_percent(atom.as_str()))
230241
.join(":")
231-
)),
232-
(_, true) => {
233-
// Add the class name to the arguments, to be created by the CSS loader
234-
arguments.push(
235-
Expr::Member(MemberExpr {
236-
span: DUMMY_SP,
237-
obj: Box::new(Expr::Ident(css_module_identifier.clone())),
238-
prop: create_member_prop_from_string(self.generated_class_name.clone().unwrap()),
239-
})
240-
.into(),
241-
);
242-
Some("YAK Extracted CSS:".to_string())
243-
}
244-
_ => None,
242+
))
243+
} else {
244+
None
245245
};
246+
246247
YakTransformResult {
247248
css: YakCss {
248249
comment_prefix: css_prefix,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { css } from "next-yak";
2+
3+
export const YakLogo = () => (
4+
<div
5+
css={css`
6+
display: flex;
7+
gap: 6px;
8+
`}
9+
>
10+
Yak
11+
</div>
12+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { css, __yak_mergeCssProp } from "next-yak/internal";
2+
import __styleYak from "./input.yak.module.css!=!./input?./input.yak.module.css";
3+
export const YakLogo = ()=><div {.../*YAK Extracted CSS:
4+
.YakLogo {
5+
display: flex;
6+
gap: 6px;
7+
}
8+
*/ /*#__PURE__*/ css(__styleYak.YakLogo)({})}>
9+
Yak
10+
</div>;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { css, __yak_mergeCssProp } from "next-yak/internal";
2+
import __styleYak from "./input.yak.module.css!=!./input?./input.yak.module.css";
3+
export const YakLogo = ()=><div {.../*YAK Extracted CSS:
4+
.YakLogo {
5+
display: flex;
6+
gap: 6px;
7+
}
8+
*/ /*#__PURE__*/ css(__styleYak.YakLogo)({})}>
9+
Yak
10+
</div>;

0 commit comments

Comments
 (0)