bpo-icon-lib 0.0.1
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/LICENSE +22 -0
- package/README.md +263 -0
- package/dist/Icon.d.ts +78 -0
- package/dist/Icon.d.ts.map +1 -0
- package/dist/bpo-icon-lib.js +232 -0
- package/dist/fonts/Untitled.otf +0 -0
- package/dist/fonts/Untitled.ttf +0 -0
- package/dist/fonts/Untitled.woff +0 -0
- package/dist/fonts/Untitled.woff2 +0 -0
- package/dist/iconMap.d.ts +3 -0
- package/dist/iconMap.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/style.css +568 -0
- package/dist/vite.svg +1 -0
- package/package.json +108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 BPO Icon Library
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# BPO Icon Library
|
|
2
|
+
|
|
3
|
+
A lightweight, TypeScript-first React icon library with dynamic SVG icon loading. Easily add and use SVG icons in your React applications with full type safety.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 **TypeScript Support** - Full type definitions included
|
|
8
|
+
- ⚡ **Dynamic Icon Loading** - Automatically discovers icons from the `icons/` directory
|
|
9
|
+
- 🎨 **Customizable** - Control size, color, and styling with props
|
|
10
|
+
- 📦 **Tree-shakeable** - Only includes icons you use
|
|
11
|
+
- 🚀 **Zero Runtime** - Icons are compiled at build time
|
|
12
|
+
- ♿ **Accessible** - Includes proper ARIA attributes
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install bpo-icon-lib
|
|
18
|
+
# or
|
|
19
|
+
yarn add bpo-icon-lib
|
|
20
|
+
# or
|
|
21
|
+
pnpm add bpo-icon-lib
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Peer Dependencies
|
|
25
|
+
|
|
26
|
+
This library requires React 16.8.0 or higher:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install react react-dom
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Import
|
|
33
|
+
|
|
34
|
+
### Import the Icon Component
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { Icon } from 'bpo-icon-lib';
|
|
38
|
+
// or
|
|
39
|
+
import Icon from 'bpo-icon-lib';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Import TypeScript Types
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import type { IconProps, IconName } from 'bpo-icon-lib';
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Import Utility Functions
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import {
|
|
52
|
+
iconFontMap,
|
|
53
|
+
getIconFontCode,
|
|
54
|
+
getIconFontChar,
|
|
55
|
+
generateIconFontHTML,
|
|
56
|
+
} from 'bpo-icon-lib';
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Import CSS and Fonts
|
|
60
|
+
|
|
61
|
+
**⚠️ Important: You must import `style.css` to use the icon fonts.** The CSS file contains the `@font-face` declaration and icon styles required for the icons to display correctly.
|
|
62
|
+
|
|
63
|
+
Add the CSS file to your HTML or import it in your main entry file:
|
|
64
|
+
|
|
65
|
+
**Option 1: HTML (Recommended)**
|
|
66
|
+
|
|
67
|
+
```html
|
|
68
|
+
<link rel="stylesheet" href="node_modules/bpo-icon-lib/dist/style.css" />
|
|
69
|
+
<link
|
|
70
|
+
rel="preload"
|
|
71
|
+
href="node_modules/bpo-icon-lib/dist/fonts/Untitled.woff2"
|
|
72
|
+
as="font"
|
|
73
|
+
type="font/woff2"
|
|
74
|
+
crossorigin="anonymous"
|
|
75
|
+
/>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Option 2: JavaScript/TypeScript**
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
// In your main.tsx or App.tsx
|
|
82
|
+
// You can use either path:
|
|
83
|
+
import 'bpo-icon-lib/style.css';
|
|
84
|
+
// or
|
|
85
|
+
import 'bpo-icon-lib/dist/style.css';
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Option 3: CSS Import**
|
|
89
|
+
|
|
90
|
+
```css
|
|
91
|
+
@import 'bpo-icon-lib/style.css';
|
|
92
|
+
/* or */
|
|
93
|
+
@import 'bpo-icon-lib/dist/style.css';
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The font files are automatically available at `node_modules/bpo-icon-lib/dist/fonts/` after installation.
|
|
97
|
+
|
|
98
|
+
**Note:** Without importing `style.css`, the icons will not display correctly as the font-face definitions and icon styles are defined in the CSS file.
|
|
99
|
+
|
|
100
|
+
## Usage
|
|
101
|
+
|
|
102
|
+
### Basic Usage
|
|
103
|
+
|
|
104
|
+
**Don't forget to import the CSS file first!**
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
// Import CSS (required for fonts to work)
|
|
108
|
+
import 'bpo-icon-lib/dist/style.css';
|
|
109
|
+
import { Icon } from 'bpo-icon-lib';
|
|
110
|
+
|
|
111
|
+
function App() {
|
|
112
|
+
return (
|
|
113
|
+
<div>
|
|
114
|
+
<Icon name="spam_management" size={24} />
|
|
115
|
+
<Icon name="search" size={32} color="#ff0000" />
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### With Custom Styling
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import 'bpo-icon-lib/dist/style.css';
|
|
125
|
+
import { Icon } from 'bpo-icon-lib';
|
|
126
|
+
|
|
127
|
+
function App() {
|
|
128
|
+
return (
|
|
129
|
+
<Icon
|
|
130
|
+
name="add_circle"
|
|
131
|
+
size={48}
|
|
132
|
+
color="#646cff"
|
|
133
|
+
className="my-custom-icon"
|
|
134
|
+
style={{ margin: '10px' }}
|
|
135
|
+
/>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Inline Icons (without wrapper)
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
import 'bpo-icon-lib/dist/style.css';
|
|
144
|
+
import { Icon } from 'bpo-icon-lib';
|
|
145
|
+
|
|
146
|
+
function App() {
|
|
147
|
+
return (
|
|
148
|
+
<div>
|
|
149
|
+
<Icon name="search" size={20} color="#999" className="" />
|
|
150
|
+
<input type="text" placeholder="Search..." />
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### With Label
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
import 'bpo-icon-lib/dist/style.css';
|
|
160
|
+
import { Icon } from 'bpo-icon-lib';
|
|
161
|
+
|
|
162
|
+
function App() {
|
|
163
|
+
return <Icon name="spam_management" showLabel={true} />;
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Available Icons
|
|
168
|
+
|
|
169
|
+
The library includes 118+ icons. Some examples:
|
|
170
|
+
|
|
171
|
+
- `spam_management` - Spam management icon
|
|
172
|
+
- `search` - Search icon
|
|
173
|
+
- `add_circle` - Add circle icon
|
|
174
|
+
- `user` - User icon
|
|
175
|
+
- `settings` - Settings icon
|
|
176
|
+
- And many more...
|
|
177
|
+
|
|
178
|
+
Use TypeScript autocomplete to see all available icon names, or check the `IconName` type.
|
|
179
|
+
|
|
180
|
+
## API
|
|
181
|
+
|
|
182
|
+
### Icon Component Props
|
|
183
|
+
|
|
184
|
+
| Prop | Type | Default | Description |
|
|
185
|
+
| --------------- | --------------------- | --------------- | ------------------------------------------------------------------------------------------------------ |
|
|
186
|
+
| `name` | `IconName` | **required** | The name of the icon to display. Must be a valid icon name from the icon map. |
|
|
187
|
+
| `size` | `number` | `12` | Font size of the icon in pixels. |
|
|
188
|
+
| `color` | `string` | - | Color of the icon. Uses `currentColor` by default if not specified. |
|
|
189
|
+
| `className` | `string \| undefined` | `'_demo_glyph'` | CSS class for the wrapper div. Use `''` (empty string) to render only the icon span without a wrapper. |
|
|
190
|
+
| `iconClassName` | `string` | `'icon'` | CSS class for the icon span element. This is added alongside the `icon-{name}` class. |
|
|
191
|
+
| `showLabel` | `boolean` | `false` | Whether to display the icon name as a label below the icon. |
|
|
192
|
+
| `style` | `React.CSSProperties` | - | Inline styles to apply to the wrapper element (or icon span if `className` is empty string). |
|
|
193
|
+
|
|
194
|
+
### TypeScript Types
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
import type { IconProps, IconName } from 'bpo-icon-lib';
|
|
198
|
+
|
|
199
|
+
// IconName is a union type of available icon names
|
|
200
|
+
const iconName: IconName = 'add'; // ✅
|
|
201
|
+
const invalidName: IconName = 'invalid'; // ❌ TypeScript error
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Using Icon Font Utilities
|
|
205
|
+
|
|
206
|
+
You can also use the icon font utilities directly:
|
|
207
|
+
|
|
208
|
+
```tsx
|
|
209
|
+
import { getIconFontCode, generateIconFontHTML } from 'bpo-icon-lib';
|
|
210
|
+
|
|
211
|
+
// Get the Unicode code for an icon
|
|
212
|
+
const code = getIconFontCode('search'); // Returns: ""
|
|
213
|
+
|
|
214
|
+
// Generate HTML string
|
|
215
|
+
const html = generateIconFontHTML('spam_management');
|
|
216
|
+
// Returns: '<div class="_demo_glyph">\n <span class="icon"></span> icon-spam_management\n</div>'
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## HTML/CSS Usage
|
|
220
|
+
|
|
221
|
+
You can also use icons directly in HTML without React. **Make sure to include the CSS file first:**
|
|
222
|
+
|
|
223
|
+
```html
|
|
224
|
+
<!-- Required: Import the CSS file -->
|
|
225
|
+
<link rel="stylesheet" href="node_modules/bpo-icon-lib/dist/style.css" />
|
|
226
|
+
|
|
227
|
+
<!-- Then use icons in your HTML with the icon-{name} class format -->
|
|
228
|
+
<span class="icon-cash"></span>
|
|
229
|
+
<span class="icon-search"></span>
|
|
230
|
+
<span class="icon-spam_management"></span>
|
|
231
|
+
|
|
232
|
+
<!-- Or with the wrapper div for demo purposes -->
|
|
233
|
+
<div class="_demo_glyph"><span class="icon-cash"></span> icon-cash</div>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The CSS file is required as it contains the `@font-face` declaration and icon styles (using `:before` pseudo-elements) needed for the fonts to work. Each icon uses the class format `icon-{iconName}` where `{iconName}` matches the icon name from the icon map.
|
|
237
|
+
|
|
238
|
+
## Development
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
# Install dependencies
|
|
242
|
+
npm install
|
|
243
|
+
|
|
244
|
+
# Run development server
|
|
245
|
+
npm run dev
|
|
246
|
+
|
|
247
|
+
# Build for production
|
|
248
|
+
npm run build
|
|
249
|
+
|
|
250
|
+
# Run tests
|
|
251
|
+
npm test
|
|
252
|
+
|
|
253
|
+
# Format code
|
|
254
|
+
npm run format
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
MIT
|
|
260
|
+
|
|
261
|
+
## Contributing
|
|
262
|
+
|
|
263
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/dist/Icon.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { IconName } from './iconMap';
|
|
3
|
+
/**
|
|
4
|
+
* Props for the Icon component
|
|
5
|
+
*
|
|
6
|
+
* @interface IconProps
|
|
7
|
+
*/
|
|
8
|
+
export interface IconProps {
|
|
9
|
+
/** The name of the icon to display. Must be a valid icon name from the icon map. */
|
|
10
|
+
name: IconName;
|
|
11
|
+
/**
|
|
12
|
+
* CSS class name for the wrapper div element.
|
|
13
|
+
* - If `undefined`: defaults to `'_demo_glyph'`
|
|
14
|
+
* - If `''` (empty string): renders only the icon span without a wrapper div
|
|
15
|
+
* - If a string value: uses that as the wrapper class name
|
|
16
|
+
*/
|
|
17
|
+
className?: string;
|
|
18
|
+
/**
|
|
19
|
+
* CSS class name for the icon span element.
|
|
20
|
+
* @default 'icon'
|
|
21
|
+
*/
|
|
22
|
+
iconClassName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to display the icon name as a label below the icon.
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
showLabel?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Inline styles to apply to the wrapper element (or icon span if className is empty).
|
|
30
|
+
*/
|
|
31
|
+
style?: React.CSSProperties;
|
|
32
|
+
/**
|
|
33
|
+
* Color of the icon. Uses `currentColor` by default if not specified.
|
|
34
|
+
*/
|
|
35
|
+
color?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Font size of the icon in pixels.
|
|
38
|
+
* @default 12
|
|
39
|
+
*/
|
|
40
|
+
size?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Icon component that renders icons using icon font (CSS-based icon font).
|
|
44
|
+
*
|
|
45
|
+
* This component uses CSS classes and the `:before` pseudo-element to display icons
|
|
46
|
+
* from the icon font. The icon font must be loaded via the `style.css` file.
|
|
47
|
+
*
|
|
48
|
+
* @component
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* // Basic usage
|
|
52
|
+
* <Icon name="spam_management" />
|
|
53
|
+
*
|
|
54
|
+
* // With custom size and color
|
|
55
|
+
* <Icon name="search" size={24} color="#ff0000" />
|
|
56
|
+
*
|
|
57
|
+
* // Inline icon (no wrapper div)
|
|
58
|
+
* <Icon name="search" size={20} className="" />
|
|
59
|
+
*
|
|
60
|
+
* // With label
|
|
61
|
+
* <Icon name="add" showLabel={true} />
|
|
62
|
+
*
|
|
63
|
+
* // With custom styling
|
|
64
|
+
* <Icon
|
|
65
|
+
* name="settings"
|
|
66
|
+
* size={32}
|
|
67
|
+
* color="#646cff"
|
|
68
|
+
* className="my-icon-wrapper"
|
|
69
|
+
* style={{ margin: '10px' }}
|
|
70
|
+
* />
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @param {IconProps} props - The component props
|
|
74
|
+
* @returns {JSX.Element | null} The rendered icon component or null if icon not found
|
|
75
|
+
*/
|
|
76
|
+
export declare const Icon: React.FC<IconProps>;
|
|
77
|
+
export default Icon;
|
|
78
|
+
//# sourceMappingURL=Icon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Icon.d.ts","sourceRoot":"","sources":["../src/Icon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAG1C;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,oFAAoF;IACpF,IAAI,EAAE,QAAQ,CAAC;IACf;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAyDpC,CAAC;AAEF,eAAe,IAAI,CAAC"}
|