Skip to content

Commit

Permalink
fix: solve compatibility with IE11 & round-to (#33)
Browse files Browse the repository at this point in the history
* Remove round-to package and add custom function.

* Add tests on roundTo function.

* Add some documentation on roundTo method.

* Update roundTo to add some typehint.

Co-Authored-By: Pierre Tondereau <ptondereau@users.noreply.github.com>
  • Loading branch information
2 people authored and akameco committed May 15, 2019
1 parent 12cc274 commit 0f4006d
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 13 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
"files": [
"dist"
],
"dependencies": {
"round-to": "^4.0.0"
},
"dependencies": {},
"devDependencies": {
"@akameco/tsconfig": "^0.2.0",
"@types/jest": "^24.0.12",
Expand Down
3 changes: 1 addition & 2 deletions src/Circle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import roundTo from 'round-to'
import { getRange } from '../util'
import { getRange, roundTo } from '../util'
import { SpinkitProps, DEFAULT_SIZE, DEFAULT_COLOR } from '../types'
import { Child, StyledCircle } from './styles'

Expand Down
2 changes: 1 addition & 1 deletion src/CubeGrid/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import roundTo from 'round-to'
import { SpinkitProps, DEFAULT_SIZE, DEFAULT_COLOR } from '../types'
import { Child, StyledCubeGrid } from './styles'
import { roundTo } from '../util'

const CubeGrid: React.FC<SpinkitProps> = ({
size = DEFAULT_SIZE,
Expand Down
3 changes: 1 addition & 2 deletions src/FadingCircle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import roundTo from 'round-to'
import { getRange } from '../util'
import { getRange, roundTo } from '../util'
import { SpinkitProps, DEFAULT_SIZE, DEFAULT_COLOR } from '../types'
import { Child, StyledForldingCircle } from './styles'

Expand Down
2 changes: 1 addition & 1 deletion src/FoldingCube/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import roundTo from 'round-to'
import { SpinkitProps, DEFAULT_SIZE, DEFAULT_COLOR } from '../types'
import { Child, StyledFoldingCube } from './styles'
import { roundTo } from '../util'

const FoldingCube: React.FC<SpinkitProps> = ({
size = DEFAULT_SIZE,
Expand Down
2 changes: 1 addition & 1 deletion src/WanderingCubes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import roundTo from 'round-to'
import { SpinkitProps, DEFAULT_SIZE, DEFAULT_COLOR } from '../types'
import { Child, StyledWanderingCubes } from './styles'
import { roundTo } from '../util'

const WanderingCubes: React.FC<SpinkitProps> = ({
size = DEFAULT_SIZE,
Expand Down
2 changes: 1 addition & 1 deletion src/WanderingCubes/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import styled, { keyframes } from 'styled-components'
import roundTo from 'round-to'
import {
propSize,
propBgColor,
propDelay,
SizeProps,
DelayProps,
BgColorProps,
roundTo
} from '../util'

const createAnim = (cubeDistance: number = 42) => keyframes`
Expand Down
3 changes: 1 addition & 2 deletions src/WaveLoading/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import roundTo from 'round-to'
import { getRange } from '../util'
import { getRange, roundTo } from '../util'
import { SpinkitProps, DEFAULT_SIZE, DEFAULT_COLOR } from '../types'
import { Rect, StyledWave } from './styles'

Expand Down
6 changes: 6 additions & 0 deletions src/util/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { roundTo } from '../util'

test('roundTo util function ', () => {
expect(roundTo(4, 1)).toEqual(4);
expect(roundTo(1.1337, 3)).toEqual(1.134);
})
4 changes: 4 additions & 0 deletions src/util/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { css } from 'styled-components'

// This is an improvement of Math.round.
// It gives you the ability to round after a decimal.
export const roundTo = (n: number, precision: number): number => (Math.round((n * Math.pow(10, precision))) / Math.pow(10, precision))

export const size = (width: string, height: string = width) => css`
width: ${width};
height: ${height};
Expand Down

0 comments on commit 0f4006d

Please sign in to comment.