Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playground System for Live Documentation #3529

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3a963a1
Setting up basic playground, Routing, Button Example
anishagg17 May 29, 2020
02193da
created custom knobs
anishagg17 May 29, 2020
3eb6748
added routing
anishagg17 May 30, 2020
afc8b37
removed notFound from nav
anishagg17 May 30, 2020
601b8b2
sideNav improved
anishagg17 May 30, 2020
9f16ad0
removed circular dep
anishagg17 May 30, 2020
bae76a9
removed redundant code
anishagg17 May 30, 2020
f462a31
Merge branch 'master' of https://github.com/elastic/eui into playground
anishagg17 May 31, 2020
3b0a24f
hooks within button added
anishagg17 May 31, 2020
b583bcf
removed redundant code
anishagg17 May 31, 2020
39e1947
added 'fs' to webpack.config
anishagg17 Jun 1, 2020
ee8ea52
Props utility for string , enum, bool
anishagg17 Jun 1, 2020
2357d95
added Select as knob
anishagg17 Jun 1, 2020
121ae29
made code reusable
anishagg17 Jun 1, 2020
55ced89
Accordino example added
anishagg17 Jun 1, 2020
f3baccc
Merge branch 'master' into playground
anishagg17 Jun 2, 2020
5c3945b
updated according to router
anishagg17 Jun 2, 2020
8241cf2
added links in docs to respective playgrounds
anishagg17 Jun 2, 2020
b710ebf
added Beacon playground
anishagg17 Jun 2, 2020
30fa2eb
avatar playground
anishagg17 Jun 2, 2020
4a716ed
callout Playground
anishagg17 Jun 2, 2020
993e22d
default value is selected by default, used Number Field for number, h…
anishagg17 Jun 2, 2020
47c1e55
health playground
anishagg17 Jun 3, 2020
490dee6
stat playground
anishagg17 Jun 3, 2020
92f800a
title playground
anishagg17 Jun 3, 2020
4dc0aa2
added Labels to knobs
anishagg17 Jun 3, 2020
d836607
resolved merge conflicts
anishagg17 Jun 6, 2020
f75784c
updated mode to JSX
anishagg17 Jun 8, 2020
dd49609
Update props.js
anishagg17 Jun 11, 2020
02a7f7e
Merge branch 'master' of https://github.com/elastic/eui into playground
anishagg17 Jun 12, 2020
c0986d2
used name with id to fix props with same label
anishagg17 Jun 13, 2020
cd35da5
use ${key}__${name} only for radio
anishagg17 Jun 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"react-focus-lock": "^1.17.7",
"react-input-autosize": "^2.2.2",
"react-is": "~16.3.0",
"react-view": "^2.3.2",
"react-virtualized": "^9.21.2",
"resize-observer-polyfill": "^1.5.0",
"tabbable": "^3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src-docs/src/components/guide_page/guide_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const GuidePage = ({
title,
intro,
componentLinkTo,
componentLinkToText,
isBeta,
}) => {
const betaBadge = isBeta ? (
Expand All @@ -42,7 +43,7 @@ export const GuidePage = ({
{componentLinkTo && (
<EuiFlexItem grow={false}>
<EuiButton href={getRouterLinkProps(componentLinkTo).href}>
View component code
{componentLinkToText || 'View component code'}
</EuiButton>
</EuiFlexItem>
)}
Expand Down
26 changes: 20 additions & 6 deletions src-docs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import { AppContainer } from './views/app_container';
import { HomeView } from './views/home/home_view';
import { NotFoundView } from './views/not_found/not_found_view';
import { registerTheme } from './services';
import { PlaygroundView } from './views/playground_view';

import Routes from './routes';
import { childRoutes as playgrounds } from './playground_routes';

import themeLight from './theme_light.scss';
import themeDark from './theme_dark.scss';
import themeAmsterdamLight from './theme_amsterdam_light.scss';
Expand All @@ -31,11 +34,6 @@ registerTheme('amsterdam-dark', [themeAmsterdamDark]);
const store = configureStore();

const childRoutes = [].concat(Routes.getAppRoutes());
childRoutes.push({
path: '*',
component: NotFoundView,
name: 'Page Not Found',
});

const routes = [
{
Expand All @@ -62,8 +60,24 @@ ReactDOM.render(
);
return null;
})}
{playgrounds.map(({ name, path, component }, i) => {
if (component)
return (
<Route key={`play__${i}`} exact path={`/playgrounds/${path}`}>
<PlaygroundView currentRoute={{ name, path }}>
{createElement(component, {})}
</PlaygroundView>
</Route>
);
return null;
})}
<Route key="Page Not Found" exact path={'*'}>
<AppContainer currentRoute={{ name: 'Page Not Found', path: '*' }}>
{createElement(NotFoundView, {})}
</AppContainer>
</Route>
</Switch>
</Router>{' '}
</Router>
</ThemeProvider>
</Provider>,
document.getElementById('guide')
Expand Down
56 changes: 56 additions & 0 deletions src-docs/src/playground.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';

import {
useView,
Compiler,
Error,
ActionButtons,
Placeholder,
} from 'react-view';
import 'brace/mode/jsx';
import 'brace/theme/github';

import { EuiCodeEditor, EuiSpacer } from '../../src/components';
import Knobs from './services/playground/knobs';

export default config => {
if (config.props) {
if (config.props.className) config.props.className.hidden = true;
if (config.props['data-test-subj'])
config.props['data-test-subj'].hidden = true;
if (config.props['aria-label']) config.props['aria-label'].hidden = true;
}

const params = useView(config);
return (
<React.Fragment>
<Compiler
{...params.compilerProps}
minHeight={62}
placeholder={Placeholder}
/>
<Error msg={params.errorProps.msg} isPopup />
<Knobs {...params.knobProps} />
<EuiSpacer />
<EuiCodeEditor
mode="jsx"
theme="github"
width="100%"
value={params.editorProps.code}
onChange={params.editorProps.onChange}
setOptions={{
fontSize: '14px',
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
}}
onBlur={() => {
console.log('blur');
}} // eslint-disable-line no-console
aria-label="Code Editor"
/>
<Error {...params.errorProps} />
<ActionButtons {...params.actions} />
</React.Fragment>
);
};
64 changes: 64 additions & 0 deletions src-docs/src/playground_routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import playground from './playground';
import buttonConfig from './views/button/playground';
import accordionConfig from './views/accordion/playground';
import avatarConfig from './views/avatar/playground';
import beaconConfig from './views/beacon/playground';
import calloutConfig from './views/call_out/playground';
import healthConfig from './views/health/playground';
import statConfig from './views/stat/playground';
import titleConfig from './views/title/playground';
import imageConfig from './views/image/playground';

export const childRoutes = [
{
path: 'accordion',
component: () => playground(accordionConfig()),
name: 'EuiAccordion',
},
{
path: 'avatar',
component: () => playground(avatarConfig()),
name: 'EuiAvatar',
},
{
path: 'beacon',
component: () => playground(beaconConfig()),
name: 'EuiBeacon',
},
{
path: 'button',
component: () => playground(buttonConfig()),
name: 'EuiButton',
},
{
path: 'callout',
component: () => playground(calloutConfig()),
name: 'EuiCallOut',
},
{
path: 'image',
component: () => playground(imageConfig()),
name: 'EuiImage',
},
{
path: 'health',
component: () => playground(healthConfig()),
name: 'EuiHealth',
},
{
path: 'stat',
component: () => playground(statConfig()),
name: 'EuiStat',
},
{
path: 'title',
component: () => playground(titleConfig()),
name: 'EuiTitle',
},
{
path: '*',
component: () => <div>Not Found</div>,
name: 'Page Not Found',
},
];
17 changes: 15 additions & 2 deletions src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,15 @@ const createExample = (example, customTitle) => {
);
}

const { title, intro, sections, beta, isNew } = example;
const {
title,
intro,
sections,
beta,
isNew,
componentLinkTo,
componentLinkToText,
} = example;
sections.forEach(section => {
section.id = slugify(section.title || title);
});
Expand All @@ -263,7 +271,12 @@ const createExample = (example, customTitle) => {

const component = () => (
<EuiErrorBoundary>
<GuidePage title={title} intro={intro} isBeta={beta}>
<GuidePage
title={title}
intro={intro}
isBeta={beta}
componentLinkToText={componentLinkToText}
componentLinkTo={componentLinkTo}>
{renderedSections}
</GuidePage>
</EuiErrorBoundary>
Expand Down
Loading