@fibery/ui-kit 1.40.0 → 1.40.2

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +5 -4
  3. package/src/appIcons.json +10 -0
  4. package/src/box.tsx +2 -2
  5. package/src/button/base-button.tsx +18 -3
  6. package/src/button/button.tsx +14 -6
  7. package/src/button/icon-button.tsx +4 -1
  8. package/src/design-system.ts +6 -3
  9. package/src/dot.tsx +36 -0
  10. package/src/file-item-2.tsx +12 -12
  11. package/src/html-styles.ts +11 -15
  12. package/src/icons/ast/Dividers.ts +8 -0
  13. package/src/icons/ast/DoubleLine.ts +8 -0
  14. package/src/icons/ast/LineJump.ts +8 -0
  15. package/src/icons/ast/QuickFilter.ts +8 -0
  16. package/src/icons/ast/QuickFilterPersonal.ts +8 -0
  17. package/src/icons/ast/index.tsx +5 -0
  18. package/src/icons/react/Dividers.tsx +13 -0
  19. package/src/icons/react/DoubleLine.tsx +13 -0
  20. package/src/icons/react/LineJump.tsx +13 -0
  21. package/src/icons/react/QuickFilter.tsx +13 -0
  22. package/src/icons/react/QuickFilterPersonal.tsx +13 -0
  23. package/src/icons/react/index.tsx +5 -0
  24. package/src/icons/svg/dividers.svg +3 -0
  25. package/src/icons/svg/double-line.svg +3 -0
  26. package/src/icons/svg/line-jump.svg +4 -0
  27. package/src/icons/svg/quick-filter-personal.svg +3 -0
  28. package/src/icons/svg/quick-filter.svg +3 -0
  29. package/src/images-gallery/get-gallery-src.ts +71 -0
  30. package/src/images-gallery/images-gallery.tsx +1 -1
  31. package/src/images-gallery/thumbnails-mime-types-white-list.ts +17 -0
  32. package/src/notification-dot.tsx +11 -21
  33. package/src/popover/index.tsx +22 -13
  34. package/src/select/components/menu.tsx +1 -0
  35. package/src/select/index.tsx +95 -259
  36. package/src/select/select-in-popover.tsx +11 -3
  37. package/src/select/select.tsx +288 -0
  38. package/src/toast/toast.tsx +1 -1
  39. package/src/toggle-button/toggle-button.tsx +16 -4
  40. package/src/toggle-on-off.tsx +10 -1
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
2
+ <path d="M5 16.0267L5.22143 18L6.65633 16.6311L9.10983 9.87556C8.50753 9.72444 7.97608 9.42222 7.54207 9.00444L5 16.0267ZM12.4491 9.00444C12.0151 9.42222 11.4748 9.72444 10.8813 9.87556L13.3348 16.6311L14.7697 18L15 16.0267L12.4491 9.00444ZM12.5996 6.97778C12.8654 5.59111 12.0682 4.36444 10.8813 3.93778V2.88889C10.8813 2.4 10.4827 2 9.99557 2C9.50841 2 9.10983 2.4 9.10983 2.88889V3.93778C8.08237 4.31111 7.33835 5.28889 7.33835 6.44444C7.33835 8.08 8.80868 9.37778 10.4916 9.06667C11.5368 8.87111 12.3959 8.02667 12.5996 6.97778ZM9.99557 7.33333C9.50841 7.33333 9.10983 6.93333 9.10983 6.44444C9.10983 5.95556 9.50841 5.55556 9.99557 5.55556C10.4827 5.55556 10.8813 5.95556 10.8813 6.44444C10.8813 6.93333 10.4827 7.33333 9.99557 7.33333Z"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
2
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 7.5C1.5 7.08579 1.83579 6.75 2.25 6.75H17.75C18.1642 6.75 18.5 7.08579 18.5 7.5C18.5 7.91421 18.1642 8.25 17.75 8.25H2.25C1.83579 8.25 1.5 7.91421 1.5 7.5ZM1.5 12.5C1.5 12.0858 1.83579 11.75 2.25 11.75H17.75C18.1642 11.75 18.5 12.0858 18.5 12.5C18.5 12.9142 18.1642 13.25 17.75 13.25H2.25C1.83579 13.25 1.5 12.9142 1.5 12.5Z" />
3
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M3.05 6.11H5.74C6.11 6.11 6.46 6.25 6.72 6.51L9.4 9.19C9.47718 9.26801 9.56907 9.32993 9.67034 9.3722C9.77162 9.41446 9.88026 9.43622 9.99 9.43622C10.0997 9.43622 10.2084 9.41446 10.3097 9.3722C10.4109 9.32993 10.5028 9.26801 10.58 9.19C10.658 9.11282 10.7199 9.02093 10.7622 8.91966C10.8045 8.81839 10.8262 8.70974 10.8262 8.6C10.8262 8.49026 10.8045 8.38162 10.7622 8.28034C10.7199 8.17907 10.658 8.08718 10.58 8.01L7.9 5.33C7.61677 5.04609 7.28001 4.82123 6.90922 4.66846C6.53844 4.51568 6.14102 4.43803 5.74 4.44H3.05C2.82987 4.44 2.61876 4.52745 2.4631 4.6831C2.30745 4.83876 2.22 5.04987 2.22 5.27C2.22 5.49013 2.30745 5.70124 2.4631 5.8569C2.61876 6.01255 2.82987 6.1 3.05 6.1V6.11Z" />
3
+ <path d="M18.63 10.79L15.57 7.74C15.4957 7.6527 15.4042 7.58173 15.3011 7.53156C15.1981 7.48139 15.0857 7.45311 14.9712 7.4485C14.8567 7.44389 14.7424 7.46305 14.6357 7.50478C14.5289 7.5465 14.432 7.60988 14.3509 7.69093C14.2699 7.77198 14.2065 7.86894 14.1648 7.97569C14.1231 8.08245 14.1039 8.19669 14.1085 8.31121C14.1131 8.42574 14.1414 8.53807 14.1916 8.64112C14.2417 8.74418 14.3127 8.83573 14.4 8.91L16.03 10.55H0.83C0.60987 10.55 0.398757 10.6374 0.243101 10.7931C0.0874462 10.9488 0 11.1599 0 11.38C0 11.6001 0.0874462 11.8112 0.243101 11.9669C0.398757 12.1226 0.60987 12.21 0.83 12.21H16.03L14.4 13.84C14.2435 13.9952 14.1551 14.2061 14.1542 14.4265C14.1532 14.6468 14.2398 14.8585 14.395 15.015C14.5502 15.1715 14.7611 15.2599 14.9815 15.2609C15.2018 15.2618 15.4135 15.1752 15.57 15.02L18.62 11.97C18.698 11.8928 18.7599 11.8009 18.8022 11.6997C18.8445 11.5984 18.8662 11.4897 18.8662 11.38C18.8662 11.2703 18.8445 11.1616 18.8022 11.0603C18.7599 10.9591 18.698 10.8672 18.62 10.79H18.63Z" />
4
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M2.75 11.25C3.16421 11.25 3.5 11.5858 3.5 12V15.25C3.5 15.9404 4.05964 16.5 4.75 16.5H8C8.41421 16.5 8.75 16.8358 8.75 17.25C8.75 17.6642 8.41421 18 8 18H4.75C3.23122 18 2 16.7688 2 15.25V12C2 11.5858 2.33579 11.25 2.75 11.25ZM17.25 11.25C17.6642 11.25 18 11.5858 18 12V15.25C18 16.7688 16.7688 18 15.25 18H12C11.5858 18 11.25 17.6642 11.25 17.25C11.25 16.8358 11.5858 16.5 12 16.5H15.25C15.9404 16.5 16.5 15.9404 16.5 15.25V12C16.5 11.5858 16.8358 11.25 17.25 11.25ZM11.25 12C11.6642 12 12 12.3358 12 12.75C12 13.1642 11.6642 13.5 11.25 13.5H8.75C8.33579 13.5 8 13.1642 8 12.75C8 12.3358 8.33579 12 8.75 12H11.25ZM12.25 9.25C12.6642 9.25 13 9.58579 13 10C13 10.4142 12.6642 10.75 12.25 10.75H7.75C7.33579 10.75 7 10.4142 7 10C7 9.58579 7.33579 9.25 7.75 9.25H12.25ZM8 2C8.41421 2 8.75 2.33579 8.75 2.75C8.75 3.16421 8.41421 3.5 8 3.5H4.75C4.05964 3.5 3.5 4.05964 3.5 4.75V8C3.5 8.41421 3.16421 8.75 2.75 8.75C2.33579 8.75 2 8.41421 2 8V4.75C2 3.23122 3.23122 2 4.75 2H8ZM15.25 2C16.7688 2 18 3.23122 18 4.75V8C18 8.41421 17.6642 8.75 17.25 8.75C16.8358 8.75 16.5 8.41421 16.5 8V4.75C16.5 4.05964 15.9404 3.5 15.25 3.5H12C11.5858 3.5 11.25 3.16421 11.25 2.75C11.25 2.33579 11.5858 2 12 2H15.25ZM13.25 6.5C13.6642 6.5 14 6.83579 14 7.25C14 7.66421 13.6642 8 13.25 8H6.75C6.33579 8 6 7.66421 6 7.25C6 6.83579 6.33579 6.5 6.75 6.5H13.25Z" fill="black"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M15.25 2C16.7688 2 18 3.23122 18 4.75V15.25C18 16.7688 16.7688 18 15.25 18H4.75C3.23122 18 2 16.7688 2 15.25V4.75C2 3.23122 3.23122 2 4.75 2H15.25ZM4.75 3.5C4.05964 3.5 3.5 4.05964 3.5 4.75V15.25C3.5 15.9404 4.05964 16.5 4.75 16.5H15.25C15.9404 16.5 16.5 15.9404 16.5 15.25V4.75C16.5 4.05964 15.9404 3.5 15.25 3.5H4.75ZM11.25 12C11.6642 12 12 12.3358 12 12.75C12 13.1642 11.6642 13.5 11.25 13.5H8.75C8.33579 13.5 8 13.1642 8 12.75C8 12.3358 8.33579 12 8.75 12H11.25ZM12.25 9.25C12.6642 9.25 13 9.58579 13 10C13 10.4142 12.6642 10.75 12.25 10.75H7.75C7.33579 10.75 7 10.4142 7 10C7 9.58579 7.33579 9.25 7.75 9.25H12.25ZM13.25 6.5C13.6642 6.5 14 6.83579 14 7.25C14 7.66421 13.6642 8 13.25 8H6.75C6.33579 8 6 7.66421 6 7.25C6 6.83579 6.33579 6.5 6.75 6.5H13.25Z" fill="black"/>
3
+ </svg>
@@ -0,0 +1,71 @@
1
+ import {thumbnailsMimeTypesWhiteList} from "./thumbnails-mime-types-white-list";
2
+
3
+ export function getGallerySrc({
4
+ src,
5
+ contentType,
6
+ contentLength,
7
+ isPhone,
8
+ }: {
9
+ src: string;
10
+ contentType: string;
11
+ contentLength: number;
12
+ isPhone: boolean;
13
+ }): null | {
14
+ type: "iframe" | "video" | "image";
15
+ src: string;
16
+ } {
17
+ const isFiberyFile = src?.startsWith("/api/files");
18
+
19
+ if (!isPhone && isFiberyFile && contentType?.startsWith("text/") && contentLength < 2 * 1024 * 1024) {
20
+ const url = new URL(src, `${window.location}`);
21
+ url.searchParams.append("plain-text", "true");
22
+
23
+ return {
24
+ type: "iframe",
25
+ src: url.href,
26
+ };
27
+ }
28
+
29
+ if (!contentType || !thumbnailsMimeTypesWhiteList.has(contentType)) {
30
+ return null;
31
+ }
32
+
33
+ if (ImageContentTypes.includes(contentType)) {
34
+ return {
35
+ type: "image",
36
+ src,
37
+ };
38
+ }
39
+
40
+ if (VideoContentTypes.includes(contentType)) {
41
+ return {
42
+ type: "video",
43
+ src,
44
+ };
45
+ }
46
+
47
+ if (!isPhone && IframeContentTypes.includes(contentType)) {
48
+ return {
49
+ type: "iframe",
50
+ src: new URL(src, `${window.location}`).href,
51
+ };
52
+ }
53
+
54
+ return null;
55
+ }
56
+
57
+ const ImageContentTypes = [
58
+ "image/apng",
59
+ "image/png",
60
+ "image/jpeg",
61
+ "image/webp",
62
+ "image/avif",
63
+ "image/gif",
64
+ "image/x-icon",
65
+ "image/bmp",
66
+ "image/tiff",
67
+ "image/svg+xml",
68
+ ];
69
+
70
+ const VideoContentTypes = ["video/mp4", "video/quicktime"];
71
+ const IframeContentTypes = ["application/pdf"];
@@ -340,7 +340,7 @@ export function createPhotoSwipeLightbox(
340
340
  return photoSwipeLightbox;
341
341
  }
342
342
 
343
- function initGallery(
343
+ export function initGallery(
344
344
  imagesRegistry: Registry,
345
345
  {toastQueue, themeMode, isPhone}: {toastQueue: ToastQueue; themeMode: ThemeMode; isPhone: boolean}
346
346
  ) {
@@ -0,0 +1,17 @@
1
+ export const thumbnailsMimeTypesWhiteList = new Set([
2
+ "image/apng",
3
+ "image/png",
4
+ "image/jpeg",
5
+ "image/webp",
6
+ "image/avif",
7
+ "image/gif",
8
+ "image/x-icon",
9
+ "image/bmp",
10
+ "image/tiff",
11
+ "image/heic",
12
+ "image/svg+xml",
13
+ "video/mp4",
14
+ "video/quicktime",
15
+ "application/pdf",
16
+ "image/vnd.adobe.photoshop",
17
+ ]);
@@ -1,32 +1,22 @@
1
- import {css} from "@linaria/core";
2
- import {space, themeVars} from "./design-system";
1
+ import {themeVars} from "./design-system";
2
+ import {Dot} from "./dot";
3
+ import {CSSProperties} from "react";
3
4
 
4
- const activityIndicatorStyle = css`
5
- ${{
6
- backgroundColor: themeVars.active,
7
- borderRadius: "50%",
8
- position: "absolute",
9
- top: 0,
10
- }}
11
- `;
12
-
13
- type PropsType = {
5
+ type Props = {
14
6
  big?: boolean;
15
7
  color?: string;
16
- style?: Record<string, string | number | null>;
17
- };
8
+ } & React.ComponentProps<"div">;
18
9
 
19
- export const NotificationDot = ({big = true, color = themeVars.active, style}: PropsType) => {
20
- const size = big ? space.s6 : space.s4;
10
+ export const NotificationDot = ({big = true, color = themeVars.active, style}: Props) => {
21
11
  const marginTop = big ? -6 : -1;
22
12
  const marginRight = big ? -1 : 0;
23
13
  const styleObject = {
24
- backgroundColor: color,
25
- width: size,
26
- height: size,
14
+ position: "absolute",
15
+ top: 0,
27
16
  marginTop,
28
17
  marginRight,
29
18
  ...style,
30
- };
31
- return <div className={activityIndicatorStyle} style={styleObject} />;
19
+ } as CSSProperties;
20
+
21
+ return <Dot color={color} size={big ? "medium" : "small"} style={styleObject} />;
32
22
  };
@@ -44,6 +44,9 @@ import {usePopupStackContext} from "./popup-stack-context";
44
44
  import {useComposedRefs} from "@fibery/react/src/use-composed-refs";
45
45
  import {createContext} from "@fibery/react/src/create-context";
46
46
  import {Wrap} from "@fibery/react/src/wrap";
47
+ import {composeEventHandlers} from "@fibery/react/src/compose-event-handlers";
48
+
49
+ export const mobileZIndex = 1002;
47
50
 
48
51
  const Backdrop = ({className}: {className?: string}) => {
49
52
  return (
@@ -171,7 +174,7 @@ export function MobilePopup({
171
174
  right: var(${safeAreaInsetRightVar});
172
175
  top: var(${safeAreaInsetTopVar});
173
176
  bottom: var(${safeAreaInsetBottomVar});
174
- z-index: 1002;
177
+ z-index: ${mobileZIndex};
175
178
  `,
176
179
  !height && mobileAnimationClassName,
177
180
  !height && popupContentClassName,
@@ -230,20 +233,25 @@ type TriggerProps = {
230
233
  asChild?: boolean;
231
234
  // Support case when popup trigger is virtual reference
232
235
  reference?: Reference;
233
- children?: ReactNode;
234
- };
236
+ } & React.ComponentPropsWithoutRef<"div">;
235
237
 
236
- const Trigger = ({asChild = false, reference, children}: TriggerProps) => {
238
+ const Trigger = ({asChild = false, reference, children, onMouseDown, ...props}: TriggerProps) => {
237
239
  const {setTriggerElement, disabled, open, onOpen, onClose} = useContext();
238
240
 
239
- const onMouseDown: React.MouseEventHandler<HTMLElement> = (e) => {
240
- if (disabled) {
241
- return;
242
- }
243
- if (e.button === 0) {
244
- open ? onClose?.(e as unknown as Event) : onOpen?.();
241
+ const onMouseDownCb: React.MouseEventHandler<HTMLElement> = composeEventHandlers(
242
+ onMouseDown,
243
+ (e) => {
244
+ if (disabled) {
245
+ return;
246
+ }
247
+ if (e.button === 0) {
248
+ open ? onClose?.(e as unknown as Event) : onOpen?.();
249
+ }
250
+ },
251
+ {
252
+ checkForDefaultPrevented: false,
245
253
  }
246
- };
254
+ );
247
255
 
248
256
  useEffect(() => {
249
257
  if (reference) {
@@ -261,12 +269,13 @@ const Trigger = ({asChild = false, reference, children}: TriggerProps) => {
261
269
  ref: setTriggerElement,
262
270
  "aria-expanded": open,
263
271
  "aria-haspopup": true,
264
- onMouseDown,
272
+ onMouseDown: onMouseDownCb,
273
+ ...props,
265
274
  });
266
275
  }
267
276
 
268
277
  return (
269
- <div ref={setTriggerElement} onMouseDown={onMouseDown}>
278
+ <div ref={setTriggerElement} onMouseDown={onMouseDownCb} {...props}>
270
279
  {children}
271
280
  </div>
272
281
  );
@@ -32,6 +32,7 @@ export function Menu<T, U extends boolean, V extends GroupBase<T>>(props: MenuPr
32
32
 
33
33
  const menuTransparentCss = css`
34
34
  background-color: ${themeVars.transparent};
35
+ overflow: auto;
35
36
  `;
36
37
 
37
38
  export function MenuTransparent<T, U extends boolean, V extends GroupBase<T>>(props: MenuProps<T, U, V>) {
@@ -1,44 +1,13 @@
1
1
  /* eslint-disable no-use-before-define */
2
- import {useComposedRefs} from "@fibery/react/src/use-composed-refs";
3
- import {ForwardedRef, forwardRef, RefObject, useCallback, useMemo, useRef, useState} from "react";
4
- import BaseSelect, {
5
- ActionMeta,
6
- components as reactSelectComponents,
7
- createFilter,
8
- MenuListProps,
9
- MenuProps,
10
- ControlProps,
11
- mergeStyles,
12
- MultiValue,
13
- MultiValueProps,
14
- OnChangeValue,
15
- OptionProps,
16
- OptionsOrGroups,
17
- Props as BaseSelectProps,
18
- PropsValue,
19
- SelectInstance,
20
- SingleValue,
21
- SingleValueProps,
22
- StylesConfig,
23
- } from "react-select";
24
- import BaseCreatableSelect, {CreatableProps} from "react-select/creatable";
25
- import {ClearIndicator, NoClearIndicator} from "./components/clear-indicator";
26
- import {DropdownIndicator} from "./components/drop-down-indicator";
27
- import {GroupHeading} from "./components/group-heading";
28
- import {Menu} from "./components/menu";
29
- import {MenuListVirtualized} from "./components/menu-list-virtualized";
30
- import {NoOptionsMessage} from "./components/no-option-message";
31
- import {Option, OptionSlow} from "./components/option";
32
- import {useSelectControlSettings} from "./select-control-settings-context";
33
- import {
34
- makeComponentsStyles,
35
- makeNonVirtualizedStyles,
36
- makeSingleLineStyles,
37
- makeVirtualizedStyles,
38
- makeZIndexStyles,
39
- } from "./styles";
40
- import {countOptions, GroupBase, ReactSelectRefContext} from "./util";
41
- import _ from "lodash";
2
+ import {useIsPhone} from "../use-is-phone";
3
+ import {SelectComponent} from "./select";
4
+ import React, {ForwardedRef, forwardRef} from "react";
5
+ import type {SelectProps, GroupBase, SelectInstance} from "./select";
6
+ import {SelectInPopover} from "./select-in-popover";
7
+ import {combineStyles} from "./select";
8
+ import {makeSingleLineStyles} from "./styles";
9
+ import {css} from "@linaria/core";
10
+ import {$TSFixMe} from "../tsfixme";
42
11
 
43
12
  export type {
44
13
  ActionMeta,
@@ -57,244 +26,111 @@ export type {
57
26
  StylesConfig,
58
27
  SelectInstance,
59
28
  BaseSelectProps,
60
- };
29
+ SelectProps,
30
+ } from "./select";
61
31
 
62
- export {reactSelectComponents as components, MenuListVirtualized, createFilter};
32
+ export {components, MenuListVirtualized, createFilter} from "./select";
63
33
 
64
- function GroupVirtualized() {
65
- return null;
66
- }
67
-
68
- export function combineStyles<T, U extends boolean, V extends GroupBase<T>>(styles: StylesConfig<T, U, V>[]) {
69
- return styles.reduce(mergeStyles, {});
70
- }
34
+ export {combineStyles} from "./select";
71
35
 
72
- export type SelectProps<T = unknown, U extends boolean = boolean, V extends GroupBase<T> = GroupBase<T>> = Omit<
73
- Omit<Omit<BaseSelectProps<T, U, V>, "isMulti">, "backspaceRemovesValue">,
74
- "isDisabled"
75
- > & {
76
- virtualized?: boolean;
77
- isCollectionMode?: U;
78
- disabled?: boolean;
79
- forbidValuesClearInCollnMode?: boolean;
36
+ const emptyComponents = {
37
+ Menu: () => null,
80
38
  };
81
39
 
82
- export function SingleRowSelect<T = unknown, U extends boolean = boolean, V extends GroupBase<T> = GroupBase<T>>({
83
- styles = {},
84
- ...rest
85
- }: SelectProps<T, U, V>) {
86
- return <Select<T, U, V> {...rest} styles={combineStyles([makeSingleLineStyles(), styles])} />;
87
- }
88
-
89
- const FAST_OPTION_USAGE_THRESHOLD = 200;
90
-
91
- function useSelectComponents<T, U extends boolean, V extends GroupBase<T>>({
92
- components,
93
- optionsCount,
94
- virtualized,
95
- isCollectionMode,
96
- forbidValuesClearInCollnMode,
97
- }: {
98
- components: SelectProps<T, U, V>["components"];
99
- optionsCount: number;
100
- virtualized: boolean;
101
- isCollectionMode?: U;
102
- forbidValuesClearInCollnMode?: boolean;
103
- }) {
104
- const shouldUseFastOption = optionsCount > FAST_OPTION_USAGE_THRESHOLD;
105
- const shouldHideMultiValueRemove = isCollectionMode && forbidValuesClearInCollnMode;
106
-
107
- return {
108
- Menu,
109
- DropdownIndicator,
110
- ClearIndicator,
111
- MultiValueRemove: shouldHideMultiValueRemove ? NoClearIndicator : ClearIndicator,
112
- NoOptionsMessage,
113
- GroupHeading,
114
- Option: shouldUseFastOption ? Option : OptionSlow,
115
- ...components,
116
- Group: virtualized ? GroupVirtualized : components?.Group ? components.Group : reactSelectComponents.Group,
117
- MenuList: virtualized
118
- ? MenuListVirtualized
119
- : components?.MenuList
120
- ? components.MenuList
121
- : reactSelectComponents.MenuList,
122
- };
123
- }
124
-
125
- function useSelectStyles<T, U extends boolean, V extends GroupBase<T>>({
126
- virtualized,
127
- zIndex,
128
- styles,
129
- }: {
130
- virtualized: boolean;
131
- zIndex?: number;
132
- styles?: SelectProps<T, U, V>["styles"];
133
- }) {
134
- return useMemo(() => {
135
- return combineStyles<T, U, V>(
136
- _.compact([
137
- makeComponentsStyles<T, U, V>(),
138
- virtualized ? makeVirtualizedStyles<T, U, V>() : makeNonVirtualizedStyles<T, U, V>(),
139
- zIndex ? makeZIndexStyles<T, U, V>(zIndex) : null,
140
- styles,
141
- ])
142
- );
143
- }, [styles, virtualized, zIndex]);
144
- }
145
-
146
- export const Select = forwardRef(function Select<
40
+ export const Select = forwardRef(function SelectInner<
147
41
  T = unknown,
148
42
  U extends boolean = boolean,
149
43
  V extends GroupBase<T> = GroupBase<T>
150
44
  >(
151
45
  {
152
- components,
153
- isCollectionMode,
154
- menuPortalTarget,
155
- onKeyDown,
46
+ maxMenuHeight,
47
+ options = [],
48
+ formatOptionLabel,
49
+ isOptionDisabled,
156
50
  styles,
157
- virtualized = true,
158
- onMenuOpen,
159
- onMenuClose,
160
- onChange,
161
- forbidValuesClearInCollnMode,
162
- ...rest
51
+ isClearable,
52
+ placeholder,
53
+ title,
54
+ isSearchable,
55
+ ...restProps
163
56
  }: SelectProps<T, U, V>,
164
57
  forwardedRef: ForwardedRef<SelectInstance<T, U, V>>
165
58
  ) {
166
- const {getPopupContainerElement, zIndex} = useSelectControlSettings();
167
- const [menuOpenState, setMenuOpenState] = useState(rest.defaultMenuIsOpen);
168
- const optionsCount = useMemo(() => countOptions(rest.options), [rest.options]);
169
-
170
- const onMenuOpenWrapped = useCallback(() => {
171
- setMenuOpenState(true);
172
- onMenuOpen && onMenuOpen();
173
- }, [onMenuOpen]);
174
-
175
- const onMenuCloseWrapped = useCallback(() => {
176
- setMenuOpenState(false);
177
- onMenuClose && onMenuClose();
178
- }, [onMenuClose]);
179
-
180
- const handleKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(
181
- (e) => {
182
- switch (e.key) {
183
- case "Escape":
184
- // we can't rely on "menuIsOpen" prop here, as user may not pass this prop and rely on internal component behavior instead.
185
- if (menuOpenState) {
186
- e.stopPropagation();
187
- }
188
- break;
189
- case "Home":
190
- e.preventDefault();
191
- if (e.shiftKey) {
192
- (e.target as HTMLInputElement).selectionStart = 0;
193
- } else {
194
- (e.target as HTMLInputElement).setSelectionRange(0, 0);
195
- }
196
- break;
197
- case "End": {
198
- e.preventDefault();
199
- const len = (e.target as HTMLInputElement).value.length;
200
- if (e.shiftKey) {
201
- (e.target as HTMLInputElement).selectionEnd = len;
202
- } else {
203
- (e.target as HTMLInputElement).setSelectionRange(len, len);
204
- }
205
- break;
59
+ const isPhone = useIsPhone();
60
+ if (isPhone) {
61
+ return (
62
+ <SelectInPopover
63
+ {...(restProps as $TSFixMe)}
64
+ options={options}
65
+ isSearchable={isSearchable}
66
+ title={title || typeof placeholder === "string" ? placeholder : ""}
67
+ isClearable={typeof isClearable === "undefined" ? false : isClearable}
68
+ formatOptionLabel={
69
+ formatOptionLabel as ((option: T, {context}: {context: "menu" | "value"}) => React.ReactNode) | undefined
206
70
  }
207
- default:
208
- }
209
- onKeyDown && onKeyDown(e);
210
- },
211
- [onKeyDown, menuOpenState]
212
- );
213
-
214
- const selectRef = useRef<SelectInstance<T, U, V> | null>(null);
215
- const composedRef = useComposedRefs(forwardedRef, selectRef);
216
-
217
- const selectComponents = useSelectComponents({
218
- components,
219
- optionsCount,
220
- virtualized,
221
- isCollectionMode,
222
- forbidValuesClearInCollnMode,
223
- });
224
-
225
- const combinedStyles = useSelectStyles({virtualized, zIndex, styles});
226
-
227
- return (
228
- <ReactSelectRefContext.Provider value={selectRef as RefObject<SelectInstance>}>
229
- <BaseSelect<T, U, V>
230
- ref={composedRef}
231
- // There are places, where it is useful to override menuPortalTarget globally for all selects.
232
- // When you are already in some popup. e.g. user input in buttons, relation filter popover.
233
- menuPortalTarget={getPopupContainerElement ? getPopupContainerElement() : menuPortalTarget}
234
- menuPlacement={"auto"}
235
- styles={combinedStyles}
236
- isMulti={isCollectionMode}
237
- backspaceRemovesValue={isCollectionMode && !forbidValuesClearInCollnMode}
238
- tabSelectsValue={false}
239
- components={selectComponents}
240
- {...rest}
241
- onKeyDown={handleKeyDown}
242
- onMenuOpen={onMenuOpenWrapped}
243
- onMenuClose={onMenuCloseWrapped}
244
- onChange={rest.disabled ? undefined : onChange}
245
- isDisabled={rest.disabled}
71
+ isOptionDisabled={isOptionDisabled as ((option: T) => boolean) | undefined}
72
+ renderValue={() => {
73
+ return (
74
+ <div
75
+ className={css`
76
+ display: block;
77
+ position: relative;
78
+ `}
79
+ >
80
+ <div
81
+ className={css`
82
+ position: absolute;
83
+ inset: 0;
84
+ z-index: 1;
85
+ `}
86
+ />
87
+ <div
88
+ className={css`
89
+ pointer-events: none;
90
+ `}
91
+ >
92
+ <SelectComponent
93
+ {...restProps}
94
+ isSearchable={false}
95
+ components={emptyComponents}
96
+ placeholder={placeholder}
97
+ maxMenuHeight={maxMenuHeight}
98
+ options={options}
99
+ styles={styles}
100
+ formatOptionLabel={formatOptionLabel}
101
+ isOptionDisabled={isOptionDisabled}
102
+ isClearable={isClearable}
103
+ menuIsOpen={false}
104
+ />
105
+ </div>
106
+ </div>
107
+ );
108
+ }}
246
109
  />
247
- </ReactSelectRefContext.Provider>
110
+ );
111
+ }
112
+ return (
113
+ <SelectComponent<T, U, V>
114
+ ref={forwardedRef}
115
+ maxMenuHeight={maxMenuHeight}
116
+ options={options}
117
+ placeholder={placeholder}
118
+ formatOptionLabel={formatOptionLabel}
119
+ isOptionDisabled={isOptionDisabled}
120
+ isClearable={isClearable}
121
+ styles={styles}
122
+ {...restProps}
123
+ />
248
124
  );
249
125
  }) as <Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>>(
250
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
251
- props: SelectProps<Option, IsMulti, Group> & {ref?: any}
126
+ props: SelectProps<Option, IsMulti, Group> & {ref?: $TSFixMe}
252
127
  ) => JSX.Element;
253
128
 
254
- function CreatableSelectInner<T = unknown, U extends boolean = boolean, V extends GroupBase<T> = GroupBase<T>>(
255
- {
256
- components,
257
- isCollectionMode,
258
- menuPortalTarget,
259
- styles = {},
260
- virtualized = true,
261
- forbidValuesClearInCollnMode,
262
- ...rest
263
- }: CreatableProps<T, U, V> & SelectProps<T, U, V>,
264
- ref: ForwardedRef<SelectInstance<T, U, V>>
265
- ) {
266
- const optionsCount = useMemo(() => countOptions(rest.options), [rest.options]);
267
-
268
- const selectComponents = useSelectComponents({
269
- components,
270
- optionsCount,
271
- virtualized,
272
- isCollectionMode,
273
- forbidValuesClearInCollnMode,
274
- });
275
-
276
- const combinedStyles = useSelectStyles({virtualized, styles});
277
-
278
- return (
279
- <BaseCreatableSelect
280
- ref={ref}
281
- menuPortalTarget={menuPortalTarget}
282
- menuPlacement={"auto"}
283
- styles={combinedStyles}
284
- isMulti={isCollectionMode}
285
- backspaceRemovesValue={isCollectionMode}
286
- tabSelectsValue={false}
287
- components={selectComponents}
288
- {...rest}
289
- isDisabled={rest.disabled}
290
- />
291
- );
129
+ export function SingleRowSelect<T = unknown, U extends boolean = boolean, V extends GroupBase<T> = GroupBase<T>>({
130
+ styles = {},
131
+ ...rest
132
+ }: SelectProps<T, U, V>) {
133
+ return <Select {...rest} styles={combineStyles([makeSingleLineStyles<T, U, V>(), styles])} />;
292
134
  }
293
135
 
294
- export const CreatableSelect = forwardRef(CreatableSelectInner) as <
295
- T = unknown,
296
- U extends boolean = boolean,
297
- V extends GroupBase<T> = GroupBase<T>
298
- >(
299
- props: CreatableProps<T, U, V> & SelectProps<T, U, V>
300
- ) => ReturnType<typeof CreatableSelectInner>;
136
+ export {CreatableSelect} from "./select";