-
Notifications
You must be signed in to change notification settings - Fork 44
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 all 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,87 @@ | ||
<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|}} | ||
{{#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}} | ||
{{/each}} | ||
</div> | ||
{{/if}} | ||
|
||
{{! IMPORTANT: don't change the formatting or it will add empty space inside the element (we're using ":empty" in CSS to hide it when it's empty!) }} | ||
{{#if (has-block "actions")}} | ||
<div class="hds-alert__actions">{{yield | ||
(hash | ||
Button=(component "hds/button") | ||
Link::Standalone=(component "hds/link/standalone") | ||
LinkTo::Standalone=(component "hds/link-to/standalone") | ||
) | ||
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,44 @@ | ||
// | ||
// 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 | ||
|
||
> * + * { | ||
margin-left: 1rem; // 16px | ||
} | ||
|
||
&:empty { | ||
display: none; | ||
} | ||
} |
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
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
15 changes: 15 additions & 0 deletions
15
packages/components/tests/dummy/app/styles/pages/db-alert.scss
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,15 @@ | ||
// ALERT | ||
|
||
.dummy-alert-sample-custom-actions__actions { | ||
display: flex; | ||
gap: 16px; | ||
align-items: center; | ||
} | ||
|
||
.dummy-alert-sample-custom-actions__text { | ||
@include dummyFontFamily(); | ||
@include dummyFontSize(0.8rem); | ||
display: block; | ||
color: #999; | ||
margin-top: 1rem; | ||
} |
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