-
Notifications
You must be signed in to change notification settings - Fork 80
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
Refactor/component-types #212
Changes from 1 commit
a43e648
27ba48d
cc82e23
b65ee7d
aa8558c
bde4b1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import _ from 'lodash'; | |
import Button from '../Button/Button'; | ||
import React from 'react'; | ||
import { lucidClassNames } from '../../util/style-helpers'; | ||
import { createClass } from '../../util/component-definition'; | ||
import { createClass, findTypes } from '../../util/component-types'; | ||
import reducers from './ButtonGroup.reducers'; | ||
|
||
const boundClassNames = lucidClassNames.bind('&-ButtonGroup'); | ||
|
@@ -24,8 +24,11 @@ const { | |
const ButtonGroup = createClass({ | ||
displayName: 'ButtonGroup', | ||
|
||
childProps: { | ||
Button: { ...Button.propTypes } | ||
components: { | ||
Button: createClass({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you not just use a reference to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. er, i guess not since it has a render fn... this part seems a little weird seems like it would be good to be able to get at least There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right we should reference it as is right here instead of creating a new type, but the goal of this change was a 1:1 change in how child components are defined and filtered, we should have another PR that cleans up any redundancies that we identify with child components There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't it be weird since |
||
displayName: 'ButtonGroup.Button', | ||
propName: 'Button' | ||
}) | ||
}, | ||
|
||
reducers: reducers, | ||
|
@@ -70,7 +73,7 @@ const ButtonGroup = createClass({ | |
|
||
handleSelect({ event, props: childProps }) { | ||
const { callbackId } = childProps; | ||
const clickedButtonProps = ButtonGroup.Button.findInAllAsProps(this.props)[callbackId]; | ||
const clickedButtonProps = findTypes(this.props, ButtonGroup.Button)[callbackId]; | ||
|
||
// If the consumer passed in an `onClick` to the child `ButtonGroup.Button` | ||
// component, we should make sure to call that in addition to the | ||
|
@@ -90,7 +93,7 @@ const ButtonGroup = createClass({ | |
...others | ||
} = this.props; | ||
|
||
const buttonChildProps = ButtonGroup.Button.findInAllAsProps(this.props); | ||
const buttonChildProps = _.map(findTypes(this.props, ButtonGroup.Button), 'props'); | ||
|
||
return ( | ||
<span | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import _ from 'lodash'; | ||
import React from 'react'; | ||
import { lucidClassNames } from '../../util/style-helpers'; | ||
import { createClass } from '../../util/component-definition'; | ||
import { findAllChildComponents } from '../../util/child-component'; | ||
import { createClass, findTypes, filterTypes } from '../../util/component-types'; | ||
|
||
import Checkbox from '../Checkbox/Checkbox'; | ||
import ScrollTable from '../ScrollTable/ScrollTable'; | ||
|
@@ -108,14 +107,22 @@ const DataTable = createClass({ | |
}; | ||
}, | ||
|
||
childProps: { | ||
Column: { | ||
field: string.isRequired, | ||
title: string | ||
}, | ||
ColumnGroup: { | ||
title: string | ||
} | ||
components: { | ||
Column: createClass({ | ||
displayName: 'DataTable.Column', | ||
propName: 'Column', | ||
propTypes: { | ||
field: string.isRequired, | ||
title: string | ||
} | ||
}), | ||
ColumnGroup: createClass({ | ||
displayName: 'DataTable.ColumnGroup', | ||
propName: 'ColumnGroup', | ||
propTypes: { | ||
title: string | ||
} | ||
}) | ||
}, | ||
|
||
statics: { | ||
|
@@ -175,13 +182,13 @@ const DataTable = createClass({ | |
} = this.props; | ||
|
||
|
||
const childComponentElements = findAllChildComponents(this.props, [DataTable.Column, DataTable.ColumnGroup]); | ||
const childComponentElements = findTypes(this.props, [DataTable.Column, DataTable.ColumnGroup]); | ||
const flattenedColumns = _.reduce(childComponentElements, (acc, childComponentElement) => { | ||
if (childComponentElement.type === DataTable.Column) { | ||
return acc.concat([{props: childComponentElement.props, columnGroupProps: null}]); | ||
} | ||
if (childComponentElement.type === DataTable.ColumnGroup) { | ||
return acc.concat(_.map(findAllChildComponents(childComponentElement.props, [DataTable.Column]), (columnChildComponent) => ({ props: columnChildComponent.props, columnGroupProps: childComponentElement.props }))); | ||
return acc.concat(_.map(findTypes(childComponentElement.props, DataTable.Column), (columnChildComponent) => ({ props: columnChildComponent.props, columnGroupProps: childComponentElement.props }))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. format this a little better |
||
} | ||
}, []); | ||
|
||
|
@@ -207,7 +214,7 @@ const DataTable = createClass({ | |
</Th> | ||
) : ( | ||
<Th | ||
colSpan={_.size(DataTable.Column.findInChildren(props.children))} | ||
colSpan={_.size(filterTypes(props.children, DataTable.Column))} | ||
{..._.omit(props, ['field', 'children', 'width', 'title'])} | ||
key={_.get(props, 'field', index)} | ||
> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import React from 'react'; | ||
import _ from 'lodash'; | ||
import { lucidClassNames } from '../../util/style-helpers'; | ||
import { createClass } from '../../util/component-definition'; | ||
import { createClass, findTypes, rejectTypes } from '../../util/component-types'; | ||
import { scrollParentTo } from '../../util/dom-helpers'; | ||
import { rejectNullElements } from '../../util/child-component'; | ||
import * as KEYCODE from '../../constants/key-code'; | ||
import * as reducers from './DropMenu.reducers'; | ||
import ContextMenu from '../ContextMenu/ContextMenu'; | ||
|
@@ -43,13 +42,26 @@ const DropMenu = createClass({ | |
|
||
reducers, | ||
|
||
childProps: { | ||
Control: {}, | ||
OptionGroup: {}, | ||
Option: { | ||
isDisabled: bool | ||
}, | ||
NullOption: {} | ||
components: { | ||
Control: createClass({ | ||
displayName: 'DropMenu.Control', | ||
propName: 'Control' | ||
}), | ||
OptionGroup: createClass({ | ||
displayName: 'DropMenu.OptionGroup', | ||
propName: 'OptionGroup' | ||
}), | ||
Option: createClass({ | ||
displayName: 'DropMenu.Option', | ||
propName: 'Option', | ||
propTypes: { | ||
isDisabled: bool | ||
} | ||
}), | ||
NullOption: createClass({ | ||
displayName: 'DropMenu.NullOption', | ||
propName: 'NullOption' | ||
}) | ||
}, | ||
|
||
propTypes: { | ||
|
@@ -179,13 +191,17 @@ const DropMenu = createClass({ | |
Option, | ||
NullOption | ||
} = ParentType; | ||
const optionGroups = OptionGroup.findInAllAsProps(props); // find all OptionGroup props | ||
const ungroupedOptions = Option.findInAllAsProps(props); // find all ungrouped Option props | ||
const nullOptions = NullOption ? NullOption.findInAllAsProps(props) : []; // find all NullOption props | ||
//const optionGroups = OptionGroup.findInAllAsProps(props); // find all OptionGroup props | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented code |
||
const optionGroups = _.map(findTypes(props, OptionGroup), 'props'); // find all OptionGroup props | ||
//const ungroupedOptions = Option.findInAllAsProps(props); // find all ungrouped Option props | ||
const ungroupedOptions = _.map(findTypes(props, Option), 'props') // find all ungrouped Option props | ||
//const nullOptions = NullOption ? NullOption.findInAllAsProps(props) : []; // find all NullOption props | ||
const nullOptions = NullOption ? _.map(findTypes(props, NullOption), 'props') : []; // find all NullOption props | ||
|
||
// flatten grouped options into array of objects to associate { index, group index, and props } for each option | ||
const groupedOptionData = _.reduce(optionGroups, (memo, optionGroupProps, optionGroupIndex) => { | ||
const groupedOptions = Option.findInAllAsProps(optionGroupProps); // find all Option props for current group | ||
//const groupedOptions = Option.findInAllAsProps(optionGroupProps); // find all Option props for current group | ||
const groupedOptions = _.map(findTypes(optionGroupProps, Option), 'props'); // find all Option props for current group | ||
return memo.concat(_.map(groupedOptions, (optionProps, localOptionIndex) => { | ||
return { | ||
localOptionIndex, | ||
|
@@ -416,7 +432,8 @@ const DropMenu = createClass({ | |
nullOptions | ||
} = this.state; | ||
|
||
const controlProps = _.first(DropMenu.Control.findInAllAsProps(this.props)); | ||
//const controlProps = _.first(DropMenu.Control.findInAllAsProps(this.props)); | ||
const controlProps = _.get(_.first(findTypes(this.props, DropMenu.Control)), 'props', {}); | ||
|
||
return ( | ||
<div className={boundClassNames('&', '&-base', { | ||
|
@@ -445,7 +462,7 @@ const DropMenu = createClass({ | |
joinArray( | ||
// for each option group, | ||
_.map(optionGroups, (optionGroupProps, optionGroupIndex) => { | ||
const labelElements = rejectNullElements(optionGroupProps.children); | ||
const labelElements = rejectTypes(optionGroupProps.children, [DropMenu.Control, DropMenu.OptionGroup, DropMenu.Option, DropMenu.NullOption]); | ||
// render label if there is one | ||
return (_.isEmpty(labelElements) ? [] : [ | ||
<div {...optionGroupProps} className={boundClassNames('&-label', optionGroupProps.className)}> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes it so that when u call
findTypes(props, Button)
it will also look for the propButton
on the props object in addition toprops.children
.