Skip to content
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
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
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 Mar 18, 2022
fce00dc
Add scratch reference and API sections
amyrlam Mar 18, 2022
484f936
Add base component: icon, title, body only
amyrlam Mar 18, 2022
8ed1abb
Fix prop name in comment
amyrlam Mar 18, 2022
b34c465
Delete second Alert in scrappy docs
amyrlam Mar 18, 2022
e6f3056
Rename `body` to `description`
amyrlam Mar 19, 2022
2cf5156
Move classNames to bottom of file per repo pattern
amyrlam Mar 19, 2022
b665352
Add TODO for later
amyrlam Mar 19, 2022
ea4e335
Temp skip tests and fix prettier
amyrlam Mar 19, 2022
31d6c90
Remove mention of icon size of 24
amyrlam Mar 19, 2022
34a2b0a
Remove <p> from alert
amyrlam Mar 19, 2022
8080b8e
Add title or description required logic
amyrlam Mar 19, 2022
633d294
Change to this to be consistent
amyrlam Mar 19, 2022
de56be0
simplified “alert” base implementation
didoo Mar 21, 2022
3ab5ade
Merge pull request #101 from hashicorp/cr-alert-base-tweaks
amyrlam Mar 21, 2022
74b2d7f
Lint tests and remove /tests from .prettierignore
amyrlam Mar 21, 2022
411eb13
added handling of the “actions” to the “Alert/Base” component
didoo Mar 21, 2022
0e8cbd4
updated showcase for “Alerts” to include examples of actions
didoo Mar 21, 2022
85ff8b8
added custom styles for “Alerts” dummy page
didoo Mar 21, 2022
bdc737d
small fix to the “DummyPlaceholder” component
didoo Mar 21, 2022
154a8be
first stab at adding documentation for the “actions” of the “Alert” c…
didoo Mar 21, 2022
a3b6cb9
refactored “Actions” in “Alert” component to support yielded componen…
didoo Mar 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions packages/components/addon/components/hds/alert/index.hbs
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}}
Copy link
Contributor

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

<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>
36 changes: 36 additions & 0 deletions packages/components/addon/components/hds/alert/index.js
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;
}
}
1 change: 1 addition & 0 deletions packages/components/app/components/hds/alert/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@hashicorp/design-system-components/components/hds/alert/index';
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@use "helpers/elevation";
@use "helpers/focus-ring";

@use "../components/alert";
@use "../components/badge";
@use "../components/badge-count";
@use "../components/breadcrumb";
Expand Down
44 changes: 44 additions & 0 deletions packages/components/app/styles/components/alert.scss
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class DummyPlaceholderIndexComponent extends Component {
get width() {
let { width = '100%' } = this.args;

if (typeof width === 'string' && width.match(/[\d]+/)) {
if (typeof width === 'string' && width.match(/^[\d]+$/)) {
width = `${parseInt(width, 10)}px`;
}

Expand All @@ -28,7 +28,7 @@ export default class DummyPlaceholderIndexComponent extends Component {
get height() {
let { height = '100%' } = this.args;

if (typeof height === 'string' && height.match(/[\d]+/)) {
if (typeof height === 'string' && height.match(/^[\d]+$/)) {
height = `${parseInt(height, 10)}px`;
}

Expand Down
1 change: 1 addition & 0 deletions packages/components/tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Router.map(function () {
this.route('focus-ring');
});
this.route('components', function () {
this.route('alert');
this.route('badge');
this.route('breadcrumb');
this.route('button');
Expand Down
1 change: 1 addition & 0 deletions packages/components/tests/dummy/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@import "./_typography";

@import "./pages/db-alert";
@import "./pages/db-badge";
@import "./pages/db-breadcrumb";
@import "./pages/db-button";
Expand Down
15 changes: 15 additions & 0 deletions packages/components/tests/dummy/app/styles/pages/db-alert.scss
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;
}
Loading