Skip to content

Commit f9b5c69

Browse files
committed
add method to adjust font-size property based on the input text
1 parent ef0c7a2 commit f9b5c69

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/components/CardModel.vue

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
<div>
99
<div class="card-name">
1010
<a @click="selectEntity(card)"
11-
:class="{'selected': card.selected, 'targetable': doingAction && targets.indexOf(card.id) !== -1}">{{card.properties.name}}
11+
:class="{'selected': card.selected, 'targetable': doingAction && targets.indexOf(card.id) !== -1}"
12+
:style="`font-size: ${adjustFontSize(card.properties.name)}em`">
13+
{{card.properties.name}}
1214
</a>
1315
</div>
1416
</div>
@@ -20,7 +22,8 @@
2022
</div>
2123
</div>
2224
<!-- card type -->
23-
<div class="card-type">
25+
<div class="card-type"
26+
:style="`font-size: ${adjustFontSize(card.properties.creatureType)}em`">
2427
{{card.properties.creatureType}}
2528
</div>
2629
<!-- card statistics -->
@@ -103,6 +106,25 @@ export default {
103106
methods: {
104107
resolveImage(path) {
105108
return require('../assets/images/cards/' + path);
109+
},
110+
111+
/**
112+
* Adjusts the size of the font to be displayed on a CardModel
113+
* based on the length of the text and whether it is all caps.
114+
*
115+
* @param {String} text - the text to decide the font size for
116+
* @return {Number} - the font size in em units
117+
*/
118+
adjustFontSize(text) {
119+
let baselineEm = 1.1;
120+
const isAllCaps = text === text.toUpperCase();
121+
const length = text.length;
122+
if (length >= 20) {
123+
baselineEm = isAllCaps ? 0.7 : 0.8;
124+
} else if (length >= 18) {
125+
baselineEm = isAllCaps ? 0.9 : 1.0;
126+
}
127+
return baselineEm;
106128
}
107129
},
108130
created() {

0 commit comments

Comments
 (0)