Skip to content

Commit

Permalink
Update CardsList to use visual-card styling (getredash#3679)
Browse files Browse the repository at this point in the history
* Update CardsList to use old markup

* CR
  • Loading branch information
gabrieldutra authored and harveyrendell committed Nov 14, 2019
1 parent 136d21a commit 95e6800
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 49 deletions.
72 changes: 72 additions & 0 deletions client/app/assets/less/redash/redash-newstyle.less
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,78 @@ body {
float: right;
}

.visual-card {
background: #FFFFFF;
border: 1px solid fade(@redash-gray, 15%);
border-radius: 3px;
margin: 5px;
width: 212px;
padding: 15px 5px;
cursor: pointer;
box-shadow: none;
transition: transform 0.12s ease-out;
transition-duration: 0.3s;
transition-property: box-shadow;

display: flex;
align-items: center;

&:hover {
box-shadow: rgba(102, 136, 153, 0.15) 0px 4px 9px -3px;
}

img {
width: 64px !important;
height: 64px !important;
margin-right: 5px;
}

h3 {
font-size: 13px;
color: #323232;
margin: 0 !important;
text-overflow: ellipsis;
overflow: hidden;
}
}

@media (max-width: 1200px) {
.visual-card {
width: 217px;
}
}

@media (max-width: 755px) {
.visual-card {
width: 47%;
}
}

@media (max-width: 515px) {
.visual-card {
width: 47%;

img {
width: 48px;
height: 48px;
}
}
}

@media (max-width: 408px) {
.visual-card {
width: 100%;
padding: 5px;
margin: 5px 0;

img {
width: 48px;
height: 48px;
}
}
}


.t-header:not(.th-alt) {
padding: 15px;

Expand Down
50 changes: 23 additions & 27 deletions client/app/components/cards-list/CardsList.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import Card from 'antd/lib/card';
import Input from 'antd/lib/input';
import List from 'antd/lib/list';
import { includes, isEmpty } from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
import EmptyState from '@/components/items-list/components/EmptyState';

import './CardsList.less';

const { Search } = Input;
const { Meta } = Card;

export default class CardsList extends React.Component {
static propTypes = {
Expand All @@ -33,34 +28,36 @@ export default class CardsList extends React.Component {
searchText: '',
};

constructor(props) {
super(props);
this.items = [];

let itemId = 1;
props.items.forEach((item) => {
this.items.push({ id: itemId, ...item });
itemId += 1;
});
}

// eslint-disable-next-line class-methods-use-this
renderListItem(item) {
const card = (
<Card
size="small"
cover={(<div><img alt={item.title} src={item.imgSrc} /></div>)}
onClick={item.onClick}
hoverable
>
<Meta title={(<h3>{item.title}</h3>)} />
</Card>
);
return (
<List.Item className="cards-list-item">
{item.href ? (<a href={item.href}>{card}</a>) : card}
</List.Item>
<a key={`card${item.id}`} className="visual-card" onClick={item.onClick} href={item.href}>
<img alt={item.title} src={item.imgSrc} />
<h3>{item.title}</h3>
</a>
);
}

render() {
const { items, showSearch } = this.props;
const { showSearch } = this.props;
const { searchText } = this.state;

const filteredItems = items.filter(item => isEmpty(searchText) ||
const filteredItems = this.items.filter(item => isEmpty(searchText) ||
includes(item.title.toLowerCase(), searchText.toLowerCase()));

return (
<div className="cards-list" data-test="CardsList">
<div data-test="CardsList">
{showSearch && (
<div className="row p-10">
<div className="col-md-4 col-md-offset-4">
Expand All @@ -73,12 +70,11 @@ export default class CardsList extends React.Component {
</div>
)}
{isEmpty(filteredItems) ? (<EmptyState className="" />) : (
<List
className="p-10"
grid={{ gutter: 12, column: 6, xs: 1, sm: 3, lg: 4, xl: 6 }}
dataSource={filteredItems}
renderItem={item => this.renderListItem(item)}
/>
<div className="row">
<div className="col-lg-12 d-inline-flex flex-wrap">
{filteredItems.map(item => this.renderListItem(item))}
</div>
</div>
)}
</div>
);
Expand Down
22 changes: 0 additions & 22 deletions client/app/components/cards-list/CardsList.less

This file was deleted.

0 comments on commit 95e6800

Please sign in to comment.