-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathToolbar.tsx
More file actions
78 lines (65 loc) · 2.36 KB
/
Toolbar.tsx
File metadata and controls
78 lines (65 loc) · 2.36 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { hooks } from 'botframework-webchat';
import cx from 'classnames';
import React, { memo, type MouseEventHandler, type ReactNode } from 'react';
import { useStyles } from '../../styles';
import styles from './Toolbar.module.css';
const { useUIState } = hooks;
const preventDefaultHandler: MouseEventHandler<HTMLButtonElement> = event => event.preventDefault();
export const ToolbarButton = memo(
(
props: Readonly<{
'aria-label'?: string | undefined;
children?: ReactNode | undefined;
className?: string | undefined;
'data-testid'?: string | undefined;
disabled?: boolean | undefined;
onClick?: MouseEventHandler<HTMLButtonElement> | undefined;
selected?: boolean | undefined;
type?: 'button' | 'submit' | undefined;
}>
) => {
const classNames = useStyles(styles);
const [uiState] = useUIState();
const disabled = props.disabled || uiState === 'disabled';
return (
<button
aria-disabled={disabled ? 'true' : undefined}
aria-label={props['aria-label']}
className={cx(classNames['sendbox__toolbar-button'], props.className, {
[classNames['sendbox__toolbar-button--selected']]: props.selected
})}
data-testid={props['data-testid']}
onClick={disabled ? preventDefaultHandler : props.onClick}
// eslint-disable-next-line no-magic-numbers
tabIndex={disabled ? -1 : undefined}
type={props.type === 'submit' ? 'submit' : 'button'}
>
{props.children}
</button>
);
}
);
ToolbarButton.displayName = 'ToolbarButton';
export const Toolbar = memo((props: Readonly<{ children?: ReactNode | undefined; className?: string | undefined }>) => {
const [uiState] = useUIState();
const classNames = useStyles(styles);
return (
<div className={cx(classNames['sendbox__toolbar'], props.className)}>
{uiState !== 'blueprint' && props.children}
</div>
);
});
Toolbar.displayName = 'Toolbar';
export const ToolbarSeparator = memo(
(props: Readonly<{ children?: ReactNode | undefined; className?: string | undefined }>) => {
const classNames = useStyles(styles);
return (
<div
aria-orientation="vertical"
className={cx(classNames['sendbox__toolbar-separator'], props.className)}
role="separator"
/>
);
}
);
ToolbarSeparator.displayName = 'ToolbarSeparator';