From bea531e9b331d8f6f4a85ed3a046fe10f9198466 Mon Sep 17 00:00:00 2001
From: Levi Thomason
Date: Thu, 12 Jan 2017 19:07:35 -0800
Subject: [PATCH 1/7] feat(typings): add closeOnBlur and openOnFocus (#1151)
* feat(typings): add closeOnBlur and openOnFocus
* refactor(Dropdown): sort prop types
---
src/modules/Dropdown/Dropdown.js | 12 +++---
src/modules/Dropdown/index.d.ts | 71 +++++++++++++++++---------------
2 files changed, 44 insertions(+), 39 deletions(-)
diff --git a/src/modules/Dropdown/Dropdown.js b/src/modules/Dropdown/Dropdown.js
index 3bed4274d0..e1517f154f 100644
--- a/src/modules/Dropdown/Dropdown.js
+++ b/src/modules/Dropdown/Dropdown.js
@@ -81,6 +81,9 @@ export default class Dropdown extends Component {
/** Additional classes. */
className: PropTypes.string,
+ /** Whether or not the menu should close when the dropdown is blurred. */
+ closeOnBlur: PropTypes.bool,
+
/** A compact dropdown has no minimum width. */
compact: PropTypes.bool,
@@ -230,6 +233,9 @@ export default class Dropdown extends Component {
/** Controls whether or not the dropdown menu is displayed. */
open: PropTypes.bool,
+ /** Whether or not the menu should open when the dropdown is focused. */
+ openOnFocus: PropTypes.bool,
+
/** Array of Dropdown.Item props e.g. `{ text: '', value: '' }` */
options: customPropTypes.every([
customPropTypes.disallow(['children']),
@@ -296,12 +302,6 @@ export default class Dropdown extends Component {
/** The text displayed in the dropdown, usually for the active item. */
text: PropTypes.string,
- /** Whether or not the menu should open when the dropdown is focused. */
- openOnFocus: PropTypes.bool,
-
- /** Whether or not the menu should close when the dropdown is blurred. */
- closeOnBlur: PropTypes.bool,
-
/** Custom element to trigger the menu to become visible. Takes place of 'text'. */
trigger: customPropTypes.every([
customPropTypes.disallow(['selection', 'text']),
diff --git a/src/modules/Dropdown/index.d.ts b/src/modules/Dropdown/index.d.ts
index bcd1249447..14606368eb 100644
--- a/src/modules/Dropdown/index.d.ts
+++ b/src/modules/Dropdown/index.d.ts
@@ -1,23 +1,22 @@
-import { ReactFocusEvents, ReactFormEvents, ReactMouseEvents } from '../..';
+import {ReactFocusEvents, ReactFormEvents, ReactMouseEvents} from '../..';
import * as React from 'react';
export type DropdownPropPointing = 'left' | 'right' | 'top' | 'top left' | 'top right' | 'bottom' | 'bottom left' | 'bottom right'
export type DropdownPropAdditionPosition = 'top' | 'bottom';
export interface DropdownProps extends ReactMouseEvents, ReactFocusEvents, ReactFormEvents {
-
/** Label prefixed to an option added by a user. */
additionLabel?: string;
-
+
/** Position of the `Add: ...` option in the dropdown list ('top' or 'bottom'). */
additionPosition?: DropdownPropAdditionPosition;
-
+
/**
* Allow user additions to the list of options (boolean).
* Requires the use of `selection`, `options` and `search`.
*/
allowAdditions?: any;
-
+
/** An element type to render as (string or function). */
as?: any;
@@ -33,20 +32,23 @@ export interface DropdownProps extends ReactMouseEvents, ReactFocus
/** Additional classes. */
className?: string;
+ /** Whether or not the menu should close when the dropdown is blurred. */
+ closeOnBlur?: boolean,
+
/** A compact dropdown has no minimum width. */
compact?: boolean;
/** Initial value of open. */
defaultOpen?: boolean;
-
+
/** Currently selected label in multi-select. */
- defaultSelectedLabel?:any;
+ defaultSelectedLabel?: any;
/** Initial value or value array if multiple. */
defaultValue?: string|number|Array|Array;
-
+
/** A disabled dropdown menu or item does not allow user interaction. */
- disabled?:boolean;
+ disabled?: boolean;
/** An errored dropdown can alert a user to a problem. */
error?: boolean;
@@ -59,7 +61,7 @@ export interface DropdownProps extends ReactMouseEvents, ReactFocus
/** A dropdown menu can contain a header. */
header?: React.ReactNode;
-
+
/** Shorthand for Icon. */
icon?: any;
@@ -76,7 +78,7 @@ export interface DropdownProps extends ReactMouseEvents, ReactFocus
multiple?: boolean;
/** Name of the hidden input which holds the value. */
- name?:string;
+ name?: string;
/** Message to display when there are no results. */
noResultsMessage?: string;
@@ -96,25 +98,28 @@ export interface DropdownProps extends ReactMouseEvents, ReactFocus
* @param {string} value - Current value of search input.
*/
onSearchChange?: React.FormEventHandler;
-
+
/** Controls whether or not the dropdown menu is displayed. */
open?: boolean;
+ /** Whether or not the menu should open when the dropdown is focused. */
+ openOnFocus?: boolean,
+
/** Array of Dropdown.Item props e.g. `{ text: '', value: '' }` */
options?: Array;
-
+
/** Placeholder text. */
placeholder?: string;
/** A dropdown can be formatted so that its menu is pointing. */
pointing?: boolean | DropdownPropPointing;
-
+
/**
* A function that takes (data, index, defaultLabelProps) and returns
* shorthand for Label .
*/
- renderLabel?:any;
-
+ renderLabel?: any;
+
/** A dropdown can have its menu scroll. */
scrolling?: boolean;
@@ -122,8 +127,8 @@ export interface DropdownProps extends ReactMouseEvents, ReactFocus
* A selection dropdown can allow a user to search through a large list of choices.
* Pass a function here to replace the default search.
*/
- search?: ((filteredOptions:any, searchQuery:any) => void) | boolean; // TODO -add search function;
-
+ search?: ((filteredOptions: any, searchQuery: any) => void) | boolean; // TODO -add search function;
+
/** Define whether the highlighted item should be selected on blur. */
selectOnBlur?: boolean;
@@ -134,7 +139,7 @@ export interface DropdownProps extends ReactMouseEvents, ReactFocus
simple?: boolean;
/** A dropdown can receive focus. */
- tabIndex?:string;
+ tabIndex?: string;
/** The text displayed in the dropdown, usually for the active item. */
text?: string|React.ReactNode;
@@ -156,20 +161,20 @@ interface DropdownClass extends React.ComponentClass {
export const Dropdown: DropdownClass;
interface DropdownDividerProps {
-
+
/** An element type to render as (string or function). */
- as?: any;
+ as?: any;
/** Additional classes. */
- className?:string;
+ className?: string;
}
export const DropdownDivider: React.ComponentClass;
interface DropdownHeaderProps {
-
+
/** An element type to render as (string or function). */
- as?: any;
+ as?: any;
/** Primary content. */
children?: React.ReactNode;
@@ -187,12 +192,12 @@ interface DropdownHeaderProps {
export const DropdownHeader: React.ComponentClass;
interface DropdownItemProps extends ReactMouseEvents, ReactFocusEvents, ReactFormEvents {
-
+
/** Style as the currently chosen item. */
active?: boolean;
-
+
/** An element type to render as (string or function). */
- as?: any;
+ as?: any;
/** Primary content. */
children?: React.ReactNode;
@@ -207,16 +212,16 @@ interface DropdownItemProps extends ReactMouseEvents, ReactFocusEve
disabled?: boolean;
/** Shorthand for Flag. */
- flag?:any;
+ flag?: any;
/** Shorthand for Icon. */
icon?: any;
/** Shorthand for Image. */
- image?:any;
+ image?: any;
/** Shorthand for Label. */
- label?:any;
+ label?: any;
/**
* The item currently selected by keyboard shortcut.
@@ -234,9 +239,9 @@ interface DropdownItemProps extends ReactMouseEvents, ReactFocusEve
export const DropdownItem: React.ComponentClass;
interface DropdownMenuProps {
-
+
/** An element type to render as (string or function). */
- as?: any;
+ as?: any;
/** Primary content. */
children?: React.ReactNode;
@@ -245,7 +250,7 @@ interface DropdownMenuProps {
className?: string;
/** A dropdown menu can scroll. */
- scrolling?:boolean;
+ scrolling?: boolean;
}
export const DropdownMenu: React.ComponentClass;
From ab48267f7f8f3198ad66d57790f48a3736590640 Mon Sep 17 00:00:00 2001
From: Alexander Fedyashov
Date: Fri, 13 Jan 2017 06:59:05 +0200
Subject: [PATCH 2/7] perf(props): Remove propTypes from production build
(#731)
* perf(props): Remove propTypes from production build
perf(props): Remove propTypes from production build
* perf(package): add babel react optimization plugins
* wip(Rail): remove props
feat(Plugin): remove props
fix(Plugin): remove plugin code
fix(Plugin): remove plugin code
fix(Plugin): remove plugin code
fix(Plugin): remove plugin code
* revert(package): remove `babel-register`
* chore(package): add plugin
* chore(package): add plugin
* feat(package): Add plugin, update tests, cleanups
* fix(ComponentProps): update component (remove enums functionality), fix lint issues
* fix(common): fix review comments
---
.babelrc | 10 ++-
.github/CONTRIBUTING.md | 24 ++++--
.../Components/ComponentDoc/ComponentProps.js | 82 ++-----------------
package.json | 5 ++
src/elements/Rail/Rail.js | 11 +--
src/lib/getUnhandledProps.js | 31 +------
test/specs/commonTests.js | 36 ++++----
test/specs/lib/getUnhandledProps-test.js | 41 +++-------
8 files changed, 74 insertions(+), 166 deletions(-)
diff --git a/.babelrc b/.babelrc
index f408783fde..2fc567d3e3 100644
--- a/.babelrc
+++ b/.babelrc
@@ -5,7 +5,15 @@
"stage-1"
],
"plugins": [
- "lodash"
+ "lodash",
+ "transform-react-handled-props",
+ ["transform-react-remove-prop-types", {
+ "mode": "wrap"
+ }],
+ ["transform-runtime", {
+ "polyfill": false,
+ "regenerator": false
+ }]
],
"env": {
"test": {
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index adeb8d3c5e..8819c03c32 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -126,7 +126,7 @@ class Dropdown extends Component {
### Define _meta
-Every component has a static property called `_meta`. This object defines the component. The values here are used in `propTypes`, generated documentation, generated test cases, and some utilities.
+Every component has a static property called `_meta`. This object defines the component. The values here are used for generated documentation, generated test cases and some utilities.
Here's an example `_meta` object:
@@ -136,9 +136,6 @@ import { META } from '../../lib'
const _meta = {
name: 'MyComponent',
type: META.TYPES.MODULE,
- props: {
- pointing: ['bottom left', 'bottom right'],
- },
}
```
@@ -162,6 +159,23 @@ class MyComponent {
}
```
+### Using propTypes
+
+Every component must have fully described `propTypes`.
+
+ ```js
+ import React, { PropTypes } from 'react'
+
+ function MyComponent(props) {
+ return