Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(Button): icon colors and layout #135

Merged
merged 11 commits into from
Aug 30, 2018

Conversation

kuzhelov
Copy link
Contributor

@kuzhelov kuzhelov commented Aug 24, 2018

TODO

  • Address issues screener has reported about (site variables were not applied for some reason?)
  • Update the CHANGELOG.md

Introduces changes that are aimed to solve the following problems with Button.

Colors

No color for default button

This customization parameter was absent for default button - although there was backgroundColor variable.

<Button icon='chess rook' variables={{ color: 'red' }} />

was (irregardless of value provided)

image

now

image

Icon's color of primary/secondary Button

Was not inherited - was hardcoded to be either black or white.

<Button primary ... variables={{ typePrimaryColor: 'red' }} />

was

image

now

image

Styles vanished in disabled state

All button in disabled state were displayed as grey - styling system hasn't honored any colors of enabled look of the button.

<Button disabled primary ... variables={{ typePrimaryColor: 'red' }} />

was

image

now

image

Layout

Layout styles were generally simplified, problems for the following cases were addressed:

iconPosition='before'

<Button content='...some long text...' icon='chess rook' iconPosition='before' />

was

image

now

image

iconPosition='after'

<Button content='...some long text...' icon='chess rook' iconPosition='after' />

was

image

now

image

@codecov
Copy link

codecov bot commented Aug 24, 2018

Codecov Report

Merging #135 into master will increase coverage by 0.01%.
The diff coverage is 94.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
+ Coverage   89.04%   89.05%   +0.01%     
==========================================
  Files          47       47              
  Lines         776      786      +10     
  Branches      101      113      +12     
==========================================
+ Hits          691      700       +9     
- Misses         83       84       +1     
  Partials        2        2
Impacted Files Coverage Δ
src/components/Button/Button.tsx 93.02% <94.11%> (-0.92%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c18fbd7...f81b239. Read the comment docs.

@kuzhelov kuzhelov added 🚀 ready for review 🧰 fix Introduces fix for broken behavior. and removed 🚧 WIP labels Aug 24, 2018
@kuzhelov kuzhelov changed the title fix(Button): icon layout fix(Button): icon colors and layout Aug 24, 2018
@@ -25,6 +26,7 @@ export default (siteVars: any): IButtonVariables => {
height: pxToRem(32),
minWidth: pxToRem(96),
maxWidth: pxToRem(280),
color: undefined,
Copy link
Member

Choose a reason for hiding this comment

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

Seems strange to have an undefined variable that is also never set to a value. Is there not a siteVariable available for this value?

In either case, what is the motivation for this variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the motivation for this variable is to allow to customize Button's color (where 'color' comes in general sense, not something that is tied to corresponding CSS property only). This will open way for the following customization scenarios, as well as allow to customize this aspect of Button component in docs

<Button variables={{ color: 'red' }} ... />

Seems strange to have an undefined variable that is also never set to a value. Is there not a siteVariable available for this value?

Yes, let me initialise it with an appropriate site variable - the reason haven't done it before is because it was unclear to me at this moment which ones will be provided by teams theme

: type === 'secondary'
? variables.typeSecondaryColor
: variables.color,
},
Copy link
Member

Choose a reason for hiding this comment

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

Any variables or styles used directly in a component's logic implicitly become part of a global theming interface.

All themes will have to implement variables.typePrimaryColor, for instance, in order for this to work. Additionally, we are removing the styling from the theme and baking it into the component instead.

I think all theming values and theming logic should live in the theme's files. This way, each theme is free to choose the values and logic behind their styles. The question is how?

Proposal 1 - Component part variables

Component variables files could define variables for each component parts as well. Then, variable values and logic for component parts can be left to the theme and not dictated to all themes by the component. Here's an example of the Button theme defining an icon part in its variables.

// themes/teams/components/Button/buttonVariables.tsx

export default (siteVariables) => {
  const variables = {
    color: undefined,
    typePrimaryColor: siteVariables.white,
    typeSecondaryColor: siteVariables.black,
  }

  variables.icon = {
    color:
      type === "primary"
        ? variables.typePrimaryColor
        : type === "secondary"
          ? variables.typeSecondaryColor
          : variables.color
  }

  return variables
}

Now, the component simply implements a contract that says "we pass variables[part] to each component part":

// Button.tsx

Icon.create(icon, {
  defaultProps: {
    variables: variables.icon
  }
})

This would also allow us to do this consistently for all components, including the styles for each component part. That then would allow us to write a conformance test for it. This would make the API easier to understand and work with as well since there is only one concept, "components pass variables/styles to each component part".

Proposal 2 - A high-level theme interface

This proposal would introduce a new concept. Something like a lightweight theme interface that is allowed to pass between components. It would consist of backgroundColor, foregroundColor, and perhaps an accentColor initially (names and keys are inspired by present convergence talks with several teams at Microsoft).

The Button in this case would define these three values for its bounds. Then, they would passed to the Icon.

There are a lot more considerations here, but I'm less in favor of this pattern for the problem at hand so I'll leave it here for now.


Thoughts?

Copy link
Contributor Author

@kuzhelov kuzhelov Aug 30, 2018

Choose a reason for hiding this comment

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

yes, agree with the reasons provided above, thanks - this goes in line with the exactly the same discussion we've had with Miro. For the sake of avoiding to introduce additional complexity at that moment we've decided to move forward with the simplest approach that would indicate our intent to pass variables to child component, and after that introduce changes in a way that theming aspects will be completely separated from logic.

Speaking of the options suggested - I would definitely support the first one, as it suggest clear path that not changes but extends approach we are using now - and, thus, it is not associated with significant complexity increase. Also, with this one we will be able to address quite broad set of scenarios we are currently struggling with (or using the approach where variables are coupled with implementation)

Not saying 'no' to the second option, though - but would rather wait once this concept will solidify in our minds, for the sake of us being absolutely sure about what we are buying for additional efforts laid in this direction, as well as whether this concept is able to cover the cases we are interested in (and how flexible it would be to cover potentially emerged edge-cases)

Copy link
Contributor Author

@kuzhelov kuzhelov Aug 30, 2018

Choose a reason for hiding this comment

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

for the sake of progressing with that, let me suggest the following steps:

  • leave the logic as it is for this PR - as from the consumer perspective provided changes introduce several important fixes
  • introduce RFC for those concerns that were raised about how variables should be passed to child components ([RFC] Decouple variables passed to child components from parent component's logic #162 )
  • implement related changes by means of dedicated PR (and, as part of this work, also ensure that improved approach is used at all places where variables were passed in the component's logic)

This will allow us to progress with fixes, as well as split these subsequent changes so that it would be easier to review them.

Please, let me know what do you think about it. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

agreed, let's merge this

const { children, content, disabled, iconPosition } = this.props
const hasChildren = childrenExist(children)

if (hasChildren) {
return children
}
Copy link
Member

Choose a reason for hiding this comment

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

If I now do:

<Button>Click me</Button>

Won't this result in rendering the text "Click me" only? We'd still want to wrap the text in an ElementType and apply our classes/accessibility/rest props.

@codecov
Copy link

codecov bot commented Aug 30, 2018

Codecov Report

Merging #135 into master will increase coverage by 0.31%.
The diff coverage is 65.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
+ Coverage   67.71%   68.02%   +0.31%     
==========================================
  Files         101      101              
  Lines        1363     1370       +7     
  Branches      261      269       +8     
==========================================
+ Hits          923      932       +9     
+ Misses        438      436       -2     
  Partials        2        2
Impacted Files Coverage Δ
.../themes/teams/components/Button/buttonVariables.ts 66.66% <ø> (ø) ⬆️
src/themes/teams/components/Button/buttonStyles.ts 12.12% <0%> (+0.69%) ⬆️
src/components/Button/Button.tsx 95.23% <100%> (+1.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc95292...c1d5714. Read the comment docs.

@levithomason levithomason merged commit e5ef249 into master Aug 30, 2018
@levithomason levithomason deleted the fix/button-layout-and-icon-color branch August 30, 2018 23:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧰 fix Introduces fix for broken behavior. 🚀 ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants