-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(card): new helper sub-components (#2375)
- Loading branch information
1 parent
96e5e81
commit ff25314
Showing
8 changed files
with
281 additions
and
147 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { mergeData } from 'vue-functional-data-merge' | ||
import stripScripts from '../../utils/strip-scripts' | ||
|
||
export const props = { | ||
subTitle: { | ||
type: String, | ||
default: null | ||
}, | ||
subTitleTag: { | ||
type: String, | ||
default: 'h6' | ||
}, | ||
subTitleTextVariant: { | ||
type: String, | ||
default: 'muted' | ||
} | ||
} | ||
|
||
// @vue/component | ||
export default { | ||
name: 'BCardSubTitle', | ||
functional: true, | ||
props, | ||
render (h, { props, data, children }) { | ||
const domProps = children ? {} : { innerHTML: stripScripts(props.subTitle) } | ||
return h( | ||
props.subTitleTag, | ||
mergeData(data, { | ||
staticClass: 'card-subtitle', | ||
class: [ | ||
props.subTitleTextVariant ? `text-${props.subTitleTextVariant}` : null | ||
], | ||
domProps | ||
}), | ||
children | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { mergeData } from 'vue-functional-data-merge' | ||
|
||
export const props = { | ||
textTag: { | ||
type: String, | ||
default: 'p' | ||
} | ||
} | ||
|
||
// @vue/component | ||
export default { | ||
name: 'BCardText', | ||
functional: true, | ||
props, | ||
render (h, { props, data, children }) { | ||
return h( | ||
props.textTag, | ||
mergeData(data, { staticClass: 'card-text' }), | ||
children | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import CardText from './card-text' | ||
import { mount } from '@vue/test-utils' | ||
|
||
describe('card-text', async () => { | ||
it('has root element "p"', async () => { | ||
const wrapper = mount(CardText) | ||
expect(wrapper.is('p')).toBe(true) | ||
}) | ||
|
||
it('has class card-text', async () => { | ||
const wrapper = mount(CardText) | ||
expect(wrapper.classes()).toContain('card-text') | ||
}) | ||
|
||
it('has custom root element "div" when prop text-tag=div', async () => { | ||
const wrapper = mount(CardText, { | ||
context: { | ||
props: { | ||
textTag: 'div' | ||
} | ||
} | ||
}) | ||
expect(wrapper.is('div')).toBe(true) | ||
expect(wrapper.classes()).toContain('card-text') | ||
}) | ||
|
||
it('accepts custom classes', async () => { | ||
const wrapper = mount(CardText, { | ||
context: { | ||
class: ['foobar'] | ||
} | ||
}) | ||
expect(wrapper.classes()).toContain('card-text') | ||
expect(wrapper.classes()).toContain('foobar') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { mergeData } from 'vue-functional-data-merge' | ||
import stripScripts from '../../utils/strip-scripts' | ||
|
||
export const props = { | ||
title: { | ||
type: String, | ||
default: null | ||
}, | ||
titleTag: { | ||
type: String, | ||
default: 'h4' | ||
} | ||
} | ||
|
||
// @vue/component | ||
export default { | ||
name: 'BCardTitle', | ||
functional: true, | ||
props, | ||
render (h, { props, data, children }) { | ||
const domProps = children ? {} : { innerHTML: stripScripts(props.title) } | ||
return h( | ||
props.titleTag, | ||
mergeData(data, { | ||
staticClass: 'card-title', | ||
domProps | ||
}), | ||
children | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
{ | ||
"name": "@bootstrap-vue/card", | ||
"version": "1.0.0", | ||
"meta": { | ||
"title": "Card", | ||
"component": "BCard", | ||
"components": [ | ||
"BCardHeader", | ||
"BCardFooter", | ||
"BCardBody", | ||
"BCardImg", | ||
"BCardGroup" | ||
], | ||
"slots": [ | ||
{ | ||
"name": "header", | ||
"description": "For custom rendering of header content" | ||
}, | ||
{ | ||
"name": "footer", | ||
"description": "For custom rendering of footer content" | ||
} | ||
] | ||
} | ||
"name": "@bootstrap-vue/card", | ||
"version": "1.0.0", | ||
"meta": { | ||
"title": "Card", | ||
"component": "BCard", | ||
"components": [ | ||
"BCardHeader", | ||
"BCardFooter", | ||
"BCardBody", | ||
"BCardTitle", | ||
"BCardSubTitle", | ||
"BCardImg", | ||
"BCardText", | ||
"BCardGroup" | ||
], | ||
"slots": [ | ||
{ | ||
"name": "header", | ||
"description": "For custom rendering of header content" | ||
}, | ||
{ | ||
"name": "footer", | ||
"description": "For custom rendering of footer content" | ||
} | ||
] | ||
} | ||
} |