├── .gitignore ├── README.md ├── SUMMARY.md ├── images ├── affix │ ├── affix_placeholder.png │ └── decorator.png ├── breadcrumb │ └── route3.png └── button │ └── button1.png ├── story ├── components │ ├── affix.md │ ├── breadcrumb.md │ ├── button.md │ ├── button_group.md │ ├── dropdown.md │ ├── form.md │ ├── grid.md │ ├── icon.md │ ├── notification.md │ ├── trigger_index.md │ └── trigger_popup.md └── index.js.md └── typeface.zip /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | !server/logs 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | *.DS_Store 11 | 12 | # testing 13 | **/coverage 14 | 15 | # node-waf configuration 16 | .lock-wscript 17 | 18 | # Compiled binary addons (http://nodejs.org/api/addons.html) 19 | build/Release 20 | ui/build 21 | server/build 22 | 23 | # Dependency directory 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 25 | node_modules 26 | 27 | # Bower 28 | bower_components/ 29 | dist 30 | 31 | # WebStorm文件 32 | *.idea/ 33 | 34 | # Emacs 35 | # tern(JS解析器, emacs里补全用的) 36 | .tern-port 37 | .#* 38 | *# 39 | *~ 40 | 41 | # 其他 42 | dump.rdb 43 | .DS_Store 44 | .env.local 45 | .env.development.local 46 | .env.test.local 47 | .env.production.local 48 | 49 | # 后端工程配置文件(敏感信息) 50 | server/config/default.yml 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > github: [地址](https://github.com/zhangzewei/read-antd-code) 2 | > gitbook: [地址](https://markzzw.gitbook.io/yue-du-antd-yuan-ma/) 3 | 4 | # 简介 5 | 本书主要是解读蚂蚁金服[Antd](https://ant.design/index-cn)的react框架源代码而写,为了学习其思想和代码技巧,如果有什么问题欢迎提出和添加 6 | 7 | # 须知 8 | 9 | 1. 本书主要研究其 `2.13.4` 版本的代码 10 | 2. 由于是解读源代码,所以请在观看本书的时候也将代码下载下来一同观看效果更佳 11 | 3. antd组件基本采用的是typescript语法,所以需要了解TP的语法 -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [本书简介](README.md) 4 | 5 | + Index 6 | + [Index.js](./story/index.js.md) 7 | 8 | + Icon 9 | + [Icon组件](./story/components/icon.md) 10 | 11 | + Button 12 | + [Button组件](./story/components/button.md) 13 | + [ButtonGroup组件](./story/components/button_group.md) 14 | 15 | + Layout 16 | + [Grid组件](./story/components/grid.md) 17 | 18 | + Navigation 19 | + [Affix组件](./story/components/affix.md) 20 | + [Breadcrumb组件](./story/components/breadcrumb.md) 21 | + [Dropdown组件](./story/components/dropdown.md) 22 | + [Trigger-index.js](./story/components/trigger_index.md) 23 | 24 | + Entry 25 | + [Form组件](./story/components/form.md) 26 | + [notification](./story/components/notification.md) -------------------------------------------------------------------------------- /images/affix/affix_placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangzewei/read-antd-code/14e7e376417867bc75ee8ff3ade8765a00c58f7b/images/affix/affix_placeholder.png -------------------------------------------------------------------------------- /images/affix/decorator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangzewei/read-antd-code/14e7e376417867bc75ee8ff3ade8765a00c58f7b/images/affix/decorator.png -------------------------------------------------------------------------------- /images/breadcrumb/route3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangzewei/read-antd-code/14e7e376417867bc75ee8ff3ade8765a00c58f7b/images/breadcrumb/route3.png -------------------------------------------------------------------------------- /images/button/button1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangzewei/read-antd-code/14e7e376417867bc75ee8ff3ade8765a00c58f7b/images/button/button1.png -------------------------------------------------------------------------------- /story/components/affix.md: -------------------------------------------------------------------------------- 1 | # Affix 2 | 3 | 这个组件是一个图钉组件,使用的fixed布局,让组件固定在窗口的某一个位置上,并且可以在到达指定位置的时候才去固定。 4 | 5 | ## AffixProps 6 | 7 | 还是老样子,看一个组件首先我们先来看看他可以传入什么参数 8 | 9 | ```js 10 | // Affix 11 | export interface AffixProps { 12 | /** 13 | * 距离窗口顶部达到指定偏移量后触发 14 | */ 15 | offsetTop?: number; 16 | offset?: number; 17 | /** 距离窗口底部达到指定偏移量后触发 */ 18 | offsetBottom?: number; 19 | style?: React.CSSProperties; 20 | /** 固定状态改变时触发的回调函数 */ 21 | onChange?: (affixed?: boolean) => void; 22 | /** 设置 Affix 需要监听其滚动事件的元素,值为一个返回对应 DOM 元素的函数 */ 23 | target?: () => Window | HTMLElement; 24 | // class样式命名空间,可以定义自己的样式命名 25 | prefixCls?: string; 26 | } 27 | ``` 28 | 29 | ## Render() 30 | 31 | 看完传入参数之后,就到入口函数看看这里用到了什么参数 32 | 33 | ```js 34 | render() { 35 | // 构造当前组件的class样式 36 | const className = classNames({ 37 | [this.props.prefixCls || 'ant-affix']: this.state.affixStyle, 38 | }); 39 | // 这里和之前看的一样,忽略掉props中的在div标签上面不需要的一些属性 40 | // 但是貌似没有去掉offset,后面我还查了一下DIV上面能不能有offset 41 | // 但是没看见有offset,只看见offsetLeft, offsetHeight.... 42 | const props = omit(this.props, ['prefixCls', 'offsetTop', 'offsetBottom', 'target', 'onChange']); 43 | const placeholderStyle = { ...this.state.placeholderStyle, ...this.props.style }; 44 | return ( 45 | // 注意咯 看这里placeholder的作用了 如图 46 | // 这里的placeholder的作用是当这个组件样式变为fixed的时候, 47 | // 会脱离文档流,然后导致原本的dom结构变化,宽高都会有所变化 48 | // 所以这是后放一个占位元素来顶住这一组件脱离文档流的时候的影响 49 |
name | 344 |type | 345 |default | 346 |description | 347 |
---|---|---|---|
popupClassName | 352 |string | 353 |354 | | additional className added to popup | 355 |
destroyPopupOnHide | 358 |boolean | 359 |false | 360 |whether destroy popup when hide | 361 |
getPopupClassNameFromAlign | 364 |getPopupClassNameFromAlign(align: Object):String | 365 |366 | | additional className added to popup according to align | 367 |
action | 370 |string[] | 371 |['hover'] | 372 |which actions cause popup shown. enum of 'hover','click','focus','contextMenu' | 373 |
mouseEnterDelay | 376 |number | 377 |0 | 378 |delay time to show when mouse enter. unit: s. | 379 |
mouseLeaveDelay | 382 |number | 383 |0.1 | 384 |delay time to hide when mouse leave. unit: s. | 385 |
popupStyle | 388 |Object | 389 |390 | | additional style of popup | 391 |
prefixCls | 394 |String | 395 |rc-trigger-popup | 396 |prefix class name | 397 |
popupTransitionName | 400 |String|Object | 401 |402 | | https://github.com/react-component/animate | 403 |
maskTransitionName | 406 |String|Object | 407 |408 | | https://github.com/react-component/animate | 409 |
onPopupVisibleChange | 412 |Function | 413 |414 | | call when popup visible is changed | 415 |
mask | 418 |boolean | 419 |false | 420 |whether to support mask | 421 |
maskClosable | 424 |boolean | 425 |true | 426 |whether to support click mask to hide | 427 |
popupVisible | 430 |boolean | 431 |432 | | whether popup is visible | 433 |
zIndex | 436 |number | 437 |438 | | popup's zIndex | 439 |
defaultPopupVisible | 442 |boolean | 443 |444 | | whether popup is visible initially | 445 |
popupAlign | 448 |Object: alignConfig of [dom-align](https://github.com/yiminghe/dom-align) | 449 |450 | | popup 's align config | 451 |
onPopupAlign | 454 |function(popupDomNode, align) | 455 |456 | | callback when popup node is aligned | 457 |
popup | 460 |React.Element | function() => React.Element | 461 |462 | | popup content | 463 |
getPopupContainer | 466 |getPopupContainer(): HTMLElement | 467 |468 | | function returning html node which will act as popup container | 469 |
getDocument | 472 |getDocument(): HTMLElement | 473 |474 | | function returning document node which will be attached click event to close trigger | 475 |
popupPlacement | 478 |string | 479 |480 | | use preset popup align config from builtinPlacements, can be merged by popupAlign prop | 481 |
builtinPlacements | 484 |object | 485 |486 | | builtin placement align map. used by placement prop | 487 |
name | 39 |type | 40 |default | 41 |description | 42 |
---|---|---|---|
align | 47 |Object | 48 |49 | | same with alignConfig from https://github.com/yiminghe/dom-align | 50 |
onAlign | 53 |function(source:HTMLElement, align:Object) | 54 |55 | | called when align | 56 |
target | 59 |function():HTMLElement | 60 |function(){return window;} | 61 |a function which returned value is used for target from https://github.com/yiminghe/dom-align | 62 |
monitorWindowResize | 65 |Boolean | 66 |false | 67 |whether realign when window is resized | 68 |
name | 82 |type | 83 |default | 84 |description | 85 |
---|---|---|---|
component | 90 |React.Element/String | 91 |'span' | 92 |wrap dom node or component for children. set to '' if you do not wrap for only one child | 93 |
showProp | 96 |String | 97 |98 | | using prop for show and hide. [demo](http://react-component.github.io/animate/examples/hide-todo.html) | 99 |
exclusive | 102 |Boolean | 103 |104 | | whether allow only one set of animations(enter and leave) at the same time. | 105 |
transitionName | 108 |String | 109 |110 | | transitionName, need to specify corresponding css | 111 |
transitionAppear | 114 |Boolean | 115 |false | 116 |whether support transition appear anim | 117 |
transitionEnter | 120 |Boolean | 121 |true | 122 |whether support transition enter anim | 123 |
transitionLeave | 126 |Boolean | 127 |true | 128 |whether support transition leave anim | 129 |
onEnd | 132 |function(key:String, exists:Boolean) | 133 |true | 134 |animation end callback | 135 |
animation | 138 |Object | 139 |{} | 140 |141 | to animate with js. see animation format below. 142 | | 143 |