Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

26 行
598 B

  1. export type Unit = 'px' | '%' | 'rem'
  2. export interface ValueAndUnit {
  3. magnitude: number
  4. unit: Unit
  5. }
  6. interface SplitValueAndUnit {
  7. (value: any): ValueAndUnit
  8. }
  9. const splitValueAndUnit: SplitValueAndUnit = (value) => {
  10. if (!['string', 'number'].includes(typeof value)) {
  11. throw TypeError('Argument must be a valid CSS number')
  12. }
  13. const valueString = typeof value! === 'number' ? `${value}px` : String(value)
  14. const magnitude = parseFloat(valueString)
  15. return {
  16. magnitude,
  17. unit: valueString.slice(String(magnitude).length) as Unit,
  18. }
  19. }
  20. export default splitValueAndUnit