Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-pumpkins-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/math-input": minor
---

Update Keypad to use WonderBlocks Tabs component

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,14 @@ exports[`mobile keypad should render keypad when active 1`] = `
class="default_xu2jcg inlineStyles_6alflt"
>
<div
class="default_xu2jcg-o_O-wrapper_144oaus"
class="default_xu2jcg wrapper "
>
<div
class="default_xu2jcg-o_O-tabbar_zvl22d"
>
<div
class="default_xu2jcg"
>
<button
aria-disabled="false"
aria-label="Dismiss"
aria-selected="false"
class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-clickable_1ncqa8p"
role="button"
tabindex="0"
type="button"
>
<div
class="default_xu2jcg-o_O-base_1pupywz"
>
<div
class="default_xu2jcg-o_O-innerBox_qdbgl3"
>
<svg
fill="none"
height="44"
viewBox="0 0 44 44"
width="44"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M28.7071 15.2929C28.3166 14.9024 27.6834 14.9024 27.2929 15.2929L22 20.5858L16.7071 15.2929C16.3166 14.9024 15.6834 14.9024 15.2929 15.2929C14.9024 15.6834 14.9024 16.3166 15.2929 16.7071L20.5858 22L15.2929 27.2929C14.9024 27.6834 14.9024 28.3166 15.2929 28.7071C15.6834 29.0976 16.3166 29.0976 16.7071 28.7071L22 23.4142L27.2929 28.7071C27.6834 29.0976 28.3166 29.0976 28.7071 28.7071C29.0976 28.3166 29.0976 27.6834 28.7071 27.2929L23.4142 22L28.7071 16.7071C29.0976 16.3166 29.0976 15.6834 28.7071 15.2929Z"
fill="rgba(33,36,44,0.64)"
fill-rule="evenodd"
/>
</svg>
</div>
</div>
</button>
</div>
</div>
<div
class="default_xu2jcg-o_O-keypadInnerContainer_huowys"
class="default_xu2jcg-o_O-inlineStyles_1hoepsr"
>
<div
aria-label="Keypad"
class="default_xu2jcg-o_O-keypadGrid_ztxlrb-o_O-fractionsGrid_1aelnry"
class="default_xu2jcg keypad-grid fractions-grid"
>
<div
class="default_xu2jcg-o_O-inlineStyles_1c2q4k1"
Expand Down Expand Up @@ -567,7 +527,7 @@ exports[`mobile keypad should render keypad when active 1`] = `
class="default_xu2jcg-o_O-outerBoxBase_3w5jmh"
>
<div
class="default_xu2jcg-o_O-base_muxx52-o_O-inlineStyles_wps3dh"
class="default_xu2jcg-o_O-base_muxx52-o_O-inlineStyles_s65xgl"
>
<svg
fill="none"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {View} from "@khanacademy/wonder-blocks-core";
import {semanticColor} from "@khanacademy/wonder-blocks-tokens";
import * as React from "react";

import FractionsPage from "./keypad-pages/fractions-page";
import styles from "./keypad.module.css";
import {RenderKeyPadPanel} from "./render-keypad-panel";

import type {KeypadProps} from "./keypad";
import type {KeypadPageType} from "../../types";

export type KeypadFractionsOnlyProps = Pick<
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear to me why we need both KeypadFractionsOnly and FractionsPage. Couldn't KeypadFractionsOnly just be part of Keypad?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

During the refactor i've separated the logic

  1. Displaying of the fractions only without any tabs
  2. Displaying of fractions together with other tabs

Both of this uses the FractionsPage, the first one is rendered directly from the KeyPad while the second one is is rendered via the util getAvailableTabs which will form the props that will be provided to the WB Tabs component.

Initially with #1 I added it in the Keypad component, but since it has a number of lines of code i decided to make it a different component so it will be easier to read in Keypad component like this (making the code dry):

// We don't want to show any available tabs on the fraction keypad
    if (fractionsOnly) {
        return <KeypadFractionsOnly {...props} />;
    }

KeypadProps,
| "fractionsOnly"
| "onClickKey"
| "cursorContext"
| "convertDotToTimes"
| "divisionKey"
| "expandedView"
>;

// Inline styles needed because CSS modules don't have enough specificity
// to override Wonder Blocks View default styles
const keypadInnerContainerStyle = {
display: "flex",
flexDirection: "row",
flexWrap: "nowrap",
backgroundColor: semanticColor.core.background.disabled.strong,
// Even in RTL languages, math is LTR.
// So we force this component to always render LTR
direction: "ltr",
} as const;

export function KeypadFractionsOnly(props: KeypadFractionsOnlyProps) {
const {onClickKey, cursorContext, expandedView} = props;
const selectedPage: KeypadPageType = "Fractions";

return (
<View className={expandedView ? styles.keypadOuterContainer : ""}>
<View
className={`${styles.wrapper} ${expandedView ? styles.expandedWrapper : ""}`}
>
<View style={keypadInnerContainerStyle}>
<RenderKeyPadPanel {...props} selectedPage={selectedPage}>
<FractionsPage
onClickKey={onClickKey}
cursorContext={cursorContext}
/>
</RenderKeyPadPanel>
</View>
</View>
</View>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from "react";
import KeyConfigs from "../../../data/key-configs";
import {useMathInputI18n} from "../../i18n-context";
import {KeypadButton} from "../keypad-button";
import {getCursorContextConfig} from "../utils";
import {getCursorContextConfig} from "../utils/get-cursor-context-config";

import type {ClickKeyCallback} from "../../../types";
import type {CursorContext} from "../../input/cursor-contexts";
Expand Down Expand Up @@ -121,7 +121,7 @@ export default function FractionsPage(props: Props) {
keyConfig={Keys.BACKSPACE}
onClickKey={onClickKey}
coord={[4, 3]}
action
secondary
/>
</>
);
Expand Down
35 changes: 35 additions & 0 deletions packages/math-input/src/components/keypad/keypad.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.keypad-outer-container {
display: flex;
align-items: center;
}

.wrapper {
background-color: var(--wb-semanticColor-core-background-base-default);
}

.expanded-wrapper {
border-width: 1px 1px 0 1px;
border-color: var(--wb-semanticColor-core-border-neutral-default);
/* see expandedViewThreshold */
max-width: 500px;
border-radius: 3px 3px 0 0;
}

.keypad-inner-container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
background-color: var(--wb-semanticColor-core-background-disabled-strong);
/* Even in RTL languages, math is LTR, So we force this component to always render LTR. */
direction: ltr;
}

.keypad-grid {
display: grid !important;
grid-template-rows: repeat(4, 1fr);
flex: 1;
}

.fractions-grid {
grid-template-columns: repeat(5, 1fr);
}
Loading
Loading