Skip to content

Commit a3de754

Browse files
committed
feat: CListGroup and CListGroupItem components
1 parent a5f5e36 commit a3de754

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { mergeData } from 'vue-functional-data-merge'
2+
3+
export default {
4+
functional: true,
5+
name: 'CListGroup',
6+
props: {
7+
tag: {
8+
type: String,
9+
default: 'div'
10+
},
11+
flush: Boolean,
12+
},
13+
render (h, { props, data, children }) {
14+
const componentData = {
15+
staticClass: 'list-group',
16+
class: { 'list-group-flush': props.flush }
17+
}
18+
return h(props.tag, mergeData(data, componentData), children)
19+
}
20+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { mergeData } from 'vue-functional-data-merge'
2+
import pluckProps from '../../utils/pluck-props'
3+
import { assign } from '../../utils/object'
4+
import CLink, { propsFactory as linkPropsFactory } from '../Link/CLink'
5+
let linkProps = linkPropsFactory()
6+
7+
const props = assign(
8+
{
9+
tag: {
10+
type: String,
11+
default: 'div'
12+
},
13+
action: Boolean,
14+
variant: String,
15+
},
16+
linkProps
17+
)
18+
19+
export default {
20+
functional: true,
21+
name: 'CListGroupItem',
22+
props,
23+
render (h, { props, data, children }) {
24+
const tag = !props.href && !props.to ? props.tag : CLink
25+
const isAction = Boolean(
26+
props.action ||
27+
props.href ||
28+
props.to ||
29+
props.tag == 'button'
30+
)
31+
const attrs = {}
32+
let itemProps = {}
33+
if (tag === 'button') {
34+
if (!data.attrs || !data.attrs.type)
35+
attrs.type = 'button'
36+
if (props.disabled)
37+
attrs.disabled = true
38+
} else {
39+
itemProps = pluckProps(linkProps, props)
40+
}
41+
const componentData = {
42+
attrs,
43+
props: itemProps,
44+
staticClass: 'list-group-item',
45+
class: {
46+
[`list-group-item-${props.variant}`]: Boolean(props.variant),
47+
'list-group-item-action': isAction,
48+
active: props.active,
49+
disabled: props.disabled
50+
}
51+
}
52+
return h(tag, mergeData(data, componentData), children)
53+
}
54+
}

src/components/ListGroup/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import CListGroup from './CListGroup'
2+
import CListGroupItem from './CListGroupItem'
3+
4+
export {
5+
CListGroup,
6+
CListGroupItem
7+
}

src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './Alert'
1515
export * from './Button'
1616
export * from './Card'
1717
export * from './Dropdown'
18+
export * from './ListGroup'

0 commit comments

Comments
 (0)