summaryrefslogtreecommitdiff
path: root/HintButton.js
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2021-04-13 12:33:23 -0500
committersanine-a <sanine.not@pm.me>2021-04-13 12:33:23 -0500
commitad2e991545f37f3659f40d30c709133b4055bb9e (patch)
tree0db9e976d4141c506263d7949a159062018c61a6 /HintButton.js
parentc9c1b78ed805371615d3ca8b54c86da9a35db8ce (diff)
create hint button
Diffstat (limited to 'HintButton.js')
-rw-r--r--HintButton.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/HintButton.js b/HintButton.js
new file mode 100644
index 0000000..4e081fc
--- /dev/null
+++ b/HintButton.js
@@ -0,0 +1,37 @@
+function getHint(answer, level)
+{
+ const defaultText = 'Reveal Hint';
+
+ if (level === 0)
+ return defaultText;
+
+ if (level > 3 || level >= answer.length)
+ return answer;
+
+ let hint = '';
+ for (let i=0; i<answer.length; i++)
+ hint += i >= level ? '*' : answer[i];
+
+ // pad so that button size doesn't change
+ while (hint.length < defaultText.length)
+ hint = ` ${hint} `;
+
+ return hint;
+}
+
+
+function HintButton({ answer, hintLevel, handleClick })
+{
+ const hint = getHint(answer, hintLevel);
+
+ return h(
+ StyleButton,
+ { text: hint,
+ style: {
+ 'min-width': '100px',
+ },
+ enabled: true,
+ handleClick,
+ }
+ );
+}