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

fix(Icon): Color & docs update for Teams theme #384

Merged
merged 8 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Fixes
- Fix build on Windows @jurokapsiar ([#383](https://github.com/stardust-ui/react/pull/383))
- Add warning for rendering components outside provider @Bugaa92 ([#378](https://github.com/stardust-ui/react/pull/378))
- Fix icon colors for Teams theme @codepretty ([#384](https://github.com/stardust-ui/react/pull/384))

### Features
- Export `mergeThemes` @levithomason ([#285](https://github.com/stardust-ui/react/pull/285))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { Icon } from '@stardust-ui/react'
const IconExampleDisabled = () => (
<div>
<Icon disabled name="umbrella" size="big" />
<Icon disabled name="umbrella" size="big" variables={{ color: 'blue' }} />
<Icon disabled name="umbrella" size="big" variables={{ color: 'red' }} />
<Icon disabled name="umbrella" size="big" variables={{ color: 'orange' }} />
</div>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'
import { Icon } from '@stardust-ui/react'

const IconExampleColor = () => (
<div>
<Icon name="home" />
<Icon name="home" variables={{ color: 'blue' }} />
<Icon name="home" variables={{ color: 'red' }} />
<Icon name="home" variables={{ color: 'orange' }} />
</div>
)

export default IconExampleColor
5 changes: 5 additions & 0 deletions docs/src/examples/components/Icon/Variations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const Variations = () => (
description="An icon can have space before, after or on both sides. 'none' value removes the default space around the icon."
examplePath="components/Icon/Variations/IconExampleSpace"
/>
<ComponentExample
title="Color"
description="An icon can have a different color"
examplePath="components/Icon/Variations/IconExampleColor"
/>
<ComponentExample
title="Size"
description="An icon can vary in size."
Expand Down
45 changes: 21 additions & 24 deletions src/themes/teams/components/Icon/iconStyles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fontAwesomeIcons from './fontAwesomeIconStyles'
import { callable } from '../../../../lib'
import { disabledStyle, fittedStyle } from '../../../../styles/customCSS'
import { fittedStyle } from '../../../../styles/customCSS'
import { ComponentSlotStylesInput, ICSSInJSStyle, FontIconSpec } from '../../../types'
import { ResultOf } from '../../../../../types/utils'
import { IconXSpacing, IconProps } from '../../../../components/Icon/Icon'
Expand Down Expand Up @@ -30,22 +30,12 @@ const getFontStyles = (iconName: string, themeIcon?: ResultOf<FontIconSpec>): IC

return {
fontFamily,
width: '1.18em',
fontStyle: 'normal',
fontWeight: 400,
textDecoration: 'inherit',
textAlign: 'center',

'-webkit-font-smoothing': 'antialiased',
'-moz-osx-font-smoothing': 'grayscale',
backfaceVisibility: 'hidden',

lineHeight: 1,
width: '1.18em',

'::before': {
content,
boxSizing: 'inherit',
background: '0 0',
},
}
}
Expand All @@ -67,7 +57,6 @@ const getBorderedStyles = (isFontBased, circular, borderColor, color): ICSSInJSS
return {
...getPaddedStyle(isFontBased),

// TODO: "black" here should actually match the Icon's fill or text color
boxShadow: `0 0 0 0.05em ${borderColor || color || 'black'} inset`,
...(circular ? { borderRadius: '50%' } : {}),
}
Expand All @@ -87,43 +76,51 @@ const iconStyles: ComponentSlotStylesInput<IconProps, any> = {
}): ICSSInJSStyle => {
const iconSpec = theme.icons[name]
const isFontBased = !iconSpec || !iconSpec.isSvg
const iconColor = v.color || 'currentColor'

return {
backgroundColor: v.backgroundColor,
display: 'inline-block',
fontSize: getSize(size),

margin: v.margin,
speak: 'none',
verticalAlign: 'middle',
overflow: 'hidden',
width: '1em',
height: '1em',

...(isFontBased &&
getFontStyles(name, callable(iconSpec && (iconSpec.icon as FontIconSpec))())),

...(isFontBased && { color: v.color }),
backgroundColor: v.backgroundColor,
...(isFontBased && {
color: iconColor,

opacity: 1,
margin: v.margin,
...(disabled && {
color: v.disabledColor,
}),
}),

speak: 'none',
...(!isFontBased && {
fill: iconColor,

verticalAlign: 'middle',
overflow: 'hidden',
...(disabled && {
fill: v.disabledColor,
}),
}),

...getXSpacingStyles(xSpacing, v.horizontalSpace),

...((bordered || v.borderColor || circular) &&
getBorderedStyles(isFontBased, circular, v.borderColor, v.color)),

...(disabled && disabledStyle),
}
},

svg: getSvgStyle('svg'),

g: getSvgStyle('g'),

/* additional SVG styles for different paths could be added/used in the same way */
path: getSvgStyle('path'),

secondaryPath: getSvgStyle('secondaryPath'),
}

Expand Down
8 changes: 4 additions & 4 deletions src/themes/teams/components/Icon/iconVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export interface IconVariables {
horizontalSpace: string
margin: string
secondaryColor: string
disabledColor: string
}

export default (): IconVariables => ({
export default (siteVars): IconVariables => ({
color: undefined,
// TODO move initial variable discovery to JSON files
// similar to how components have an info.json file
backgroundColor: undefined,
borderColor: undefined,
horizontalSpace: pxToRem(10),
margin: '0 0.25em 0 0',
secondaryColor: 'white',
secondaryColor: siteVars.white,
disabledColor: siteVars.gray06,
})