Skip to content

Commit

Permalink
refactor(services): minor refactor + code style (#6557)
Browse files Browse the repository at this point in the history
* refactor(services): use short power syntax in easing functions

* refactor(services): clean up icons' presets' code

* style(theme): comment default colors

* Update packages/vuetify/src/services/goto/__tests__/easing-patterns.spec.ts

Co-Authored-By: sh7dm <[email protected]>

* style: fix color annotations
  • Loading branch information
Dmitry Sharshakov authored and johnleider committed Feb 21, 2019
1 parent 65cabd9 commit a0ebde1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ describe('easing-patterns.ts', () => {
expect(easingPatterns.easeInQuint(5)).toBe(3125)
expect(easingPatterns.easeOutQuint(5)).toBe(1025)
expect(easingPatterns.easeInOutQuint(5)).toBe(16385)
expect(easingPatterns.easeInOutQuint(0.1)).toBe(0.00016000000000000007)
expect(easingPatterns.easeInOutQuint(0.1)).toBeCloseTo(0.00016, 5)
})
})
20 changes: 10 additions & 10 deletions packages/vuetify/src/services/goto/easing-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ export type EasingFunction = (t: number) => number
// linear
export const linear = (t: number) => t
// accelerating from zero velocity
export const easeInQuad = (t: number) => t * t
export const easeInQuad = (t: number) => t ** 2
// decelerating to zero velocity
export const easeOutQuad = (t: number) => t * (2 - t)
// acceleration until halfway, then deceleration
export const easeInOutQuad = (t: number) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t)
export const easeInOutQuad = (t: number) => (t < 0.5 ? 2 * t ** 2 : -1 + (4 - 2 * t) * t)
// accelerating from zero velocity
export const easeInCubic = (t: number) => t * t * t
export const easeInCubic = (t: number) => t ** 3
// decelerating to zero velocity
export const easeOutCubic = (t: number) => --t * t * t + 1
export const easeOutCubic = (t: number) => --t ** 3 + 1
// acceleration until halfway, then deceleration
export const easeInOutCubic = (t: number) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
export const easeInOutCubic = (t: number) => t < 0.5 ? 4 * t ** 3 : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
// accelerating from zero velocity
export const easeInQuart = (t: number) => t * t * t * t
export const easeInQuart = (t: number) => t ** 4
// decelerating to zero velocity
export const easeOutQuart = (t: number) => 1 - --t * t * t * t
export const easeOutQuart = (t: number) => 1 - --t ** 4
// acceleration until halfway, then deceleration
export const easeInOutQuart = (t: number) => (t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t)
// accelerating from zero velocity
export const easeInQuint = (t: number) => t * t * t * t * t
export const easeInQuint = (t: number) => t ** 5
// decelerating to zero velocity
export const easeOutQuint = (t: number) => 1 + --t * t * t * t * t
export const easeOutQuint = (t: number) => 1 + --t ** 5
// acceleration until halfway, then deceleration
export const easeInOutQuint = (t: number) => t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t
export const easeInOutQuint = (t: number) => t < 0.5 ? 16 * t ** 5 : 1 + 16 * --t ** 5
18 changes: 4 additions & 14 deletions packages/vuetify/src/services/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,23 @@
import { Service } from '../service'

// Types
import {
VuetifyIconSets,
VuetifyIconOptions
} from 'vuetify/types/services/icons'
import { VuetifyIconOptions } from 'vuetify/types/services/icons'

// Presets
import md from './presets/md'
import mdi from './presets/mdi'
import fa from './presets/fa'
import fa4 from './presets/fa4'

const iconFonts: VuetifyIconSets = Object.freeze({
md, mdi, fa, fa4
})
import presets from './presets'

export class Icons extends Service {
static property = 'icons'

public iconfont: VuetifyIconOptions['iconfont'] = 'md'
public values: VuetifyIconOptions['values'] = iconFonts[this.iconfont]
public values: VuetifyIconOptions['values'] = presets[this.iconfont]

constructor (options: Partial<VuetifyIconOptions> = {}) {
super()
if (options.iconfont) this.iconfont = options.iconfont

this.values = {
...iconFonts[this.iconfont],
...presets[this.iconfont],
...(options.values || {})
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/vuetify/src/services/icons/presets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Types
import { VuetifyIconSets } from 'vuetify/types/services/icons'

import md from './md'
import mdi from './mdi'
import fa from './fa'
import fa4 from './fa4'

export default Object.freeze({
md, mdi, fa, fa4
}) as VuetifyIconSets
29 changes: 15 additions & 14 deletions packages/vuetify/src/services/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-multi-spaces */
// Extensions
import { Service } from '../service'

Expand All @@ -20,22 +21,22 @@ export class Theme extends Service {
public styleEl?: HTMLStyleElement
public themes: VuetifyThemes = {
light: {
primary: '#1976D2',
secondary: '#424242',
accent: '#82B1FF',
error: '#FF5252',
info: '#2196F3',
success: '#4CAF50',
warning: '#FB8C00'
primary: '#1976D2', // blue.darken2
secondary: '#424242', // grey.darken3
accent: '#82B1FF', // blue.accent1
error: '#FF5252', // red.accent2
info: '#2196F3', // blue.base
success: '#4CAF50', // green.base
warning: '#FB8C00' // amber.base
},
dark: {
primary: '#2196F3',
secondary: '#424242',
accent: '#FF3F80',
error: '#FF5252',
info: '#2196F3',
success: '#4CAF50',
warning: '#FB8C00'
primary: '#2196F3', // blue.base
secondary: '#424242', // grey.darken3
accent: '#FF4081', // pink.accent-2
error: '#FF5252', // red.accent2
info: '#2196F3', // blue.base
success: '#4CAF50', // green.base
warning: '#FB8C00' // amber.base
}
}

Expand Down

0 comments on commit a0ebde1

Please sign in to comment.