mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 03:05:15 +08:00
Revamp notifications stylesheet (grid and flex) (#2822)
This commit is contained in:
parent
bbff3a2748
commit
3ca035f9aa
|
@ -4,6 +4,7 @@ import icon from '../../common/helpers/icon';
|
||||||
import humanTime from '../../common/helpers/humanTime';
|
import humanTime from '../../common/helpers/humanTime';
|
||||||
import Button from '../../common/components/Button';
|
import Button from '../../common/components/Button';
|
||||||
import Link from '../../common/components/Link';
|
import Link from '../../common/components/Link';
|
||||||
|
import classList from '../../common/utils/classList';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `Notification` component abstract displays a single notification.
|
* The `Notification` component abstract displays a single notification.
|
||||||
|
@ -22,27 +23,31 @@ export default class Notification extends Component {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
className={'Notification Notification--' + notification.contentType() + ' ' + (!notification.isRead() ? 'unread' : '')}
|
className={classList('Notification', `Notification--${notification.contentType()}`, [!notification.isRead() && 'unread'])}
|
||||||
href={href}
|
href={href}
|
||||||
external={href.includes('://')}
|
external={href.includes('://')}
|
||||||
onclick={this.markAsRead.bind(this)}
|
onclick={this.markAsRead.bind(this)}
|
||||||
>
|
>
|
||||||
{!notification.isRead() &&
|
{avatar(notification.fromUser())}
|
||||||
Button.component({
|
{icon(this.icon(), { className: 'Notification-icon' })}
|
||||||
className: 'Notification-action Button Button--icon Button--link',
|
<span className="Notification-title">
|
||||||
icon: 'fas fa-check',
|
<span className="Notification-content">{this.content()}</span>
|
||||||
title: app.translator.trans('core.forum.notifications.mark_as_read_tooltip'),
|
<span className="Notification-title-spring" />
|
||||||
onclick: (e) => {
|
{humanTime(notification.createdAt())}
|
||||||
|
</span>
|
||||||
|
{!notification.isRead() && (
|
||||||
|
<Button
|
||||||
|
className="Notification-action Button Button--link"
|
||||||
|
icon="fas fa-check"
|
||||||
|
title={app.translator.trans('core.forum.notifications.mark_as_read_tooltip')}
|
||||||
|
onclick={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
this.markAsRead();
|
this.markAsRead();
|
||||||
},
|
}}
|
||||||
})}
|
/>
|
||||||
{avatar(notification.fromUser())}
|
)}
|
||||||
{icon(this.icon(), { className: 'Notification-icon' })}
|
|
||||||
<span className="Notification-content">{this.content()}</span>
|
|
||||||
{humanTime(notification.createdAt())}
|
|
||||||
<div className="Notification-excerpt">{this.excerpt()}</div>
|
<div className="Notification-excerpt">{this.excerpt()}</div>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,16 +17,16 @@ export default class NotificationList extends Component {
|
||||||
return (
|
return (
|
||||||
<div className="NotificationList">
|
<div className="NotificationList">
|
||||||
<div className="NotificationList-header">
|
<div className="NotificationList-header">
|
||||||
<div className="App-primaryControl">
|
|
||||||
{Button.component({
|
|
||||||
className: 'Button Button--icon Button--link',
|
|
||||||
icon: 'fas fa-check',
|
|
||||||
title: app.translator.trans('core.forum.notifications.mark_all_as_read_tooltip'),
|
|
||||||
onclick: state.markAllAsRead.bind(state),
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h4 className="App-titleControl App-titleControl--text">{app.translator.trans('core.forum.notifications.title')}</h4>
|
<h4 className="App-titleControl App-titleControl--text">{app.translator.trans('core.forum.notifications.title')}</h4>
|
||||||
|
|
||||||
|
<div className="App-primaryControl">
|
||||||
|
<Button
|
||||||
|
className="Button Button--link"
|
||||||
|
icon="fas fa-check"
|
||||||
|
title={app.translator.trans('core.forum.notifications.mark_all_as_read_tooltip')}
|
||||||
|
onclick={state.markAllAsRead.bind(state)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="NotificationList-content">
|
<div className="NotificationList-content">
|
||||||
|
@ -43,7 +43,7 @@ export default class NotificationList extends Component {
|
||||||
// Get the discussion that this notification is related to. If it's not
|
// Get the discussion that this notification is related to. If it's not
|
||||||
// directly related to a discussion, it may be related to a post or
|
// directly related to a discussion, it may be related to a post or
|
||||||
// other entity which is related to a discussion.
|
// other entity which is related to a discussion.
|
||||||
let discussion = false;
|
let discussion = null;
|
||||||
if (subject instanceof Discussion) discussion = subject;
|
if (subject instanceof Discussion) discussion = subject;
|
||||||
else if (subject && subject.discussion) discussion = subject.discussion();
|
else if (subject && subject.discussion) discussion = subject.discussion();
|
||||||
|
|
||||||
|
@ -65,8 +65,8 @@ export default class NotificationList extends Component {
|
||||||
<div className="NotificationGroup">
|
<div className="NotificationGroup">
|
||||||
{group.discussion ? (
|
{group.discussion ? (
|
||||||
<Link className="NotificationGroup-header" href={app.route.discussion(group.discussion)}>
|
<Link className="NotificationGroup-header" href={app.route.discussion(group.discussion)}>
|
||||||
{badges && badges.length ? <ul className="NotificationGroup-badges badges">{listItems(badges)}</ul> : ''}
|
{badges && badges.length && <ul className="NotificationGroup-badges badges">{listItems(badges)}</ul>}
|
||||||
{group.discussion.title()}
|
<span>{group.discussion.title()}</span>
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<div className="NotificationGroup-header">{app.forum.attribute('title')}</div>
|
<div className="NotificationGroup-header">{app.forum.attribute('title')}</div>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import Dropdown from '../../common/components/Dropdown';
|
import Dropdown from '../../common/components/Dropdown';
|
||||||
import icon from '../../common/helpers/icon';
|
import icon from '../../common/helpers/icon';
|
||||||
|
import classList from '../../common/utils/classList';
|
||||||
import NotificationList from './NotificationList';
|
import NotificationList from './NotificationList';
|
||||||
|
|
||||||
export default class NotificationsDropdown extends Dropdown {
|
export default class NotificationsDropdown extends Dropdown {
|
||||||
|
@ -9,6 +10,7 @@ export default class NotificationsDropdown extends Dropdown {
|
||||||
attrs.menuClassName = attrs.menuClassName || 'Dropdown-menu--right';
|
attrs.menuClassName = attrs.menuClassName || 'Dropdown-menu--right';
|
||||||
attrs.label = attrs.label || app.translator.trans('core.forum.notifications.tooltip');
|
attrs.label = attrs.label || app.translator.trans('core.forum.notifications.tooltip');
|
||||||
attrs.icon = attrs.icon || 'fas fa-bell';
|
attrs.icon = attrs.icon || 'fas fa-bell';
|
||||||
|
|
||||||
// For best a11y support, both `title` and `aria-label` should be used
|
// For best a11y support, both `title` and `aria-label` should be used
|
||||||
attrs.accessibleToggleLabel = attrs.accessibleToggleLabel || app.translator.trans('core.forum.notifications.toggle_dropdown_accessible_label');
|
attrs.accessibleToggleLabel = attrs.accessibleToggleLabel || app.translator.trans('core.forum.notifications.toggle_dropdown_accessible_label');
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ export default class NotificationsDropdown extends Dropdown {
|
||||||
|
|
||||||
vdom.attrs.title = this.attrs.label;
|
vdom.attrs.title = this.attrs.label;
|
||||||
|
|
||||||
vdom.attrs.className += newNotifications ? ' new' : '';
|
vdom.attrs.className = classList(vdom.attrs.className, [newNotifications && 'new']);
|
||||||
vdom.attrs.onclick = this.onclick.bind(this);
|
vdom.attrs.onclick = this.onclick.bind(this);
|
||||||
|
|
||||||
return vdom;
|
return vdom;
|
||||||
|
@ -32,15 +34,15 @@ export default class NotificationsDropdown extends Dropdown {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
icon(this.attrs.icon, { className: 'Button-icon' }),
|
icon(this.attrs.icon, { className: 'Button-icon' }),
|
||||||
unread ? <span className="NotificationsDropdown-unread">{unread}</span> : '',
|
unread !== 0 && <span className="NotificationsDropdown-unread">{unread}</span>,
|
||||||
<span className="Button-label">{this.attrs.label}</span>,
|
<span className="Button-label">{this.attrs.label}</span>,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
getMenu() {
|
getMenu() {
|
||||||
return (
|
return (
|
||||||
<div className={'Dropdown-menu ' + this.attrs.menuClassName} onclick={this.menuClick.bind(this)}>
|
<div className={classList('Dropdown-menu', this.attrs.menuClassName)} onclick={this.menuClick.bind(this)}>
|
||||||
{this.showing ? NotificationList.component({ state: this.attrs.state }) : ''}
|
{this.showing && NotificationList.component({ state: this.attrs.state })}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +1,60 @@
|
||||||
|
|
||||||
.NotificationList {
|
.NotificationList {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
& .loading-indicator {
|
|
||||||
height: 100px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.NotificationList-header {
|
&-header {
|
||||||
@media @tablet-up {
|
@media @tablet-up {
|
||||||
padding: 12px 15px;
|
padding: 12px 15px;
|
||||||
border-bottom: 1px solid @control-bg;
|
border-bottom: 1px solid @control-bg;
|
||||||
|
|
||||||
h4 {
|
display: flex;
|
||||||
font-size: 12px;
|
justify-content: space-between;
|
||||||
text-transform: uppercase;
|
align-items: center;
|
||||||
font-weight: bold;
|
|
||||||
margin: 0;
|
h4 {
|
||||||
color: @muted-color;
|
font-size: 12px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: bold;
|
||||||
|
margin: 0;
|
||||||
|
color: @muted-color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.Button {
|
|
||||||
float: right;
|
|
||||||
margin-top: -11px;
|
|
||||||
margin-right: -11px;
|
|
||||||
|
|
||||||
// The NotificationList may be displayed inside of the drawer as a
|
// Mark all as read button
|
||||||
// dropdown menu – but the drawer may have .light-contents() applied to
|
.Button {
|
||||||
// it. In this case we will need to reset the button's styles back to
|
padding: 0;
|
||||||
// normal.
|
text-decoration: none;
|
||||||
& when (@config-colored-header = true) {
|
|
||||||
.Button--color(@control-color, @control-bg);
|
|
||||||
|
|
||||||
&:hover {
|
// The NotificationList may be displayed inside of the drawer as a
|
||||||
color: @link-color;
|
// dropdown menu – but the drawer may have .light-contents() applied to
|
||||||
|
// it. In this case we will need to reset the button's styles back to
|
||||||
|
// normal.
|
||||||
|
& when (@config-colored-header = true) {
|
||||||
|
color: @control-color;
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&:focus {
|
||||||
|
color: @link-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-keyboard-focus-ring();
|
||||||
|
.add-keyboard-focus-ring-offset(4px);
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Message displayed when notifications are empty
|
||||||
|
&-empty {
|
||||||
|
color: @muted-color;
|
||||||
|
text-align: center;
|
||||||
|
padding: 50px 0;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.NotificationList-empty {
|
|
||||||
color: @muted-color;
|
|
||||||
text-align: center;
|
|
||||||
padding: 50px 0;
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
.NotificationGroup {
|
.NotificationGroup {
|
||||||
border-top: 1px solid @control-bg;
|
border-top: 1px solid @control-bg;
|
||||||
margin-top: -1px;
|
margin-top: -1px;
|
||||||
|
@ -50,99 +62,143 @@
|
||||||
&:not(:last-child) {
|
&:not(:last-child) {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.NotificationGroup-header {
|
|
||||||
font-weight: bold;
|
|
||||||
color: @heading-color !important;
|
|
||||||
padding: 6px 15px;
|
|
||||||
display: block;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
.NotificationGroup-badges {
|
|
||||||
margin-left: -2px;
|
|
||||||
margin-right: 18px;
|
|
||||||
vertical-align: 1px;
|
|
||||||
|
|
||||||
.Badge {
|
&-header {
|
||||||
margin-right: -13px;
|
font-weight: bold;
|
||||||
position: relative;
|
color: @heading-color !important;
|
||||||
.Badge--size(21px);
|
padding: 8px 16px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
// Prevent outline overflowing parent
|
||||||
|
.add-keyboard-focus-ring-offset(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
&-badges {
|
||||||
|
@overlap: 13px;
|
||||||
|
|
||||||
|
margin-right: 8px;
|
||||||
|
padding-right: @overlap;
|
||||||
|
|
||||||
|
.Badge {
|
||||||
|
margin-right: -@overlap;
|
||||||
|
position: relative;
|
||||||
|
.Badge--size(21px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-content {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.NotificationGroup-content {
|
|
||||||
list-style: none;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
.Notification {
|
.Notification {
|
||||||
display: block;
|
padding: 8px 16px;
|
||||||
padding: 8px 15px 8px 70px;
|
|
||||||
color: @muted-color !important; // required to override .light-contents applied to header
|
color: @muted-color !important; // required to override .light-contents applied to header
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
.unread& {
|
display: grid;
|
||||||
|
grid-template-columns: auto auto 1fr auto;
|
||||||
|
|
||||||
|
grid-template-areas:
|
||||||
|
"avatar icon title button"
|
||||||
|
"x x excerpt excerpt";
|
||||||
|
|
||||||
|
align-items: baseline;
|
||||||
|
row-gap: 1px;
|
||||||
|
column-gap: 6px;
|
||||||
|
|
||||||
|
// Prevent outline overflowing parent
|
||||||
|
.add-keyboard-focus-ring-offset(-1px);
|
||||||
|
|
||||||
|
&.unread {
|
||||||
background: @control-bg;
|
background: @control-bg;
|
||||||
}
|
}
|
||||||
&:hover {
|
|
||||||
|
&:hover,
|
||||||
|
&:focus,
|
||||||
|
&:focus-within {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
background: @control-bg;
|
background: @control-bg;
|
||||||
|
|
||||||
.Notification-action {
|
.Notification-action {
|
||||||
display: block;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.Avatar {
|
.Avatar {
|
||||||
.Avatar--size(24px);
|
.Avatar--size(24px);
|
||||||
float: left;
|
grid-area: avatar;
|
||||||
margin: -2px 0 -2px -55px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-icon {
|
||||||
|
font-size: 14px;
|
||||||
|
grid-area: icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-title {
|
||||||
|
grid-area: title;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: baseline;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-content {
|
||||||
|
line-height: 19px;
|
||||||
|
margin-right: 8px;
|
||||||
|
|
||||||
|
.username {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
time {
|
time {
|
||||||
|
line-height: inherit;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
|
line-height: 19px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
.Notification-action {
|
&-action {
|
||||||
float: right;
|
|
||||||
display: none;
|
|
||||||
margin-top: -7px;
|
|
||||||
margin-right: -10px;
|
|
||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
padding: 5px 0;
|
padding: 0;
|
||||||
|
opacity: 0;
|
||||||
|
|
||||||
& when (@config-colored-header = true) {
|
.add-keyboard-focus-ring();
|
||||||
.Button--color(@control-color, @control-bg);
|
.add-keyboard-focus-ring-offset(4px);
|
||||||
|
|
||||||
&:hover {
|
grid-area: button;
|
||||||
|
|
||||||
|
// Needs more specificity to fix hover/focus styles not applying in dropdown
|
||||||
|
.Notification & when (@config-colored-header = true) {
|
||||||
|
color: @control-color;
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&:focus {
|
||||||
color: @link-color;
|
color: @link-color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
font-size: 12px;
|
font-size: 13px;
|
||||||
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.Notification-icon {
|
|
||||||
float: left;
|
|
||||||
margin-left: -23px;
|
|
||||||
font-size: 14px;
|
|
||||||
margin-top: 2px;
|
|
||||||
}
|
|
||||||
.Notification-content {
|
|
||||||
margin-right: 5px;
|
|
||||||
|
|
||||||
.username {
|
&-excerpt {
|
||||||
font-weight: bold;
|
grid-area: excerpt;
|
||||||
|
color: @muted-more-color;
|
||||||
|
font-size: 11px;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.Notification-excerpt {
|
|
||||||
color: @muted-more-color;
|
|
||||||
font-size: 11px;
|
|
||||||
margin-top: 3px;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user