This repository has been archived by the owner on Feb 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(system-addon): Closes #2818 Port Highlight card UI to system addon
- Loading branch information
Showing
14 changed files
with
303 additions
and
58 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
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,71 @@ | ||
const React = require("react"); | ||
const LinkMenu = require("content-src/components/LinkMenu/LinkMenu"); | ||
const shortURL = require("content-src/lib/short-url"); | ||
const {FormattedMessage} = require("react-intl"); | ||
const cardContextTypes = require("./types"); | ||
|
||
/** | ||
* Card component. | ||
* Cards are found within a Section component and contain information about a link such | ||
* as preview image, page title, page description, and some context about if the page | ||
* was visited, bookmarked, trending etc... | ||
* Each Section can make an unordered list of Cards which will create one instane of | ||
* this class. Each card will then get a context menu which reflects the actions that | ||
* can be done on this Card. | ||
*/ | ||
class Card extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = {showContextMenu: false, activeCard: null}; | ||
} | ||
toggleContextMenu(event, index) { | ||
this.setState({showContextMenu: true, activeCard: index}); | ||
} | ||
setBackgroundImageStyle(image) { | ||
const style = {}; | ||
if (image) { | ||
style.backgroundImage = `url(${image})`; | ||
} else { | ||
style.display = "none"; | ||
} | ||
return style; | ||
} | ||
render() { | ||
const {index, link, dispatch} = this.props; | ||
const isContextMenuOpen = this.state.showContextMenu && this.state.activeCard === index; | ||
const hostname = shortURL(link); | ||
const {icon, intlID} = cardContextTypes[link.type]; | ||
|
||
return (<li className={`card-outer${isContextMenuOpen ? " active" : ""}`}> | ||
<a href={link.url}> | ||
<div className="card"> | ||
<div className="card-preview-image" style={this.setBackgroundImageStyle(link.image)} /> | ||
<div className="card-details"> | ||
<div className="card-host-name"> {hostname} </div> | ||
<h4 className="card-title"> {link.title} </h4> | ||
<p className={`card-description${link.image ? "" : " full-height"}`}> {link.description} </p> | ||
<div className="card-context"> | ||
<span className={`card-context-icon icon icon-${icon}`} /> | ||
<div className="card-context-label"><FormattedMessage id={intlID} defaultMessage="Visited" /></div> | ||
</div> | ||
</div> | ||
</div> | ||
</a> | ||
<button className="context-menu-button" | ||
onClick={e => { | ||
e.preventDefault(); | ||
this.toggleContextMenu(e, index); | ||
}}> | ||
<span className="sr-only">{`Open context menu for ${link.title}`}</span> | ||
</button> | ||
<LinkMenu | ||
dispatch={dispatch} | ||
visible={isContextMenuOpen} | ||
onUpdate={val => this.setState({showContextMenu: val})} | ||
index={index} | ||
site={link} | ||
options={link.context_menu_options} /> | ||
</li>); | ||
} | ||
} | ||
module.exports = Card; |
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,110 @@ | ||
.card-outer { | ||
$card-width: $grid-unit * 2 + $base-gutter; | ||
$card-height: 266px; | ||
$card-preview-image-height: 122px; | ||
$card-description-height: 34px; | ||
$card-description-height-max: 200px; | ||
|
||
background: $white; | ||
display: inline-block; | ||
margin-inline-end: $base-gutter; | ||
width: $card-width; | ||
border-radius: $border-radius; | ||
border-color: $faintest-black; | ||
height: $card-height; | ||
position: relative; | ||
@include context-menu-button; | ||
|
||
.card { | ||
height: 100%; | ||
border-radius: $border-radius; | ||
} | ||
|
||
> a { | ||
display: block; | ||
color: inherit; | ||
height: 100%; | ||
outline: none; | ||
position: absolute; | ||
|
||
&.active, &:focus { | ||
.card { | ||
@include fade-in; | ||
} | ||
} | ||
} | ||
|
||
&:hover, &:focus, &.active { | ||
outline: none; | ||
@include fade-in; | ||
@include context-menu-button-hover; | ||
} | ||
|
||
.card-preview-image { | ||
position: relative; | ||
background-size: cover; | ||
background-position: center; | ||
background-repeat: no-repeat; | ||
height: $card-preview-image-height; | ||
border-bottom-color: $faintest-black; | ||
border-bottom-style: solid; | ||
border-bottom-width: 1px; | ||
border-radius: $border-radius $border-radius 0 0; | ||
} | ||
|
||
.card-details { | ||
padding: 10px 16px 12px; | ||
} | ||
|
||
.card-host-name { | ||
color: $mid-light-grey; | ||
font-size: 10px; | ||
padding-bottom: 4px; | ||
text-transform: uppercase; | ||
} | ||
|
||
.card-title { | ||
margin: 0 0 2px; | ||
font-size: inherit; | ||
word-wrap: break-word; | ||
} | ||
|
||
.card-description { | ||
font-size: 12px; | ||
margin: 0; | ||
word-wrap: break-word; | ||
overflow: hidden; | ||
line-height: 18px; | ||
max-height: $card-description-height; | ||
|
||
&.full-height { | ||
max-height: $card-description-height-max; | ||
} | ||
} | ||
|
||
.card-context { | ||
padding: 16px 16px 14px 14px; | ||
position: absolute; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
color: $light-grey; | ||
font-size: 11px; | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.card-context-icon { | ||
opacity: 0.5; | ||
font-size: 13px; | ||
margin-inline-end: 6px; | ||
display: block; | ||
} | ||
|
||
.card-context-label { | ||
flex-grow: 1; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} | ||
} |
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,14 @@ | ||
module.exports = { | ||
history: { | ||
intlID: "type_label_visited", | ||
icon: "historyItem" | ||
}, | ||
bookmark: { | ||
intlID: "type_label_bookmarked", | ||
icon: "bookmark" | ||
}, | ||
trending: { | ||
intlID: "type_label_recommended", | ||
icon: "trending" | ||
} | ||
}; |
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
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.