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

props/page_header #39

Merged
merged 3 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 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']),
},
};
};