Skip to content

Commit 0b25803

Browse files
committed
refactor: delete html props from small components
- Remove textHtml prop from CBadge, CLink and CButton, - refactor CSidebarNavLink, CBreadcrumb and CBreadcrumbRouter, - update tests and typings
1 parent 359d744 commit 0b25803

File tree

16 files changed

+56
-46
lines changed

16 files changed

+56
-46
lines changed

src/components/Badge/CBadge.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const props = Object.assign(linkProps, {
88
default: 'span'
99
},
1010
color: String,
11-
pill: Boolean,
12-
textHtml: String
11+
pill: Boolean
1312
})
1413
1514
export default {
@@ -18,7 +17,6 @@ export default {
1817
props,
1918
render (h, { props, data, children }) {
2019
const tag = !props.href && !props.to ? props.tag : CLink
21-
const domProps = props.textHtml ? { innerHTML: props.textHtml } : null
2220
const componentData = {
2321
staticClass: 'badge',
2422
class: {
@@ -27,7 +25,6 @@ export default {
2725
'active': props.active,
2826
'disabled': props.disabled
2927
},
30-
domProps,
3128
props
3229
}
3330
return h(tag, mergeData(data, componentData), children)

src/components/Badge/tests/CBadge.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ const ComponentName = 'CBadge'
55
const wrapper = mount(Component)
66
const customWrapper = mount(Component, {
77
propsData: {
8-
textHtml: 'Badge text',
98
color: 'success',
109
active: true,
1110
pill: true,
1211
disabled: true,
1312
href: 'someLink'
13+
},
14+
slots: {
15+
default: 'Badge text'
1416
}
1517
})
1618

@@ -21,7 +23,7 @@ describe(`${ComponentName} .vue`, () => {
2123
it('renders correctly', () => {
2224
expect(wrapper.element).toMatchSnapshot()
2325
})
24-
it('renders correctly from textHtml prop', () => {
26+
it('renders correctly with slot', () => {
2527
expect(customWrapper.element).toMatchSnapshot()
2628
})
2729
});

src/components/Badge/tests/__snapshots__/CBadge.spec.js.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,17 @@ exports[`CBadge .vue renders correctly from textHtml prop 1`] = `
1717
Badge text
1818
</a>
1919
`;
20+
21+
exports[`CBadge .vue renders correctly with slot 1`] = `
22+
<a
23+
aria-disabled="true"
24+
class="badge disabled active badge-success badge-pill active disabled"
25+
href="someLink"
26+
tabindex="-1"
27+
target="_self"
28+
>
29+
<template>
30+
Badge text
31+
</template>
32+
</a>
33+
`;

src/components/Breadcrumb/CBreadcrumb.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
:class="[item.addClasses, sharedClasses, addLinkClasses]"
77
role="presentation"
88
>
9-
<component
10-
:is="'CLink'"
11-
v-bind="Object.assign({}, item, { addClasses: null })"
12-
/>
9+
<CLink v-bind="Object.assign({}, item, { addClasses: null, text: null })">
10+
{{item.text}}
11+
</CLink>
1312
</li>
1413
<li
1514
:class="['active', lastItem.addClasses, sharedClasses, addLastItemClasses]"
1615
role="presentation"
1716
>
1817
<!-- span added to enable text styling through classes -->
19-
<span v-text="lastItem.textHtml"></span>
18+
<span v-text="lastItem.text"></span>
2019
</li>
2120
<slot></slot>
2221
</ol>

src/components/Breadcrumb/CBreadcrumbRouter.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626
const meta = route.meta || {}
2727
return {
2828
to: route,
29-
textHtml: meta.label || route.name
29+
text: meta.label || route.name
3030
}
3131
})
3232
},

src/components/Breadcrumb/tests/__snapshots__/CBreadcrumb.spec.js.snap

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ exports[`CBreadcrumb renders correctly 1`] = `
1212
class=""
1313
href="#"
1414
target="_self"
15-
text="Admin"
16-
/>
15+
>
16+
17+
Admin
18+
19+
</a>
1720
</li>
1821
<li
1922
class="additional-class breadcrumb-item additional-link-class"
@@ -23,15 +26,20 @@ exports[`CBreadcrumb renders correctly 1`] = `
2326
class=""
2427
href="#"
2528
target="_self"
26-
text="Manage"
27-
/>
29+
>
30+
31+
Manage
32+
33+
</a>
2834
</li>
2935
3036
<li
3137
class="active additional-class breadcrumb-item additional-last-item-class"
3238
role="presentation"
3339
>
34-
<span />
40+
<span>
41+
Library
42+
</span>
3543
</li>
3644
3745
</ol>

src/components/Breadcrumb/tests/__snapshots__/CBreadcrumbRouter.spec.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ exports[`CBreadcrumbRouter renders correctly 1`] = `
1313
href="#"
1414
target="_self"
1515
>
16+
1617
Home
18+
1719
</a>
1820
</li>
1921
<li
@@ -25,7 +27,9 @@ exports[`CBreadcrumbRouter renders correctly 1`] = `
2527
href="#"
2628
target="_self"
2729
>
30+
2831
Menu
32+
2933
</a>
3034
</li>
3135

src/components/Button/CButton.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ const btnProps = {
2121
pressed: {
2222
type: Boolean,
2323
default: null
24-
},
25-
textHtml: String
24+
}
2625
}
2726
export const props = Object.assign(linkPropsFactory(), btnProps)
2827
@@ -81,13 +80,11 @@ export default {
8180
}
8281
}
8382
}
84-
const domProps = children ? '' : { innerHTML: props.textHtml }
8583
const componentData = {
8684
staticClass: 'btn',
8785
class: computeClasses(props),
8886
props: computePassedProps(props),
8987
attrs: computeAttrs(props, data, isButton, toggle),
90-
domProps,
9188
on
9289
}
9390
return h(

src/components/Link/CLink.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { mergeData } from 'vue-functional-data-merge'
44
export function propsFactory () {
55
return {
66
href: String,
7-
textHtml: String,
87
rel: String,
98
target: {
109
type: String,
@@ -80,8 +79,6 @@ export default {
8079
8180
const tabindex = data.attrs ? data.attrs.tabindex : null
8281
83-
const domProps = props.textHtml ? { innerHTML: props.textHtml } : null
84-
8582
const componentData = mergeData(data, {
8683
class: {
8784
'disabled': props.disabled,
@@ -94,7 +91,6 @@ export default {
9491
tabindex: props.disabled ? '-1' : tabindex,
9592
'aria-disabled': tag === 'a' && props.disabled ? 'true' : null
9693
},
97-
domProps,
9894
props: Object.assign(props, { tag: props.routerTag })
9995
})
10096

src/components/Link/tests/CLink.spec.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ const App = localVue.extend({
2222
h('CLink', { props: { to: '/a' }, nativeOn: { click } }, ['to-path-a']),
2323
// regular link
2424
h('CLink', { props: { href: '/a' }, on: { click } }, ['href-a']),
25-
// regular link with textHtml prop
26-
h('CLink', { props: { href: '/a', textHtml: 'href-a' } }),
2725
// disabled link
2826
h('CLink', { props: { disabled: true, href: '/a' }, on: { click } }, ['href-a'])
2927
])
@@ -46,7 +44,6 @@ describe(`${ComponentName} .vue`, () => {
4644
const links = customWrapper.findAll('a')
4745

4846
links.at(2).trigger('click')
49-
links.at(3).trigger('click')
5047
expect(triggerLink).not.toBeCalled()
5148

5249
links.at(0).trigger('click')

src/components/Link/tests/__snapshots__/CLink.spec.js.snap

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ exports[`CLink .vue renders correctly 2`] = `
2424
>
2525
href-a
2626
</a>
27-
<a
28-
class=""
29-
href="/a"
30-
target="_self"
31-
>
32-
href-a
33-
</a>
3427
<a
3528
aria-disabled="true"
3629
class="disabled"

src/components/Sidebar/CSidebarNavLink.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
{{name}}
1111
<CBadge
1212
v-if="badge"
13-
v-bind="badge"
14-
/>
13+
v-bind="Object.assign({}, badge, { text: null })"
14+
>
15+
{{badge.text}}
16+
</CBadge>
1517
</slot>
1618
</CLink>
1719
</li>

src/components/Sidebar/tests/CSidebarNavLink.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const wrapper = mount(Component, {
99
icon: 'cui-settings',
1010
badge: {
1111
color: 'success',
12-
textHtml: 'NEW'
12+
text: 'NEW'
1313
}
1414
},
1515
attrs: {
@@ -25,7 +25,7 @@ const wrapperLabel = mount(Component, {
2525
icon: 'cui-settings',
2626
badge: {
2727
color: 'success',
28-
textHtml: 'NEW'
28+
text: 'NEW'
2929
}
3030
},
3131
attrs: {

src/components/Sidebar/tests/__snapshots__/CSidebarNavLink.spec.js.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ exports[`CSidebarNavLink.vue renders correctly 1`] = `
1919
<span
2020
class="badge badge-success"
2121
>
22-
NEW
22+
23+
NEW
24+
2325
</span>
2426
</a>
2527
</li>
@@ -44,7 +46,9 @@ exports[`CSidebarNavLink.vue renders correctly in label mode 1`] = `
4446
<span
4547
class="badge badge-success"
4648
>
47-
NEW
49+
50+
NEW
51+
4852
</span>
4953
</a>
5054
</li>

src/components/Toggler/tests/__snapshots__/CToggler.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ exports[`CToggler .vue renders correctly 1`] = `
1212

1313
exports[`CToggler .vue renders correctly inHeader 1`] = `
1414
<div
15-
class="header-toggler"
15+
class="c-header-toggler"
1616
>
1717
<span
18-
class="header-toggler-icon"
18+
class="c-header-toggler-icon"
1919
/>
2020
</div>
2121
`;

src/components/index.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export declare class CBadge extends CLink {
1010
tag: string
1111
color: string
1212
pill: boolean
13-
textHtml: string
1413
}
1514

1615
export declare class CBreadcrumb extends Vue {
@@ -36,7 +35,6 @@ export declare class CButton extends CLink {
3635
color: string
3736
type: string
3837
pressed: boolean
39-
textHtml: string
4038
}
4139

4240
export declare class CButtonClose extends Vue {
@@ -337,7 +335,6 @@ export declare class CJumbotron extends Vue {
337335

338336
export declare class CLink extends Vue {
339337
href: string
340-
textHtml: string
341338
rel: string
342339
target: string
343340
disabled: boolean

0 commit comments

Comments
 (0)