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.
| Component | Group | React | Shows |
|---|---|---|---|
| Tabs and Tab | Layout | no | a slot of blocks of one kind, a behavior that runs on the page but not in the editor |
| Carousel | Layout | no | a slot of any blocks, a slider that works in the editor, an editor-only switch |
| Questions and answers | Content | no | a list with rich text, structured data for search engines |
| Timeline | Content | no | a list with icons, CSS scroll-driven animation |
| Feature grid | Content | no | a list with icons and links, a colour of the theme, a slot for buttons |
| Comparison table | Content | no | a list of lists (the cells of a table) |
| Icon | Content | no | the icon picker and an icon font for the whole theme |
| Recipe explorer | Content | yes | content 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 pill | Content | no | the items of a list (item: in the component file) |
| Gallery item and Gallery grid | Media | no | the items and the wrapper of a list, container queries |
| Gallery | Media | yes | a list of images with their size and alt text, a lightbox |
| Logo cloud | Media | no | images in a list, an animation in CSS only |
| Hero with video | Media | no | a picture with responsive image styles, a video, Width Full width |
| Pricing table | Marketing | yes | numbers, lists inside a list, state in React |
| Numbers that count up | Marketing | yes | an animation that starts when it scrolls into view |
| Testimonials | Marketing | yes | images in a list, a slider that plays by itself |
| Countdown | Marketing | yes | a date and time, a timer |
| Sign-up form | Marketing | no | a 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):
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 crThe 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 }}", andindex.jsxmounts the component withJSON.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, orframe.space(m)in SCSS. Change the tokens inframe_demo_umami.info.ymland 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 (
tablet48em,desktop75em). - Translated. Fixed text is
|tin Twig andDrupal.t()in JavaScript, with Spanish intranslations/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__/:
cd examples/frame_demo_umami && npm test