Skip to content

Example components ​

The example subtheme frame_demo_umami (examples/frame_demo_umami/) has components that show what a component can do in Frame: slots that hold other blocks, lists of values, images from the media library, icons, colours of the theme, Width and the other features of Layout and style, and React. Each one is a normal Single Directory Component: copy the folder into your theme, rename it, and change it.

ComponentGroupReactShows
Tabs and TabLayoutnoa slot of blocks of one kind, a behavior that runs on the page but not in the editor
CarouselLayoutnoa slot of any blocks, a slider that works in the editor, an editor-only switch
Questions and answersContentnoa list with rich text, structured data for search engines
TimelineContentnoa list with icons, CSS scroll-driven animation
Feature gridContentnoa list with icons and links, a colour of the theme, a slot for buttons
Comparison tableContentnoa list of lists (the cells of a table)
IconContentnothe icon picker and an icon font for the whole theme
Recipe explorerContentyescontent of a view as JSON, filters in React, a slot next to a React root, controls that work in Edit mode
Tag chip and Category pillContentnothe items of a list (item: in the component file)
Gallery item and Gallery gridMedianothe items and the wrapper of a list, container queries
GalleryMediayesa list of images with their size and alt text, a lightbox
Logo cloudMedianoimages in a list, an animation in CSS only
Hero with videoMedianoa picture with responsive image styles, a video, Width Full width
Pricing tableMarketingyesnumbers, lists inside a list, state in React
Numbers that count upMarketingyesan animation that starts when it scrolls into view
TestimonialsMarketingyesimages in a list, a slider that plays by itself
CountdownMarketingyesa date and time, a timer
Sign-up formMarketingnoa form with checks in the browser

In the editor ​

The components are dragged onto a page and edited: the carousel, the tabs, the price switch, the numbers, the lightbox and the search of the questions, in the editor and on the published page.

Try them ​

Build the subtheme and make it the theme of the site (see Getting started):

bash
cd examples/frame_demo_umami && npm install && npm run build
drush theme:install frame_demo_umami && drush config:set system.theme default frame_demo_umami -y && drush cr

The components are in the Blocks panel of the editor, in the groups Layout, Content, Media and Marketing. Each starts with example content, so it looks finished the moment it is dropped on the page.

What they have in common ​

  • Server markup first. Every component, also the React ones, prints its content in Twig. The page reads without JavaScript, and search engines see the text. React and the small scripts then add what moves.
  • The props of a React component go in one attribute. The template prints data-props="{{ data|json_encode }}", and index.jsx mounts the component with JSON.parse(element.dataset.props). A list of values arrives as a list.
  • The theme's tokens. Colours, spacing and fonts come from CSS custom properties: --frame-accent, --frame-space-m, --font-display, or frame.space(m) in SCSS. Change the tokens in frame_demo_umami.info.yml and the components follow.
  • Accessible. Real buttons and links, labels, aria-* where HTML has no element for it, the keyboard, focus that can be seen, and no motion for visitors who asked their system for less (prefers-reduced-motion).
  • Phone first. One column on a phone, more from the theme's breakpoints on (tablet 48em, desktop 75em).
  • Translated. Fixed text is |t in Twig and Drupal.t() in JavaScript, with Spanish in translations/es.po (see Translations).

Scripts on the page, not in the editor ​

Frame runs the behaviors of a component in its canvas only when the component has no slot: a React island would replace what is in the slot, and with it the drop zones of the editor (Components for the editor). So:

  • Components without slots (Gallery, Pricing table, Testimonials…) work in the editor as on the page: the lightbox opens, the switch changes the prices.
  • Components with slots (Tabs, Carousel, Hero with video) are written so that their markup without a script is what the editor needs: all tabs one under the other, all slides side by side. A small script (tabs.js, carousel.js) turns that into tabs and a carousel on the page. Rules for the editor only are scoped to #frame-editor, or to the editor's slot markup [data-frame-editor-slot] > [data-puck-dropzone].

Tests ​

The React components and the Tabs behavior have Jest tests in __tests__/:

bash
cd examples/frame_demo_umami && npm test