Problem/Motivation

This is part of the CSS modernization initiative.

The first issue was regarding the file stylesheet.

Steps to reproduce

The stylesheet at https://git.drupalcode.org/project/drupal/-/blob/10.0.x/core/themes/claro/css/components/file.pcss.css needs to be refactored to make use of modern CSS and Drupal core's PostCSS tooling.

Proposed resolution

Use CSS Logical Properties where appropriate
Use CSS nesting where appropriate

Remaining tasks

We need two patches. One for Drupal 9.5.x and one for Drupal 10.0.x
We need a followup issue to refactor this component in Drupal 10.0.x to make use of component-level CSS custom properties.

User interface changes

None. There should be no visual differences.

CommentFileSizeAuthor
#62 Screenshot 2023-04-18 at 4.09.48 PM.png144.77 KBSantosh_Verma
#52 interdiff-40_52.txt1.97 KBGauravvvv
#52 3293398-52.patch1.92 KBGauravvvv
#51 trial.patch21.77 KBStanzin
#48 interdiff_46-48.txt1.11 KBAkram Khan
#48 3293398-48.patch2.25 KBAkram Khan
#46 interdiff_40-46.txt691 byteskunal_sahu
#46 3293398-46.patch2.25 KBkunal_sahu
#40 interdiff-36_40.txt2.02 KBGauravvvv
#40 3293398-40.patch2.23 KBGauravvvv
#36 3293398-36.patch1.61 KBSakthivel M
#35 3293398-35.patch528 bytes_utsavsharma
#32 interdiff_3293398-27-32.txt548 bytes_utsavsharma
#32 3293398-32.patch548 bytes_utsavsharma
#27 trial.patch1.56 KBhitaarthh
#27 trial.patch1.56 KBhitaarthh
#26 3293398-9.5.x.patch1.25 KBhitaarthh
#25 3293398-10.0.x.patch1.8 KBAditya4478
#24 3293398.patch1.25 KBAditya4478
#21 3293398-10.0.x.patch1.86 KBAditya4478
#20 3293398-9.5.x.patch1.3 KBAditya4478
#18 3293398-10.0.x.patch1.72 KBAditya4478
#17 3293398-version9.5.x.patch1.11 KBAditya4478
#13 3293398-version10.0.x.patch1.44 KBAditya4478
#11 32933998-version9.5.x.patch985 bytesAditya4478
#10 3293398-version9.5.x.patch985 bytesAditya4478
#9 3293398-version10.0.x.patch1.01 KBAditya4478
#8 temporary-check.patch2.5 KBAditya4478
#6 3299398-9.5.x-version.patch2.27 KBAditya4478
#5 3299398-9.5.x-version.patch2.51 KBAditya4478
#3 3293398-9.5.x-version.patch2.51 KBAditya4478
#2 3293398-10.0.x-version.patch2.66 KBAditya4478

Issue fork drupal-3293398

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sasanikolic created an issue. See original summary.

Aditya4478’s picture

Version: 9.5.x-dev » 10.0.x-dev
Status: Active » Needs review
FileSize
2.66 KB

Patch for Drupal 10.0.x

Aditya4478’s picture

Version: 10.0.x-dev » 9.5.x-dev
FileSize
2.51 KB
sasanikolic’s picture

Issue summary: View changes
Aditya4478’s picture

Aditya4478’s picture

sasanikolic’s picture

Status: Needs review » Needs work
  1. +++ b/core/themes/claro/css/components/file.pcss.css
    @@ -12,11 +12,12 @@
    +  & + [dir="rtl"] .file {
    

    I don't think this is correct. + is a css selector for direct siblings, while dir="rtl" is the selector for right-to-left languages. This should remain as-is when compiled.

  2. +++ b/core/themes/claro/css/components/file.pcss.css
    @@ -12,11 +12,12 @@
    +  & + .file__size {
    

    Also this + is not needed.

Aditya4478’s picture

please completely ignore this.

Aditya4478’s picture

Version: 9.5.x-dev » 10.0.x-dev
FileSize
1.01 KB
Aditya4478’s picture

Version: 10.0.x-dev » 9.5.x-dev
FileSize
985 bytes
Aditya4478’s picture

FileSize
985 bytes

Do not consider this patch

sasanikolic’s picture

+++ b/core/themes/claro/css/components/file.pcss.css
@@ -12,9 +12,10 @@
+  [dir="rtl"] & {

I think this is a perfect example where we can use CSS logical properties and just use margin-inline-start to cover the LTR and RTL padding definitions. https://css-tricks.com/css-logical-properties/.

Aditya4478’s picture

Version: 9.5.x-dev » 10.0.x-dev
Status: Needs work » Needs review
FileSize
1.44 KB

For D9 there are now changes found. For D10 please consider this patch.

sasanikolic’s picture

Status: Needs review » Needs work
+++ b/core/themes/claro/css/components/file.pcss.css
@@ -5,16 +5,12 @@
   min-height: calc(var(--space-m) + 0.0625rem);

Let's put this 0.0625rem to a local variable.

sasanikolic’s picture

+++ b/core/themes/claro/css/components/file.pcss.css
@@ -12,9 +12,10 @@
-[dir="rtl"] .file {

This RTL change should remain as it was here.

As mentioned above, I think the only change for d9 is to use the local variable for the 0.0625rem value.

sasanikolic’s picture

Also, please check https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties. We may need to use more logical properties here, such as min-block-size.

Aditya4478’s picture

Version: 10.0.x-dev » 9.5.x-dev
Status: Needs work » Needs review
FileSize
1.11 KB
Aditya4478’s picture

Version: 9.5.x-dev » 10.0.x-dev
FileSize
1.72 KB
sasanikolic’s picture

Status: Needs review » Needs work
+++ b/core/themes/claro/css/components/file.pcss.css
@@ -6,7 +6,9 @@
   background-position: left 0.0625rem;

We defined the new variable above so we can reuse it also here. So it shouldn't be named spacing because it's used in calculating the height and the background position. What is this value actually? I don't think it's a container-required spacing - maybe that was just copied from somewhere else?

Aditya4478’s picture

Version: 10.0.x-dev » 9.5.x-dev
Status: Needs work » Needs review
FileSize
1.3 KB

"--positioning-elements" sounds good ?

Aditya4478’s picture

Version: 9.5.x-dev » 10.0.x-dev
FileSize
1.86 KB

The last submitted patch, 20: 3293398-9.5.x.patch, failed testing. View results

sasanikolic’s picture

Status: Needs review » Needs work
+++ b/core/themes/claro/css/components/file.css
@@ -11,9 +11,11 @@
+  --positioning-element: 0.0625rem;

Let's name it something like --file--offset and fix the failing test.

Aditya4478’s picture

Version: 10.0.x-dev » 9.5.x-dev
Status: Needs work » Needs review
FileSize
1.25 KB
Aditya4478’s picture

Version: 9.5.x-dev » 10.0.x-dev
FileSize
1.8 KB
hitaarthh’s picture

Version: 10.0.x-dev » 9.5.x-dev
FileSize
1.25 KB

Trial Patch.

hitaarthh’s picture

Version: 9.5.x-dev » 10.0.x-dev
FileSize
1.56 KB
1.56 KB

Practicing

sasanikolic’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/themes/claro/css/components/file.css
@@ -10,19 +10,24 @@
+  min-height: calc(var(--space-m) + var(--file-offset)); /* LTR */

This is funky, the comment jumped to the previous line. :)

Hi @hitaarthh. I can't see how are your changes different from the patches from @Aditya4478?

Changes look good to me.

hitaarthh’s picture

hello @sasanikolic,
It was a trial patch as this was my first contribution in drupal, just getting hands on experience with drupal 9/10.

Are they any more issues opened related to CSS modernization or some frontend development where i can potentially contribute to?

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

@hitaarthh Welcome! If you are interested in helping on CSS refactoring, we have many CSS refactoring issues in the Claro issue queue. Here's a link for the Claro issue queue: https://www.drupal.org/project/issues/drupal?component=Claro+theme

+++ b/core/themes/claro/css/components/file.pcss.css
@@ -4,16 +4,15 @@
+  padding-inline-start: var(--space-l); /* LTR */

Should we use this in both Drupal 10 and Drupal 9 since this would get compiled by PostCSS?

We can also remove the LTR comment since this now applies for both, LTR and RTL.

hitaarthh’s picture

@lauriii Yeah i just started off contributing to drupal, will surely look into it.

_utsavsharma’s picture

Status: Needs work » Needs review
FileSize
548 bytes
548 bytes

@lauriii Made changes as per the comment #30.
Needs review.

smustgrave’s picture

Status: Needs review » Needs work

Patch failed to apply. You can test a patch before uploading with the core/scripts/dev/commit-code-check.sh

smustgrave’s picture

So what patch was the correct one? I see there were a number of trial patches and I think #32 may have been off one of those. So should we review #25?

_utsavsharma’s picture

Sorry for the #32.
Made changes as per the comment #30.
Needs review.

Sakthivel M’s picture

Status: Needs work » Needs review
FileSize
1.61 KB

Updated #28 Comment, Please review the patch

Status: Needs review » Needs work

The last submitted patch, 36: 3293398-36.patch, failed testing. View results

ckrina’s picture

ckrina’s picture

Issue summary: View changes
Gauravvvv’s picture

Version: 10.0.x-dev » 10.1.x-dev
Status: Needs work » Needs review
FileSize
2.23 KB
2.02 KB

Added variables on component level. please review

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Nesting looks good

But not sure if these spaces are needed

  --file-font-size: var(--font-size-s);

  min-block-size: calc(var(--file-space-m) + var(--file-offset));
  --file-size-color: var(--color-gray-800);

  color: var(--file-size-color);
Gauravvvv’s picture

Status: Needs work » Needs review

But not sure if these spaces are needed

Even without spaces in pcss.css file, compiled CSS file have the space after declared variable. I think we need these space to differentiate between variables and properties.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

If that's the case then this should be fine.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/themes/claro/css/components/file.pcss.css
    @@ -4,17 +4,21 @@
    +  --file-space-m: var(--space-m);
    +  --file-space-l: var(--space-l);
    

    These variables don't seem particularly helpful at least with the current naming 🤔 I think we need to either rename to something that explains what is their purpose in this component or just remove.

  2. +++ b/core/themes/claro/css/components/file.pcss.css
    @@ -4,17 +4,21 @@
    +  --file-size-color: var(--color-gray-800);
    

    This should be added to the .file rule.

kunal_sahu made their first commit to this issue’s fork.

kunal_sahu’s picture

As per @lauriii's suggestion in #44, I have made changes to the .file rule.

Attaching the patch along with interdiff.

Kindly review. And please guide me if you find my changes inappropriate.

Thanks

Akram Khan’s picture

Assigned: Unassigned » Akram Khan
Akram Khan’s picture

Added updated patch and fixed CCF #46

smustgrave’s picture

Hiding patches #46 and #48

.file .file__size {
color: var(--file-size-color);
}

Is undoing some of the nesting previously done

And neither seem to address #44.1 so least do a restart back to #40 before continuing this forward.

So starting from #40 lets address the points in #44

Akram Khan’s picture

Assigned: Akram Khan » Unassigned
Stanzin’s picture

FileSize
21.77 KB

// Ignore this patch
I am new to env. Checking the patch works or not.

Gauravvvv’s picture

Status: Needs work » Needs review
FileSize
1.92 KB
1.97 KB

Addressed #44, attached patch and interdiff with #40 for same. please review

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

#44 seems to be addressed.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 52: 3293398-52.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Seems random failure.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 52: 3293398-52.patch, failed testing. View results

kunal_sahu’s picture

I reviewed this Patch and doesn't seem to have any issue. The patch LGTM. But the error message that is mentioned typically appears in PHPUnit tests when an assertion is made that an object or array should be empty, but it is not.

Drupal\Tests\user\Kernel\Migrate\MigrateUserStubTest
fail: [Other] Line 0 of sites/default/files/simpletest/phpunit-1178.xml:
PHPUnit Test failed to complete; Error: PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\user\Kernel\Migrate\MigrateUserStubTest
F                                                                   1 / 1 (100%)

Time: 00:01.502, Memory: 4.00 MB

There was 1 failure:

1) Drupal\Tests\user\Kernel\Migrate\MigrateUserStubTest::testStub
Failed asserting that an object is empty.

/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122
/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
/var/www/html/core/modules/migrate_drupal/src/Tests/StubTestTrait.php:22
/var/www/html/core/modules/user/tests/src/Kernel/Migrate/MigrateUserStubTest.php:35
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

FAILURES!
Tests: 1, Assertions: 8, Failures: 1.

It is not related to the CSS code itself.

So i guess we can move it to RTBC.

Thanks

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Random failure

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 52: 3293398-52.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Ticket isn’t having luck with random failures

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 52: 3293398-52.patch, failed testing. View results

Santosh_Verma’s picture

Tested the patch #52 which is is showing fail testing,
It is applying cleanly.I think failure is not related to patch

SS

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Gauravvvv’s picture

Status: Needs work » Reviewed & tested by the community

Patch #52, still applies on 11.x. Restoring the status

  • lauriii committed 9cd44537 on 11.x
    Issue #3293398 by Aditya4478, Gauravvvv, _utsavsharma, Sakthivel M,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 9cd4453 and pushed to 11.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

quietone’s picture

Issue tags: -Needs followup

This is a minor only change, removing tag for the followup.