Skip to content

Commit

Permalink
Merge pull request #39 from thompsongl/props/page_header
Browse files Browse the repository at this point in the history
props/page_header
  • Loading branch information
cchaos committed Feb 2, 2021
2 parents 09285bf + eb08a9d commit b4df1a7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
1 change: 1 addition & 0 deletions src-docs/src/services/playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { iconValidator } from './iconValidator';
export { createOptionalEnum } from './createOptionalEnum';
export { dummyFunction } from './dummyFunction';
export { simulateFunction } from './simulateFunction';
export { generateAst, generateCustomProps } from './utils';
4 changes: 2 additions & 2 deletions src-docs/src/services/playground/knobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ const Knob = ({
<EuiSwitch
id={name}
label={custom.label || ''}
checked={typeof val !== 'undefined' && val}
checked={typeof val !== 'undefined' && Boolean(val)}
onChange={(e) => {
const value = e.target.checked;

set(value ? value : undefined);
set(value ? custom.value ?? e.target.checked : undefined);
}}
compressed
/>
Expand Down
16 changes: 16 additions & 0 deletions src-docs/src/services/playground/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import template from '@babel/template';

export const generateAst = (value) => {
return template.ast(String(value), { plugins: ['jsx'] }).expression;
};

export const generateCustomProps = (props) => {
return props.reduce((obj, item) => {
return {
...obj,
[item]: {
generate: generateAst,
},
};
}, {});
};
38 changes: 27 additions & 11 deletions src-docs/src/views/page/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@

import React from 'react';
import { PropTypes } from 'react-view';
import { EuiPageHeader, EuiButton, EuiText } from '../../../../src/components/';
import { EuiPageHeader, EuiButton } from '../../../../src/components/';
import {
propUtilityForPlayground,
iconValidator,
simulateFunction,
generateCustomProps,
} from '../../services/playground';

// HELP: Can we get a "simulate" toggle and pass ReactNodes?
const tabs = [
const tabs = `[
{
label: 'Tab 1',
isSelected: true,
},
{
label: 'Tab 2',
},
];
]`;

const rightSideContent = [
const rightSideContent = `[
<EuiButton fill>Button 1</EuiButton>,
<EuiButton>Button 2</EuiButton>,
];
]`;

export default () => {
const docgenInfo = Array.isArray(EuiPageHeader.__docgenInfo)
Expand All @@ -38,16 +39,30 @@ export default () => {
value: 'Page title',
};

propsToUse.leftSideContent = {
...propsToUse.leftSideContent,
type: PropTypes.String,
};

propsToUse.description = {
...propsToUse.description,
value: 'Example of a description.',
type: PropTypes.String,
};

propsToUse.rightSideContent = {
propsToUse.rightSideContent = simulateFunction({
...propsToUse.rightSideContent,
type: PropTypes.Array,
};
custom: {
value: rightSideContent,
},
});

propsToUse.tabs = simulateFunction({
...propsToUse.tabs,
custom: {
value: tabs,
},
});

propsToUse.children = {
type: PropTypes.ReactNode,
Expand All @@ -60,13 +75,14 @@ export default () => {
props: propsToUse,
scope: {
EuiPageHeader,
EuiText,
EuiButton,
},
imports: {
'@elastic/eui': {
named: ['EuiPageHeader', 'EuiText'],
named: ['EuiPageHeader', 'EuiButton'],
},
},
customProps: generateCustomProps(['rightSideContent', 'tabs']),
},
};
};

0 comments on commit b4df1a7

Please sign in to comment.