Skip to content

fix: refine scratch block category styles - #1568

Open
maxelkins wants to merge 5 commits into
mainfrom
scratch-block-category-css
Open

fix: refine scratch block category styles#1568
maxelkins wants to merge 5 commits into
mainfrom
scratch-block-category-css

Conversation

@maxelkins

@maxelkins maxelkins commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Closes https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1687

Summary

Add Scratch block category colours as CSS custom properties, uses them and update the code style (used for the highlighted text).

Pulled from the discovery prototype on experience-cs-instructions-prototype (RaspberryPiFoundation/digital-editor-issues#1687).

The custom attribute syntax and marked extension explored on that branch are deliberately left out — they'll land as a separate follow-up issue.

Changes

--scratch-* custom properties

Adds the Scratch block category colours in instructions from --scratch-* CSS custom properties instead of hardcoded hex values.

High contrast details

Scratch has an option to turn on high contrast block colours. This is enabled when the users OS preference is set to prefers-contrast: more. It normally can also be turn on in the Scratch settings UI (which we don't have).

So to make sure that the colours in the instructions match the blocks when prefers-contrast: more is true, I've also added support of the high contrast colours in the instructions when the preference is set.

Code styles

Also tidies the inline code snippet padding to use the design system's spacing tokens.

Now uses the --space-0-25/--space-0-5 tokens

Notes

  • New --scratch-* custom properties currently scoped to the instructions panel, but could be moved in future if needed elsewhere.

Viewing these changes

Enable editable instructions in the preview:

newWebComp.setAttribute("editable_instructions", "true");

Code element padding changes can be seen by adding a code snippet to the user editable (teacher) instructions.

Currently the Scratch colours can only been seen in 2 ways

  1. By using the non-editable instructions like the Projects site (see example below)
  2. By adding support for the inline kramdown styles proposed in the epic. This is in the current prototype and will in done in a follow up PR.

Screenshots

Code style refinement:

Screenshot 2026-08-03 at 16 29 09

Categories:

Screenshot 2026-08-03 at 16 29 17

Categories (high contrast):

Screenshot 2026-08-03 at 16 30 09

Non-editable instructions demo (like Code Club Projects)

Demo code used

newWebComp.setAttribute(
  "instructions",
  JSON.stringify({
    project: {
      steps: [
        {
          title: "Step 1",
          content: `
  <h2>Move the sprite</h2>
  <p>Drag out a <code class="block3motion">move 10 steps</code> block and click it a few times.</p>
  <p>Then add a <code class="block3looks">say Hello!</code> block underneath.</p>
`,
        },
      ],
    },
  }),
);
Screenshot 2026-08-03 at 17 09 17

Adds --scratch-* CSS custom properties for each Scratch block category
(and a prefers-contrast: more variant), sourced from scratch-gui's
colour-mode tokens, ready to be wired into the instructions styles.

Pulled from the discovery prototype on experience-cs-instructions-prototype
(RaspberryPiFoundation/digital-editor-issues#1687).
Swaps the hardcoded hex background colours on the block category
classes for the new --scratch-* custom properties, and adds a
prefers-contrast: more override so the category text stays legible
against the higher-contrast background colours.

Pulled from the discovery prototype on experience-cs-instructions-prototype
(RaspberryPiFoundation/digital-editor-issues#1687).
Uses the --space-0-25/--space-0-5 tokens for the inline code padding
instead of a one-off calc() derived from a spacing token, matching the
rest of the design system's spacing scale.
@maxelkins
maxelkins temporarily deployed to previews/1568/merge August 3, 2026 15:31 — with GitHub Actions Inactive
@maxelkins maxelkins changed the title feat: add scratch block type styles feat: use CSS variables for scratch block category colours in instructions Aug 3, 2026
@maxelkins maxelkins changed the title feat: use CSS variables for scratch block category colours in instructions feat: add scratch block category styles Aug 3, 2026
@maxelkins
maxelkins marked this pull request as ready for review August 3, 2026 16:14
@maxelkins
maxelkins temporarily deployed to previews/1568/merge August 3, 2026 16:14 — with GitHub Actions Inactive
Comment thread src/assets/stylesheets/_scratch_colours.scss
@maxelkins
maxelkins marked this pull request as draft August 3, 2026 16:54
@maxelkins

Copy link
Copy Markdown
Contributor Author

Putting back to draft for a sec while I tweak something...

@maxelkins
maxelkins marked this pull request as ready for review August 4, 2026 11:32
@maxelkins maxelkins changed the title feat: add scratch block category styles feat: refine scratch block category styles Aug 4, 2026
@maxelkins maxelkins changed the title feat: refine scratch block category styles fix: refine scratch block category styles Aug 4, 2026
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.

1 participant