Skip to content

Commit a03d4f0

Browse files
author
Ives van Hoorne
committed
Add font size option for embeds
1 parent c90dce7 commit a03d4f0

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

src/app/pages/Sandbox/Editor/Content/Header/ShareView.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const ShareOptions = styled.div`
5555
color: rgba(255, 255, 255, 0.8);
5656
padding: 1rem;
5757
58-
box-shadow: -1px 4px 5px rgba(0,0,0,0.5);
58+
box-shadow: -1px 4px 5px rgba(0, 0, 0, 0.5);
5959
background-color: ${props => props.theme.background2};
6060
6161
width: 900px;
@@ -120,9 +120,7 @@ const Column = styled.div`
120120
}
121121
`;
122122

123-
const ButtonContainer = styled.div`
124-
margin-top: 0.25rem;
125-
`;
123+
const ButtonContainer = styled.div`margin-top: 0.25rem;`;
126124

127125
const ButtonName = styled.div`
128126
margin: 0.5rem 0;
@@ -152,6 +150,7 @@ class ShareView extends React.PureComponent {
152150
defaultModule: null,
153151
autoResize: false,
154152
hideNavigation: false,
153+
fontSize: 16,
155154
};
156155

157156
handleChange = e => this.setState({ message: e.target.value });
@@ -178,6 +177,7 @@ class ShareView extends React.PureComponent {
178177
showPreview,
179178
autoResize,
180179
hideNavigation,
180+
fontSize,
181181
} = this.state;
182182

183183
const options = {};
@@ -201,6 +201,10 @@ class ShareView extends React.PureComponent {
201201
options.hidenavigation = 1;
202202
}
203203

204+
if (fontSize !== 16) {
205+
options.fontsize = fontSize;
206+
}
207+
204208
return optionsToParameterizedUrl(options);
205209
};
206210

@@ -247,9 +251,17 @@ class ShareView extends React.PureComponent {
247251
this.setState({ hideNavigation });
248252
};
249253

254+
setFontSize = (fontSize: number) => [this.setState({ fontSize })];
255+
250256
render() {
251257
const { sandbox, modules, directories } = this.props;
252-
const { showEditor, showPreview, autoResize, hideNavigation } = this.state;
258+
const {
259+
showEditor,
260+
showPreview,
261+
autoResize,
262+
hideNavigation,
263+
fontSize,
264+
} = this.state;
253265

254266
const defaultModule =
255267
this.state.defaultModule || findMainModule(modules).id;
@@ -283,6 +295,11 @@ class ShareView extends React.PureComponent {
283295
value={hideNavigation}
284296
setValue={this.setHideNavigation}
285297
/>
298+
<PaddedPreference
299+
title="Font size"
300+
value={fontSize}
301+
setValue={this.setFontSize}
302+
/>
286303
</div>
287304
<div>
288305
<h4>Default view</h4>

src/common/url.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
export const getSandboxOptions = (url: string) => {
44
const result = {};
5-
const moduleMatch = url.match(/(\?|\&)(module)\=([^&]+)/);
5+
const moduleMatch = url.match(/(\?|&)(module)=([^&]+)/);
66
if (moduleMatch) {
77
result.currentModule = moduleMatch[3];
88
}
9+
10+
const fontSizeMatch = url.match(/(\?|&)(fontsize)=([^&]+)/);
11+
if (fontSizeMatch) {
12+
result.fontSize = +fontSizeMatch[3];
13+
}
14+
915
result.isPreviewScreen = url.includes('view=preview');
1016
result.isEditorScreen = url.includes('view=editor');
1117

src/embed/App.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type State = {
5252
sidebarOpen: boolean,
5353
autoResize: boolean,
5454
hideNavigation: boolean,
55+
fontSize: number,
5556
};
5657

5758
export default class App extends React.PureComponent {
@@ -66,11 +67,13 @@ export default class App extends React.PureComponent {
6667
isEditorScreen,
6768
autoResize,
6869
hideNavigation,
70+
fontSize,
6971
} = getSandboxOptions(document.location.href);
7072

7173
this.state = {
7274
notFound: false,
7375
sandbox: null,
76+
fontSize: fontSize || 16,
7477
showEditor: !isPreviewScreen,
7578
showPreview: !isEditorScreen,
7679
isInProjectView: !currentModule,
@@ -104,9 +107,9 @@ export default class App extends React.PureComponent {
104107
sandbox: response.data,
105108
currentModule:
106109
this.state.currentModule ||
107-
response.data.modules.find(
108-
m => m.title === 'index.js' && m.directoryShortid == null,
109-
).shortid,
110+
response.data.modules.find(
111+
m => m.title === 'index.js' && m.directoryShortid == null,
112+
).shortid,
110113
});
111114
} catch (e) {
112115
this.setState({ notFound: true });
@@ -178,6 +181,7 @@ export default class App extends React.PureComponent {
178181
currentModule={this.state.currentModule}
179182
hideNavigation={this.state.hideNavigation}
180183
autoResize={this.state.autoResize}
184+
fontSize={this.state.fontSize}
181185
/>
182186
</Container>
183187
);

src/embed/components/Content.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Props = {
3232
isInProjectView: boolean,
3333
hideNavigation: boolean,
3434
autoResize: boolean,
35+
fontSize: number,
3536
};
3637

3738
type State = {
@@ -151,6 +152,10 @@ export default class Content extends React.PureComponent {
151152
livePreviewEnabled: true,
152153
};
153154

155+
getPreferences = () => {
156+
return { ...this.preferences, fontSize: this.props.fontSize };
157+
};
158+
154159
props: Props;
155160
state: State;
156161
render() {
@@ -161,6 +166,7 @@ export default class Content extends React.PureComponent {
161166
isInProjectView,
162167
currentModule,
163168
hideNavigation,
169+
fontSize,
164170
} = this.props;
165171

166172
const { errors } = this.state;
@@ -190,7 +196,7 @@ export default class Content extends React.PureComponent {
190196
mainModule.id,
191197
)}
192198
changeCode={this.setCode}
193-
preferences={this.preferences}
199+
preferences={this.getPreferences()}
194200
/>
195201
</Split>}
196202

@@ -207,7 +213,7 @@ export default class Content extends React.PureComponent {
207213
fetchBundle={this.fetchBundle}
208214
addError={this.addError}
209215
clearErrors={this.clearErrors}
210-
preferences={this.preferences}
216+
preferences={this.getPreferences()}
211217
setProjectView={this.props.setProjectView}
212218
hideNavigation={hideNavigation}
213219
setFrameHeight={this.handleResize}

0 commit comments

Comments
 (0)