LogoLogo
10.0.x
10.0.x
  • Overview
    • About Varbase
    • Roadmap
    • Release Cycle and Supported Versions
    • How to Get Support
  • Developers
    • Getting Started
    • Installing Varbase
      • Requirements
      • Installing Varbase locally with DDEV
      • Installing Varbase locally with Lando
    • Understanding Varbase
      • Basic Concepts
      • Core Components
        • Varbase Core
          • Varbase Admin
          • Varbase Page
          • Varbase Security
          • Varbase Webform
          • Varbase Default Content
          • Varbase Tour
        • Varbase Media
        • Varbase Editor
        • Varbase Email
        • Varbase SEO
        • Varbase Workflow
        • Varbase Dashboards
        • Varbase Layout Builder
          • Varbase Landing page (Layout Builder)
          • Varbase Heading Block
          • Varbase Rich Text Block
          • Varbase HTML Code Block
          • Varbase Media (Image/Video) Block
          • Varbase Gallery Block
        • Varbase Components
        • Vartheme Claro
        • Vartheme BS5
      • Optional Components
        • Varbase AI
          • Varbase AI Default recipe
          • Varbase AI Editor Assistant recipe
          • Varbase AI Image Alt recipe
          • Varbase AI Taxonomy Tagging recipe
          • Varbase AI Agents recipe
        • Varbase API
        • Varbase Internationalization
        • Varbase Hero Slider
        • Varbase Carousels
        • Varbase Blog
        • Varbase Search
        • Varbase Social Single Sign-On
        • Varbase Media Twitter
        • Varbase Media Instagram
        • Varbase Content Planner
        • Varbase Bootstrap Paragraphs
          • Varbase Bootstrap Paragraphs Text and Image
        • Varbase Landing Page (Paragraphs)
      • Additional Components
        • Varbase Media Header
        • Varbase FAQs
        • Varbase Reports
        • Varbase Commerce
        • Varbase YouTube Import
      • Development Components
        • Varbase Development
        • Reroute Email
        • Varbase Updates Helper
      • Deprecated Components
        • Varbase Media Hero Slider
        • Varbase Style Guide
        • Vartheme BS4
        • Varbase Total Control Dashboard
    • Configuring a Varbase Site
      • Navigation
        • Defining Active Menu Trail Using Menu Position
      • Using View Modes Inventory
      • Content Moderation and Workflows
      • URL Aliases in Varbase/Drupal
        • Configuring URL Aliases
        • Managing URL Aliases
      • Managing URL Patterns for Multilingual Websites
      • Managing Date and Time Formats to Display Across the Site
      • Using Varbase Layout Builder
        • Creating a Landing Page With Varbase Layout Builder
        • Activating Varbase Layout Builder for Content Types
      • Configuring Pathologic When Going Live
      • Configuring SEO Features
        • Disallow Oembed Media Links
      • Configuring Security Features
        • Spam Protection
        • Password Policies
        • Other Security Kits
        • Flood Contorl
        • Enable HTTP Password Authentication
      • Configuring JSON:API Features
      • Configure Varbase Media Hero Slider
      • Configuring Varbase Media Header
      • Configuring Varbase Mailer Settings
        • Configure Symfony Mailer
      • Configure Level of Logging and Errors
      • Entity Definition Update Manager Class
      • Module Installer Factory Class
      • Configure Ckeditor 5 Media Embed
    • Theme Development with Varbase
      • Understanding The Vartheme Starterkit Theme
      • Creating Your Own Theme
      • Integration of Varbase with Storybook 1.0 - CL Server
      • Integration of Varbase with Storybook 2.0
      • Customize a Varbase Single Directory Components (SDC) In a Custom Theme
      • Local Tasks and Moderation Sidebar
      • Add Preloaded Fonts in Vartheme
      • Command to Install Needed Theming Tools
      • Manually Install Needed Theming Tools
    • Launching a Varbase Site to Production
    • Updating a Varbase Site
      • Understanding Varbase Updater Package
      • Handling Patches When Updating
      • Handling Configuration Updates
      • Updating Varbase to work with Composer 2.0
      • Updating Drush to the Latest Stable Version
      • Version Update Guides
        • Updating Varbase ~9.0 to Drupal 10
        • Updating from Varbase 8.x to 9.x
    • Varbase Patches
    • Frequently Asked Questions (FAQs)
    • Extending Varbase
      • Overriding Varbase
      • Creating Your Own Feature
      • Install Needed YARN and Webpack Tools
      • Compiling Provided Component Styles
      • Check Standards/Practice Coding And Linting
  • Content Designers
    • Accessing the Administration Area
      • Website Environments
    • Dashboard
      • Reports
    • Content Management
      • Create Content
        • Rich-Text Editor “WYSIWYG”
      • Modify Content
      • Delete Content
      • Preview Content
      • Bulk Edit Content
      • Publish Content
      • Authoring Information
    • Content Structure
      • EntityQueues
        • Add a New Term
      • Menu Management
        • Add Menu Items
        • Update Menu Items
        • Adding a Page to the Menu
      • Taxonomies
        • List Terms
        • Add Terms
        • Reorder and Edit Terms
    • Content Translation
      • Translating Content
      • Language Switcher
      • Deleting a Translation
      • Editing a Translation
    • Content Workflow
    • Layout Builder
      • Section
        • Section Styles
      • Block Management
        • Block Styles
      • Reordering Blocks
    • Webforms
      • Create New Webform View
      • Setting up Emails Handler Conditions
      • Setting up Confirmations Message Settings Types
    • Media Management
      • Accessing the Media Library
      • Uploading Media Files
        • Image
        • Remote Video
        • Video
      • Applying Metadata and Descriptions
      • Resizing Images
    • User Management
      • Login & Registration
      • Add User
      • Edit User
      • Delete User
      • Simulating Another User
      • Default Roles and Site Personas
        • Edit Roles' Permissions
        • Managing Roles
    • URL Management
      • URL Aliases
      • Generating URL Alias
      • URL Redirects
      • Domain Redirects
    • SEO Management
      • XML Sitemap
      • Meta Tags in Varbase
      • Disallow Indexing for Content Items
    • Site Configuration
      • System
        • Clearing Varbase Cache
        • Google Analytics
        • Mail Templates
      • User Interface
        • Coffee
        • External Links
        • Gin Moderation Sidebar
        • Layout Builder Modal
        • Moderation Sidebar
        • Shortcuts
        • Taxonomy Manager
        • Tours
        • CL Components
        • Antibot
        • Responsive Preview
        • Navigation Settings
      • Development
      • Varbase Settings
      • Web Services
        • OpenAPI
    • Additional Tips
      • Content Uploading Standards
      • Common Error Handling Tips
      • Glossary
  • Contributing
    • Contributing to Documentation
Powered by GitBook
On this page
  • Copy the Varbase Component to the Custom theme
  • Add replaces to the Copied Component
  • Add the Custom SCSS files to the Webpack Config for Components
  • Compile SASS to CSS files for components
  • Change the SDC Component to Customize
  • Defining Schemas for SDC Component Metadata
  • Drafts of JSON Schema
  • Options to custom
  • Proof of Concept: Custom Varbase Blog Card Components
  • Offering an Example Avenue
  • Example: Use the General Cards/Teasers
  • Field mapping with Components
  • Example: Impressed Card as a View Mode for a Content Type
  • More Info and FAQ about SDC
  • SDC Examples
  1. Developers
  2. Theme Development with Varbase

Customize a Varbase Single Directory Components (SDC) In a Custom Theme

PreviousIntegration of Varbase with Storybook 2.0NextLocal Tasks and Moderation Sidebar

Last updated 11 months ago

The components folder contains various Single Directory Components (SDC). To enhance the default components, Projects are using the components provided by module.

To replace any component from the Varbase Components module, follow the example below:

Example:

Suppose we have a custom style for the Alert component on our site, which differs from the default style. Here are the steps to implement the custom style:

Copy the Varbase Component to the Custom theme

Copy the alert folder from Varbase Components to your project's theme folder:

cd PATH_TO_THE_PROJECT/docroot
cp -r modules/contrib/varbase_components/components/molecules/alert themes/custom/PROJECT_THEME/components/molecules/alert

Add replaces to the Copied Component

Edit the alert.component.yml file in your PROJECT_THEME folder.

Add the following line after name: Alert in the YAML file:

replaces: 'varbase_components:alert'

The updated alert.component.yml should look like this:

name: Alert
replaces: 'varbase_components:alert'

Add the Custom SCSS files to the Webpack Config for Components

Uncomment the following line in the PROJECT_THEME/webpack.config.components.js file:

    './components/molecules/alert/alert': ['./components/molecules/alert/alert.scss'],

Note: As a custom theme, Developers and themers have the authority to modify any part of the "status-messages.html.twig" template file, which is the default system template in Drupal.

You can also make changes to the SASS, TWIG, and JavaScript files in the components/molecules/alert folder.

Compile SASS to CSS files for components

yarn components:build

These steps will allow you to incorporate your custom style for the Alert component, using the Varbase Components module as a base.

Change the SDC Component to Customize

  • Add JS file, or more JS files to dependencies

  • Add more SCSS/CSS files

  • Change the custom component twig template

Defining Schemas for SDC Component Metadata

The draft has been seamlessly integrated with YAML in SDC Components within the Drupal core. This integration now serves as the backbone for all front-end and web components, providing a unified and efficient system.

  • Required in modules

  • Optional in themes (file presence needed)

Add the Schema Metadata

$schema: https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json 

In all SDC components in Varbase Components or custom myproject_components module.

The will read the schema file to understand the syntax for fixes and enable autocomplete.

Drafts of JSON Schema

Front End frameworks are using a selected draft to create their custom schema metadata for components.

http://json-schema.org/draft-01/schema# http://json-schema.org/draft-02/schema# http://json-schema.org/draft-03/schema# http://json-schema.org/draft-04/schema# ( Used by Drupal core SDC module) http://json-schema.org/draft-05/schema# http://json-schema.org/draft-06/schema# http://json-schema.org/draft-07/schema#

Options to custom

  • Clone the custom card component, which is targeted for a selected content type, and have the custom changes for with styles(css) and scripts(js), or even with custom props and slots.

  • Switch to use the starterkit/recipes for the provided Varbase Cards from Varbase Components directly from the display mode for an entity.

  • Clone the Varbase Card component and customize it in a custom theme

Proof of Concept: Custom Varbase Blog Card Components

While Varbase Blog will retain the use of the standard Varbase Card Components, This is an proof of concept example with a selection of custom components.

Offering an Example Avenue

Explore customizing card components for specific content types. Our present example revolves around the Varbase Blog content type.

You're welcome to download the components and tailor them according to your chosen view mode and content type's requirements.

Make the transition from the inline CSS class placement method for UI patterns to using custom Card components. Additionally, enhance organization and readability by integrating Custom Cards as stories within Varbase Storybook.

Example: Use the General Cards/Teasers

view modes for your site, and if necessary, you can utilize or clone the Varbase Cards Starterkit/Recipe.

  • Incorporate custom Card components when working with specific Content types like the Varbase Blog

  • This approach streamlines the development workflow, enabling smooth collaboration between Design, Storybook, Front-End development with SDC components and stories, and the mapping process in the theme. The Back-end team can also effortlessly integrate components into the site structure.

  • The Site builder gains the flexibility to associate SDC components with both UI Pattern and SDC Display, ensuring a cohesive and efficient implementation.

Field mapping with Components

Can be managed in number of approaches

( Building the list of components for fields can be now in projects or products ) Then later SDC Display can map them from the UI.

Example: Impressed Card as a View Mode for a Content Type

Example: Impressed Card with style size of medium, card border, Equal height, Anchoring all the card, media position to the top, and passing an extra Bootstrap ~5.3.0 utility classes for light background and large shadow over the used card

Which only has the following in varbase-blog-card-impressed-medium.twig file:

{% include 'varbase_components:card-impressed' with {
  style_size: 'medium',
  card_border: true,
  equal_height: true,
  anchor_all: true,
  media_position: 'top',
  utility_classes: ['bg-light', 'shadow-lg'],
  media_utility_classes: [],
  content_utility_classes: [],
  media: media,
  content: content,
} only %}

The equivalent in Storybook using the custom Varbase Impressed Card -medium

Which is the equivalent of using the default Impressed Card - medium - with Read more story with the default standard Impressed Card in the storybook - but without the light background and no shadows.

More Info and FAQ about SDC

Read: Using Single Directory Components

Read: F.A.Q. (Frequently Asked Questions) about SDC

Read: Creating Your First Single Directory Component within Drupal

Read: Single Directory Components in Drupal Core

Watch: Single Directory Components in Core: Pittsburgh 2023

SDC Examples

Component Libraries: Components Examples

Have a look at the code and README.md for list of props, slots, and example how to use.



Following with of JSON Schema, which is a declarative language that allows you to annotate and validate JSON documents.

To follow with metadata.schema.json selected by Drupal Core team

to integrate with that

serves as an exemplary model for understanding how to effectively manage various elements such as Content types, View modes, Layout Libraries, Views, site section pages, categories, and tags using the comprehensive range of "assembled" , modules, and "Starterkit/Recipes" configs.

Example first approach: Use the module. Select a component for a field display from the UI, and map values to props and slots. Example second approach: Create a card-text-body-field component and use the component with the twig template in Vartheme BS5 suggestion for the field body.

The component files are in ( )

module

module

, , , , ...

Varbase Components
Draft 4
https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json
Storybook JSON Schema Addon
Integration of Varbase with Storybook 1.0 - CL Server
Varbase Blog
Varbase Components
varbase-blog-card-impressed-medium.zip
varbase-blog-card-featured-small.zip
varbase-blog-card-featured-xsmall.zip
varbase-blog-card-text-small.zip
SDC Display
varbase-blog-card-impressed-medium.zip
https://www.drupal.org/docs/develop/theming-drupal/using-single-directory-components
https://www.drupal.org/docs/develop/theming-drupal/using-single-directory-components/faq-frequently-asked-questions
https://herchel.com/articles/creating-your-first-single-directory-component-within-drupal
https://www.lullabot.com/articles/getting-single-directory-components-drupal-core
https://www.youtube.com/watch?v=gDd7pCK9KsA
SDC Examples
Varbase Components
Featured Card
Impressed Card
Overlay Card
Hero Card
Text Card
Button
Close Button
Badge
Alert
Progress Bar
JSON SchemaJSON Schema
JSON Schema Enables the Confident and Reliable use of the JSON Data Format
Logo
View of the Impressed Card size of medium with custom in Varbase ~10.0.0
View of the Impressed Card size of medium with custom in Varbase Storybook
Impressed Card - medium - with Read more