Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-116194 Add token-definition part 1 #119

Closed
wants to merge 1 commit into from

Conversation

edalgrin
Copy link
Collaborator

@edalgrin edalgrin commented Jul 15, 2020

Work in progress to be merged to #111

@liferay-continuous-integration
Copy link
Collaborator

To conserve resources, the PR Tester does not automatically run for every pull.

If your code changes were already tested in another pull, reference that pull in this pull so the test results can be analyzed.

If your pull was never tested, comment "ci:test" to run the PR Tester for this pull.

@edalgrin edalgrin marked this pull request as draft July 15, 2020 08:32
],
"tokens": [
{
"ccp": "--white",
Copy link

Choose a reason for hiding this comment

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

So, this is the only thing... @izaera, @ruben-pulido, @marcoscv-work, @wincent... thoughts on how to better model it now that we can see it?

I still think something like:

{
    "editorType": "ColorPicker",
    "label": "gray-100",
     "mappings": {
        "ccp": "gray-100"
        "figma": {
            "id": 200,
            "value": "gray-100",
        }
    },
    "name": "gray100Color",
    "tokenCategoryName": "colors",
    "tokenSetName": "general",
    "type": "String"
}

We could make the CSS CustomProperties mapping as simple as a string to allow for more complex ones in the future.

We would need to decide if we want mappings to be an indexed object as in the example or an array with mappingType and mapping properties. The second one is more verbose but also more readable...

Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer indexed objects because:

  1. They enforce keys to be unique
  2. They let you index by key in O(1)

Said that, it is obvious that we can do whatever we want in the JSON and then transform it internally to suit our programming needs.

However, I don't know how easy/possible it is to enforce unique keys inside an array in JSON schema. That could be key...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was wondering why we include custom mappings in this file:

  1. Because it's their final place and we want them to be here
  2. Because we don't know yet what to do with them and we are just proofing

@ruben-pulido seems to be aligned with me (as per private conversation) and thinks the reason is 2

Choose a reason for hiding this comment

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

However, I don't know how easy/possible it is to enforce unique keys inside an array in JSON schema. That could be key...

The current specification of JSON schema does not allow it AFAIK.
There is an open issue asking for this.

Choose a reason for hiding this comment

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

In other places in the portal where we want to guarantee uniqueness we are adding code to perform that check outside of the JSON schema validation

Copy link
Collaborator

Choose a reason for hiding this comment

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

it will be way too easy for tokens to fall out of sync and have no mappings

That's a point too 🤔

My concern was that the person writing the tokens may not know anything about the mappings. It could even be that the mappings are not known at the stage where the theme is developed. But it is true that that problem may be fixed with a proper development workflow...

Maybe we can settle on adding mappings in the file and then let it be extended (after deployment of the theme) if needed.

In that case, we just need to decide if we want an array or an object...

Copy link

Choose a reason for hiding this comment

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

Well... seeing as we have a schema and indexed objects are not spec'd... looks like we'll have an array?

{
    "editorType": "ColorPicker",
    "label": "gray-100",
     "mappings": [
          {
               "mappingType": "cssVariable",
               "value": "gray-100"   
        }
    ],
    "name": "gray100Color",
    "tokenCategoryName": "colors",
    "tokenSetName": "general",
    "type": "String"
}

This, @ruben-pulido, @izaera, @eduardoallegrini? 👆

Choose a reason for hiding this comment

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

That looks good to me. I'll update the token definition JSON schema in #99 accordingly

Choose a reason for hiding this comment

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

"mappings": [
{
"mappingType": "cssVariable",
"value": "gray-100"
}
],

I'll use type instead of mappingType as the name of the field. Prefixing type but not prefixing value seems otherwise inconsistent

Choose a reason for hiding this comment

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

The example mentioned above will then be:

{
    "editorType": "ColorPicker",
    "label": "gray-100",
     "mappings": [
          {
               "type": "cssVariable",
               "value": "gray-100"   
        }
    ],
    "name": "gray100Color",
    "tokenCategoryName": "colors",
    "tokenSetName": "general",
    "type": "String"
}

@eduardoallegrini Can you modify token-definition.json to include the change?

@edalgrin
Copy link
Collaborator Author

edalgrin commented Jul 15, 2020

I have a question about the "editorType": "ColorPicker" if we only have one, can't we include it as "type": "Color" and process it with something like this?

if (type === "Color") {
   editor = ColorPicker;
   type = String;
}

],
"tokens": [
{
"ccp": "--white",

Choose a reason for hiding this comment

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

What does "ccp" stand for?

Copy link
Collaborator Author

@edalgrin edalgrin Jul 15, 2020

Choose a reason for hiding this comment

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

CSS Custom Properties, it's not the most fancy name but it's the official one 🤷‍♂️ https://www.w3.org/TR/css-variables-1/

Choose a reason for hiding this comment

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

I guess CSS Custom Property

@edalgrin
Copy link
Collaborator Author

Another question: what are tokenCategoryName and tokenSetName? I tried to give a meaning on my own but it's not really clear to me

@izaera
Copy link
Collaborator

izaera commented Jul 15, 2020

Other than my feedback in this thread, the rest LGTM.

I would probably rename ccp to something more comprehensible and less similar to CCCP 😅 , but I'm OK with it if you find it correct. For example: css looks OK, since the only mappings from tokens to CSS that come to mind are "CSS custom properties", I think.

@izaera
Copy link
Collaborator

izaera commented Jul 15, 2020

@eduardoallegrini Regarding your question: editorType is the UI, type is the data type. They are different things.

For example, a variable of type string can be edited with a color picker or an input.

We could even potentially allow more than one editorType if we wanted to...

@wincent
Copy link

wincent commented Jul 15, 2020

Just to give some feedback from an "outsider" perspective (ie. somebody who doesn't know much about our Custom CSS Properties implementation), this are the questions that I have in my mind as I read this:

  • How did we decide on the ordering inside tokenCategories, tokenSets and, tokens?
  • We have both a "general" category and a "general" set, which may be confusing. At the moment in this PR we have tokens using the category/set pairs listed below; so it's a bit confusing to me that we have a "general" set inside the "colors" category, but we also have a "utility" set inside the "general" category... I don't know if this structure is dictated by our existing Custom CSS Properties implementation:
    • "colors" category / "general" set
    • "colors" category / "utility" set
    • "colors" category / "layout" set
    • "general" category / "utility" set
    • "spaces" category / "layout" set
    • "typography" category / "utility" set
    • "typography" category / "general" set
  • I don't know if this is a partial example of that, but there are a number of sets that have no tokens defined for them at all (eg. "alerts", "cards" etc).

@wincent
Copy link

wincent commented Jul 15, 2020

Oh, and I forgot to mention, "layout" (set) + "colors" (categories) is a bit of a strange combination to me. We're using it in this PR for --body-bg and --body-color. The body doesn't feel like a layout primitive to me, so I'm not sure why we're classifying it this way.

@jbalsas
Copy link

jbalsas commented Jul 15, 2020

Ok, quickly from https://www.figma.com/file/R0ccjMTdAmU3t348wSTUUJ/LPS---115168---Style-Editor-02?node-id=30%3A16019

Screen_Shot_2020-07-15_at_13_24_46

How did we decide on the ordering inside tokenCategories, tokenSets and, tokens?

Arbitrary, however we want... probably through some heuristic based on importance and frequency of usage, but as of right now, just make a guess.

@wincent
Copy link

wincent commented Jul 15, 2020

Arbitrary, however we want... probably through some heuristic based on importance and frequency of usage, but as of right now, just make a guess.

Awesome, that clears it up perfectly then.

Based on the Figma, then perhaps we have some minor discrepancies in terminology:

Figma category PR category
General general
Layout spaces
Text typography
Color colors

and:

Figma set PR set
Border radius Utility
etc ...

Not sure what the "source of truth" should be considered to be, but I do know that whenever the language for concepts is not consistent throughout all the levels of a system (eg. UI terminology, terminology at various levels inside the implementation, terminology inside data/configuration artifacts etc) that it can increase the cognitive load of working with the system. It's not always possible, of course, for everything to be in exact harmony, but insofar as it is possible, it is desirable to keep discrepancies to a minimum.

@ruben-pulido
Copy link

ruben-pulido commented Jul 15, 2020

I would probably rename ccp to something more comprehensible and less similar to CCCP 😅 , but I'm OK with it if you find it correct. For example: css looks OK, since the only mappings from tokens to CSS that come to mind are "CSS custom properties", I think.

I agree: ccp is a bit cryptic. I find css or cssCustomProperties better options

@edalgrin
Copy link
Collaborator Author

edalgrin commented Jul 15, 2020

@wincent

  • How did we decide on the ordering inside tokenCategories, tokenSets and, tokens?

I tried to follow the order of the notes https://www.notion.so/Stylebook-Variables-a919ebecc01046d5bb8f89e076842503

  • We have both a "general" category and a "general" set, which may be confusing. At the moment in this PR we have tokens using the category/set pairs listed below; so it's a bit confusing to me that we have a "general" set inside the "colors" category, but we also have a "utility" set inside the "general" category... I don't know if this structure is dictated by our existing Custom CSS Properties implementation:

    • "colors" category / "general" set
    • "colors" category / "utility" set
    • "colors" category / "layout" set
    • "general" category / "utility" set
    • "spaces" category / "layout" set
    • "typography" category / "utility" set
    • "typography" category / "general" set

You are right! I don't know how to define them

  • I don't know if this is a partial example of that, but there are a number of sets that have no tokens defined for them at all (eg. "alerts", "cards" etc).

I tried to copy the categories we defined in https://github.com/liferay/liferay-portal/blob/master/modules/apps/frontend-theme/frontend-theme-classic/src/css/custom_properties/_custom_properties_variables.scss

@jbalsas
Copy link

jbalsas commented Jul 15, 2020

I tried to copy the categories we defined in https://github.com/liferay/liferay-portal/blob/master/modules/apps/frontend-theme/frontend-theme-classic/src/css/custom_properties/_custom_properties_variables.scss

This should be customer-data-ux-driven... so maybe ping the author of https://www.notion.so/Stylebook-Variables-a919ebecc01046d5bb8f89e076842503, Juan? :)

@edalgrin
Copy link
Collaborator Author

edalgrin commented Jul 15, 2020

@izaera @ruben-pulido

I would probably rename ccp to something more comprehensible and less similar to CCCP 😅 , but I'm OK with it if you find it correct. For example: css looks OK, since the only mappings from tokens to CSS that come to mind are "CSS custom properties", I think.

I agree: ccp is a bit cryptic. I find css or cssCustomProperties better options

What about cssVariable as @jbalsas suggested previously?

@ruben-pulido
Copy link

What about cssVariable as @jbalsas suggested previously?

Sounds OK to me since that seems to be a term commonly used (https://developer.mozilla.org/en-US/docs/Web/CSS/--*)

@izaera
Copy link
Collaborator

izaera commented Jul 15, 2020

@ruben-pulido Are all these changes included in the JSON schema or it has to be modified?

@edalgrin
Copy link
Collaborator Author

edalgrin commented Jul 15, 2020

I've updated the PR making the changes mentioned in the comments. I didn't modify the categories and sets yet, because we have scheduled a meeting tomorrow to talk about it, but I think @izaera can proceed with the integration.

@ruben-pulido
Copy link

ruben-pulido commented Jul 15, 2020

@ruben-pulido Are all these changes included in the JSON schema or it has to be modified?

@izaera I'm going to modify the JSON schema to include the mapping as discussed here and will link it here once finished

@ruben-pulido
Copy link

@ruben-pulido Are all these changes included in the JSON schema or it has to be modified?

@izaera I'm going to modify the JSON schema to include the mapping as discussed here and will link it here once finished

Token definition JSON schema updated with mappings:

izaera added a commit to izaera/liferay-portal that referenced this pull request Jul 15, 2020
@jbalsas
Copy link

jbalsas commented Jul 15, 2020

Closing here since it's been updated there

izaera added a commit to izaera/liferay-portal that referenced this pull request Jul 17, 2020
jbalsas pushed a commit to izaera/liferay-portal that referenced this pull request Jul 17, 2020
ealonso pushed a commit to ealonso/liferay-portal that referenced this pull request Jul 20, 2020
izaera added a commit to izaera/liferay-portal that referenced this pull request Jul 20, 2020
ealonso pushed a commit to ealonso/liferay-portal that referenced this pull request Jul 21, 2020
brianchandotcom pushed a commit to brianchandotcom/liferay-portal that referenced this pull request Jul 22, 2020
@edalgrin edalgrin deleted the LPS-116194 branch September 4, 2020 07:56
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.

6 participants