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

ListItem click handling? #25

Open
arjunkomath opened this issue May 6, 2016 · 1 comment
Open

ListItem click handling? #25

arjunkomath opened this issue May 6, 2016 · 1 comment

Comments

@arjunkomath
Copy link

How do handle a click on ListItem, I couldn't find anything in the docs. Thanks.

@mitchdav
Copy link

mitchdav commented May 5, 2017

To those that are looking for this functionality, I've been able to add it by overwriting the ListItem class as below:

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import {ListItem as Base} from 'react-photonkit';

export default class ListItem extends Base {
    onClickHandler() {

    }

    render() {
        const classes = super.getPtClassSet();

        classes.active = this.props.active;

        const className = classNames(this.props.className, classes);

        let img;

        if (this.props.image) {
            img = (
                <img className="img-circle media-object pull-left" src={this.props.image} width="32" height="32"/>
            );
        }

        return (
            <li className={className} onClick={this.props.onClick || this.onClickHandler}>
                {img}
                <div className="media-body">
                    <strong>{this.props.title}</strong>
                    <p>{this.props.subtitle}</p>
                </div>
            </li>
        );
    }
};

You would then call this from your components like this:

import ListItem from './ListItem';

const FeedItem = (props) => {
    return (
        <ListItem image={props.image}
                  title={props.title}
                  subtitle={props.subtitle}
                  onClick={() => { console.log('clicked'); }}
        />
    );
};

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

No branches or pull requests

3 participants