Guest User

Untitled

a guest
Mar 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. class App extends React.Component {
  2. render() {
  3. const columns = [
  4. {
  5. header: '',
  6. cell: 'id',
  7. },
  8. {
  9. header: 'First Name',
  10. cell: 'firstName',
  11. },
  12. {
  13. header: 'Last Name',
  14. cell: 'lastName',
  15. },
  16. {
  17. header: 'Phone Number',
  18. cell: 'phoneNumber',
  19. },
  20. {
  21. header: 'Email',
  22. cell: 'email',
  23. },
  24. ]
  25.  
  26. const data = generateFakeData(
  27. faker => ({
  28. id: faker.random.uuid(),
  29. firstName: faker.name.firstName(),
  30. lastName: faker.name.lastName(),
  31. phoneNumber: faker.phone.phoneNumber(),
  32. email: faker.internet.email(),
  33. }),
  34. 100
  35. )
  36.  
  37. return (
  38. <div
  39. role="grid"
  40. aria-readonly="true"
  41. aria-colcount={columns.length}
  42. aria-rowcount={data.length}
  43. style={{
  44. display: 'grid',
  45. gridTemplateColumns: `repeat(${columns.length}, auto)`,
  46. border: '1px solid #f1f1f1',
  47. }}
  48. >
  49. {/* header */}
  50. {columns.map((column, index) => (
  51. <div
  52. key={index}
  53. role="columnheader"
  54. id={`column-${index}`}
  55. style={{
  56. padding: 12,
  57. whiteSpace: 'nowrap',
  58. backgroundColor: '#f1f1f1',
  59. position: 'sticky',
  60. top: 0,
  61. zIndex: 5,
  62. }}
  63. >
  64. {column.header}
  65. </div>
  66. ))}
  67. {/* body */}
  68. {data.map(row =>
  69. columns.map((column, index) => (
  70. <div
  71. key={index}
  72. role="gridcell"
  73. aria-labelledby={`column-${index}`}
  74. style={{
  75. padding: 12,
  76. whiteSpace: 'nowrap',
  77. borderTop: '1px solid #f1f1f1',
  78. backgroundColor: '#ffffff',
  79. position: index === 0 && 'sticky',
  80. left: 0,
  81. zIndex: index === 0 ? 3 : 1,
  82. }}
  83. >
  84. {row[column.cell]}
  85. </div>
  86. ))
  87. )}
  88. </div>
  89. )
  90. }
  91. }
Add Comment
Please, Sign In to add comment