Skip to content

Commit b83bdf3

Browse files
authored
Update new radio types to interface (#2554)
## Summary: Update new radio types to interface Issue: LEMS-3170 ## Test plan: - No visual and behavior changes, just confirm radio widget still works as expected Author: ivyolamit Reviewers: anakaren-rojas, SonicScrewdriver, mark-fitzgerald Required Reviewers: Approved By: anakaren-rojas, SonicScrewdriver Checks: ✅ 8 checks were successful Pull Request URL: #2554
1 parent b2647ed commit b83bdf3

File tree

8 files changed

+29
-20
lines changed

8 files changed

+29
-20
lines changed

.changeset/eleven-wolves-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/perseus": patch
3+
---
4+
5+
Update new radio types to interface

docs/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ specific render props the widget uses).
171171
### `RenderProps`
172172

173173
The `RenderProps` type defines the props that are returned by the widget's
174-
`transform` and `staticTransform` functions. If these fucntions are not defined
174+
`transform` and `staticTransform` functions. If these functions are not defined
175175
on the widget's `WidgetExport<T>` object, then `RenderProps` is synonymous with
176176
the widgets options type (ie. the type `T` wrapped in `WidgetOptions<T>` from
177177
`perseus-types.ts`).

packages/perseus/src/widgets/radio/base-radio.new.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import type {StyleDeclaration} from "aphrodite";
2424

2525
const {captureScratchpadTouchStart} = Util;
2626

27+
// TODO(LEMS-3170): Simplify the ChoiceType by using ChoiceProps directly.
2728
// exported for tests
28-
export type ChoiceType = {
29+
export interface ChoiceType {
2930
checked: boolean;
3031
content: React.ReactNode;
3132
rationale: React.ReactNode;
@@ -38,9 +39,9 @@ export type ChoiceType = {
3839
previouslyAnswered: boolean;
3940
revealNoneOfTheAbove: boolean;
4041
disabled: boolean;
41-
};
42+
}
4243

43-
type Props = {
44+
interface BaseRadioProps {
4445
apiOptions: APIOptions;
4546
choices: ReadonlyArray<ChoiceType>;
4647
deselectEnabled?: boolean;
@@ -61,7 +62,7 @@ type Props = {
6162
// Renderer. Determines whether we'll auto-scroll the page upon
6263
// entering review mode.
6364
isLastUsedWidget?: boolean;
64-
};
65+
}
6566

6667
/**
6768
* The BaseRadio component is the core component for the radio widget.
@@ -85,7 +86,7 @@ const BaseRadio = ({
8586
numCorrect,
8687
isLastUsedWidget,
8788
onChange,
88-
}: Props): React.ReactElement => {
89+
}: BaseRadioProps): React.ReactElement => {
8990
const {strings} = usePerseusI18n();
9091

9192
// useEffect doesn't have previous props

packages/perseus/src/widgets/radio/choice-icon/choice-icon.new.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {getChoiceLetter} from "../util";
1414

1515
import choiceIconStyles, {CHOICE_ICON_SIZE} from "./choice-icon-styles";
1616

17-
type ChoiceIconProps = {
17+
interface ChoiceIconProps {
1818
pos: number;
1919
checked: boolean;
2020
focused: boolean;
@@ -25,13 +25,13 @@ type ChoiceIconProps = {
2525
multipleSelect: boolean;
2626
reviewMode: boolean;
2727
previouslyAnswered: boolean;
28-
};
28+
}
2929

30-
type ChoiceInnerProps = {
30+
interface ChoiceInnerProps {
3131
pos: number;
3232
showCorrectness: boolean;
3333
correct: boolean | null | undefined;
34-
};
34+
}
3535

3636
function ChoiceInner(props: ChoiceInnerProps) {
3737
const {pos, showCorrectness, correct} = props;

packages/perseus/src/widgets/radio/choice-none-above.new.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Choice from "./choice.new";
77

88
import type {ChoiceProps} from "./choice.new";
99

10-
interface Props extends ChoiceProps {
10+
interface ChoiceNoneAboveProps extends ChoiceProps {
1111
showContent?: boolean;
1212
}
1313

@@ -18,7 +18,10 @@ interface Props extends ChoiceProps {
1818
*
1919
* TODO(LEMS-2994): Clean up this file.
2020
*/
21-
const ChoiceNoneAbove = React.forwardRef<HTMLButtonElement, Props>(
21+
const ChoiceNoneAbove = React.forwardRef<
22+
HTMLButtonElement,
23+
ChoiceNoneAboveProps
24+
>(
2225
(
2326
{content, showContent = true, ...otherChoiceProps},
2427
forwardedRef,

packages/perseus/src/widgets/radio/choice.new.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {APIOptions} from "../../types";
1818
const intermediateCheckboxPadding = `16px 16px`;
1919
const intermediateCheckboxPaddingPhone = `12px 16px`;
2020

21-
export type ChoiceProps = {
21+
export interface ChoiceProps {
2222
apiOptions?: APIOptions;
2323
checked?: boolean;
2424
rationale: React.ReactNode;
@@ -41,7 +41,7 @@ export type ChoiceProps = {
4141
// an object with a `checked` key. It contains a boolean value specifying
4242
// the new checked value of this choice.
4343
onChange?: (newValues: {checked: boolean}) => void;
44-
};
44+
}
4545

4646
/**
4747
* This component is a duplicate of the Choice component in choice.tsx

packages/perseus/src/widgets/radio/focus-ring.new.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as React from "react";
77

88
import * as styleConstants from "../../styles/constants";
99

10-
type Props = {
10+
interface FocusRingProps {
1111
children?: React.ReactNode;
1212
// Whether the focus ring is visible. Allows for positioning
1313
// the child identically regardless of whether the ring is visible.
@@ -16,7 +16,7 @@ type Props = {
1616
color?: string;
1717
// Whether a user can select multiple options or not
1818
multipleSelect?: boolean;
19-
};
19+
}
2020

2121
/**
2222
* This component is a duplicate of the FocusRing component in focus-ring.tsx
@@ -30,7 +30,7 @@ const FocusRing = ({
3030
color = styleConstants.kaGreen,
3131
multipleSelect = false,
3232
children,
33-
}: Props): React.ReactElement => {
33+
}: FocusRingProps): React.ReactElement => {
3434
const borderColor = visible ? color : "transparent";
3535
const borderRadius = multipleSelect ? 5 : "50%";
3636
const style = {

packages/perseus/src/widgets/radio/option-status.new.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import {usePerseusI18n} from "../../components/i18n-context";
1414

1515
import {getOptionStatusText} from "./utils/string-utils";
1616

17-
type Props = {
17+
interface OptionStatusProps {
1818
// Was this option the correct answer?
1919
correct: boolean;
2020
// Did the user select this option as the answer?
2121
checked: boolean;
2222
// Did the user select this option as the answer earlier?
2323
previouslyAnswered: boolean;
2424
reviewMode: boolean;
25-
};
25+
}
2626

2727
/**
2828
* This component is a duplicate of the OptionStatus component in option-status.tsx
@@ -36,7 +36,7 @@ const OptionStatus = ({
3636
correct,
3737
previouslyAnswered,
3838
reviewMode,
39-
}: Props): React.ReactElement | null => {
39+
}: OptionStatusProps): React.ReactElement | null => {
4040
const {strings} = usePerseusI18n();
4141

4242
// Option status is shown only in review mode, or for incorrectly

0 commit comments

Comments
 (0)