diff --git a/.eslintignore b/.eslintignore
index 2db218e1..f01dc4e7 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1,3 +1,4 @@
scripts/*
bower_components/*
generator-bulbs-elements
+examples/*
diff --git a/examples/component.js b/examples/component.js
index fec9a925..9746488e 100644
--- a/examples/component.js
+++ b/examples/component.js
@@ -1,24 +1,279 @@
-/* eslint react/no-unknown-property: "off" */
-/* eslint-disable react/prop-types, react/no-danger */
-
import React from 'react';
+import { browserHistory } from 'react-router';
import examples from './element-examples';
-class Component extends React.Component {
+const DEVICES = {
+ desktop: {
+ width: '1000px',
+ },
+ tablet: {
+ width: '600px',
+ },
+ mobile: {
+ width: '320px',
+ },
+};
+
+function Checkerboard () {
+ let gridSize = 8;
+ let gridColor = '#fafafa';
+ return (
+
+ );
+}
+
+class ExampleViewport extends React.Component {
+ constructor (props) {
+ super(props);
+ this.state = {
+ scale: 1,
+ workspace: 1,
+ };
+ }
+
+ setDevice (device) {
+ let segments = [
+ 'example',
+ this.props.params.element,
+ this.props.params.example,
+ device,
+ ];
+
+ console.log('/' + segments.join('/'), {});
+ browserHistory.push('/' + segments.join('/'), {});
+ }
+
+ setScale(event) {
+ this.setState({
+ scale: event.target.value,
+ });
+ }
+
+ setWorkspace(event) {
+ this.setState({
+ workspace: event.target.value,
+ });
+ }
+
+ render () {
+ return (
+
+
+
+
+
+ {
+ this.props.params.device.split(',').map((device) => {
+ return (
+
+ )
+ })
+ }
+
+
+
+ );
+ }
+}
+
+export class RenderComponent extends React.Component {
renderExample () {
- let example = examples.find((exmpl) => {
- return exmpl.element === this.props.params.element;
+ let example = examples.find((anExample) => {
+ return anExample.element === this.props.params.element;
});
return {
__html: example.examples[this.props.params.example].render(),
};
}
+ render () {
+ try {
+ return ;
+ }
+ catch (error) {
+ let knownError;
+ switch (error.message) {
+ case "Cannot read property 'render' of undefined":
+ knownError = "The example for this url does not exist."
+ break;
+ }
+ return (
+
+
+
+ Failed to render example at:
+
+
+ { location.href }
+
+
+
+ {knownError}
+
+
+
+ {
+ error.stack.split('\n').map((line) => {
+ return (
+
+ {line}
+
+ );
+ })
+ }
+
+
+ );
+ }
+ }
+}
+
+export class Component extends React.Component {
+ buildComponentPath () {
+ return '/' + [
+ 'render-example',
+ this.props.params.element,
+ this.props.params.example,
+ ].join('/');
+ }
+
render () {
- return (
-
- );
+ return (
+
+
+ );
}
}
-
-export default Component;
diff --git a/examples/examples.js b/examples/examples.js
index b017f103..5643ff81 100644
--- a/examples/examples.js
+++ b/examples/examples.js
@@ -1,5 +1,8 @@
/* eslint-disable no-unused-vars */
-let context = require.context('../elements', true, /^\.\/[^\/]+\/.+\.js$/);
+// This regex matches .js files
+// it excludes *.test.js files, if we parse test files webpack tries to load
+// enzyme, which breaks the environment.
+let context = require.context('../elements', true, /^\.\/[^\/]+\/[^.]+\.js$/);
context.keys().forEach((key) => {
let [_x, dir, file] = key.match(/\.\/(.+)\/(.+).js/) || [];// eslint-disable-line
if (dir === file) {
diff --git a/examples/index.html b/examples/index.html
index 77164877..a5c07bca 100644
--- a/examples/index.html
+++ b/examples/index.html
@@ -1,6 +1,9 @@
+
Bulbs Elements Examples
diff --git a/examples/index.js b/examples/index.js
index d6741db0..7a3ead05 100644
--- a/examples/index.js
+++ b/examples/index.js
@@ -1,8 +1,7 @@
-import { React } from 'react';
+import React from 'react';
import { Link } from 'react-router';
import examples from './element-examples';
import inflection from 'inflection';
-window.ga = function(){};
export default class Index extends React.Component {
render () {
@@ -17,29 +16,25 @@ export default class Index extends React.Component {
{
examples.map((group, index) => {
- return (
- -
-
- {`<${group.element}>`}
-
-
- {
- Object.keys(group.examples).map((name) => {
- return (
- -
-
- {group.examples[name].title}
-
-
- );
- })
- }
-
-
- );
+ return -
+
+ {`<${group.element}>`}
+
+
+ {
+ Object.keys(group.examples).map((name) => {
+ return -
+
+ {group.examples[name].title}
+
+
+ })
+ }
+
+
})
}
@@ -51,3 +46,4 @@ export default class Index extends React.Component {
);
}
}
+
diff --git a/examples/routes.js b/examples/routes.js
index 089654c5..66710620 100644
--- a/examples/routes.js
+++ b/examples/routes.js
@@ -1,15 +1,26 @@
import React from 'react';
-import { Router, Route } from 'react-router';
-import createBrowserHistory from 'history/lib/createBrowserHistory';
-let browserHistory = createBrowserHistory();
+import {
+ Router,
+ Route,
+ browserHistory,
+} from 'react-router';
import Index from './index';
-import Component from './component';
+import {
+ Component,
+ RenderComponent,
+} from './component';
+
+function Empty () {
+ return Choose an Example
;
+}
const Routes = (
+
-
+
+
);
diff --git a/examples/style.scss b/examples/style.scss
index 90e9323a..4b096684 100644
--- a/examples/style.scss
+++ b/examples/style.scss
@@ -16,11 +16,19 @@ body, html, #mount {
display: flex;
}
+[data-reactroot] {
+ width: 100%;
+}
+
.examples-index {
display: flex;
flex-grow: 1;
}
+iframe {
+ width: 100%;
+}
+
.examples-index-list {
min-width: 200px;
font-family: 'Slabo 27px', serif;
@@ -35,6 +43,7 @@ body, html, #mount {
.examples-index-pane {
overflow: auto;
flex-grow: 1;
+ display: flex;
}
.examples-example-group {