-
Notifications
You must be signed in to change notification settings - Fork 47
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
[SPIKE] "Alert" component - actions implementation #104
Closed
Closed
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
792ee62
Set up Alert base branch
amyrlam fce00dc
Add scratch reference and API sections
amyrlam 484f936
Add base component: icon, title, body only
amyrlam 8ed1abb
Fix prop name in comment
amyrlam b34c465
Delete second Alert in scrappy docs
amyrlam e6f3056
Rename `body` to `description`
amyrlam 2cf5156
Move classNames to bottom of file per repo pattern
amyrlam b665352
Add TODO for later
amyrlam ea4e335
Temp skip tests and fix prettier
amyrlam 31d6c90
Remove mention of icon size of 24
amyrlam 34a2b0a
Remove <p> from alert
amyrlam 8080b8e
Add title or description required logic
amyrlam 633d294
Change to this to be consistent
amyrlam de56be0
simplified “alert” base implementation
didoo 3ab5ade
Merge pull request #101 from hashicorp/cr-alert-base-tweaks
amyrlam 74b2d7f
Lint tests and remove /tests from .prettierignore
amyrlam 411eb13
added handling of the “actions” to the “Alert/Base” component
didoo 0e8cbd4
updated showcase for “Alerts” to include examples of actions
didoo 85ff8b8
added custom styles for “Alerts” dummy page
didoo bdc737d
small fix to the “DummyPlaceholder” component
didoo 154a8be
first stab at adding documentation for the “actions” of the “Alert” c…
didoo a3b6cb9
refactored “Actions” in “Alert” component to support yielded componen…
didoo 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 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,82 @@ | ||
<div class={{this.classNames}} ...attributes role="alert"> | ||
{{#if this.icon}} | ||
<div class="hds-alert__icon"> | ||
<FlightIcon | ||
@name={{this.icon}} | ||
@size="24" | ||
{{! TODO: Replace w/dynamic color, once color prop implemented }} | ||
@color="var(--token-color-foreground-warning-on-surface)" | ||
@isInlineBlock={{false}} | ||
/> | ||
</div> | ||
{{/if}} | ||
|
||
<div class="hds-alert__content"> | ||
|
||
<div class="hds-alert__text"> | ||
{{#if @title}} | ||
<div class="hds-alert__title">{{@title}}</div> | ||
{{/if}} | ||
|
||
{{#if @description}} | ||
<div class="hds-alert__description">{{@description}}</div> | ||
{{/if}} | ||
</div> | ||
|
||
{{#if @actions}} | ||
<div class="hds-alert__actions"> | ||
{{#each @actions as |action|}} | ||
<div class="hds-alert__action"> | ||
{{#if (eq action.element "button")}} | ||
<Hds::Button | ||
@icon={{action.icon}} | ||
@iconPosition={{action.iconPosition}} | ||
@text={{action.text}} | ||
@color={{action.color}} | ||
{{! | ||
TODO: here we're assuming that all the buttons in the alert actions are small | ||
we have to discuss with CVeight what are the "defaults" and locked props we want here | ||
}} | ||
@size="small" | ||
/> | ||
{{/if}} | ||
{{#if (eq action.element "link-to")}} | ||
<Hds::LinkTo::Standalone | ||
@icon={{action.icon}} | ||
@iconPosition={{action.iconPosition}} | ||
@text={{action.text}} | ||
@color={{action.color}} | ||
@route="components.alert" | ||
{{! | ||
TODO: here we're assuming that all the links in the alert actions are small | ||
we have to discuss with CVeight what are the "defaults" and locked props we want here | ||
}} | ||
@size="small" | ||
/> | ||
{{/if}} | ||
{{#if (eq action.element "link")}} | ||
<Hds::Link::Standalone | ||
@icon={{action.icon}} | ||
@iconPosition={{action.iconPosition}} | ||
@text={{action.text}} | ||
@color={{action.color}} | ||
@href="#" | ||
{{! | ||
TODO: here we're assuming that all the links in the alert actions are small | ||
we have to discuss with CVeight what are the "defaults" and locked props we want here | ||
}} | ||
@size="small" | ||
/> | ||
{{/if}} | ||
</div> | ||
{{/each}} | ||
</div> | ||
{{/if}} | ||
{{#if (has-block "actions")}} | ||
<div class="hds-alert__actions"> | ||
{{yield to="actions"}} | ||
</div> | ||
{{/if}} | ||
|
||
</div> | ||
</div> |
This file contains 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,36 @@ | ||
import Component from '@glimmer/component'; | ||
import { assert } from '@ember/debug'; | ||
|
||
export default class HdsAlertIndexComponent extends Component { | ||
constructor() { | ||
super(...arguments); | ||
|
||
assert( | ||
`you need to pass @title or @description to the "Hds::Alert" component`, | ||
!(this.args.title === undefined && this.args.description === undefined) | ||
); | ||
} | ||
|
||
/** | ||
* @param icon | ||
* @type {string} | ||
* @default null | ||
* @description The name of the icon to be used. | ||
*/ | ||
get icon() { | ||
return this.args.icon ?? null; | ||
} | ||
|
||
/** | ||
* Get the class names to apply to the component. | ||
* @method Alert#classNames | ||
* @return {string} The "class" attribute to apply to the component. | ||
*/ | ||
// "hds-alert" | ||
get classNames() { | ||
let classes = ['hds-alert']; | ||
|
||
// TODO: Add type classes, once type implemented | ||
return classes; | ||
} | ||
} |
This file contains 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 @@ | ||
export { default } from '@hashicorp/design-system-components/components/hds/alert/index'; |
This file contains 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 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,42 @@ | ||
// | ||
// ALERT | ||
// | ||
// properties within each class are sorted alphabetically | ||
// | ||
// | ||
|
||
.hds-alert { | ||
background-color: var(--token-color-surface-warning); | ||
padding: 1.25rem; // 20px | ||
display: flex; | ||
align-content: flex-start; | ||
} | ||
|
||
.hds-alert__icon { | ||
margin-right: 0.75rem; // 12px | ||
} | ||
|
||
.hds-alert__text { | ||
color: var(--token-color-foreground-warning-on-surface); | ||
font-family: var(--token-typography-body-200-font-family); | ||
} | ||
|
||
.hds-alert__title { | ||
font-weight: var(--token-typography-font-weight-semibold); | ||
} | ||
|
||
.hds-alert__title + .hds-alert__description { | ||
margin-top: 0.75rem; // 12px | ||
} | ||
|
||
.hds-alert__actions { | ||
align-items: center; | ||
display: flex; | ||
margin-top: 1rem; // 16px | ||
} | ||
|
||
.hds-alert__action { | ||
& + & { | ||
margin-left: 1rem; // 16px | ||
} | ||
} |
This file contains 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
170 changes: 170 additions & 0 deletions
170
packages/components/tests/dummy/app/templates/components/alert.hbs
This file contains 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,170 @@ | ||
{{page-title "Alert component"}} | ||
|
||
<h2 class="dummy-h2">Alert</h2> | ||
|
||
<section> | ||
<h3 class="dummy-h3">Scratch reference links</h3> | ||
<p>Alert types coming soon: | ||
<code class="dummy-code">Hds::Alert::FullWidth</code>, | ||
<code class="dummy-code">Hds::Alert::Inline</code>, and | ||
<code class="dummy-code">Hds::Alert::Toast</code>. | ||
</p> | ||
<ul class="dummy-paragraph"> | ||
<li> | ||
<a href="https://docs.google.com/document/d/1MC0MTm8-0F26s6Y-gou_RsMj6rtKS6jC-eM7rmruqLY/edit#heading=h.gjdgxs"> | ||
WIP Alert Component Requirement Document (CRD) | ||
</a> | ||
</li> | ||
<li> | ||
<a | ||
href="https://www.figma.com/file/noyY6dUMDYjmySpHcMjhkN/branch/Ru0h1oqy6r7SeGxwtQ6085/HDS-Product---Components-%5BWIP%5D?node-id=4023%3A15691" | ||
> | ||
WIP Figma file | ||
</a> | ||
</li> | ||
</ul> | ||
</section> | ||
|
||
<section> | ||
<h3 class="dummy-h3">Component API</h3> | ||
<p class="dummy-paragraph">Here is the API for the component:</p> | ||
<dl class="dummy-component-props"> | ||
<dt>color <code>enum</code></dt> | ||
<dd> | ||
<p><code class="dummy-code">color</code> | ||
results in a default | ||
<code class="dummy-code">icon</code>, which | ||
<strong>can</strong> | ||
be overriden. | ||
<code class="dummy-code">color</code> | ||
sets the color scheme for background, border, | ||
<code class="dummy-code">title</code>, and | ||
<code class="dummy-code">description</code>, which | ||
<strong>cannot</strong> | ||
be overriden. | ||
</p> | ||
<p>Acceptable values:</p> | ||
<ol> | ||
<li>critical</li> | ||
<li>warning</li> | ||
<li class="default">neutral</li> | ||
<li>highlight</li> | ||
<li>success</li> | ||
</ol> | ||
</dd> | ||
|
||
<dt class="dummy-indent">icon <code>string</code></dt> | ||
<dd class="dummy-indent"> | ||
<p>Shows an icon in the alert. Optional parameter.</p> | ||
<p>Acceptable value:</p> | ||
<p>Any | ||
<a href="https://flight-hashicorp.vercel.app/" target="_blank" rel="noopener noreferrer"> | ||
Flight icon</a> | ||
name. | ||
</p> | ||
</dd> | ||
|
||
<dt>title <code>string</code></dt> | ||
<dd> | ||
<p> | ||
The title text in the alert. | ||
<code class="dummy-code">title</code> | ||
<strong>and/or</strong> | ||
<code class="dummy-code">description</code> | ||
is required. | ||
</p> | ||
</dd> | ||
|
||
<dt>description <code>string</code></dt> | ||
<dd> | ||
<p>The description text in the alert. | ||
<code class="dummy-code">description</code> | ||
<strong>and/or</strong> | ||
<code class="dummy-code">title</code> | ||
is required.</p> | ||
</dd> | ||
|
||
<dt>isDismissible <code>boolean</code></dt> | ||
<p>The alert can be dismissed by the user. This parameter has some accessibility considerations for | ||
<code class="dummy-code">Hds::Alert::Toast</code> | ||
(<code class="dummy-code">role="alertdialog"</code>). | ||
</p> | ||
<dd> | ||
<p>Acceptable values:</p> | ||
<ol> | ||
<li class="default">true</li> | ||
<li>false</li> | ||
</ol> | ||
</dd> | ||
|
||
<dt>hasActions <code>boolean</code></dt> | ||
<p>The alert has content below the | ||
<code class="dummy-code">title</code> | ||
and | ||
<code class="dummy-code">description</code>, such as an | ||
<code class="dummy-code">Hds::Button</code> | ||
and an | ||
<code class="dummy-code">Hds::LinkTo::Standalone</code>. | ||
</p> | ||
<dd> | ||
<p>Acceptable values:</p> | ||
<ol> | ||
<li>true</li> | ||
<li class="default">false</li> | ||
</ol> | ||
</dd> | ||
|
||
<dt>“splattributes”</dt> | ||
<dd> | ||
<p><code class="dummy-code">...attributes</code> spreading is supported on this component.</p> | ||
</dd> | ||
</dl> | ||
</section> | ||
|
||
<section> | ||
<h3 class="dummy-h3">Temporary scratch showcase</h3> | ||
<Hds::Alert | ||
@icon="alert-triangle" | ||
@title="Alert w/title & description" | ||
@description="Your Intention settings are currently set to default allow. This | ||
means that this view will show connections to every service in your | ||
cluster. We recommend changing your Intention settings to default deny and | ||
creating specific Intentions for upstream and downstream services for this | ||
view to be useful." | ||
/> | ||
<br /> | ||
<Hds::Alert @icon="alert-triangle" @description="Description only please" /> | ||
<br /> | ||
<Hds::Alert | ||
@icon="alert-triangle" | ||
@title="Really long title, yet no description. Your Intention settings are currently set to default allow. This | ||
means that this view will show connections to every service in your | ||
cluster. We recommend changing your Intention settings to default deny and | ||
creating specific Intentions for upstream and downstream services for this | ||
view to be useful." | ||
/> | ||
<br /> | ||
Below alert with no title, no description does not appear (see error in console): | ||
<Hds::Alert @icon="meh" /> | ||
<br /> | ||
</section> | ||
|
||
<section> | ||
<h3 class="dummy-h3">How to use</h3> | ||
</section> | ||
|
||
<section> | ||
<h3 class="dummy-h3">Design guidelines</h3> | ||
</section> | ||
|
||
<section data-test-percy> | ||
<h3 class="dummy-h3">Showcase</h3> | ||
<h4 class="dummy-h4">Content</h4> | ||
|
||
<h4 class="dummy-h4">Size</h4> | ||
|
||
<h4 class="dummy-h4">Type</h4> | ||
|
||
<h4 class="dummy-h4">Color:</h4> | ||
|
||
</section> |
This file contains 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
Oops, something went wrong.
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 haven't looked at any use cases in the "real world" of consumers yet, but I think that this is a really interesting approach! I can't recall seeing an Ember component that strongly recommends a default, but allows an escape hatch, in this manner