Skip to content

Commit 57a47ba

Browse files
committed
refactor: CToast and CToaster components refactor:
- delete style attribute, - disable fixed toasts without toaster, - add new styles, - delete reverse prop
1 parent 9025520 commit 57a47ba

File tree

7 files changed

+37
-91
lines changed

7 files changed

+37
-91
lines changed

src/components/toast/CToast.vue

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
role="alert"
77
aria-live="assertive"
88
aria-atomic="true"
9-
:style="computedStyles"
109
>
1110
<div
1211
v-if="header !== undefined || $slots.header"
@@ -29,16 +28,16 @@
2928
</template>
3029

3130
<script>
32-
import toastMixin from './toast-mixin'
31+
import { props } from './toast-props'
3332
import CButtonClose from '../button/CButtonClose'
3433
3534
export default {
3635
name: 'CToast',
37-
mixins: [ toastMixin ],
3836
components: {
3937
CButtonClose
4038
},
4139
props: {
40+
...props,
4241
show: Boolean,
4342
header: String
4443
},
@@ -69,8 +68,7 @@ export default {
6968
return [
7069
'toast',
7170
{
72-
'show': this.isShowed || this.hidding,
73-
'toast-full': this.props.position.includes('full'),
71+
'show': this.isShowed,
7472
}
7573
]
7674
},
@@ -81,7 +79,7 @@ export default {
8179
return this.toaster && this.toaster.props ? this.toaster.props : {}
8280
},
8381
props () {
84-
return Object.keys(toastMixin.props).reduce((computedProps, key) => {
82+
return Object.keys(props).reduce((computedProps, key) => {
8583
const propIsDirectlyDeclared = this.directlyDeclaredProps.includes(key)
8684
const parentPropExists = this.injectedProps[key] !== undefined
8785
const propIsInherited = parentPropExists && !propIsDirectlyDeclared

src/components/toast/CToaster.vue

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<template>
2-
<div
3-
:class="toasterClasses"
4-
:style="computedStyles"
5-
>
2+
<div :class="toasterClasses">
63
<slot></slot>
74
</div>
85
</template>
96

107
<script>
11-
import toastMixin from './toast-mixin'
8+
import { props } from './toast-props'
129
1310
export default {
1411
name: 'CToaster',
@@ -19,18 +16,25 @@ export default {
1916
})
2017
return { toaster }
2118
},
22-
mixins: [ toastMixin ],
2319
props: {
24-
reverse: {
25-
type: Boolean,
26-
default: true
20+
...props,
21+
position: {
22+
type: String,
23+
default: 'top-right',
24+
validator: position => {
25+
return [
26+
'', 'static', 'top-right', 'top-left', 'top-center', 'top-full',
27+
'bottom-right', 'bottom-left', 'bottom-center', 'bottom-full'
28+
].includes(position)
29+
}
2730
}
2831
},
2932
computed: {
3033
toasterClasses () {
34+
const hasFixedPosition = this.position && this.position !== 'static'
3135
return [
3236
'toaster',
33-
{ 'toaster-reverse': !this.reverse }
37+
{ [`toaster-${this.position}`]: hasFixedPosition }
3438
]
3539
}
3640
}

src/components/toast/tests/CToast.spec.js

-11
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,4 @@ describe(ComponentName, () => {
6464
// done()
6565
// }, 25)
6666
// })
67-
it('properly changes position', () => {
68-
const stylesIncludes = (string) => {
69-
return JSON.stringify(customWrapper.vm.computedStyles).includes(string)
70-
}
71-
72-
customWrapper.setProps({ position: 'top-left'})
73-
expect(stylesIncludes('"top":0')).toBe(true)
74-
75-
customWrapper.setProps({ position: 'top-full'})
76-
expect(stylesIncludes('"right":0,"left":0')).toBe(true)
77-
})
7867
})

src/components/toast/tests/__snapshots__/CToast.spec.js.snap

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`CToast renders correctly 1`] = `
66
aria-atomic="true"
77
aria-live="assertive"
88
class="toast show"
9+
position="static"
910
role="alert"
1011
style=""
1112
>
@@ -24,8 +25,9 @@ exports[`CToast renders correctly custom wrapper 1`] = `
2425
aria-live="assertive"
2526
class="toast show"
2627
name="fade"
28+
position="bottom-center"
2729
role="alert"
28-
style="z-index: 1100; min-width: 350px; position: fixed; bottom: 0px; left: 50%; transform: translateX(-50%);"
30+
style=""
2931
>
3032
<div
3133
class="toast-header"

src/components/toast/tests/__snapshots__/CToaster.spec.js.snap

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
exports[`CToaster renders correctly 1`] = `
44
<div
5-
class="toaster"
6-
style="z-index: 1100; min-width: 350px; position: fixed; top: 0px; right: 0px;"
5+
class="toaster toaster-top-right"
76
/>
87
`;
98

109
exports[`CToaster renders correctly custom wrapper 1`] = `
1110
<div
12-
class="toaster"
13-
style="z-index: 1100; min-width: 350px; position: fixed; top: 0px; left: 0px;"
11+
class="toaster toaster-top-left"
1412
>
1513
<div
1614
appear=""

src/components/toast/toast-mixin.js

-59
This file was deleted.

src/components/toast/toast-props.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const props = {
2+
autohide: {
3+
type: [Number, Boolean],
4+
validator: val => typeof val === 'number' || val === false
5+
},
6+
closeButton: {
7+
type: Boolean,
8+
default: true
9+
},
10+
fade: {
11+
type: Boolean,
12+
default: true
13+
}
14+
}

0 commit comments

Comments
 (0)