forked from coreui/coreui-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDataTable.stories.js
147 lines (136 loc) · 6.36 KB
/
CDataTable.stories.js
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
import React from 'react';
import CDataTable from '../src/table/CDataTable'
import CBadge from '../src/badge/CBadge'
import CCard from '../src/card/CCard'
import CCardBody from '../src/card/CCardBody'
import CCol from '../src/grid/CCol'
import { boolean, number, text } from '@storybook/addon-knobs';
export default {
title: 'CDataTable'
};
const fields = ['name','registered', 'role', 'status']
const usersData = [
{id: 0, name: 'John Doe', registered: '2018/01/01', role: 'Guest', status: 'Pending'},
{id: 1, name: 'Samppa Nori', registered: '2018/01/01', role: 'Member', status: 'Active'},
{id: 2, name: 'Estavan Lykos', registered: '2018/02/01', role: 'Staff', status: 'Banned'},
{id: 3, name: 'Chetan Mohamed', registered: '2018/02/01', role: 'Admin', status: 'Inactive'},
{id: 4, name: 'Derick Maximinus', registered: '2018/03/01', role: 'Member', status: 'Pending'},
{id: 5, name: 'Friderik Dávid', registered: '2018/01/21', role: 'Staff', status: 'Active'},
{id: 6, name: 'Yiorgos Avraamu', registered: '2018/01/01', role: 'Member', status: 'Active'},
{id: 7, name: 'Avram Tarasios', registered: '2018/02/01', role: 'Staff', status: 'Banned'},
{id: 8, name: 'Quintin Ed', registered: '2018/02/01', role: 'Admin', status: 'Inactive'},
{id: 9, name: 'Enéas Kwadwo', registered: '2018/03/01', role: 'Member', status: 'Pending'},
{id: 10, name: 'Agapetus Tadeáš', registered: '2018/01/21', role: 'Staff', status: 'Active'},
{id: 11, name: 'Carwyn Fachtna', registered: '2018/01/01', role: 'Member', status: 'Active'},
{id: 12, name: 'Nehemiah Tatius', registered: '2018/02/01', role: 'Staff', status: 'Banned'},
{id: 13, name: 'Ebbe Gemariah', registered: '2018/02/01', role: 'Admin', status: 'Inactive'},
{id: 14, name: 'Eustorgios Amulius', registered: '2018/03/01', role: 'Member', status: 'Pending'},
{id: 15, name: 'Leopold Gáspár', registered: '2018/01/21', role: 'Staff', status: 'Active'},
{id: 16, name: 'Pompeius René', registered: '2018/01/01', role: 'Member', status: 'Active'},
{id: 17, name: 'Paĉjo Jadon', registered: '2018/02/01', role: 'Staff', status: 'Banned'},
{id: 18, name: 'Micheal Mercurius', registered: '2018/02/01', role: 'Admin', status: 'Inactive'},
{id: 19, name: 'Ganesha Dubhghall', registered: '2018/03/01', role: 'Member', status: 'Pending'},
{id: 20, name: 'Hiroto Šimun', registered: '2018/01/21', role: 'Staff', status: 'Active'},
{id: 21, name: 'Vishnu Serghei', registered: '2018/01/01', role: 'Member', status: 'Active'},
{id: 22, name: 'Zbyněk Phoibos', registered: '2018/02/01', role: 'Staff', status: 'Banned'},
{id: 23, name: 'Aulus Agmundr', registered: '2018/01/01', role: 'Member', status: 'Pending'},
{id: 42, name: 'Ford Prefect', registered: '2001/05/25', role: 'Alien', status: 'Don\'t panic!'}
]
const getBadge = status => {
switch (status) {
case 'Active': return 'success'
case 'Inactive': return 'secondary'
case 'Pending': return 'warning'
case 'Banned': return 'danger'
default: return 'primary'
}
}
export const simple = () =>
<CCol lg="6" xs="12">
<CCard>
<CCardBody>
<CDataTable
items={usersData}
fields={fields}
itemsPerPage={5}
pagination
scopedSlots = {{
'status':
(item)=>(
<td>
<CBadge color={getBadge(item.status)}>
{item.status}
</CBadge>
</td>
)
}}
/>
</CCardBody>
</CCard>
</CCol>
export const full = () => {
const dark = boolean('Dark', false, 'View')
const hover = boolean('Hover', false, 'View')
const striped = boolean('Striped', false, 'View')
const border = boolean('Bordered', false, 'View')
const outlined = boolean('Outlined', false, 'View')
const responsive = boolean('Responsive', true, 'View')
const footer = boolean('Footer', false, 'View')
const header = boolean('Header', true, 'View')
const pagination = boolean('Pagination', false, 'Pagination')
const itemsPerPageSelect = boolean('Items per page select', false, 'Pagination')
const itemsPerPage = number('Items per page', 10, {}, 'Pagination')
const pagActivePage = number('Pagination active page on start', 1, {}, 'Pagination')
const loading = boolean('Loading', false, 'Other')
const addTableClasses = text('Add table classes', '', 'Other')
const sorter = boolean('Sorter', false, 'Sort and filter')
//const clickableRows = boolean('Clickable rows', false, 'Sort and filter')
const columnFilter = boolean('Column filter', false, 'Sort and filter')
const tableFilter = boolean('Table filter', false, 'Sort and filter')
const tableFilterValue = text('Table filter value', '', 'Sort and filter')
return <CCol lg="6" xs="12">
<CCard>
<CCardBody>
<CDataTable
//data
items={usersData}
fields={fields}
//view
dark={dark}
hover={hover}
striped={striped}
border={border}
outlined={outlined}
responsive={responsive}
footer={footer}
header={header}
//pagination
itemsPerPage={itemsPerPage}
pagination={pagination}
itemsPerPageSelect={itemsPerPageSelect}
activePage={pagActivePage}
//other
loading={loading}
addTableClasses={addTableClasses}
//sort and filter
sorter={sorter}
//clickableRows={clickableRows}
columnFilter={columnFilter}
tableFilter={tableFilter}
tableFilterValue={tableFilterValue}
//scoped slots
scopedSlots = {{
'status':
(item)=>(
<td>
<CBadge color={getBadge(item.status)}>
{item.status}
</CBadge>
</td>
)
}}
/>
</CCardBody>
</CCard>
</CCol>
}