-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathButtonNormal.vue
221 lines (189 loc) · 4.48 KB
/
ButtonNormal.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<template lang="pug">
//TODO: popup w/ errors
//TODO: https://stackoverflow.com/questions/31402576/enable-focus-only-on-keyboard-use-or-tab-press
//TODO: Rename this component
.button
component.btn(
:is="href ? (externalHref ? 'a' : 'nuxt-link') : 'button'"
:to="href && !externalHref ? href : false"
:href="externalHref ? href : false"
:target="externalHref && !inPlace ? '_blank' : false"
v-bind="{ type, role }"
:class="{[`btn--${variant}`]: true, small, smaller}"
:disabled="disabled || !v.validated"
v-tooltip="validationErrors"
@click="!href ? $emit('click') : ''"
no-default
)
slot
</template>
<script>
export default {
props: {
type: {
type: String,
default: 'button',
},
variant: {
type: String,
default: 'outline',
// validator: (v) => ["primary", "outline", "secondary"].includes(v)
},
validation: {
type: Object,
default: null,
},
disabled: {
type: Boolean,
default: false,
},
small: {
type: Boolean,
default: false,
},
smaller: {
type: Boolean,
default: false,
},
href: {
type: String,
default: null,
},
role: {
type: String,
default: null,
},
inPlace: {
// Open external links in-place
type: Boolean,
default: false,
},
},
computed: {
v() {
if (this.validation === null) return { validated: true, errors: {} }
return this.validation
},
validationErrors() {
if (this.v.validated) return false
return (
'<ul class="default-styles" style="padding-left:1em;text-align:left">' +
Object.values(this.v.errors)
.filter(v => v.length)
.map(v => '<li>' + v[0] + '</li>')
.join('') +
'</ul>'
)
},
externalHref() {
return this.href && /^https?:\/\//.test(this.href)
},
},
}
</script>
<style lang="stylus" scoped>
.button
display inline-block
.btn
display flex
margin 0 5px
padding 15px 20px
font-size 1.05em
transition all 0.125s ease
-webkit-appearance none
appearance none
&.small, &.smaller
display inline-flex
margin 0 1.5em
font-size 0.9em
&.small
padding 0.75em 1em
&.smaller
padding 0.5em 0.8em
justify-content center
align-items center
border-radius var(--border-radius)
text-align center
&[disabled]
cursor not-allowed
& /deep/ i
margin-right 0.2em
font-size 1.3em
.btn--outline
border 2px solid var(--grey)
color var(--blue)
&[role=danger]
color var(--red)
&:hover, &:focus
border-color var(--blue)
background-color transparent
&[role=danger]
border-color var(--red)
background-color transparent
&:active
border-color var(--blue-offset)
background-color var(--blue-offset)
color var(--blue-dark)
&[role=danger]
border-color var(--red)
background-color var(--red)
color white
&[disabled]
border-color var(--grey)
background transparent
color var(--grey)
.btn--primary
border 2px solid var(--blue)
background-color var(--blue)
color white
&[role=danger]
border 2px solid var(--red)
background-color var(--red)
&:hover, &:focus
border 2px solid var(--blue-dark)
background-color var(--blue-dark)
&[role=danger]
border 2px solid var(--red-dark)
background-color var(--red-dark)
&:active
color rgba(255, 255, 255, 0.25)
&[disabled]
border 2px solid var(--grey-offset)
background var(--grey-offset)
color var(--grey-dark)
.btn--secondary
border 2px solid var(--blue-offset)
background-color var(--blue-offset)
color var(--blue)
&:hover, &:focus
border 2px solid var(--blue)
background-color var(--blue)
color white
&:active
border 2px solid var(--blue-dark)
background-color var(--blue-dark)
.btn--text
border 2px solid transparent
background-color transparent
color black
&:hover, &:focus
border 2px solid var(--grey-light)
.btn--flat
margin 0
padding 10px 0
color var(--blue)
text-transform uppercase
letter-spacing 0.125em
font-weight bold
&:hover, &:focus
color var(--blue-dark)
& /deep/ i
margin-bottom 0.15em //vertical centering
.btn--text-blue
padding 0
background-color transparent
color var(--blue)
font-size 1.2em
&:hover, &:focus
color var(--blue-dark)
</style>