Problem/Motivation
Single directory components (SDC) is a new way to theme Drupal. Instead of scattering related files around your theme, they're contained to one directory. The primary issue for SDC is at #3313520: Single-directory components in core.
As part of SDC's roadmap (see #3345922: Single Directory Components module roadmap: the path to beta and stable), we want to convert an Umami component to use SDC. For this task I'm choosing the card view mode component, which includes markup and CSS.
This issue is of course blocked on actually getting SDC into core. See #3340712: Add Single Directory Components as a new experimental module.
Testing instructions
- Make sure you have SDC module enabled, if enabling via
drush si demo_umamiit will be installed by the profile - Clear caches
- Test card view mode and it's variants (most of the listings use it) - you should see HTML like the screenshot below showing that the cards are being rendered via a component

Components description:
Card Component:
1. Has optional html_tag prop with values article or div
2. Has slot content without restrictions of content inside.
Title component:
1. specific Drupal properties: title_prefix, title_suffix
2. optional html tag as property
3. In the future, it will allow us to control the typography of the site through css classes. EG: `.umami-title--h1 {}` what is better that `h1 {}`
In terms of BEM: https://en.bem.info/methodology/quick-start/#block `You also shouldn't use CSS tag or ID selectors when using BEM.`
Read more component used only in cards for now. But it can be reused everywhere now.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3347672
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
markconroy commentedComment #4
smustgrave commentedOnly postponing until the parent issue makes it in. Since this can be looked at but it can't be truly reviewed (as the parent may need changes) or move forward.
Tagging for Needs Review Queue though so when the parent gets committed and this gets moved back to NW we can prioritize
Comment #5
ipwa commentedParent issue committed.
Comment #6
smustgrave commentedImagine the MR will have to rebased. Current MR has some failures.
Comment #7
markconroy commentedComment #8
markconroy commentedComment #9
markconroy commentedIt was mentioned on Slack that Umami maintainers do not want to allow the use of experimental modules in the umami profile.
I had forgotten that we weren’t going to use experimental features, I got so excited about using SDC. The fear is that if we use experimental modules
However, given that experimental modules in reality don't seem to actually get removed and given there are not concerns related to data storage in the SDC module (it's only templating changes), I'm happy as an Umami maintainer for us to override our policy on experimental modules for SDC.
Comment #10
smustgrave commentedWon't hold up but applying patch I get
test.patch:73: trailing whitespace.
test.patch:88: trailing whitespace.
warning: 2 lines add whitespace errors
Applied the patch on a fresh Umami install and checking the cards on the homepage nothing seemed to change. Attaching some screenshots.
Reviewing the MR the changes look good and right along the time of component/atomic structure.
Let me know if there's anything else you want me to check!
Comment #11
markconroy commented@smustgrave Thanks for that review and moving to RTBC. I've actually gone and updated the MR to move all the card components to their own directory, so I can (later) add in more directories beside it for other view modes. Can you give it another review?
New directory structure will allow us to do something like this:
Comment #12
smustgrave commentedMakes sense to me.
Comment #13
lauriiiProvided some feedback on the MR
Comment #15
moshe weitzman commentedLooks like we lost some steam here, right near the end. Anyone available to address the feedback?
Comment #16
markconroy commentedSorry @moshe weitzman
I've just been snowed under with work for the past couple of weeks and haven't had a chance to get back to this yet.
Comment #17
e0ipsoComment #18
e0ipsoI updated the parent issue to #3364673: [META] Create Single Directory Components for the Umami theme.
Comment #19
mortona2k commentedWorking on this @ Drupalcon.
Comment #20
mortona2k commented1. Classes
I moved the classes array out of the component templates and into node templates. I think they can also be safely removed from the node templates. If we keep them in, it will inject a bunch of classes potentially for future use, but currently aren't used.
One exception is .view-mode-card. I don't think this is an appropriate class to use in a component, because it targets a view mode named card, not a card component, which we are creating. Instead, I used .umami-card, with .umami-card--common and .umami-card--common-alt variations.
I changed node__title and node__content to umami-card__title and umami-card__content.
2.1 Title
I used a slot for the title, but have an h2.umami-card__title element in the component, which wraps it.
This way, the component template defines the h2 tag, and the content can be whatever is passed through. In this case, it's a span, with a bunch of classes on it.
Having done this, I am leaning towards stripping things down to just what is needed for the component instead of trying to support unknown variations.
Comment #21
mortona2k commentedI could use some feeback on this.
Last round of changes make the card--common and card--common-alt components extend the card template.
Any thoughts on how we're using props and slots?
Comment #22
markconroy commentedThanks @mortona2k
This looks really good now. I've only read through the code, not actually tested it yet. I'll try get it tested later this week.
Comment #23
e0ipsoAdded some suggestions.
Comment #24
mortona2k commentedI made the suggested changes.
Comment #25
e0ipsoI didn't check the changes (and I don't think I am qualified to talk about CSS), but I still see several unresolved threads in the MR. Did you consider those as well?
Comment #26
mortona2k commentedI made the changes I could for those. I marked some of them as pending review, not sure if I'm doing that right.
I have a few questions on some of the threads, otherwise it's as close as I can get atm.
Comment #27
smustgrave commentedSeems the failures are from passing NULL in
{{ node.type.entity.label() }}Wonder if you have to pass that in as a slot value?
Comment #28
e0ipso@smustgrave if the component is embedded without context leaks, then you need to pass the label as well. IMHO a card component should not depend on a node object, but a label seems reasonable. In any case, mapping it into context should do.
Comment #29
smustgrave commented@mortona2k do you want to give that a shot? So I can stay in the review role.
Seems the only failures in the MR are due to that node object being empty.
Comment #30
mortona2k commentedI added a read_more_label property, set with node.type.entity.label() in the node templates.
Do I need to set a default value, or does defining the property take care of that?
Comment #31
smustgrave commentedI don't think a default is needed but will let committer decide.
Think this is actually good to go!
Applied the MR and compared the cards on the homepage vs without the MR and they appear unchanged.
Comment #32
e0ipsoI left a bunch more comments. I think we are getting very close. Thanks for figuring all this out together!
Some of the comments on the metadata apply to all the components in here.
Comment #34
gauravvvv commentedComment #35
smustgrave commentedSeems a number of open threads. If some are done can they least be marked with a comment. Know you can't always resolve the thread.
Comment #38
finnsky commentedHello all!
I'm happy that SDC in core because i'm big fan of components development. So:
I created new MR with different approach:
- From my point of view components should be abstract and not related to Drupal view modes, fields, content types or whatever.
- All that 3 cards absolutely same. So what for to create 3 components?
- Read More link should be independent component. It is reusable now. even if used only in cards.
- Title also pretty useful component in terms of typography. I added it without CSS because typography not designed well yet.
Minor updates:
- Changed spacing policy to CSS Grid. Some small visual layout regressions appear. But i don't think they are critical.
- BEMified components to have cleaner styles inheritance.
- removed label-items class in theme preprocess. It has default margin-bottom. What is bad in terms of BEM:
https://en.bem.info/methodology/css/#external-geometry-and-positioning
Please review!
Thanks
Comment #39
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #40
finnsky commentedComment #41
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #42
andypost@finnsky please update MR to use 11.x as target branch instead of 10.1
Comment #43
finnsky commentedThanks @andypost !
Comment #44
gauravvvv commentedComment #45
e0ipsoMoving back to Needs Work, since there are a bunch of unresolved tasks.
Comment #46
finnsky commentedAdded `only`
Comment #47
smustgrave commentedFor review purposes can the issue summary be updated to match what's in the MR. Current IS talks about a card component which resulted in a title, readmore, and card components. Think that should be documented.
Thanks this looks really good!
Comment #48
finnsky commentedComment #49
finnsky commentedComment #50
smustgrave commentedApplied the MR and verified that the cards still render the same as before.
Comment #54
justafishCommitted and pushed to 11.x and 10.2.x - thanks!