lucid-ui
Version:
A UI component library from AppNexus.
205 lines (202 loc) • 6.56 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import React from 'react';
import createClass from 'create-react-class';
import { DataTable, SuccessIcon, TextField, CheckboxLabeled } from '../../../index';
var data = [{
id: 1,
first_name: 'Isaac',
last_name: 'Newton',
email: 'inewton@example.com',
occupation: 'Physicist',
salary: '$100.01',
status: /*#__PURE__*/React.createElement(SuccessIcon, null)
}, {
id: 2,
first_name: 'Albert',
last_name: 'Einstein',
email: 'aeinstein@example.com',
occupation: 'Physicist',
salary: '$100.02',
status: /*#__PURE__*/React.createElement(SuccessIcon, null),
isSelected: true
}, {
id: 3,
first_name: 'Leonardo',
last_name: 'da Vinci',
email: 'ldvinci@example.com',
occupation: 'Engineer',
salary: '$100.03',
status: /*#__PURE__*/React.createElement(SuccessIcon, null),
isActive: true
}, {
id: 4,
first_name: 'Aristotle',
last_name: null,
email: 'aristotle@example.com',
occupation: 'Tutor',
salary: '$100.04',
status: /*#__PURE__*/React.createElement(SuccessIcon, null)
}, {
id: 5,
first_name: 'Galileo',
email: 'ggalilei@example.com',
occupation: 'Physicist',
salary: '$100.05',
status: /*#__PURE__*/React.createElement(SuccessIcon, null)
}, {
id: 6,
first_name: 'Charles',
last_name: 'Darwin',
email: 'cdarwin@example.com',
occupation: 'Biologist',
salary: '$100.06',
status: /*#__PURE__*/React.createElement(SuccessIcon, null)
}, {
id: 7,
first_name: 'Alexander',
last_name: 'Macedon',
email: 'amacedon@example.com',
occupation: 'Head of State',
salary: '$100.07',
status: /*#__PURE__*/React.createElement(SuccessIcon, null)
}, {
id: 8,
first_name: 'Plato',
last_name: 'Plato',
email: 'plato@example.com',
occupation: 'Philosopher',
salary: '$100.08',
status: /*#__PURE__*/React.createElement(SuccessIcon, null)
}, {
id: 9,
first_name: 'Mahatma',
last_name: 'Gandhi',
email: 'mgandhi@example.com',
occupation: 'Politician',
salary: '$100.09',
status: /*#__PURE__*/React.createElement(SuccessIcon, null)
}, {
id: 10,
first_name: 'William',
last_name: 'Shakespeare',
email: 'wshakespear@example.com',
occupation: 'Playwright',
salary: '$100.10',
status: /*#__PURE__*/React.createElement(SuccessIcon, null)
}];
export default createClass({
getInitialState: function getInitialState() {
return {
hasFixedHeader: true,
isSelectable: true,
hasLightHeader: false,
fixedColumnCount: 2,
fixedRowHeight: 50,
isActionable: false
};
},
handleToggle: function handleToggle(stateItem) {
this.setState(_defineProperty({}, stateItem, !this.state[stateItem]));
},
handleNumeric: function handleNumeric(stateItem, value) {
this.setState(_defineProperty({}, stateItem, value));
},
renderDataTable: function renderDataTable(props) {
return /*#__PURE__*/React.createElement(DataTable, _extends({
data: data
}, props), /*#__PURE__*/React.createElement(DataTable.Column, {
field: "id",
align: "left",
width: 35
}, "ID"), /*#__PURE__*/React.createElement(DataTable.Column, {
field: "first_name",
align: "left",
width: 100
}, "First"), /*#__PURE__*/React.createElement(DataTable.Column, {
field: "last_name",
align: "left",
width: 100
}, "Last"), /*#__PURE__*/React.createElement(DataTable.Column, {
field: "email",
align: "left",
width: 900
}, "E-Mail"), /*#__PURE__*/React.createElement(DataTable.Column, {
field: "occupation",
align: "left",
width: 100
}, "Occupation"), /*#__PURE__*/React.createElement(DataTable.Column, {
field: "salary",
align: "right",
width: 100
}, "Salary"), /*#__PURE__*/React.createElement(DataTable.Column, {
field: "status",
align: "center",
width: 100
}, "Status"));
},
render: function render() {
var _this = this;
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
style: {
marginBottom: 6,
display: 'block',
fontSize: 12
}
}, /*#__PURE__*/React.createElement(TextField, {
style: {
marginRight: 9,
width: 45
},
onChangeDebounced: function onChangeDebounced(v) {
return _this.handleNumeric('fixedColumnCount', parseInt(v, 10));
},
placeholder: "fixedColumnCount",
value: this.state.fixedColumnCount
}), "fixedColumnCount"), /*#__PURE__*/React.createElement("label", {
style: {
marginBottom: 6,
display: 'block',
fontSize: 12
}
}, /*#__PURE__*/React.createElement(TextField, {
style: {
marginRight: 9,
width: 45
},
onChangeDebounced: function onChangeDebounced(v) {
return _this.handleNumeric('fixedRowHeight', parseInt(v, 10));
},
placeholder: "fixedRowHeight",
value: this.state.fixedRowHeight
}), "fixedRowHeight"), /*#__PURE__*/React.createElement(CheckboxLabeled, {
Label: "hasFixedHeader",
isSelected: this.state.hasFixedHeader,
onSelect: function onSelect() {
return _this.handleToggle('hasFixedHeader');
}
}), /*#__PURE__*/React.createElement(CheckboxLabeled, {
Label: "isSelectable",
isSelected: this.state.isSelectable,
onSelect: function onSelect() {
return _this.handleToggle('isSelectable');
}
}), /*#__PURE__*/React.createElement(CheckboxLabeled, {
Label: "hasLightHeader",
isSelected: this.state.hasLightHeader,
onSelect: function onSelect() {
return _this.handleToggle('hasLightHeader');
}
}), /*#__PURE__*/React.createElement(CheckboxLabeled, {
Label: "isActionable",
isSelected: this.state.isActionable,
onSelect: function onSelect() {
return _this.handleToggle('isActionable');
}
}), /*#__PURE__*/React.createElement("div", {
style: {
height: '200px'
}
}, this.renderDataTable(this.state)));
}
});