Skip to content

Commit

Permalink
fix(core): correct opacity spelling of style properties
Browse files Browse the repository at this point in the history
Refs #14.
  • Loading branch information
colinmeinke committed Jan 30, 2017
1 parent 0c329df commit 0c400ad
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -440,7 +440,7 @@ can also have any of the following optional style properties.

- `fill` is a *string* that defines the shape's `fill`
attribute
- `fillOpactity` is a *number* that defines the shape's
- `fillOpacity` is a *number* that defines the shape's
`fill-opacity` attribute
- `fillRule` is a *string* that defines the shape's
`fill-rule` attribute
Expand All @@ -454,7 +454,7 @@ can also have any of the following optional style properties.
`stroke-linecap` attribute
- `strokeLinejoin` is a *string* that defines the shape's
`stroke-linejoin` attribute
- `strokeOpactity` is a *number* that defines the shape's
- `strokeOpacity` is a *number* that defines the shape's
`stroke-opacity` attribute
- `strokeWidth` is a *number* that defines the shape's
`stroke-width` attribute
Expand Down
4 changes: 2 additions & 2 deletions src/core/shape/props.js
Expand Up @@ -44,14 +44,14 @@ const shapeProps = [

const stylePropAttrMap = {
fill: 'fill',
fillOpactity: 'fill-opacity',
fillOpacity: 'fill-opacity',
fillRule: 'fill-rule',
stroke: 'stroke',
strokeDasharray: 'stroke-dasharray',
strokeDashoffset: 'stroke-dashoffset',
strokeLinecap: 'stroke-linecap',
strokeLinejoin: 'stroke-linejoin',
strokeOpactity: 'stroke-opacity',
strokeOpacity: 'stroke-opacity',
strokeWidth: 'stroke-width',
vectorEffect: 'vector-effect'
}
Expand Down
62 changes: 62 additions & 0 deletions tests/core/shape/state.js
@@ -0,0 +1,62 @@
/* globals describe it expect */

import { styleAttributes } from '../../../src/core/shape/state'

const stylePropAttrMap = {
fill: 'fill',
fillOpacity: 'fill-opacity',
fillRule: 'fill-rule',
stroke: 'stroke',
strokeDasharray: 'stroke-dasharray',
strokeDashoffset: 'stroke-dashoffset',
strokeLinecap: 'stroke-linecap',
strokeLinejoin: 'stroke-linejoin',
strokeOpacity: 'stroke-opacity',
strokeWidth: 'stroke-width',
vectorEffect: 'vector-effect'
}

describe('styleAttributes', () => {
it('converts style props to correct style attributes', () => {
const props = {
fill: '#FFF',
fillOpacity: 0.5,
fillRule: 'evenodd',
stroke: '#000',
strokeDasharray: '5, 5',
strokeDashoffset: 100,
strokeLinecap: 'round',
strokeLinejoin: 'round',
strokeOpacity: 1,
strokeWidth: 2,
vectorEffect: 'non-scaling-shape'
}

const attributes = {
'fill': '#FFF',
'fill-opacity': 0.5,
'fill-rule': 'evenodd',
'stroke': '#000',
'stroke-dasharray': '5, 5',
'stroke-dashoffset': 100,
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-opacity': 1,
'stroke-width': 2,
'vector-effect': 'non-scaling-shape'
}

expect(styleAttributes(props)).toEqual(attributes)
})

it('filters out unrecognised keys', () => {
const props = {
fill: '#FFF',
foo: 'bar'
}

const attributes = { fill: '#FFF' }

expect(styleAttributes(props)).toEqual(attributes)
})
})

0 comments on commit 0c400ad

Please sign in to comment.