Skip to content

fix: Refactor demo snippets#6648

Open
GZolla wants to merge 23 commits intomainfrom
gzolla/clean-demo-snippet
Open

fix: Refactor demo snippets#6648
GZolla wants to merge 23 commits intomainfrom
gzolla/clean-demo-snippet

Conversation

@GZolla
Copy link
Contributor

@GZolla GZolla commented Mar 3, 2026

GAUD-9549

There is a lot of code on the demo snippet component that is no longer needed:

  • Code meant to support toggling rtl, a feature which has since been removed
  • code to support IE11
  • other opportunities to simplify and defects to fix

@GZolla GZolla requested a review from a team as a code owner March 3, 2026 21:42
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-6648/

Note

The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

text = text.replace(/^[\t]*\n/, '').replace(/\n[\t]*$/, '');
const templateMatch = text.match(/^[\t]*<template>[\n]*/);
this._isTemplate = templateMatch && templateMatch.length > 0;
text = text.replace(/^(\t*\n)*/, '').replace(/(\n\t*)*$/, '');
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 regex now handles multiple whitelines, before the code would break if 2 white lines where included in the demos. Not something we should expect but it should not break either

Comment on lines +172 to -216
// fix script whitespace
text = setIndent(text.replace(/\t/g, ' '))
.replace(/<\/script>/g, '\n</script>')
.replace(/<script>/g, '<script>\n')
.replace(/<script type="module">/g, '<script type="module">\n')
.replace(/<script data-demo-hide(.+?)<\/script>/gis, '')
.split('\n');
let scriptIndent = 0;
lines = lines.map((l) => {
if (l.indexOf('<script') > -1) {
scriptIndent = l.match(/^(\s*)/)[0].length;
return l;
} else if (l.indexOf('</script>') > -1) {
const nl = this._repeat(' ', scriptIndent) + l ;
scriptIndent = 0;
return nl;
} else if (scriptIndent && !this._isTemplate) {
return this._repeat(' ', scriptIndent + 2) + l;
} else {
return l;
}
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before we would look for script tags, and only fix indentation for those, now the same logic is applied to the whole snippet on setIndent. This is needed for when custom lit templates can be set, the function can handle cases where we want to ignore the first line (e.g. a template that starts inline but spans multiple lines html`<some-tag>\n ...) or we want to set an indentation level(e.g. nested templates)

});
}

_applyAttr(name, value, applyToShadowRoot) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was meant to handle setting rtl, that feature was removed so this is not needed anymore. This is now handled by _getDemoNodes() and _handleSkeletonChange()

}
}

_repeat(value, times) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a guard for string.repeat on IE11

@EdwinACL831
Copy link
Contributor

I might ask, if there are any existing tests that will fail after these changes. or in other words, are there any tests that need to be updated ? if not, should new tests be added for these changes ?

@GZolla
Copy link
Contributor Author

GZolla commented Mar 4, 2026

I might ask, if there are any existing tests that will fail after these changes. or in other words, are there any tests that need to be updated ? if not, should new tests be added for these changes ?

Good point, the tests are very barebones, I'll add some

dlockhart
dlockhart previously approved these changes Mar 5, 2026
@dlockhart
Copy link
Member

Hmm, looks like a test is timing out in Webkit...

@GZolla GZolla dismissed dlockhart’s stale review March 5, 2026 17:48

modified _hasSkeleton

dlockhart
dlockhart previously approved these changes Mar 5, 2026
@GZolla GZolla marked this pull request as draft March 5, 2026 19:24
@GZolla GZolla dismissed dlockhart’s stale review March 5, 2026 19:25

Still need to figure out the timing issue

@GZolla GZolla marked this pull request as ready for review March 6, 2026 19:26
border: 1px solid var(--d2l-sem-border-color-standard);
border-radius: 6px;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.85);
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've replaced this box-shadow with the floating shadow from the semantic palette, it seems a lot more noticeable though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to attached shadow, seems closer to the original

Copy link
Contributor

Choose a reason for hiding this comment

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

The naming is totally up in the air at the moment. These attached variants are named with the top/bottom scroll cases in mind. We probably need something more general (going to talk with Jeff about it), but these are the values.

--d2l-shadow-attached-block-start: 0 2px 4px 0 rgba(0, 0, 0, 0.03);
--d2l-shadow-attached-block-end: 0 -2px 4px 0 rgba(0, 0, 0, 0.03);
--d2l-shadow-floating: 0 2px 12px 0 rgba(0, 0, 0, 0.15);
--d2l-shadow-inset: inset 0 2px 0 0 rgba(177, 185, 190, 0.2); /* corundum */

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.

4 participants