Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

26 linhas
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