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] EuiBadge, EuiNotificationBadge, EuiBetaBadge #3722

Merged
merged 20 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 3 additions & 1 deletion src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ const createExample = (example, customTitle) => {

let playgroundComponent;
if (playground) {
playgroundComponent = playgroundCreator(playground());
if (Array.isArray(playground)) {
playgroundComponent = playground.map(elm => playgroundCreator(elm()));
} else playgroundComponent = playgroundCreator(playground());
}

const component = () => (
Expand Down
6 changes: 6 additions & 0 deletions src-docs/src/views/badge/badge_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {
EuiBadgeGroup,
EuiCallOut,
} from '../../../../src/components';
import {
badgeConfig,
betaBadgeConfig,
notificationBadgeConfig,
} from './playground';

import Badge from './badge';

Expand Down Expand Up @@ -317,4 +322,5 @@ export const BadgeExample = {
demo: <NotificationBadge />,
},
],
playground: [badgeConfig, betaBadgeConfig, notificationBadgeConfig],
};
128 changes: 128 additions & 0 deletions src-docs/src/views/badge/playground.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { PropTypes } from 'react-view';
import {
EuiBadge,
EuiNotificationBadge,
EuiBetaBadge,
} from '../../../../src/components/';
import {
propUtilityForPlayground,
mapOptions,
} from '../../services/playground';
import { iconTypes } from '../icon/icons';

const iconOptions = mapOptions(iconTypes);

export const badgeConfig = () => {
const docgenInfo = Array.isArray(EuiBadge.__docgenInfo)
? EuiBadge.__docgenInfo[0]
: EuiBadge.__docgenInfo;
const propsToUse = propUtilityForPlayground(docgenInfo.props);

propsToUse.onClick = {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
...propsToUse.onClick,
value: "() => console.log('Clicked')",
};

propsToUse.children = {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
type: PropTypes.String,
value: 'badge content',
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
hidden: true,
};

propsToUse.iconType = {
...propsToUse.iconType,
value: undefined,
type: PropTypes.String,
custom: {
...propsToUse.iconType.custom,
validator: val => iconOptions[val],
},
};
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved

propsToUse.color = {
...propsToUse.color,
value: undefined,
type: PropTypes.String,
};

return {
config: {
componentName: 'EuiBadge',
props: propsToUse,
scope: {
EuiBadge,
},
imports: {
'@elastic/eui': {
named: ['EuiBadge'],
},
},
},
};
};

export const betaBadgeConfig = () => {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
const docgenInfo = Array.isArray(EuiBetaBadge.__docgenInfo)
? EuiBetaBadge.__docgenInfo[0]
: EuiBetaBadge.__docgenInfo;
const propsToUse = propUtilityForPlayground(docgenInfo.props);

propsToUse.label = {
...propsToUse.label,
type: PropTypes.String,
value: 'content',
};

propsToUse.iconType = {
...propsToUse.iconType,
value: undefined,
type: PropTypes.String,
custom: {
...propsToUse.iconType.custom,
validator: val => iconOptions[val],
},
};

return {
config: {
componentName: 'EuiBetaBadge',
props: propsToUse,
scope: {
EuiBetaBadge,
},
imports: {
'@elastic/eui': {
named: ['EuiBetaBadge'],
},
},
},
};
};

export const notificationBadgeConfig = () => {
const docgenInfo = Array.isArray(EuiNotificationBadge.__docgenInfo)
? EuiNotificationBadge.__docgenInfo[0]
: EuiNotificationBadge.__docgenInfo;
const propsToUse = propUtilityForPlayground(docgenInfo.props);

propsToUse.children = {
type: PropTypes.String,
value: 'badge content',
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
hidden: true,
};

return {
config: {
componentName: 'EuiNotificationBadge',
props: propsToUse,
scope: {
EuiNotificationBadge,
},
imports: {
'@elastic/eui': {
named: ['EuiNotificationBadge'],
},
},
},
};
};