zyrous / drupal-theme-base
This is used to create base theme based on storybook
Requires
- drupal/components: ^3.0@beta
- drupal/twig_tweak: ^3.2
This package is auto-updated.
Last update: 2025-08-30 06:47:47 UTC
README
Zyrous base theme package is hosted on [Packagist] (https://packagist.org/packages/zyrous/drupal-theme-base) Zyrous base theme repo is hosted on [Bitbucket] (https://bitbucket.org/zyrous/drupal-theme) Zyrous Gesso is a Sass-based starter theme that outputs accessible HTML5 markup. It uses a mobile-first responsive approach and leverages SMACSS to organize styles. This encourages a component-based approach to theming through the creation of discrete, reusable UI elements. Gesso is heavily integrated with Storybook and the Component Libraries module, allowing Drupal and Storybook to share the same markup.
Visit the Gesso Storybook demo site.
Global prerequisites
The following packages need to be installed on your system in order to compile and use Gesso.
Creating Subtheme
You can create a subtheme through a shell script.
- Navigate to the "themes/contrib/drupal-theme-base" folder change permissions to shell
script chmod +x scripts/create_subtheme.sh
and run:
./scripts/create_subtheme.sh or bash scripts/create_subtheme.sh
- The script will ask a series of configuration questions and then create your subtheme.
- If you don't already have a "themes/custom" folder, it will create one, then place your subtheme there.
From the subtheme folder:
- Install gulp:
npm install --global gulp-cli
Update line #19 of the gulpfile.js file with your own domain.
browserSync.init({ proxy: "http://yourdomain.com", });
Execution
Just run
gulp
This will generate a style.css file at subtheme/css folder.
Installation
Create the subtheme following above steps.
Enable the Gesso Helper module. This module comes packaged with the theme, but must be manually enabled for the theme to function.
Install the Component Libraries module. Since many of the Drupal templates reference twig files inside Storybook using Twig namespaces, this module is required for the theme to function.
Install the Twig Tweak module.
Optional: Install the Twig Field Value module. This is not required, but it can make working with Twig templates easier. Please note, however, that using the
|field_value
Twig filter from this module will break Drupal’s QuickEdit functionality.Optional: Install the Background Images Formatter module and its Responsive Background Images Formatter submodule. This is not required, but it will allow you to use images uploaded to Drupal as background images, with different image sizes at different breakpoints.
Getting started
For development, you can set the theme up as part of a Drupal site or work only in Storybook. Zyrous Gesso includes npm tasks to compile design tokens, CSS, JS, Storybook, and the SVG sprite using webpack.
To use these tasks, first run the following npm command in the theme folder to install node dependencies.
npm i
To compile the theme, start Storybook, and watch for changes run the following command in the theme directory:
npm run dev
Open localhost:6006 to view Storybook. If you’re using Docker (or some other container engine) for local development, this might be mapped to a custom domain or a port on a custom domain such as storybook.ddev.site or site.ddev.site:6006.
If you add new SCSS and/or JS files, you will need to restart webpack by
canceling and then re-running npm run dev
. New files will not be processed
until webpack restarts. Errors will also be shown for duplicate filenames.
To initiate the build tasks only (without watching for changes), run the following command in the theme directory:
npm run build
Generating new components
Run npm run component
to create boilerplate files for a new component. This is
the recommended approach as it will set up basic Twig and Storybook files that
you can modify.
Storybook
Name your stories files [component].stories.jsx
. See menu.stories.jsx
for
an example.
To match Storybook to your site’s branding, change the colors in
.storybook/manager.js
. Any fonts can be added in
.storybook/manager-head.html
. See the Storybook
docs for more
information about and examples of theming.
Sass
Sass can be compiled as part of the global styles.css file or to individual CSS files for use in a Drupal library.
@use
is used to import Sass variables, mixins, and/or functions into
individual SCSS files. @import
is discouraged by the Sass team and will
eventually be phased out..
This means that most files will start with @use '00-config' as *;
. This allows
you to use the design token accessor functions without an additional namespace.
Other functions and mixins can be used similarly. Note that to avoid namespace
collisions, only Gesso-related variables, mixins, and functions should be used
with *
.
All Sass files that are compiled to individual CSS files must have a unique filename, even if they are in different directories.
Global styles
Prefix the name of your Sass file with _
, e.g. _card.scss
. Add it to the
appropriate aggregate file (i.e. _components.scss
).
Individual component/library styles
DO NOT prefix the name of your Sass file with _
, e.g. menu.scss
. Import the
config and global aggregate files. Import your SCSS file at the top of your
Storybook file. See dropdown-menu.stories.jsx
for an example. Don’t forget to
add it to the gesso.libraries.yml
file as well.
Sass Linting
Stylelint and Prettier are used to lint CSS and SCSS files. Warnings will break the build, so if you have a valid reason to break Stylelint rules you can have it ignore code in two ways:
Add
// stylelint-disable-next-line
to the line just before where the Stylelint warning is triggered.To ignore several lines, add
// stylelint-disable
before the code in question and add// stylelint-enable
afterwards.
In both cases above, please add a comment about the valid reason to disable the Stylelint rule(s) in your use case.
The Stylelint rules can be changed in the .stylelintrc.yml
file. By default,
Gesso follows the
sass-guideline.es
and Prettier’s recommended
guidelines, with some
additional customizations.
The Prettier config can be changed in the .prettierrc
file.
JavaScript
JavaScript can be compiled to individual JS files for use in a JavaScript
library or included within a different JS file. JS files that use modern
(ES2015+) syntax must be named [name].es6.js
, but this is not required by the
compiler. JavaScript files should go in the appropriate folder under source
(e.g., source/03-components/menu
for menu-related JavaScript). There is not a
separate folder for JS files as there was in previous versions of Gesso.
All JavaScript files must have a unique filename, even if they are in different directories.
Modules
Prefix the name of your JavaScript file with _
, e.g. _Menu.es6.js
. Import it
to the appropriate JavaScript file(s), (i.e. primary-menu.es6.js
).
Individual component/library scripts
DO NOT prefix the name of your JS file with _
. Import your JS file at the top
of your Storybook file. See dropdown-menu.stories.jsx
for an example. Don’t
forget to add it to the gesso.libraries.yml
file as well.
JS Linting
ESLint and Prettier are used to lint JavaScript files. If you have a valid reason to break one of the rules, you can ignore a specific line using any of the options in the ESLint documentation.
Please add a comment about the valid reason to disable the ESLint rule(s) in your use case.
The ESLint config can be changed in the .eslintrc.js
file. Gesso follows the
Airbnb standards, which are followed
by Drupal
as well.
The Prettier config can be changed in the .prettierrc
file.
Design tokens
Gesso uses the configuration file source/00-config/config.design-tokens.yml
to
manage the theme’s design tokens. The npm build and dev tasks will automatically
generate a global Sass map to easily pull design tokens into individual SCSS
files.
Functions
The following Sass functions can be used to access the tokens defined in
config.design-tokens.yml
.
gesso-box-shadow($shadow)
Output a shadow value from the box-shadow token list.
box-shadow: gesso-box-shadow(1);
gesso-breakpoint($breakpoint)
Output a size value from the breakpoints token list.
@include breakpoint(gesso-breakpoint(desktop)) {
display: flex;
}
@include breakpoint-max(gesso-breakpoint(mobile), true) {
display: none;
}
@include breakpoint-min-max(
gesso-breakpoint(mobile),
gesso-breakpoint(tablet),
true
) {
display: block;
}
gesso-brand($color, $variant)
Output a color value from the palette brand token list.
color: gesso-brand(blue, light);
gesso-color($type, $subtype)
Output a color value from the colors token list.
color: gesso-color(text, primary);
gesso-constrain($constrain)
Output a size value from the constrains token list.
max-width: gesso-constrain(sm);
gesso-duration($duration)
Output a timing value from the transitions duration token list.
transition-duration: gesso-duration(short);
gesso-easing($easing)
Output an easing value from the transitions ease token list.
transition-timing-function: gesso-easing(ease-in-out);
gesso-font-family($family)
Output a stack value from the font-family token list.
font-family: gesso-font-family(primary);
gesso-font-size($size)
Output a size value from the font-size token list.
font-size: rem(gesso-font-size(2));
gesso-font-weight($weight)
Output a weight value from the font-weight token list.
font-weight: gesso-font-weight(semibold);
gesso-grayscale($color)
Output a color value from the palette grayscale token list.
color: gesso-grayscale(gray-2);
gesso-line-height($height)
Output a height value from the line-height token list.
line-height: gesso-line-height(tight);
gesso-spacing($spacing)
Output a size value from the spacing token list.
margin-bottom: rem(gesso-spacing(md));
gesso-z-index($index)
Output an index value from the z-index token list.
z-index: gesso-z-index(modal);
Design tokens in JavaScript
The values in Gesso’s configuration file are also exported to JavaScript objects
so that the same values can be used in CSS and JS. The JS objects can be found
in source/00-config/_GESSO.es6.js
. This file is also rebuilt whenever
npm run dev
or npm run build
are run.
For example, to use a breakpoint in a script:
import { BREAKPOINTS } from '../../../00-config/_GESSO.es6';
if (window.matchMedia(`min-width: ${BREAKPOINTS.desktop}`).matches) {
// Some script that should only run on larger screens.
}
This will use the same breakpoint as breakpoint(gesso-breakpoint(desktop))
in
your Sass.
Width-based media queries
Gesso uses custom mixins to specify viewport width based media queries:
breakpoint
: min-width queriesbreakpoint-max
: max-width queriesbreakpoint-min-max
: queries with both a min and max width
Each mixin takes one or two width parameters, which can be a straight value
(e.g., 800px, 40em) or a design token value called using the gesso-breakpoint
function (e.g., gesso-breakpoint(tablet-lg)
). The breakpoint-max
and
breakpoint-min-max
mixins can also take an optional parameter to subtract one
pixel from the max-width value, which can be useful when you want your query to
go up to the value but not to include it, such as when using Gesso breakpoint
token values.
@include breakpoint($width) { // styles }
Output a min-width based media query.
@include breakpoint(800px) {
display: flex;
}
@include breakpoint(gesso-breakpoint(desktop)) {
display: none;
}
@include breakpoint-max($width, $subtract_1_from_max) { // styles }
Output a max-width based media query. The optional $subtract_1_from_max
parameter will subtract 1px from the width value if set to true
(default:
false
).
@include breakpoint-max(900px) {
display: block;
}
@include breakpoint-max(gesso-breakpoint(mobile), true) {
display: none;
}
@include breakpoint-min-max($min-width, $max-width, $subtract_1_from_max) { // styles }
Output a media query with both a min-width and max-width. The optional
$subtract_1_from_max parameter will subtract 1px from the max-width value if
set to true
(default: false
).
@include breakpoint-min-max(400px, 700px) {
display: flex;
}
@include breakpoint-min-max(
gesso-breakpoint(mobile),
gesso-breakpoint(tablet),
true
) {
display: block;
}
Building Storybook
A static Storybook site can be built with npm run build-storybook
. You will
then be able to view Storybook at
YOUR_URL/themes/gesso/storybook/index.html.
Theme settings
Some aspects of Gesso can be configured in the theme settings. These include the Back to Top component, Breadcrumb options, and Button styles for links.
For the buttons, put the classes that should be added for each button size
and button style on each line, with classes separated with .
, similar to how
you would add custom classes to the WYSIWYG editor.
c-button|Primary
c-button.c-button--secondary|Secondary
c-button.c-button--tertiary|Tertiary
To use these classes, select Gesso Button as the formatter for a link field under the entity's display settings.