From 722ae5afb6b3d50b11737d678cbdfcabfcb8906f Mon Sep 17 00:00:00 2001 From: Tyler Sticka Date: Fri, 8 Apr 2022 15:44:15 -0700 Subject: [PATCH] Replace buggy Author avatar object with block --- .changeset/good-ligers-arrive.md | 5 +++ src/components/author/author.stories.mdx | 10 ++++-- src/components/author/author.twig | 41 ++++++++++++++---------- 3 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 .changeset/good-ligers-arrive.md diff --git a/.changeset/good-ligers-arrive.md b/.changeset/good-ligers-arrive.md new file mode 100644 index 000000000..e827cacec --- /dev/null +++ b/.changeset/good-ligers-arrive.md @@ -0,0 +1,5 @@ +--- +'@cloudfour/patterns': major +--- + +Replaces the buggy Author `avatar.src` functionality with a template block diff --git a/src/components/author/author.stories.mdx b/src/components/author/author.stories.mdx index 737ced807..a19cac88f 100644 --- a/src/components/author/author.stories.mdx +++ b/src/components/author/author.stories.mdx @@ -13,7 +13,7 @@ const allAuthors = [ }, { name: 'Danielle Romo', - avatar: { src: danielleImage, width: 64 }, + avatar: danielleImage, link: 'https://cloudfour.com/is/danielle', }, { @@ -142,7 +142,7 @@ Multiple authors are also supported. `authors` (array): Array of [author objects](https://timber.github.io/docs/reference/timber-user/#properties), each containing: - `name` (string): The author's name. -- `avatar` (string or object): If this is an object containing a `src`, this will be passed directly to [the Avatar component](/?path=/docs/components-avatar--empty) (along with any other properties, for example `srcset` or `sizes`). Otherwise, it is assumed to be a string and used as the Avatar's `src` property. +- `avatar` (string): A URL for the author's avatar. For more complex customization, use the `avatars` block. - `link` (optional, string): An `href` for the author's name to link to, for example a bio page. `author_prefix` (optional, string, default "By"): Used to create a more @@ -154,3 +154,9 @@ accessible user experience by adding visually hidden text, prefixes the author n `date_prefix` (optional, string, default "Published on"): Used to create a more accessible user experience by adding visually hidden text, prefixes the date value (e.g. "Published on March 31st, 2021") + +## Template Blocks + +- `authors`: The author links to display. +- `avatars`: The [Avatars](/?path=/docs/components-avatar--empty), which will be passed to a [Bunch](/?path=/docs/objects-bunch--of-avatars). Use this if you want to make deeper customizations to the avatars, for example adding `srcset` and `sizes`. +- `meta_content`: The date or other additional content to display. diff --git a/src/components/author/author.twig b/src/components/author/author.twig index 17090876e..66a6bb227 100644 --- a/src/components/author/author.twig +++ b/src/components/author/author.twig @@ -40,17 +40,22 @@ {% endblock %} {% endset %} +{% set _avatars %} + {% block avatars %} + {% for author in authors %} + {% include '@cloudfour/components/avatar/avatar.twig' with { src: author.avatar } only %} + {% endfor %} + {% endblock %} +{% endset %} +
{# Avatar(s) #} - {% embed '@cloudfour/objects/bunch/bunch.twig' with { class: 'o-media__object' } %} + {% embed '@cloudfour/objects/bunch/bunch.twig' with { + class: 'o-media__object', + _avatars: _avatars + } only %} {% block content %} - {% for author in authors %} - {% if author.avatar.src is defined %} - {% include '@cloudfour/components/avatar/avatar.twig' with author.avatar only %} - {% else %} - {% include '@cloudfour/components/avatar/avatar.twig' with { src: author.avatar } only %} - {% endif %} - {% endfor %} + {{_avatars}} {% endblock %} {% endembed %} @@ -59,15 +64,17 @@ {# Author links #}

{{ author_prefix|default("By") }} - {% for author in authors %} - {% if loop.last and loop.length > 1 %}and {% endif %} - {% if author.link %} - {{ author.name }} - {% else %} - {{ author.name }} - {% endif %} - {%- if not loop.last and loop.length > 2 %},{% endif %} - {% endfor %} + {% block authors %} + {% for author in authors %} + {% if loop.last and loop.length > 1 %}and {% endif %} + {% if author.link %} + {{ author.name }} + {% else %} + {{ author.name }} + {% endif %} + {%- if not loop.last and loop.length > 2 %},{% endif %} + {% endfor %} + {% endblock %}

{# Author meta content #}