center notification icon on settings and make label clickable

pull/1528/head
Audric Ackermann 4 years ago
parent 533b95c827
commit a04bc0d225

@ -1086,23 +1086,18 @@ label {
border: none; border: none;
margin-inline-start: $session-margin-sm; margin-inline-start: $session-margin-sm;
margin-top: $session-margin-sm; margin-top: $session-margin-sm;
.session-radio {
padding: $session-margin-xs 0px;
}
} }
.session-radio { .session-radio-group fieldset {
input[type='radio'] { input[type='radio'] {
border: 0;
opacity: 0; opacity: 0;
padding: 0;
position: absolute; position: absolute;
cursor: pointer; cursor: pointer;
} }
label { label {
margin-inline-end: 1em; margin-inline-end: 1em;
cursor: pointer;
} }
label:before { label:before {
@ -1112,7 +1107,7 @@ label {
height: 0.5em; height: 0.5em;
margin-inline-end: 0.8em; margin-inline-end: 0.8em;
border-radius: 100%; border-radius: 100%;
vertical-align: -3px; vertical-align: 0px;
border: 2px solid rgba($session-color-white, 0.6); border: 2px solid rgba($session-color-white, 0.6);
padding: 0.2em; padding: 0.2em;
@include themify($themes) { @include themify($themes) {

@ -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();
}
}
}

@ -80,10 +80,12 @@ export class SessionSettingListItem extends React.Component<Props, State> {
{type === SessionSettingType.Options && ( {type === SessionSettingType.Options && (
<SessionRadioGroup <SessionRadioGroup
initalItem={content.options.initalItem} initialItem={content.options.initalItem}
group={content.options.group} group={content.options.group}
items={content.options.items} items={content.options.items}
onClick={this.handleClick} onClick={(selectedRadioValue: string) => {
this.props.onClick(selectedRadioValue);
}}
/> />
)} )}

@ -139,8 +139,8 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
const onClickFn = const onClickFn =
setting.onClick || setting.onClick ||
(() => { ((value?: string) => {
this.updateSetting(setting); this.updateSetting(setting, value);
}); });
return ( return (
@ -263,10 +263,7 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
); );
} }
public setOptionsSetting(settingID: string) { public setOptionsSetting(settingID: string, selectedValue: string) {
const selectedValue = jQuery(
`#${settingID} .session-radio input:checked`
).val();
window.setSettingValue(settingID, selectedValue); window.setSettingValue(settingID, selectedValue);
} }
@ -278,12 +275,16 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
}); });
} }
public updateSetting(item: any) { public updateSetting(item: any, value?: string) {
// If there's a custom afterClick function, // If there's a custom afterClick function,
// execute it instead of automatically updating settings // execute it instead of automatically updating settings
if (item.setFn) { if (item.setFn) {
item.setFn(); if (value) {
item.setFn(value);
} else {
item.setFn();
}
} else { } else {
if (item.type === SessionSettingType.Toggle) { if (item.type === SessionSettingType.Toggle) {
// If no custom afterClick function given, alter values in storage here // If no custom afterClick function given, alter values in storage here
@ -382,8 +383,8 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
description: undefined, description: undefined,
hidden: undefined, hidden: undefined,
onClick: undefined, onClick: undefined,
setFn: () => { setFn: (selectedValue: string) => {
this.setOptionsSetting('notification-setting'); this.setOptionsSetting('notification-setting', selectedValue);
}, },
content: { content: {
options: { options: {

Loading…
Cancel
Save