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

feat(Icon): mark icons that should be rotated in rtl for teams theme #788

Merged
merged 15 commits into from
Jan 30, 2019
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Fixes
- Fix layout of `Accordion` panel's title @kuzhelov ([#780](https://github.com/stardust-ui/react/pull/780))

### Features
- Add mechanism for marking icons that should rotate in rtl in teams theme; marked icons: `send`, `bullets`, `leave`, `number-list`, `outdent`, `redo`, `undo`, `send` @mnajdova ([#788](https://github.com/stardust-ui/react/pull/788))
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

<!--------------------------------[ v0.19.0 ]------------------------------- -->
## [v0.19.0](https://github.com/stardust-ui/react/tree/v0.19.0) (2019-01-28)
[Compare changes](https://github.com/stardust-ui/react/compare/v0.18.0...v0.19.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ import { Icon, Label } from '@stardust-ui/react'
const IconExampleSpace = () => (
<div>
<p>
<Label content="Default" />
<Label>Default</Label>
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 was change because of console errors for invalid dom structure (div inside p element)

Copy link
Member

@notandrew notandrew Jan 29, 2019

Choose a reason for hiding this comment

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

Is <Label> referring to an HTML element or a Stardust element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

<Icon name="call-video" />
<Label content="Default" />
<Label>Default</Label>
</p>
<p>
<Label content="Before" />
<Label>Before</Label>
<Icon name="call-video" xSpacing="before" />
<Label content="Before" />
<Label>Before</Label>
</p>
<p>
<Label content="After" />
<Label>After</Label>
<Icon name="call-video" xSpacing="after" />
<Label content="After" />
<Label>After</Label>
</p>
<p>
<Label content="Both" />
<Label>Both</Label>
<Icon name="call-video" xSpacing="both" />
<Label content="Both" />
<Label>Both</Label>
</p>
<p>
<Label content="None" />
<Label>None</Label>
<Icon name="call-video" xSpacing="none" />
<Label content="None" />
<Label>None</Label>
</p>
</div>
)
Expand Down
8 changes: 5 additions & 3 deletions src/themes/teams/components/Icon/iconStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ const iconStyles: ComponentSlotStylesInput<IconProps, IconVariables> = {
...((bordered || v.borderColor || circular) &&
getBorderedStyles(circular, v.borderColor || getIconColor(color, v))),

...(rtl && {
transform: `scaleX(-1) rotate(${-1 * rotate}deg)`,
}),
...(rtl &&
!isFontBased &&
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
iconSpec.rotateInRtl && {
transform: `scaleX(-1) rotate(${-1 * rotate}deg)`,
}),

...(!rtl && {
transform: `rotate(${rotate}deg)`,
Expand Down
1 change: 1 addition & 0 deletions src/themes/teams/components/Icon/svg/icons/bullets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export default {
</svg>
),
styles: {},
rotateInRtl: true,
} as TeamsSvgIconSpec
1 change: 1 addition & 0 deletions src/themes/teams/components/Icon/svg/icons/indent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export default {
</svg>
),
styles: {},
rotateInRtl: true,
} as TeamsProcessedSvgIconSpec
1 change: 1 addition & 0 deletions src/themes/teams/components/Icon/svg/icons/leave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export default {
</svg>
),
styles: {},
rotateInRtl: true,
} as TeamsSvgIconSpec
1 change: 1 addition & 0 deletions src/themes/teams/components/Icon/svg/icons/numberList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export default {
</svg>
),
styles: {},
rotateInRtl: true,
} as TeamsProcessedSvgIconSpec
1 change: 1 addition & 0 deletions src/themes/teams/components/Icon/svg/icons/outdent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export default {
</svg>
),
styles: {},
rotateInRtl: true,
} as TeamsProcessedSvgIconSpec
1 change: 1 addition & 0 deletions src/themes/teams/components/Icon/svg/icons/redo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export default {
</svg>
),
styles: {},
rotateInRtl: true,
} as TeamsProcessedSvgIconSpec
1 change: 1 addition & 0 deletions src/themes/teams/components/Icon/svg/icons/send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export default {
</svg>
),
styles: {},
rotateInRtl: true,
} as TeamsSvgIconSpec
1 change: 1 addition & 0 deletions src/themes/teams/components/Icon/svg/icons/undo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export default {
</svg>
),
styles: {},
rotateInRtl: true,
} as TeamsProcessedSvgIconSpec
10 changes: 5 additions & 5 deletions src/themes/teams/components/Icon/svg/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import svgIconsAndStyles from './icons'
import { SvgIconSpecWithStyles, TeamsSvgIconSpec } from './types'
import svgIconsAndMetaData from './icons'
import { SvgIconSpecWithMetaData, TeamsSvgIconSpec } from './types'

export const getStyle = partName => {
return args => {
const { props } = args

const maybeIconSpec = svgIconsAndStyles[props.name]
const maybeIconStyles = maybeIconSpec && (maybeIconSpec as SvgIconSpecWithStyles).styles
const maybeIconSpec = svgIconsAndMetaData[props.name]
const maybeIconStyles = maybeIconSpec && (maybeIconSpec as SvgIconSpecWithMetaData).styles

if (maybeIconStyles && maybeIconStyles[partName]) {
return maybeIconStyles[partName](args)
Expand All @@ -16,4 +16,4 @@ export const getStyle = partName => {
}
}

export default svgIconsAndStyles as { [iconName: string]: TeamsSvgIconSpec }
export default svgIconsAndMetaData as { [iconName: string]: TeamsSvgIconSpec }
7 changes: 4 additions & 3 deletions src/themes/teams/components/Icon/svg/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { SvgIconSpec, ComponentSlotStyleFunction } from '../../../../types'
import { ObjectOf } from '../../../../../../types/utils'
import { IconProps } from '../../../../../components/Icon/Icon'

type SvgIconSpecWithStyles = {
type SvgIconSpecWithMetaData = {
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
icon: SvgIconSpec
styles: ObjectOf<ComponentSlotStyleFunction<IconProps, any>>
rotateInRtl?: boolean
}

export type TeamsSvgIconSpec = SvgIconSpec | SvgIconSpecWithStyles
export type TeamsSvgIconSpec = SvgIconSpec | SvgIconSpecWithMetaData

// TEMPORARY, till the moment when all necessary Teams icons will be moved
// to this Stardust theme
export type TeamsProcessedSvgIconSpec = SvgIconSpecWithStyles & {
export type TeamsProcessedSvgIconSpec = SvgIconSpecWithMetaData & {
exportedAs?: string
}
23 changes: 14 additions & 9 deletions src/themes/teams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,33 @@ import * as componentStyles from './componentStyles'
import fontFaces from './fontFaces'
import staticStyles from './staticStyles'

import { default as svgIconsAndStyles } from './components/Icon/svg'
import { default as svgIconsAndMetaData } from './components/Icon/svg'
import { default as fontIcons } from './components/Icon/font'

import { TeamsSvgIconSpec, SvgIconSpecWithStyles } from './components/Icon/svg/types'
import { TeamsSvgIconSpec, SvgIconSpecWithMetaData } from './components/Icon/svg/types'

const declareSvg = (svgIcon: SvgIconSpec): ThemeIconSpec => ({
const declareSvg = (svgIcon: SvgIconSpec, rotateInRtl: boolean): ThemeIconSpec => ({
isSvg: true,
icon: svgIcon,
rotateInRtl,
})

const declareFontBased = (fontIcon: FontIconSpec): ThemeIconSpec => ({ icon: fontIcon })

const icons: ThemeIcons = Object.keys(svgIconsAndStyles as {
const icons: ThemeIcons = Object.keys(svgIconsAndMetaData as {
[iconName: string]: TeamsSvgIconSpec
}).reduce<ThemeIcons>((accIcons, iconName) => {
const iconAndMaybeStyles = svgIconsAndStyles[iconName]
const iconAndMaybeMetaData = svgIconsAndMetaData[iconName]

const icon: SvgIconSpec = (iconAndMaybeStyles as any).styles
? (iconAndMaybeStyles as SvgIconSpecWithStyles).icon
: (iconAndMaybeStyles as SvgIconSpec)
const icon: SvgIconSpec = (iconAndMaybeMetaData as any).styles
? (iconAndMaybeMetaData as SvgIconSpecWithMetaData).icon
: (iconAndMaybeMetaData as SvgIconSpec)

return { ...accIcons, ...{ [iconName]: declareSvg(icon) } }
const rotateInRtl = (iconAndMaybeMetaData as any).rotateInRtl
? (iconAndMaybeMetaData as any).rotateInRtl
: false

return { ...accIcons, ...{ [iconName]: declareSvg(icon, rotateInRtl) } }
}, {})

Object.keys(fontIcons).forEach(iconName => {
Expand Down
23 changes: 16 additions & 7 deletions src/themes/teams/withProcessedIcons.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
import { ThemeInput, ThemeIcons, ThemeIconSpec, SvgIconSpec } from '../types'

import { default as svgIconsAndStyles } from './components/Icon/svg/ProcessedIcons'
import { TeamsProcessedSvgIconSpec, SvgIconSpecWithStyles } from './components/Icon/svg/types'
import { TeamsProcessedSvgIconSpec, SvgIconSpecWithMetaData } from './components/Icon/svg/types'

type ThemeProcessedIconSpec = ThemeIconSpec &
{ [K in keyof TeamsProcessedSvgIconSpec]?: TeamsProcessedSvgIconSpec[K] }

const declareSvg = (svgIcon: SvgIconSpec, exportedAs?: string): ThemeProcessedIconSpec => ({
const declareSvg = (
svgIcon: SvgIconSpec,
rotateInRtl,
exportedAs?: string,
): ThemeProcessedIconSpec => ({
isSvg: true,
icon: svgIcon,
rotateInRtl,
exportedAs,
})

const processedIcons: ThemeIcons = Object.keys(svgIconsAndStyles as {
[iconName: string]: TeamsProcessedSvgIconSpec
}).reduce<ThemeIcons>((accIcons, iconName) => {
const iconAndMaybeStyles = svgIconsAndStyles[iconName]
const iconAndMaybeMetaData = svgIconsAndStyles[iconName]

const icon: SvgIconSpec = (iconAndMaybeStyles as any).styles
? (iconAndMaybeStyles as SvgIconSpecWithStyles).icon
: (iconAndMaybeStyles as SvgIconSpec)
const icon: SvgIconSpec = (iconAndMaybeMetaData as any).styles
? (iconAndMaybeMetaData as SvgIconSpecWithMetaData).icon
: (iconAndMaybeMetaData as SvgIconSpec)

const rotateInRtl = (iconAndMaybeMetaData as any).rotateInRtl
? (iconAndMaybeMetaData as any).rotateInRtl
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
: false

return {
...accIcons,
...{ [iconName]: declareSvg(icon, (iconAndMaybeStyles as any).exportedAs) },
...{ [iconName]: declareSvg(icon, rotateInRtl, (iconAndMaybeMetaData as any).exportedAs) },
}
}, {})

Expand Down
1 change: 1 addition & 0 deletions src/themes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ export type FontIconSpec = ObjectOrFunc<{
export type ThemeIconSpec = {
isSvg?: boolean
icon: FontIconSpec | SvgIconSpec
rotateInRtl?: boolean
}

export type ThemeIcons = { [iconName: string]: ThemeIconSpec }