superdesk-ui-framework 3.0.43 → 3.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,84 @@
1
+ import * as React from "react";
2
+ import { Icon } from "../Icon";
3
+ import {getTextColor} from '../Label';
4
+ import {ITreeNode} from './TreeSelect';
5
+
6
+ export function getPrefixedItemId(id: string) {
7
+ return id + '-focus';
8
+ }
9
+
10
+ interface IProps<T> {
11
+ option: ITreeNode<T>;
12
+ selectedItem: boolean;
13
+ allowMultiple?: boolean;
14
+ handleTree(event: React.MouseEvent<HTMLLIElement, MouseEvent>, option: ITreeNode<T>): any;
15
+ getLabel(item: T): string;
16
+ getId(item: T): string;
17
+ getBackgroundColor?(item: T): string;
18
+ getBorderColor?(item: T): string;
19
+ optionTemplate?(item: T): React.ComponentType<T> | JSX.Element;
20
+ onClick?: () => void;
21
+ onKeyDown?: () => void;
22
+ }
23
+
24
+ export class TreeSelectItem<T> extends React.Component<IProps<T>> {
25
+ render() {
26
+ return (
27
+ <li
28
+ className='suggestion-item suggestion-item--multi-select'
29
+ onClick={(event) => {
30
+ this.props.onClick?.();
31
+ event.preventDefault();
32
+ event.stopPropagation();
33
+ this.props.handleTree(event, this.props.option);
34
+ }}
35
+ >
36
+ <button
37
+ // the className is generated in order to focus the element later
38
+ className={`suggestion-item--btn ${getPrefixedItemId(this.props.getId(this.props.option.value))}`}
39
+ onKeyDown={(event) => {
40
+ if (event.key === 'Enter' && this.props.option.children) {
41
+ this.props.onKeyDown?.();
42
+ }
43
+ }}
44
+ >
45
+ {(this.props.getBorderColor && !this.props.allowMultiple)
46
+ && <div
47
+ className="item-border"
48
+ style={{
49
+ backgroundColor: this.props.getBorderColor(this.props.option.value),
50
+ }}
51
+ >
52
+ </div>
53
+ }
54
+
55
+ <span
56
+ className={
57
+ 'suggestion-item--bgcolor'
58
+ + (this.props.selectedItem ? ' suggestion-item--disabled' : '')}
59
+ style={
60
+ (this.props.getBackgroundColor && this.props.option.value)
61
+ ? {
62
+ backgroundColor: this.props.getBackgroundColor(this.props.option.value),
63
+ color: getTextColor(this.props.getBackgroundColor(this.props.option.value),
64
+ ),
65
+ }
66
+ : undefined
67
+ }
68
+ >
69
+ {this.props.optionTemplate
70
+ ? this.props.optionTemplate(this.props.option.value)
71
+ : this.props.getLabel(this.props.option.value)
72
+ }
73
+ </span>
74
+
75
+ {this.props.option.children
76
+ && <span className="suggestion-item__icon">
77
+ <Icon name="chevron-right-thin"></Icon>
78
+ </span>
79
+ }
80
+ </button>
81
+ </li>
82
+ );
83
+ }
84
+ }
@@ -0,0 +1,53 @@
1
+ import * as React from "react";
2
+ import {Icon} from "../Icon";
3
+ import {getTextColor} from '../Label';
4
+
5
+ interface IProps<T> {
6
+ item: T;
7
+ readOnly?: boolean;
8
+ disabled?: boolean;
9
+ backgroundColor: string | undefined;
10
+ onRemove(): void;
11
+ valueTemplate?(item: T, Wrapper: React.ElementType): React.ComponentType<T> | JSX.Element;
12
+ getBackgroundColor?(item: T): string;
13
+ }
14
+
15
+ export class TreeSelectPill<T> extends React.Component<IProps<T>> {
16
+ render() {
17
+ return (
18
+ <li
19
+ className={
20
+ "tags-input__tag-item tags-input__tag-item--multi-select"
21
+ + (this.props.readOnly ? ' tags-input__tag-item--readonly' : '')
22
+ }
23
+ onClick={() => (!this.props.readOnly && !this.props.disabled)
24
+ && this.props.onRemove()
25
+ }
26
+ style={
27
+ this.props.valueTemplate
28
+ ? {backgroundColor: this.props.backgroundColor}
29
+ : this.props.getBackgroundColor
30
+ && {backgroundColor: this.props.getBackgroundColor(this.props.item)}
31
+ }
32
+ >
33
+ <span
34
+ className="tags-input__helper-box"
35
+ style={{
36
+ color: this.props.backgroundColor
37
+ ? getTextColor(this.props.backgroundColor)
38
+ : this.props.getBackgroundColor
39
+ && getTextColor(this.props.getBackgroundColor(this.props.item)),
40
+ }}
41
+ >
42
+ {this.props.children}
43
+
44
+ {!this.props.readOnly
45
+ && <span className="tags-input__remove-button">
46
+ <Icon name="close-small"></Icon>
47
+ </span>
48
+ }
49
+ </span>
50
+ </li>
51
+ );
52
+ }
53
+ }
@@ -90,7 +90,7 @@ export { Text } from './components/Text/Text';
90
90
  export { Time } from './components/Text/Time';
91
91
  export { Heading } from './components/Text/Heading';
92
92
  export { BottomNav } from './components/Navigation/BottomNav';
93
- export { TreeSelect } from './components/TreeSelect';
93
+ export { TreeSelect } from './components/TreeSelect/TreeSelect';
94
94
  export { TableList, TableListItem } from './components/Lists/TableList';
95
95
  export { ContentListItem } from './components/Lists/ContentList';
96
96
  export { MultiSelect } from './components/MultiSelect';