xinbaihui / Blog

web front end
1 stars 0 forks source link

【React】在ACE项目中封装了Pagination Component #43

Open xinbaihui opened 3 years ago

xinbaihui commented 3 years ago

Add Pagination Component in ACE project (2019.08.18)

  1. keypress VS keydown

    • keypress: The keypress event is fired when a key is pressed down and that key normally produces a character value
    • keydown: 与 keypress事件不同的是,无论是否产生一个字符值,keydown事件均会被触发
    • eg: ctrl, shift不会产生字符, 只触发keydown,其他比如enter,space会产生字符,两个都触发
    • The implementation of the theory is not same in all browsers.

      so 此处用keyPress合适

  2. input size 定义空间初始大小,默认20。指的是input的大小能显示20个字符。

  3. e.target VS e.currentTarget e.target is what triggers the event dispatcher to trigger and e.currentTarget is what you assigned your listener to.

    • e.target: 指向事件触发的元素
    • e.currentTarget: 指向事件绑定的元素
  4. use parseInt(xx, 10) instead of parseInt(xx) 参考:https://devdocs.io/javascript/global_objects/parseint

  5. origin code

    
    import * as React from 'react';
    import { withStyles, WithStyles } from '@material-ui/core/styles';
    import { compose } from 'recompose';

import ClrIcon from '../ClrIcon'

import styles from './styles';

interface PaginationProps extends WithStyles { className?: string; pageSize?: number; total?: number; onPageNumberChange(pageNum: number): void; }

interface PaginationState { currentPageNum: number; // 1 ~ lastPageNum inputValue: number; // 1 ~ lastPageNum }

class Pagination extends React.PureComponent<PaginationProps, PaginationState> { static defaultProps = { pageSize: 10, total: 0 };

state = { currentPageNum: 1, inputValue: 1 };

/**