Skip to content

Commit

Permalink
Roll v2 Keypad Onto Desktop Web (#711)
Browse files Browse the repository at this point in the history
https://github.com/Khan/perseus/assets/23404711/b199ff5b-9db6-4394-8ef3-120531564ab3

Updates Perseus / Math Input to use keypad.

Also changes how it's used: 

- Instead of a set of keys appearing on focus, the button on the right acts as a toggle.
- Instead of a warning icon appearing when there is an parsing, the input shows a red "invalid" state and a tooltip appears with a friendly message.
- `buttonsVisible` prop states changed:
  - `focused` default behavior, toggle off to start
  - `always` default behavior, toggle on to start
  - `never` toggle button disabled
- `buttonSets` type was marked as deprecated
  - `keypadButtonSets` prop added that takes new type
  - `buttonSets` maps to `keypadButtonSets`
- Also adds optional `extraKeys` prop that takes an array of `Keys`.

Author: nedredmond

Reviewers: jeremywiebe, nedredmond, handeyeco

Required Reviewers:

Approved By: jeremywiebe

Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage, ✅ Publish npm snapshot (ubuntu-latest, 16.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 16.x), ✅ Cypress (ubuntu-latest, 16.x), ✅ Extract i18n strings (ubuntu-latest, 16.x), ✅ Jest Coverage (ubuntu-latest, 16.x), ✅ Check builds for changes in size (ubuntu-latest, 16.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 16.x), ✅ gerald, ✅ Check for .changeset entries for all changed files (ubuntu-latest, 16.x)

Pull Request URL: #711
  • Loading branch information
nedredmond authored Oct 11, 2023
1 parent 3046780 commit 5bcf118
Show file tree
Hide file tree
Showing 18 changed files with 730 additions and 465 deletions.
9 changes: 9 additions & 0 deletions .changeset/great-pigs-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@khanacademy/perseus": major
"@khanacademy/perseus-editor": patch
---

# Update MathInput

- `buttonSets` is now deprecated in favor of `keypadButtonSets`, but currently maps to the new prop for backwards compatability.
- `buttonsVisible` is now a bit misleading: "focused" is the default state with a toggle-able keypad and "always" shows the keypad by default.
7 changes: 7 additions & 0 deletions .changeset/stale-otters-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@khanacademy/perseus": minor
"@khanacademy/math-input": minor
"@khanacademy/perseus-editor": minor
---

Desktop Expression Widget now uses v2 keypad
233 changes: 118 additions & 115 deletions packages/math-input/src/data/keys.ts
Original file line number Diff line number Diff line change
@@ -1,120 +1,123 @@
type Key =
| "PLUS"
| "MINUS"
| "NEGATIVE"
| "TIMES"
| "DIVIDE"
| "DECIMAL"
| "PERIOD"
| "PERCENT"
| "CDOT"
| "EQUAL"
| "NEQ"
| "GT"
| "LT"
| "GEQ"
| "LEQ" // mobile native only
| "FRAC_INCLUSIVE" // mobile native only
| "FRAC_EXCLUSIVE" // mobile native only
| "FRAC"
| "EXP"
| "EXP_2"
| "EXP_3"
| "SQRT"
| "CUBE_ROOT"
| "RADICAL"
| "LEFT_PAREN"
| "RIGHT_PAREN"
| "LN"
| "LOG"
| "LOG_N"
| "SIN"
| "COS" // TODO(charlie): Add in additional Greek letters.
| "TAN"
| "PI"
| "THETA"
| "UP"
| "RIGHT"
| "DOWN"
| "LEFT"
| "BACKSPACE"
| "DISMISS"
| "JUMP_OUT_PARENTHESES"
| "JUMP_OUT_EXPONENT"
| "JUMP_OUT_BASE"
| "JUMP_INTO_NUMERATOR"
| "JUMP_OUT_NUMERATOR"
| "JUMP_OUT_DENOMINATOR" // Multi-functional keys.
| "NOOP" // mobile native only
| "MANY" // A custom key that captures an arbitrary number of symbols but has no 'default' symbol or action.
| "NUM_0"
| "NUM_1"
| "NUM_2"
| "NUM_3"
| "NUM_4"
| "NUM_5"
| "NUM_6"
| "NUM_7"
| "NUM_8"
| "NUM_9"
| "a"
| "b"
| "c"
| "d"
| "e"
| "f"
| "g"
| "h"
| "i"
| "j"
| "k"
| "l"
| "m"
| "n"
| "o"
| "p"
| "q"
| "r"
| "s"
| "t"
| "u"
| "v"
| "w"
| "x"
| "y"
| "z"
| "A"
| "B"
| "C"
| "D"
| "E"
| "F"
| "G"
| "H"
| "I"
| "J"
| "K"
| "L"
| "M"
| "N"
| "O"
| "P"
| "Q"
| "R"
| "S"
| "T"
| "U"
| "V"
| "W"
| "X"
| "Y"
| "Z"
export const KeyArray = [
"PLUS",
"MINUS",
"NEGATIVE",
"TIMES",
"DIVIDE",
"DECIMAL",
"PERIOD",
"PERCENT",
"CDOT",
"EQUAL",
"NEQ",
"GT",
"LT",
"GEQ",
"LEQ", // mobile native only
"FRAC_INCLUSIVE", // mobile native only
"FRAC_EXCLUSIVE", // mobile native only
"FRAC",
"EXP",
"EXP_2",
"EXP_3",
"SQRT",
"CUBE_ROOT",
"RADICAL",
"LEFT_PAREN",
"RIGHT_PAREN",
"LN",
"LOG",
"LOG_N",
"SIN",
"COS", // TODO(charlie): Add in additional Greek letters.,
"TAN",
"PI",
"THETA",
"UP",
"RIGHT",
"DOWN",
"LEFT",
"BACKSPACE",
"DISMISS",
"JUMP_OUT_PARENTHESES",
"JUMP_OUT_EXPONENT",
"JUMP_OUT_BASE",
"JUMP_INTO_NUMERATOR",
"JUMP_OUT_NUMERATOR",
"JUMP_OUT_DENOMINATOR", // Multi-functional keys.
"NOOP", // mobile native only
"MANY", // A custom key that captures an arbitrary number of symbols but has no 'default' symbol or action.
"NUM_0",
"NUM_1",
"NUM_2",
"NUM_3",
"NUM_4",
"NUM_5",
"NUM_6",
"NUM_7",
"NUM_8",
"NUM_9",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",

// Currently only used by
// Perseus' Expression MathInput
| "PHI"
| "NTHROOT3"
| "POW"
| "LOG_B";
"PHI",
"NTHROOT3",
"POW",
"LOG_B",
] as const;

type Key = typeof KeyArray[number];

export default Key;
1 change: 1 addition & 0 deletions packages/math-input/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type {KeypadAPI, KeypadConfiguration} from "./types";

// Key list, configuration map, and types
export type {default as Keys} from "./data/keys";
export {KeyArray} from "./data/keys";
export {default as KeyConfigs} from "./data/key-configs";
export {type KeyType, KeypadType} from "./enums";

Expand Down
Loading

0 comments on commit 5bcf118

Please sign in to comment.