Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information...
markdalgleish committed Oct 25, 2018
0 parents commit 22004af324baf6d3a9d0a2515f836f0d8dab35ed
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.snap]
trim_trailing_whitespace = false
@@ -0,0 +1,6 @@
node_modules/
package-lock.json
*.log
.DS_Store
.vscode/
.idea/
1 .npmrc
@@ -0,0 +1 @@
package-lock=false
1 .nvmrc
@@ -0,0 +1 @@
lts/*
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
21 LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 SEEK

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
113 README.md
@@ -0,0 +1,113 @@
# Playroom

Simultaneously design across a variety of themes and screen sizes, powered by JSX and your own component library.

Playroom allows you to create a zero-install code-oriented design environment, built into a standalone HTML + JS bundle which can be deployed alongside your existing design system documentation.

- Iterate on your designs within the final medium, not an illustation tool.
- Create quick mock-ups and interactive prototypes with real code.
- Exercise and evaluate the flexibility of your design system.
- Share your work with others by simply copying the URL.

## Setup

```bash
$ npm install --save-dev playroom
```

Add the following scripts to your `package.json`:

```json
{
"scripts": {
"playroom:start": "playroom start",
"playroom:build": "playroom build"
}
}
```

Add a `playroom.config.js` file to the root of your project:

```js
module.exports = {
title: 'Playroom',
outputPath: './dist/playroom',
components: './src/components',
themes: './src/themes',
frameComponent: './playroom/FrameComponent.js',
widths: [320, 375, 768, 1024],
exampleCode: `
<Button>
Hello World!
</Button>
`,
webpackConfig: () => ({
// Custom webpack config goes here...
})
};
```

Your `components` and `themes` files are expected to export a single object or a series of named exports. For example, your components file might look like this:

```js
module.exports = {
Text: require('./Text/Text'),
Button: require('./Button/Button'),
// etc...
};
```

When providing themes, your themes file might look something like this:

```js
module.exports = {
themeA: require('./themeA'),
themeB: require('./themeB'),
// etc...
};
```

If your components need to be nested within custom provider components, you can provide a custom React component file via the `frameComponent` option, which is a path to a file that might look something like this:

```js
import React from 'react';
import ThemeProvider from '../path/to/your/ThemeProvider';
export default ({ theme, children }) => (
<ThemeProvider theme={theme}>
{children}
</ThemeProvider>
);
```

If you're using a CSS-in-JS library that generates styles dynamically, you might need to configure it to insert them into the iframe. For example, when using [styled-components](https://www.styled-components.com):

```js
import React from 'react';
import { StyleSheetManager } from 'styled-components';
import ThemeProvider from '../path/to/ThemeProvider';
export default ({ theme, children, frameWindow }) => (
<StyleSheetManager target={frameWindow.document.head}>
<ThemeProvider theme={theme}>
{children}
</ThemeProvider>
</StyleSheetManager>
);
```

Now that your project is configured, you can start a local development server:

```bash
$ npm run playroom:start
```

To build your assets for production:

```bash
$ npm run playroom:build
```

## License

MIT.
@@ -0,0 +1,75 @@
#!/usr/bin/env node
const path = require('path');
const commandLineArgs = require('command-line-args');
const commandLineUsage = require('command-line-usage');
const webpack = require('webpack');
const findUp = require('find-up');
const lib = require('../lib');

const showUsage = () => {
console.log(
commandLineUsage([
{
header: 'playroom',
content:
'Code-oriented component design tool.\n\nUsage: playroom <command> [options...]'
},
{
header: 'Commands',
content: [
{ name: 'start', summary: 'Start a local playroom.' },
{
name: 'build',
summary: 'Build a playroom for production.'
},
{ name: 'help', summary: 'Show this usage guide.' }
]
},
{
header: 'Options',
optionList: [
{
name: 'config',
typeLabel: '{underline path}',
description: 'Path to a config file.'
}
]
}
])
);
};

(async () => {
const args = commandLineArgs([
{ name: 'command', defaultOption: true, defaultValue: 'start' },
{ name: 'config' },
{ name: 'help', type: Boolean }
]);

if (args.command === 'help' || args.help) {
return showUsage();
}

const cwd = process.cwd();
const configPath = args.config
? path.resolve(cwd, args.config)
: await findUp('playroom.config.js', { cwd });

const config = require(configPath);

const playroom = lib({
cwd: path.dirname(configPath),
...config
});

if (playroom.hasOwnProperty(args.command)) {
playroom[args.command](err => {
if (err) {
process.exit(1);
}
});
} else {
showUsage();
process.exit(1);
}
})();
@@ -0,0 +1,14 @@
module.exports = {
title: 'Material-UI',
outputPath: './dist/playroom',
components: '@material-ui/core',
frameComponent: './playroom/FrameComponent.js',
widths: [320, 375, 768, 1024],
exampleCode: `
{/* For some reason, the styles only work in the first iframe. */}
{/* We'll need to look into this further... */}
<Badge badgeContent="2" color="primary">
<Button color="primary">Hello</Button>
</Badge>
`
};
@@ -0,0 +1,28 @@
import React from 'react';
import { create } from 'jss';
import { createGenerateClassName, jssPreset } from '@material-ui/core/styles';
import JssProvider from 'react-jss/lib/JssProvider';

export default class FrameComponent extends React.Component {
constructor(props) {
super(props);

console.log(props.frameWindow.document.head);

this.generateClassName = createGenerateClassName();
this.jss = create({
...jssPreset(),
insertionPoint: props.frameWindow.document.head
});
}

render() {
const { children } = this.props;

return (
<JssProvider jss={this.jss} generateClassName={this.generateClassName}>
{children}
</JssProvider>
);
}
}
@@ -0,0 +1,13 @@
module.exports = {
title: 'Reakit',
outputPath: './dist/playroom',
components: 'reakit',
frameComponent: './playroom/FrameComponent.js',
widths: [320, 375, 768, 1024],
exampleCode: `
<Group vertical>
<Button maxWidth="20vmin">Up</Button>
<Button maxWidth="20vmin">Down</Button>
</Group>
`
};
@@ -0,0 +1,15 @@
import React from 'react';
import { StyleSheetManager } from 'styled-components';
import { Provider } from 'reakit';
import theme from 'reakit-theme-default';

export default ({ children, frameWindow }) => (
<Provider theme={theme}>
<StyleSheetManager target={frameWindow.document.head}>
<React.Fragment>
<style>{'* { font-family: Helvetica, Arial, sans-serif; }'}</style>
{children}
</React.Fragment>
</StyleSheetManager>
</Provider>
);
@@ -0,0 +1,12 @@
const webpack = require('webpack');
const makeWebpackConfig = require('./makeWebpackConfig');

module.exports = (config, callback) => {
const webpackConfig = makeWebpackConfig(config, { production: true });

webpack(webpackConfig, (...args) => {
if (typeof callback === 'function') {
callback(...args);
}
});
};
@@ -0,0 +1,3 @@
import React, { Fragment } from 'react';

export default ({ children }) => <Fragment>{children}</Fragment>;
@@ -0,0 +1 @@
export const __PLAYROOM__NO_THEME__ = null;
@@ -0,0 +1,9 @@
const start = require('./start');
const build = require('./build');

module.exports = config => {
return {
start: callback => start(config, callback),
build: callback => build(config, callback)
};
};

0 comments on commit 22004af

Please sign in to comment.
You can’t perform that action at this time.