/
CheckListBox.tsx
83 lines (78 loc) · 2.35 KB
/
CheckListBox.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
75
76
77
78
79
80
81
82
83
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module CheckListBox
*/
import "./CheckListBox.scss";
import classnames from "classnames";
import * as React from "react";
import { Checkbox } from "@itwin/itwinui-react";
import type { CommonProps } from "../utils/Props";
/** Properties for the [[CheckListBoxItem]] component
* @public
*/
export interface CheckListBoxItemProps extends CommonProps {
/** Label */
label: string;
/** Indicates whether the item is checked or not */
checked?: boolean;
/** Indicates whether the item is disabled or not */
disabled?: boolean;
/** Function called when item is clicked. */
onClick?: () => any;
/** Function called when item is changed. */
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => any;
}
/** Item with a checkbox added to a [[CheckListBox]].
* @public
*/
export class CheckListBoxItem extends React.PureComponent<CheckListBoxItemProps> {
public override render() {
const className = classnames(
"core-chk-listboxitem-checkbox",
this.props.className
);
return (
<li>
<Checkbox
checked={this.props.checked}
disabled={this.props.disabled}
label={this.props.label}
onClick={this.props.onClick}
onChange={this.props.onChange}
data-testid="core-chk-listboxitem-checkbox"
wrapperProps={{
className,
style: this.props.style,
}}
/>
</li>
);
}
}
/** Separator added to a [[CheckListBox]].
* @public
*/
export function CheckListBoxSeparator() {
return <div className="core-chk-listbox-separator" />;
}
/** React component showing a list of Checkbox items.
* @public
*/
export class CheckListBox extends React.PureComponent<
CommonProps & {
/** Content */
children?: React.ReactNode;
}
> {
public override render() {
const className = classnames("core-chk-listbox", this.props.className);
return (
<ul className={className} style={this.props.style}>
{this.props.children}
</ul>
);
}
}