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

fix(Avatar): alignment of status icon on size changes #828

Merged
merged 22 commits into from
Feb 5, 2019

Conversation

kuzhelov
Copy link
Contributor

@kuzhelov kuzhelov commented Feb 1, 2019

TODO

  • introduce breaking change entry to CHANGELOG

Breaking Change

This PR unifies the set of values that could be provided to size prop of Avatar and Status components: instead of numbers that were originally used, now there is a finite set of string values that could be provided as size:

type SizeValue = 'smallest' | 'smaller' | 'small' | 'medium' | 'large' | 'larger' | 'largest'

Necessary changes on the client side

This PR requires the following changes to be made on the client side at places where size values were provided to either Avatar component, or to the size prop of its status slot. No changes should be introduced in case if no any value was provided to size prop.

sizes of Avatar and status slot originally were not in sync

Size of status icon was always remained the same and haven't responded to Avatar's size changes - now size of status slot changes alongside with changes to Avatar's size:

<Avatar size='larger' status={{ icon: 'check', color: 'green' }} image={...} />

Was

image

Now

image

In order to preserve original behavior size of status slot must be set explicitly:

<Avatar size='larger' status={{ size='medium', ... }} image={...} />

Avatar, value was provided to size prop

// Before
<Avatar size={32} />

// After
<Avatar size='medium' />

Avatar, size value is provided to status slot

// Before
<Avatar status={{ size: 10, ... }}/>

// After
<Avatar status={{ size: 'medium', ... }}/>

Removed types

AvatarPropsWithDefaults and StatusPropsWithDefaults types were removed from public API. Client should replace them with AvatarProps and StatusProps at places of usage, accordingly.


Description

This PR unifies size values for Avatar component - now those values are taken from common Stardust dictionary (smallest -> ... -> largest).

Related styles of Teams theme were adjusted accordingly.

Fix: unresponsiveness of status slot to size changes

Was

image

Now

image

@codecov
Copy link

codecov bot commented Feb 1, 2019

Codecov Report

Merging #828 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #828   +/-   ##
=======================================
  Coverage   93.54%   93.54%           
=======================================
  Files          21       21           
  Lines         728      728           
  Branches       69       69           
=======================================
  Hits          681      681           
  Misses         47       47

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 faf1e2a...d53a6ec. Read the comment docs.

@kuzhelov kuzhelov added 🚀 ready for review 🧰 fix Introduces fix for broken behavior. labels Feb 1, 2019
}

export const getSizeStyles = (sizeInPx: number, variables: StatusVariables) => {
const sizeInRem = pxToRem(sizeInPx + 2 * ((variables.borderColor && variables.borderWidth) || 0))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const sizeInRem = pxToRem(sizeInPx + 2 * ((variables.borderColor && variables.borderWidth) || 0))
const borderWidth = (variables.borderColor && variables.borderWidth) || 0
const sizeInRem = pxToRem(sizeInPx + 2 * borderWidth)

One line will not save us 😸 Can we make it more readable?

import { getStyle as getSvgStyle } from './svg'
import { IconVariables, IconSizeModifier } from './iconVariables'

const sizes: { [key in IconSize]: number } = {
const sizes: { [key in SizeValue]: number } = {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const sizes: { [key in SizeValue]: number } = {
const sizes: Record<SizeValue, number> = {

As I remember this should work

@@ -35,16 +35,33 @@ const getTextColor = (state: string, variables: StatusVariables) => {
}
}

const statusStyles: ComponentSlotStylesInput<StatusPropsWithDefaults, StatusVariables> = {
export const sizeToPxValue = {
Copy link
Member

Choose a reason for hiding this comment

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

Can we introduce a type there, i.e.:

Suggested change
export const sizeToPxValue = {
export const sizeToPxValue: Record<SizeValue, number> = {

@@ -120,7 +120,7 @@ export {
export { default as Ref, RefProps } from './components/Ref/Ref'
export { default as Segment, SegmentProps } from './components/Segment/Segment'

export { default as Status, StatusPropsWithDefaults, StatusProps } from './components/Status/Status'
export { default as Status, StatusProps } from './components/Status/Status'
Copy link
Member

Choose a reason for hiding this comment

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

StatusPropsWithDefaults was part of public API, so this is a breaking change, too

@@ -23,10 +24,10 @@ export interface AvatarProps extends UIComponentProps {
name?: string

/** Size multiplier. */
size?: number
size?: SizeValue
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check if there are some usages in the prototypes (I am pretty sure there is employee card prototype that has bigger Avatar)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, thanks for heads up!


/** Shorthand for the status of the user. */
status?: ShorthandValue
status?: ShorthandValue<StatusProps>
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

LGTM please just check the prototypes if there are some miss-usages of the size props after these changes.

@kuzhelov kuzhelov added the needs author feedback Author's opinion is asked label Feb 4, 2019
@kuzhelov kuzhelov added ready for merge and removed needs author feedback Author's opinion is asked labels Feb 5, 2019
@kuzhelov kuzhelov merged commit aefc1fa into master Feb 5, 2019
@kuzhelov kuzhelov deleted the fix/avatar-sizes branch February 5, 2019 11:12
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 merge 🚀 ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants