@@ -2,63 +2,112 @@ import React, { Component } from "react";
22import { render } from "react-dom" ;
33import MuiDataTable from "../../lib" ;
44import data from "./data" ;
5- import { Button , Paper } from "@material-ui/core/es/index" ;
5+ import { AppBar , Button , Paper , Toolbar , SvgIcon , IconButton } from "@material-ui/core/es/index" ;
6+ import { createGenerateClassName , createMuiTheme , MuiThemeProvider } from "@material-ui/core/styles" ;
7+ import { blue } from "@material-ui/core/colors" ;
8+ import "./styles.css" ;
69
7- import JssProvider from 'react-jss/lib/JssProvider' ;
8- import { createGenerateClassName } from '@material-ui/core/styles' ;
10+ import JssProvider from "react-jss/lib/JssProvider" ;
911
1012const generateClassName = createGenerateClassName ( {
1113 dangerouslyUseGlobalCSS : true ,
12- productionPrefix : 'c' ,
14+ productionPrefix : "c" ,
1315} ) ;
1416
17+ function GitHub ( props ) {
18+ return (
19+ < SvgIcon { ...props } >
20+ < path d = "M12 .3a12 12 0 0 0-3.8 23.4c.6.1.8-.3.8-.6v-2c-3.3.7-4-1.6-4-1.6-.6-1.4-1.4-1.8-1.4-1.8-1-.7.1-.7.1-.7 1.2 0 1.9 1.2 1.9 1.2 1 1.8 2.8 1.3 3.5 1 0-.8.4-1.3.7-1.6-2.7-.3-5.5-1.3-5.5-6 0-1.2.5-2.3 1.3-3.1-.2-.4-.6-1.6 0-3.2 0 0 1-.3 3.4 1.2a11.5 11.5 0 0 1 6 0c2.3-1.5 3.3-1.2 3.3-1.2.6 1.6.2 2.8 0 3.2.9.8 1.3 1.9 1.3 3.2 0 4.6-2.8 5.6-5.5 5.9.5.4.9 1 .9 2.2v3.3c0 .3.1.7.8.6A12 12 0 0 0 12 .3" />
21+ </ SvgIcon >
22+ )
23+ }
1524class App extends Component {
1625 constructor ( props ) {
1726 super ( props ) ;
18-
27+ this . state = {
28+ theme : 'light'
29+ } ;
30+
1931 App . handleClick = App . handleClick . bind ( this ) ;
32+ this . handleThemeChange = this . handleThemeChange . bind ( this ) ;
2033 }
21-
34+
2235 componentWillMount ( ) {
23-
36+
2437 }
25-
38+
2639 static handleClick ( e ) {
2740 /* Your code is here.alert is the example */
2841 alert ( "parent td#id: " + e . target . parentNode . id ) ;
2942 }
30-
43+
44+ handleThemeChange ( ) {
45+ const theme = this . state . theme ;
46+ if ( theme === "light" ) {
47+ this . setState ( { theme : "dark" } )
48+ } else {
49+ this . setState ( { theme : "light" } )
50+ }
51+ }
52+
3153 render ( ) {
54+ const theme = createMuiTheme ( {
55+ palette : {
56+ secondary : {
57+ main : blue [ 700 ] ,
58+ } ,
59+ type : this . state . theme ,
60+ } ,
61+ } ) ;
62+
3263 const columns = [
33- { label : "First Name" , key : "fname" , sort : true } ,
34- { label : "Last Name" , key : "lname" , sort : true } ,
35- { label : "Email" , key : "email" } ,
36- { label : "Gender" , key : "gender" } ,
37- { label : "Action" , key : "action" } , /* <-- this is required if you using customAction */
38- ] ; /* <-- Table header columns. this is required */
39-
40- const action = < Button onClick = { App . handleClick } > Action</ Button > ; /* <-- action button */
41-
64+ { label : "First Name" , key : "fname" , sort : true } ,
65+ { label : "Last Name" , key : "lname" , sort : true } ,
66+ { label : "Email" , key : "email" } ,
67+ { label : "Gender" , key : "gender" } ,
68+ { label : "Action" , key : "action" } , /* <-- this is required if you using customAction */
69+ ] ;
70+ /* <-- Table header columns. this is required */
71+
72+ const action = < Button onClick = { App . handleClick } > Action</ Button > ;
73+ /* <-- action button */
74+
4275 const options = {
43- hasIndex : true , /* <-- use numbers for rows*/
76+ hasIndex : true , /* <-- use numbers for rows*/
4477 customAction : action , /* <-- use action button for row */
45- searchBox : true , /* <-- search true or false */
46- csv : true , /* <-- csv download true or false */
47- indexColumn : "fname" /* <-- add your data first unique column name for this like _id, i used fname because i don't have a _id field in my array */
78+ searchBox : true , /* <-- search true or false */
79+ csv : true , /* <-- csv download true or false */
80+ indexColumn : "fname" , /* <-- add your data first unique column name for this like _id, i used fname because i don't have a _id field in my array */
81+ darkTheme : true
4882 } ;
49-
83+
5084 return (
5185 < div >
52- < Paper style = { { padding : 16 , margin : 16 } } >
53- < MuiDataTable data = { data } columns = { columns } options = { options } title = { "User Data" } />
86+ < MuiThemeProvider theme = { theme } >
87+ < AppBar position = "static" >
88+ < Toolbar >
89+ < Button color = "secondary" variant = { "raised" } onClick = { this . handleThemeChange } > Change Theme
90+ Light / Dark</ Button >
91+
92+ < div style = { { flexGrow :1 } } />
93+
94+ < IconButton style = { { color :'#fff' } } component = { 'a' } href = { 'https://github.com/GihanRangana/react-mui-datatables' } >
95+ < GitHub />
96+ </ IconButton >
97+ </ Toolbar >
98+ </ AppBar >
99+
100+ < Paper style = { { padding : 16 , margin : 16 } } >
101+ < MuiDataTable data = { data } columns = { columns } options = { options } title = { "User Data" } />
54102 </ Paper >
103+ </ MuiThemeProvider >
55104 </ div >
56105 ) ;
57106 }
58-
107+
59108}
60109
61110render (
62111 < JssProvider generateClassName = { generateClassName } >
63- < App />
112+ < App />
64113 </ JssProvider > , document . getElementById ( "root" ) ) ;
0 commit comments