Advertisement
Guest User

menu app

a guest
Jul 17th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import '../scss/test.scss';
  3. import { Typography, Row, Col, Icon, Button } from 'antd';
  4. const { Title } = Typography;
  5.  
  6. class Test extends React.Component {
  7.   constructor (props) {
  8.     super(props);
  9.     this.data = [
  10.       {
  11.         name: 'HR',
  12.         module: [
  13.           {
  14.             name: 'Human Resource',
  15.             icon: 'user'
  16.           }
  17.         ]
  18.       },
  19.       {
  20.         name: 'Office',
  21.         module: [
  22.           {
  23.             name: 'Human Resource',
  24.             icon: 'user'
  25.           },
  26.           {
  27.             name: 'Human Resource',
  28.             icon: 'user'
  29.           }
  30.         ]
  31.       },
  32.       {
  33.         name: 'Project',
  34.         module: [
  35.           {
  36.             name: 'Human Resource',
  37.             icon: 'user'
  38.           },
  39.           {
  40.             name: 'Human Resource',
  41.             icon: 'user'
  42.           },
  43.           {
  44.             name: 'Human Resource',
  45.             icon: 'user'
  46.           },
  47.           {
  48.             name: 'Human Resource',
  49.             icon: 'user'
  50.           }
  51.         ]
  52.       },
  53.       {
  54.         name: 'Booking',
  55.         module: [
  56.           {
  57.             name: 'Human Resource',
  58.             icon: 'solution'
  59.           },
  60.           {
  61.             name: 'Human Resource',
  62.             icon: 'user'
  63.           },
  64.           {
  65.             name: 'Human Resource',
  66.             icon: 'qq'
  67.           }
  68.         ]
  69.       }
  70.     ];
  71.   }
  72.  
  73.   showMenu () {
  74.     const size = this.data.length;
  75.     const menu = this.data.map((item, index) => {
  76.       return (
  77.         <Col key={index} order={index} span={24 / size}>
  78.           <div className="divider">
  79.             <Title level={3} style={{ textAlign: 'center' }}>{item.name}</Title>
  80.             {this.showItem(item.module)}
  81.           </div>
  82.         </Col>
  83.       );
  84.     });
  85.     return menu;
  86.   }
  87.  
  88.   showItem (items) {
  89.     // map throw 2 object in arrays
  90.     return items.map((item, index) => {
  91.       if (index % 2 === 0) {
  92.         return (
  93.           <Row type="flex" justify="center" align="top" gutter={8}>
  94.             {
  95.               !item ? null
  96.                 : (<Col style={{ textAlign: 'center', margin: '10px' }}>
  97.                   <Button style={{ height: 100, color: '#2ecc71', width: 100 }}>
  98.                     <Icon type={item.icon} style={{ fontSize: 50 }}/>
  99.                   </Button>
  100.                   <p className="p">{item.name} </p>
  101.                 </Col>)
  102.             }
  103.             {
  104.               !items[index + 1] ? null
  105.                 : <Col style={{ textAlign: 'center', margin: '10px' }}>
  106.                   <Button style={{ height: 100, color: '#2ecc71', width: 100 }}>
  107.                     <Icon type={items[index + 1].icon} style={{ fontSize: 50 }}/>
  108.                   </Button>
  109.                   <p className="p">{items[index + 1].name} </p>
  110.                 </Col>
  111.             }
  112.           </Row>
  113.         );
  114.       }
  115.     });
  116.   }
  117.   render () {
  118.     return (
  119.       <div>
  120.         <h1 className="title">FPT Work</h1>
  121.         <Row type="flex" >
  122.           {this.showMenu()}
  123.         </Row>
  124.       </div>
  125.     );
  126.   }
  127. }
  128.  
  129. export default Test;
  130.  
  131.  
  132. $color : #2ecc71;
  133.  
  134. .title {
  135.     // {textAlign:"center", backgroundColor:"#2ecc71" , color:"white", padding:"20px"}
  136.     text-align: center;
  137.     background-color: $color;
  138.     color: white;
  139.     padding: 20px;
  140. };
  141.  
  142. .divider {
  143.     border-right: 0.5px solid $color;
  144.     min-height: 90vh;
  145.      
  146. }
  147. .p {
  148.     color: $color;
  149.     width: 100%;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement