@versini/ui-icon-picker 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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +140 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Arno Versini
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @versini/ui-icon-picker
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@versini/ui-icon-picker)
|
|
4
|
+
>)
|
|
5
|
+
|
|
6
|
+
> A flexible and accessible React icon picker component built with TypeScript and TailwindCSS.
|
|
7
|
+
|
|
8
|
+
The Icon Picker component provides a searchable grid of icons from `@versini/ui-icons`. Users can browse, search, and select icons. It supports multiple themes and accessibility features out of the box.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @versini/ui-icon-picker
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Dependencies
|
|
17
|
+
|
|
18
|
+
This package includes `@versini/ui-button` and `@versini/ui-textinput` as runtime dependencies. You also need `react` (19+) in your project.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### IconPicker
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { IconPicker } from "@versini/ui-icon-picker";
|
|
26
|
+
|
|
27
|
+
const MyComponent = () => {
|
|
28
|
+
const handleIconChange = (iconName: string) => {
|
|
29
|
+
console.info("Selected icon:", iconName);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return <IconPicker onChange={handleIconChange} />;
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### IconRenderer
|
|
37
|
+
|
|
38
|
+
Render a single icon by name:
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { IconRenderer } from "@versini/ui-icon-picker";
|
|
42
|
+
|
|
43
|
+
const MyComponent = () => {
|
|
44
|
+
return <IconRenderer icon="IconSettings" className="size-6" />;
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Props
|
|
49
|
+
|
|
50
|
+
### IconPicker
|
|
51
|
+
|
|
52
|
+
| Prop | Type | Default | Description |
|
|
53
|
+
| --------------- | ------------------------------------------------ | -------- | ------------------------------------------------- |
|
|
54
|
+
| `onChange` | `(icon: string) => void` | required | Callback fired when an icon is selected. |
|
|
55
|
+
| `className` | `string` | - | Optional class name for the root element. |
|
|
56
|
+
| `textInputMode` | `"dark" \| "light" \| "system" \| "alt-system"` | `"dark"` | Theme mode for the search input. |
|
|
57
|
+
| `noSearch` | `boolean` | `false` | If `true`, the search input is hidden. |
|
|
58
|
+
|
|
59
|
+
### IconRenderer
|
|
60
|
+
|
|
61
|
+
| Prop | Type | Default | Description |
|
|
62
|
+
| ------ | -------- | -------- | ------------------------------------------------------------ |
|
|
63
|
+
| `icon` | `string` | required | The name of the icon component to render (e.g. `"IconSettings"`). |
|
|
64
|
+
| `...rest` | `SVGProps` | - | Any additional props are passed to the underlying `<svg>` element. |
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { JSX } from 'react/jsx-runtime';
|
|
2
|
+
import { default as React_2 } from 'react';
|
|
3
|
+
|
|
4
|
+
export declare const ICON_PICKER_CLASSNAME = "av-icon-picker";
|
|
5
|
+
|
|
6
|
+
export declare const IconPicker: ({ onChange, className, textInputMode, noSearch, }: IconPickerProps) => JSX.Element;
|
|
7
|
+
|
|
8
|
+
declare type IconPickerProps = {
|
|
9
|
+
/**
|
|
10
|
+
* Optional class name for the root element of the IconPicker component.
|
|
11
|
+
*/
|
|
12
|
+
className?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Callback function that is called when an icon is selected. It receives the
|
|
15
|
+
* name of the selected icon as a parameter.
|
|
16
|
+
*/
|
|
17
|
+
onChange: (icon: string) => void;
|
|
18
|
+
/**
|
|
19
|
+
* The mode of the search input. It can be "dark", "light", "system" or
|
|
20
|
+
* "alt-system". The default value is "dark". This prop is used to set the mode
|
|
21
|
+
* of the search input, which can be useful for better integration with
|
|
22
|
+
* different themes.
|
|
23
|
+
*/
|
|
24
|
+
textInputMode?: "dark" | "light" | "system" | "alt-system";
|
|
25
|
+
/**
|
|
26
|
+
* If true, the search input will not be displayed. The default value is false.
|
|
27
|
+
* This prop can be useful if you want to use the IconPicker component without
|
|
28
|
+
* the search functionality, for example if you want to display all icons
|
|
29
|
+
* without filtering.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
noSearch?: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export declare const IconRenderer: ({ icon, ...rest }: {
|
|
36
|
+
icon: string;
|
|
37
|
+
} & React_2.ComponentPropsWithoutRef<"svg">) => JSX.Element | null;
|
|
38
|
+
|
|
39
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
@versini/ui-icon-picker v1.0.0
|
|
3
|
+
© 2026 gizmette.com
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { Button } from "@versini/ui-button/button";
|
|
8
|
+
import { ButtonIcon } from "@versini/ui-button/button-icon";
|
|
9
|
+
import { TextInput } from "@versini/ui-textinput";
|
|
10
|
+
import clsx from "clsx";
|
|
11
|
+
import { useEffect, useMemo, useState } from "react";
|
|
12
|
+
|
|
13
|
+
const ICON_PICKER_CLASSNAME = "av-icon-picker";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const useIconPicker = ()=>{
|
|
23
|
+
const [iconModule, setIconModule] = useState(null);
|
|
24
|
+
const [loading, setLoading] = useState(true);
|
|
25
|
+
useEffect(()=>{
|
|
26
|
+
import("@versini/ui-icons/all").then((mod)=>{
|
|
27
|
+
setIconModule(mod);
|
|
28
|
+
setLoading(false);
|
|
29
|
+
});
|
|
30
|
+
}, []);
|
|
31
|
+
const icons = useMemo(()=>iconModule ? Object.entries(iconModule).filter(([iconName])=>iconName !== "IconDog").map(([iconName, IconComponent])=>({
|
|
32
|
+
name: iconName,
|
|
33
|
+
friendlyName: iconName.match(/[A-Z][a-z]+/g)?.join(" ") ?? iconName,
|
|
34
|
+
Component: IconComponent
|
|
35
|
+
})) : [], [
|
|
36
|
+
iconModule
|
|
37
|
+
]);
|
|
38
|
+
const [search, setSearch] = useState("");
|
|
39
|
+
const filteredIcons = useMemo(()=>{
|
|
40
|
+
if (search === "") {
|
|
41
|
+
return icons;
|
|
42
|
+
}
|
|
43
|
+
const lowerSearch = search.toLowerCase();
|
|
44
|
+
return icons.filter((icon)=>icon.name.toLowerCase().includes(lowerSearch));
|
|
45
|
+
}, [
|
|
46
|
+
icons,
|
|
47
|
+
search
|
|
48
|
+
]);
|
|
49
|
+
return {
|
|
50
|
+
search,
|
|
51
|
+
setSearch,
|
|
52
|
+
icons: filteredIcons,
|
|
53
|
+
loading
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const IconRenderer = ({ icon, ...rest })=>{
|
|
65
|
+
const [IconComponent, setIconComponent] = useState(null);
|
|
66
|
+
useEffect(()=>{
|
|
67
|
+
setIconComponent(null);
|
|
68
|
+
import("@versini/ui-icons/all").then((mod)=>{
|
|
69
|
+
const ic = mod[icon];
|
|
70
|
+
if (ic) {
|
|
71
|
+
setIconComponent(()=>ic);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}, [
|
|
75
|
+
icon
|
|
76
|
+
]);
|
|
77
|
+
if (!IconComponent) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return /*#__PURE__*/ jsx(IconComponent, {
|
|
81
|
+
"data-slot": "icon",
|
|
82
|
+
...rest
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const IconPicker = ({ onChange, className, textInputMode = "dark", noSearch = false })=>{
|
|
86
|
+
const { search, setSearch, icons, loading } = useIconPicker();
|
|
87
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
88
|
+
className: clsx("relative", className),
|
|
89
|
+
children: [
|
|
90
|
+
!noSearch && /*#__PURE__*/ jsx(TextInput, {
|
|
91
|
+
mode: textInputMode,
|
|
92
|
+
name: "Search-icons-by-name",
|
|
93
|
+
label: "Search icons by name",
|
|
94
|
+
type: "search",
|
|
95
|
+
value: search,
|
|
96
|
+
onChange: (e)=>setSearch(e.target.value),
|
|
97
|
+
className: "mb-4"
|
|
98
|
+
}),
|
|
99
|
+
/*#__PURE__*/ jsxs("div", {
|
|
100
|
+
className: "flex h-full flex-wrap gap-2 overflow-y-scroll p-2 sm:p-4",
|
|
101
|
+
children: [
|
|
102
|
+
loading && /*#__PURE__*/ jsx("p", {
|
|
103
|
+
children: "Loading icons..."
|
|
104
|
+
}),
|
|
105
|
+
icons.map(({ name, Component })=>/*#__PURE__*/ jsxs(ButtonIcon, {
|
|
106
|
+
onClick: ()=>onChange(name),
|
|
107
|
+
label: name,
|
|
108
|
+
mode: "dark",
|
|
109
|
+
variant: "primary",
|
|
110
|
+
children: [
|
|
111
|
+
/*#__PURE__*/ jsx(Component, {}),
|
|
112
|
+
/*#__PURE__*/ jsx("span", {
|
|
113
|
+
className: "sr-only",
|
|
114
|
+
children: name
|
|
115
|
+
})
|
|
116
|
+
]
|
|
117
|
+
}, name)),
|
|
118
|
+
!loading && icons.length === 0 && /*#__PURE__*/ jsxs("div", {
|
|
119
|
+
className: "col-span-full flex grow flex-col items-center justify-center gap-2 text-center",
|
|
120
|
+
children: [
|
|
121
|
+
/*#__PURE__*/ jsx("p", {
|
|
122
|
+
children: "No icons found..."
|
|
123
|
+
}),
|
|
124
|
+
/*#__PURE__*/ jsx(Button, {
|
|
125
|
+
onClick: ()=>setSearch(""),
|
|
126
|
+
children: "Clear search"
|
|
127
|
+
})
|
|
128
|
+
]
|
|
129
|
+
})
|
|
130
|
+
]
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
/* export default */ const IconPicker_IconPicker = ((/* unused pure expression or super */ null && (IconPicker)));
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
export { ICON_PICKER_CLASSNAME, IconPicker, IconRenderer };
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@versini/ui-icon-picker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Arno Versini",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://www.npmjs.com/package/@versini/ui-icon-picker",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git@github.com:aversini/ui-components.git"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build:check": "tsc",
|
|
23
|
+
"build:js": "rslib build",
|
|
24
|
+
"build:types": "echo 'Types now built with rslib'",
|
|
25
|
+
"build": "npm-run-all --serial clean build:check build:js",
|
|
26
|
+
"clean": "rimraf dist tmp coverage",
|
|
27
|
+
"dev:js": "rslib build --watch",
|
|
28
|
+
"dev:types": "echo 'Types now watched with rslib'",
|
|
29
|
+
"dev": "rslib build --watch",
|
|
30
|
+
"lint": "biome lint src",
|
|
31
|
+
"lint:fix": "biome check src --write --no-errors-on-unmatched",
|
|
32
|
+
"prettier": "biome check --write --no-errors-on-unmatched",
|
|
33
|
+
"start": "static-server dist --port 5173",
|
|
34
|
+
"test:coverage:ui": "vitest --coverage --ui",
|
|
35
|
+
"test:coverage": "vitest run --coverage",
|
|
36
|
+
"test:watch": "vitest",
|
|
37
|
+
"test": "vitest run"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@testing-library/jest-dom": "6.9.1",
|
|
41
|
+
"@versini/ui-types": "8.4.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@versini/ui-button": "12.2.0",
|
|
45
|
+
"@versini/ui-icons": "4.20.0",
|
|
46
|
+
"@versini/ui-textinput": "6.4.4",
|
|
47
|
+
"clsx": "2.1.1",
|
|
48
|
+
"tailwindcss": "4.2.1"
|
|
49
|
+
},
|
|
50
|
+
"sideEffects": [
|
|
51
|
+
"**/*.css"
|
|
52
|
+
],
|
|
53
|
+
"gitHead": "992cb83ea45b32a2c41fc024751d33922b4146e5"
|
|
54
|
+
}
|