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

[WIP] Major API changes #179

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
127 changes: 0 additions & 127 deletions packages/pretty-proptypes/src/HybridLayout/PropEntry.js

This file was deleted.

97 changes: 0 additions & 97 deletions packages/pretty-proptypes/src/HybridLayout/index.js

This file was deleted.

91 changes: 91 additions & 0 deletions packages/pretty-proptypes/src/PrettyProps/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// @flow
import React, { ComponentType, ReactNode, FunctionComponent } from 'react';

import { CommonProps } from '../types';

import getPropTypes from '../getPropTypes';
import { renderProp, extract } from '../PropType';

import { type RawProps } from '../types';

import DefaultLayout from '../layouts/DefaultLayout';

type Components = {};

type LayoutProps = {
components: Components
};

type Obj = {
kind: 'object',
members: Array<any>
};

type Gen = {
kind: 'generic',
value: any
};

type Inter = {
kind: 'intersection',
types: Array<Obj | Gen>
};

type DynamicPropsProps = {
components?: Components,
heading?: string,
shouldCollapseProps?: boolean,
overrides?: {
[key: string]: ComponentType<CommonProps>
},
props?: {
component?: Obj | Inter
},
component?: ComponentType<any>
};

// TODO: figure out a better name
export type IPrettyProps = {
Layout: LayoutProps => ReactNode,
props?: RawProps,
component?: ComponentType<any>
};

const getProps = (props: RawProps) => {
if (props && props.component) {
return getPropTypes(props.component);
}
return null;
};

const PrettyProps: FunctionComponent<IPrettyProps> = ({
layout: Layout = DefaultLayout,
props,
component
}) => {
let propTypes;

if (component) {
/* $FlowFixMe the component prop is typed as a component because
that's what people pass to Props and the ___types property shouldn't
exist in the components types so we're just going to ignore this error */
if (component.___types) {
propTypes = getProps({ type: 'program', component: component.___types });
} else {
/* eslint-disable-next-line no-console */
console.error(
'A component was passed to <Props> but it does not have types attached.\n' +
'babel-plugin-extract-react-types may not be correctly installed.\n' +
'<Props> will fallback to the props prop to display types.'
);
}
}

propTypes = propTypes || getProps(props);

if (!propTypes) return null;

return propTypes.map(renderProp(Layout));
};

export default PrettyProps;
42 changes: 0 additions & 42 deletions packages/pretty-proptypes/src/Prop/index.js

This file was deleted.

Loading