|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+module rpgcards {
|
|
|
2
|
+
|
|
|
3
|
+ export interface DeckTileProps {
|
|
|
4
|
+ key : string; //< Unique key for react
|
|
|
5
|
+ id : string;
|
|
|
6
|
+ name : string;
|
|
|
7
|
+ desc : string;
|
|
|
8
|
+ cards : number;
|
|
|
9
|
+ }
|
|
|
10
|
+ function DeckTilePropsEqual(a:DeckTileProps, b:DeckTileProps) {
|
|
|
11
|
+ return a.id === b.id &&
|
|
|
12
|
+ a.name === b.name &&
|
|
|
13
|
+ a.desc === b.desc &&
|
|
|
14
|
+ a.cards === b.cards;
|
|
|
15
|
+ }
|
|
|
16
|
+
|
|
|
17
|
+ interface DeckTileState {
|
|
|
18
|
+ }
|
|
|
19
|
+
|
|
|
20
|
+ export function tileHeader(id: string, name: string) {
|
|
|
21
|
+ return React.DOM.div
|
|
|
22
|
+ ( { className: 'deck-tile-header', onClick: null }
|
|
|
23
|
+ , React.DOM.div({ className: 'deck-tile-header-name' }, name)
|
|
|
24
|
+ , React.DOM.div({ className: 'deck-tile-header-id' }, id.substring(0, 5))
|
|
|
25
|
+ );
|
|
|
26
|
+ }
|
|
|
27
|
+
|
|
|
28
|
+ export function tileBody(description: string) {
|
|
|
29
|
+ return React.DOM.div
|
|
|
30
|
+ ( { className: 'deck-tile-body', onClick: null }
|
|
|
31
|
+ , description
|
|
|
32
|
+ );
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ export function tileFooter(cards: number) {
|
|
|
36
|
+ let cardsText = "This deck contains " + cards + " cards.";
|
|
|
37
|
+ return React.DOM.div
|
|
|
38
|
+ ( { className: 'deck-tile-footer', onClick: null }
|
|
|
39
|
+ , cardsText
|
|
|
40
|
+ );
|
|
|
41
|
+ }
|
|
|
42
|
+
|
|
|
43
|
+ export class DeckTileSpec extends React.Component<DeckTileProps, DeckTileState> {
|
|
|
44
|
+ displayName: string;
|
|
|
45
|
+
|
|
|
46
|
+ initialState(props: DeckTileProps): DeckTileState {
|
|
|
47
|
+ return {};
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+ // Use this function to speed up rendering
|
|
|
51
|
+ /*
|
|
|
52
|
+ shouldComponentUpdate(nextProps: DeckTileProps, nextState: DeckTileState): boolean {
|
|
|
53
|
+ return DeckTilePropsEqual(this.props, nextProps);
|
|
|
54
|
+ }
|
|
|
55
|
+ */
|
|
|
56
|
+
|
|
|
57
|
+ constructor(props: DeckTileProps) {
|
|
|
58
|
+ super(props);
|
|
|
59
|
+ this.state = this.initialState(props);
|
|
|
60
|
+ this.displayName = "DeckTile";
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ render() {
|
|
|
64
|
+ let deckId = this.props.id;
|
|
|
65
|
+ let deckName = this.props.name;
|
|
|
66
|
+ let deckDesc = this.props.desc;
|
|
|
67
|
+ let deckCards = this.props.cards;
|
|
|
68
|
+
|
|
|
69
|
+ return React.DOM.div
|
|
|
70
|
+ ( { className: 'deck-tile' }
|
|
|
71
|
+ , tileHeader(deckId, deckName)
|
|
|
72
|
+ , tileBody(deckDesc)
|
|
|
73
|
+ , tileFooter(deckCards)
|
|
|
74
|
+ );
|
|
|
75
|
+ }
|
|
|
76
|
+ }
|
|
|
77
|
+
|
|
|
78
|
+ export var DeckTile: React.Factory<DeckTileProps> = React.createFactory(DeckTileSpec);
|
|
|
79
|
+}
|