Skip to content

Commit efda08d

Browse files
authored
Added alerts (#16)
Added alerts component
1 parent 814faa3 commit efda08d

File tree

11 files changed

+189
-1
lines changed

11 files changed

+189
-1
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ charset = utf-8
1111
trim_trailing_whitespace = true
1212
insert_final_newline = true
1313
indent_style = space
14+
indent_size = 4
15+
16+
[*.css]
1417
indent_size = 2
1518

1619
[*.hbs]
1720
insert_final_newline = false
21+
indent_size = 2
1822

1923
[*.{diff,md}]
2024
trim_trailing_whitespace = false
25+
indent_size = 2

addon/components/s-alert.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import Component from '@ember/component';
2+
import {
3+
computed
4+
} from '@ember/object';
5+
import layout from '../templates/components/s-alert';
6+
import { later } from '@ember/runloop';
7+
8+
export default Component.extend({
9+
layout,
10+
classNames: ['alert', 's-alert'],
11+
classNameBindings: ['alertClass', 'disappearing'],
12+
isHidden: false,
13+
disappearing: computed('isHidden', function() {
14+
return this.get('isHidden') ? 'disappearing' : '';
15+
}),
16+
alertClasses: computed(function () {
17+
return {
18+
info: 'alert-primary',
19+
warning: 'alert-warning',
20+
success: 'alert-success'
21+
};
22+
}),
23+
alertIcons: computed(function () {
24+
return {
25+
info: 'info',
26+
warning: 'alert-triangle',
27+
success: 'check-circle'
28+
};
29+
}),
30+
31+
alertClass: computed('type', function () {
32+
return this.get('alertClasses')[this.get('type')];
33+
}),
34+
alertIcon: computed('type', function () {
35+
return this.get('alertIcons')[this.get('type')];
36+
}),
37+
actions: {
38+
dismissAlert() {
39+
this.set('isHidden', true);
40+
later(this, function () {
41+
this.set('isVisible', false);
42+
}, 500);
43+
}
44+
}
45+
});

addon/styles/addon.scss

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
@import "components/_s-notification";
1717
@import "components/_s-steps";
1818
@import "components/_s-timeline";
19+
@import "components/s-alert";

addon/styles/components/_s-alert.scss

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.s-alert {
2+
&.alert-primary {
3+
background: #F2FAFF;
4+
border: 0.5px solid #049EE0;
5+
6+
.alert-icon {
7+
color: #049EE0;
8+
}
9+
}
10+
11+
&.alert-warning {
12+
background: #FFF4D6;
13+
border: 0.5px solid #F5A623;
14+
.alert-icon {
15+
color: #F5A623;
16+
vertical-align: sub;
17+
margin-bottom: 0;
18+
}
19+
}
20+
21+
&.alert-success {
22+
border: 0.5px solid #197B1B;
23+
background: #E0F6DE;
24+
}
25+
26+
&.alert {
27+
border-radius: 4px !important;
28+
padding: 0.2rem 1rem;
29+
margin-bottom: 5px;
30+
}
31+
32+
p {
33+
margin-bottom: 0;
34+
font-size: 12px;
35+
color: #424B52;
36+
37+
.alert-icon {
38+
width: 15px;
39+
height: auto;
40+
margin-bottom: 2px;
41+
}
42+
43+
.close {
44+
margin-left: 20px;
45+
opacity: 1;
46+
color: #424B52;
47+
svg {
48+
width: 15px;
49+
height: auto;
50+
margin-bottom: 13px;
51+
}
52+
&:focus {
53+
outline: 0;
54+
}
55+
}
56+
}
57+
58+
&.disappearing {
59+
animation: out 0.5s ease 0s forwards 1;
60+
}
61+
}
62+
63+
@keyframes out {
64+
from {
65+
opacity: 1;
66+
}
67+
68+
to {
69+
opacity: 0;
70+
}
71+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<p>
2+
{{s-icon name=alertIcon cssClasses='alert-icon'}}
3+
{{yield}}
4+
{{#if dismissable}}
5+
<button type="button" class="close" {{action "dismissAlert"}}>
6+
{{s-icon name='x-circle'}}
7+
</button>
8+
{{/if}}
9+
</p>

app/components/s-alert.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from 'space-ui/components/s-alert';

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "space-ui",
3-
"version": "0.0.15",
3+
"version": "0.0.16",
44
"description": "Space UI components for Ember projects.",
55
"keywords": [
66
"ember-addon",

tests/dummy/app/router.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Router.map(function () {
3333
this.route('collapse');
3434
this.route('checkbox');
3535
this.route('timeline');
36+
this.route('alerts');
3637

3738

3839
/* Your docs routes go here */

tests/dummy/app/templates/docs.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{{nav.item "Input" "docs.input"}}
1515
{{nav.item "Radio" "docs.radio"}}
1616
{{nav.item "Checkbox" "docs.checkbox"}}
17+
{{nav.item "Alerts" "docs.alerts"}}
1718
{{nav.item "Tag" "docs.tag"}}
1819
{{nav.item "Icon" "docs.icon"}}
1920
{{nav.item "Loader" "docs.loader"}}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Alerts
2+
3+
<p>Short messages to provide contextual feedback.</p>
4+
5+
{{#docs-demo as |demo|}}
6+
{{#demo.example name='demo-alerts.hbs'}}
7+
8+
9+
{{#s-alert
10+
dismissable=true type='info'}}
11+
This is a simple info alert.
12+
{{/s-alert}}
13+
14+
{{/demo.example}}
15+
16+
{{demo.snippet 'demo-alerts.hbs'}}
17+
{{/docs-demo}}
18+
19+
20+
21+
22+
23+
24+
25+
| Property | Description | Type | Default |
26+
| ---------- | ---------------------------------------------------------------------------- | ------- | ------- |
27+
| dismissable | Specifies whether the alert can be dismissed. | boolean | false |
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
3+
import { render } from '@ember/test-helpers';
4+
import hbs from 'htmlbars-inline-precompile';
5+
6+
module('Integration | Component | s-alert', function(hooks) {
7+
setupRenderingTest(hooks);
8+
9+
test('it renders', async function(assert) {
10+
// Set any properties with this.set('myProperty', 'value');
11+
// Handle any actions with this.set('myAction', function(val) { ... });
12+
13+
await render(hbs`{{s-alert}}`);
14+
15+
assert.equal(this.element.textContent.trim(), '');
16+
17+
// Template block usage:
18+
await render(hbs`
19+
{{#s-alert}}
20+
template block text
21+
{{/s-alert}}
22+
`);
23+
24+
assert.equal(this.element.textContent.trim(), 'template block text');
25+
});
26+
});

0 commit comments

Comments
 (0)