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