|
1 | | -# React + TypeScript + Vite |
| 1 | +# react-fitter |
2 | 2 |
|
3 | | -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. |
| 3 | +In a project of mine I had to fit some text of unknown length to a container |
| 4 | +without it wrapping. This utility component does exactly that, regardless of |
| 5 | +whether if it sits inline, in a flexbox, grid or table. It just works. |
4 | 6 |
|
5 | | -Currently, two official plugins are available: |
6 | | - |
7 | | -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh |
8 | | -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
9 | | - |
10 | | -## Expanding the ESLint configuration |
| 7 | +```bash |
| 8 | +npm install react-fitter |
| 9 | +``` |
11 | 10 |
|
12 | | -If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: |
| 11 | +Usage: |
| 12 | +```jsx |
| 13 | +import { Fitter } from 'react-fitter' |
13 | 14 |
|
14 | | -- Configure the top-level `parserOptions` property like this: |
| 15 | +// ... |
15 | 16 |
|
16 | | -```js |
17 | | -export default tseslint.config({ |
18 | | - languageOptions: { |
19 | | - // other options... |
20 | | - parserOptions: { |
21 | | - project: ['./tsconfig.node.json', './tsconfig.app.json'], |
22 | | - tsconfigRootDir: import.meta.dirname, |
23 | | - }, |
24 | | - }, |
25 | | -}) |
| 17 | +<div className="my-text"> |
| 18 | + <Fitter> |
| 19 | + This is some text that will perfectly fit in the container |
| 20 | + </Fitter> |
| 21 | +</div> |
26 | 22 | ``` |
27 | 23 |
|
28 | | -- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` |
29 | | -- Optionally add `...tseslint.configs.stylisticTypeChecked` |
30 | | -- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: |
31 | | - |
32 | | -```js |
33 | | -// eslint.config.js |
34 | | -import react from 'eslint-plugin-react' |
35 | | - |
36 | | -export default tseslint.config({ |
37 | | - // Set the react version |
38 | | - settings: { react: { version: '18.3' } }, |
39 | | - plugins: { |
40 | | - // Add the react plugin |
41 | | - react, |
42 | | - }, |
43 | | - rules: { |
44 | | - // other rules... |
45 | | - // Enable its recommended rules |
46 | | - ...react.configs.recommended.rules, |
47 | | - ...react.configs['jsx-runtime'].rules, |
48 | | - }, |
49 | | -}) |
| 24 | +And your CSS can be whatever you want. The Fitter component will never make the |
| 25 | +text larger than what's set by your styles. It will only ever make it smaller. |
| 26 | +```css |
| 27 | +.my-text { |
| 28 | + width: 400px; |
| 29 | + font-size: 24px; |
| 30 | + border: 1px solid hotpink; |
| 31 | +} |
50 | 32 | ``` |
| 33 | + |
| 34 | +Which would look like this: |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +In contrast to how it would look without react-fitter: |
| 40 | + |
| 41 | + |
0 commit comments