How to use the @xstyled/util.string function in @xstyled/util

To help you get started, we’ve selected a few @xstyled/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github smooth-code / xstyled / packages / core / src / customProperties.js View on Github external
export function toCustomPropertiesReferences(object, parent, theme = object) {
  const next = Array.isArray(object) ? [] : {}

  for (const key in object) {
    const value = object[key]
    const name = join(parent, key)
    if (obj(value)) {
      next[key] = toCustomPropertiesReferences(value, name, theme)
      continue
    }
    if (string(value)) {
      next[key] = toVarValue(name, value)
      continue
    }
    if (func(value)) {
      next[key] = toVarValue(name, value({ theme }))
      continue
    }
  }

  return next
}
github smooth-code / xstyled / packages / system / src / styles / space.js View on Github external
transform: (_, { rawValue, variants, props }) => {
    if (string(rawValue)) {
      const neg = rawValue.startsWith('-')
      const absoluteValue = neg ? rawValue.substr(1) : rawValue
      const variantValue = getThemeValue(props, absoluteValue, variants)
      const value = is(variantValue) ? variantValue : absoluteValue
      return neg ? toNegative(value) : value
    }
    const abs = Math.abs(rawValue)
    const neg = negative(rawValue)
    const value = is(variants[abs]) ? variants[abs] : abs
    return neg ? toNegative(value) : value
  },
})
github smooth-code / xstyled / packages / system / src / styles / space.js View on Github external
function toNegative(value) {
  if (string(value)) return `-${value}`
  return value * -1
}
github smooth-code / xstyled / packages / system / src / unit.js View on Github external
export const rpx = value => {
  if (!string(value) || value.length < 4) return value
  const unit = value.slice(-3)
  if (unit !== 'rpx') return value
  const n = Number(value.slice(0, value.length - 3))
  if (n === 0) return 0
  return `${pxToRem(n)}rem`
}
github smooth-code / xstyled / packages / core / src / customProperties.js View on Github external
export function toCustomPropertiesDeclarations(
  object,
  parent,
  theme = object,
  state = { value: '' },
) {
  for (const key in object) {
    const value = object[key]
    const name = join(parent, key)
    if (obj(value)) {
      toCustomPropertiesDeclarations(value, name, theme, state)
      continue
    }
    if (string(value)) {
      state.value += `${toVarName(name)}: ${value};`
      continue
    }
    if (func(value)) {
      state.value += `${toVarName(name)}: ${value({ theme })};`
      continue
    }
  }

  return state.value
}