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

Commit

Permalink
feat(Icon): add props arg to SVG spec (#1562)
Browse files Browse the repository at this point in the history
* add props arg to svg icon spec

* leave size modifier to be an optional var

* remove sizeModifier const

* upd changelog

* upd changelog
  • Loading branch information
kuzhelov authored Jul 8, 2019
1 parent 442ff22 commit 8c9ef6b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add static `className` prop to result type of `createComponent` @kuzhelov ([#1563](https://github.com/stardust-ui/react/pull/1563))
- Add `hand` icon to Teams theme @t-proko ([#1567](https://github.com/stardust-ui/react/pull/1567))
- Add accessibility attributes and keyboard handlers for `Tooltip` @sophieH29 ([#1575](https://github.com/stardust-ui/react/pull/1575))
- Add `labelPosition` prop to `Checkbox` component @layershifter ([#1578](https://github.com/stardust-ui/react/pull/1578))
- Add `labelPosition` prop to `Checkbox` component @layershifter ([#1578](https://github.com/stardust-ui/react/pull/1578))
- Pass `props` of `Icon` component to SVG spec @kuzhelov ([#1562](https://github.com/stardust-ui/react/pull/1562))

### Documentation
- Ensure docs content doesn't overlap with sidebar @kuzhelov ([#1568](https://github.com/stardust-ui/react/pull/1568))
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Icon extends UIComponent<WithAsProp<IconProps>, any> {

return (
<ElementType className={classes.root} {...accessibility.attributes.root} {...unhandledProps}>
{isSvgIcon && callable(maybeIcon.icon)({ classes, rtl })}
{isSvgIcon && callable(maybeIcon.icon)({ classes, rtl, props: this.props })}
</ElementType>
)
}
Expand Down
14 changes: 6 additions & 8 deletions packages/react/src/themes/teams/components/Icon/iconStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../../types'
import { IconProps } from '../../../../components/Icon/Icon'
import { getStyle as getSvgStyle } from './svg'
import { IconVariables, IconSizeModifier, iconColorAreas } from './iconVariables'
import { IconVariables, iconColorAreas } from './iconVariables'

const getPaddedStyle = (): ICSSInJSStyle => ({
padding: pxToRem(4),
Expand All @@ -23,19 +23,17 @@ const getBorderedStyles = (boxShadowColor: string): ICSSInJSStyle => {
}
}

const getIconSize = (size: SizeValue, sizeModifier: IconSizeModifier, v: IconVariables): string => {
if (!sizeModifier) {
return v[`${size}Size`]
}

const getIconSize = (size: SizeValue, v: IconVariables): string => {
const modifiedSizes = {
large: {
x: 24,
xx: 28,
},
}

return modifiedSizes[size] && pxToRem(modifiedSizes[size][sizeModifier])
return v.sizeModifier && modifiedSizes[size] && modifiedSizes[size][v.sizeModifier]
? pxToRem(modifiedSizes[size][v.sizeModifier])
: v[`${size}Size`]
}

const getIconColor = (variables, colors: StrictColorScheme<ItemType<typeof iconColorAreas>>) => {
Expand Down Expand Up @@ -80,7 +78,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)

return {
display: 'block',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export const iconColorAreas = stringLiteralsArray('foreground')
export type IconColorSchemeMapping = TeamsSchemeMappingWithAreas<ItemType<typeof iconColorAreas>>

export interface IconVariables extends BaseIconVariables {
colorScheme?: IconColorSchemeMapping
brandColor?: string
colorScheme: IconColorSchemeMapping
brandColor: string
secondaryColor: string
redColor?: string
redColor: string

sizeModifier?: IconSizeModifier
}
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/themes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ export type FontFaces = FontFace[]
type SvgIconFuncArg = {
classes: { [iconSlot: string]: string }
rtl: boolean
props: IconProps
}

export type SvgIconSpec = ObjectOrFunc<React.ReactNode, SvgIconFuncArg>
Expand Down

0 comments on commit 8c9ef6b

Please sign in to comment.