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
56 changes: 56 additions & 0 deletions src/__tests__/vendor/tailwind/container-queries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { fireEvent, screen } from "@testing-library/react-native";
import { View } from "react-native-css/components";

import { render } from "./_tailwind";

const parentID = "parent";
const childID = "child";

test("Unnamed containers", async () => {
await render(
<View testID={parentID} className="@container">
<View testID={childID} className="@sm:text-white" />
</View>,
);

const parent = screen.getByTestId(parentID);
const child = screen.getByTestId(childID);

expect(child).toHaveStyle(undefined);

// Jest does not fire layout events, so we need to manually
fireEvent(parent, "layout", {
nativeEvent: {
layout: {
width: 500,
height: 200,
},
},
});

expect(child).toHaveStyle({ color: "#fff" });
});

test("Named containers", async () => {
await render(
<View testID={parentID} className="@container/main">
<View testID={childID} className="@sm/main:text-white" />
</View>,
);

const parent = screen.getByTestId(parentID);
const child = screen.getByTestId(childID);

expect(child).toHaveStyle(undefined);

fireEvent(parent, "layout", {
nativeEvent: {
layout: {
width: 500,
height: 200,
},
},
});

expect(child).toHaveStyle({ color: "#fff" });
});
4 changes: 2 additions & 2 deletions src/compiler/__tests__/selectors.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test(".my-class { &:is(:where(.my-parent, .my-second-parent):hover *) {} }", ()
className: "my-class",
containerQuery: [
{
n: "my-parent",
n: "g:my-parent",
p: {
h: 1,
},
Expand All @@ -73,7 +73,7 @@ test(".my-class { &:is(:where(.my-parent, .my-second-parent):hover *) {} }", ()
className: "my-class",
containerQuery: [
{
n: "my-second-parent",
n: "g:my-second-parent",
p: {
h: 1,
},
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function extractContainer(
};

if (containerRule.name) {
query.n = containerRule.name;
query.n = `c:${containerRule.name}`;
}

builder.addContainerQuery(query);
Expand Down
18 changes: 9 additions & 9 deletions src/compiler/inheritance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test("nested classes", () => {
"my-class",
[
{
c: ["my-class"],
c: ["g:my-class"],
s: [0],
},
],
Expand All @@ -21,7 +21,7 @@ test("nested classes", () => {
"test",
[
{
cq: [{ n: "my-class" }],
cq: [{ n: "g:my-class" }],
d: [{ color: "#f00" }],
v: [["__rn-css-color", "#f00"]],
s: [1, 2],
Expand All @@ -44,7 +44,7 @@ test("multiple tiers classes", () => {
"one",
[
{
c: ["one"],
c: ["g:one"],
s: [0],
},
],
Expand All @@ -53,7 +53,7 @@ test("multiple tiers classes", () => {
"two",
[
{
c: ["two"],
c: ["g:two"],
s: [0],
},
],
Expand All @@ -62,7 +62,7 @@ test("multiple tiers classes", () => {
"test",
[
{
cq: [{ n: "one" }, { n: "two" }],
cq: [{ n: "g:one" }, { n: "g:two" }],
d: [{ color: "#f00" }],
v: [["__rn-css-color", "#f00"]],
s: [1, 3],
Expand All @@ -85,7 +85,7 @@ test("tiers with multiple classes", () => {
"one",
[
{
c: ["one"],
c: ["g:one"],
s: [0],
},
],
Expand All @@ -94,7 +94,7 @@ test("tiers with multiple classes", () => {
"three",
[
{
c: ["three.two"],
c: ["g:three.two"],
s: [0],
aq: [["a", "className", "*=", "two"]],
},
Expand All @@ -105,9 +105,9 @@ test("tiers with multiple classes", () => {
[
{
cq: [
{ n: "one" },
{ n: "g:one" },
{
n: "three.two",
n: "g:three.two",
},
],
d: [{ color: "#f00" }],
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/selector-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function parseComponents(
containerQueries.unshift(ref);
}

ref.n = ref.n ? `${ref.n}.${component.name}` : component.name;
ref.n = ref.n ? `${ref.n}.${component.name}` : `g:${component.name}`;
}

specificity[Specificity.ClassName] =
Expand Down Expand Up @@ -492,7 +492,9 @@ function parseIsWhereComponents(
(query.specificity[Specificity.ClassName] ?? 0) + 1;
}

query.n = query.n ? `${query.n}.${component.name}` : component.name;
query.n = query.n
? `${query.n}.${component.name}`
: `g:${component.name}`;
}

return parseIsWhereComponents(type, selector, index + 1, queries);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export class StylesheetBuilder {
continue;
}

const [first, ...rest] = name.split(".");
const [first, ...rest] = name.slice(2).split(".");

if (typeof first !== "string") {
continue;
Expand Down
Loading