font-controls 1.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,14 +6,14 @@ A beautiful, Leva-inspired font controls library for React. Provides an intuitiv
6
6
 
7
7
  ## Features
8
8
 
9
- **Beautiful UI** - Glassmorphism design with smooth animations
10
- 🎨 **Dark Mode** - Automatic dark mode support
11
- 🖱️ **Draggable** - Drag to reposition the control panel
12
- 🔄 **Reset Button** - Quickly reset all values to defaults
13
- 📦 **Lightweight** - Minimal dependencies
14
- 🔧 **TypeScript** - Full TypeScript support with type definitions
15
- ⚡ **Real-time Preview** - See changes instantly
16
- 🎯 **Customizable** - Configure fonts, ranges, and more
9
+ **- 100 Google Fonts**
10
+ **- Draggable Panel**
11
+ **- CSS Isolated**
12
+ **- Copy Paste Your Text Instantly**
13
+
14
+ ## Screenshot
15
+
16
+ ![Font Controls Demo](./screenshot.png)
17
17
 
18
18
  ## Installation
19
19
 
@@ -21,80 +21,112 @@ A beautiful, Leva-inspired font controls library for React. Provides an intuitiv
21
21
  npm install font-controls
22
22
  ```
23
23
 
24
- or
24
+ ## Quick Start
25
25
 
26
- ```bash
27
- yarn add font-controls
28
- ```
26
+ ```tsx
27
+ import { FontControls, useFontControls } from "font-controls";
28
+ import "font-controls/dist/style.css";
29
29
 
30
- or
30
+ function App() {
31
+ const { config, setConfig } = useFontControls();
31
32
 
32
- ```bash
33
- pnpm add font-controls
33
+ return (
34
+ <div>
35
+ <div style={config}>
36
+ <h1>Your styled text here</h1>
37
+ <p>Typography controls made easy!</p>
38
+ </div>
39
+
40
+ <FontControls value={config} onChange={setConfig} />
41
+ </div>
42
+ );
43
+ }
34
44
  ```
35
45
 
36
- ## Quick Start
46
+ **That's it!** Google Fonts are loaded automatically.
47
+
48
+ ## Complete Example
49
+
50
+ Here's a full example with live preview:
37
51
 
38
52
  ```tsx
39
- import { FontControls } from "font-controls";
53
+ import { FontControls, useFontControls } from "font-controls";
40
54
  import "font-controls/dist/style.css";
41
- import { useState } from "react";
42
55
 
43
56
  function App() {
44
- const [fontConfig, setFontConfig] = useState({
45
- fontFamily: "Arial",
46
- fontSize: 16,
47
- fontWeight: 400,
48
- lineHeight: 1.5,
49
- letterSpacing: 0,
50
- textTransform: "none",
51
- color: "#000000",
52
- textAlign: "left",
53
- });
57
+ const { config, setConfig } = useFontControls();
54
58
 
55
59
  return (
56
- <div>
57
- <h1
58
- style={{
59
- fontFamily: fontConfig.fontFamily,
60
- fontSize: `${fontConfig.fontSize}px`,
61
- fontWeight: fontConfig.fontWeight,
62
- lineHeight: fontConfig.lineHeight,
63
- letterSpacing: `${fontConfig.letterSpacing}px`,
64
- textTransform: fontConfig.textTransform,
65
- color: fontConfig.color,
66
- textAlign: fontConfig.textAlign,
67
- }}
68
- >
69
- Hello, World!
70
- </h1>
71
-
72
- <FontControls value={fontConfig} onChange={setFontConfig} />
60
+ <div style={{ minHeight: "100vh", padding: "40px" }}>
61
+ <div style={{ maxWidth: "1200px", margin: "0 auto" }}>
62
+ <h1>Font Controls Demo</h1>
63
+
64
+ {/* Preview area with live font changes */}
65
+ <div
66
+ style={{
67
+ ...config,
68
+ padding: "40px",
69
+ border: "1px solid #eee",
70
+ borderRadius: "8px",
71
+ }}
72
+ >
73
+ <h2>The Quick Brown Fox Jumps Over The Lazy Dog</h2>
74
+ <p>
75
+ Typography is the art and technique of arranging type to make
76
+ written language legible, readable and appealing when displayed.
77
+ </p>
78
+ </div>
79
+
80
+ {/* Current config display */}
81
+ <pre
82
+ style={{
83
+ background: "#f5f5f5",
84
+ padding: "20px",
85
+ borderRadius: "6px",
86
+ marginTop: "20px",
87
+ }}
88
+ >
89
+ {JSON.stringify(config, null, 2)}
90
+ </pre>
91
+ </div>
92
+
93
+ {/* Font Controls Panel */}
94
+ <FontControls value={config} onChange={setConfig} />
73
95
  </div>
74
96
  );
75
97
  }
76
98
  ```
77
99
 
78
- **That's it!** Google Fonts are loaded automatically - no need to add `<link>` tags to your HTML.
79
-
80
100
  ## API Reference
81
101
 
82
- ### FontControls Props
102
+ ### `useFontControls` Hook
103
+
104
+ The easiest way to use font controls:
105
+
106
+ ```tsx
107
+ const { config, setConfig, updateConfig, resetConfig } =
108
+ useFontControls(initialConfig);
109
+ ```
110
+
111
+ **Returns:**
83
112
 
84
- | Prop | Type | Default | Description |
85
- | -------------- | ------------------------------ | ----------------------------- | --------------------------------------------- |
86
- | `value` | `Partial<FontConfig>` | - | Initial font configuration |
87
- | `onChange` | `(config: FontConfig) => void` | - | Callback fired when any font property changes |
88
- | `fontFamilies` | `string[]` | `['Arial', 'Helvetica', ...]` | Custom list of font families |
89
- | `minFontSize` | `number` | `8` | Minimum font size |
90
- | `maxFontSize` | `number` | `120` | Maximum font size |
91
- | `fontSizeStep` | `number` | `1` | Font size step increment |
92
- | `title` | `string` | `'Font Controls'` | Panel title |
93
- | `collapsed` | `boolean` | `false` | Initial collapsed state |
94
- | `draggable` | `boolean` | `true` | Enable drag to reposition |
95
- | `position` | `{ x: number; y: number }` | `{ x: 20, y: 20 }` | Initial position |
113
+ - `config` - Current font configuration object
114
+ - `setConfig` - Set entire config at once
115
+ - `updateConfig` - Update a single property
116
+ - `resetConfig` - Reset to defaults
96
117
 
97
- ### FontConfig Type
118
+ ### `<FontControls>` Component
119
+
120
+ | Prop | Type | Default | Description |
121
+ | -------------- | ------------------------------ | -------------------------- | ------------------------------- |
122
+ | `value` | `Partial<FontConfig>` | - | Current font configuration |
123
+ | `onChange` | `(config: FontConfig) => void` | - | Called when config changes |
124
+ | `fontFamilies` | `string[]` | `['Inter', 'Roboto', ...]` | Custom font list (100 defaults) |
125
+ | `minFontSize` | `number` | `8` | Minimum font size |
126
+ | `maxFontSize` | `number` | `120` | Maximum font size |
127
+ | `fontSizeStep` | `number` | `1` | Font size increment |
128
+
129
+ ### `FontConfig` Type
98
130
 
99
131
  ```typescript
100
132
  interface FontConfig {
@@ -111,120 +143,59 @@ interface FontConfig {
111
143
 
112
144
  ## Advanced Usage
113
145
 
114
- ### Using the Hook
115
-
116
- For more control, you can use the `useFontControls` hook:
117
-
118
- ```tsx
119
- import { useFontControls } from "font-controls";
120
-
121
- function App() {
122
- const { config, setConfig, updateConfig, resetConfig } = useFontControls({
123
- fontFamily: "Georgia",
124
- fontSize: 24,
125
- });
126
-
127
- return (
128
- <div>
129
- <p style={{ ...config }}>Styled text</p>
130
- <button onClick={resetConfig}>Reset</button>
131
- </div>
132
- );
133
- }
134
- ```
135
-
136
146
  ### Custom Font List
137
147
 
138
148
  ```tsx
139
149
  <FontControls
140
- fontFamilies={["Inter", "Roboto", "Open Sans", "Lato", "Montserrat"]}
141
- onChange={setFontConfig}
150
+ value={config}
151
+ onChange={setConfig}
152
+ fontFamilies={["Inter", "Roboto", "Playfair Display", "Fira Code"]}
142
153
  />
143
154
  ```
144
155
 
145
- ### Custom Position
156
+ ### Without the Hook
146
157
 
147
158
  ```tsx
148
- <FontControls
149
- position={{ x: 100, y: 100 }}
150
- draggable={true}
151
- onChange={setFontConfig}
152
- />
159
+ import { useState } from "react";
160
+ import { FontControls } from "font-controls";
161
+
162
+ function App() {
163
+ const [config, setConfig] = useState({});
164
+
165
+ return <FontControls value={config} onChange={setConfig} />;
166
+ }
153
167
  ```
154
168
 
155
- ### Controlled Component
169
+ ### Update Single Property
156
170
 
157
171
  ```tsx
158
- const [config, setConfig] = useState<FontConfig>({
159
- fontFamily: "Arial",
160
- fontSize: 16,
161
- // ... other properties
162
- });
172
+ const { config, updateConfig } = useFontControls();
163
173
 
164
- <FontControls
165
- value={config}
166
- onChange={(newConfig) => {
167
- console.log("Font changed:", newConfig);
168
- setConfig(newConfig);
169
- }}
170
- />;
174
+ // Update just the font size
175
+ updateConfig("fontSize", 24);
176
+
177
+ // Update just the color
178
+ updateConfig("color", "#ff0000");
171
179
  ```
172
180
 
173
181
  ## Styling
174
182
 
175
- The library uses CSS variables for theming. You can customize the appearance:
183
+ The library uses CSS variables for theming:
176
184
 
177
185
  ```css
178
186
  :root {
179
- --fc-bg: rgba(255, 255, 255, 0.95);
180
- --fc-accent: #3b82f6;
181
- --fc-text: #1a1a1a;
182
- /* ... other variables */
187
+ --fc-bg: hsl(0, 0%, 100%); /* Panel background */
188
+ --fc-text: hsl(0, 0%, 3.9%); /* Text color */
189
+ --fc-border: hsl(0, 0%, 89.8%); /* Border color */
190
+ --fc-accent: hsl(0, 0%, 9%); /* Accent color */
183
191
  }
184
192
  ```
185
193
 
186
- ## Examples
187
-
188
- ### Basic Example
194
+ ### CSS Isolation
189
195
 
190
- ```tsx
191
- import { FontControls } from "font-controls";
192
- import "font-controls/dist/style.css";
193
-
194
- function BasicExample() {
195
- const [config, setConfig] = useState({});
196
-
197
- return <FontControls onChange={setConfig} />;
198
- }
199
- ```
200
-
201
- ### With Live Preview
202
-
203
- ```tsx
204
- function LivePreview() {
205
- const [config, setConfig] = useState({
206
- fontFamily: "Georgia",
207
- fontSize: 32,
208
- color: "#333",
209
- });
210
-
211
- return (
212
- <div>
213
- <div
214
- style={{
215
- fontFamily: config.fontFamily,
216
- fontSize: `${config.fontSize}px`,
217
- color: config.color,
218
- }}
219
- >
220
- Live preview text
221
- </div>
222
-
223
- <FontControls value={config} onChange={setConfig} />
224
- </div>
225
- );
226
- }
227
- ```
196
+ ✅ **No conflicts** - All styles are scoped to `.font-controls-panel`
197
+ **Safe to use** - Won't affect your existing CSS
198
+ **No global resets** - Your layout stays intact
228
199
 
229
200
  ## Browser Support
230
201
 
@@ -233,30 +204,10 @@ function LivePreview() {
233
204
  - Safari (latest)
234
205
  - Edge (latest)
235
206
 
236
- ## Development
237
-
238
- ```bash
239
- # Install dependencies
240
- npm install
241
-
242
- # Run demo
243
- npm run dev
244
-
245
- # Build library
246
- npm run build
247
-
248
- # Preview build
249
- npm run preview
250
- ```
251
-
252
- ## Contributing
253
-
254
- Contributions are welcome! Please feel free to submit a Pull Request.
255
-
256
207
  ## License
257
208
 
258
- MIT © [Your Name]
209
+ MIT
259
210
 
260
211
  ## Credits
261
212
 
262
- Inspired by [Leva](https://github.com/pmndrs/leva) - A GUI controls library for React.
213
+ Inspired by [Leva](https://github.com/pmndrs/leva)