Skip to content

Commit 4a27f8a

Browse files
committed
update es-note
1 parent bbb659f commit 4a27f8a

File tree

8 files changed

+65
-49
lines changed

8 files changed

+65
-49
lines changed

addon/components/es-note.js

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,26 @@
1-
import Component from '@ember/component';
2-
import { get } from '@ember/object';
3-
import layout from '../templates/components/es-note';
4-
import {
5-
DefaultMessage as defaultMessage,
6-
Mascots as mascots,
7-
} from '../constants/mascots';
1+
import Component from '@glimmer/component';
82

9-
export default Component.extend({
10-
layout,
3+
const Mascots = {
4+
tomster: { image: '/images/mascots/tomster.png', name: 'Tomster' },
5+
zoey: { image: '/images/mascots/zoey.png', name: 'Zoey' },
6+
}
117

12-
classNames: ['cta'],
8+
function randomMascot() {
9+
let mascotKeys = Object.keys(Mascots);
1310

14-
imageUrl: null,
15-
mascots,
16-
nameTitle: null,
17-
defaultMessage,
11+
let randomIndex = Math.floor(Math.random() * Math.floor(mascotKeys.length));
1812

19-
init() {
20-
this._super(...arguments);
13+
return Mascots[mascotKeys[randomIndex]];
14+
}
2115

22-
this._randomMascot();
23-
},
16+
export default class EsNoteComponent extends Component {
17+
constructor() {
18+
super(...arguments);
2419

25-
_randomMascot() {
26-
const random = Math.random();
27-
const mascots = get(this, 'mascots');
28-
let randomIndex, mascot = mascots[0];
29-
30-
if (mascots.length > 1) {
31-
randomIndex = Math.floor(random * Math.floor(2));
32-
mascot = mascots[randomIndex];
20+
if (this.args.mascot) {
21+
this.mascot = Mascots[this.args.mascot];
22+
} else {
23+
this.mascot = randomMascot();
3324
}
34-
35-
this.setProperties({
36-
imageUrl: get(mascot, 'image'),
37-
nameTitle: `${get(mascot, 'name')} says...`,
38-
});
39-
},
40-
});
25+
}
26+
}

addon/constants/mascots.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

addon/styles/addon.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
@import 'components/es-card.css';
2323
@import 'components/es-footer.css';
2424
@import 'components/es-header.css';
25+
@import 'components/es-note.css';

addon/styles/components/es-note.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.cta-note {
2+
background-color: var(--color-gray-200);
3+
margin: auto;
4+
max-width: 90%;
5+
}
6+
7+
.cta-note .cta-note-content {
8+
display: flex;
9+
justify-content: space-between;
10+
}
11+
12+
.cta-note .cta-mascot {
13+
transform: rotate(15deg);
14+
}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
<div class="cta-note">
2-
<div class="cta-note-body">
3-
<div class="cta-note-heading hide-in-percy">{{this.nameTitle}}</div>
4-
<div class="cta-note-message">
5-
{{#if hasBlock}}
1+
<div class="cta-note" ...attributes>
2+
<div class="cta-note-content">
3+
<div class="cta-note-body p-2">
4+
<div class="text-lg mb-1 hide-in-percy">{{this.mascot.name}} says...</div>
5+
<div class="cta-note-message">
66
{{yield}}
7-
{{else}}
8-
{{this.defaultMessage}}
9-
{{/if}}
7+
</div>
108
</div>
9+
<img src={{this.mascot.image}} role="presentation" alt="" class="hide-in-percy cta-mascot m-2">
1110
</div>
12-
<img src={{this.imageUrl}} role="presentation" alt="" class="hide-in-percy">
1311
</div>

app/templates/components/es-note.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from 'ember-styleguide/templates/components/es-note';

docs/components/note.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Note
2+
3+
Sometimes in our documentation we might want to bring someone's attention to something, either as a warning or a quick suggestion. We have a qwirky component that can be used for exactly this
4+
5+
## Usage
6+
7+
```handlebars
8+
<EsNote>You should try out this cool note component</EsNote>
9+
```
10+
11+
If you don't pass in a specific mascot (either `tomster` or `zoey`) then it will randomly pick between them. Try refreshing the page now and see them change!
12+
13+
You might notice on this page that they flicker a little bit and seem to swap between a Tomster and a Zoey sometimes just after rendering. This is related to how we are pre-rendering this page and then when the page is loaded Ember will re-run the code that picks the mascot that is displayed.
14+
15+
In **all** cases where we are pre-rendering a page using fastboot or prember, we **must** pass in the `@mascot` argument to the component.
16+
17+
```handlebars
18+
<EsNote @mascot="tomster">I am a Tomster, and I approve this message</EsNote>
19+
```
20+
21+
```handlebars
22+
<EsNote @mascot="zoey">I am a Zoey, and I approve this message</EsNote>
23+
```

public/images/mascots/zoey.png

3.92 KB
Loading

0 commit comments

Comments
 (0)