Skip to content

Commit 34b3878

Browse files
authored
Add option to show a back button to Navigation and View components (#51)
1 parent 80b0d6c commit 34b3878

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

components/src/stories/Navigation.stories.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ export const Component = {
88
setup() {
99
return { args };
1010
},
11-
template: '<ui-nav v-bind="args" @click-tab="setTab"><div slot="actions"><button>Action Button (slot example)</button></div></ui-nav>',
11+
template: '<ui-nav v-bind="args" @click-tab="setTab" @go-back="goBack"><div slot="actions"><button>Action Button (slot example)</button></div></ui-nav>',
1212
methods: {
1313
setTab({ detail }) {
1414
this.args.currentTab = detail;
1515
},
16+
goBack() {
17+
alert('The back button was clicked!');
18+
},
1619
},
1720
}),
1821

@@ -24,6 +27,7 @@ export const Component = {
2427
{ value: 'first', label: 'First tab' },
2528
{ value: 'second', label: 'Second tab' },
2629
],
30+
showBackButton: false,
2731
},
2832
};
2933

@@ -43,5 +47,6 @@ export default {
4347
control: 'select',
4448
options: Component.args.tabs.map(v => v.value),
4549
},
50+
showBackButton: 'boolean',
4651
},
4752
};

components/src/stories/View.stories.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ export const Component = {
99
return { args };
1010
},
1111
template: `
12-
<ui-view v-bind="args">
12+
<ui-view v-bind="args" @go-back="goBack">
1313
<div slot="loader">Loader slot: Loading...</div>
1414
<div slot="actions"><button>Action Button (slot example)</button></div>
1515
<div slot="first"><p>First tab content</p></div>
1616
<div slot="second"><p>Second tab content</p></div>
17-
</ui-view>`,
17+
</ui-view>
18+
`,
19+
methods: {
20+
goBack() {
21+
alert('The back button was clicked!');
22+
},
23+
},
1824
}),
1925

2026
args: {
@@ -27,6 +33,7 @@ export const Component = {
2733
{ value: 'first', label: 'First tab' },
2834
{ value: 'second', label: 'Second tab' },
2935
],
36+
showBackButton: false,
3037
},
3138
};
3239

@@ -45,5 +52,6 @@ export default {
4552
control: 'object',
4653
},
4754
currentTab: 'text',
55+
showBackButton: 'boolean',
4856
},
4957
};

components/src/widgets/navigation/widget.vue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<template>
22
<div class="navigation-bar">
3+
<button
4+
v-if="showBackButton"
5+
class="navigation-bar__back-button"
6+
@click="$emit('go-back')"
7+
>
8+
<ui-icon
9+
color="#666666"
10+
icon-name="googleArrowBackBaseline"
11+
size="24"
12+
/>
13+
</button>
314
<div
415
v-if="assistiveTitle"
516
class="navigation-bar__page-title-holder"
@@ -42,9 +53,11 @@
4253

4354
<script>
4455
import tabs from '~widgets/tabs/widget.vue';
56+
import icon from '~widgets/icon/widget.vue';
4557
import registerWidget from '~core/registerWidget';
4658
4759
registerWidget('ui-tabs', tabs);
60+
registerWidget('ui-icon', icon);
4861
4962
export default {
5063
props: {
@@ -67,7 +80,14 @@ export default {
6780
type: String,
6881
default: '',
6982
},
83+
84+
showBackButton: {
85+
type: Boolean,
86+
default: false,
87+
},
7088
},
89+
90+
emits: ['go-back'],
7191
};
7292
</script>
7393

@@ -129,6 +149,25 @@ export default {
129149
align-items: center;
130150
flex: 0 0 auto;
131151
}
152+
153+
&__back-button {
154+
height: 36px;
155+
width: 36px;
156+
margin: 0 24px 0 -8px;
157+
padding: 0;
158+
display: flex;
159+
justify-content: center;
160+
align-items: center;
161+
border: 0;
162+
outline: none;
163+
border-radius: 2px;
164+
background-color: transparent;
165+
cursor: pointer;
166+
167+
&:hover {
168+
background-color: #e0e0e0;
169+
}
170+
}
132171
}
133172
134173
.page-title {

components/src/widgets/view/widget.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
class="c-view__navigation"
1313
:assistive-title="assistiveTitle"
1414
:current-tab="activeTab"
15+
:show-back-button="showBackButton ? '' : null"
1516
:title="title"
1617
.tabs="tabs"
1718
@click-tab="setCurrentTab"
19+
@go-back="$emit('go-back')"
1820
>
1921
<slot name="tabs" />
2022
<!-- eslint-disable-next-line vue/no-deprecated-slot-attribute -->
@@ -80,8 +82,15 @@ export default {
8082
type: Array,
8183
default: () => [],
8284
},
85+
86+
showBackButton: {
87+
type: Boolean,
88+
default: false,
89+
},
8390
},
8491
92+
emits: ['go-back'],
93+
8594
data: () => ({
8695
activeTab: '',
8796
}),

0 commit comments

Comments
 (0)