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

BP-1293: Add theming support to new rich-text editor for basic redactor configuration #240

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

jovana-marceta
Copy link
Contributor

@jovana-marceta jovana-marceta commented Oct 30, 2024

https://enigmatry.atlassian.net/browse/BP-1293

The Redactor editor will replace CKEditor. This new rich text editor includes predefined CSS that lacks support for our custom theming system, which covers colors, fonts, spacing, and other customizable options.

To address this, this update introduces a mixin that overrides default values for the following elements used in the Basics & Standard Redactor configurations.

Covered elements: Headings (h1 to h6), toolbar buttons, paragraphs, bullet and numbered lists, checkboxes (to-do items), tables, buttons, and links.

Additionally, our custom Redactor class and light mode by default have been added to the Redactor repository.


.enigmatry-redactor-content {
.rx-editor, .rx-content, .rx-content p {
@if $theming-fonts and map.has-key($theming-fonts, 'body') and map.get($theming-fonts, 'body', 'color') != null {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I attempted various approaches to avoid the null value and bypass the stylelint rule, but unfortunately, none of them were successful.

Copy link
Member

Choose a reason for hiding this comment

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

map.get($theming-fonts, 'body', 'color') != null fails to compile without previous checks if i.e. $theming-font is unset or there is no body defined in it?

.enigmatry-redactor-content {
button, .rx-content button {

@if (theming-buttons, 'colors', 'primary') {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not aware of this comparison. Can you give us as some example of docs from which you learned this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made a mistake and forgot to add the $ sign to the theming-buttons variable. Condition should look like this:
@if (map.get($theme, 'general', 'fonts', 'buttons'), 'colors', 'primary')

Copy link
Member

Choose a reason for hiding this comment

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

That's fine. Short and sweat, but where did you find it? Nothing about that in official docs AFAIK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ability to pass multiple keys to map.get is a feature supported in Dart Sass, as described in the official Sass documentation. This functionality allows for concise access to deeply nested values in maps without chaining multiple map.get calls manually. It simplifies the process of working with complex nested data structures like our $theme map

This feature is documented in the official Sass sass:map module

Additionally, here are GitHub issuse tracking the feature:
sass/sass#1739
sass/dart-sass#1884

Copy link
Member

Choose a reason for hiding this comment

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

This is not about map.get keys. We're using that on various places. The question was about if condition joined with such map syntax?
IDK how this would even compile: @if ($theming-buttons, 'colors', 'primary')

Is the intention to map.get primary color and then compare it with unset (null) value?


.rx-toolbar-buttons .rx-button {
&.active, &:hover {
@if map.get($theme, 'general', 'inputs', 'background') {
Copy link
Member

Choose a reason for hiding this comment

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

This is duplicated extraction. We can just do it once and make null comparison if unset.

}
}

@if (map.get($theme, 'tables', 'header', 'font-size')) {
Copy link
Member

Choose a reason for hiding this comment

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

Duplicated retrieval.


table, table td, table th {
/* stylelint-disable-next-line scss/at-if-no-null */
@if $theming-fonts and map.has-key($theming-fonts, 'body') and map.get($theming-fonts, 'body', 'size') != null {
Copy link
Member

Choose a reason for hiding this comment

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

Will it fail compiling if we just check directly size from body (without has key and previous check)?
We would then get rid of duplicated retrieval.

Copy link
Member

Choose a reason for hiding this comment

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

Still legit.


#{$redactor-th-selector} {
/* stylelint-disable-next-line scss/at-if-no-null */
@if map.has-key($theme, 'tables') and map.has-key(map.get($theme, 'tables', 'header'), 'font-size')
Copy link
Member

Choose a reason for hiding this comment

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

The same applies for this one.


.enigmatry-redactor-content {
.rx-editor, .rx-content, .rx-content p {
@if $theming-fonts and map.has-key($theming-fonts, 'body') and map.get($theming-fonts, 'body', 'color') != null {
Copy link
Member

Choose a reason for hiding this comment

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

map.get($theming-fonts, 'body', 'color') != null fails to compile without previous checks if i.e. $theming-font is unset or there is no body defined in it?

@else {
font-family: map.get($body-typography, 'font-family');
}

Copy link
Member

Choose a reason for hiding this comment

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

This is too much duplication and hard to follow. Maybe an option to change this is to replace with the following:

  • pseudocode -
    Get the body.
    Check if body is null, if it is, created default settings and return.
    If it's not, try getting individual settings, the way it's already done, but without constant and the same null checks + syntax will be way shorter once you have body,


@mixin generate-from($theme) {
$theming-primary: map.get($theme, 'general', 'colors', 'primary');
$theming-font-family: map.get($theme, 'general', 'fonts', 'buttons', 'family');
Copy link
Member

Choose a reason for hiding this comment

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

Another variable to isolate map.get($theme, 'general', 'fonts', 'buttons') would make other variables shorter and more readable.

$theming-font-weight: map.get($theme, 'general', 'fonts', 'buttons', 'weight');
$theming-font-size: map.get($theme, 'general', 'fonts', 'buttons', 'size');

$primary-color: if($theming-primary == '' or $theming-primary == null, mat.get-color-from-palette(mat.$primary-palette, 500), $theming-primary);
Copy link
Member

Choose a reason for hiding this comment

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

@Cvetanovic please communicate with @jovana-marceta where she has found this shorter IF syntax for Scss because I was not able to find it the latest official docs (which doesn't mean it's not working).


.enigmatry-redactor-content {

$checkbox-color: if($theming-accent-color == '' or $theming-accent-color == null,
Copy link
Member

Choose a reason for hiding this comment

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

I understood we need to check for empty string and null for variables coming from AM, but this is our theme which leads me to the fact something's maybe not right on your machine, @jovana-marceta .
@Cvetanovic please switch to this branch and try testing this if condition without empty string and communicate with Jovana (and me eventually) whether is working and what exactly isn't since we expect null value if unset and not an empty string.


table, table td, table th {
/* stylelint-disable-next-line scss/at-if-no-null */
@if $theming-fonts and map.has-key($theming-fonts, 'body') and map.get($theming-fonts, 'body', 'size') != null {
Copy link
Member

Choose a reason for hiding this comment

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

Still legit.

.enigmatry-redactor-content {
button, .rx-content button {

@if (theming-buttons, 'colors', 'primary') {
Copy link
Member

Choose a reason for hiding this comment

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

That's fine. Short and sweat, but where did you find it? Nothing about that in official docs AFAIK?

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.

3 participants