Browse Source

removed unused comment + added detailed proptype for popinfixed

Skylsmoi 7 years ago
parent
commit
77a213bc7f
2 changed files with 19 additions and 7 deletions
  1. 0 7
      src/component/common/Card/Card.jsx
  2. 19 0
      src/component/common/PopinFixed/PopinFixed.jsx

+ 0 - 7
src/component/common/Card/Card.jsx View File

@@ -14,13 +14,6 @@ const Card = props => {
14 14
 export default Card
15 15
 
16 16
 Card.propTypes = {
17
-  // check https://stackoverflow.com/questions/27366077/only-allow-children-of-a-specific-type-in-a-react-component
18
-  // children: PropTypes.arrayOf( // children is an array
19
-  //   PropTypes.shape({ // of objects
20
-  //     type: PropTypes.oneOf([CardHeader, CardBody]) // that as an attribute 'type' equals to CardHeader or CardBody
21
-  //   })
22
-  // ),
23
-
24 17
   // from http://www.mattzabriskie.com/blog/react-validating-children
25 18
   children: PropTypes.arrayOf((children, key, componentName /* , location, propFullName */) => {
26 19
     if (

+ 19 - 0
src/component/common/PopinFixed/PopinFixed.jsx View File

@@ -1,6 +1,9 @@
1 1
 import React from 'react'
2 2
 import classnames from 'classnames'
3 3
 import PropTypes from 'prop-types'
4
+import PopinFixedHeader from './PopinFixedHeader.jsx'
5
+import PopinFixedOption from './PopinFixedOption.jsx'
6
+import PopinFixedContent from './PopinFixedContent.jsx'
4 7
 
5 8
 const PopinFixed = props => {
6 9
   return (
@@ -17,6 +20,22 @@ PopinFixed.propTypes = {
17 20
   visible: PropTypes.bool
18 21
 }
19 22
 
23
+PopinFixed.propTypes = {
24
+  // from http://www.mattzabriskie.com/blog/react-validating-children
25
+  children: PropTypes.arrayOf((children, key, componentName /* , location, propFullName */) => {
26
+    if (
27
+      children.length > 3 ||
28
+      children[0].type !== PopinFixedHeader ||
29
+      children[1].type !== PopinFixedOption ||
30
+      children[2].type !== PopinFixedContent
31
+    ) {
32
+      return new Error(`PropType Error: childrens of ${componentName} must be: 1 PopinFixedHeader, 1 PopinFixedOption and 1 PopinFixedContent.`)
33
+    }
34
+  }).isRequired,
35
+  customClass: PropTypes.string,
36
+  visible: PropTypes.bool
37
+}
38
+
20 39
 PopinFixed.defaultProps = {
21 40
   customClass: '',
22 41
   visible: true