项目作者: b-feldmann

项目描述 :
React Component that resizes text to fit into a container
高级语言: TypeScript
项目地址: git://github.com/b-feldmann/react-text-resize.git
创建时间: 2019-09-08T14:08:30Z
项目社区:https://github.com/b-feldmann/react-text-resize

开源协议:

下载


Component that resizes font-size of children to fit the parent container.

Supports Typescript

Examples

  1. <TextResize defaultFontSize={26}>
  2. <p>Lorem Ipsum...</p>
  3. </TextResize>
  4. <TextResize defaultFontSize={26}>
  5. Lorem Ipsum...
  6. </TextResize>
  7. <TextResize defaultFontSize={26}>
  8. Lorem Ipsum...
  9. <div>Lorem Ipsum...</div>
  10. <p>Lorem Ipsum...</p>
  11. </TextResize>
  12. <TextResize defaultFontSize={26} minFontSize={14} maxFontSize={36}>
  13. <p>Lorem Ipsum...</p>
  14. </TextResize>

React Props

  • defaultFontSize: Starting font size
  • maxFontSize: maximum font size
  • minFontSize: minimum font size
  • className: add some css to the text parent

Algorithm

Uses binary search to find the right font-size - Blazing fast!
Uses useRef (React Hooks) to access the components and check the dimension.