Skip to content

Commit

Permalink
[pigment-css][react] Use class selector instead of value
Browse files Browse the repository at this point in the history
for composition. Now, you don't have to explicitly add a "." selector.
  • Loading branch information
brijeshb42 committed Mar 10, 2024
1 parent b3e0b43 commit eb362dd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/pigment-react/src/processors/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ export class StyledProcessor extends BaseProcessor {
* ```js
* const Component = styled(...)(...)
* const Component2 = styled()({
* [`.${Component} &`]: {
* [`${Component} &`]: {
* color: 'red'
* }
* })
* ```
* to further target `Component` rendered inside `Component2`.
*/
doEvaltimeReplacement() {
this.replacer(this.value, false);
this.replacer(this.astService.stringLiteral(this.asSelector), false);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/pigment-react/src/processors/sx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class SxProcessor extends BaseProcessor {
}
}

if (!this.elementClassName) {
if (!this.elementClassName || this.elementClassName[0] !== '.') {
return;
}

Expand All @@ -55,7 +55,7 @@ export class SxProcessor extends BaseProcessor {
cssText = this.processCss(styleObjOrFn, sxStyle);
}
const selector = this.elementClassName
? `.${this.elementClassName}${this.asSelector}`
? `${this.elementClassName}${this.asSelector}`
: this.asSelector;

if (!cssText) {
Expand Down
3 changes: 3 additions & 0 deletions packages/pigment-react/tests/styled/fixtures/styled.input.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ const SliderRail2 = styled.span`
display: block;
opacity: 0.38;
font-size: ${({ theme }) => (theme.vars ?? theme).size.font.h1};
${SliderRail} {
display: none;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
opacity: 0.38;
font-size: 3rem;
}
.s6hrafw .s1sjy0ja {
display: none;
}

0 comments on commit eb362dd

Please sign in to comment.