center notification icon on settings and make label clickable
parent
533b95c827
commit
a04bc0d225
@ -1,58 +1,40 @@
|
||||
import React from 'react';
|
||||
import { Flex } from './Flex';
|
||||
// tslint:disable: react-unused-props-and-state
|
||||
|
||||
interface Props {
|
||||
label: string;
|
||||
value: string;
|
||||
active: boolean;
|
||||
group?: string;
|
||||
onClick: any;
|
||||
onClick: (value: string) => any;
|
||||
}
|
||||
|
||||
interface State {
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export class SessionRadio extends React.PureComponent<Props, State> {
|
||||
public static defaultProps = {
|
||||
onClick: () => null,
|
||||
};
|
||||
export const SessionRadio = (props: Props) => {
|
||||
const { label, group, value, active, onClick } = props;
|
||||
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.clickHandler = this.clickHandler.bind(this);
|
||||
function clickHandler(e: any) {
|
||||
e.stopPropagation();
|
||||
console.warn(`SessionRadio clickHandler ${value}`);
|
||||
|
||||
this.state = {
|
||||
active: this.props.active,
|
||||
};
|
||||
onClick(value);
|
||||
}
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
console.warn(`isactive ${value}: ${active}`);
|
||||
|
||||
return (
|
||||
<Flex>
|
||||
<input
|
||||
type="radio"
|
||||
name={group || ''}
|
||||
value={value}
|
||||
aria-checked={active}
|
||||
checked={active}
|
||||
onClick={clickHandler}
|
||||
/>
|
||||
<label role="button" onClick={clickHandler}>
|
||||
{label}
|
||||
</label>
|
||||
</Flex>
|
||||
);
|
||||
};
|
||||
|
@ -1,60 +1,45 @@
|
||||
import React from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
import { SessionRadio } from './SessionRadio';
|
||||
|
||||
interface Props {
|
||||
initalItem: string;
|
||||
// tslint:disable: react-unused-props-and-state
|
||||
initialItem: string;
|
||||
items: Array<any>;
|
||||
group: string;
|
||||
onClick?: any;
|
||||
onClick: (selectedValue: string) => any;
|
||||
}
|
||||
|
||||
interface State {
|
||||
activeItem: string;
|
||||
}
|
||||
|
||||
export class SessionRadioGroup extends React.PureComponent<Props, State> {
|
||||
public static defaultProps = {
|
||||
onClick: () => null,
|
||||
};
|
||||
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.clickHandler = this.clickHandler.bind(this);
|
||||
|
||||
this.state = {
|
||||
activeItem: this.props.initalItem,
|
||||
};
|
||||
}
|
||||
|
||||
public render() {
|
||||
const { items, group } = this.props;
|
||||
|
||||
return (
|
||||
<div className="session-radio-group">
|
||||
<fieldset id={group}>
|
||||
{items.map(item => {
|
||||
const itemIsActive = item.value === this.state.activeItem;
|
||||
|
||||
return (
|
||||
<SessionRadio
|
||||
key={item.value}
|
||||
label={item.label}
|
||||
active={itemIsActive}
|
||||
value={item.value}
|
||||
group={group}
|
||||
onClick={this.clickHandler}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</fieldset>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private clickHandler() {
|
||||
if (this.props.onClick) {
|
||||
this.props.onClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
export const SessionRadioGroup = (props: Props) => {
|
||||
const [activeItem, setActiveItem] = useState('');
|
||||
const { items, group, initialItem } = props;
|
||||
|
||||
useEffect(() => {
|
||||
console.warn('unMNount:', initialItem);
|
||||
setActiveItem(initialItem);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="session-radio-group">
|
||||
<fieldset id={group}>
|
||||
{items.map(item => {
|
||||
const itemIsActive = item.value === activeItem;
|
||||
|
||||
return (
|
||||
<SessionRadio
|
||||
key={item.value}
|
||||
label={item.label}
|
||||
active={itemIsActive}
|
||||
value={item.value}
|
||||
group={group}
|
||||
onClick={(value: string) => {
|
||||
setActiveItem(value);
|
||||
props.onClick(value);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</fieldset>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue