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

HDS-2367: Better SCSS tool to replace BEM util #1457

Open
wants to merge 30 commits into
base: development
Choose a base branch
from

Conversation

NikoHelle
Copy link
Contributor

@NikoHelle NikoHelle commented Jan 1, 2025

Description

Constructing scss files with the style that was introduced in the cookie-consent is very verbose and requires a tedious amount of @if $all or $xyz or $other blocks.

The "_bem.scss" helps to create selectors for all combinations of block + modifier + element, but is not very usable with the @if...syntax.

This tool makes creating scss and outputting css simpler.

Instead of (examples from button.scss)

@mixin button(
  $all: true,
  $base: false,
  $icon: false,
  $small: false,
  $fullwidth: false,
  $primary: false,
  $secondary: false,
  $supplementary: false,
  $clear: false,
  $success: false,
  $danger: false,
  $themeCoat: false,
  $themeBlack: false,
  $override: null,
  $react: false
)

 @if $all or $base {
    @include BemUtil.block($className, if($override, true, false), $react) {

You can use

@mixin button($modifiers: true, $elements: true, $extras: true, $config: null) {
  $void: init-multi-sass(
    $modifiers: $modifiers,
    $elements: $elements,
    $extras: $extras,
    $block: 'button',
    $config: $config,
  );

  @include block {
    @include if-content-allowed {
    

This new tool, named "multi-sass", stores the arguments passed to it, so there is no need for @if blocks. If outputs the selectors with correct prefixes and delimeters, so the old "_bem.scss" will be obsolete.

Didn't have time to do more conversions other than button-mixin. But added testing tool to verify the outputted css matches, which makes converting easier.

The tool also helps with using core with React, because it can output css directly to wrappers used in *.module.css and strip selectors used in core *.scss.

The code and logic is explained in detail in the README.md

Related Issue

Helps with HDS-2367

How Has This Been Tested?

Added scss testing tool.

Demos:

Links to demos are in the comments

Screenshots (if appropriate):

Add to changelog

  • no need, internal tool.

Version matches React's jest, so no lock file changes.
Sass is missing a lot of basic stuff, so added functions for them
The mixin file has container embedded to the base.

Cannot separate and import to React module
Copy link

github-actions bot commented Jan 1, 2025

Test Results

  1 files   66 suites   12m 27s ⏱️
 65 tests  65 ✅ 0 💤 0 ❌
130 runs  130 ✅ 0 💤 0 ❌

Results for commit 2fb2804.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jan 1, 2025

Preview found from hds-demo docs/preview_1457

Demos

Docs
Core Storybook
React Storybook

Copy link
Contributor

@timwessman timwessman left a comment

Choose a reason for hiding this comment

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

This is huge PR, and excellent! Good work. packages/core/src/utils/README.md is really good documentation page how our scss system works!

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

Successfully merging this pull request may close these issues.

2 participants