Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernization and Migration of InputWithExamples to NumericInput folder #2121

Open
wants to merge 5 commits into
base: feature/numeric-dx-refactor
Choose a base branch
from

Conversation

SonicScrewdriver
Copy link
Contributor

@SonicScrewdriver SonicScrewdriver commented Jan 16, 2025

Summary:

This PR is part of the Numeric Input Project work. It is being landed onto the feature/numeric-dx-refactor branch.

This PR contains the following changes:

  1. Moves the InputWithExamples component to the NumericInput folder
  2. Modernizes InputWithExamples to be a functional component
  3. Addition of some comments

Video Example of Snapshot Testing:

Screen.Recording.2025-01-16.at.2.45.52.PM.mov

Issue: LEMS-2785

Test plan:

  • Ensure all tests pass
  • Manual testing with PR Snapshot in upstream consumer
  • Landing onto feature branch that will see full QA regression pass before deployment

@SonicScrewdriver SonicScrewdriver self-assigned this Jan 16, 2025
@SonicScrewdriver SonicScrewdriver changed the title docs(changeset): Modernization and Migration of InputWithExamples to NumericInput folder Modernization and Migration of InputWithExamples to NumericInput folder Jan 16, 2025
Copy link
Contributor

github-actions bot commented Jan 16, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (64d86ca) and published it to npm. You
can install it using the tag PR2121.

Example:

yarn add @khanacademy/perseus@PR2121

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR2121

Copy link
Contributor

github-actions bot commented Jan 16, 2025

Size Change: +251 B (+0.02%)

Total Size: 1.47 MB

Filename Size Change
packages/perseus/dist/es/index.js 413 kB +251 B (+0.06%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 83.1 kB
packages/math-input/dist/es/index.js 78.1 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 23.1 kB
packages/perseus-editor/dist/es/index.js 689 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus-score/dist/es/index.js 103 kB
packages/perseus/dist/es/strings.js 5.04 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

const [state, setState] = React.useState<State>({
focused: false,
showExamples: false,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two variables are always set together, so I've opted to keep this pairing after the shift to the functional component. I wasn't sure of a good name to explain both of them so I went "generic", but I could easily see an argument to rename this to something like "setFocusStates".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...Wait. If these are always set the exact same thing in multiple places ... why do we even need both? I bet we could just use "focused".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this to just use a single inputFocused state.

@SonicScrewdriver SonicScrewdriver marked this pull request as ready for review January 16, 2025 23:12
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to keep this a separate file as it seemed like too long a component to append to the numeric-input file.

focus: () => {
if (inputRef.current) {
inputRef.current.focus();
inputRef.current?.focus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the optional (?) needed when we have the code within a conditional that checks for its existence? I thought that Typescript was able to understand that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooo I actually meant to replace the if conditional! Thank you for catching this

Copy link
Contributor

@mark-fitzgerald mark-fitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Great progress on all this clean-up work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants