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

feat: introduce scoped css for default styles #493

Merged

Conversation

kaiszybiak
Copy link

@kaiszybiak kaiszybiak commented Dec 2, 2021

Description

We integrate the asyncapi component as a plugin into the backstage ecosystem. During the integration of the pre release version containing the switch to tailwind we noticed, that by including the default styles import "@asyncapi/react-component/styles/default.css"; those styles where globally applied and had an effect on other components, as they are not scoped (see related PR).

This PR is inspired by #381. Our initial idea was to resolve the merge conflicts and go with the CSS prefix solution. (see branch). However the tailwind prefix does not affect:

/* default.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

Our second approach was to use tailwind selector-strategy:

// tailwind.config.js
module.exports = {
  important: '#app',
}

This made the refactoring easier, as we only had to add one id to the container and were not forced to change all of the tailwind utility classes manually but it still had the same problem as the prefix solution, that there where still styles applied globally e.g.

/* snippet from @asyncapi/react-component/styles/default.css */

button:focus {
  outline: 1px dotted;
  outline: 5px auto -webkit-focus-ring-color;
}

Solution

We scope all CSS by using the postcss plugin postcss-scopify. The default styles will only affect the asyncapi component. There is a slightly difference between the following screenshots, as the default.css doesn't affect the CodeMirror component anymore.

Essentially all styles stay the same only styles applied to html and body do not have an effect anymore as they are scoped but the scoping class .aui-root is applied some levels deeper to the AsyncApiLayout.

/**
Use a more readable tab size (opinionated).
*/

.aui-root html {
  -moz-tab-size: 4;
  -o-tab-size: 4;
     tab-size: 4;
}

/**
1. Correct the line height in all browsers.
2. Prevent adjustments of font size after orientation changes in iOS.
*/

.aui-root html {
  line-height: 1.15; /* 1 */
  -webkit-text-size-adjust: 100%; /* 2 */
}

Before:
Bildschirmfoto 2021-12-02 um 14 44 15

After:
Bildschirmfoto 2021-12-02 um 14 29 42

Changes proposed in this pull request:

  • Introduce postcss plugin postcss-scopify
  • Add aui-root as a scoped class to the AsyncApiLayout component
  • Add leading-normal to match the line-height applied before to the html tag by @tailwind base

Related issue
Resolves #369
See also #381

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.

Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@kaiszybiak kaiszybiak force-pushed the next-branches/tailwind-scoped-css branch from c18a472 to a3a6136 Compare December 2, 2021 15:10
@kaiszybiak kaiszybiak marked this pull request as ready for review December 2, 2021 15:24
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 6, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@magicmatatjahu
Copy link
Member

@kaiszybiak Thanks for great description and solution! Yeah, I went with adding to all classes the prefix but your is better, I like it! That I hadn't thought of something similar either 😅 Thanks again, everything looks great :) I also read the discussion in the attached PR in the backstage and don't worry. The next version will not be changed much in terms of styles. The only thing we still want to do is fix the bugs that people have reported and we'll release 1.0.0. We waited so long to release next because we were waiting for a designer to be hired, but it took us so long that the new styles won't be available until 2.0.0.

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 1.0.0-next.25 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants