onekijs-ui 0.16.2 → 0.16.3
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.
- package/dist/components/list/DropdownList.d.ts +1 -0
- package/dist/components/list/components/ArrayListComponent.d.ts +1 -0
- package/dist/components/list/components/CollectionListComponent.d.ts +1 -0
- package/dist/components/list/components/ListBodyComponent.d.ts +1 -0
- package/dist/components/list/components/ListComponent.d.ts +1 -0
- package/dist/components/list/components/VirtualListComponent.d.ts +1 -0
- package/dist/components/list/index.d.ts +1 -0
- package/dist/components/select/TreeSelect.d.ts +0 -1
- package/dist/components/select/components/ControlledSelectComponent.d.ts +1 -1
- package/dist/components/select/components/SelectTokensComponent.d.ts +1 -1
- package/dist/components/select/index.d.ts +0 -1
- package/dist/components/select/typings.d.ts +3 -0
- package/dist/components/tree/components/ArrayTreeComponent.d.ts +1 -0
- package/dist/components/tree/components/ControllerTreeComponent.d.ts +1 -0
- package/dist/components/tree/components/TreeBodyComponent.d.ts +1 -0
- package/dist/components/tree/components/TreeComponent.d.ts +1 -0
- package/dist/components/tree/components/TreeItemComponent.d.ts +1 -0
- package/dist/components/tree/components/TreeListComponent.d.ts +1 -0
- package/dist/components/tree/components/VirtualTreeBodyComponent.d.ts +1 -0
- package/dist/components/tree/components/VirtualTreeListComponent.d.ts +1 -0
- package/dist/components/tree/index.d.ts +1 -0
- package/dist/index.js +73 -29
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +73 -29
- package/dist/index.module.js.map +1 -1
- package/dist/styles/size.d.ts +6 -6
- package/dist/styles/typography.d.ts +1 -1
- package/package.json +3 -3
- package/src/components/icon/LoadingIcon.tsx +12 -3
- package/src/components/select/FormSelect.tsx +5 -7
- package/src/components/select/SelectService.ts +3 -1
- package/src/components/select/components/ControlledSelectComponent.tsx +4 -0
- package/src/components/select/components/SelectInputComponent.tsx +7 -4
- package/src/components/select/components/SelectTokenComponent.tsx +2 -1
- package/src/components/select/components/SelectTokensComponent.tsx +29 -18
- package/src/components/select/style.ts +10 -1
- package/src/components/select/typings.ts +3 -0
- package/src/components/table/components/ControllerTableComponent.tsx +1 -1
- package/src/components/table/components/filters/TableSelectFilterComponent.tsx +2 -1
- package/src/components/tooltip/components/TooltipComponent.tsx +24 -2
package/dist/styles/size.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { OverscrollBehaviorBlockProperty, OverscrollBehaviorInlineProperty, OverscrollBehaviorXProperty, OverscrollBehaviorYProperty } from 'csstype';
|
|
2
|
-
export declare const width: import("./typings").CssProperty<string | 0 |
|
|
3
|
-
export declare const minWidth: import("./typings").CssProperty<string | 0 |
|
|
4
|
-
export declare const maxWidth: import("./typings").CssProperty<string | 0 |
|
|
5
|
-
export declare const height: import("./typings").CssProperty<string | 0 |
|
|
6
|
-
export declare const minHeight: import("./typings").CssProperty<string | 0 |
|
|
7
|
-
export declare const maxHeight: import("./typings").CssProperty<string | 0 |
|
|
2
|
+
export declare const width: import("./typings").CssProperty<string | 0 | 4 | 5 | 6 | 8 | 10 | 1 | 2 | 3 | 12 | 16 | 20 | 24 | 32 | 40 | 48 | 56 | 64>;
|
|
3
|
+
export declare const minWidth: import("./typings").CssProperty<string | 0 | 4 | 5 | 6 | 8 | 10 | 1 | 2 | 3 | 12 | 16 | 20 | 24 | 32 | 40 | 48 | 56 | 64>;
|
|
4
|
+
export declare const maxWidth: import("./typings").CssProperty<string | 0 | 4 | 5 | 6 | 8 | 10 | 1 | 2 | 3 | 12 | 16 | 20 | 24 | 32 | 40 | 48 | 56 | 64>;
|
|
5
|
+
export declare const height: import("./typings").CssProperty<string | 0 | 4 | 5 | 6 | 8 | 10 | 1 | 2 | 3 | 12 | 16 | 20 | 24 | 32 | 40 | 48 | 56 | 64>;
|
|
6
|
+
export declare const minHeight: import("./typings").CssProperty<string | 0 | 4 | 5 | 6 | 8 | 10 | 1 | 2 | 3 | 12 | 16 | 20 | 24 | 32 | 40 | 48 | 56 | 64>;
|
|
7
|
+
export declare const maxHeight: import("./typings").CssProperty<string | 0 | 4 | 5 | 6 | 8 | 10 | 1 | 2 | 3 | 12 | 16 | 20 | 24 | 32 | 40 | 48 | 56 | 64>;
|
|
8
8
|
export declare const overscrollBehavior: import("./typings").CssProperty<string>;
|
|
9
9
|
export declare const overscrollBehaviorBlock: import("./typings").CssProperty<OverscrollBehaviorBlockProperty>;
|
|
10
10
|
export declare const overscrollBehaviorInline: import("./typings").CssProperty<OverscrollBehaviorInlineProperty>;
|
|
@@ -20,7 +20,7 @@ export declare const fontVariantLigatures: import("./typings").CssProperty<strin
|
|
|
20
20
|
export declare const fontVariantNumeric: import("./typings").CssProperty<string>;
|
|
21
21
|
export declare const fontVariantPosition: import("./typings").CssProperty<FontVariantPositionProperty>;
|
|
22
22
|
export declare const fontVariationSettings: import("./typings").CssProperty<string>;
|
|
23
|
-
export declare const fontWeight: import("./typings").CssProperty<number | "
|
|
23
|
+
export declare const fontWeight: import("./typings").CssProperty<number | "medium" | "lighter" | "light" | "black" | "-moz-initial" | "inherit" | "initial" | "revert" | "revert-layer" | "unset" | "thin" | "hairline" | "normal" | "semibold" | "bold" | "extrabold" | "bolder">;
|
|
24
24
|
export declare const hyphens: import("./typings").CssProperty<HyphensProperty>;
|
|
25
25
|
export declare const letterSpacing: import("./typings").CssProperty<LetterSpacingProperty<TLength>>;
|
|
26
26
|
export declare const lineHeight: import("./typings").CssProperty<string | number>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onekijs-ui",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.3",
|
|
5
5
|
"description": "Opiniated React framework built on top of Next.js",
|
|
6
6
|
"source": "src/index.ts",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@clr/city": "^1.1.0",
|
|
34
34
|
"@popperjs/core": "^2.4.4",
|
|
35
|
-
"onekijs-framework": "^0.16.
|
|
35
|
+
"onekijs-framework": "^0.16.3",
|
|
36
36
|
"react-icons": "^4.2.0",
|
|
37
37
|
"react-popper": "^2.2.3",
|
|
38
38
|
"react-popper-tooltip": "^4.2.0",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"react-dom": ">=18"
|
|
53
53
|
},
|
|
54
54
|
"sideEffects": false,
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "c368e1d54b7e1efa2e21804a089cbfe4d8fd2d75"
|
|
56
56
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import styled, { css, keyframes } from 'styled-components';
|
|
3
3
|
import { stroke } from '../../styles/svg';
|
|
4
|
+
import { ComponentStyle } from '../../styles/typings';
|
|
4
5
|
import { addClassname } from '../../utils/style';
|
|
5
6
|
import { IconProps } from './typings';
|
|
6
7
|
|
|
@@ -40,8 +41,12 @@ const iconCircleKeyFrame = keyframes`
|
|
|
40
41
|
}
|
|
41
42
|
`;
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
const iconStyle: ComponentStyle<IconProps> = ({
|
|
45
|
+
width: cssWidth = '16px',
|
|
46
|
+
height: cssHeight = '16px',
|
|
47
|
+
color: cssColor = 'primary',
|
|
48
|
+
}) => {
|
|
49
|
+
return css`
|
|
45
50
|
height: ${cssHeight};
|
|
46
51
|
width: ${cssWidth};
|
|
47
52
|
display: inline-flex;
|
|
@@ -60,5 +65,9 @@ export default styled(IconComponent)`
|
|
|
60
65
|
stroke-width: 10px;
|
|
61
66
|
transform-origin: 50% 50%;
|
|
62
67
|
}
|
|
63
|
-
|
|
68
|
+
`;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default styled(IconComponent)`
|
|
72
|
+
${iconStyle}
|
|
64
73
|
`;
|
|
@@ -5,19 +5,17 @@ import useFieldLayout from '../field/hooks/useFieldLayout';
|
|
|
5
5
|
import { FormSelectProps, SelectItem, SelectProps } from './typings';
|
|
6
6
|
|
|
7
7
|
const FormSelect = <T = any, I extends SelectItem<T> = SelectItem<T>>(props: FormSelectProps<T, I>) => {
|
|
8
|
+
const defaultValue = props.defaultValue === undefined ? (props.multiple ? [] : null) : props.defaultValue;
|
|
8
9
|
const [fieldLayoutProps, fieldComponentProps] = useFieldLayout<SelectProps<T, I>>(
|
|
9
|
-
Object.assign(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
props,
|
|
14
|
-
),
|
|
10
|
+
Object.assign({}, props, {
|
|
11
|
+
defaultValue,
|
|
12
|
+
}),
|
|
15
13
|
);
|
|
16
14
|
const Component = props.FieldComponent || Select;
|
|
17
15
|
|
|
18
16
|
return (
|
|
19
17
|
<FieldLayout {...fieldLayoutProps} required={props.required}>
|
|
20
|
-
<Component {...fieldComponentProps} required={props.required} defaultValue={
|
|
18
|
+
<Component {...fieldComponentProps} required={props.required} defaultValue={defaultValue} />
|
|
21
19
|
</FieldLayout>
|
|
22
20
|
);
|
|
23
21
|
};
|
|
@@ -61,7 +61,9 @@ class SelectService<
|
|
|
61
61
|
yield this._setValidDefaultValue(
|
|
62
62
|
this.config === undefined || this.config.nullable || !this.state.items
|
|
63
63
|
? null
|
|
64
|
-
: this.config.defaultValue === undefined ||
|
|
64
|
+
: this.config.defaultValue === undefined ||
|
|
65
|
+
this.config.defaultValue === null ||
|
|
66
|
+
this.state.defaultValue === null
|
|
65
67
|
? this.state.items[0]?.data || null
|
|
66
68
|
: null,
|
|
67
69
|
);
|
|
@@ -109,6 +109,7 @@ const ControlledSelectComponent = <
|
|
|
109
109
|
clickable = true,
|
|
110
110
|
ListComponent = DefaultSelectListComponent,
|
|
111
111
|
autoCompleteSearch = true,
|
|
112
|
+
maxDisplayTokens,
|
|
112
113
|
}: ControllerSelectProps<T, I, S, C>) => {
|
|
113
114
|
if (nullable === undefined) {
|
|
114
115
|
nullable = !required;
|
|
@@ -152,6 +153,7 @@ const ControlledSelectComponent = <
|
|
|
152
153
|
sameWidth,
|
|
153
154
|
overscan,
|
|
154
155
|
autoCompleteSearch,
|
|
156
|
+
maxDisplayTokens,
|
|
155
157
|
};
|
|
156
158
|
} else {
|
|
157
159
|
service.config = {
|
|
@@ -188,6 +190,7 @@ const ControlledSelectComponent = <
|
|
|
188
190
|
sameWidth,
|
|
189
191
|
overscan,
|
|
190
192
|
autoCompleteSearch,
|
|
193
|
+
maxDisplayTokens,
|
|
191
194
|
};
|
|
192
195
|
}
|
|
193
196
|
|
|
@@ -613,6 +616,7 @@ const ControlledSelectComponent = <
|
|
|
613
616
|
ref={triggerRef}
|
|
614
617
|
disabled={disabled}
|
|
615
618
|
autoCompleteSearch={autoCompleteSearch}
|
|
619
|
+
maxDisplayTokens={maxDisplayTokens}
|
|
616
620
|
/>
|
|
617
621
|
<Dropdown
|
|
618
622
|
attachToBody={attachDropdownToBody}
|
|
@@ -27,6 +27,7 @@ const SelectInputComponent = <T, I extends SelectItem<T> = SelectItem<T>>(
|
|
|
27
27
|
searchable,
|
|
28
28
|
minChars,
|
|
29
29
|
disabled,
|
|
30
|
+
maxDisplayTokens,
|
|
30
31
|
}: SelectInputProps<T, I>,
|
|
31
32
|
ref: React.ForwardedRef<HTMLDivElement>,
|
|
32
33
|
) => {
|
|
@@ -199,8 +200,9 @@ const SelectInputComponent = <T, I extends SelectItem<T> = SelectItem<T>>(
|
|
|
199
200
|
|
|
200
201
|
return (
|
|
201
202
|
<div className={className} style={style} ref={ref}>
|
|
202
|
-
<div className="o-select-input-data">
|
|
203
|
-
{multiple && <SelectTokensComponent tokens={tokens} onRemove={onRemove} />}
|
|
203
|
+
<div className="o-select-input-data" onClick={searchable ? undefined : onClick}>
|
|
204
|
+
{multiple && <SelectTokensComponent tokens={tokens} onRemove={onRemove} maxDisplayTokens={maxDisplayTokens} />}
|
|
205
|
+
|
|
204
206
|
<div className="o-select-input-wrapper">
|
|
205
207
|
<span ref={autoSizeRef} className="o-select-input-auto-sizer" />
|
|
206
208
|
<input
|
|
@@ -212,7 +214,7 @@ const SelectInputComponent = <T, I extends SelectItem<T> = SelectItem<T>>(
|
|
|
212
214
|
onChange={handleChange}
|
|
213
215
|
onKeyDown={handleKeyDown}
|
|
214
216
|
onKeyUp={handleKeyUp}
|
|
215
|
-
value={proxyValue}
|
|
217
|
+
value={searchable ? proxyValue : ''}
|
|
216
218
|
onClick={onClick}
|
|
217
219
|
autoCapitalize="none"
|
|
218
220
|
autoComplete="off"
|
|
@@ -220,9 +222,10 @@ const SelectInputComponent = <T, I extends SelectItem<T> = SelectItem<T>>(
|
|
|
220
222
|
spellCheck="false"
|
|
221
223
|
disabled={disabled}
|
|
222
224
|
/>
|
|
225
|
+
|
|
223
226
|
{!searchable && (
|
|
224
227
|
<span className="o-select-input o-select-input-text" onClick={onClick}>
|
|
225
|
-
{proxyValue || ''}
|
|
228
|
+
{multiple ? '' : proxyValue || ''}
|
|
226
229
|
</span>
|
|
227
230
|
)}
|
|
228
231
|
</div>
|
|
@@ -14,8 +14,9 @@ const SelectTokenComponent = <T, I extends SelectItem<T> = SelectItem<T>>({
|
|
|
14
14
|
<div
|
|
15
15
|
className="o-select-token-remove"
|
|
16
16
|
key="o-select-token-remove"
|
|
17
|
-
onClick={() => {
|
|
17
|
+
onClick={(e) => {
|
|
18
18
|
onRemove(token, index);
|
|
19
|
+
e.stopPropagation();
|
|
19
20
|
}}
|
|
20
21
|
>
|
|
21
22
|
✖
|
|
@@ -6,6 +6,7 @@ import SelectTokenComponent from './SelectTokenComponent';
|
|
|
6
6
|
const SelectTokensComponent = <T, I extends SelectItem<T> = SelectItem<T>>({
|
|
7
7
|
tokens,
|
|
8
8
|
onRemove,
|
|
9
|
+
maxDisplayTokens,
|
|
9
10
|
}: SelectTokensProps<T, I>) => {
|
|
10
11
|
const widthRef = useRef<number>();
|
|
11
12
|
|
|
@@ -26,24 +27,34 @@ const SelectTokensComponent = <T, I extends SelectItem<T> = SelectItem<T>>({
|
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
if (tokens !== undefined) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
if (!maxDisplayTokens || tokens.length <= maxDisplayTokens) {
|
|
31
|
+
return (
|
|
32
|
+
<TransitionGroup component={null}>
|
|
33
|
+
{tokens.map((token, index) => (
|
|
34
|
+
<CSSTransition
|
|
35
|
+
timeout={150}
|
|
36
|
+
classNames="o-select-token-animation"
|
|
37
|
+
mountOnEnter={true}
|
|
38
|
+
appear={true}
|
|
39
|
+
unmountOnExit={true}
|
|
40
|
+
key={`o-select-token-${token.id}`}
|
|
41
|
+
onEntering={onEntering}
|
|
42
|
+
onExiting={onExiting}
|
|
43
|
+
>
|
|
44
|
+
<SelectTokenComponent token={token} onRemove={onRemove} index={index} />
|
|
45
|
+
</CSSTransition>
|
|
46
|
+
))}
|
|
47
|
+
</TransitionGroup>
|
|
48
|
+
);
|
|
49
|
+
} else {
|
|
50
|
+
return (
|
|
51
|
+
<div className="o-select-token o-select-token-disabled">
|
|
52
|
+
<div className="o-select-token-text" key="o-select-token-text">
|
|
53
|
+
{tokens.length} selected
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
59
|
return null;
|
|
49
60
|
};
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
marginY,
|
|
25
25
|
padding,
|
|
26
26
|
paddingLeft,
|
|
27
|
+
paddingRight,
|
|
27
28
|
paddingTop,
|
|
28
29
|
paddingX,
|
|
29
30
|
paddingY,
|
|
@@ -227,7 +228,8 @@ const selectStyle: ComponentStyle<SelectProps> = ({ theme, clickable = true, sea
|
|
|
227
228
|
${flexGrow(1)}
|
|
228
229
|
${flexWrap('wrap')}
|
|
229
230
|
${alignItems('center')}
|
|
230
|
-
${
|
|
231
|
+
${paddingLeft('sm')}
|
|
232
|
+
${paddingRight(searchable ? 'sm' : 0)}
|
|
231
233
|
${maxWidth('calc(100% - 32px)')}
|
|
232
234
|
}
|
|
233
235
|
|
|
@@ -272,6 +274,13 @@ const selectStyle: ComponentStyle<SelectProps> = ({ theme, clickable = true, sea
|
|
|
272
274
|
${flexGrow(1)}
|
|
273
275
|
${paddingLeft('sm')}
|
|
274
276
|
}
|
|
277
|
+
|
|
278
|
+
.o-select-token-disabled {
|
|
279
|
+
${paddingRight('sm')}
|
|
280
|
+
${backgroundColor('dark')}
|
|
281
|
+
${color('lightest')}
|
|
282
|
+
}
|
|
283
|
+
|
|
275
284
|
.o-select-token-remove {
|
|
276
285
|
${cursor('pointer')}
|
|
277
286
|
${color('white', { hover: 'danger' })}
|
|
@@ -98,6 +98,7 @@ export interface SelectInputProps<T = any, I extends SelectItem<T> = SelectItem<
|
|
|
98
98
|
clickable: boolean;
|
|
99
99
|
minChars: number;
|
|
100
100
|
autoCompleteSearch: boolean;
|
|
101
|
+
maxDisplayTokens?: number;
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
export type SelectGroup =
|
|
@@ -191,6 +192,7 @@ export type SelectConfig<T = any, I extends SelectItem<T> = SelectItem<T>> = Omi
|
|
|
191
192
|
sameWidth?: boolean;
|
|
192
193
|
ListComponent?: React.FC<SelectListComponentProps<T, I>>;
|
|
193
194
|
autoCompleteSearch?: boolean;
|
|
195
|
+
maxDisplayTokens?: number;
|
|
194
196
|
};
|
|
195
197
|
|
|
196
198
|
export type SelectListComponentProps<T = any, I extends SelectItem<T> = SelectItem<T>> = CollectionListProps<T, I> & {
|
|
@@ -206,6 +208,7 @@ export type SelectState<T = any, I extends SelectItem<T> = SelectItem<T>> = List
|
|
|
206
208
|
export interface SelectTokensProps<T = any, I extends SelectItem<T> = SelectItem<T>> {
|
|
207
209
|
tokens?: I[];
|
|
208
210
|
onRemove: SelectOptionHandler<T, I>;
|
|
211
|
+
maxDisplayTokens?: number;
|
|
209
212
|
}
|
|
210
213
|
|
|
211
214
|
export interface SelectTokenProps<T = any, I extends SelectItem<T> = SelectItem<T>> {
|
|
@@ -4,10 +4,10 @@ import { TableConfigContext } from '../hooks/useTableConfig';
|
|
|
4
4
|
import { TableServiceContext } from '../hooks/useTableService';
|
|
5
5
|
import { TableStateContext } from '../hooks/useTableState';
|
|
6
6
|
import { ControllerTableProps, TableConfig } from '../typings';
|
|
7
|
-
import ExpandedCellComponent from './cells/ExpandedCellComponent';
|
|
8
7
|
import TableBodyComponent from './TableBodyComponent';
|
|
9
8
|
import TableFooterComponent from './TableFooterComponent';
|
|
10
9
|
import TableHeaderComponent from './TableHeaderComponent';
|
|
10
|
+
import ExpandedCellComponent from './cells/ExpandedCellComponent';
|
|
11
11
|
|
|
12
12
|
const ControllerTableComponent: React.FC<ControllerTableProps> = ({
|
|
13
13
|
autoRefresh,
|
|
@@ -31,7 +31,7 @@ const addFilter = (
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const operators: TableFilterOperator[] = [{ text: '
|
|
34
|
+
const operators: TableFilterOperator[] = [{ text: 'any of', operator: 'in', not: false }];
|
|
35
35
|
|
|
36
36
|
const TableSelectFilterComponent: React.FC<TableHeaderCellProps & { dataSource: [unknown, string][] | string[] }> = ({
|
|
37
37
|
column,
|
|
@@ -73,6 +73,7 @@ const TableSelectFilterComponent: React.FC<TableHeaderCellProps & { dataSource:
|
|
|
73
73
|
onChange={onValueChange}
|
|
74
74
|
size="xsmall"
|
|
75
75
|
attachDropdownToBody={true}
|
|
76
|
+
maxDisplayTokens={1}
|
|
76
77
|
/>
|
|
77
78
|
</div>
|
|
78
79
|
);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { FCC } from 'onekijs-framework';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect, useId, useState } from 'react';
|
|
3
3
|
import { usePopperTooltip } from 'react-popper-tooltip';
|
|
4
4
|
import { addClassname } from '../../../utils/style';
|
|
5
5
|
import { TooltipProps } from '../typings';
|
|
6
6
|
|
|
7
7
|
const TooltipComponent: FCC<TooltipProps> = (props) => {
|
|
8
8
|
const { content, className, popperOptions, children, delayHide = 300, ...tooltipConfig } = props;
|
|
9
|
+
const [show, setShow] = useState<boolean>(true);
|
|
9
10
|
const tooltipOptions = Object.assign(
|
|
10
11
|
{
|
|
11
12
|
interactive: true,
|
|
@@ -21,11 +22,32 @@ const TooltipComponent: FCC<TooltipProps> = (props) => {
|
|
|
21
22
|
const { style: containerStyle, ...containerProps } = getTooltipProps({ className: 'o-tooltip-container' });
|
|
22
23
|
const { style: arrowStyle, ...arrowProps } = getArrowProps({ className: 'o-tooltip-arrow' });
|
|
23
24
|
const classNames = addClassname('o-tooltip', className);
|
|
25
|
+
const uid = useId();
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (visible) {
|
|
29
|
+
const event = new CustomEvent<string>('tooltipVisible', {
|
|
30
|
+
detail: uid,
|
|
31
|
+
});
|
|
32
|
+
document.dispatchEvent(event);
|
|
33
|
+
}
|
|
34
|
+
}, [visible, uid]);
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const listener = (e: any) => {
|
|
38
|
+
setShow(e.detail === uid);
|
|
39
|
+
};
|
|
40
|
+
document.addEventListener('tooltipVisible', listener);
|
|
41
|
+
|
|
42
|
+
return () => {
|
|
43
|
+
document.removeEventListener('tooltipVisible', listener);
|
|
44
|
+
};
|
|
45
|
+
}, [uid]);
|
|
24
46
|
|
|
25
47
|
return (
|
|
26
48
|
<div className={classNames} ref={setTriggerRef}>
|
|
27
49
|
{children}
|
|
28
|
-
{visible && content && (
|
|
50
|
+
{show && visible && content && (
|
|
29
51
|
<div ref={setTooltipRef} style={containerStyle as React.CSSProperties} {...containerProps}>
|
|
30
52
|
<div style={arrowStyle as React.CSSProperties} {...arrowProps} />
|
|
31
53
|
{content}
|