Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8040 from vanilla/feature/kb-user-dropdown
New MeBox User drop down
- Loading branch information
Showing
17 changed files
with
343 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @author Stéphane LaFlèche <stephane.l@vanillaforums.com> | ||
* @copyright 2009-2018 Vanilla Forums Inc. | ||
* @license GPL-2.0-only | ||
*/ | ||
|
||
import * as React from "react"; | ||
import classNames from "classnames"; | ||
import numeral from "numeral"; | ||
|
||
interface IProps { | ||
value: number; | ||
className?: string; | ||
} | ||
|
||
/** | ||
* A component to format numbers. The react number format supports localization. The way we'll pass in the options are TBD. | ||
*/ | ||
export default class NumberFormatted extends React.Component<IProps> { | ||
public render() { | ||
numeral.localeData("en"); // | ||
const { className } = this.props; | ||
const value = numeral(this.props.value); | ||
const compactValue = this.stripTrailingZeros(value.format("0a.0")); | ||
const fullValue = value.format(); | ||
|
||
const Tag = fullValue === compactValue ? `span` : `abbr`; | ||
return ( | ||
<Tag title={fullValue} className={classNames("number", className)}> | ||
{compactValue} | ||
</Tag> | ||
); | ||
} | ||
|
||
private stripTrailingZeros(value: string) { | ||
if (isNaN(Number(value))) { | ||
return value; | ||
} else { | ||
return Number(value).toString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
library/src/scripts/components/dropdown/items/DropDownItemLinkWithCount.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* @author Stéphane LaFlèche <stephane.l@vanillaforums.com> | ||
* @copyright 2009-2018 Vanilla Forums Inc. | ||
* @license GPL-2.0-only | ||
*/ | ||
|
||
import * as React from "react"; | ||
import DropDownItemLink, { IDropDownItemLink } from "@library/components/dropdown/items/DropDownItemLink"; | ||
import NumberFormatted from "@library/components/NumberFormatted"; | ||
import classNames from "classnames"; | ||
|
||
interface IProps extends IDropDownItemLink { | ||
count?: number; | ||
hideCountWhenZero?: boolean; | ||
className?: string; | ||
} | ||
|
||
/** | ||
* Implements link type of item with count for DropDown menu | ||
*/ | ||
export default class DropDownItemLinkWithCount extends React.Component<IProps> { | ||
public static defaultProps = { | ||
hideCountWhenZero: true, | ||
}; | ||
public render() { | ||
const { name, children, count } = this.props; | ||
const linkContents = children ? children : name; | ||
const showCount = !!count && !(this.props.hideCountWhenZero && this.props.count === 0); | ||
return ( | ||
<DropDownItemLink {...this.props}> | ||
<span className="dropDownItem-text">{linkContents}</span> | ||
{showCount && ( | ||
<NumberFormatted | ||
className={classNames("dropDownItem-count", this.props.className)} | ||
value={count!} | ||
/> | ||
)} | ||
</DropDownItemLink> | ||
); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
library/src/scripts/components/dropdown/items/DropDownSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* @author Stéphane LaFlèche <stephane.l@vanillaforums.com> | ||
* @copyright 2009-2018 Vanilla Forums Inc. | ||
* @license GPL-2.0-only | ||
*/ | ||
|
||
import * as React from "react"; | ||
import classNames from "classnames"; | ||
import DropDownItem from "./DropDownItem"; | ||
import Heading from "@library/components/Heading"; | ||
import DropDownItemSeparator from "@library/components/dropdown/items/DropDownItemSeparator"; | ||
|
||
interface IProps { | ||
title: string; | ||
className?: string; | ||
level?: 2 | 3; | ||
children: React.ReactNode; | ||
} | ||
|
||
/** | ||
* Implements DropDownSection component. It add a heading to a group of elements in a DropDown menu | ||
*/ | ||
export default class DropDownSection extends React.Component<IProps> { | ||
public render() { | ||
return ( | ||
<React.Fragment> | ||
<DropDownItemSeparator /> | ||
<DropDownItem className={classNames("dropDown-section", this.props.className)}> | ||
<Heading title={this.props.title} className="dropDown-sectionHeading" /> | ||
<ul className="dropDown-sectionContents">{this.props.children}</ul> | ||
</DropDownItem> | ||
</React.Fragment> | ||
); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
library/src/scripts/components/dropdown/items/DropDownUserCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* @author Stéphane LaFlèche <stephane.l@vanillaforums.com> | ||
* @copyright 2009-2018 Vanilla Forums Inc. | ||
* @license GPL-2.0-only | ||
*/ | ||
|
||
import * as React from "react"; | ||
import classNames from "classnames"; | ||
import { UserPhoto, UserPhotoSize } from "@library/components/mebox/pieces/UserPhoto"; | ||
import { IInjectableUserState } from "@library/users/UsersModel"; | ||
import { connect } from "react-redux"; | ||
import UsersModel from "@library/users/UsersModel"; | ||
import SmartLink from "@library/components/navigation/SmartLink"; | ||
|
||
export interface IProps extends IInjectableUserState { | ||
className?: string; | ||
photoSize?: UserPhotoSize; | ||
} | ||
|
||
/** | ||
* Implements DropDownUserCard component for DropDown menus. | ||
*/ | ||
export class DropDownUserCard extends React.Component<IProps> { | ||
public render() { | ||
const currentUser = this.props.currentUser.data!; | ||
const profileLink = `${window.location.origin}/profile/${currentUser.name}`; | ||
return ( | ||
<li className={classNames("dropDown-userCard", this.props.className)}> | ||
<SmartLink to={profileLink} className="userDropDown-userCardPhotoLink"> | ||
<UserPhoto | ||
className="userDropDown-userCardPhoto" | ||
userInfo={currentUser} | ||
size={this.props.photoSize || UserPhotoSize.LARGE} | ||
/> | ||
</SmartLink> | ||
<SmartLink to={profileLink} className="userDropDown-userCardName" tabIndex={-1}> | ||
{currentUser.name} | ||
</SmartLink> | ||
</li> | ||
); | ||
} | ||
} | ||
const withRedux = connect(UsersModel.mapStateToProps); | ||
export default withRedux(DropDownUserCard); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.