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

feat(Icon): add props arg to SVG spec #1562

Merged
merged 7 commits into from
Jul 8, 2019
Merged

Conversation

kuzhelov
Copy link
Contributor

@kuzhelov kuzhelov commented Jul 1, 2019

Fixes #1356 .

This PR provides props argument to SVG icon spec. This makes it possible to use props values, such as size, to define SVG paths accordingly.

Example (added props arg)

// call.tsx
export default {
  icon: ({ classes, props }) => (
     {props.size === 'small' && (
           <svg>
            ...
          </svg>
     )}
     ...
} as TeamsSvgIconSpec

Opened question on icon's box sizes (width and height)

It still remains to be an opened question whether changes to logic of applying box sizes to SVG element (such as width and height) should be provided.

As it is suggested by #1356, in cases if size prop (with, say, small value) is handled by icon's render spec, width and height of the icon should remain to be default ones (and shouldn't be changed to small value). Specifically:

but if an icon has a smaller version (either new SVG or paths or ??) then it should use that. If not, then it should scale via css.

However, this behavior may provide unexpected effects to the client for, say, the following code:

// this icon renders different SVG path for 'smaller', 
// but its box's width and height doesn't change with 'size' prop
<Icon name='call' size='smaller' bordered> 

<Icon name='video' size='smaller' bordered>

Lets suppose that only call icon provides different SVG path for smaller size - and, thus, box size of this call icon won't be changed to smaller width and height values. In that case this will be the rendered result:

image

Even given that both icons were rendered as smaller, they have different box sizes which, in its turn, breaks alignment.


My proposal here would be to guarantee that box sizing algorithms work the same way for icons of any type, the same invariant we had before for Icon styles - as this guarantees proper alignment for any icons defined. Should note that this strategy will be sufficient enough to address the case of #1359.

However, it may be the case that I am missing some use cases missing with that - so, lets discuss and get to decision before merging the PR. FYI @codepretty

@codecov
Copy link

codecov bot commented Jul 1, 2019

Codecov Report

Merging #1562 into master will decrease coverage by 0.01%.
The diff coverage is 28.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1562      +/-   ##
==========================================
- Coverage   71.55%   71.54%   -0.02%     
==========================================
  Files         838      838              
  Lines        6858     6859       +1     
  Branches     1947     1968      +21     
==========================================
  Hits         4907     4907              
- Misses       1945     1946       +1     
  Partials        6        6
Impacted Files Coverage Δ
.../src/themes/teams/components/Icon/iconVariables.ts 50% <ø> (ø) ⬆️
packages/react/src/components/Icon/Icon.tsx 100% <100%> (ø) ⬆️
...act/src/themes/teams/components/Icon/iconStyles.ts 14.28% <16.66%> (-0.43%) ⬇️

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 ca579ed...85fa60d. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 1, 2019

Codecov Report

Merging #1562 into master will not change coverage.
The diff coverage is 33.33%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1562   +/-   ##
=======================================
  Coverage   71.67%   71.67%           
=======================================
  Files         848      848           
  Lines        6916     6916           
  Branches     1964     1965    +1     
=======================================
  Hits         4957     4957           
  Misses       1953     1953           
  Partials        6        6
Impacted Files Coverage Δ
.../src/themes/teams/components/Icon/iconVariables.ts 50% <ø> (ø) ⬆️
packages/react/src/components/Icon/Icon.tsx 100% <100%> (ø) ⬆️
...act/src/themes/teams/components/Icon/iconStyles.ts 14.7% <20%> (ø) ⬆️

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 442ff22...e1b6a39. Read the comment docs.

@mnajdova
Copy link
Contributor

mnajdova commented Jul 2, 2019

My proposal here would be to guarantee that box sizing algorithms work the same way for icons of any type, the same invariant we had before for Icon styles - as this guarantees proper alignment for any icons defined. Should note that this strategy will be sufficient enough to address the case of #1359.

I agree with this, all types of icons should behave the same, and depending on the theme's requirement, we can make the box (border around the icon) to grow or always be the same for all icons. For the icons that do not support different sizes, the box will still always be the same, as well as the icon size.

return v[`${size}Size`]
}
const getIconSize = (size: SizeValue, v: IconVariables): string => {
const sizeModifier: IconSizeModifier = v.sizeModifier
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this const now?

@@ -35,7 +33,9 @@ const getIconSize = (size: SizeValue, sizeModifier: IconSizeModifier, v: IconVar
},
}

return modifiedSizes[size] && pxToRem(modifiedSizes[size][sizeModifier])
return sizeModifier && modifiedSizes[size] && modifiedSizes[size][sizeModifier]
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, in my opinion the prev conditional is more readable. Is there a solid reason why it was changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change was necessary to remove branching at method's start:

 if (!sizeModifier) {
    return v[`${size}Size`]
 }

Essentially, in this method we have two branches to handle, thus it is an expected thing that we need just one if for that. Previously there were two ifs (at start of the method and at return) for, essentially, differentiate between the same two branches (sizeModifier is provided or not), and that has complicated the overall's function logic - and now there is only one.

@@ -80,7 +80,7 @@ const iconStyles: ComponentSlotStylesInput<IconProps, IconVariables> = {

svg: ({ props: { size, color, disabled, rotate }, variables: v }): ICSSInJSStyle => {
const colors = v.colorScheme[color]
const iconSizeInRems = getIconSize(size, v.sizeModifier, v)
const iconSizeInRems = getIconSize(size, v)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@kuzhelov kuzhelov merged commit 8c9ef6b into master Jul 8, 2019
@delete-merged-branch delete-merged-branch bot deleted the feat/add-props-to-icon-spec branch July 8, 2019 03:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Icon sizes that pull in different paths
3 participants