Skip to content

[DO NOT MERGE] Add story for MakeCode Editor without lang control #7

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions src/react/MakeCodeFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface MakeCodeFrameProps
version?: string;
lang?: string;
controller?: 1 | 2;
hideLanguage?: boolean;
// You can use these to specify query variants or other options not directly supported by this component
// https://github.com/microsoft/pxt-microbit/blob/master/pxtarget.json#L605C6-L605C14
queryParams?: Record<string, string>;
Expand Down Expand Up @@ -72,6 +73,7 @@ const MakeCodeFrame = forwardRef<MakeCodeFrameDriver, MakeCodeFrameProps>(
version,
lang,
controller,
hideLanguage,
queryParams,

initialProjects,
Expand Down Expand Up @@ -136,6 +138,7 @@ const MakeCodeFrame = forwardRef<MakeCodeFrameDriver, MakeCodeFrameProps>(
version,
lang,
controller,
hideLanguage,
queryParams
);
return (
Expand Down
18 changes: 18 additions & 0 deletions src/stories/react/MakeCodeFrame.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ export const MakeCodeEditorWithControlsStory: Story = {
},
};

export const MakeCodeEditorWithoutLangPickerStory: Story = {
name: 'MakeCode Editor without language picker',
args: {
version: 'default',
},
render: (args) => {
const { version } = args;
return (
<StoryWrapper>
<MakeCodeEditorWithControls
version={version === 'default' ? undefined : version}
hideLanguage
/>
</StoryWrapper>
);
},
};

export const MakeCodeEditorControllerAppModeStory: Story = {
name: 'MakeCode Editor with controller=2 mode',
args: {
Expand Down
11 changes: 11 additions & 0 deletions src/stories/vanilla/makecode-frame-driver.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface StoryArgs {
version?: string;
lang?: string;
controller?: 1 | 2;
hideLanguage?: boolean;
queryParams?: Record<string, string>;
};
project?: MakeCodeProject;
Expand Down Expand Up @@ -44,6 +45,7 @@ const renderEditor = (args: StoryArgs) => {
args.options?.version === 'default' ? undefined : args.options?.version,
args.options?.lang,
args.options?.controller ?? 1,
args.options?.hideLanguage,
args.options?.queryParams
);
iframe.width = '100%';
Expand Down Expand Up @@ -92,6 +94,15 @@ export const MakeCodeEditorWithControlsStory: Story = {
},
};

export const MakeCodeEditorWithoutLangPickerStory: Story = {
name: 'MakeCode Editor without language picker',
render: renderEditor,
args: {
options: { version: 'default', hideLanguage: true },
project: defaultMakeCodeProject,
},
};

export const MakeCodeEditorControllerAppModeStory: Story = {
name: 'MakeCode Editor with controller=2 mode',
render: renderEditor,
Expand Down
4 changes: 4 additions & 0 deletions src/vanilla/makecode-frame-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ export const createMakeCodeURL = (
version: string | undefined,
lang: string | undefined,
controller: number | undefined,
hideLanguage: boolean | undefined,
queryParams: Record<string, string> | undefined
): string => {
const url = new URL(
Expand All @@ -817,6 +818,9 @@ export const createMakeCodeURL = (
if (controller) {
url.searchParams.set('controller', controller.toString());
}
if (hideLanguage) {
url.searchParams.set('hidelanguage', '1')
}
if (queryParams) {
for (const [k, v] of Object.entries(queryParams)) {
url.searchParams.set(k, v);
Expand Down