Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/__tests__/vendor/tailwind.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,45 @@ test("filter", () => {
testID,
});
});

test("line-clamp", () => {
const compiled = registerCSS(`
.my-class {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1
}
`);

expect(compiled.stylesheet()).toStrictEqual({
s: [
[
"my-class",
[
{
d: [
{
overflow: "hidden",
},
[1, ["numberOfLines"]],
],
s: [1, 1],
},
],
],
],
});

render(<View testID={testID} className="my-class" />);
const component = screen.getByTestId(testID);

expect(component.props).toStrictEqual({
children: undefined,
numberOfLines: 1,
style: {
overflow: "hidden",
},
testID,
});
});
60 changes: 43 additions & 17 deletions src/compiler/__tests__/@prop.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { render, screen } from "@testing-library/react-native";
import { View } from "react-native-css/components";
import { registerCSS, testID } from "react-native-css/jest";

import { compile } from "../compiler";

test("@prop single", () => {
const compiled = compile(`
.test {
const compiled = registerCSS(`
.my-class {
color: red;
background-color: blue;
@prop background-color: myBackgroundColor;
Expand All @@ -12,14 +16,14 @@ test("@prop single", () => {
expect(compiled.stylesheet()).toStrictEqual({
s: [
[
"test",
"my-class",
[
{
d: [
{
color: "#f00",
myBackgroundColor: "#00f",
},
["#00f", ["myBackgroundColor"]],
],
v: [["__rn-css-color", "#f00"]],
s: [1, 1],
Expand All @@ -28,6 +32,18 @@ test("@prop single", () => {
],
],
});

render(<View testID={testID} className="my-class" />);
const component = screen.getByTestId(testID);

expect(component.props).toStrictEqual({
testID,
children: undefined,
myBackgroundColor: "#00f",
style: {
color: "#f00",
},
});
});

test("@prop single, nested value", () => {
Expand Down Expand Up @@ -60,12 +76,12 @@ test("@prop single, nested value", () => {
});
});

test("@prop single, top level", () => {
test("@prop single, on target", () => {
const compiled = compile(`
.test {
color: red;
background-color: blue;
@prop background-color: ^myBackgroundColor;
@prop background-color: *.myBackgroundColor;
}
`);

Expand All @@ -78,8 +94,8 @@ test("@prop single, top level", () => {
d: [
{
color: "#f00",
myBackgroundColor: "#00f",
},
["#00f", ["^", "myBackgroundColor"]],
],
v: [["__rn-css-color", "#f00"]],
s: [1, 1],
Expand All @@ -90,26 +106,26 @@ test("@prop single, top level", () => {
});
});

test("@prop single, top level, nested", () => {
const compiled = compile(`
.test {
test("@prop single, nested", () => {
const compiled = registerCSS(`
.my-class {
color: red;
background-color: blue;
@prop background-color: ^myBackgroundColor.test;
@prop background-color: *.myBackgroundColor.test;
}
`);

expect(compiled.stylesheet()).toStrictEqual({
s: [
[
"test",
"my-class",
[
{
d: [
{
color: "#f00",
},
["#00f", ["^", "myBackgroundColor", "test"]],
["#00f", ["*", "myBackgroundColor", "test"]],
],
v: [["__rn-css-color", "#f00"]],
s: [1, 1],
Expand All @@ -118,14 +134,24 @@ test("@prop single, top level, nested", () => {
],
],
});

render(<View testID={testID} className="my-class" />);
const component = screen.getByTestId(testID);

expect(component.props.style).toStrictEqual({
color: "#f00",
myBackgroundColor: {
test: "#00f",
},
});
});

test("@prop single, top level, nested", () => {
const compiled = compile(`
.test {
color: red;
background-color: blue;
@prop background-color: ^myBackgroundColor.test;
@prop background-color: myBackgroundColor.test;
}
`);

Expand All @@ -139,7 +165,7 @@ test("@prop single, top level, nested", () => {
{
color: "#f00",
},
["#00f", ["^", "myBackgroundColor", "test"]],
["#00f", ["myBackgroundColor", "test"]],
],
s: [1, 1],
v: [["__rn-css-color", "#f00"]],
Expand All @@ -156,8 +182,8 @@ test("@prop multiple", () => {
color: red;
background-color: blue;
@prop {
background-color: myBackgroundColor;
color: myColor;
background-color: *.myBackgroundColor;
color: *.myColor;
}
}
`);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/atRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function propAtRuleBlock(
mapping[toRNProperty(fromToken.value.value)] = to.flatMap((item, index) => {
switch (item.value.type) {
case "delim":
return index === 0 && item.value.value === "^" ? ["^"] : [];
return index === 0 && item.value.value === "*" ? ["*"] : [];
case "ident":
return [toRNProperty(item.value.value)];
default:
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,12 @@ export function parseDeclarationCustom(
property,
parseUnparsed(declaration.value.value, builder, allowAuto.has(property)),
);
} else if (property === "-webkit-line-clamp") {
builder.addMapping({ [property]: ["numberOfLines"] });
builder.addDescriptor(
property,
parseUnparsed(declaration.value.value, builder, allowAuto.has(property)),
);
} else {
builder.addWarning("property", declaration.value.name);
}
Expand Down
27 changes: 15 additions & 12 deletions src/compiler/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export class StylesheetBuilder {
};
}

addMapping(mapping: StyleRuleMapping) {
this.mapping = { ...this.mapping, ...mapping };
}

newRule(mapping = this.mapping, { important = false } = {}) {
this.mapping = mapping;
this.rule = this.cloneRule(this.ruleTemplate);
Expand Down Expand Up @@ -331,30 +335,29 @@ export class StylesheetBuilder {
}

private pushDescriptor(
property: string,
rawProperty: string,
value: StyleDescriptor,
declarations: StyleDeclaration[],
forceTuple = false,
delayed = false,
) {
property = toRNProperty(property);
const property = toRNProperty(rawProperty);

let propPath: string | string[] =
this.mapping[property] ?? this.mapping["*"] ?? property;
let propPath: string | string[] | undefined =
this.mapping[rawProperty] ?? this.mapping[property] ?? this.mapping["*"];

if (Array.isArray(propPath)) {
const first = propPath[0];
const [first, second] = propPath;

if (!first) {
// This should not happen, but if it does, we skip the property
return;
}

if (propPath.length === 1) {
propPath = first;
if (propPath.length === 2 && first === "*" && second) {
propPath = second;
} else {
forceTuple = true;
}
} else if (propPath) {
forceTuple = true;
} else {
propPath = property;
}

if (isStyleFunction(value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/native/__tests__/selectors.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.skip(':root[class="dark"]', () => {
expect(component.props.style).toStrictEqual({ color: "red" });
});

test(':root[class~="dark"]', () => {
test.skip(':root[class~="dark"]', () => {
registerCSS(`
@react-native {
darkMode: dark;
Expand Down
Loading