You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
import React from 'react';
 | 
						|
 | 
						|
interface Props {
 | 
						|
  label: string;
 | 
						|
  value: string;
 | 
						|
  active: boolean;
 | 
						|
  group?: string;
 | 
						|
  onClick: any;
 | 
						|
}
 | 
						|
 | 
						|
interface State {
 | 
						|
  active: boolean;
 | 
						|
}
 | 
						|
 | 
						|
export class SessionRadio extends React.PureComponent<Props, State> {
 | 
						|
  public static defaultProps = {
 | 
						|
    onClick: () => null,
 | 
						|
  };
 | 
						|
 | 
						|
  constructor(props: any) {
 | 
						|
    super(props);
 | 
						|
    this.clickHandler = this.clickHandler.bind(this);
 | 
						|
 | 
						|
    this.state = {
 | 
						|
      active: this.props.active,
 | 
						|
    };
 | 
						|
  }
 | 
						|
 | 
						|
  public render() {
 | 
						|
    const active = this.state.active;
 | 
						|
    const { label, group, value } = this.props;
 | 
						|
 | 
						|
    return (
 | 
						|
      <div className="session-radio">
 | 
						|
        <input
 | 
						|
          type="radio"
 | 
						|
          name={group || ''}
 | 
						|
          value={value}
 | 
						|
          defaultChecked={active}
 | 
						|
          aria-checked={active}
 | 
						|
          onClick={this.clickHandler}
 | 
						|
        />
 | 
						|
        <label>{label} </label>
 | 
						|
      </div>
 | 
						|
    );
 | 
						|
  }
 | 
						|
 | 
						|
  private clickHandler(e: any) {
 | 
						|
    if (this.props.onClick) {
 | 
						|
      e.stopPropagation();
 | 
						|
      this.props.onClick();
 | 
						|
 | 
						|
      this.setState({
 | 
						|
        active: !this.state.active,
 | 
						|
      });
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 |