Skip to content

Commit ef01243

Browse files
authored
Merge pull request #56 from ekoeryanto/prop-types
feat(prop-types): add prop-types validation to components
2 parents 6b929b7 + 01f846e commit ef01243

File tree

11 files changed

+154
-9
lines changed

11 files changed

+154
-9
lines changed

src/cms/preview-templates/AboutPagePreview.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import { AboutPageTemplate } from '../../templates/about-page'
34

45
const AboutPagePreview = ({ entry, widgetFor }) => (
@@ -8,4 +9,11 @@ const AboutPagePreview = ({ entry, widgetFor }) => (
89
/>
910
)
1011

12+
AboutPagePreview.propTypes = {
13+
entry: PropTypes.shape({
14+
getIn: PropTypes.func,
15+
}),
16+
widgetFor: PropTypes.func,
17+
}
18+
1119
export default AboutPagePreview

src/cms/preview-templates/BlogPostPreview.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import { BlogPostTemplate } from '../../templates/blog-post'
34

45
const BlogPostPreview = ({ entry, widgetFor }) => (
@@ -10,4 +11,11 @@ const BlogPostPreview = ({ entry, widgetFor }) => (
1011
/>
1112
)
1213

14+
BlogPostPreview.propTypes = {
15+
entry: PropTypes.shape({
16+
getIn: PropTypes.func,
17+
}),
18+
widgetFor: PropTypes.func,
19+
}
20+
1321
export default BlogPostPreview

src/cms/preview-templates/ProductPagePreview.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import { ProductPageTemplate } from '../../templates/product-page'
34

45
const ProductPagePreview = ({ entry, getAsset }) => {
@@ -45,4 +46,11 @@ const ProductPagePreview = ({ entry, getAsset }) => {
4546
)
4647
}
4748

49+
ProductPagePreview.propTypes = {
50+
entry: PropTypes.shape({
51+
getIn: PropTypes.func,
52+
}),
53+
getAsset: PropTypes.func,
54+
}
55+
4856
export default ProductPagePreview

src/components/Content.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23

3-
export default ({ content, className }) => (
4-
<div className={className}>{content}</div>
5-
)
64
export const HTMLContent = ({ content, className }) => (
75
<div className={className} dangerouslySetInnerHTML={{ __html: content }} />
86
)
7+
8+
const Content = ({ content, className }) => (
9+
<div className={className}>{content}</div>
10+
)
11+
12+
Content.propTypes = {
13+
content: PropTypes.string,
14+
className: PropTypes.string,
15+
}
16+
17+
HTMLContent.propTypes = Content.propTypes
18+
19+
export default Content

src/components/Features.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23

34
const FeatureGrid = ({ gridItems }) => (
45
<div className="columns is-multiline">
@@ -15,4 +16,13 @@ const FeatureGrid = ({ gridItems }) => (
1516
</div>
1617
)
1718

19+
FeatureGrid.propTypes = {
20+
gridItems: PropTypes.arrayOf(
21+
PropTypes.shape({
22+
image: PropTypes.string,
23+
text: PropTypes.string,
24+
})
25+
),
26+
}
27+
1828
export default FeatureGrid

src/components/Pricing.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23

3-
export default ({ data }) => (
4+
const Pricing = ({ data }) => (
45
<div className="columns">
56
{data.map(price => (
67
<div key={price.plan} className="column">
@@ -24,3 +25,16 @@ export default ({ data }) => (
2425
))}
2526
</div>
2627
)
28+
29+
Pricing.propTypes = {
30+
data: PropTypes.arrayOf(
31+
PropTypes.shape({
32+
plan: PropTypes.string,
33+
price: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
34+
description: PropTypes.string,
35+
items: PropTypes.array,
36+
})
37+
),
38+
}
39+
40+
export default Pricing

src/components/Testimonials.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23

3-
export default ({ testimonials }) => (
4+
const Testimonials = ({ testimonials }) => (
45
<div>
56
{testimonials.map(testimonial => (
67
<article className="message">
@@ -13,3 +14,14 @@ export default ({ testimonials }) => (
1314
))}
1415
</div>
1516
)
17+
18+
Testimonials.propTypes = {
19+
testimonials: PropTypes.arrayOf(
20+
PropTypes.shape({
21+
quote: PropTypes.string,
22+
author: PropTypes.string,
23+
})
24+
),
25+
}
26+
27+
export default Testimonials

src/pages/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import Link from 'gatsby-link'
34

45
export default class IndexPage extends React.Component {
@@ -43,6 +44,14 @@ export default class IndexPage extends React.Component {
4344
}
4445
}
4546

47+
IndexPage.propTypes = {
48+
data: PropTypes.shape({
49+
allMarkdownRemark: PropTypes.shape({
50+
edges: PropTypes.array,
51+
}),
52+
}),
53+
}
54+
4655
export const pageQuery = graphql`
4756
query IndexQuery {
4857
allMarkdownRemark(sort: { order: DESC, fields: [frontmatter___date] }) {

src/templates/about-page.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import Content, { HTMLContent } from '../components/Content'
34

45
export const AboutPageTemplate = ({ title, content, contentComponent }) => {
@@ -22,7 +23,13 @@ export const AboutPageTemplate = ({ title, content, contentComponent }) => {
2223
)
2324
}
2425

25-
export default ({ data }) => {
26+
AboutPageTemplate.propTypes = {
27+
title: PropTypes.string.isRequired,
28+
content: PropTypes.string,
29+
contentComponent: PropTypes.func,
30+
}
31+
32+
const AboutPage = ({ data }) => {
2633
const { markdownRemark: post } = data
2734

2835
return (
@@ -34,6 +41,12 @@ export default ({ data }) => {
3441
)
3542
}
3643

44+
AboutPage.propTypes = {
45+
data: PropTypes.object.isRequired,
46+
}
47+
48+
export default AboutPage
49+
3750
export const aboutPageQuery = graphql`
3851
query AboutPage($id: String!) {
3952
markdownRemark(id: { eq: $id }) {

src/templates/blog-post.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import { kebabCase } from 'lodash'
34
import Helmet from 'react-helmet'
45
import Link from 'gatsby-link'
@@ -44,8 +45,16 @@ export const BlogPostTemplate = ({
4445
)
4546
}
4647

47-
export default props => {
48-
const { markdownRemark: post } = props.data
48+
BlogPostTemplate.propTypes = {
49+
content: PropTypes.string.isRequired,
50+
contentComponent: PropTypes.func,
51+
description: PropTypes.string,
52+
title: PropTypes.string,
53+
helmet: PropTypes.instanceOf(Helmet),
54+
}
55+
56+
const BlogPost = ({ data }) => {
57+
const { markdownRemark: post } = data
4958

5059
return (
5160
<BlogPostTemplate
@@ -59,6 +68,14 @@ export default props => {
5968
)
6069
}
6170

71+
BlogPost.propTypes = {
72+
data: PropTypes.shape({
73+
markdownRemark: PropTypes.object,
74+
}),
75+
}
76+
77+
export default BlogPost
78+
6279
export const pageQuery = graphql`
6380
query BlogPostByID($id: String!) {
6481
markdownRemark(id: { eq: $id }) {

src/templates/product-page.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import Features from '../components/Features'
34
import Testimonials from '../components/Testimonials'
45
import Pricing from '../components/Pricing'
@@ -104,7 +105,31 @@ export const ProductPageTemplate = ({
104105
</section>
105106
)
106107

107-
export default ({ data }) => {
108+
ProductPageTemplate.propTypes = {
109+
image: PropTypes.string,
110+
title: PropTypes.string,
111+
heading: PropTypes.string,
112+
description: PropTypes.string,
113+
intro: PropTypes.shape({
114+
blurbs: PropTypes.array,
115+
}),
116+
main: PropTypes.shape({
117+
heading: PropTypes.string,
118+
description: PropTypes.string,
119+
image1: PropTypes.object,
120+
image2: PropTypes.object,
121+
image3: PropTypes.object,
122+
}),
123+
testimonials: PropTypes.array,
124+
fullImage: PropTypes.string,
125+
pricing: PropTypes.shape({
126+
heading: PropTypes.string,
127+
description: PropTypes.string,
128+
plans: PropTypes.array,
129+
}),
130+
}
131+
132+
const ProductPage = ({ data }) => {
108133
const { frontmatter } = data.markdownRemark
109134

110135
return (
@@ -122,6 +147,16 @@ export default ({ data }) => {
122147
)
123148
}
124149

150+
ProductPage.propTypes = {
151+
data: PropTypes.shape({
152+
markdownRemark: PropTypes.shape({
153+
frontmatter: PropTypes.object,
154+
}),
155+
}),
156+
}
157+
158+
export default ProductPage
159+
125160
export const productPageQuery = graphql`
126161
query ProductPage($id: String!) {
127162
markdownRemark(id: { eq: $id }) {

0 commit comments

Comments
 (0)