-
Notifications
You must be signed in to change notification settings - Fork 4k
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
RFC: Base component #419
Comments
Yep, for this I've been toying with "reusable component parts", see #345. I made a memoized component part factory, The "base component" I'm thinking of would also be usable in any of our components somehow. Example, maybe it has I'm not really sure if this is a great idea, a base component. Though, the reusable parts for the most basic component parts (sub components) I think surely is. |
There's already an idiomatic way of doing this with an Higher Order Components. export default baseComponent(WrappedComponent, class) {
return class BaseComponent extends React.Component {
displayName = WrappedComponent.displayName || 'BaseComponent';
render() {
const { className, children, ...props } = this.props;
const classes = cx(class, className)
const rest = getUnhandledProps(WrappedComponent, props)
const ElementType = getElementType(WrappedComponent, props)
return <WrappedComponent {...rest} className={classes} component={ElementType}>{children}</WrappedComponent>
}
}
}; Now your sub-components are vastly simpler: function MessageHeader(props) {
const { component: Component, ...rest } = props;
return <Component {...rest} />;
}
MessageHeader._meta = {
name: 'MessageHeader',
parent: 'Message',
type: META.TYPES.COLLECTION,
}
export baseComponent(MessageHeader, 'header'); |
|
At least for SUIR right now, there are no styles until #1579 lands.
|
cc. Semantic-Org/Semantic-UI#5420 - while working on a dojo2 integration I also noticed that a shared baseClass for |
Closing for housekeeping. I have a branch going which will add |
There is basic functionality that is shared by all components:
as
andclassName
propTypes, most the time alsochildren
Updating components in any of these areas requires updating all components. This was just done to support augmentation, see #414. There are ~1,800 lines added to accomplish this. The grand majority of this work was duplicating the logic and propTypes for all components.
It seems we could use a base component factory to generate a "conformant" base component. It would handle the common functionality for all components. It could make maintenance much easier. It could also give us the ability to better standardize how components are generated.
This would either work similar to the reusable component parts factories in #345, or be a base component that we extend. In either case, the above list of required features would be abstracted into a single place.
The text was updated successfully, but these errors were encountered: