Skip to content

Commit d88023b

Browse files
committed
CardTile: Add skeleton loading
Can be enabled by passing null to id, name or cost prop.
1 parent 1ab6c9f commit d88023b

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Added CardTile skeleton for null props
10+
811
### Changed
912
- Upgraded dependencies
1013

src/components/CardTile.tsx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as React from "react";
22
import styled, { injectGlobal } from "styled-components";
33

44
export interface CardTileProps extends React.ClassAttributes<CardTile> {
5-
id: string;
6-
name: string;
7-
cost: number;
5+
id: string | null;
6+
name: string | null;
7+
cost: number | null;
88
icon?: string;
99
rarity?: string;
1010
disabled?: boolean;
@@ -106,15 +106,17 @@ const CardTileNameBase = CardTileTextElement.extend`
106106
`;
107107

108108
const CardTileName = CardTileNameBase.extend`
109-
background-image: linear-gradient(
109+
background: linear-gradient(
110110
65deg,
111111
#313109,
112112
#313131 calc(100% - 96px),
113113
rgba(49, 49, 49, 0) calc(100% - 26px),
114114
rgba(49, 49, 49, 0)
115115
),
116-
${(props: React.HTMLProps<HTMLDivElement> & { cardId: string }) =>
117-
`url("https://art.hearthstonejson.com/v1/tiles/${props.cardId}.png")`};
116+
${(props: React.HTMLProps<HTMLDivElement> & { cardId: string | null }) =>
117+
props.cardId !== null
118+
? `url("https://art.hearthstonejson.com/v1/tiles/${props.cardId}.png")`
119+
: "rgba(255, 255, 255, 0.3)"};
118120
`;
119121

120122
const CardTileGem = CardTileTextElement.extend`
@@ -158,8 +160,18 @@ const CardTileCounter = (CardTileTextElement as any).extend`
158160
border-left: solid 1px black;
159161
`;
160162

163+
const SkeletonLine = (styled.span as any)`
164+
display: inline-block;
165+
background-color: rgba(255, 255, 255, 0.3);
166+
border-radius: 1em;
167+
height: 0.75em;
168+
width: ${(props: React.HTMLProps<HTMLSpanElement> & { width?: string }) =>
169+
props.width || 0};
170+
`;
171+
161172
export interface CardTileState {
162173
flashIndex: number;
174+
skeletonNameWidth?: string;
163175
}
164176

165177
export default class CardTile extends React.Component<
@@ -170,6 +182,7 @@ export default class CardTile extends React.Component<
170182
super(props, context);
171183
this.state = {
172184
flashIndex: 0,
185+
skeletonNameWidth: `${35 + Math.round(Math.random() * 35)}%`,
173186
};
174187
}
175188

@@ -190,7 +203,11 @@ export default class CardTile extends React.Component<
190203
return (
191204
<CardTileName cardId={this.props.id}>
192205
{this.props.icon ? <img src={this.props.icon} /> : null}
193-
{this.props.name}
206+
{this.props.name !== null ? (
207+
this.props.name
208+
) : (
209+
<SkeletonLine width={this.state.skeletonNameWidth} />
210+
)}
194211
</CardTileName>
195212
);
196213
}
@@ -223,7 +240,11 @@ export default class CardTile extends React.Component<
223240
<CardTileGem
224241
rarity={this.props.showRarity ? this.props.rarity : undefined}
225242
>
226-
{this.props.cost}
243+
{this.props.cost !== null ? (
244+
this.props.cost
245+
) : (
246+
<SkeletonLine width={"0.75em"} />
247+
)}
227248
</CardTileGem>
228249
{this.renderName()}
229250
{this.renderCount()}

0 commit comments

Comments
 (0)