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

Using generic components #26

Open
gruckion opened this issue Apr 11, 2019 · 1 comment
Open

Using generic components #26

gruckion opened this issue Apr 11, 2019 · 1 comment

Comments

@gruckion
Copy link
Owner

gruckion commented Apr 11, 2019

microsoft/TypeScript#3960

Tried to make the drop down as a generic component. Didn't work as intended so parking it here.

interface Props<TModel> {
    dropdownOptions: DropdownItemProps[];
    propertyName: keyof TModel;
    updateProperty: (prop: keyof TModel, value: any, valid: boolean) => void;
    dropdownValues: LinkObject[];
}

export default class LinkObjectValuedDropDownMulti<TModel> extends React.Component<Props<TModel> & DropdownProps, {}> {
    public render() {
        return (
            < ...  />
        );
    }

    private onUpdateSelectedProperty = (values: string[], valid: boolean) => {
        this.props.updateProperty(this.props.propertyName, values.map((v): LinkObject =>
            ({ name: this.props.dropdownOptions.find(d => d.id === v).name, id: v })), valid);
    }
}

Usage

const NamedDropDownMulti = LinkObjectValuedDropDownMulti as (new () => LinkObjectValuedDropDownMulti<NamedModel>);
<WorkGroupDropDownMulti
    search
    dynamicOptions
    dropdownValues={this.state.values.named}
    label="named"
    placeholder="named"
    showErrors={this.state.showErrors}
    dropdownOptions={this.props.named}
    updateProperty={this.updateProperty}
    propertyName="named"
    onUpdateSelectedProperty={this.onUpdateSelectedProperty}
/>
@gruckion
Copy link
Owner Author

Was having an issue with the this reference on semantic UI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant