Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule.Selector now accepts string array instead of string #534

Merged
Show file tree
Hide file tree
Changes from 2 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
39 changes: 24 additions & 15 deletions packages/ppx/src/Css_to_runtime.re
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,15 @@ and render_container_query = (~loc, at_rule: at_rule) => {
| Error(error_expr) => error_expr
| Ok(conditions) =>
let query =
String_interpolation.transform(
~attrs,
~delimiter,
~loc=at_rule.loc,
"@container " ++ conditions,
);
[
String_interpolation.transform(
~attrs,
~delimiter,
~loc=at_rule.loc,
"@container " ++ conditions,
),
]
|> Builder.pexp_array(~loc=at_rule.loc);

let rules =
switch (at_rule.block) {
Expand Down Expand Up @@ -336,7 +339,11 @@ and render_selector = (~loc, selector: selector) => {
":"
++ name
++ "("
++ (render_selectors(~loc, payload) |> String.trim)
++ (
render_selectors(~loc, payload)
|> String.concat(", ")
|> String.trim
)
++ ")";
}
and render_pseudo_selector =
Expand Down Expand Up @@ -389,8 +396,7 @@ and render_selector = (~loc, selector: selector) => {
}
and render_selectors = (~loc, selectors) => {
selectors
|> List.map(((selector, _loc)) => render_selector(~loc, selector))
|> String.concat(", ");
|> List.map(((selector, _loc)) => render_selector(~loc, selector));
}
and render_style_rule = (~loc, rule: style_rule) => {
let (prelude, prelude_loc) = rule.prelude;
Expand All @@ -407,12 +413,15 @@ and render_style_rule = (~loc, rule: style_rule) => {
let selector_name =
prelude
|> render_selectors(~loc=selector_location)
|> String.trim
|> String_interpolation.transform(
~attrs,
~delimiter,
~loc=selector_location,
);
|> List.map(String.trim)
|> List.map(
String_interpolation.transform(
~attrs,
~delimiter,
~loc=selector_location,
),
)
|> Builder.pexp_array(~loc=selector_location);

Helper.Exp.apply(
~loc=selector_location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If this test fail means that the module is not in sync with the ppx
CSS.label("selectors"),
CSS.color(CSS.white),
CSS.selector(
{js|&:hover|js},
[|{js|&:hover|js}|],
[|[%ocaml.error "Unknown property 'colorx'"]|],
),
|]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If this test fail means that the module is not in sync with the ppx
CSS.label("selectors"),
CSS.color(CSS.white),
CSS.selector(
{js|&:hover|js},
[|{js|&:hover|js}|],
[|[%ocaml.error "Property 'color' has an invalid value: 'cositas'"]|],
),
|]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ If this test fail means that the module is not in sync with the ppx
let _className =
CSS.style([|
CSS.label("_className"),
CSS.selector({js|.lolaso :nth-child(2n)|js}, [|CSS.color(CSS.red)|]),
CSS.selector(
[|{js|.lolaso :nth-child(2n)|js}|],
[|CSS.color(CSS.red)|],
),
|]);

let _className = [%ocaml.error "Parse error while reading token '2'"];
12 changes: 7 additions & 5 deletions packages/ppx/test/css-support/selectors.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,26 @@ If this test fail means that the module is not in sync with the ppx
CSS.label("_chart"),
CSS.userSelect(`none),
CSS.selector(
{js|.recharts-cartesian-grid-horizontal|js},
[|{js|.recharts-cartesian-grid-horizontal|js}|],
[|
CSS.selector(
{js|line|js},
[|{js|line|js}|],
[|
CSS.selector(
{js|:nth-last-child(1), :nth-last-child(2)|js},
[|{js|:nth-last-child(1)|js}, {js|:nth-last-child(2)|js}|],
[|CSS.SVG.strokeOpacity(`num(0.))|],
),
|],
),
|],
),
CSS.selector(
{js|.recharts-scatter .recharts-scatter-symbol .recharts-symbols|js},
[|
{js|.recharts-scatter .recharts-scatter-symbol .recharts-symbols|js},
|],
[|
CSS.opacity(0.8),
CSS.selector({js|:hover|js}, [|CSS.opacity(1.)|]),
CSS.selector([|{js|:hover|js}|], [|CSS.opacity(1.)|]),
|],
),
|]);
Expand Down
24 changes: 13 additions & 11 deletions packages/ppx/test/native/At_rule_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ let container_query_tests = [
[%expr [%cx "@container (min-width: 150px) {}"]],
[%expr
CSS.style([|
CSS.selector({js|@container (min-width: 150px)|js}, [||]),
CSS.selector([|{js|@container (min-width: 150px)|js}|], [||]),
|])
],
),
Expand All @@ -266,7 +266,7 @@ let container_query_tests = [
[%expr [%cx "@container (max-width: 1000px) {}"]],
[%expr
CSS.style([|
CSS.selector({js|@container (max-width: 1000px)|js}, [||]),
CSS.selector([|{js|@container (max-width: 1000px)|js}|], [||]),
|])
],
),
Expand All @@ -275,23 +275,25 @@ let container_query_tests = [
[%expr [%cx "@container name (width >= 150px) {}"]],
[%expr
CSS.style([|
CSS.selector({js|@container name (width >= 150px)|js}, [||]),
CSS.selector([|{js|@container name (width >= 150px)|js}|], [||]),
|])
],
),
(
"(height >= 150px)",
[%expr [%cx "@container (height >= 150px) {}"]],
[%expr
CSS.style([|CSS.selector({js|@container (height >= 150px)|js}, [||])|])
CSS.style([|
CSS.selector([|{js|@container (height >= 150px)|js}|], [||]),
|])
],
),
(
"(inline-size >= 150px)",
[%expr [%cx "@container (inline-size >= 150px) {}"]],
[%expr
CSS.style([|
CSS.selector({js|@container (inline-size >= 150px)|js}, [||]),
CSS.selector([|{js|@container (inline-size >= 150px)|js}|], [||]),
|])
],
),
Expand All @@ -300,7 +302,7 @@ let container_query_tests = [
[%expr [%cx "@container (block-size >= 150px) {}"]],
[%expr
CSS.style([|
CSS.selector({js|@container (block-size >= 150px)|js}, [||]),
CSS.selector([|{js|@container (block-size >= 150px)|js}|], [||]),
|])
],
),
Expand All @@ -309,7 +311,7 @@ let container_query_tests = [
[%expr [%cx "@container (aspect-ratio: 1 / 1) {}"]],
[%expr
CSS.style([|
CSS.selector({js|@container (aspect-ratio: 1 / 1)|js}, [||]),
CSS.selector([|{js|@container (aspect-ratio: 1 / 1)|js}|], [||]),
|])
],
),
Expand All @@ -318,7 +320,7 @@ let container_query_tests = [
[%expr [%cx "@container (orientation: portrait) {}"]],
[%expr
CSS.style([|
CSS.selector({js|@container (orientation: portrait)|js}, [||]),
CSS.selector([|{js|@container (orientation: portrait)|js}|], [||]),
|])
],
),
Expand All @@ -328,7 +330,7 @@ let container_query_tests = [
[%expr
CSS.style([|
CSS.selector(
{js|@container (width >= 150px) and (orientation: portrait)|js},
[|{js|@container (width >= 150px) and (orientation: portrait)|js}|],
[||],
),
|])
Expand All @@ -339,7 +341,7 @@ let container_query_tests = [
[%expr [%cx "@container name not (width < 150px) {}"]],
[%expr
CSS.style([|
CSS.selector({js|@container name not (width < 150px)|js}, [||]),
CSS.selector([|{js|@container name not (width < 150px)|js}|], [||]),
|])
],
),
Expand All @@ -349,7 +351,7 @@ let container_query_tests = [
[%expr
CSS.style([|
CSS.selector(
{js|@container (width >= 150px) or (orientation: portrait)|js},
[|{js|@container (width >= 150px) or (orientation: portrait)|js}|],
[||],
),
|])
Expand Down
Loading
Loading