-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathModdableIcon.tsx
More file actions
41 lines (33 loc) · 1.49 KB
/
ModdableIcon.tsx
File metadata and controls
41 lines (33 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { validateProps } from 'botframework-webchat-react-valibot';
import classNames from 'classnames';
import React, { useMemo, type CSSProperties } from 'react';
import { object, optional, pipe, readonly, string, type InferInput } from 'valibot';
import useStyleSet from '../hooks/useStyleSet';
const moddableIconPropsSchema = pipe(
object({
className: optional(string()),
color: optional(string()),
imageURL: optional(string()),
maskURL: optional(string()),
size: optional(string())
}),
readonly()
);
type ModdableIconProps = InferInput<typeof moddableIconPropsSchema>;
function ModdableIcon(props: ModdableIconProps) {
const { className, color, imageURL, maskURL, size } = validateProps(moddableIconPropsSchema, props);
const [{ moddableIcon: moddableIconClassName }] = useStyleSet();
const style = useMemo<CSSProperties>(
() =>
({
'--webchat__moddable-icon--color': color,
'--webchat__moddable-icon--mask': maskURL && `url(${maskURL})`,
'--webchat__moddable-icon--image': imageURL && `url(${imageURL})`,
'--webchat__moddable-icon--size': size
}) satisfies Record<`--${string}`, number | string | undefined> as any, // csstype.CSSProperties does not allow CSS custom variables yet.
[color, imageURL, maskURL, size]
);
return <div className={classNames('webchat__moddable-icon', moddableIconClassName + '', className)} style={style} />;
}
export default ModdableIcon;
export { moddableIconPropsSchema, type ModdableIconProps };