Skip to content

Commit

Permalink
[Playground] Created iconValidator util (#3820)
Browse files Browse the repository at this point in the history
  • Loading branch information
anishagg17 authored Jul 30, 2020
1 parent 57b8cae commit 472062b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 46 deletions.
18 changes: 18 additions & 0 deletions src-docs/src/services/playground/iconValidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { iconTypes } from '../../views/icon/icons';
import { mapOptions } from './mapOptions';
import { PropTypes } from 'react-view';

const iconOptions = mapOptions(iconTypes);

export const iconValidator = prop => {
const newProp = {
...prop,
value: undefined,
type: PropTypes.String,
custom: {
...prop.custom,
validator: val => iconOptions[val],
},
};
return newProp;
};
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 @@ -2,3 +2,4 @@ export { default as playgroundCreator } from './playground';
export { default as Knobs } from './knobs';
export { default as propUtilityForPlayground } from './props';
export { mapOptions } from './mapOptions';
export { iconValidator } from './iconValidator';
25 changes: 3 additions & 22 deletions src-docs/src/views/badge/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import {
} from '../../../../src/components/';
import {
propUtilityForPlayground,
mapOptions,
iconValidator,
} from '../../services/playground';
import { iconTypes } from '../icon/icons';
import * as t from '@babel/types';

const iconOptions = mapOptions(iconTypes);

export const badgeConfig = () => {
const docgenInfo = Array.isArray(EuiBadge.__docgenInfo)
? EuiBadge.__docgenInfo[0]
Expand Down Expand Up @@ -70,15 +67,7 @@ export const badgeConfig = () => {
type: PropTypes.String,
};

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

propsToUse.color = {
...propsToUse.color,
Expand Down Expand Up @@ -132,15 +121,7 @@ export const betaBadgeConfig = () => {
type: PropTypes.String,
};

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

return {
config: {
Expand Down
14 changes: 2 additions & 12 deletions src-docs/src/views/button/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@ import { PropTypes } from 'react-view';
import { EuiButton } from '../../../../src/components/';
import {
propUtilityForPlayground,
mapOptions,
iconValidator,
} from '../../services/playground';
import { iconTypes } from '../icon/icons';

export default () => {
const docgenInfo = Array.isArray(EuiButton.__docgenInfo)
? EuiButton.__docgenInfo[0]
: EuiButton.__docgenInfo;
const propsToUse = propUtilityForPlayground(docgenInfo.props);
const options = mapOptions(iconTypes);

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

propsToUse.children = {
value: 'Button',
Expand Down
14 changes: 2 additions & 12 deletions src-docs/src/views/call_out/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@ import { PropTypes } from 'react-view';
import { EuiCallOut, EuiText } from '../../../../src/components/';
import {
propUtilityForPlayground,
mapOptions,
iconValidator,
} from '../../services/playground';
import { iconTypes } from '../icon/icons';

export default () => {
const docgenInfo = Array.isArray(EuiCallOut.__docgenInfo)
? EuiCallOut.__docgenInfo[0]
: EuiCallOut.__docgenInfo;
const propsToUse = propUtilityForPlayground(docgenInfo.props);
const options = mapOptions(iconTypes);

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

propsToUse.title = {
...propsToUse.title,
Expand Down

0 comments on commit 472062b

Please sign in to comment.