-
Notifications
You must be signed in to change notification settings - Fork 3
Add Badge component, pencil icon, demo roles to Comment #1379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6dd9a58
Basic WIP badge design
tylersticka 14109d7
Adjust spacing
tylersticka 7c795a6
Add pencil icon
tylersticka 928c8a1
Integrate badge into comments
tylersticka 99d0bfa
Add comments to badge
tylersticka 24dcb69
Add changeset
tylersticka 9ec9af2
Hide decorative icons from screen readers
tylersticka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@cloudfour/patterns': minor | ||
| --- | ||
|
|
||
| Add 'pencil' icon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@cloudfour/patterns': minor | ||
| --- | ||
|
|
||
| Add Badge component |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| @use "../../compiled/tokens/scss/font-weight"; | ||
| @use "../../compiled/tokens/scss/line-height"; | ||
| @use "../../compiled/tokens/scss/size"; | ||
| @use '../../mixins/ms'; | ||
| @use 'sass:math'; | ||
|
|
||
| .c-badge { | ||
| align-items: center; | ||
| background: var(--theme-color-background-secondary); | ||
| border-radius: size.$border-radius-medium; | ||
| color: var(--theme-color-text-muted); | ||
| display: inline-flex; | ||
| font-size: ms.step(-1); | ||
| font-weight: font-weight.$medium; | ||
| // Because the text in a badge does not wrap, we can avoid icons accidentally | ||
| // increasing the height as often by setting this here instead of relying on | ||
| // vertical padding. | ||
| height: ms.step(2); | ||
| line-height: line-height.$tighter; | ||
| // We only apply half padding because the padding feels too tight around icons | ||
| // but not around the label content. We'll apply the other half of padding on | ||
| // the content element itself. | ||
| padding: 0 math.div(size.$padding-cell-horizontal, 2); | ||
| vertical-align: middle; | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| .c-badge__content { | ||
| &:first-child { | ||
| padding-left: math.div(size.$padding-cell-horizontal, 2); | ||
| } | ||
|
|
||
| &:last-child { | ||
| padding-right: math.div(size.$padding-cell-horizontal, 2); | ||
| } | ||
| } | ||
|
|
||
| .c-badge__extra { | ||
| align-items: center; | ||
| display: flex; | ||
| flex: none; | ||
| justify-content: center; | ||
| min-width: ms.step(2); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { Story, Canvas, Meta } from '@storybook/addon-docs/blocks'; | ||
| import template from './badge.twig'; | ||
|
|
||
| <Meta | ||
| title="Components/Badge" | ||
| argTypes={{ | ||
| label: { type: { name: 'string' } }, | ||
| icon: { | ||
| type: { name: 'string' }, | ||
| control: { | ||
| type: 'select', | ||
| options: ['', 'check', 'heart', 'pencil'], | ||
| }, | ||
| defaultValue: '', | ||
| }, | ||
| }} | ||
| /> | ||
|
|
||
| # Badge | ||
|
|
||
| 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). | ||
|
|
||
| <Canvas> | ||
| <Story name="Basic" args={{ label: 'Hello' }}> | ||
| {(args) => template(args)} | ||
| </Story> | ||
| </Canvas> | ||
|
|
||
| ## With icon | ||
|
|
||
| <Canvas> | ||
| <Story name="With icon" args={{ icon: 'check', label: 'Verified' }}> | ||
| {(args) => template(args)} | ||
| </Story> | ||
| </Canvas> | ||
|
|
||
| ## Template Properties | ||
|
|
||
| - `class` (string) | ||
| - `icon` (string): The name of one of [our icons](/docs/design-icons--page) to display. | ||
| - `message` (string, default `'Label'`) | ||
|
|
||
| ## Template Blocks | ||
|
|
||
| - `content`: The main label content, typically the value of `message`. | ||
| - `extra`: A visual extra preceding the content, typically populated by an icon if `icon` is set. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| {% set _extra_content %} | ||
| {% block extra %} | ||
| {% if icon %} | ||
| {% include '@cloudfour/components/icon/icon.twig' with { | ||
| name: icon, | ||
| aria_hidden: 'true', | ||
| } only %} | ||
| {% endif %} | ||
| {% endblock %} | ||
| {% endset %} | ||
|
|
||
| <span class="c-badge{% if class %} {{class}}{% endif %}"> | ||
| {% if _extra_content|trim %} | ||
| <span class="c-badge__extra"> | ||
| {{_extra_content}} | ||
| </span> | ||
| {% endif %} | ||
| <span class="c-badge__content"> | ||
| {% block content %} | ||
| {{label|default('Label')}} | ||
| {% endblock %} | ||
| </span> | ||
| </span> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed the Firefox a11y inspector was complaining about this being an unlabeled image:
Since this is decorative should we add
aria-hidden="true"orrole="presentation"?(FWIW this does read correctly in VoiceOver, but I wonder if it could lead to issues in other assistive technologies.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh! This is an oversight on my part, thank you for pointing it out.