Skip to content

Commit 799e874

Browse files
authored
Add Badge component, pencil icon, demo roles to Comment (#1379)
* Add Badge component * Add pencil icon * Integrate role Badge into Comment
1 parent 717bf10 commit 799e874

File tree

8 files changed

+174
-2
lines changed

8 files changed

+174
-2
lines changed

.changeset/kind-beans-fry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': minor
3+
---
4+
5+
Add 'pencil' icon

.changeset/loud-ligers-remember.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': minor
3+
---
4+
5+
Add Badge component

src/assets/icons/pencil.svg

Lines changed: 7 additions & 0 deletions
Loading

src/components/badge/badge.scss

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@use "../../compiled/tokens/scss/font-weight";
2+
@use "../../compiled/tokens/scss/line-height";
3+
@use "../../compiled/tokens/scss/size";
4+
@use '../../mixins/ms';
5+
@use 'sass:math';
6+
7+
.c-badge {
8+
align-items: center;
9+
background: var(--theme-color-background-secondary);
10+
border-radius: size.$border-radius-medium;
11+
color: var(--theme-color-text-muted);
12+
display: inline-flex;
13+
font-size: ms.step(-1);
14+
font-weight: font-weight.$medium;
15+
// Because the text in a badge does not wrap, we can avoid icons accidentally
16+
// increasing the height as often by setting this here instead of relying on
17+
// vertical padding.
18+
height: ms.step(2);
19+
line-height: line-height.$tighter;
20+
// We only apply half padding because the padding feels too tight around icons
21+
// but not around the label content. We'll apply the other half of padding on
22+
// the content element itself.
23+
padding: 0 math.div(size.$padding-cell-horizontal, 2);
24+
vertical-align: middle;
25+
white-space: nowrap;
26+
}
27+
28+
.c-badge__content {
29+
&:first-child {
30+
padding-left: math.div(size.$padding-cell-horizontal, 2);
31+
}
32+
33+
&:last-child {
34+
padding-right: math.div(size.$padding-cell-horizontal, 2);
35+
}
36+
}
37+
38+
.c-badge__extra {
39+
align-items: center;
40+
display: flex;
41+
flex: none;
42+
justify-content: center;
43+
min-width: ms.step(2);
44+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Story, Canvas, Meta } from '@storybook/addon-docs/blocks';
2+
import template from './badge.twig';
3+
4+
<Meta
5+
title="Components/Badge"
6+
argTypes={{
7+
label: { type: { name: 'string' } },
8+
icon: {
9+
type: { name: 'string' },
10+
control: {
11+
type: 'select',
12+
options: ['', 'check', 'heart', 'pencil'],
13+
},
14+
defaultValue: '',
15+
},
16+
}}
17+
/>
18+
19+
# Badge
20+
21+
Badges help provide just a smidge more context to repetitive or serialized content. For example, a badge can help the reader identify when [a comment on an article is by the author of that article](/docs/components-comment--role-author#role-badges).
22+
23+
<Canvas>
24+
<Story name="Basic" args={{ label: 'Hello' }}>
25+
{(args) => template(args)}
26+
</Story>
27+
</Canvas>
28+
29+
## With icon
30+
31+
<Canvas>
32+
<Story name="With icon" args={{ icon: 'check', label: 'Verified' }}>
33+
{(args) => template(args)}
34+
</Story>
35+
</Canvas>
36+
37+
## Template Properties
38+
39+
- `class` (string)
40+
- `icon` (string): The name of one of [our icons](/docs/design-icons--page) to display.
41+
- `message` (string, default `'Label'`)
42+
43+
## Template Blocks
44+
45+
- `content`: The main label content, typically the value of `message`.
46+
- `extra`: A visual extra preceding the content, typically populated by an icon if `icon` is set.

src/components/badge/badge.twig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% set _extra_content %}
2+
{% block extra %}
3+
{% if icon %}
4+
{% include '@cloudfour/components/icon/icon.twig' with {
5+
name: icon,
6+
aria_hidden: 'true',
7+
} only %}
8+
{% endif %}
9+
{% endblock %}
10+
{% endset %}
11+
12+
<span class="c-badge{% if class %} {{class}}{% endif %}">
13+
{% if _extra_content|trim %}
14+
<span class="c-badge__extra">
15+
{{_extra_content}}
16+
</span>
17+
{% endif %}
18+
<span class="c-badge__content">
19+
{% block content %}
20+
{{label|default('Label')}}
21+
{% endblock %}
22+
</span>
23+
</span>

src/components/comment/comment.stories.mdx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ Displays a single comment in a comment thread, optionally with replies. Multiple
1212

1313
This component is still a work in progress. The following features are still in development:
1414

15-
- Indicating when a comment's author is a Cloud Four team member.
1615
- Integrating the comment reply form.
17-
- Adding blocks to the template to allow for more customization.
16+
- Finalizing this pattern's blocks and properties for theme integration.
1817

1918
## Single
2019

@@ -32,6 +31,22 @@ This information may be passed to the component as a `comment` object matching t
3231
<Story name="Single">{template({ comment: makeComment() })}</Story>
3332
</Canvas>
3433

34+
## Role badges
35+
36+
It is helpful for context within a discussion to know when a commentor is the original post author or a Cloud Four team member. The mechanics of this feature are still in development, but these stories show how these roles should appear using [the Badge component](/docs/components-badge--basic).
37+
38+
<Canvas>
39+
<Story name="Role: Author">
40+
{template({ comment: makeComment(), demo_post_author: true })}
41+
</Story>
42+
</Canvas>
43+
44+
<Canvas>
45+
<Story name="Role: Cloud Four">
46+
{template({ comment: makeComment(), demo_cloud_four_member: true })}
47+
</Story>
48+
</Canvas>
49+
3550
## Unapproved
3651

3752
If `comment.approved` is not `true`, an [Alert](/docs/components-alert--basic) will indicate that the comment is not yet approved.

src/components/comment/comment.twig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44
<header class="c-comment__header">
55
<h{{_heading_depth}} class="c-comment__heading">
66
{{comment.author.name}}
7+
{#
8+
TODO: Replace `demo_post_author` and `demo_cloud_four_member` with
9+
more meaningful blocks or properties once we have a better idea of how
10+
we'll integrate role badging based on actual comment data.
11+
#}
12+
{% if demo_post_author %}
13+
<span class="u-hidden-visually">(Article</span>
14+
{% embed '@cloudfour/components/badge/badge.twig' with {
15+
label: 'Author',
16+
icon: 'pencil',
17+
} only %}
18+
{% endembed %}
19+
<span class="u-hidden-visually">)</span>
20+
{% elseif demo_cloud_four_member %}
21+
<span class="u-hidden-visually">(Cloud Four</span>
22+
{% embed '@cloudfour/components/badge/badge.twig' with {
23+
label: 'Team'
24+
} only %}
25+
{% block extra %}
26+
{% include '@cloudfour/assets/brand/logo.svg.twig' with {
27+
class: 'c-icon',
28+
aria_hidden: 'true',
29+
} only %}
30+
{% endblock %}
31+
{% endembed %}
32+
<span class="u-hidden-visually">Member)</span>
33+
{% endif %}
734
<span class="u-hidden-visually">
835
{% if comment.is_child %}replied{% else %}said{% endif %}:
936
</span>

0 commit comments

Comments
 (0)