Skip to content

Commit

Permalink
♻️ Add scale option to values
Browse files Browse the repository at this point in the history
  • Loading branch information
exah committed Mar 6, 2019
1 parent 6515aed commit d59ade3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
14 changes: 9 additions & 5 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2673,6 +2673,8 @@ See [fontFamily][65], [radius][230].
- `options.themeKey` **[String][223]**
- `options.transformValue` **[Function][229]** (optional, default `identity`)
- `options.themeGetter` **[Function][229]** (optional, default `getThemeValue(themeKey,transformValue)`)
- `options.scale`
- `options.getter` (optional, default `getThemeValue({themeKey,transformValue,scale})`)
#### Examples
Expand Down Expand Up @@ -2757,9 +2759,10 @@ Related: [textStyle][20].
#### Parameters
- `options` **[Object][215]** (optional, default `{}`)
- `options.themeKey` **[String][223]**
- `options.transformValue` **[Function][229]** (optional, default `identity`)
- `options.themeGetter` **[Function][229]** (optional, default `getThemeValue(themeKey,transformValue)`)
- `options.themeKey`
- `options.transformValue`
- `options.scale`
- `options.getter` (optional, default `getThemeValue({themeKey,transformValue,scale})`)
#### Examples
Expand Down Expand Up @@ -2853,11 +2856,12 @@ Related: [textStyle][20], [boxStyle][14], [rule][179], [themeValue][196], [theme
#### Parameters
- `options` **[Object][215]**
- `options.themeKey`
- `options.prop` (optional, default `VARIANT`)
- `options.cssProp` (optional, default `false`)
- `options.scale`
- `options.themeKey`
- `options.transformValue`
- `options.themeGetter` (optional, default `getThemeValue(themeKey)`)
- `options.getter`
#### Examples
Expand Down
10 changes: 5 additions & 5 deletions src/core/create-variant.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { VARIANT } from '../constants'
import { getThemeValue } from '../getters'
import { themeValue } from '../values/theme-value'
import { createStyles } from './create-styles'
import { themeStyle } from './theme-style'
Expand Down Expand Up @@ -47,15 +46,16 @@ import { rule } from './rule'
*/

function createVariant ({
themeKey,
prop = VARIANT,
cssProp = false,
scale,
themeKey,
transformValue,
themeGetter = getThemeValue(themeKey)
getter
}) {
const style = cssProp === false
? themeStyle({ themeKey, transformValue, themeGetter })
: rule(cssProp, themeValue({ themeKey, transformValue, themeGetter }))
? themeStyle({ themeKey, transformValue, scale, getter })
: rule(cssProp, themeValue({ themeKey, transformValue, scale, getter }))

const mixin = createStyles({
[prop]: style
Expand Down
8 changes: 3 additions & 5 deletions src/core/theme-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import { everyMedia } from './every-media'
* Related: {@link textStyle}.
*
* @param {Object} [options = {}]
* @param {String} options.themeKey
* @param {Function} [options.transformValue = identity]
* @param {Function} [options.themeGetter = getThemeValue(themeKey, transformValue)]
* @return {Function}
*
* @example
Expand Down Expand Up @@ -59,11 +56,12 @@ import { everyMedia } from './every-media'
function themeStyle ({
themeKey,
transformValue,
themeGetter = getThemeValue(themeKey, transformValue)
scale,
getter = getThemeValue({ themeKey, transformValue, scale })
} = {}) {
return (inputs, props, mediaKey) => toArr(inputs).reduce((acc, input) => ({
...acc,
...everyMedia(props, themeGetter(input, null, mediaKey)(props))
...everyMedia(props, getter(input, null, mediaKey)(props))
}), {})
}

Expand Down
4 changes: 2 additions & 2 deletions src/getters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const getMedia = (input, media) => media
? path(input)(media)
: (props) => path(input)(getThemeMedia(props))

export function getThemeValue (themeKey, transformValue) {
export function getThemeValue ({ themeKey, transformValue, scale }) {
const isTransformValue = isFn(transformValue)

if (!isTransformValue) {
Expand All @@ -60,7 +60,7 @@ export function getThemeValue (themeKey, transformValue) {
? getDefault(themeKey)(props)
: input

const themeData = themePath(themeKey)(props)
const themeData = themePath(themeKey, scale)(props)
const themeValue = path(valueKey)(themeData)

if (Object(themeValue).hasOwnProperty(mediaKey)) {
Expand Down
6 changes: 4 additions & 2 deletions src/values/color-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { themePath, getDefault } from '../getters'
export function createColorValue ({
themeColorKey = COLORS_KEY,
themePaletteKey = PALETTE_KEY,
colorsGetter = themePath(themeColorKey, {}),
paletteGetter = themePath(themePaletteKey, {})
colorsScale = {},
paletteScale = {},
colorsGetter = themePath(themeColorKey, colorsScale),
paletteGetter = themePath(themePaletteKey, paletteScale)
} = {}) {
const getColor = (defaultColorName) => (colorName) => (props) => {
const colors = colorsGetter(props)
Expand Down
11 changes: 3 additions & 8 deletions src/values/size-value.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { isStr, path, identity } from '@exah/utils'
import { isStr, identity } from '@exah/utils'
import { SIZES_KEY } from '../constants'
import { px } from '../utils'
import { getThemeValue } from '../getters'

const scaleGetter = (scale, transformValue = identity) =>
(input, fallback) => transformValue(path(input, fallback)(scale))

export function createSizeValue ({
transformValue = identity,
themeKey = SIZES_KEY,
scale = null,
getter = scale
? scaleGetter(scale, transformValue)
: getThemeValue(themeKey, transformValue)
scale,
getter = getThemeValue({ themeKey, transformValue, scale })
} = {}) {
return (defaultValue = transformValue) => (
input,
Expand Down
5 changes: 3 additions & 2 deletions src/values/theme-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ import { getThemeValue } from '../getters'
function themeValue ({
themeKey,
transformValue,
themeGetter = getThemeValue(themeKey, transformValue)
scale,
getter = getThemeValue({ themeKey, transformValue, scale })
} = {}) {
return (input, props, mediaKey) => themeGetter(input, input, mediaKey)(props)
return (input, props, mediaKey) => getter(input, input, mediaKey)(props)
}

export {
Expand Down

0 comments on commit d59ade3

Please sign in to comment.