Skip to content

Commit

Permalink
Make a SharedRendererProps type (#1530)
Browse files Browse the repository at this point in the history
## Summary:
I don't know how useful this is, but this is my motivation: Khan/webapp#24684

## Test plan:
Nothing should change but types

Author: handeyeco

Reviewers: jeremywiebe

Required Reviewers:

Approved By: jeremywiebe

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

Pull Request URL: #1530
  • Loading branch information
handeyeco authored Aug 22, 2024
1 parent 0667abe commit 811f914
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-parrots-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Add SharedRendererProps type
30 changes: 14 additions & 16 deletions packages/perseus/src/article-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@ import Renderer from "./renderer";
import Util from "./util";

import type {PerseusRenderer} from "./perseus-types";
import type {APIOptions, PerseusDependenciesV2} from "./types";
import type {PerseusDependenciesV2, SharedRendererProps} from "./types";
import type {KeypadAPI} from "@khanacademy/math-input";
import type {KeypadContextRendererInterface} from "@khanacademy/perseus-core";
import type {LinterContextProps} from "@khanacademy/perseus-linter";

type Props = Partial<React.ContextType<typeof DependenciesContext>> & {
apiOptions: APIOptions;
json: PerseusRenderer | ReadonlyArray<PerseusRenderer>;
// Whether to use the new Bibliotron styles for articles
/**
* @deprecated Does nothing
*/
useNewStyles: boolean;
linterContext: LinterContextProps;
legacyPerseusLint?: ReadonlyArray<string>;
keypadElement?: KeypadAPI | null | undefined;
dependencies: PerseusDependenciesV2;
};

type Props = Partial<React.ContextType<typeof DependenciesContext>> &
SharedRendererProps & {
json: PerseusRenderer | ReadonlyArray<PerseusRenderer>;
// Whether to use the new Bibliotron styles for articles
/**
* @deprecated Does nothing
*/
useNewStyles: boolean;
legacyPerseusLint?: ReadonlyArray<string>;
keypadElement?: KeypadAPI | null | undefined;
dependencies: PerseusDependenciesV2;
};

type DefaultProps = {
apiOptions: Props["apiOptions"];
Expand Down
7 changes: 2 additions & 5 deletions packages/perseus/src/hint-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ import Renderer from "./renderer";
import {baseUnitPx, hintBorderWidth, kaGreen, gray97} from "./styles/constants";
import mediaQueries from "./styles/media-queries";

import type {APIOptions} from "./types";
import type {LinterContextProps} from "@khanacademy/perseus-linter";
import type {SharedRendererProps} from "./types";

type Props = {
apiOptions: APIOptions;
type Props = SharedRendererProps & {
className?: string;
hint: any;
lastHint?: boolean;
lastRendered?: boolean;
pos: number;
totalHints?: number;
findExternalWidgets?: any;
linterContext: LinterContextProps;
};

type DefaultProps = {
Expand Down
1 change: 1 addition & 0 deletions packages/perseus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export type {
VideoKind,
WidgetDict,
WidgetExports,
SharedRendererProps,
} from "./types";
export type {ParsedValue} from "./util";
export type {
Expand Down
11 changes: 6 additions & 5 deletions packages/perseus/src/server-item-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@ import Renderer from "./renderer";
import Util from "./util";

import type {PerseusItem, ShowSolutions} from "./perseus-types";
import type {APIOptions, FocusPath, PerseusDependenciesV2} from "./types";
import type {
FocusPath,
PerseusDependenciesV2,
SharedRendererProps,
} from "./types";
import type {KeypadAPI} from "@khanacademy/math-input";
import type {
KeypadContextRendererInterface,
RendererInterface,
KEScore,
} from "@khanacademy/perseus-core";
import type {LinterContextProps} from "@khanacademy/perseus-linter";
import type {PropsFor} from "@khanacademy/wonder-blocks-core";

const {mapObject} = Objective;

type OwnProps = {
apiOptions: APIOptions;
hintsVisible?: number;
item: PerseusItem;
linterContext: LinterContextProps;
problemNum?: number;
reviewMode?: boolean;
keypadElement?: KeypadAPI | null | undefined;
Expand All @@ -51,7 +52,7 @@ type HOCProps = {
onRendered: (isRendered: boolean) => void;
};

type Props = OwnProps & HOCProps;
type Props = SharedRendererProps & OwnProps & HOCProps;

type DefaultProps = Required<
Pick<Props, "apiOptions" | "onRendered" | "linterContext">
Expand Down
5 changes: 5 additions & 0 deletions packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,8 @@ export type ChangeFn = (
propValue?: any,
callback?: () => unknown,
) => any | null | undefined;

export type SharedRendererProps = {
apiOptions: APIOptions;
linterContext: LinterContextProps;
};

0 comments on commit 811f914

Please sign in to comment.