Skip to content

Commit 0a7f036

Browse files
authored
Merge pull request #260 from ember-learn/redesign/buttons
Add styling for link buttons
2 parents 0468dab + 11f3567 commit 0a7f036

File tree

7 files changed

+74
-66
lines changed

7 files changed

+74
-66
lines changed

addon/styles/colors.css

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
background-color: var(--color-gray-900);
3030
color: var(--color-gray-300);
3131

32+
--color-link: var(--color-brand);
33+
--color-link-hover: var(--color-brand-hc-light);
34+
3235
& h1,
3336
& h2,
3437
& h3,

addon/styles/components/es-button.css

+39-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
.es-button,
22
a.es-button,
33
a.es-button:link,
4-
a.es-button:visited {
5-
background-color: var(--color-brand);
6-
color: var(--color-white);
4+
a.es-button:visited,
5+
.es-button-secondary,
6+
a.es-button-secondary,
7+
a.es-button-secondary:link,
8+
a.es-button-secondary:visited {
9+
background-color: var(--color-button-bg);
10+
color: var(--color-button-text);
711
padding-left: var(--spacing-3);
812
padding-right: var(--spacing-3);
913
padding-top: var(--spacing-1);
@@ -12,13 +16,42 @@ a.es-button:visited {
1216
border-radius: var(--radius-lg);
1317
font-size: var(--font-size-md);
1418
line-height: var(--line-height-md);
19+
transition: background-color 0.2s, color 0.1s;
20+
box-shadow: 0 0 2px -1px var(--color-gray-800), 0 2px 9px -5px var(--color-gray-800);
1521
}
1622

17-
.es-button:active {
18-
background: var(--color-brand-hc-dark);
23+
.es-button:focus,
24+
a.es-button:focus,
25+
.es-button-secondary:focus,
26+
a.es-button-secondary:focus {
27+
box-shadow: var(--focus), 0 0 2px -1px var(--color-gray-800), 0 2px 8px -4px var(--color-gray-800);
1928
}
2029

21-
a.es-button {
30+
.es-button:hover,
31+
.es-button:active,
32+
a.es-button:hover,
33+
a.es-button:active {
34+
background: var(--color-button-bg-hover);
35+
}
36+
37+
a.es-button,
38+
a.es-button-secondary {
2239
display: inline-block;
2340
text-decoration: none;
2441
}
42+
43+
.es-button-secondary,
44+
a.es-button-secondary,
45+
a.es-button-secondary:link,
46+
a.es-button-secondary:visited {
47+
background: var(--color-button-secondary-bg);
48+
color: var(--color-button-secondary-text);
49+
}
50+
51+
.es-button-secondary:hover,
52+
.es-button-secondary:active,
53+
a.es-button-secondary:hover,
54+
a.es-button-secondary:active {
55+
background: var(--color-button-secondary-bg-hover);
56+
color: var(--color-button-secondary-text-hover);
57+
}

addon/styles/components/es-header.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
margin-left: -0.5rem;
217217
padding-right: 1rem;
218218
padding-left: 0.5rem;
219-
background-position: right center;
219+
background-position: right 1px center;
220220
}
221221

222222
.navbar-dropdown-list {

addon/styles/global.css

+18-7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@
6767

6868
--radius: 0.3125rem;
6969
--radius-lg: 0.625rem;
70+
71+
72+
--color-button-text: var(--color-white);
73+
--color-button-bg: var(--color-brand);
74+
--color-button-bg-hover: var(--color-brand-hc-dark);
75+
--color-button-secondary-text: var(--color-brand);
76+
--color-button-secondary-bg: var(--color-white);
77+
--color-button-secondary-bg-hover: var(--color-brand);
78+
--color-button-secondary-text-hover: var(--color-white);
79+
80+
--color-link: var(--color-brand-hc-dark);
81+
--color-link-hover: var(--color-brand);
82+
83+
--focus: 0 0 0px 3px rgba(25, 116, 220, 0.8);
7084
}
7185

7286
@media (min-width: 1008px) {
@@ -129,26 +143,23 @@ main {
129143
main a,
130144
main a:link,
131145
main a:visited {
132-
color: var(--color-brand-hc-dark);
146+
color: var(--color-link);
133147
text-decoration: none;
134148
background: no-repeat left bottom
135149
linear-gradient(var(--color-brand-40), var(--color-brand-40));
136150
background-size: 100% 0.1875rem;
137151
}
138152

139153
main a:focus,
140-
main a:hover {
141-
color: var(--color-brand);
142-
}
143-
154+
main a:hover,
144155
main a:active,
145156
main .active {
146-
color: var(--color-brand);
157+
color: var(--color-link-hover);
147158
}
148159

149160
*:focus {
150161
outline: none;
151-
box-shadow: 0 0 0px 3px rgba(25, 116, 220, 0.8);
162+
box-shadow: var(--focus);
152163
}
153164

154165
p {

addon/templates/components/es-button.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<button
2-
class="es-button {{if @isLight "button-light"}} {{if @isTiny "button-tiny"}} {{if @isBlock "button-block"}}"
2+
class={{if @secondary "es-button-secondary" "es-button"}}
33
aria-label={{@label}}
44
onclick={{action this.buttonClicked}}
55
...attributes

docs/components/button.md

+12-45
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,15 @@
55
Simplest use case: a button with text in it, telling the user what to do.
66

77
```handlebars
8-
{{es-button label="click me"}}
8+
<EsButton @label="click me" />
99
```
1010

11-
1211
Also supported- block use:
1312

1413
```handlebars
15-
{{#es-button}}
14+
<EsButton>
1615
click me <span>🐹</span>
17-
{{/es-button}}
18-
```
19-
20-
To toggle the 'disabled' property, set 'isDisabled' to true
21-
22-
```handlebars
23-
{{es-button label="click me" isDisabled=true}}
16+
</EsButton>
2417
```
2518

2619
To add interactivity you can pass an action to `onClicked`
@@ -33,37 +26,18 @@ To add interactivity you can pass an action to `onClicked`
3326
{{value}}
3427
```
3528

36-
## Styling Links
37-
It is also possible to style a link to look like a button using the `something` class
38-
39-
```html
40-
<a href="https://emberjs.com" class="es-button">Go to Ember homepage</a>
41-
```
42-
43-
## Styles
44-
45-
Outline button style:
29+
## Secondary Buttons
4630

4731
```handlebars
48-
{{es-button label="click me" isDark=false}}
32+
<EsButton @label="click me" @secondary={{true}} />
4933
```
5034

51-
Smaller button:
52-
53-
```handlebars
54-
{{es-button label="click me" isTiny=true}}
55-
```
56-
57-
Less Padding:
58-
59-
```handlebars
60-
{{es-button label="click me" isDark=true isDense=true}}
61-
```
62-
63-
Full-width button:
35+
## Styling Links
36+
It is also possible to style a link to look like a button using the `something` class
6437

65-
```handlebars
66-
{{es-button label="click me" isBlock=true}}
38+
```html
39+
<a href="https://emberjs.com" class="es-button">Go to Ember homepage</a>
40+
<a href="https://guides.emberjs.com" class="es-button-secondary">Go to the Guides</a>
6741
```
6842

6943
## Accessibility
@@ -73,14 +47,7 @@ Since we're using the native HTML button element and requiring a label value to
7347
If you are going to put an icon in the button, then you will need to set an aria-label property on the button:
7448

7549
```handlebars
76-
{{#es-button ariaLabel="Hamster Secrets" title="Hamster Secrets"}}
50+
<EsButton aria-label="Hamster Secrets" title="Hamster Secrets">
7751
🐹
78-
{{/es-button}}
52+
</EsButton>
7953
```
80-
81-
## Other Uses
82-
83-
There are some other ways this component could be used:
84-
85-
- as a link
86-
- as a toggle button (supports the aria-pressed attribute)

tests/integration/components/es-button-test.js

-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ module('Integration | Component | es button', function(hooks){
2828
assert.ok(document.querySelector('.es-button'), 'has base es-button class');
2929
});
3030

31-
test('can set button-block class', async function(assert) {
32-
await render(hbs`{{es-button isBlock=true}}`);
33-
34-
assert.ok(document.querySelector('.button-block'), 'has button-block class');
35-
});
36-
3731
test('can display set label', async function(assert) {
3832
const label = 'Button Label';
3933

0 commit comments

Comments
 (0)