Skip to content

Commit b8a77dd

Browse files
committed
feat: add support raw function
1 parent 8ba31b9 commit b8a77dd

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

packages/typewind/src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ type Typewind = ${types.join(' & ')} & {
8686
// [arbitraryVariant: string]: (style: Property) => Property;
8787
} & {
8888
variant<T extends \`&\${string}\` | \`@\${string}\`>(variant: T, style: Property | string): Property;
89-
};
89+
raw(style: string): Property;
90+
}
9091
9192
declare const tw: Typewind;
9293

packages/typewind/src/evaluate.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export const createTw: any = () => {
6060
return thisTw;
6161
}
6262

63+
if (name === 'raw') {
64+
return (style: string) => spreadModifier('', style);
65+
}
66+
6367
if (name === 'variant') {
6468
return (modifier: string, classes: any) =>
6569
spreadModifier(`[${modifier}]:`, classes);

packages/typewind/swc/lib.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,20 @@ fn analyse_expr(v: &mut TransformVisitor, wr: &mut Vec<String>, e: &Expr) {
128128
.as_ref(),
129129
);
130130

131-
if style == "variant" {
131+
if style == "raw" {
132+
let style = match &args
133+
.get(0)
134+
.expect("style not specified")
135+
.expr
136+
.as_lit()
137+
.expect("Only literal values allowed")
138+
{
139+
Lit::Str(str) => str.value.to_string(),
140+
_ => panic!("Only string literal values allowed"),
141+
};
142+
143+
wr.push(style);
144+
} else if style == "variant" {
132145
let prefix = match &args
133146
.get(0)
134147
.expect("variant not specified")
@@ -214,7 +227,7 @@ test!(
214227
|_| as_folder(TransformVisitor::new()),
215228
boo,
216229
// Input codes
217-
r#"let style = tw.flex.$lg(tw.bg_black$['20']).md(tw.important(tw.works).text_["18px"].text_["red-200"])"#,
230+
r#"let style = tw.flex.$lg(tw.bg_black$['20']).md(tw.important(tw.works).text_["18px"].text_["red-200"]).variant('&:nth-child(3)', tw.underline).raw("s-1/2")"#,
218231
// Output codes after transformed with plugin
219-
r#"let style = "flex @lg:bg-black/20 md:text-red-200 md:text-[18px] md:!works""#
232+
r#"let style = "flex @lg:bg-black/20 md:text-red-200 md:text-[18px] md:!works [&:nth-child(3)]:underline s-1/2""#
220233
);

0 commit comments

Comments
 (0)