Skip to content

Commit

Permalink
Fix: Do not lowercase nested keys of example settings object, pass pr…
Browse files Browse the repository at this point in the history
…ops to Preview component
  • Loading branch information
sapegin committed Aug 19, 2017
1 parent 6b87220 commit 916e173
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 37 deletions.
8 changes: 7 additions & 1 deletion docs/Documenting.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ Styleguidist will look for any `Readme.md` or `ComponentName.md` files in the co
<Button size="large">Push Me</Button>
```

You can disable an editor by passing a `noeditor` modifier:
You can add a custom props to an example wrapper:

```js { "props": { "className": "checks" } }
<Button>I’m transparent!</Button>
```

Or disable an editor by passing a `noeditor` modifier:

```jsx noeditor
<Button>Push Me</Button>
Expand Down
6 changes: 6 additions & 0 deletions examples/basic/src/components/Button/Button.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
vertical-align: middle;
cursor: pointer;
}

.checks {
background-image: linear-gradient(45deg, #f5f5f5 25%, transparent 25%), linear-gradient(-45deg, #f5f5f5 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #f5f5f5 75%), linear-gradient(-45deg, transparent 75%, #f5f5f5 75%);
background-size: 16px 16px;
background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}
8 changes: 7 additions & 1 deletion examples/basic/src/components/Button/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ Fenced code blocks with `js`, `jsx` or `javascript` languages are rendered as a
<Button>Push Me</Button>
```

You can disable an editor by passing a `noeditor` modifier (```` ```js noeditor````):
You can add a custom props to an example wrapper (```` ```js { "props": { "className": "checks" } }````):

```js { "props": { "className": "checks" } }
<Button>I’m transparent!</Button>
```

Or disable an editor by passing a `noeditor` modifier (```` ```js noeditor````):

```jsx noeditor
<Button>Push Me</Button>
Expand Down
1 change: 1 addition & 0 deletions loaders/examples-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function examplesLoader(source) {
const updateExample = config.updateExample
? props => config.updateExample(props, this.resourcePath)
: undefined;

// Load examples
const examples = chunkify(source, updateExample);

Expand Down
7 changes: 0 additions & 7 deletions loaders/utils/__tests__/keysToLowerCaseDeep.spec.js

This file was deleted.

18 changes: 0 additions & 18 deletions loaders/utils/keysToLowerCaseDeep.js

This file was deleted.

4 changes: 2 additions & 2 deletions loaders/utils/parseExample.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const consts = require('../../scripts/consts');
const keysToLowerCaseDeep = require('./keysToLowerCaseDeep');
const lowercaseKeys = require('lowercase-keys');

const splitLangAndModifiers = header => {
const m = (header || '').match(/(\w*)(?: (.*))?/);
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports = function parseExample(content, header, updateExample) {
example = updateExample(example);
}

example.settings = keysToLowerCaseDeep(example.settings);
example.settings = lowercaseKeys(example.settings);

return example;
};
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"listify": "^1.0.0",
"loader-utils": "^1.1.0",
"lodash": "^4.17.4",
"lowercase-keys": "^1.0.0",
"markdown-to-jsx": "^5.4.2",
"minimist": "^1.2.0",
"pretty-format": "^20.0.3",
Expand Down
1 change: 1 addition & 0 deletions src/rsg-components/Playground/Playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default class Playground extends Component {
<PlaygroundRenderer
name={name}
preview={preview}
previewProps={settings.props || {}}
tabButtons={
<Slot
name="exampleTabButtons"
Expand Down
5 changes: 3 additions & 2 deletions src/rsg-components/Playground/Playground.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import Playground from './Playground';
import '../../styles/setupjss';
import slots, { EXAMPLE_TAB_CODE_EDITOR } from '../slots';
import { PlaygroundRenderer } from './PlaygroundRenderer';
import { PlaygroundRenderer, styles } from './PlaygroundRenderer';

const evalInContext = a =>
new Function('require', 'const React = require("react");' + a).bind(null, require); // eslint-disable-line no-new-func
Expand Down Expand Up @@ -122,9 +122,10 @@ it('showcode option in example settings should overwrite style guide config opti
it('renderer should render preview', () => {
const actual = shallow(
<PlaygroundRenderer
classes={{}}
classes={classes(styles)}
name="name"
preview={<div>preview</div>}
previewProps={{ className: 'pizza', title: 'salami' }}
tabButtons={<div>tab buttons</div>}
tabBody={<div>tab body</div>}
toolbar={<div>toolbar</div>}
Expand Down
17 changes: 14 additions & 3 deletions src/rsg-components/Playground/PlaygroundRenderer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import Styled from 'rsg-components/Styled';

const styles = ({ space, color, borderRadius }) => ({
export const styles = ({ space, color, borderRadius }) => ({
root: {
marginBottom: space[4],
},
Expand All @@ -20,10 +21,19 @@ const styles = ({ space, color, borderRadius }) => ({
},
});

export function PlaygroundRenderer({ classes, name, preview, tabButtons, tabBody, toolbar }) {
export function PlaygroundRenderer({
classes,
name,
preview,
previewProps,
tabButtons,
tabBody,
toolbar,
}) {
const { className, ...props } = previewProps;
return (
<div className={classes.root}>
<div className={classes.preview} data-preview={name}>
<div className={cx(classes.preview, className)} {...props} data-preview={name}>
{preview}
</div>
<div className={classes.controls}>
Expand All @@ -45,6 +55,7 @@ PlaygroundRenderer.propTypes = {
classes: PropTypes.object.isRequired,
name: PropTypes.string.isRequired,
preview: PropTypes.node.isRequired,
previewProps: PropTypes.object.isRequired,
tabButtons: PropTypes.node.isRequired,
tabBody: PropTypes.node.isRequired,
toolbar: PropTypes.node.isRequired,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renderer should render preview 1`] = `
<div>
<div
className="root"
>
<div
className="preview pizza"
data-preview="name"
title="salami"
>
<div>
preview
</div>
</div>
<div>
<div
className="controls"
>
<div>
<div>
tab buttons
</div>
</div>
<div>
<div
className="toolbar"
>
<div>
toolbar
</div>
Expand All @@ -38,6 +46,7 @@ exports[`should render component renderer 1`] = `
evalInContext={[Function]}
/>
}
previewProps={Object {}}
tabBody={
<Slot
name="exampleTabs"
Expand Down

0 comments on commit 916e173

Please sign in to comment.