Skip to content

Commit 86d5c87

Browse files
committed
auto-fit card headers
1 parent 9b17c28 commit 86d5c87

File tree

4 files changed

+72
-28
lines changed

4 files changed

+72
-28
lines changed

package-lock.json

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"pg": "^8.5.1",
3333
"react": "17.0.1",
3434
"react-dom": "17.0.1",
35+
"react-textfit": "^1.1.1",
3536
"short-uuid": "^4.1.0",
3637
"sqlite3": "^5.0.0"
3738
},
@@ -44,6 +45,7 @@
4445
"@types/puppeteer": "^5.4.2",
4546
"@types/react": "^17.0.0",
4647
"@types/react-dom": "^17.0.0",
48+
"@types/react-textfit": "^1.1.0",
4749
"@types/sqlite3": "^3.1.6",
4850
"@typescript-eslint/eslint-plugin": "^4.11.0",
4951
"@typescript-eslint/parser": "^4.11.0",

src/components/Card.tsx

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from "react";
2+
import { Textfit } from "react-textfit";
23
import { Card as CardModel } from "../model/card";
34
import styles from "../styles/card.module.css";
45
import {
@@ -187,25 +188,25 @@ const Card: React.FC<{ name: CardName; usedForCritter?: boolean }> = ({
187188
return (
188189
<>
189190
<div className={styles.card}>
190-
<div className={styles.card_header_row}>
191-
<div className={[styles.circle, styles.card_header_symbol].join(" ")}>
191+
<div className={[styles.card_header_row, colorClass].join(" ")}>
192+
<div className={[styles.circle].join(" ")}>
192193
<CardTypeSymbol cardType={card.cardType} />
193194
</div>
194-
<div
195-
className={[
196-
styles.circle,
197-
styles.color_victory_point,
198-
styles.card_header_vp,
199-
].join(" ")}
200-
>
201-
<span className={styles.card_header_vp_number}>{card.baseVP}</span>
202-
</div>
203-
<div className={[styles.card_header, colorClass].join(" ")}>
204-
<span>{name}</span>
195+
<div className={styles.card_header}>
196+
<span>
197+
<Textfit min={1} max={12} mode="single">
198+
{name}
199+
</Textfit>
200+
</span>
205201
{card.expansion && (
206202
<span className={styles.expansion}>{card.expansion}</span>
207203
)}
208204
</div>
205+
<div
206+
className={[styles.circle, styles.color_victory_point].join(" ")}
207+
>
208+
<span className={styles.card_header_vp_number}>{card.baseVP}</span>
209+
</div>
209210
</div>
210211
<div className={styles.rarity_label}>
211212
{rarityLabel}

src/styles/card.module.css

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.card {
22
min-height: 200px;
3-
width: 240px;
3+
width: 200px;
44
border-radius: 5px;
55
position: relative;
66
border: 1px solid var(--border-color);
@@ -12,6 +12,14 @@
1212
justify-content: space-between;
1313
}
1414

15+
.card_header_row {
16+
display: flex;
17+
flex-wrap: nowrap;
18+
justify-content: space-between;
19+
width: 100%;
20+
overflow: hidden;
21+
}
22+
1523
.card_header {
1624
height: 35px;
1725
font-weight: var(--font-bold);
@@ -22,6 +30,8 @@
2230
display: flex;
2331
flex-direction: column;
2432
justify-content: center;
33+
flex: 1 1 auto;
34+
overflow: hidden;
2535
}
2636

2737
.expansion {
@@ -108,16 +118,10 @@
108118
width: 24px;
109119
height: 24px;
110120
margin: 6px;
111-
112121
text-align: center;
113122
font-size: 27px;
114-
}
115-
116-
.card_header_vp {
117-
position: absolute;
118-
top: 0;
119-
right: 0;
120-
z-index: 10;
123+
position: relative;
124+
flex: 0 0 auto;
121125
}
122126

123127
.card_header_vp_number {
@@ -127,12 +131,7 @@
127131
margin-top: -14px;
128132
vertical-align: middle;
129133
color: var(--color-vp-text);
130-
}
131-
132-
.card_header_symbol {
133-
position: absolute;
134-
top: 0;
135-
z-index: 10;
134+
flex: 0 0 auto;
136135
}
137136

138137
.color_victory_point {

0 commit comments

Comments
 (0)