SDC: Sharing trough composer and discovery mechanism

Created on 25 September 2024, 5 months ago

Problem/Motivation

SDC has been working great on my projects, and I have little by little built a library of components.

However, now if I'd like to start a project from scratch and reuse them, it means I need to create a new theme and pretty much copy all of the definitions.

I know that I could create a theme or module and them have my components there, but it kind of feels like an unnecesary / annoying requirement.

Proposed resolution

I have 2 ideas in mind:

  • Since the Recipes initiative allows to have recipes that live outside Drupal, I was thinking if it makes sense to do something similar for SDC. Have them live outside and be discovered.
  • We could have a components folder, similar to what we have with modules or themes, where we could have contrib SDC and custom SDC. This would require writing a new installer type, but then these could be shared in packagist in a way. But then users could just require the ones they need for their projects.

API changes

Change the discovery mechanism for SDC.

✨ Feature request
Status

Active

Version

10.4 ✨

Component

single-directory components

Created by

πŸ‡¨πŸ‡·Costa Rica alemadlei

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

Comments & Activities

  • Issue created by @alemadlei
  • πŸ‡ΊπŸ‡ΈUnited States mherchel Gainesville, FL, US

    I want to give a hearty +100 to this. It's something that I've been thinking about for a while.

    Updating IS with next steps

    1. Find out who needs to give sign off
    2. Get sign off on the initial idea
    3. Figure out technical implantation (this will require DA staff as well as core changes)
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    This has been asked of us many times in the recipes realm. Recipes themselves don't have anything to do with Single Directory Components (SDC), but could require them using the recipe's composer.json file. The dependency for that requirement could be unpacked to the project's composer.json file so it would be have like a contrib project and would be updatable from the source.

    I assume you wouldn't need to do anything to SDCs to make that work. Just make them available from a composer or asset packagist.

    If Drupal defines a new package type, say drupal-sdc, you would then want to open an issue with composer/installers to add that package type. Here is the drupal-recipe pull request for reference.

    You would then need to define a place to put the SDCs. With recipes, we did that by adding an installer-path to the drupal/recommended-project and drupal/legacy-project composer templates πŸ“Œ Add support for recipes to drupal/recommended-project and drupal/legacy-project Fixed .

    "Change the discovery mechanism for SDC." sounds like the perfect description for that last step and far from my expertise to comment on.

    Love this idea!

  • πŸ‡ΊπŸ‡ΈUnited States sea2709 Texas

    I see that many components using variables from the theme, especially theme's colors, font styles, etc.. Just wondering, if components are something separate from the theme, will we need to have some guidelines or standards about how to define variables or how to pass variables from theme to components. Just want to share my thoughts!

  • πŸ‡¨πŸ‡·Costa Rica alemadlei

    Hey sea2709,

    That's one way to implement it, however, you could also try to define broad CSS variables with default values or use CSS layers so that they are easy to override.

    Some people also use Tailwind when defining their components, and those clases are standardized elsewhere.

  • πŸ‡ΊπŸ‡ΈUnited States sea2709 Texas

    you could also try to define broad CSS variables with default values or use CSS layers so that they are easy to override.

    Yeah, this is what I meant, we need to have a guidelines about how to build outside / dependent components to make them work well with themes later on.

    One more thing came across my mind is when we have a set of base components and apply these components for different projects. So there might be a chance that we want to add more properties, more slots for components. From what I understand, we don't have this ability at this moment, the way we do is to replace a component by another component in case we want to extend it.

  • e0ipso Can Picafort

    I know that I could create a theme or module and them have my components there, but it kind of feels like an unnecesary / annoying requirement.

    When we were on the drawing board, this was considered. However it was discarded because Drupal does not have a way to deal with name collisions in composer packages. It does however have one for modules. This way we were able to reliably determine the component prefix.

    The important question here is: why does it feel like an unnecesary / annoying requirement?

    I'd like to clarify this part of the IS before moving forward with this.

  • πŸ‡¨πŸ‡·Costa Rica alemadlei

    Hi e0ipso,

    So my train of though is as follows:

    * The way I write SDC I try to avoid dependency to other Drupal things. I know they are flexible enough so that you can build them any way you want, but I try to have them be completly agnostic regarding what environment they are in (my larger goal is that maybe I could use them on Wordpress or Laravel projects in the future).
    * Having a theme wrapper or a module wrapper to just include a components folder kind of feels (and I know this is my own opinion) unncesesary because you are not adding anything else other than the components folder.
    * Recipes right now are something that don't require a module or theme to be created. They exist and they can be used in a project by running the script. Related to recipes, checking the Drupal source, once installed recipes have their own folders, no need for modules or themes. So I feel kind of envious towards that, and think that SDCs could also have their own folder for contrib and custom. That way they can be shared trough composer or custom repositories.

Production build 0.71.5 2024