react-mdc / react-material-components-web

React wrapper of Google's Material Components Web
https://react-mdc.github.io/
178 stars 15 forks source link

[common] Remove Wrapper API #23

Closed Hardtack closed 7 years ago

Hardtack commented 7 years ago

We have cool API named Wrapper and PropWrapper. But, type inferencing of these components is too complex.

So I'm considering to change API with following.

For default HTML element

<Button>Text</Button>

And for custom HTML Element

<Button.Wrap>
    <a href="link">Text</a>
</Button.Wrap>

Implementation may be like

class Wrap extends React.Component<WrapperProps, State> {
    //...
}

export default class Button extends React.Component<WrapperProps & Props, {}> {
    public static Wrap = Wrap;

    public render() {
        const {
            buttonProp1,
            buttonProp2,
            ...props,
        }
        return (
            <Wrap buttonProp1={buttonProp1} buttonProp2={buttonProp2}>
                <button {...props} />
            </Wrap>
        );
    }
}

This is also cool