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] Created iconValidator util #3820

Merged
merged 1 commit into from
Jul 30, 2020
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
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