-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathFluentIcon.tsx
More file actions
51 lines (40 loc) · 1.49 KB
/
FluentIcon.tsx
File metadata and controls
51 lines (40 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
42
43
44
45
46
47
48
49
50
51
import { validateProps } from '@msinternal/botframework-webchat-react-valibot';
import { useStyles } from '@msinternal/botframework-webchat-styles/react';
import { createIconComponent } from 'botframework-webchat/internal';
import cx from 'classnames';
import React, { memo, useMemo, type CSSProperties } from 'react';
import { object, optional, pipe, readonly, string, type InferInput } from 'valibot';
import styles from './FluentIcon.module.css';
const baseFluentIconPropsSchema = pipe(
object({
className: optional(string()),
mask: optional(string())
}),
readonly()
);
function BaseFluentIcon(props: InferInput<typeof baseFluentIconPropsSchema>) {
const { className } = validateProps(baseFluentIconPropsSchema, props);
const classNames = useStyles(styles);
const maskStyle = useMemo(
() =>
props.mask ? ({ '--webchat__fluent-icon--mask': `url(${JSON.stringify(props.mask)})` } as CSSProperties) : {},
[props.mask]
);
return <div className={cx(classNames['fluent-icon'], className)} style={maskStyle} />;
}
const { component: FluentIcon, modifierPropsSchema } = createIconComponent(
styles,
['appearance', 'icon'],
BaseFluentIcon
);
FluentIcon.displayName = 'FluentIcon';
const fluentIconPropsSchema = pipe(
object({
...baseFluentIconPropsSchema.entries,
...modifierPropsSchema.entries
}),
readonly()
);
type FluentIconProps = InferInput<typeof fluentIconPropsSchema>;
export default memo(FluentIcon);
export { fluentIconPropsSchema, type FluentIconProps };