Skip to content

Javalab: add resize text options in the settings menu - #48077

Merged
sanchitmalhotra126 merged 4 commits into
stagingfrom
sanchit/javalab-text-change
Sep 15, 2022
Merged

Javalab: add resize text options in the settings menu#48077
sanchitmalhotra126 merged 4 commits into
stagingfrom
sanchit/javalab-text-change

Conversation

@sanchitmalhotra126

Copy link
Copy Markdown
Contributor

Adds the ability to resize text in the Javalab editor. This resizes text both in the CodeMirror editor and the console.
In order to add this options to the settings menu, I had to refactor the JavalabSettings component a bit. Previously, it was designed to be a generic settings button that could display an arbitrary number of settings options, provided that they were buttons and closed the menu on click. Since the new text resize option is unfortunately neither of these, it was a bit difficult to make it work with the more generic structure that the component had, so I opted to just make it specific to Javalab (as it is currently only used to display Javalab's settings). This also allowed me to pull in the theme selection logic into this component rather than having it passed in from JavalabView.

Screen.Recording.2022-09-13.at.4.25.02.PM.mov

Links

Spec: https://docs.google.com/document/d/1TNIZwpGWLpB3P5IY7nJ8uHbvgNbzsxaeRSqtGzuSmEw/edit#bookmark=id.gnh0bg9juf8o
JIRA: https://codedotorg.atlassian.net/browse/JAVA-659

Testing story

Tested locally (Chrome running on Macbook)

Deployment strategy

Follow-up work

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@sanchitmalhotra126
sanchitmalhotra126 requested review from a team and moneppo September 13, 2022 22:08
@sanchitmalhotra126
sanchitmalhotra126 marked this pull request as ready for review September 13, 2022 22:08
@sanchitmalhotra126
sanchitmalhotra126 requested a review from a team as a code owner September 13, 2022 22:08

@molly-moen molly-moen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@import "color.scss";

.dropdown {
// The placeholder classes (%) allow these to be extended in other modules

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this comment!

? styles.darkModeInput
: styles.lightModeInput)
: styles.lightModeInput),
fontSize: this.props.editorFontSize

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be unavoidable with the way we want to programmatically change font size, but I'm curious if this means we won't be able to fully remove inline styles from this component? @madelynkasula

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good question, I was wondering the same. I opted to keep this here since this component is still using inline styles, but if we can programmatically do this via scss somehow that would be ideal. Maybe some sass magic to extract the font size value from the class name?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i was wondering the same thing. there are probably other solutions, but the 2 i think of immediately are:

  1. all styles are SCSS except fontSize (simplest, not really the worst to live with)
  2. we write some creative SCSS to generate the classes we need to set fontSize. this would be pretty simple to write (a map or function that programmatically generates classes like fontSize-13, fontSize-18, etc). however, this would likely leave us tightly coupled to the JS here unless we can figure out a creative way to share constants since both JS and SCSS would need to know that the font size can be from 13-68 and increments by 5 each step

if we can figure out a DRY way to share the "font sizes range from 13-68 every 5px," i think we could figure something out from there, but i'm not sure if it's worth it. we could just leave a comment that says why fontSize is set by the style attr and to use SCSS for everything else 🤷🏻‍♀️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, yeah I'll leave a comment for now and we can revisit when this component gets converted to use SCSS.

@maddiedierker maddiedierker Sep 14, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, maybe i disagree with myself. the constant-sharing would be pretty easy if SCSS controls everything... some pseudocode to explain what i'm thinking (pay no attention to the weird filenames and stuff)

// javalab-editor.module.scss
$increment: 5;
$min-size: 13;
$max-size: 68;

// a function that generates CSS classes to control font-size from 13-68, incrementing every 5

:export {
  // variables created above to be used in JS
}
// redux.js
import style from 'javalab-editor.module.scss';

const INCREMENT_PX = parseInt(style.increment);

interested in y'alls thoughts on how this feels though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh interesting. Wasn't too sure about how to share variables but this looks pretty promising. I'll give it a shot, thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't see @sanchitmalhotra126's comment until after i wrote my previous comment -- i'm fine with your suggestion for how to handle right now, just brainstorming how to handle this in the future 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha sounds good :) I think I'm inclined to leave as-is for now (with the comment), but do think this is a direction worth exploring

import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import i18n from '@cdo/locale';
import javalabMsg from '@cdo/javalab/locale';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it's a little confusing that some strings are i18n and others are javalabMsg -- maybe javalabI18n instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we tend to use javalabMsg across most Javalab components, so I can change i18n to msg instead if that's clearer?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me!

? styles.darkModeInput
: styles.lightModeInput)
: styles.lightModeInput),
fontSize: this.props.editorFontSize

@maddiedierker maddiedierker Sep 14, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, maybe i disagree with myself. the constant-sharing would be pretty easy if SCSS controls everything... some pseudocode to explain what i'm thinking (pay no attention to the weird filenames and stuff)

// javalab-editor.module.scss
$increment: 5;
$min-size: 13;
$max-size: 68;

// a function that generates CSS classes to control font-size from 13-68, incrementing every 5

:export {
  // variables created above to be used in JS
}
// redux.js
import style from 'javalab-editor.module.scss';

const INCREMENT_PX = parseInt(style.increment);

interested in y'alls thoughts on how this feels though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants