Skip to content

Instantly share code, notes, and snippets.

@dschinkel
Last active May 3, 2017 19:17
Show Gist options
  • Save dschinkel/94db9bd80a556ff4d0ed7e1385cfe02a to your computer and use it in GitHub Desktop.
Save dschinkel/94db9bd80a556ff4d0ed7e1385cfe02a to your computer and use it in GitHub Desktop.
A few examples of React components from WeDoTDD.com
// a "dumb/presentational" React Component
import CompanyHeader from './CompanyHeader';
import CompanyProfile from './CompanyProfile';
import InterviewContentMain from './InterviewContentMain';
import Main from '../Main';
import MainLayout from '../MainLayout';
import React, { Component } from 'react';
export default class Interview extends Component{
render(){
const company = this.props.companies;
return (
<Main>
<MainLayout title={title}>
<div>
<div id='ft-interview'>
<div className="panel vertical-space">
<CompanyHeader company={company}/>
<CompanyProfile company={company}/>
<InterviewContentMain company={company}/>
</div>
</div>
</div>
</MainLayout>
</Main>
)
}
}
@dschinkel
Copy link
Author

index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="alternate" type="application/rss+xml" title="We Do TDD - Companies & Teams Practicing Test Driven Development" href="http://feeds.feedburner.com/WeDoTdd-AListOfCompaniesPracticingTestDrivenDevelopment"/>
        <link rel="stylesheet" type="text/css" href="http://fastly.ink.sapo.pt/3.1.10/css/ink.min.css">
        <script type="text/javascript" src="http://fastly.ink.sapo.pt/3.1.10/js/ink-all.min.js"></script>
        <!--[if lt IE 9 ]>
        <link rel="stylesheet" href="ink-ie.min.css" type="text/css">
        <![endif]-->
        <link rel="stylesheet" type="text/css" href="/lib/css/master.css" />
    </head>
    <body>
        <div id="app"></div>
        <script type="text/javascript" src="/scripts/app.bundle.js"></script>
    </body>
</html>

@dschinkel
Copy link
Author

RelatedLinks Component (the Related Links section you see in an interview):

import React, { Component } from 'react';

export default class RelatedLinks extends Component {
    render(){
        const {company} = this.props
        return (
            <div className="all-100 padding-bottom-200">
                { company.interview.relatedLinks &&
                    <div id="ft-relatedLinks">
                        <p id="relatedLinks" className="section-heading bold padding-top-20 font-22">Related Links</p>
                        <div className="all-100 padding-left-30 align-left">
                            <div className="all-100">
                                <Links links={company.interview.relatedLinks}/>
                            </div>
                        </div>
                    </div>
                }
            </div>
        )
    }
}

export class Links extends Component {
    render(){
        const {links} = this.props;
        let formattedLink,
            formattedLinkGroup,
            formattedLinks = [],
            formattedLinkGroups = []

        for (let [i, link] of links.entries()) {
            formattedLink = <li key={i}><a href={link.href} target="_blank"><span className="black small">{link.text}</span></a></li>;
            formattedLinkGroup = <div key={i} className="all-40"><ul className="noStyle line-height-1 margin-0">{formattedLinks}</ul></div>;

            formattedLinks.push(formattedLink);

            if ((++i) % 12 === 0) {
                formattedLinkGroups.push(formattedLinkGroup);
                formattedLinks = [];
            }
        }

        if(formattedLinkGroups.length === 0){
            formattedLinkGroups.push(formattedLinkGroup);
        }

        return(<div className="ft-links column-group">{formattedLinkGroups}</div>)
    }
}

@dschinkel
Copy link
Author

using NGINX

{
  "root": "dist/client/",
  "routes": {
    "/**": "index.html"
  },
  "proxies": {
    "/api/": {
      "origin": "https://wedotdd-service.herokuapp.com"
    }
  }
}

@dschinkel
Copy link
Author

MainLayout component

const DocumentTitle = require('react-document-title');
import React, {Component} from 'react';
import Header from './Header';
import TopNav from './TopNav';


export default class MainLayout extends Component{
    render() {
        return (
            <div className="wrap">
                <div className="ink-grid">
                    <Header />
                    <DocumentTitle title={this.props.title} />
                    <div className='ft-homepage'>
                        <TopNav />
                        {this.props.children}
                    </div>
                </div>
            </div>
        )
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment