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
69 changes: 69 additions & 0 deletions newIDE/app/src/Course/TextBasedCourseChapterCalloutBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// @flow

import * as React from 'react';
import GDevelopThemeContext from '../UI/Theme/GDevelopThemeContext';
import { MarkdownText } from '../UI/MarkdownText';
import { Trans } from '@lingui/macro';
import ReactMarkdown from 'react-markdown';

type Props = {|
calloutType?: 'info' | 'warning' | 'tip' | 'note',
title: string,
text: string,
children?: React.Node,
|};

const TextBasedCourseChapterCalloutBlock = ({
title,
text,
calloutType = 'info',
children,
}: Props) => {
const gdevelopTheme = React.useContext(GDevelopThemeContext);

const isDarkMode = gdevelopTheme.palette.type === 'dark';
const backgroundColor = isDarkMode ? '#0f172a' : '#f3f4f6';
const borderColor = isDarkMode
? 'rgba(255, 255, 255, 0.08)'
: 'rgba(15, 23, 42, 0.15)';

const getIcon = (type: string): string => {
switch (type) {
case 'info':
return 'ℹ️';
case 'warning':
return '⚠️';
case 'tip':
return '💡';
case 'note':
return '📝';
default:
return '📝';
}
};

return (
<div
style={{
display: 'flex',
gap: 12,
padding: 16,
borderRadius: 8,
border: '1px solid transparent',
borderColor,
backgroundColor,
alignItems: 'flex-start',
fontFamily: gdevelopTheme.fontFamily || 'sans-serif',
}}
>
<div style={{ fontSize: 24, lineHeight: 1 }}>{getIcon(calloutType)}</div>
<div style={{ flex: 1 }}>
<div style={{ fontWeight: 'bold', marginBottom: 4 }}>{title}</div>

<MarkdownText key={title} allowParagraphs source={text} />
</div>
</div>
);
};

export default TextBasedCourseChapterCalloutBlock;
14 changes: 14 additions & 0 deletions newIDE/app/src/Course/TextBasedCourseChapterItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
TextBasedCourseChapterVideoItem as TextBasedCourseChapterVideoItemType,
TextBasedCourseChapterCodeItem as TextBasedCourseChapterCodeItemType,
TextBasedCourseChapterTableItem as TextBasedCourseChapterTableItemType,
TextBasedCourseChapterCalloutItem as TextBasedCourseChapterCalloutItemType,
} from '../Utils/GDevelopServices/Asset';
import GDevelopThemeContext from '../UI/Theme/GDevelopThemeContext';
import { MarkdownText } from '../UI/MarkdownText';
Expand All @@ -16,6 +17,7 @@ import TextBasedCourseChapterTaskItem from './TextBasedCourseChapterTaskItem';
import { ColumnStackLayout } from '../UI/Layout';
import { Column, Line } from '../UI/Grid';
import TextBasedCourseChapterCodeBlock from './TextBasedCourseChapterCodeBlock';
import TextBasedCourseChapterCalloutBlock from './TextBasedCourseChapterCalloutBlock';
import TextBasedCourseChapterTable from './TextBasedCourseChapterTable';

const styles = {
Expand All @@ -34,13 +36,15 @@ type Props = {|
| TextBasedCourseChapterImageItemType
| TextBasedCourseChapterVideoItemType
| TextBasedCourseChapterCodeItemType
| TextBasedCourseChapterCalloutItemType
| TextBasedCourseChapterTableItemType
>
| Array<
| TextBasedCourseChapterTextItemType
| TextBasedCourseChapterImageItemType
| TextBasedCourseChapterVideoItemType
| TextBasedCourseChapterCodeItemType
| TextBasedCourseChapterCalloutItemType
| TextBasedCourseChapterTableItemType
>,
|};
Expand Down Expand Up @@ -109,6 +113,16 @@ const TextBasedCourseChapterItems = ({
/>
);
}
if (item.type === 'callout') {
return (
<TextBasedCourseChapterCalloutBlock
key={itemIndex.toString()}
calloutType={'info'}
title={'title callout'}
text={item.text}
/>
);
}
if (item.type === 'table') {
return (
<TextBasedCourseChapterTable
Expand Down
12 changes: 12 additions & 0 deletions newIDE/app/src/UI/MarkdownText.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ const makeMarkdownCustomComponents = (
},
// eslint-disable-next-line jsx-a11y/alt-text
img: ({ node, ...props }) => <img style={{ display: 'flex' }} {...props} />,
code: ({ node, ...props }) => (
<code
style={{
backgroundColor: 'rgba(179, 179, 179, 0.24)',
border: '1px solid rgba(145, 145, 145, 0.46)',
padding: '2px 4px',
borderRadius: 4,
fontFamily: 'Monaco, "Courier New", monospace',
}}
{...props}
/>
),
});

type Props = {|
Expand Down
10 changes: 10 additions & 0 deletions newIDE/app/src/Utils/GDevelopServices/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ export type TextBasedCourseChapterCodeItem = {|
language?: string,
|};

export type TextBasedCourseChapterCalloutItem = {|
type: 'callout',
calloutType?: 'info' | 'warning' | 'tip' | 'note',
title: string,
text: string,
|};

export type TextBasedCourseChapterTableItem = {|
type: 'table',
header?: Array<string>,
Expand All @@ -272,6 +279,7 @@ export type TextBasedCourseChapterTaskItem = {|
| TextBasedCourseChapterImageItem
| TextBasedCourseChapterVideoItem
| TextBasedCourseChapterCodeItem
| TextBasedCourseChapterCalloutItem
| TextBasedCourseChapterTableItem
>,
answer?: {
Expand All @@ -280,6 +288,7 @@ export type TextBasedCourseChapterTaskItem = {|
| TextBasedCourseChapterImageItem
| TextBasedCourseChapterVideoItem
| TextBasedCourseChapterCodeItem
| TextBasedCourseChapterCalloutItem
| TextBasedCourseChapterTableItem
>,
},
Expand All @@ -298,6 +307,7 @@ export type UnlockedTextBasedCourseChapter = {|
| TextBasedCourseChapterTaskItem
| TextBasedCourseChapterVideoItem
| TextBasedCourseChapterCodeItem
| TextBasedCourseChapterCalloutItem
| TextBasedCourseChapterTableItem
>,
|};
Expand Down
31 changes: 30 additions & 1 deletion newIDE/app/src/fixtures/GDevelopServicesTestData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3224,6 +3224,27 @@ export const textBasedCourseChapter: TextBasedCourseChapter = {
shortTitle: 'Introduction',
};

export const textBasedCourseChapterWithCallout: TextBasedCourseChapter = {
title: 'test',
templates: [],
items: [
{
type: 'text',
text:
"Let's explore how JavaScript events can control objects in your game.",
},
{
type: 'callout',
calloutType: 'info',
title: 'title callout',
text:
'3 Ceci est un encaddré **informatif**. Il utilise les couleurs `blue` par défaut. Il est parfait pour fournir des détails supplémentaires ou des précisions techniques. Les blocs de `code` sont également bien formatés.',
},
],
id: 'callout javascript',
shortTitle: 'callout javascript',
};

export const textBasedCourseChapterWithCode: TextBasedCourseChapter = {
title: 'Scripting Basics',
templates: [],
Expand Down Expand Up @@ -3270,11 +3291,19 @@ export const textBasedCourseChapterWithTables: TextBasedCourseChapter = {
type: 'table',
header: ['Stat', 'Enemy', 'Player'],
rows: [
['>', '>=', 'right bugged'],
['\\>', '\\>=', 'right escaped'],
['<', '<=', 'left ok'],
['\\<', '\\<=', 'left escaped'],
['`code1`', '``code2``', '```code3```'],
['Health', '120', '100'],
['Damage', '12', '18'],
['Move speed', '160 px/s', '200 px/s'],
],
},
{
type: 'text',
text: ' `window`, ``console.log("hello");``, ```const test = 1;``` ',
},
{
type: 'text',
text:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @flow
import * as React from 'react';
import TextBasedCourseChapterCallout from '../../../Course/TextBasedCourseChapterCalloutBlock';
import paperDecorator from '../../PaperDecorator';

export default {
title: 'Course/TextBasedCourseChapterCallout',
component: TextBasedCourseChapterCallout,
decorators: [paperDecorator],
};

export const Info = () => (
<TextBasedCourseChapterCallout
calloutType="info"
title="Information"
text={
'Test 2: Ceci est un encadré **informatif**. Il utilise les couleurs `blue` par défaut. Il est parfait pour fournir des détails supplémentaires ou des précisions techniques. Les blocs de `code` sont également bien formatés.'
}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
textBasedCourseChapter,
textBasedCourseChapterWithCode,
textBasedCourseChapterWithTables,
textBasedCourseChapterWithCallout,
} from '../../../fixtures/GDevelopServicesTestData';

export default {
Expand Down Expand Up @@ -61,3 +62,18 @@ export const Chapter3 = () => {
/>
);
};

export const Chapter4 = () => {
return (
<TextBasedCourseChapterView
course={premiumCourse}
courseChapter={textBasedCourseChapterWithCallout}
onOpenTemplate={action('open template')}
onCompleteTask={action('onCompleteTask')}
isTaskCompleted={action('isTaskCompleted')}
getChapterCompletion={action('getChapterCompletion')}
chapterIndex={3}
onClickUnlock={() => action('onClickUnlock')()}
/>
);
};