[meta] Svelte app themability

Created on 15 June 2022, over 2 years ago
Updated 28 November 2023, about 1 year ago

Problem/Motivation

Drupal core modules typically provide minimal markup and CSS (just enough to work) and themes take care of adding classes and styling beyond those essentials. Here's a very generalized overview of how different assets are themed

  • Twig templates a theme provides a template with the same filename, which overrides the default template. The override can be minimal (such as Classy adding a few classes), or a more extensive rebuild.
  • Render Arrays _preprocess() hooks are used to alter render array contents. claro.theme makes extensive use of preprocess functions to add theme-specific classes to render elements.
  • CSS CSS can be replaced (via override) or extended (via library extension), both of which are configured in a theme's info.yml file.
  • JavaScript generated Markup Some markup is dynamically generated by JavaScript, so does not come from a render array or twig template.

Svelte doesn't cleanly belong to any of the above, but ideally the app could be similarly themed. A .svelte file is a combination of JavaScript, HTML templates and CSS that is compiled to JavaScript.

Proposed resolution

  1. First, refactor many of our values into CSS custom properties. This will allow easy overrides for other themes.
  2. Second, remove the hashed classnames introduced by the Svelte build, so that markup looks more Drupal-y. Using BEM syntax where possible, this aligns better with Drupal markup today. We may need to refactor some of our existing CSS to this end.
  3. Third, allow for the insertion of markup (using Drupal.theme, for example) into component prefixes and suffixes where there's a good opportunity (e.g. the card component).
  4. Fourth, and only if there is great clamoring for it, allow users to override individual Svelte files (or pieces of them), though this introduces a build step. Note: a really motivated person could already today fork and rebuild the front-end to their heart's content.
🌱 Plan
Status

Needs work

Version

1.0

Component

Code

Created by

🇺🇸United States bnjmnm Ann Arbor, MI

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Custom Commands Failed
  • 🇺🇸United States mherchel Gainesville, FL, US
  • 🇺🇸United States chrisfromredfin Portland, Maine

    At a discussion at DrupalCon NA 2023 in Pittsburgh, the follow people met to discuss themability and the approaches proposed by Ben Mullins in this issue:

    • Lauri Eskola
    • Tim Plunkett
    • Andy Blum
    • Mike Herchel
    • Chris Wells
    • Ben Mullins

    While there, the approaches were discussed, and the following decisions made:

    1. First, refactor many of our values into CSS custom properties. This will allow easy overrides for other themes.
    2. Second, remove the hashed classnames introduced by the Svelte build, so that markup looks more Drupal-y. Using BEM syntax where possible, this aligns better with Drupal markup today. We may need to refactor some of our existing CSS to this end.
    3. Third, allow for the insertion of markup (using Drupal.theme, for example) into component prefixes and suffixes where there's a good opportunity (e.g. the card component).
    4. Fourth, and only if there is great clamoring for it, allow users to override individual Svelte files (or pieces of them), though this introduces a build step. Note: a really motivated person could already today fork and rebuild the front-end to their heart's content.
  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States chrisfromredfin Portland, Maine
  • 🇺🇸United States chrisfromredfin Portland, Maine
  • 🇺🇸United States mherchel Gainesville, FL, US

    +1 on @chrisfromredfin's comment in #19. I also want to state that there was consensus at the table that "perfect is the enemy of good" and if the insertion of markup into a component prefix/suffix is too time consuming, it should not block beta or stability.

  • 🇺🇸United States chrisfromredfin Portland, Maine

    Adding stable-blocking here, but noting from Mike's comment that we will split prefix & suffix out to a non-blocker if it proves too time-consuming.

  • 🇺🇸United States andy-blum Ohio, USA

    Is this issue still relevant after 📌 Move styles out of svelte bundle to traditional Drupal library Fixed

  • 🇺🇸United States chrisfromredfin Portland, Maine

    Yes, still relevant. Though moving it out, and that does enhance themability, we still want to convert values to custom properties, do BEM syntax, and ideally #3 if possible, allow prefix/suffix inserting with Drupal.theme().

  • 🇺🇸United States andy-blum Ohio, USA

    we still want to convert values to custom properties

    Is this necessary since the classes aren't obfuscated, the styles are BEMified, and everything is brought in via the Library API? I think once the plan outlined in #3394904 is done and the styles in PB are reduced to just basic layout styles (similar to the views module when viewed in Stark), admin themes will be responsible for theming the PB UI.

    allow prefix/suffix inserting with Drupal.theme()

    This probably needs someone investigating if this can be done safely. I imagine Drupal.theme() will break a lot of the svelte event bindings.

Production build 0.71.5 2024