forked from scratchfoundation/scratch-editor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwelcome-modal.jsx
More file actions
207 lines (198 loc) · 7.66 KB
/
Copy pathwelcome-modal.jsx
File metadata and controls
207 lines (198 loc) · 7.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { defineMessages, FormattedMessage } from 'react-intl';
import rubyIcon from './icon-ruby.svg';
import styles from './welcome-modal.css';
const messages = defineMessages({
title: {
id: 'gui.welcomeModal.title',
defaultMessage: 'Welcome to Smalruby',
description: 'Welcome modal title',
},
lead: {
id: 'gui.welcomeModal.lead',
defaultMessage:
'Smalruby is a free programming environment from Japan. ' +
'Build with blocks, then move on to Ruby — all in your browser.',
description: 'Welcome modal lead paragraph (desktop)',
},
leadShort: {
id: 'gui.welcomeModal.leadShort',
defaultMessage: 'Build with blocks, step up to Ruby — all in your browser.',
description: 'Welcome modal lead paragraph (compact, narrow screens)',
},
cardBlocksTitle: {
id: 'gui.welcomeModal.cardBlocksTitle',
defaultMessage: 'Build with blocks',
description: 'Welcome modal card 1 title',
},
cardBlocksDesc: {
id: 'gui.welcomeModal.cardBlocksDesc',
defaultMessage: 'Drag blocks to make games and animations.',
description: 'Welcome modal card 1 description',
},
cardBlocksDescShort: {
id: 'gui.welcomeModal.cardBlocksDescShort',
defaultMessage: 'Make games and animations.',
description: 'Welcome modal card 1 description (compact, narrow screens)',
},
cardRubyTitle: {
id: 'gui.welcomeModal.cardRubyTitle',
defaultMessage: 'Step up to Ruby',
description: 'Welcome modal card 2 title',
},
cardRubyDesc: {
id: 'gui.welcomeModal.cardRubyDesc',
defaultMessage: 'Switch to text code with furigana support.',
description: 'Welcome modal card 2 description',
},
cardRubyDescShort: {
id: 'gui.welcomeModal.cardRubyDescShort',
defaultMessage: 'Step up with furigana support.',
description: 'Welcome modal card 2 description (compact, narrow screens)',
},
cardMeshTitle: {
id: 'gui.welcomeModal.cardMeshTitle',
defaultMessage: 'Connect with friends',
description: 'Welcome modal card 3 title',
},
cardMeshDesc: {
id: 'gui.welcomeModal.cardMeshDesc',
defaultMessage: 'Use Mesh to share data between devices in real time.',
description: 'Welcome modal card 3 description',
},
cardMeshDescShort: {
id: 'gui.welcomeModal.cardMeshDescShort',
defaultMessage: 'Connect multiple devices to play.',
description: 'Welcome modal card 3 description (compact, narrow screens)',
},
startTutorial: {
id: 'gui.welcomeModal.startTutorial',
defaultMessage: 'Start the first tutorial',
description: 'Welcome modal primary CTA on desktop — opens the tutorials library',
},
learnMore: {
id: 'gui.welcomeModal.learnMore',
defaultMessage: 'Learn more about Smalruby',
description: 'Welcome modal secondary CTA — opens about.html',
},
later: {
id: 'gui.welcomeModal.later',
defaultMessage: 'Maybe later',
description: 'Welcome modal dismiss button',
},
});
const Card = ({ icon, titleMessage, descMessage }) => (
<div className={styles.card}>
{icon}
<h3 className={styles.cardTitle}>
<FormattedMessage {...titleMessage} />
</h3>
<p className={styles.cardDesc}>
<FormattedMessage {...descMessage} />
</p>
</div>
);
Card.propTypes = {
descMessage: PropTypes.object.isRequired,
icon: PropTypes.node.isRequired,
titleMessage: PropTypes.object.isRequired,
};
// On narrow viewports the tipsLibrary (image-heavy, fixed-width) is hidden and
// /about.html is promoted to the primary CTA instead.
const WelcomeModal = ({ isNarrow, onStartTutorial, onLearnMore, onLater }) => {
const primary = isNarrow ? (
<button
className={styles.primaryButton}
onClick={onLearnMore}
data-testid="welcome-modal-learn-more"
>
<FormattedMessage {...messages.learnMore} />
</button>
) : (
<button
className={styles.primaryButton}
onClick={onStartTutorial}
data-testid="welcome-modal-start-tutorial"
>
<FormattedMessage {...messages.startTutorial} />
</button>
);
return (
<div
className={styles.overlay}
role="dialog"
aria-modal="true"
aria-labelledby="welcome-modal-title"
data-testid="welcome-modal"
>
<div className={classNames(styles.dialog, { [styles.narrow]: isNarrow })}>
<div className={styles.dialogBody}>
<h2 className={styles.title} id="welcome-modal-title">
<FormattedMessage {...messages.title} />
</h2>
<p className={styles.lead}>
<FormattedMessage {...(isNarrow ? messages.leadShort : messages.lead)} />
</p>
<div className={styles.cards}>
<Card
icon={<div className={styles.cardEmoji}>{'🧩'}</div>}
titleMessage={messages.cardBlocksTitle}
descMessage={isNarrow ? messages.cardBlocksDescShort : messages.cardBlocksDesc}
/>
<Card
icon={
<img
alt=""
aria-hidden="true"
className={styles.cardIcon}
src={rubyIcon}
/>
}
titleMessage={messages.cardRubyTitle}
descMessage={isNarrow ? messages.cardRubyDescShort : messages.cardRubyDesc}
/>
<Card
icon={<div className={styles.cardEmoji}>{'🌐'}</div>}
titleMessage={messages.cardMeshTitle}
descMessage={isNarrow ? messages.cardMeshDescShort : messages.cardMeshDesc}
/>
</div>
</div>
<div className={styles.buttons}>
{primary}
<div className={styles.secondaryButtons}>
{!isNarrow && (
<button
className={styles.linkButton}
onClick={onLearnMore}
data-testid="welcome-modal-learn-more"
>
<FormattedMessage {...messages.learnMore} />
</button>
)}
<button
className={styles.linkButton}
onClick={onLater}
data-testid="welcome-modal-later"
>
<FormattedMessage {...messages.later} />
</button>
</div>
</div>
</div>
</div>
);
};
WelcomeModal.propTypes = {
isNarrow: PropTypes.bool,
onLater: PropTypes.func.isRequired,
onLearnMore: PropTypes.func.isRequired,
onStartTutorial: PropTypes.func.isRequired,
};
WelcomeModal.defaultProps = {
isNarrow: false,
};
export { messages };
export default WelcomeModal;