instantsearch-ui-components 0.11.2 → 0.12.0
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/cjs/components/Button.js +29 -0
- package/dist/cjs/components/Carousel.js +26 -6
- package/dist/cjs/components/autocomplete/Autocomplete.js +23 -0
- package/dist/cjs/components/autocomplete/AutocompleteIndex.js +39 -0
- package/dist/cjs/components/autocomplete/AutocompletePanel.js +25 -0
- package/dist/cjs/components/autocomplete/AutocompleteSuggestion.js +20 -0
- package/dist/cjs/components/autocomplete/index.js +49 -0
- package/dist/cjs/components/chat/Chat.js +79 -0
- package/dist/cjs/components/chat/ChatHeader.js +89 -0
- package/dist/cjs/components/chat/ChatMessage.js +138 -0
- package/dist/cjs/components/chat/ChatMessageError.js +57 -0
- package/dist/cjs/components/chat/ChatMessageLoader.js +47 -0
- package/dist/cjs/components/chat/ChatMessages.js +192 -0
- package/dist/cjs/components/chat/ChatPrompt.js +179 -0
- package/dist/cjs/components/chat/ChatToggleButton.js +46 -0
- package/dist/cjs/components/chat/icons.js +375 -0
- package/dist/cjs/components/chat/types.js +1 -0
- package/dist/cjs/components/index.js +132 -0
- package/dist/cjs/lib/index.js +22 -0
- package/dist/cjs/lib/stickToBottom.js +481 -0
- package/dist/cjs/lib/utils/find.js +15 -0
- package/dist/cjs/lib/utils/index.js +27 -0
- package/dist/cjs/lib/utils/startsWith.js +9 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/warn.js +40 -0
- package/dist/es/components/Button.d.ts +38 -0
- package/dist/es/components/Button.js +22 -0
- package/dist/es/components/Carousel.d.ts +11 -0
- package/dist/es/components/Carousel.js +26 -6
- package/dist/es/components/autocomplete/Autocomplete.d.ts +13 -0
- package/dist/es/components/autocomplete/Autocomplete.js +16 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.d.ts +31 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.js +32 -0
- package/dist/es/components/autocomplete/AutocompletePanel.d.ts +17 -0
- package/dist/es/components/autocomplete/AutocompletePanel.js +18 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.d.ts +16 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.js +14 -0
- package/dist/es/components/autocomplete/index.d.ts +4 -0
- package/dist/es/components/autocomplete/index.js +4 -0
- package/dist/es/components/chat/Chat.d.ts +42 -0
- package/dist/es/components/chat/Chat.js +72 -0
- package/dist/es/components/chat/ChatHeader.d.ts +99 -0
- package/dist/es/components/chat/ChatHeader.js +82 -0
- package/dist/es/components/chat/ChatMessage.d.ts +124 -0
- package/dist/es/components/chat/ChatMessage.js +131 -0
- package/dist/es/components/chat/ChatMessageError.d.ts +27 -0
- package/dist/es/components/chat/ChatMessageError.js +50 -0
- package/dist/es/components/chat/ChatMessageLoader.d.ts +15 -0
- package/dist/es/components/chat/ChatMessageLoader.js +40 -0
- package/dist/es/components/chat/ChatMessages.d.ts +139 -0
- package/dist/es/components/chat/ChatMessages.js +185 -0
- package/dist/es/components/chat/ChatPrompt.d.ts +119 -0
- package/dist/es/components/chat/ChatPrompt.js +172 -0
- package/dist/es/components/chat/ChatToggleButton.d.ts +29 -0
- package/dist/es/components/chat/ChatToggleButton.js +39 -0
- package/dist/es/components/chat/icons.d.ts +22 -0
- package/dist/es/components/chat/icons.js +355 -0
- package/dist/es/components/chat/types.d.ts +29 -0
- package/dist/es/components/chat/types.js +1 -0
- package/dist/es/components/index.d.ts +12 -0
- package/dist/es/components/index.js +12 -0
- package/dist/es/lib/index.d.ts +2 -0
- package/dist/es/lib/index.js +3 -1
- package/dist/es/lib/stickToBottom.d.ts +114 -0
- package/dist/es/lib/stickToBottom.js +474 -0
- package/dist/es/lib/utils/find.d.ts +1 -0
- package/dist/es/lib/utils/find.js +9 -0
- package/dist/es/lib/utils/index.d.ts +2 -0
- package/dist/es/lib/utils/index.js +2 -0
- package/dist/es/lib/utils/startsWith.d.ts +1 -0
- package/dist/es/lib/utils/startsWith.js +3 -0
- package/dist/es/types/Renderer.d.ts +1 -1
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/es/warn.d.ts +10 -0
- package/dist/es/warn.js +33 -0
- package/package.json +7 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["listRef", "nextButtonRef", "previousButtonRef", "carouselIdRef", "classNames", "itemComponent", "previousIconComponent", "nextIconComponent", "items", "translations", "sendEvent"];
|
|
4
|
+
var _excluded = ["listRef", "nextButtonRef", "previousButtonRef", "carouselIdRef", "canScrollLeft", "canScrollRight", "setCanScrollLeft", "setCanScrollRight", "classNames", "itemComponent", "previousIconComponent", "nextIconComponent", "headerComponent", "showNavigation", "items", "translations", "sendEvent"];
|
|
5
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
7
|
import { cx } from "../lib/index.js";
|
|
@@ -46,6 +46,10 @@ export function createCarouselComponent(_ref3) {
|
|
|
46
46
|
nextButtonRef = userProps.nextButtonRef,
|
|
47
47
|
previousButtonRef = userProps.previousButtonRef,
|
|
48
48
|
carouselIdRef = userProps.carouselIdRef,
|
|
49
|
+
canScrollLeft = userProps.canScrollLeft,
|
|
50
|
+
canScrollRight = userProps.canScrollRight,
|
|
51
|
+
setCanScrollLeft = userProps.setCanScrollLeft,
|
|
52
|
+
setCanScrollRight = userProps.setCanScrollRight,
|
|
49
53
|
_userProps$classNames = userProps.classNames,
|
|
50
54
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
51
55
|
_userProps$itemCompon = userProps.itemComponent,
|
|
@@ -57,6 +61,9 @@ export function createCarouselComponent(_ref3) {
|
|
|
57
61
|
PreviousIconComponent = _userProps$previousIc === void 0 ? PreviousIconDefaultComponent : _userProps$previousIc,
|
|
58
62
|
_userProps$nextIconCo = userProps.nextIconComponent,
|
|
59
63
|
NextIconComponent = _userProps$nextIconCo === void 0 ? NextIconDefaultComponent : _userProps$nextIconCo,
|
|
64
|
+
HeaderComponent = userProps.headerComponent,
|
|
65
|
+
_userProps$showNaviga = userProps.showNavigation,
|
|
66
|
+
showNavigation = _userProps$showNaviga === void 0 ? true : _userProps$showNaviga,
|
|
60
67
|
items = userProps.items,
|
|
61
68
|
userTranslations = userProps.translations,
|
|
62
69
|
sendEvent = userProps.sendEvent,
|
|
@@ -87,18 +94,31 @@ export function createCarouselComponent(_ref3) {
|
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
function updateNavigationButtonsProps() {
|
|
90
|
-
if (!listRef.current
|
|
97
|
+
if (!listRef.current) {
|
|
91
98
|
return;
|
|
92
99
|
}
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
var isLeftHidden = listRef.current.scrollLeft <= 0;
|
|
101
|
+
var isRightHidden = listRef.current.scrollLeft + listRef.current.clientWidth >= listRef.current.scrollWidth;
|
|
102
|
+
setCanScrollLeft(!isLeftHidden);
|
|
103
|
+
setCanScrollRight(!isRightHidden);
|
|
104
|
+
if (previousButtonRef.current) {
|
|
105
|
+
previousButtonRef.current.hidden = isLeftHidden;
|
|
106
|
+
}
|
|
107
|
+
if (nextButtonRef.current) {
|
|
108
|
+
nextButtonRef.current.hidden = isRightHidden;
|
|
109
|
+
}
|
|
95
110
|
}
|
|
96
111
|
if (items.length === 0) {
|
|
97
112
|
return null;
|
|
98
113
|
}
|
|
99
114
|
return createElement("div", _extends({}, props, {
|
|
100
115
|
className: cx(cssClasses.root)
|
|
101
|
-
}), createElement(
|
|
116
|
+
}), HeaderComponent && createElement(HeaderComponent, {
|
|
117
|
+
canScrollLeft: canScrollLeft,
|
|
118
|
+
canScrollRight: canScrollRight,
|
|
119
|
+
scrollLeft: scrollLeft,
|
|
120
|
+
scrollRight: scrollRight
|
|
121
|
+
}), showNavigation && createElement("button", {
|
|
102
122
|
ref: previousButtonRef,
|
|
103
123
|
title: translations.previousButtonTitle,
|
|
104
124
|
"aria-label": translations.previousButtonLabel,
|
|
@@ -145,7 +165,7 @@ export function createCarouselComponent(_ref3) {
|
|
|
145
165
|
item: item,
|
|
146
166
|
sendEvent: sendEvent
|
|
147
167
|
}));
|
|
148
|
-
})), createElement("button", {
|
|
168
|
+
})), showNavigation && createElement("button", {
|
|
149
169
|
ref: nextButtonRef,
|
|
150
170
|
title: translations.nextButtonTitle,
|
|
151
171
|
"aria-label": translations.nextButtonLabel,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentChildren, ComponentProps, Renderer } from '../../types';
|
|
3
|
+
export type AutocompleteProps = ComponentProps<'div'> & {
|
|
4
|
+
children?: ComponentChildren;
|
|
5
|
+
classNames?: Partial<AutocompleteClassNames>;
|
|
6
|
+
};
|
|
7
|
+
export type AutocompleteClassNames = {
|
|
8
|
+
/**
|
|
9
|
+
* Class names to apply to the root element
|
|
10
|
+
*/
|
|
11
|
+
root: string | string[];
|
|
12
|
+
};
|
|
13
|
+
export declare function createAutocompleteComponent({ createElement }: Renderer): (userProps: AutocompleteProps) => JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["children", "classNames"];
|
|
4
|
+
import { cx } from "../../lib/cx.js";
|
|
5
|
+
export function createAutocompleteComponent(_ref) {
|
|
6
|
+
var createElement = _ref.createElement;
|
|
7
|
+
return function Autocomplete(userProps) {
|
|
8
|
+
var children = userProps.children,
|
|
9
|
+
_userProps$classNames = userProps.classNames,
|
|
10
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
11
|
+
props = _objectWithoutProperties(userProps, _excluded);
|
|
12
|
+
return createElement("div", _extends({
|
|
13
|
+
className: cx('ais-Autocomplete', classNames.root)
|
|
14
|
+
}, props), children);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentProps, Renderer } from '../../types';
|
|
3
|
+
export type AutocompleteIndexProps<T = {
|
|
4
|
+
objectID: string;
|
|
5
|
+
__indexName: string;
|
|
6
|
+
} & Record<string, unknown>> = {
|
|
7
|
+
items: T[];
|
|
8
|
+
ItemComponent: (props: {
|
|
9
|
+
item: T;
|
|
10
|
+
onSelect: () => void;
|
|
11
|
+
}) => JSX.Element;
|
|
12
|
+
getItemProps: (item: T, index: number) => Omit<ComponentProps<'li'>, 'onSelect'> & {
|
|
13
|
+
onSelect: () => void;
|
|
14
|
+
};
|
|
15
|
+
classNames?: Partial<AutocompleteIndexClassNames>;
|
|
16
|
+
};
|
|
17
|
+
export type AutocompleteIndexClassNames = {
|
|
18
|
+
/**
|
|
19
|
+
* Class names to apply to the root element
|
|
20
|
+
**/
|
|
21
|
+
root: string | string[];
|
|
22
|
+
/**
|
|
23
|
+
* Class names to apply to the list element
|
|
24
|
+
*/
|
|
25
|
+
list: string | string[];
|
|
26
|
+
/**
|
|
27
|
+
* Class names to apply to each item element
|
|
28
|
+
*/
|
|
29
|
+
item: string | string[];
|
|
30
|
+
};
|
|
31
|
+
export declare function createAutocompleteIndexComponent({ createElement }: Renderer): (userProps: AutocompleteIndexProps) => JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["className", "onSelect"];
|
|
4
|
+
import { cx } from "../../lib/cx.js";
|
|
5
|
+
export function createAutocompleteIndexComponent(_ref) {
|
|
6
|
+
var createElement = _ref.createElement;
|
|
7
|
+
return function AutocompleteIndex(userProps) {
|
|
8
|
+
var items = userProps.items,
|
|
9
|
+
ItemComponent = userProps.ItemComponent,
|
|
10
|
+
getItemProps = userProps.getItemProps,
|
|
11
|
+
_userProps$classNames = userProps.classNames,
|
|
12
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
13
|
+
return createElement("div", {
|
|
14
|
+
className: cx('ais-AutocompleteIndex', classNames.root)
|
|
15
|
+
}, createElement("ol", {
|
|
16
|
+
className: cx('ais-AutocompleteIndexList', classNames.list)
|
|
17
|
+
}, items.map(function (item, index) {
|
|
18
|
+
var _getItemProps = getItemProps(item, index),
|
|
19
|
+
className = _getItemProps.className,
|
|
20
|
+
onSelect = _getItemProps.onSelect,
|
|
21
|
+
itemProps = _objectWithoutProperties(_getItemProps, _excluded);
|
|
22
|
+
return createElement("li", _extends({
|
|
23
|
+
key: item.objectID
|
|
24
|
+
}, itemProps, {
|
|
25
|
+
className: cx('ais-AutocompleteIndexItem', classNames.item, className)
|
|
26
|
+
}), createElement(ItemComponent, {
|
|
27
|
+
item: item,
|
|
28
|
+
onSelect: onSelect
|
|
29
|
+
}));
|
|
30
|
+
})));
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentChildren, ComponentProps, Renderer } from '../../types';
|
|
3
|
+
export type AutocompletePanelProps = ComponentProps<'div'> & {
|
|
4
|
+
children?: ComponentChildren;
|
|
5
|
+
classNames?: Partial<AutocompletePanelClassNames>;
|
|
6
|
+
};
|
|
7
|
+
export type AutocompletePanelClassNames = {
|
|
8
|
+
/**
|
|
9
|
+
* Class names to apply to the root element
|
|
10
|
+
*/
|
|
11
|
+
root: string | string[];
|
|
12
|
+
/**
|
|
13
|
+
* Class names to apply to the layout element
|
|
14
|
+
*/
|
|
15
|
+
layout: string | string[];
|
|
16
|
+
};
|
|
17
|
+
export declare function createAutocompletePanelComponent({ createElement }: Renderer): (userProps: AutocompletePanelProps) => JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["children", "classNames"];
|
|
4
|
+
import { cx } from "../../lib/cx.js";
|
|
5
|
+
export function createAutocompletePanelComponent(_ref) {
|
|
6
|
+
var createElement = _ref.createElement;
|
|
7
|
+
return function AutocompletePanel(userProps) {
|
|
8
|
+
var children = userProps.children,
|
|
9
|
+
_userProps$classNames = userProps.classNames,
|
|
10
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
11
|
+
props = _objectWithoutProperties(userProps, _excluded);
|
|
12
|
+
return createElement("div", _extends({}, props, {
|
|
13
|
+
className: cx('ais-AutocompletePanel', classNames.root, props.className)
|
|
14
|
+
}), createElement("div", {
|
|
15
|
+
className: cx('ais-AutocompletePanelLayout', classNames.layout)
|
|
16
|
+
}, children));
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { Renderer } from '../../types';
|
|
3
|
+
export type AutocompleteSuggestionProps<T = {
|
|
4
|
+
query: string;
|
|
5
|
+
} & Record<string, unknown>> = {
|
|
6
|
+
item: T;
|
|
7
|
+
onSelect: () => void;
|
|
8
|
+
classNames?: Partial<AutocompleteSuggestionClassNames>;
|
|
9
|
+
};
|
|
10
|
+
export type AutocompleteSuggestionClassNames = {
|
|
11
|
+
/**
|
|
12
|
+
* Class names to apply to the root element
|
|
13
|
+
**/
|
|
14
|
+
root: string | string[];
|
|
15
|
+
};
|
|
16
|
+
export declare function createAutocompleteSuggestionComponent({ createElement, }: Renderer): ({ item, onSelect, classNames, }: AutocompleteSuggestionProps) => JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { cx } from "../../lib/index.js";
|
|
2
|
+
export function createAutocompleteSuggestionComponent(_ref) {
|
|
3
|
+
var createElement = _ref.createElement;
|
|
4
|
+
return function AutocompleteSuggestion(_ref2) {
|
|
5
|
+
var item = _ref2.item,
|
|
6
|
+
onSelect = _ref2.onSelect,
|
|
7
|
+
_ref2$classNames = _ref2.classNames,
|
|
8
|
+
classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames;
|
|
9
|
+
return createElement("div", {
|
|
10
|
+
onClick: onSelect,
|
|
11
|
+
className: cx('ais-AutocompleteSuggestion', classNames.root)
|
|
12
|
+
}, item.query);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Renderer, ComponentProps } from '../../types';
|
|
2
|
+
import type { ChatHeaderProps, ChatHeaderOwnProps } from './ChatHeader';
|
|
3
|
+
import type { ChatMessagesProps } from './ChatMessages';
|
|
4
|
+
import type { ChatPromptProps, ChatPromptOwnProps } from './ChatPrompt';
|
|
5
|
+
import type { ChatToggleButtonOwnProps, ChatToggleButtonProps } from './ChatToggleButton';
|
|
6
|
+
export type ChatClassNames = {
|
|
7
|
+
root?: string | string[];
|
|
8
|
+
container?: string | string[];
|
|
9
|
+
header?: ChatHeaderProps['classNames'];
|
|
10
|
+
messages?: ChatMessagesProps['classNames'];
|
|
11
|
+
prompt?: ChatPromptProps['classNames'];
|
|
12
|
+
toggleButton?: ChatToggleButtonProps['classNames'];
|
|
13
|
+
};
|
|
14
|
+
export type ChatProps = Omit<ComponentProps<'div'>, 'onError' | 'title'> & {
|
|
15
|
+
open: boolean;
|
|
16
|
+
maximized?: boolean;
|
|
17
|
+
headerProps: ChatHeaderProps;
|
|
18
|
+
toggleButtonProps: ChatToggleButtonProps;
|
|
19
|
+
messagesProps: ChatMessagesProps;
|
|
20
|
+
promptProps: ChatPromptProps;
|
|
21
|
+
/**
|
|
22
|
+
* Optional class names for elements
|
|
23
|
+
*/
|
|
24
|
+
classNames?: Partial<ChatClassNames>;
|
|
25
|
+
/**
|
|
26
|
+
* Optional title for the chat
|
|
27
|
+
*/
|
|
28
|
+
title?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Optional header component for the chat
|
|
31
|
+
*/
|
|
32
|
+
headerComponent?: (props: ChatHeaderOwnProps) => JSX.Element;
|
|
33
|
+
/**
|
|
34
|
+
* Optional prompt component for the chat
|
|
35
|
+
*/
|
|
36
|
+
promptComponent?: (props: ChatPromptOwnProps) => JSX.Element;
|
|
37
|
+
/**
|
|
38
|
+
* Optional toggle button component for the chat
|
|
39
|
+
*/
|
|
40
|
+
toggleButtonComponent?: (props: ChatToggleButtonOwnProps) => JSX.Element;
|
|
41
|
+
};
|
|
42
|
+
export declare function createChatComponent({ createElement, Fragment }: Renderer): ({ open, maximized, headerProps, toggleButtonProps, messagesProps, promptProps, headerComponent: HeaderComponent, promptComponent: PromptComponent, toggleButtonComponent: ToggleButtonComponent, classNames, className, ...props }: ChatProps) => JSX.Element;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["open", "maximized", "headerProps", "toggleButtonProps", "messagesProps", "promptProps", "headerComponent", "promptComponent", "toggleButtonComponent", "classNames", "className"];
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { cx } from "../../lib/index.js";
|
|
8
|
+
import { createChatHeaderComponent } from "./ChatHeader.js";
|
|
9
|
+
import { createChatMessagesComponent } from "./ChatMessages.js";
|
|
10
|
+
import { createChatPromptComponent } from "./ChatPrompt.js";
|
|
11
|
+
import { createChatToggleButtonComponent } from "./ChatToggleButton.js";
|
|
12
|
+
export function createChatComponent(_ref) {
|
|
13
|
+
var createElement = _ref.createElement,
|
|
14
|
+
Fragment = _ref.Fragment;
|
|
15
|
+
var ChatToggleButton = createChatToggleButtonComponent({
|
|
16
|
+
createElement: createElement,
|
|
17
|
+
Fragment: Fragment
|
|
18
|
+
});
|
|
19
|
+
var ChatHeader = createChatHeaderComponent({
|
|
20
|
+
createElement: createElement,
|
|
21
|
+
Fragment: Fragment
|
|
22
|
+
});
|
|
23
|
+
var ChatMessages = createChatMessagesComponent({
|
|
24
|
+
createElement: createElement,
|
|
25
|
+
Fragment: Fragment
|
|
26
|
+
});
|
|
27
|
+
var ChatPrompt = createChatPromptComponent({
|
|
28
|
+
createElement: createElement,
|
|
29
|
+
Fragment: Fragment
|
|
30
|
+
});
|
|
31
|
+
return function Chat(_ref2) {
|
|
32
|
+
var open = _ref2.open,
|
|
33
|
+
_ref2$maximized = _ref2.maximized,
|
|
34
|
+
maximized = _ref2$maximized === void 0 ? false : _ref2$maximized,
|
|
35
|
+
headerProps = _ref2.headerProps,
|
|
36
|
+
toggleButtonProps = _ref2.toggleButtonProps,
|
|
37
|
+
messagesProps = _ref2.messagesProps,
|
|
38
|
+
_ref2$promptProps = _ref2.promptProps,
|
|
39
|
+
promptProps = _ref2$promptProps === void 0 ? {} : _ref2$promptProps,
|
|
40
|
+
HeaderComponent = _ref2.headerComponent,
|
|
41
|
+
PromptComponent = _ref2.promptComponent,
|
|
42
|
+
ToggleButtonComponent = _ref2.toggleButtonComponent,
|
|
43
|
+
_ref2$classNames = _ref2.classNames,
|
|
44
|
+
classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames,
|
|
45
|
+
className = _ref2.className,
|
|
46
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
47
|
+
return createElement("div", _extends({}, props, {
|
|
48
|
+
className: cx('ais-Chat', maximized && 'ais-Chat--maximized', classNames.root, className)
|
|
49
|
+
}), createElement("div", {
|
|
50
|
+
className: cx('ais-Chat-container', open && 'ais-Chat-container--open', maximized && 'ais-Chat-container--maximized', classNames.container)
|
|
51
|
+
}, createElement(HeaderComponent || ChatHeader, _objectSpread(_objectSpread({}, headerProps), {}, {
|
|
52
|
+
classNames: classNames.header,
|
|
53
|
+
maximized: maximized
|
|
54
|
+
})), createElement(ChatMessages, _extends({}, messagesProps, {
|
|
55
|
+
classNames: classNames.messages
|
|
56
|
+
})), createElement(PromptComponent || ChatPrompt, _objectSpread(_objectSpread({}, promptProps), {}, {
|
|
57
|
+
classNames: classNames.prompt
|
|
58
|
+
}))), createElement("div", {
|
|
59
|
+
className: "ais-Chat-toggleButtonWrapper"
|
|
60
|
+
}, createElement(ToggleButtonComponent || ChatToggleButton, _objectSpread(_objectSpread({}, toggleButtonProps), {}, {
|
|
61
|
+
classNames: classNames.toggleButton,
|
|
62
|
+
onClick: function onClick() {
|
|
63
|
+
var _toggleButtonProps$on;
|
|
64
|
+
(_toggleButtonProps$on = toggleButtonProps.onClick) === null || _toggleButtonProps$on === void 0 ? void 0 : _toggleButtonProps$on.call(toggleButtonProps);
|
|
65
|
+
if (!open) {
|
|
66
|
+
var _promptProps$promptRe, _promptProps$promptRe2;
|
|
67
|
+
(_promptProps$promptRe = promptProps.promptRef) === null || _promptProps$promptRe === void 0 ? void 0 : (_promptProps$promptRe2 = _promptProps$promptRe.current) === null || _promptProps$promptRe2 === void 0 ? void 0 : _promptProps$promptRe2.focus();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}))));
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Renderer, ComponentProps } from '../../types';
|
|
2
|
+
export type ChatHeaderTranslations = {
|
|
3
|
+
/**
|
|
4
|
+
* The title to display in the header
|
|
5
|
+
*/
|
|
6
|
+
title: string;
|
|
7
|
+
/**
|
|
8
|
+
* Accessible label for the minimize button
|
|
9
|
+
*/
|
|
10
|
+
minimizeLabel: string;
|
|
11
|
+
/**
|
|
12
|
+
* Accessible label for the maximize button
|
|
13
|
+
*/
|
|
14
|
+
maximizeLabel: string;
|
|
15
|
+
/**
|
|
16
|
+
* Accessible label for the close button
|
|
17
|
+
*/
|
|
18
|
+
closeLabel: string;
|
|
19
|
+
/**
|
|
20
|
+
* Text for the clear button
|
|
21
|
+
*/
|
|
22
|
+
clearLabel: string;
|
|
23
|
+
};
|
|
24
|
+
export type ChatHeaderClassNames = {
|
|
25
|
+
/**
|
|
26
|
+
* Class names to apply to the root element
|
|
27
|
+
*/
|
|
28
|
+
root?: string | string[];
|
|
29
|
+
/**
|
|
30
|
+
* Class names to apply to the title element
|
|
31
|
+
*/
|
|
32
|
+
title?: string | string[];
|
|
33
|
+
/**
|
|
34
|
+
* Class names to apply to the title icon element
|
|
35
|
+
*/
|
|
36
|
+
titleIcon?: string | string[];
|
|
37
|
+
/**
|
|
38
|
+
* Class names to apply to the maximize button element
|
|
39
|
+
*/
|
|
40
|
+
maximize?: string | string[];
|
|
41
|
+
/**
|
|
42
|
+
* Class names to apply to the close button element
|
|
43
|
+
*/
|
|
44
|
+
close?: string | string[];
|
|
45
|
+
/**
|
|
46
|
+
* Class names to apply to the clear button element
|
|
47
|
+
*/
|
|
48
|
+
clear?: string | string[];
|
|
49
|
+
};
|
|
50
|
+
export type ChatHeaderOwnProps = {
|
|
51
|
+
/**
|
|
52
|
+
* Whether the chat is maximized
|
|
53
|
+
*/
|
|
54
|
+
maximized?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Callback when the maximize button is clicked
|
|
57
|
+
*/
|
|
58
|
+
onToggleMaximize?: () => void;
|
|
59
|
+
/**
|
|
60
|
+
* Callback when the close button is clicked
|
|
61
|
+
*/
|
|
62
|
+
onClose: () => void;
|
|
63
|
+
/**
|
|
64
|
+
* Callback when the clear button is clicked
|
|
65
|
+
*/
|
|
66
|
+
onClear?: () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the clear button is enabled
|
|
69
|
+
*/
|
|
70
|
+
canClear?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Optional close icon component
|
|
73
|
+
*/
|
|
74
|
+
closeIconComponent?: () => JSX.Element;
|
|
75
|
+
/**
|
|
76
|
+
* Optional minimize icon component
|
|
77
|
+
*/
|
|
78
|
+
minimizeIconComponent?: () => JSX.Element;
|
|
79
|
+
/**
|
|
80
|
+
* Optional maximize icon component
|
|
81
|
+
*/
|
|
82
|
+
maximizeIconComponent?: (props: {
|
|
83
|
+
maximized: boolean;
|
|
84
|
+
}) => JSX.Element;
|
|
85
|
+
/**
|
|
86
|
+
* Optional title icon component (defaults to sparkles)
|
|
87
|
+
*/
|
|
88
|
+
titleIconComponent?: () => JSX.Element;
|
|
89
|
+
/**
|
|
90
|
+
* Optional class names for elements
|
|
91
|
+
*/
|
|
92
|
+
classNames?: Partial<ChatHeaderClassNames>;
|
|
93
|
+
/**
|
|
94
|
+
* Optional translations
|
|
95
|
+
*/
|
|
96
|
+
translations?: Partial<ChatHeaderTranslations>;
|
|
97
|
+
};
|
|
98
|
+
export type ChatHeaderProps = ComponentProps<'div'> & ChatHeaderOwnProps;
|
|
99
|
+
export declare function createChatHeaderComponent({ createElement }: Renderer): ({ maximized, onToggleMaximize, onClose, onClear, canClear, closeIconComponent: CloseIconComponent, minimizeIconComponent: MinimizeIconComponent, maximizeIconComponent: MaximizeIconComponent, titleIconComponent: TitleIconComponent, classNames, translations: userTranslations, ...props }: ChatHeaderProps) => JSX.Element;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["maximized", "onToggleMaximize", "onClose", "onClear", "canClear", "closeIconComponent", "minimizeIconComponent", "maximizeIconComponent", "titleIconComponent", "classNames", "translations"];
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { cx } from "../../lib/index.js";
|
|
8
|
+
import { createButtonComponent } from "../Button.js";
|
|
9
|
+
import { SparklesIconComponent, MaximizeIconComponent as MaximizeIconComponentDefault, MinimizeIconComponent as MinimizeIconComponentDefault, CloseIconComponent as CloseIconComponentDefault } from "./icons.js";
|
|
10
|
+
export function createChatHeaderComponent(_ref) {
|
|
11
|
+
var createElement = _ref.createElement;
|
|
12
|
+
var Button = createButtonComponent({
|
|
13
|
+
createElement: createElement
|
|
14
|
+
});
|
|
15
|
+
return function ChatHeader(_ref2) {
|
|
16
|
+
var _ref2$maximized = _ref2.maximized,
|
|
17
|
+
maximized = _ref2$maximized === void 0 ? false : _ref2$maximized,
|
|
18
|
+
onToggleMaximize = _ref2.onToggleMaximize,
|
|
19
|
+
onClose = _ref2.onClose,
|
|
20
|
+
onClear = _ref2.onClear,
|
|
21
|
+
_ref2$canClear = _ref2.canClear,
|
|
22
|
+
canClear = _ref2$canClear === void 0 ? false : _ref2$canClear,
|
|
23
|
+
CloseIconComponent = _ref2.closeIconComponent,
|
|
24
|
+
MinimizeIconComponent = _ref2.minimizeIconComponent,
|
|
25
|
+
MaximizeIconComponent = _ref2.maximizeIconComponent,
|
|
26
|
+
TitleIconComponent = _ref2.titleIconComponent,
|
|
27
|
+
_ref2$classNames = _ref2.classNames,
|
|
28
|
+
classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames,
|
|
29
|
+
userTranslations = _ref2.translations,
|
|
30
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
31
|
+
var translations = _objectSpread({
|
|
32
|
+
title: 'Chat',
|
|
33
|
+
minimizeLabel: 'Minimize chat',
|
|
34
|
+
maximizeLabel: 'Maximize chat',
|
|
35
|
+
closeLabel: 'Close chat',
|
|
36
|
+
clearLabel: 'Clear'
|
|
37
|
+
}, userTranslations);
|
|
38
|
+
var defaultMaximizeIcon = maximized ? createElement(MinimizeIconComponentDefault, {
|
|
39
|
+
createElement: createElement
|
|
40
|
+
}) : createElement(MaximizeIconComponentDefault, {
|
|
41
|
+
createElement: createElement
|
|
42
|
+
});
|
|
43
|
+
return createElement("div", _extends({
|
|
44
|
+
className: cx('ais-ChatHeader', classNames.root, props.className)
|
|
45
|
+
}, props), createElement("span", {
|
|
46
|
+
className: cx('ais-ChatHeader-title', classNames.title)
|
|
47
|
+
}, createElement("span", {
|
|
48
|
+
className: cx('ais-ChatHeader-titleIcon', classNames.titleIcon)
|
|
49
|
+
}, TitleIconComponent ? createElement(TitleIconComponent, null) : createElement(SparklesIconComponent, {
|
|
50
|
+
createElement: createElement,
|
|
51
|
+
width: 20,
|
|
52
|
+
height: 20
|
|
53
|
+
})), translations.title), createElement("div", {
|
|
54
|
+
className: cx('ais-ChatHeader-actions')
|
|
55
|
+
}, onClear && createElement(Button, {
|
|
56
|
+
variant: "ghost",
|
|
57
|
+
size: "sm",
|
|
58
|
+
className: cx('ais-ChatHeader-clear', classNames.clear),
|
|
59
|
+
onClick: onClear,
|
|
60
|
+
disabled: !canClear
|
|
61
|
+
}, translations.clearLabel), createElement(Button, {
|
|
62
|
+
variant: "ghost",
|
|
63
|
+
size: "sm",
|
|
64
|
+
iconOnly: true,
|
|
65
|
+
className: cx('ais-ChatHeader-maximize', classNames.maximize),
|
|
66
|
+
onClick: onToggleMaximize,
|
|
67
|
+
"aria-label": maximized ? translations.minimizeLabel : translations.maximizeLabel
|
|
68
|
+
}, MaximizeIconComponent ? createElement(MaximizeIconComponent, {
|
|
69
|
+
maximized: maximized
|
|
70
|
+
}) : defaultMaximizeIcon), createElement(Button, {
|
|
71
|
+
variant: "ghost",
|
|
72
|
+
size: "sm",
|
|
73
|
+
iconOnly: true,
|
|
74
|
+
className: cx('ais-ChatHeader-close', classNames.close),
|
|
75
|
+
onClick: onClose,
|
|
76
|
+
"aria-label": translations.closeLabel,
|
|
77
|
+
title: translations.closeLabel
|
|
78
|
+
}, CloseIconComponent ? createElement(CloseIconComponent, null) : createElement(CloseIconComponentDefault, {
|
|
79
|
+
createElement: createElement
|
|
80
|
+
}))));
|
|
81
|
+
};
|
|
82
|
+
}
|