Merge branch 'change-toggle-design' into 'develop'
Change design of toggle button See merge request soapbox-pub/soapbox-fe!105
This commit is contained in:
commit
ec8cd65e8d
|
@ -15,6 +15,7 @@ import { shortNumberFormat } from '../utils/numbers';
|
||||||
import { isStaff } from '../utils/accounts';
|
import { isStaff } from '../utils/accounts';
|
||||||
import { makeGetAccount } from '../selectors';
|
import { makeGetAccount } from '../selectors';
|
||||||
import { logOut } from 'soapbox/actions/auth';
|
import { logOut } from 'soapbox/actions/auth';
|
||||||
|
import ThemeToggle from '../features/ui/components/theme_toggle';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
||||||
|
@ -119,6 +120,12 @@ class SidebarMenu extends ImmutablePureComponent {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='sidebar-menu__section sidebar-menu__section--borderless'>
|
<div className='sidebar-menu__section sidebar-menu__section--borderless'>
|
||||||
|
<div className='sidebar-menu-item theme-toggle'>
|
||||||
|
<ThemeToggle showLabel />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='sidebar-menu__section sidebar-menu__section'>
|
||||||
<NavLink className='sidebar-menu-item' to={`/@${acct}`} onClick={onClose}>
|
<NavLink className='sidebar-menu-item' to={`/@${acct}`} onClick={onClose}>
|
||||||
<Icon id='user' />
|
<Icon id='user' />
|
||||||
<span className='sidebar-menu-item__title'>{intl.formatMessage(messages.profile)}</span>
|
<span className='sidebar-menu-item__title'>{intl.formatMessage(messages.profile)}</span>
|
||||||
|
|
|
@ -9,8 +9,14 @@ export default class SettingToggle extends React.PureComponent {
|
||||||
prefix: PropTypes.string,
|
prefix: PropTypes.string,
|
||||||
settings: ImmutablePropTypes.map.isRequired,
|
settings: ImmutablePropTypes.map.isRequired,
|
||||||
settingPath: PropTypes.array.isRequired,
|
settingPath: PropTypes.array.isRequired,
|
||||||
label: PropTypes.node.isRequired,
|
label: PropTypes.node,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
|
icons: PropTypes.oneOfType([
|
||||||
|
PropTypes.bool,
|
||||||
|
PropTypes.object,
|
||||||
|
]),
|
||||||
|
condition: PropTypes.string,
|
||||||
|
ariaLabel: PropTypes.string,
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange = ({ target }) => {
|
onChange = ({ target }) => {
|
||||||
|
@ -18,13 +24,13 @@ export default class SettingToggle extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { prefix, settings, settingPath, label } = this.props;
|
const { prefix, settings, settingPath, label, icons, condition, ariaLabel } = this.props;
|
||||||
const id = ['setting-toggle', prefix, ...settingPath].filter(Boolean).join('-');
|
const id = ['setting-toggle', prefix, ...settingPath].filter(Boolean).join('-');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='setting-toggle'>
|
<div className='setting-toggle' aria-label={ariaLabel}>
|
||||||
<Toggle id={id} checked={settings.getIn(settingPath)} onChange={this.onChange} onKeyDown={this.onKeyDown} />
|
<Toggle id={id} checked={condition ? settings.getIn(settingPath) === condition : settings.getIn(settingPath)} onChange={this.onChange} icons={icons} onKeyDown={this.onKeyDown} />
|
||||||
<label htmlFor={id} className='setting-toggle__label'>{label}</label>
|
{label && (<label htmlFor={id} className='setting-toggle__label'>{label}</label>)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,10 @@ import ActionBar from 'soapbox/features/compose/components/action_bar';
|
||||||
import { openModal } from '../../../actions/modal';
|
import { openModal } from '../../../actions/modal';
|
||||||
import { openSidebar } from '../../../actions/sidebar';
|
import { openSidebar } from '../../../actions/sidebar';
|
||||||
import Icon from '../../../components/icon';
|
import Icon from '../../../components/icon';
|
||||||
import { changeSetting, getSettings } from 'soapbox/actions/settings';
|
import ThemeToggle from '../../ui/components/theme_toggle';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
post: { id: 'tabs_bar.post', defaultMessage: 'Post' },
|
post: { id: 'tabs_bar.post', defaultMessage: 'Post' },
|
||||||
switchToLight: { id: 'tabs_bar.theme_toggle_light', defaultMessage: 'Switch to light theme' },
|
|
||||||
switchToDark: { id: 'tabs_bar.theme_toggle_dark', defaultMessage: 'Switch to dark theme' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@withRouter
|
@withRouter
|
||||||
|
@ -28,10 +26,8 @@ class TabsBar extends React.PureComponent {
|
||||||
history: PropTypes.object.isRequired,
|
history: PropTypes.object.isRequired,
|
||||||
onOpenCompose: PropTypes.func,
|
onOpenCompose: PropTypes.func,
|
||||||
onOpenSidebar: PropTypes.func.isRequired,
|
onOpenSidebar: PropTypes.func.isRequired,
|
||||||
toggleTheme: PropTypes.func,
|
|
||||||
logo: PropTypes.string,
|
logo: PropTypes.string,
|
||||||
account: ImmutablePropTypes.map,
|
account: ImmutablePropTypes.map,
|
||||||
themeMode: PropTypes.string,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
|
@ -83,18 +79,8 @@ class TabsBar extends React.PureComponent {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
getNewThemeValue() {
|
|
||||||
if (this.props.themeMode === 'light') return 'dark';
|
|
||||||
|
|
||||||
return 'light';
|
|
||||||
}
|
|
||||||
|
|
||||||
handleToggleTheme = () => {
|
|
||||||
this.props.toggleTheme(this.getNewThemeValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { account, onOpenCompose, onOpenSidebar, intl, themeMode } = this.props;
|
const { account, onOpenCompose, onOpenSidebar, intl } = this.props;
|
||||||
const { collapsed } = this.state;
|
const { collapsed } = this.state;
|
||||||
|
|
||||||
const classes = classNames('tabs-bar', {
|
const classes = classNames('tabs-bar', {
|
||||||
|
@ -113,9 +99,7 @@ class TabsBar extends React.PureComponent {
|
||||||
</div>
|
</div>
|
||||||
{ account &&
|
{ account &&
|
||||||
<div className='flex'>
|
<div className='flex'>
|
||||||
<button className='tabs-bar__button-theme-toggle button' onClick={this.handleToggleTheme} aria-label={themeMode === 'light' ? intl.formatMessage(messages.switchToDark) : intl.formatMessage(messages.switchToLight)}>
|
<ThemeToggle />
|
||||||
<Icon id={themeMode === 'light' ? 'sun' : 'moon'} />
|
|
||||||
</button>
|
|
||||||
<div className='tabs-bar__profile'>
|
<div className='tabs-bar__profile'>
|
||||||
<Avatar account={account} />
|
<Avatar account={account} />
|
||||||
<button className='tabs-bar__sidebar-btn' onClick={onOpenSidebar} />
|
<button className='tabs-bar__sidebar-btn' onClick={onOpenSidebar} />
|
||||||
|
@ -147,11 +131,9 @@ class TabsBar extends React.PureComponent {
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
const settings = getSettings(state);
|
|
||||||
return {
|
return {
|
||||||
account: state.getIn(['accounts', me]),
|
account: state.getIn(['accounts', me]),
|
||||||
logo: state.getIn(['soapbox', 'logo']),
|
logo: state.getIn(['soapbox', 'logo']),
|
||||||
themeMode: settings.get('themeMode'),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -162,9 +144,6 @@ const mapDispatchToProps = (dispatch) => ({
|
||||||
onOpenSidebar() {
|
onOpenSidebar() {
|
||||||
dispatch(openSidebar());
|
dispatch(openSidebar());
|
||||||
},
|
},
|
||||||
toggleTheme(setting) {
|
|
||||||
dispatch(changeSetting(['themeMode'], setting));
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default injectIntl(
|
export default injectIntl(
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { injectIntl, defineMessages } from 'react-intl';
|
||||||
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
|
import Icon from '../../../components/icon';
|
||||||
|
import { changeSetting, getSettings } from 'soapbox/actions/settings';
|
||||||
|
import SettingToggle from '../../notifications/components/setting_toggle';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
switchToLight: { id: 'tabs_bar.theme_toggle_light', defaultMessage: 'Switch to light theme' },
|
||||||
|
switchToDark: { id: 'tabs_bar.theme_toggle_dark', defaultMessage: 'Switch to dark theme' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapStateToProps = state => {
|
||||||
|
return {
|
||||||
|
settings: getSettings(state),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
toggleTheme(setting) {
|
||||||
|
dispatch(changeSetting(['themeMode'], setting));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default @connect(mapStateToProps, mapDispatchToProps)
|
||||||
|
@injectIntl
|
||||||
|
class ThemeToggle extends React.PureComponent {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
intl: PropTypes.object.isRequired,
|
||||||
|
settings: ImmutablePropTypes.map.isRequired,
|
||||||
|
toggleTheme: PropTypes.func,
|
||||||
|
showLabel: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
handleToggleTheme = () => {
|
||||||
|
this.props.toggleTheme(this.props.settings.get('themeMode') === 'light' ? 'dark' : 'light');
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { intl, settings, showLabel } = this.props;
|
||||||
|
let toggle = (
|
||||||
|
<SettingToggle settings={settings} settingPath={['themeMode']} condition={'light'} onChange={this.handleToggleTheme} icons={{ checked: <Icon id='sun' />, unchecked: <Icon id='moon' /> }} ariaLabel={settings.get('themeMode') === 'light' ? intl.formatMessage(messages.switchToDark) : intl.formatMessage(messages.switchToLight)} />
|
||||||
|
);
|
||||||
|
|
||||||
|
if (showLabel) {
|
||||||
|
toggle = (
|
||||||
|
<SettingToggle settings={settings} settingPath={['themeMode']} condition={'light'} onChange={this.handleToggleTheme} icons={{ checked: <Icon id='sun' />, unchecked: <Icon id='moon' /> }} label={settings.get('themeMode') === 'light' ? intl.formatMessage(messages.switchToDark) : intl.formatMessage(messages.switchToLight)} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class='theme-toggle'>
|
||||||
|
{toggle}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -61,6 +61,7 @@
|
||||||
@import 'components/still-image';
|
@import 'components/still-image';
|
||||||
@import 'components/timeline-queue-header';
|
@import 'components/timeline-queue-header';
|
||||||
@import 'components/badge';
|
@import 'components/badge';
|
||||||
|
@import 'components/theme-toggle';
|
||||||
@import 'components/trends';
|
@import 'components/trends';
|
||||||
@import 'components/wtf-panel';
|
@import 'components/wtf-panel';
|
||||||
@import 'components/profile-info-panel';
|
@import 'components/profile-info-panel';
|
||||||
|
|
|
@ -161,6 +161,10 @@
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.theme-toggle {
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
&__title {
|
&__title {
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
|
|
|
@ -111,14 +111,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__button-theme-toggle {
|
|
||||||
margin-left: 10px;
|
|
||||||
padding: 0 10px;
|
|
||||||
font-size: 20px;
|
|
||||||
|
|
||||||
.fa { margin-right: 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
&__button-compose {
|
&__button-compose {
|
||||||
display: block;
|
display: block;
|
||||||
@media screen and (max-width: $nav-breakpoint-3) {display: none;}
|
@media screen and (max-width: $nav-breakpoint-3) {display: none;}
|
||||||
|
@ -149,6 +141,23 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.theme-toggle {
|
||||||
|
@media screen and (max-width: $nav-breakpoint-3) {display: none;}
|
||||||
|
|
||||||
|
.setting-toggle {
|
||||||
|
margin-top: 3px;
|
||||||
|
margin-left: 10px;
|
||||||
|
|
||||||
|
.react-toggle--checked {
|
||||||
|
.react-toggle-track {
|
||||||
|
background-color: var(--accent-color);
|
||||||
|
}
|
||||||
|
&:hover:not(.react-toggle--disabled) .react-toggle-track {
|
||||||
|
background-color: var(--accent-color--bright);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabs-bar__link {
|
.tabs-bar__link {
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
.theme-toggle {
|
||||||
|
.setting-toggle {
|
||||||
|
|
||||||
|
&__label {
|
||||||
|
margin-bottom: 0px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-toggle {
|
||||||
|
vertical-align: middle;
|
||||||
|
|
||||||
|
&-track-check,
|
||||||
|
&-track-x {
|
||||||
|
height: 15px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue