-
Notifications
You must be signed in to change notification settings - Fork 2
/
Item.tsx
74 lines (70 loc) · 2.64 KB
/
Item.tsx
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Toolbar
*/
import "./Item.scss";
import classnames from "classnames";
import * as React from "react";
import type { CommonProps } from "@itwin/core-react";
/** Properties of [[ToolbarButtonItem]] component.
* @public
*/
export interface ToolbarButtonItemProps extends CommonProps {
/** button icon. */
icon?: React.ReactNode;
/** Describes if item is active. */
isActive?: boolean;
/** Describes if the item is disabled. */
isDisabled?: boolean;
/** Function called when the item is clicked. */
onClick?: () => void;
/** Function called when a key is pressed. */
onKeyDown?: (e: React.KeyboardEvent) => void;
/** Title for the item. */
title: string;
/** A badge to draw. */
badge?: React.ReactNode;
/** If true add a gap before button. Default to false. */
addGroupSeparator?: boolean;
/** value added to DOM element as a data attribute to hold name of items provider. If specified in `FrontstageProvider` then this will be undefined */
providerId?: string;
/** value added to DOM element as a data attribute, shows 0 is undefined */
itemPriority?: number;
/** value added to DOM element as a data attribute */
groupPriority?: number;
}
/** Toolbar item component. Used in [[Toolbar]] component.
* @public
*/
// eslint-disable-next-line react/display-name
export const ToolbarButtonItem = React.memo<React.FC<ToolbarButtonItemProps>>(
(props: ToolbarButtonItemProps) => {
const className = classnames(
"components-toolbar-button-item",
props.isActive && "components-active",
props.isDisabled && "components-disabled",
props.className
);
return (
<button
data-item-id={props.itemId}
data-item-type="action-tool-button"
data-item-group-priority={props.groupPriority}
data-item-priority={props.itemPriority}
data-item-provider-id={props.providerId}
disabled={props.isDisabled} // this is needed to prevent focusing/keyboard access to disabled buttons
onClick={props.onClick}
onKeyDown={props.onKeyDown}
className={className}
style={props.style}
title={props.title}
>
<div className="components-icon">{props.icon}</div>
{props.badge && <div className="components-badge">{props.badge}</div>}
</button>
);
}
);