font-controls 1.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 +262 -0
- package/dist/font-controls.js +2840 -0
- package/dist/font-controls.umd.cjs +74 -0
- package/dist/index.d.ts +97 -0
- package/dist/style.css +1 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# Font Controls
|
|
2
|
+
|
|
3
|
+
A beautiful, Leva-inspired font controls library for React. Provides an intuitive GUI panel for adjusting typography settings in real-time.
|
|
4
|
+
|
|
5
|
+
  
|
|
6
|
+
|
|
7
|
+
## Features
|
|
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
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install font-controls
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
or
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add font-controls
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
or
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm add font-controls
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { FontControls } from "font-controls";
|
|
40
|
+
import "font-controls/dist/style.css";
|
|
41
|
+
import { useState } from "react";
|
|
42
|
+
|
|
43
|
+
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
|
+
});
|
|
54
|
+
|
|
55
|
+
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} />
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**That's it!** Google Fonts are loaded automatically - no need to add `<link>` tags to your HTML.
|
|
79
|
+
|
|
80
|
+
## API Reference
|
|
81
|
+
|
|
82
|
+
### FontControls Props
|
|
83
|
+
|
|
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 |
|
|
96
|
+
|
|
97
|
+
### FontConfig Type
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
interface FontConfig {
|
|
101
|
+
fontFamily: string;
|
|
102
|
+
fontSize: number;
|
|
103
|
+
fontWeight: number;
|
|
104
|
+
lineHeight: number;
|
|
105
|
+
letterSpacing: number;
|
|
106
|
+
textTransform: "none" | "uppercase" | "lowercase" | "capitalize";
|
|
107
|
+
color: string;
|
|
108
|
+
textAlign: "left" | "center" | "right" | "justify";
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Advanced Usage
|
|
113
|
+
|
|
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
|
+
### Custom Font List
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
<FontControls
|
|
140
|
+
fontFamilies={["Inter", "Roboto", "Open Sans", "Lato", "Montserrat"]}
|
|
141
|
+
onChange={setFontConfig}
|
|
142
|
+
/>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Custom Position
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
<FontControls
|
|
149
|
+
position={{ x: 100, y: 100 }}
|
|
150
|
+
draggable={true}
|
|
151
|
+
onChange={setFontConfig}
|
|
152
|
+
/>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Controlled Component
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
const [config, setConfig] = useState<FontConfig>({
|
|
159
|
+
fontFamily: "Arial",
|
|
160
|
+
fontSize: 16,
|
|
161
|
+
// ... other properties
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
<FontControls
|
|
165
|
+
value={config}
|
|
166
|
+
onChange={(newConfig) => {
|
|
167
|
+
console.log("Font changed:", newConfig);
|
|
168
|
+
setConfig(newConfig);
|
|
169
|
+
}}
|
|
170
|
+
/>;
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Styling
|
|
174
|
+
|
|
175
|
+
The library uses CSS variables for theming. You can customize the appearance:
|
|
176
|
+
|
|
177
|
+
```css
|
|
178
|
+
:root {
|
|
179
|
+
--fc-bg: rgba(255, 255, 255, 0.95);
|
|
180
|
+
--fc-accent: #3b82f6;
|
|
181
|
+
--fc-text: #1a1a1a;
|
|
182
|
+
/* ... other variables */
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Examples
|
|
187
|
+
|
|
188
|
+
### Basic Example
|
|
189
|
+
|
|
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
|
+
```
|
|
228
|
+
|
|
229
|
+
## Browser Support
|
|
230
|
+
|
|
231
|
+
- Chrome (latest)
|
|
232
|
+
- Firefox (latest)
|
|
233
|
+
- Safari (latest)
|
|
234
|
+
- Edge (latest)
|
|
235
|
+
|
|
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
|
+
## License
|
|
257
|
+
|
|
258
|
+
MIT © [Your Name]
|
|
259
|
+
|
|
260
|
+
## Credits
|
|
261
|
+
|
|
262
|
+
Inspired by [Leva](https://github.com/pmndrs/leva) - A GUI controls library for React.
|