Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import * as React from 'react'
  2. import styled from '@emotion/styled'
  3. import { css } from '@emotion/core'
  4. import { addPropertyControls, ControlType } from 'framer'
  5.  
  6. type DataTypes = {
  7. format: 'data40' | 'data30' | 'data20' | 'data10'
  8. }
  9.  
  10. interface IDataTextProps {
  11. width?: number | string | any
  12. height?: number | string | any
  13. align?: string
  14. direction?: string
  15. format?: string
  16. transform?: string
  17. text?: string | number | any
  18. }
  19.  
  20. const sizes = {
  21. data40: 24,
  22. data30: 18,
  23. data20: 14,
  24. data10: 12
  25. }
  26.  
  27. const spacing = {
  28. data40: 32,
  29. data30: 24,
  30. data20: 20,
  31. data10: 16
  32. }
  33.  
  34. const colorVariants = {
  35. data40: '#1f2d46',
  36. data30: '#1f2d46',
  37. data20: '#1f2d46',
  38. data10: '#5c697f'
  39. }
  40.  
  41. const DataStyle = styled.p(
  42. [],
  43. ({ format, transform, align, direction }: IDataTextProps) =>
  44. css`
  45. font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
  46. sans-serif;
  47. font-size: ${sizes[format]}px;
  48. color: ${colorVariants[format]};
  49. line-height: ${spacing[format]}px;
  50. text-transform: ${transform || 'none'};
  51. text-align: ${align};
  52. direction: ${direction};
  53. margin: 0;
  54. font-variant-numeric: tabular-nums;
  55. `
  56. )
  57.  
  58. export function Data(props: IDataTextProps) {
  59. return (
  60. <>
  61. <DataStyle format={props.format} {...props}>
  62. {props.text}
  63. </DataStyle>
  64. </>
  65. )
  66. }
  67.  
  68. Data.defaultProps = {
  69. height: 32,
  70. text: '$90,836',
  71. format: 'data40',
  72. align: 'left',
  73. direction: 'ltr',
  74. transform: 'none'
  75. }
  76.  
  77. addPropertyControls(Data, {
  78. text: {
  79. type: ControlType.String,
  80. defaultValue: Data.defaultProps.text,
  81. title: 'Text'
  82. },
  83. format: {
  84. type: ControlType.Enum,
  85. title: 'Format',
  86. options: ['data40', 'data30', 'data20', 'data10'],
  87. optionTitles: ['Data 40', 'Data 30', 'Data 20', 'Data 10']
  88. },
  89. align: {
  90. type: ControlType.Enum,
  91. title: 'Align',
  92. options: ['left', 'center', 'right', 'justify', 'start', 'end'],
  93. optionTitles: ['Left', 'Center', 'Right', 'Justify', 'Start', 'End']
  94. },
  95. direction: {
  96. type: ControlType.Enum,
  97. title: 'Direction',
  98. options: ['ltr', 'rtl'],
  99. optionTitles: ['Left to Right', 'Right to Left']
  100. },
  101. transform: {
  102. type: ControlType.Enum,
  103. title: 'Transform',
  104. options: ['none', 'capitalize', 'uppercase', 'lowercase', 'full-width'],
  105. optionTitles: ['none', 'capitalize', 'uppercase', 'lowercase', 'full-width']
  106. }
  107. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement