@codecademy/codebytes 0.3.1-alpha.405be7.0 → 0.3.1-alpha.cef935.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ### [0.3.1-alpha.405be7.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.3.0...@codecademy/codebytes@0.3.1-alpha.405be7.0) (2022-01-13)
6
+ ### [0.3.1-alpha.cef935.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.3.0...@codecademy/codebytes@0.3.1-alpha.cef935.0) (2022-01-13)
7
7
 
8
8
  **Note:** Version bump only for package @codecademy/codebytes
9
9
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codecademy/codebytes",
3
3
  "description": "Codebytes Code Editor",
4
- "version": "0.3.1-alpha.405be7.0",
4
+ "version": "0.3.1-alpha.cef935.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "sideEffects": [
7
7
  "**/*.css",
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "b0c7c52677bf95764fd29e9baa58a30761858f85"
51
+ "gitHead": "0f05e194904faae9337cdbd57e84382acc355a92"
52
52
  }
package/src/consts.ts CHANGED
@@ -52,7 +52,7 @@ const scheme = `(begin
52
52
  (display "Hello world!")
53
53
  (newline))`;
54
54
 
55
- export const helloWorld = {
55
+ export const helloWorld: { [key in languageOption]?: string } = {
56
56
  cpp,
57
57
  csharp,
58
58
  golang,
@@ -61,4 +61,4 @@ export const helloWorld = {
61
61
  python,
62
62
  ruby,
63
63
  scheme,
64
- } as const;
64
+ };
package/src/editor.tsx CHANGED
@@ -13,6 +13,7 @@ import { postSnippet } from './api';
13
13
  import type { languageOption } from './consts';
14
14
  import { Drawers } from './drawers';
15
15
  import { SimpleMonacoEditor } from './MonacoEditor';
16
+ import { CodebytesChangeHandlerMap } from './types';
16
17
 
17
18
  const Output = styled.pre<{ hasError: boolean }>`
18
19
  width: 100%;
@@ -39,7 +40,7 @@ type EditorProps = {
39
40
  language: languageOption;
40
41
  text: string;
41
42
  onChange: (text: string) => void;
42
- onCopy?: (text: string, language: string) => void;
43
+ on?: CodebytesChangeHandlerMap;
43
44
  snippetsBaseUrl?: string;
44
45
  };
45
46
 
@@ -47,7 +48,7 @@ export const Editor: React.FC<EditorProps> = ({
47
48
  language,
48
49
  text,
49
50
  hideCopyButton,
50
- onCopy,
51
+ on = {},
51
52
  onChange,
52
53
  snippetsBaseUrl,
53
54
  }) => {
@@ -60,7 +61,7 @@ export const Editor: React.FC<EditorProps> = ({
60
61
  .writeText(text)
61
62
  // eslint-disable-next-line no-console
62
63
  .catch(() => console.error('Failed to copy'));
63
- onCopy?.(text, language);
64
+ on.copy?.(text, language);
64
65
  setIsCodeByteCopied(true);
65
66
  }
66
67
  };
@@ -80,6 +81,7 @@ export const Editor: React.FC<EditorProps> = ({
80
81
  };
81
82
  setStatus('waiting');
82
83
  setOutput('');
84
+ on.run?.();
83
85
 
84
86
  try {
85
87
  const response = await postSnippet(data, snippetsBaseUrl);
package/src/index.tsx CHANGED
@@ -8,19 +8,7 @@ import React, { useState } from 'react';
8
8
  import { helloWorld, languageOption } from './consts';
9
9
  import { Editor } from './editor';
10
10
  import { LanguageSelection } from './languageSelection';
11
-
12
- type CodebytesChangeHandler = (text: string, language: languageOption) => void;
13
-
14
- export interface CodeByteEditorProps {
15
- text: string;
16
- language: languageOption;
17
- hideCopyButton: boolean;
18
- onCopy?: CodebytesChangeHandler;
19
- isIFrame?: boolean;
20
- snippetsBaseUrl?: string;
21
- onEdit?: CodebytesChangeHandler;
22
- onLanguageChange?: CodebytesChangeHandler;
23
- }
11
+ import { CodeByteEditorProps } from './types';
24
12
 
25
13
  const editorStates = states({
26
14
  isIFrame: { height: '100vh' },
@@ -49,9 +37,8 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
49
37
  language: initialLanguage,
50
38
  hideCopyButton,
51
39
  isIFrame = false,
40
+ on = {},
52
41
  snippetsBaseUrl = process.env.CONTAINER_API_BASE,
53
- onEdit,
54
- onLanguageChange,
55
42
  }) => {
56
43
  const [text, setText] = useState<string>(initialText);
57
44
  const [language, setLanguage] = useState<languageOption>(initialLanguage);
@@ -65,6 +52,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
65
52
  target="_blank"
66
53
  rel="noreferrer"
67
54
  aria-label="visit codecademy.com"
55
+ onClick={() => on.logoClick?.()}
68
56
  />
69
57
  </Box>
70
58
  {language ? (
@@ -74,8 +62,9 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
74
62
  hideCopyButton={hideCopyButton}
75
63
  onChange={(newText: string) => {
76
64
  setText(newText);
77
- onEdit?.(newText, language);
65
+ on.edit?.(newText, language);
78
66
  }}
67
+ on={on}
79
68
  snippetsBaseUrl={snippetsBaseUrl}
80
69
  />
81
70
  ) : (
@@ -84,7 +73,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
84
73
  const newText: string = text || helloWorld[newLanguage] || '';
85
74
  setLanguage(newLanguage);
86
75
  setText(newText);
87
- onLanguageChange?.(newText, newLanguage);
76
+ on.languageChange?.(newText, newLanguage);
88
77
  }}
89
78
  />
90
79
  )}
@@ -1,10 +1,29 @@
1
- import { Select, Text } from '@codecademy/gamut';
2
- import { ColorMode } from '@codecademy/gamut-styles';
1
+ import { Select } from '@codecademy/gamut';
2
+ import { Background } from '@codecademy/gamut-styles';
3
+ import styled from '@emotion/styled';
3
4
  import React from 'react';
4
5
 
5
6
  import type { languageOption } from './consts';
6
7
  import { languageOptions } from './consts';
7
8
 
9
+ const StyledSelect = styled(Select)`
10
+ margin-top: 1rem;
11
+ color: ${({ theme }) => theme.colors.text};
12
+ select {
13
+ color: ${({ theme }) => theme.colors.text};
14
+ background-color: ${({ theme }) => theme.colors.black};
15
+
16
+ &:hover,
17
+ &:active,
18
+ &:focus {
19
+ border-color: ${({ theme }) => theme.colors.primary};
20
+ }
21
+ &:focus {
22
+ box-shadow: inset 0 0 0 1px ${({ theme }) => theme.colors.primary};
23
+ }
24
+ }
25
+ `;
26
+
8
27
  export type LanguageSelectionProps = {
9
28
  onChange: (newLanguage: languageOption) => void;
10
29
  };
@@ -13,14 +32,14 @@ export const LanguageSelection: React.FC<LanguageSelectionProps> = ({
13
32
  onChange,
14
33
  }) => {
15
34
  return (
16
- <ColorMode mode="dark" flex={1} px={16} pt={48}>
17
- <Text mb={16}>Which language do you want to code in?</Text>
18
- <Select
35
+ <Background bg="black" flex={1} px={16} pt={48}>
36
+ Which language do you want to code in?
37
+ <StyledSelect
19
38
  id="language-select"
20
39
  aria-label="Select a language"
21
40
  options={languageOptions}
22
41
  onChange={(e) => onChange(e.target.value as languageOption)}
23
42
  />
24
- </ColorMode>
43
+ </Background>
25
44
  );
26
45
  };
package/src/types.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { languageOption } from './consts';
2
+
3
+ type CodebytesChangeHandler = (text: string, language: languageOption) => void;
4
+
5
+ export type CodebytesChangeHandlerMap = {
6
+ logoClick?: () => void;
7
+ edit?: CodebytesChangeHandler;
8
+ languageChange?: CodebytesChangeHandler;
9
+ copy?: CodebytesChangeHandler;
10
+ run?: () => void;
11
+ };
12
+
13
+ export interface CodeByteEditorProps {
14
+ text: string;
15
+ language: languageOption;
16
+ hideCopyButton: boolean;
17
+ isIFrame?: boolean;
18
+ snippetsBaseUrl?: string /* TODO in DISC-353: Determine best way to host and include snippets endpoint for both staging and production in both the monolith and next.js repo. */;
19
+ on?: CodebytesChangeHandlerMap;
20
+ }