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

feat: further simplify icon markup in t-shirt size component #1070

Closed
wants to merge 104 commits into from

Conversation

jianliao
Copy link
Contributor

@jianliao jianliao commented Nov 9, 2020

Description

The targets that I want to achieve include:

  1. icon should allow resizing with a css variable #753 - icon should allow resizing with a css variable.
  2. Further simplify icon markup in T-shirt size component requested by this comment

Implementation detail:

  1. I followed the article mentioned by @Westbrook to build a css variable cascading(fallback) chain. It looks like:
block-size: var(--spectrum-icon-user-defined-height, var(--spectrum-icon-tshirt-size-height, var(--spectrum-icon-default-height, var(--spectrum-alias-workflow-icon-size-m)))) 

inline-size: var(--spectrum-icon-user-defined-width, var(--spectrum-icon-tshirt-size-width, var(--spectrum-icon-default-width, var(--spectrum-alias-workflow-icon-size-m))))
  • --spectrum-icon-user-defined-height is for component team(spectrum-react, spectrum-webcomponents) to customize the height.
  • --spectrum-icon-tshirt-size-height will be provided by each t-shirt size component in its size class like .spectrum-ActionButton--sizeL. See here.
  • --spectrum-icon-default-height. It is the default value when no user-defined and t-shirt size variable provided. For workflow icon height, it is default as DNA variable --spectrum-alias-workflow-icon-size-m.
  1. To remove the class like spectrum-Icon--sizeS and spectrum-UIIcon-CornerTriangle100 from workflow icon and ui icon svg element, we need to provide the t-shirt size variable in its wrapper element CSS class like .spectrum-ActionButton--sizeM. See here. The html markup for an ActionButton would look like:
<button class="spectrum-ActionButton spectrum-ActionButton--sizeM">
  <svg class="spectrum-UIIcon spectrum-ActionButton-hold" focusable="false" aria-hidden="true">
    <use xlink:href="#spectrum-css-icon-CornerTriangle100" />
  </svg>
  <svg class="spectrum-Icon" focusable="false" aria-hidden="true" aria-label="Edit">
    <use xlink:href="#spectrum-icon-18-Edit" />
  </svg>
</button>

Open issues

  1. To distinguish workflow icon and ui icon, I need to use spectrum-UIIcon for ui icon. This is not a new class, but I could not find anywhere we use it. It would be a breaking change.

  2. I defined a series of CSS variables that are not from DNA. Not sure where to put them, I just insert them into components/vars/css/components/spectrum-icon.css. It is not ideal as this file will be overridden each time we upgrade the DNA.

  3. In each component css, we have to define t-shirt size variable unused anywhere in that file. I have to comment out postcss-dropunusedvars for this purpose. Need to enhance this postcss plugin to provide a white list maybe?

  4. All the new variables name are TBD. For example:

  --spectrum-icon-user-defined-height: var(--spectrum-icon-tshirt-size-height);
  --spectrum-icon-user-defined-width: var(--spectrum-icon-tshirt-size-width);
  --spectrum-icon-tshirt-size-height: var(--spectrum-icon-default-height);
  --spectrum-icon-tshirt-size-width: var(--spectrum-icon-default-width);
  --spectrum-icon-default-height: var(--spectrum-alias-workflow-icon-size-m);
  --spectrum-icon-default-width: var(--spectrum-alias-workflow-icon-size-m);

  --spectrum-ui-icon-user-defined-height: var(--spectrum-ui-icon-tshirt-size-height);
  --spectrum-ui-icon-user-defined-width: var(--spectrum-ui-icon-tshirt-size-width);
  --spectrum-ui-icon-tshirt-size-height: var(--spectrum-ui-icon-default-height);
  --spectrum-ui-icon-tshirt-size-width: var(--spectrum-ui-icon-default-width);
  --spectrum-ui-icon-default-height: var(--spectrum-alias-workflow-icon-size-m);
  --spectrum-ui-icon-default-width: var(--spectrum-alias-workflow-icon-size-m);

How and where has this been tested?

  • How this was tested:
  • Browser(s) and OS(s) this was tested with:

Screenshots

To-do list

  • If my change impacts other components, I have tested to make sure they don't break.
  • If my change impacts documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • This pull request is ready to merge.

Sorry, something went wrong.

lazd added 30 commits October 23, 2020 10:31

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
BREAKING CHANGE: .spectrum-FieldButton has been removed, use .spectrum-ActionButton instead

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
will be overwritten and fixed when https://git.corp.adobe.com/Spectrum/spectrum-dna/pull/458 merged

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
BREAKING CHANGE: markup now requires spectrum-ActionButton where all uses of spectrum-FieldButton were


docs: add migration guide and sizing examples

BREAKING CHANGE: .spectrum-ProgressBar--large renamed to .spectrum-ProgressBar--sizeM, .spectrum-ProgressBar--large renamed to .spectrum-ProgressBar--sizeS is required for previous

BREAKING CHANGE: ProgressBar .is-warning renamed to .is-notice, .is-critical renamed to .is-negative
docs: add examples with custom widths
@adobe-spectrum-bot
Copy link
Collaborator

VRT successfully! 🎊

View the VRT result

@GarthDB GarthDB assigned GarthDB and lazd and unassigned GarthDB Nov 18, 2020
@GarthDB GarthDB added the size-3 M ~18-30hrs; moderate effort or complexity, several work days needed. label Nov 18, 2020
@Westbrook
Copy link
Contributor

@jianliao
Copy link
Contributor Author

No more specific size classes required.

@Westbrook
Copy link
Contributor

I think I misstated my question...

Good to hear that is wouldn't be required!

Would Spectrum CSS still maintain those classes for optional use, going forward?

@lazd
Copy link
Member

lazd commented Dec 1, 2020

@Westbrook yes absolutely; we do want all of the standard icon sizes to be usable. This PR simply changes their sizes contextually where we know what size the icons need to be.

We still need to really chew on this and understand if we're being consistent if we go this route; take a look at ProgressBar, it has t-shirt sizing and uses FieldLabel, which also has t-shirt sizing. You must specify the size of the FieldLabel used within the ProgressBar manually. It would be overreach for ProgressBar to change FieldLabel's variables for font size, weight, margin, etc contextually.

Given the ProgressBar and FieldLabel issue, does it make sense for Button to reach into Icon and do the same thing? Yes, it's only dimensions, but where do we draw the line?

@Westbrook
Copy link
Contributor

I'd less call this "reaching into" a component than defining what scope a component is delivered in, which would lead me to think that a ProgressBar effecting a FieldLabel internal to it would be little different than a Button effecting the Icon within it.

In either case, would delivering the internal component at a different size than the external element be considered "Spectrum correct"? If not, I'd hope that the cascade managed this without need of specific classes, this goes the extra mile of reducing the likelihood of breaking changes like we've seen in the move from sizeS to sizeM as far as Icons in Buttons, recently. In the end, I'm predominately looking for ways to better prevent these sorts of changes making their way down stream to my consumers. Then, the use of classes to make a purposeful departure from the design spec would still be possible as a specific opt-in, and would make sense why the classes I referenced above would continue to exist.

@lazd
Copy link
Member

lazd commented Dec 1, 2020

I'd less call this "reaching into" a component than defining what scope a component is delivered in, which would lead me to think that a ProgressBar effecting a FieldLabel internal to it would be little different than a Button effecting the Icon within it.

I can definitely see that, but where do we draw the line? Only icons can be contextually sized? I think that's fair, honestly, but need to hear from the rest of the team.

In either case, would delivering the internal component at a different size than the external element be considered "Spectrum correct"?

Almost certainly not, which is definitely a good argument for this approach.

If not, I'd hope that the cascade managed this without need of specific classes, this goes the extra mile of reducing the likelihood of breaking changes like we've seen in the move from sizeS to sizeM as far as Icons in Buttons, recently.

My point exactly on the other PR comment adobe/spectrum-web-components#669 (comment); token-driven icon sizing means that consumers aren't on the hook for updating markup when a design decision is made. That said, the sizeS to sizeM change was a LOOONNGGG time coming, we had legacy code from 3 years ago in there for icon sizing, and we finally unified it. I absolutely don't see that happening again any time soon, and if it did, it would be an update to the size of a medium icon, not a change in the scale (i.e. small is renamed to medium).

In the end, I'm predominately looking for ways to better prevent these sorts of changes making their way down stream to my consumers. Then, the use of classes to make a purposeful departure from the design spec would still be possible as a specific opt-in, and would make sense why the classes I referenced above would continue to exist.

Agreed. I think we're on the right track, but let's be sure to think about the system as a whole when we make changes that introduce a completely new API, as this one does (variable driven icon sizing is API!).

Base automatically changed from spectrum-tokens-26 to main December 1, 2020 19:03
@lazd
Copy link
Member

lazd commented Dec 1, 2020

@jianliao please rebase 🙏

@adobe-spectrum-bot
Copy link
Collaborator

VRT successfully! 🎊

View the VRT result

@adobe-spectrum-bot
Copy link
Collaborator

Spectrum CSS documentation build successfully! 🎉

View the documentation


.spectrum-Icon {
&,
img,
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: Nesting the size of img and svg in the same rules as .spectrum-Icon will likely cause issue in code like:

.spectrum-Tooltip-typeIcon {
margin-inline-start: calc(
var(--spectrum-tooltip-icon-margin-x) - var(--spectrum-tooltip-padding-x)
);
margin-inline-end: var(--spectrum-tooltip-icon-margin-x);
width: var(--spectrum-tooltip-icon-size);
height: var(--spectrum-tooltip-icon-size);
align-self: flex-start;
flex-shrink: 0;
/* Adjusts for weird misalignment */
margin-block-start: 1px;
}

Maybe the goal is to ALWAYS use CSS Custom Properties in this sort of context? In that case we'd need to have any such instance updated as part of this PR or prior to an actual release of these changes.

An alternative would be to not directly size the img and svg content and set them as:

    block-size: 100%;
    inline-size: 100%;

Thoughts?

@adixon-adobe
Copy link
Contributor

One thing I'll add to the FieldLabel -> ProgressBar discussion here is that I've been thinking of "specifically-sized" sizing, and "auto-sized based on context" sizing. So ProgressBar auto-sizing to the right size for FieldLabel really does make sense to me (as long as the interface for doing so is well encapsulated).

CSS variables seem to give the tools to do this, but it might be overly cumbersome to support directly in SpectrumCSS in some contexts. Icons are simple enough that I think it does.

@castastrophe
Copy link
Collaborator

@pfulton As we're reworking the tooling elsewhere and seem to have a new approach to t-shirt size variables, should this PR be closed? Is there anything else in here we want to maintain?

@castastrophe castastrophe deleted the tshirt-size-workflow-icon-continue branch March 6, 2024 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size-3 M ~18-30hrs; moderate effort or complexity, several work days needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants