onecart-ui 1.0.1 → 1.0.3
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 +64 -27
- package/dist/components/Button/Button.d.ts.map +1 -1
- package/dist/components/Button/index.d.ts +2 -2
- package/dist/components/Button/index.d.ts.map +1 -1
- package/dist/components/Icon/Icon.d.ts +40 -0
- package/dist/components/Icon/Icon.d.ts.map +1 -0
- package/dist/components/Icon/IconList.d.ts +21 -0
- package/dist/components/Icon/IconList.d.ts.map +1 -0
- package/dist/components/Icon/index.d.ts +6 -0
- package/dist/components/Icon/index.d.ts.map +1 -0
- package/dist/components/Typography/Body.d.ts +4 -0
- package/dist/components/Typography/Body.d.ts.map +1 -0
- package/dist/components/Typography/Display.d.ts +4 -0
- package/dist/components/Typography/Display.d.ts.map +1 -0
- package/dist/components/Typography/Heading.d.ts +4 -0
- package/dist/components/Typography/Heading.d.ts.map +1 -0
- package/dist/components/Typography/Utility.d.ts +4 -0
- package/dist/components/Typography/Utility.d.ts.map +1 -0
- package/dist/components/Typography/index.d.ts +4 -2
- package/dist/components/Typography/index.d.ts.map +1 -1
- package/dist/index.d.ts +4 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/styles/tokens/typography.d.ts +11 -0
- package/dist/styles/tokens/typography.d.ts.map +1 -1
- package/dist/types/Button.d.ts +17 -40
- package/dist/types/Button.d.ts.map +1 -1
- package/dist/types/Typography.d.ts +20 -55
- package/dist/types/Typography.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/components/Button/Button.tsx +233 -136
- package/src/components/Button/index.ts +7 -2
- package/src/components/Icon/Icon.tsx +113 -0
- package/src/components/Icon/IconList.tsx +110 -0
- package/src/components/Icon/icons.json +81 -0
- package/src/components/Icon/index.ts +5 -0
- package/src/components/Typography/Body.tsx +94 -0
- package/src/components/Typography/Display.tsx +79 -0
- package/src/components/Typography/Heading.tsx +110 -0
- package/src/components/Typography/Utility.tsx +107 -0
- package/src/components/Typography/index.ts +4 -7
- package/src/index.ts +8 -17
- package/src/styles/tokens/tokens-autocomplete-config.json +2 -2
- package/src/styles/tokens/tokens.css +1 -1
- package/src/styles/tokens/typography.ts +11 -0
- package/src/types/Button.ts +19 -48
- package/src/types/Typography.ts +21 -81
- package/src/components/Heading/Heading.tsx +0 -48
- package/src/components/Heading/index.ts +0 -2
- package/src/components/Paragraph/Paragraph.tsx +0 -93
- package/src/components/Paragraph/index.ts +0 -6
- package/src/components/Text/Text.tsx +0 -96
- package/src/components/Text/index.ts +0 -2
- package/src/components/Typography/Typography.tsx +0 -123
- package/src/types/Heading.ts +0 -27
- package/src/types/Paragraph.ts +0 -40
- package/src/types/Text.ts +0 -40
|
@@ -1,155 +1,252 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ViewStyle,
|
|
7
|
-
TextStyle,
|
|
8
|
-
} from "react-native";
|
|
9
|
-
import { buttonTokens } from "../../styles/tokens";
|
|
10
|
-
import { ButtonProps } from "../../types/Button";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { ButtonProps, ButtonState } from "../../types/Button";
|
|
3
|
+
import { Icon } from "../Icon";
|
|
4
|
+
import typographyTokens from "../../styles/tokens/typography";
|
|
5
|
+
import * as tokens from "../../styles/tokens/tokens";
|
|
11
6
|
|
|
12
7
|
export const Button: React.FC<ButtonProps> = ({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
size = "
|
|
8
|
+
label,
|
|
9
|
+
type = "primary",
|
|
10
|
+
size = "large",
|
|
16
11
|
disabled = false,
|
|
12
|
+
leftIcon,
|
|
13
|
+
rightIcon,
|
|
14
|
+
icon,
|
|
17
15
|
fullWidth = false,
|
|
18
|
-
loading = false,
|
|
19
16
|
style,
|
|
20
|
-
textStyle,
|
|
21
17
|
accessibilityLabel,
|
|
22
18
|
testID,
|
|
23
|
-
|
|
19
|
+
onClick,
|
|
20
|
+
className,
|
|
21
|
+
onMouseEnter,
|
|
22
|
+
onMouseLeave,
|
|
23
|
+
onMouseDown,
|
|
24
|
+
onMouseUp,
|
|
24
25
|
}) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
26
|
+
const isIconOnly = !!icon;
|
|
27
|
+
|
|
28
|
+
// Create icon components from icon names
|
|
29
|
+
const leftIconComponent = leftIcon ? (
|
|
30
|
+
<Icon name={leftIcon} size={size === "large" ? 20 : 16} />
|
|
31
|
+
) : null;
|
|
32
|
+
const rightIconComponent = rightIcon ? (
|
|
33
|
+
<Icon name={rightIcon} size={size === "large" ? 20 : 16} />
|
|
34
|
+
) : null;
|
|
35
|
+
const iconButton = icon ? (
|
|
36
|
+
<Icon name={icon} size={size === "large" ? 20 : 16} />
|
|
37
|
+
) : null;
|
|
38
|
+
|
|
39
|
+
const [buttonState, setButtonState] = useState<ButtonState>(
|
|
40
|
+
disabled ? "disabled" : "default"
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const hasBothIcons = leftIcon && rightIcon;
|
|
44
|
+
|
|
45
|
+
// Base button styles
|
|
46
|
+
const getBaseStyles = (): React.CSSProperties => {
|
|
47
|
+
const baseStyle: React.CSSProperties = {
|
|
48
|
+
display: isIconOnly ? "inline-flex" : "flex",
|
|
49
|
+
width: isIconOnly ? "auto" : fullWidth ? "100%" : "9.375rem",
|
|
50
|
+
height: size === "large" ? "2.75rem" : "2rem",
|
|
51
|
+
padding: type === "ghost" ? tokens.SPACE_0 : tokens.COMPONENT_CARD_SM,
|
|
52
|
+
justifyContent: "center",
|
|
53
|
+
alignItems: "center",
|
|
54
|
+
gap: hasBothIcons
|
|
55
|
+
? tokens.LAYOUT_SPACING_INLINE_MD
|
|
56
|
+
: tokens.LAYOUT_SPACING_INLINE_XS,
|
|
57
|
+
flexShrink: 0,
|
|
58
|
+
borderRadius: tokens.BORDER_RADIUS_BUTTON_FULL,
|
|
59
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
60
|
+
opacity: disabled ? 0.6 : 1,
|
|
61
|
+
transition: "all 0.2s ease-in-out",
|
|
62
|
+
border: "none",
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Apply styles based on type and state
|
|
66
|
+
switch (type) {
|
|
67
|
+
case "primary":
|
|
68
|
+
switch (buttonState) {
|
|
69
|
+
case "default":
|
|
70
|
+
baseStyle.background = tokens.ACTION_PRIMARY_DEFAULT;
|
|
71
|
+
break;
|
|
72
|
+
case "hover":
|
|
73
|
+
baseStyle.background = tokens.ACTION_PRIMARY_HOVER;
|
|
74
|
+
break;
|
|
75
|
+
case "active":
|
|
76
|
+
baseStyle.background = tokens.ACTION_PRIMARY_ACTIVE;
|
|
77
|
+
break;
|
|
78
|
+
case "disabled":
|
|
79
|
+
baseStyle.background = tokens.ACTION_PRIMARY_DISABLED;
|
|
80
|
+
baseStyle.opacity = 0.6;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case "outline":
|
|
85
|
+
baseStyle.background = "transparent";
|
|
86
|
+
switch (buttonState) {
|
|
87
|
+
case "default":
|
|
88
|
+
baseStyle.border = `${tokens.BORDER_WIDTH_BUTTON_DEFAULT} solid ${tokens.ACTION_TERTIARY_DEFAULT}`;
|
|
89
|
+
break;
|
|
90
|
+
case "hover":
|
|
91
|
+
baseStyle.border = `${tokens.BORDER_WIDTH_BUTTON_HOVER} solid ${tokens.ACTION_TERTIARY_HOVER}`;
|
|
92
|
+
break;
|
|
93
|
+
case "active":
|
|
94
|
+
baseStyle.border = `${tokens.BORDER_WIDTH_BUTTON_PRESSED} solid ${tokens.ACTION_TERTIARY_ACTIVE}`;
|
|
95
|
+
break;
|
|
96
|
+
case "disabled":
|
|
97
|
+
baseStyle.border = `${tokens.BORDER_WIDTH_BUTTON_DEFAULT} solid ${tokens.ACTION_TERTIARY_DISABLE}`;
|
|
98
|
+
baseStyle.opacity = 0.6;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case "ghost":
|
|
103
|
+
baseStyle.background = "transparent";
|
|
104
|
+
break;
|
|
105
|
+
case "destructive":
|
|
106
|
+
baseStyle.background = "transparent";
|
|
107
|
+
switch (buttonState) {
|
|
108
|
+
case "default":
|
|
109
|
+
baseStyle.color = tokens.ACTION_DESTRUCTIVE_HOVER;
|
|
110
|
+
break;
|
|
111
|
+
case "hover":
|
|
112
|
+
baseStyle.color = tokens.ACTION_DESTRUCTIVE_DEFAULT;
|
|
113
|
+
break;
|
|
114
|
+
case "active":
|
|
115
|
+
baseStyle.color = tokens.ACTION_DESTRUCTIVE_ACTIVE;
|
|
116
|
+
break;
|
|
117
|
+
case "disabled":
|
|
118
|
+
baseStyle.color = tokens.ACTION_DESTRUCTIVE_DISABLE;
|
|
119
|
+
baseStyle.opacity = 0.6;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return { ...baseStyle, ...style };
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const getTextStyles = (): React.CSSProperties => {
|
|
129
|
+
const buttonTokens =
|
|
130
|
+
size === "large" ? typographyTokens.labelLg : typographyTokens.labelMd;
|
|
131
|
+
|
|
132
|
+
const textStyle: React.CSSProperties = {
|
|
133
|
+
fontFamily: buttonTokens.fontFamily,
|
|
134
|
+
fontWeight: parseInt(buttonTokens.fontWeight),
|
|
135
|
+
fontSize: `${buttonTokens.fontSize}px`,
|
|
136
|
+
lineHeight: `${buttonTokens.lineHeight}px`,
|
|
137
|
+
transition: "all 0.2s ease-in-out",
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
switch (type) {
|
|
141
|
+
case "primary":
|
|
142
|
+
textStyle.color = tokens.NEUTRAL_80;
|
|
143
|
+
break;
|
|
144
|
+
case "outline":
|
|
145
|
+
switch (buttonState) {
|
|
146
|
+
case "default":
|
|
147
|
+
textStyle.color = tokens.ACTION_TERTIARY_DEFAULT;
|
|
148
|
+
break;
|
|
149
|
+
case "hover":
|
|
150
|
+
textStyle.color = tokens.ACTION_TERTIARY_HOVER;
|
|
151
|
+
break;
|
|
152
|
+
case "active":
|
|
153
|
+
textStyle.color = tokens.ACTION_TERTIARY_ACTIVE;
|
|
154
|
+
break;
|
|
155
|
+
case "disabled":
|
|
156
|
+
textStyle.color = tokens.ACTION_TERTIARY_DISABLE;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
case "ghost":
|
|
161
|
+
switch (buttonState) {
|
|
162
|
+
case "default":
|
|
163
|
+
textStyle.color = tokens.ACTION_TERTIARY_DEFAULT;
|
|
164
|
+
break;
|
|
165
|
+
case "hover":
|
|
166
|
+
textStyle.color = tokens.ACTION_TERTIARY_HOVER;
|
|
167
|
+
break;
|
|
168
|
+
case "active":
|
|
169
|
+
textStyle.color = tokens.ACTION_TERTIARY_ACTIVE;
|
|
170
|
+
break;
|
|
171
|
+
case "disabled":
|
|
172
|
+
textStyle.color = tokens.ACTION_TERTIARY_DISABLE;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case "destructive":
|
|
177
|
+
break;
|
|
59
178
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
179
|
+
|
|
180
|
+
return textStyle;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// Icon styles
|
|
184
|
+
const getIconStyles = (): React.CSSProperties => {
|
|
185
|
+
return {
|
|
186
|
+
display: "flex",
|
|
187
|
+
alignItems: "center",
|
|
188
|
+
justifyContent: "center",
|
|
189
|
+
color: "currentColor",
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// Event handlers for state changes
|
|
194
|
+
const handleMouseEnter = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
195
|
+
if (!disabled) {
|
|
196
|
+
setButtonState("hover");
|
|
197
|
+
onMouseEnter && onMouseEnter(e);
|
|
78
198
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const variantConfig = buttonTokens[variant];
|
|
86
|
-
|
|
87
|
-
const baseTextStyle: TextStyle = {
|
|
88
|
-
fontSize: sizeConfig.fontSize,
|
|
89
|
-
fontWeight: buttonTokens.common.fontWeight as any,
|
|
90
|
-
lineHeight: buttonTokens.common.lineHeight,
|
|
91
|
-
color: disabled
|
|
92
|
-
? variantConfig.text.disabled
|
|
93
|
-
: variantConfig.text.default,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
...baseTextStyle,
|
|
98
|
-
...textStyle,
|
|
99
|
-
};
|
|
100
|
-
} catch (error) {
|
|
101
|
-
// Fallback styles
|
|
102
|
-
return {
|
|
103
|
-
fontSize: size === "sm" ? 12 : size === "lg" ? 18 : 16,
|
|
104
|
-
fontWeight: "500",
|
|
105
|
-
color: disabled
|
|
106
|
-
? "#8E8E93"
|
|
107
|
-
: variant === "primary"
|
|
108
|
-
? "#FFFFFF"
|
|
109
|
-
: "#007AFF",
|
|
110
|
-
...textStyle,
|
|
111
|
-
};
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const handleMouseLeave = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
202
|
+
if (!disabled) {
|
|
203
|
+
setButtonState("default");
|
|
204
|
+
onMouseLeave && onMouseLeave(e);
|
|
112
205
|
}
|
|
113
|
-
}
|
|
206
|
+
};
|
|
114
207
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
208
|
+
const handleMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
209
|
+
if (!disabled) {
|
|
210
|
+
setButtonState("active");
|
|
211
|
+
onMouseDown && onMouseDown(e);
|
|
119
212
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
...(disabled && { opacity: 0.6 }),
|
|
129
|
-
...style,
|
|
130
|
-
}),
|
|
131
|
-
[variantStyles, sizeStyles, fullWidth, disabled, style]
|
|
132
|
-
);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const handleMouseUp = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
216
|
+
if (!disabled) {
|
|
217
|
+
setButtonState("hover");
|
|
218
|
+
onMouseUp && onMouseUp(e);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
133
221
|
|
|
134
222
|
return (
|
|
135
|
-
<
|
|
136
|
-
style={
|
|
137
|
-
|
|
138
|
-
disabled={disabled
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
223
|
+
<button
|
|
224
|
+
style={getBaseStyles()}
|
|
225
|
+
onClick={onClick}
|
|
226
|
+
disabled={disabled}
|
|
227
|
+
aria-label={accessibilityLabel || label}
|
|
228
|
+
data-testid={testID}
|
|
229
|
+
className={className}
|
|
230
|
+
onMouseEnter={handleMouseEnter}
|
|
231
|
+
onMouseLeave={handleMouseLeave}
|
|
232
|
+
onMouseDown={handleMouseDown}
|
|
233
|
+
onMouseUp={handleMouseUp}
|
|
142
234
|
>
|
|
143
|
-
{
|
|
144
|
-
<
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
235
|
+
{!isIconOnly && leftIcon && (
|
|
236
|
+
<span style={getIconStyles()} className="button-left-icon">
|
|
237
|
+
{leftIconComponent}
|
|
238
|
+
</span>
|
|
239
|
+
)}
|
|
240
|
+
|
|
241
|
+
{!isIconOnly && <span style={getTextStyles()}>{label}</span>}
|
|
242
|
+
|
|
243
|
+
{isIconOnly && <span style={getIconStyles()}>{iconButton}</span>}
|
|
244
|
+
|
|
245
|
+
{!isIconOnly && rightIcon && (
|
|
246
|
+
<span style={getIconStyles()} className="button-right-icon">
|
|
247
|
+
{rightIconComponent}
|
|
248
|
+
</span>
|
|
151
249
|
)}
|
|
152
|
-
|
|
153
|
-
</TouchableOpacity>
|
|
250
|
+
</button>
|
|
154
251
|
);
|
|
155
252
|
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import iconData from './icons.json';
|
|
3
|
+
|
|
4
|
+
export interface IconProps {
|
|
5
|
+
/**
|
|
6
|
+
* Name of the icon to display
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Size of the icon in pixels
|
|
12
|
+
*/
|
|
13
|
+
size?: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Color of the icon
|
|
17
|
+
*/
|
|
18
|
+
color?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Optional CSS class name
|
|
22
|
+
*/
|
|
23
|
+
className?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Optional style overrides
|
|
27
|
+
*/
|
|
28
|
+
style?: React.CSSProperties;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Optional click handler
|
|
32
|
+
*/
|
|
33
|
+
onClick?: React.MouseEventHandler<SVGSVGElement>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Aria label for accessibility
|
|
37
|
+
*/
|
|
38
|
+
ariaLabel?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface IconData {
|
|
42
|
+
name: string;
|
|
43
|
+
path: string;
|
|
44
|
+
viewBox: string;
|
|
45
|
+
fill?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Export icon data for use in other components
|
|
49
|
+
export const icons: IconData[] = iconData.icons;
|
|
50
|
+
|
|
51
|
+
// Create a map of icon names to icon data for quick lookup
|
|
52
|
+
const iconMap = new Map<string, IconData>();
|
|
53
|
+
icons.forEach((icon) => {
|
|
54
|
+
iconMap.set(icon.name, icon);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const Icon: React.FC<IconProps> = ({
|
|
58
|
+
name,
|
|
59
|
+
size = 24,
|
|
60
|
+
color = 'currentColor',
|
|
61
|
+
className = '',
|
|
62
|
+
style = {},
|
|
63
|
+
onClick,
|
|
64
|
+
ariaLabel,
|
|
65
|
+
}) => {
|
|
66
|
+
// Find the icon data for the given name
|
|
67
|
+
const iconInfo = iconMap.get(name);
|
|
68
|
+
|
|
69
|
+
// If the icon doesn't exist, return null or a fallback
|
|
70
|
+
if (!iconInfo) {
|
|
71
|
+
console.warn(`Icon "${name}" not found`);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Split the path string into multiple paths if it contains multiple commands
|
|
76
|
+
const paths = iconInfo.path.split(' M ').map((path, index) =>
|
|
77
|
+
index === 0 ? path : `M ${path}`
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Combine the style props
|
|
81
|
+
const combinedStyle: React.CSSProperties = {
|
|
82
|
+
display: 'inline-block',
|
|
83
|
+
verticalAlign: 'middle',
|
|
84
|
+
...style,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<svg
|
|
89
|
+
width={size}
|
|
90
|
+
height={size}
|
|
91
|
+
viewBox={iconInfo.viewBox}
|
|
92
|
+
fill="none"
|
|
93
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
94
|
+
className={className}
|
|
95
|
+
style={combinedStyle}
|
|
96
|
+
onClick={onClick}
|
|
97
|
+
aria-label={ariaLabel || `${name} icon`}
|
|
98
|
+
role="img"
|
|
99
|
+
>
|
|
100
|
+
{paths.map((path, index) => (
|
|
101
|
+
<path
|
|
102
|
+
key={index}
|
|
103
|
+
d={path}
|
|
104
|
+
stroke={iconInfo.fill ? 'none' : color}
|
|
105
|
+
fill={iconInfo.fill ? color : 'none'}
|
|
106
|
+
strokeWidth="1.5"
|
|
107
|
+
strokeLinecap="round"
|
|
108
|
+
strokeLinejoin="round"
|
|
109
|
+
/>
|
|
110
|
+
))}
|
|
111
|
+
</svg>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Icon, icons, IconData } from './Icon';
|
|
3
|
+
|
|
4
|
+
export interface IconListProps {
|
|
5
|
+
/**
|
|
6
|
+
* Search query to filter icons
|
|
7
|
+
*/
|
|
8
|
+
searchQuery?: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Size of each icon
|
|
12
|
+
*/
|
|
13
|
+
iconSize?: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Color of each icon
|
|
17
|
+
*/
|
|
18
|
+
iconColor?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Function to handle when an icon is clicked
|
|
22
|
+
*/
|
|
23
|
+
onIconClick?: (iconName: string) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const IconList: React.FC<IconListProps> = ({
|
|
27
|
+
searchQuery = '',
|
|
28
|
+
iconSize = 24,
|
|
29
|
+
iconColor = 'currentColor',
|
|
30
|
+
onIconClick,
|
|
31
|
+
}) => {
|
|
32
|
+
// Filter icons based on the search query
|
|
33
|
+
const filteredIcons = searchQuery
|
|
34
|
+
? icons.filter(icon =>
|
|
35
|
+
icon.name.toLowerCase().includes(searchQuery.toLowerCase())
|
|
36
|
+
)
|
|
37
|
+
: icons;
|
|
38
|
+
|
|
39
|
+
const handleIconClick = (iconName: string) => {
|
|
40
|
+
if (onIconClick) {
|
|
41
|
+
onIconClick(iconName);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div>
|
|
47
|
+
{filteredIcons.length === 0 ? (
|
|
48
|
+
<div style={{ padding: '20px', textAlign: 'center' }}>
|
|
49
|
+
No icons found matching "{searchQuery}"
|
|
50
|
+
</div>
|
|
51
|
+
) : (
|
|
52
|
+
<div
|
|
53
|
+
style={{
|
|
54
|
+
display: 'grid',
|
|
55
|
+
gridTemplateColumns: 'repeat(auto-fill, minmax(100px, 1fr))',
|
|
56
|
+
gap: '20px',
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{filteredIcons.map((icon: IconData) => (
|
|
60
|
+
<div
|
|
61
|
+
key={icon.name}
|
|
62
|
+
style={{
|
|
63
|
+
display: 'flex',
|
|
64
|
+
flexDirection: 'column',
|
|
65
|
+
alignItems: 'center',
|
|
66
|
+
padding: '12px',
|
|
67
|
+
border: '1px solid #eee',
|
|
68
|
+
borderRadius: '8px',
|
|
69
|
+
cursor: onIconClick ? 'pointer' : 'default',
|
|
70
|
+
transition: 'all 0.2s ease-in-out',
|
|
71
|
+
}}
|
|
72
|
+
onClick={() => handleIconClick(icon.name)}
|
|
73
|
+
onMouseOver={(e) => {
|
|
74
|
+
e.currentTarget.style.backgroundColor = '#f9f9f9';
|
|
75
|
+
e.currentTarget.style.transform = 'translateY(-2px)';
|
|
76
|
+
e.currentTarget.style.boxShadow = '0 2px 8px rgba(0,0,0,0.05)';
|
|
77
|
+
}}
|
|
78
|
+
onMouseOut={(e) => {
|
|
79
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
80
|
+
e.currentTarget.style.transform = 'translateY(0)';
|
|
81
|
+
e.currentTarget.style.boxShadow = 'none';
|
|
82
|
+
}}
|
|
83
|
+
>
|
|
84
|
+
<div
|
|
85
|
+
style={{
|
|
86
|
+
display: 'flex',
|
|
87
|
+
alignItems: 'center',
|
|
88
|
+
justifyContent: 'center',
|
|
89
|
+
height: '50px',
|
|
90
|
+
marginBottom: '8px',
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<Icon name={icon.name} size={iconSize} color={iconColor} />
|
|
94
|
+
</div>
|
|
95
|
+
<div
|
|
96
|
+
style={{
|
|
97
|
+
fontSize: '12px',
|
|
98
|
+
textAlign: 'center',
|
|
99
|
+
wordBreak: 'break-word',
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
{icon.name}
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
))}
|
|
106
|
+
</div>
|
|
107
|
+
)}
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
};
|