Skip to content

Conversation

@sarayourfriend
Copy link
Contributor

@sarayourfriend sarayourfriend commented Oct 14, 2020

Description

  • Add breakpoint mixin
  • Add variable mixin (would love other ideas of how to handle these grab-bag variables @ItsJonQ)
  • Add input mixins
  • Refine type annotations on some mixins to make dev experience a lot nicer (get auto-complete for mixin string arguments!)
  • Use CSS-in-JS for TextareaControl

How has this been tested?

Storybook shows there are no visual changes between before and after. The previously used classname is persisted so anyone targeting that classname to style the textarea control will still be able to do so successfully.

Types of changes

Non-breaking dev-experience and code quality changes.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@@ -0,0 +1,6 @@
export default {
Copy link

Choose a reason for hiding this comment

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

This was bound to happen 😂 .

Here's how I've organized it in G2. It may spark some ideas!
https://github.com/ItsJonQ/g2/blob/master/packages/styles/src/theme/config.js

I think naming it something like config.js would be helpful. At the very least, it makes it feel more important/official (which it should be).

Since it's a JS object, you can group certain values together and ...spread them in the final object :).
That's how I've been keeping things tidy!

Lemme know what you think :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think we should group everything together like G2 does, moving font and config together into a single object? I'm not necessarily opposed to that 🤷‍♀️ I don't have any strong opinions here so just let me know what you think would be best (I've already renamed this to config rather than misc-variables).

Copy link

Choose a reason for hiding this comment

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

From my experience, when you start having LOTS of variables, it's quite nice to have it somewhat centralized.

It being a flat object vs. nested is subjective, although I've found a single flat objected being easier to work with.

We don't necessarily have to do this to start :). Just wanted to share some thoughts!
The current setup works okay 👍 .

I especially like how you're developing a pattern around accessing values via some sort of function.
It's a workflow that's shared between breakpoint(), font(), color(), and now config() :)

Copy link

@ItsJonQ ItsJonQ left a comment

Choose a reason for hiding this comment

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

🚀 from me! Thank you @saramarcondes for your continued efforts! I'm excited to see a collection of utils/mixins build up. It should make future styles + refactors easier 🙌

@ItsJonQ ItsJonQ merged commit 0736204 into WordPress:master Oct 16, 2020
@github-actions github-actions bot added this to the Gutenberg 9.2 milestone Oct 16, 2020
@sarayourfriend sarayourfriend deleted the add/use-css-in-js-for-textarea-control branch October 16, 2020 20:53
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif",
fontSize: '13px',
};
'default.fontSize': '13px',
Copy link
Member

Choose a reason for hiding this comment

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

👋 @saramarcondes I'm curious about these changes and what motivated them…

Other "values" utilities use nested objects, e.g.

export const BLUE = {
wordpress: {
700: '#00669b',
},

color( 'blue.wordpress.700' );

These rely on lodash get's string object-path-like property access (get( { foo: { bar: 'baz' } }, 'foo.bar' )). In this case, it looks like the object-path-like strings are used directly as the keys. This was a bit surprising to me 🙂

That's not necessarily a bad thing! it's just inconsistent and the keys here like helpText.fontSize were surprising to me.

We may be able to move away from get and rely more on TypeScript to ensure we're accessing values that exist.

Copy link
Contributor Author

@sarayourfriend sarayourfriend Oct 29, 2020

Choose a reason for hiding this comment

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

My intention was to keep things type-check-able! get obscures everything, the way I’ve set things up you get nice autocomplete. I chose to namespace values using the dot notation to match that nice feature from the colors utility while still getting the typecheck benefits.

Is it possible for us to maintain a typechecked “getter” function while having truly nested objects?

Copy link
Member

Choose a reason for hiding this comment

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

Just to be clear, I think this direction is great but we can go farther 🙂

My intention was to keep things type-check-able! get obscures everything

get will actually do a pretty good job (it's definition is interesting to look at), but JS/JSDoc is likely hindering it. Type arguments don't seem to work as well 😢

Is it possible for us to maintain a typechecked “getter” function while having truly nested objects?

I'm confident we could do a couple of levels of nesting without much trouble. Arbitrary depth is at least more complicated (we'd probably take inspiration from get)

However, we know statically everything about these objects! What purpose does the getter serve? We swap parens for braces and we have the same behavior.

const fontSize = font( 'helpText.fontSize' );
const fontSize_ = FONTS[ 'helpText.fontSize' ];

If we want nested objects and we accept that a getter isn't necessary (it may be, please convince me) then we just access them the . notation and can get excellent type support:

Screen Shot 2020-10-30 at 14 25 42

Here's a playground link with some of this set up already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certainly, we could just access the object directly and that would work fine. However @ItsJonQ has some good rationale for a "getter" function laid out here: https://g2components.wordpress.com/2020/10/23/creating-a-variable-system/

Because of that we have some limitations as to what information we can give to TypeScript, at least that's my understanding. The definition for get you linked is indeed interesting, however it only works if you split the path into segments rather than using a the dotted notation, which is already prevelant in the codebase for the existing getter functions.

Given those limitations and given that we probably want to be able to namespace things, I did the best with what I had... perhaps there's still something I'm missing that would allow us to avoid this style of namespacing while keeping the getter functions?

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