Generates a Drupal single directory component and Storybook stories
Requires Yeoman
npm install -g yo
npm i -g @bryanbuchs/generator-component
Or, to simplify the yo
command to component
:
npm i -g generator-component@npm:@bryanbuchs/generator-component
Run the generator from the theme directory, files will be scaffolded into components/{component-name}
:
yo component
and follow the prompts.
name
- The base name of the component ("Video")group
- The name of the storybook group for the component ("Media")
The group
and name
values will be combined to create the component-name
("MediaVideo", "media-video")
description
- Optional; added as a comment in the story and behavior filesfields
- An areay of fieldnames for the component. Choose a field type for each, and indicate if it is required.js
- Boolean choice to add a behavior.js file to the component + librarystyle
- Select what format (if any) stylesheets are in (less
,css
, or none)
yo component group-name --fields=field1,field2 --slots=slot1,slot2 --js
- If a fieldname is plural ("cards", "people"), it will be treated as an array
- If a fieldname begins with "is" or "has" it will be treated as a boolean
- a simple list of slot names ("body,sidebar")
- flag to generate a
behavior.js
file
- specify the format for styles. a
false
value will not generate a stylesheet
Running the generator will create a directory with a series of boilerplate files:
components/{component-name}/{component-name}.component.yml
components/{component-name}/{component-name}.stories.js
components/{component-name}/{component-name}.twig
components/{component-name}/{component-name}.library.js
components/{component-name}/{component-name}.(css|less)
components/{component-name}/{component-name}.behavior.js