@box/user-selector 1.21.23

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 (106) hide show
  1. package/LICENSE +379 -0
  2. package/README.md +47 -0
  3. package/dist/chunks/user-selector-headless.module.js +16 -0
  4. package/dist/esm/index.js +6 -0
  5. package/dist/esm/lib/messages.js +46 -0
  6. package/dist/esm/lib/shared.js +9 -0
  7. package/dist/esm/lib/user-selector-container.js +43 -0
  8. package/dist/esm/lib/user-selector-headless/components/user-avatar.js +32 -0
  9. package/dist/esm/lib/user-selector-headless/components/user-selector-content.js +51 -0
  10. package/dist/esm/lib/user-selector-headless/components/user-selector-default-empty.js +43 -0
  11. package/dist/esm/lib/user-selector-headless/components/user-selector-default-error.js +20 -0
  12. package/dist/esm/lib/user-selector-headless/components/user-selector-skeleton.js +27 -0
  13. package/dist/esm/lib/user-selector-headless/hooks/use-avatars.js +22 -0
  14. package/dist/esm/lib/user-selector-headless/hooks/use-keyboard-navigation.js +27 -0
  15. package/dist/esm/lib/user-selector-headless/hooks/use-select-options.js +28 -0
  16. package/dist/esm/lib/user-selector-headless/user-selector-context.js +11 -0
  17. package/dist/esm/lib/user-selector-headless/user-selector-headless.js +168 -0
  18. package/dist/esm/lib/user-selector-list-item.js +114 -0
  19. package/dist/esm/lib/user-selector.js +77 -0
  20. package/dist/esm/lib/utils/VariantsAggregator.js +46 -0
  21. package/dist/esm/lib/utils/defaultRenderCustomOption.js +12 -0
  22. package/dist/esm/lib/utils/getInitials.js +7 -0
  23. package/dist/esm/lib/utils/isUserContactType.js +6 -0
  24. package/dist/i18n/bn-IN.js +12 -0
  25. package/dist/i18n/bn-IN.properties +20 -0
  26. package/dist/i18n/da-DK.js +12 -0
  27. package/dist/i18n/da-DK.properties +20 -0
  28. package/dist/i18n/de-DE.js +12 -0
  29. package/dist/i18n/de-DE.properties +20 -0
  30. package/dist/i18n/en-AU.js +12 -0
  31. package/dist/i18n/en-AU.properties +20 -0
  32. package/dist/i18n/en-CA.js +12 -0
  33. package/dist/i18n/en-CA.properties +20 -0
  34. package/dist/i18n/en-GB.js +12 -0
  35. package/dist/i18n/en-GB.properties +20 -0
  36. package/dist/i18n/en-US.js +12 -0
  37. package/dist/i18n/en-US.properties +20 -0
  38. package/dist/i18n/en-x-pseudo.js +12 -0
  39. package/dist/i18n/en-x-pseudo.properties +20 -0
  40. package/dist/i18n/es-419.js +12 -0
  41. package/dist/i18n/es-419.properties +20 -0
  42. package/dist/i18n/es-ES.js +12 -0
  43. package/dist/i18n/es-ES.properties +20 -0
  44. package/dist/i18n/fi-FI.js +12 -0
  45. package/dist/i18n/fi-FI.properties +20 -0
  46. package/dist/i18n/fr-CA.js +12 -0
  47. package/dist/i18n/fr-CA.properties +20 -0
  48. package/dist/i18n/fr-FR.js +12 -0
  49. package/dist/i18n/fr-FR.properties +20 -0
  50. package/dist/i18n/hi-IN.js +12 -0
  51. package/dist/i18n/hi-IN.properties +20 -0
  52. package/dist/i18n/it-IT.js +12 -0
  53. package/dist/i18n/it-IT.properties +20 -0
  54. package/dist/i18n/ja-JP.js +12 -0
  55. package/dist/i18n/ja-JP.properties +20 -0
  56. package/dist/i18n/json/src/lib/messages.json +1 -0
  57. package/dist/i18n/ko-KR.js +12 -0
  58. package/dist/i18n/ko-KR.properties +20 -0
  59. package/dist/i18n/nb-NO.js +12 -0
  60. package/dist/i18n/nb-NO.properties +20 -0
  61. package/dist/i18n/nl-NL.js +12 -0
  62. package/dist/i18n/nl-NL.properties +20 -0
  63. package/dist/i18n/pl-PL.js +12 -0
  64. package/dist/i18n/pl-PL.properties +20 -0
  65. package/dist/i18n/pt-BR.js +12 -0
  66. package/dist/i18n/pt-BR.properties +20 -0
  67. package/dist/i18n/ru-RU.js +12 -0
  68. package/dist/i18n/ru-RU.properties +20 -0
  69. package/dist/i18n/sv-SE.js +12 -0
  70. package/dist/i18n/sv-SE.properties +20 -0
  71. package/dist/i18n/tr-TR.js +12 -0
  72. package/dist/i18n/tr-TR.properties +20 -0
  73. package/dist/i18n/zh-CN.js +12 -0
  74. package/dist/i18n/zh-CN.properties +20 -0
  75. package/dist/i18n/zh-TW.js +12 -0
  76. package/dist/i18n/zh-TW.properties +20 -0
  77. package/dist/styles/user-selector-headless.css +1 -0
  78. package/dist/styles/user-selector-list-item.css +1 -0
  79. package/dist/styles/user-selector.css +1 -0
  80. package/dist/types/index.d.ts +3 -0
  81. package/dist/types/lib/messages.d.ts +53 -0
  82. package/dist/types/lib/shared.d.ts +2 -0
  83. package/dist/types/lib/stories/shared-headless.d.ts +4 -0
  84. package/dist/types/lib/stories/shared.d.ts +18 -0
  85. package/dist/types/lib/stories/utils/getCaretCoordinates.d.ts +5 -0
  86. package/dist/types/lib/stories/utils/testUsers.d.ts +13 -0
  87. package/dist/types/lib/types.d.ts +33 -0
  88. package/dist/types/lib/user-selector-container.d.ts +13 -0
  89. package/dist/types/lib/user-selector-headless/components/user-avatar.d.ts +6 -0
  90. package/dist/types/lib/user-selector-headless/components/user-selector-content.d.ts +15 -0
  91. package/dist/types/lib/user-selector-headless/components/user-selector-default-empty.d.ts +4 -0
  92. package/dist/types/lib/user-selector-headless/components/user-selector-default-error.d.ts +1 -0
  93. package/dist/types/lib/user-selector-headless/components/user-selector-skeleton.d.ts +5 -0
  94. package/dist/types/lib/user-selector-headless/hooks/use-avatars.d.ts +7 -0
  95. package/dist/types/lib/user-selector-headless/hooks/use-keyboard-navigation.d.ts +11 -0
  96. package/dist/types/lib/user-selector-headless/hooks/use-select-options.d.ts +14 -0
  97. package/dist/types/lib/user-selector-headless/types.d.ts +0 -0
  98. package/dist/types/lib/user-selector-headless/user-selector-context.d.ts +15 -0
  99. package/dist/types/lib/user-selector-headless/user-selector-headless.d.ts +28 -0
  100. package/dist/types/lib/user-selector-list-item.d.ts +56 -0
  101. package/dist/types/lib/user-selector.d.ts +37 -0
  102. package/dist/types/lib/utils/VariantsAggregator.d.ts +15 -0
  103. package/dist/types/lib/utils/defaultRenderCustomOption.d.ts +4 -0
  104. package/dist/types/lib/utils/getInitials.d.ts +1 -0
  105. package/dist/types/lib/utils/isUserContactType.d.ts +2 -0
  106. package/package.json +52 -0
@@ -0,0 +1,56 @@
1
+ import { AvatarProps, ComboboxOptionProps } from '@box/blueprint-web';
2
+ import { default as React, ComponentProps, ReactElement } from 'react';
3
+ import { CustomUserContactType, UserContactType, UserSelectorOption } from './types';
4
+ export type UserSelectorListItemProps = {
5
+ /**
6
+ * UserSelectorOption object to be displayed in the list item
7
+ */
8
+ userContact: UserContactType;
9
+ /**
10
+ * Function to render the avatar for the user contact
11
+ */
12
+ renderAvatar: (option: UserContactType) => ReactElement<AvatarProps>;
13
+ /**
14
+ * Callback function to be called when the list item is clicked
15
+ */
16
+ onClick?: (option: UserSelectorOption, id: string) => void;
17
+ /**
18
+ * Id of the list item
19
+ */
20
+ id?: string;
21
+ /**
22
+ * Classname to be applied to the list item
23
+ */
24
+ className?: string;
25
+ /**
26
+ * Boolean to determine if the list item is selected
27
+ */
28
+ selected?: boolean;
29
+ /**
30
+ * Boolean to determine if the user is a collaborator
31
+ */
32
+ isCollaborator?: boolean;
33
+ } & Omit<ComponentProps<'div'>, 'onClick'>;
34
+ export type UserSelectorListItemInfoProps = Omit<UserSelectorListItemProps, 'userContact' | 'onClick' | 'renderAvatar'> & {
35
+ title: string;
36
+ subtitle: string;
37
+ onClick?: () => void;
38
+ renderAvatar: () => ReactElement<AvatarProps>;
39
+ };
40
+ export type UserSelectorComboboxOptionProps = Omit<ComboboxOptionProps, 'children' | 'value'> & Omit<UserSelectorListItemProps, 'onClick' | 'userContact' | 'renderAvatar'> & {
41
+ /**
42
+ * UserSelectorOption object to be displayed in the list item
43
+ */
44
+ userContact: UserSelectorOption;
45
+ /**
46
+ * Function to render the avatar for the user contact
47
+ */
48
+ renderAvatar: (option: UserSelectorOption) => ReactElement<AvatarProps>;
49
+ /**
50
+ * Function to render the custom option
51
+ */
52
+ renderCustomOption: (option: CustomUserContactType, renderAvatar: () => ReactElement<AvatarProps>) => React.ReactNode;
53
+ };
54
+ export declare const UserSelectorListItemInfo: React.ForwardRefExoticComponent<Omit<UserSelectorListItemInfoProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
55
+ export declare const UserSelectorListItem: React.ForwardRefExoticComponent<Omit<UserSelectorListItemProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
56
+ export declare const UserSelectorComboboxOption: React.ForwardRefExoticComponent<Omit<UserSelectorComboboxOptionProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,37 @@
1
+ import { AvatarProps } from '@box/blueprint-web';
2
+ import { ComboboxWithApiProps } from '@box/combobox-with-api';
3
+ import { ReactElement } from 'react';
4
+ import { CustomUserContactType, FetchedAvatarUrls, UserContactType, UserSelectorOption } from './types';
5
+ export type BaseUserSelectorProps<T extends UserSelectorOption> = {
6
+ /**
7
+ * A dictionary with user ids mapped to avatar URLs
8
+ */
9
+ fetchedAvatarUrls: FetchedAvatarUrls;
10
+ /**
11
+ * Function to fetch users when the input value changes
12
+ */
13
+ fetchUsers: (inputValue: string) => Promise<UserContactType[]>;
14
+ /**
15
+ * onChange for controlled selected users state
16
+ */
17
+ onSelectedUsersChange: (selectedUsers: T[]) => void;
18
+ /**
19
+ * Controlled selected users state
20
+ */
21
+ selectedUsers: T[];
22
+ /**
23
+ * Support "text area" like styling
24
+ */
25
+ variant?: 'input' | 'textarea';
26
+ /**
27
+ * Default options to show when the input is empty
28
+ */
29
+ defaultOptions?: T[];
30
+ /**
31
+ * Function to render the custom option
32
+ */
33
+ renderCustomOption?: (option: CustomUserContactType, renderAvatar: () => ReactElement<AvatarProps>) => React.ReactNode;
34
+ };
35
+ export type UserSelectorProps<T extends UserSelectorOption = UserContactType> = BaseUserSelectorProps<T> & Omit<ComboboxWithApiProps<true, false, T>, 'as' | 'fetcher' | 'freeInput' | 'hideSelectedOptions' | 'loadingAriaLabel' | 'multiselect' | 'onValueChange' | 'value'>;
36
+ declare const UserSelector: <T extends UserSelectorOption = UserContactType>(props: UserSelectorProps<T>) => import("react/jsx-runtime").JSX.Element;
37
+ export default UserSelector;
@@ -0,0 +1,15 @@
1
+ import { default as React, CSSProperties, FunctionComponent } from 'react';
2
+ export type ComponentVariant<Props extends object> = {
3
+ props?: Partial<Props>;
4
+ ComponentTemplate?: FunctionComponent<any>;
5
+ };
6
+ export type ComponentRecord<ComponentProps> = Record<string, ComponentVariant<Partial<ComponentProps>>>;
7
+ export declare const VariantsAggregator: {
8
+ <T extends React.JSX.IntrinsicAttributes>({ defaultProps, DefaultComponentTemplate, variantsMap, containerStyle, }: {
9
+ defaultProps: T;
10
+ DefaultComponentTemplate: FunctionComponent<T>;
11
+ variantsMap: Record<string, ComponentVariant<T>>;
12
+ containerStyle?: CSSProperties;
13
+ }): import("react/jsx-runtime").JSX.Element;
14
+ displayName: string;
15
+ };
@@ -0,0 +1,4 @@
1
+ import { CustomUserContactType } from '@box/user-selector';
2
+ import { default as React, ReactElement } from 'react';
3
+ import { AvatarProps } from '@box/blueprint-web';
4
+ export declare function defaultRenderCustomOption(option: CustomUserContactType, renderAvatar: () => ReactElement<AvatarProps>): React.ReactNode;
@@ -0,0 +1 @@
1
+ export declare const getInitials: (name: string) => string;
@@ -0,0 +1,2 @@
1
+ import { UserContactType, UserSelectorOption } from '../types';
2
+ export declare function isUserContactType(value: UserSelectorOption): value is UserContactType;
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@box/user-selector",
3
+ "version": "1.21.23",
4
+ "peerDependencies": {
5
+ "@box/blueprint-web": "^7.8.0",
6
+ "@box/blueprint-web-assets": "^4.16.0",
7
+ "@box/combobox-with-api": "^0.5.14",
8
+ "lodash": "^4.17.15",
9
+ "react": "^17.0.0 || ^18.0.0",
10
+ "react-dom": "^17.0.0 || ^18.0.0",
11
+ "react-intl": "6.4.2"
12
+ },
13
+ "devDependencies": {
14
+ "@box/blueprint-web": "^12.68.2",
15
+ "@box/blueprint-web-assets": "^4.66.0",
16
+ "@box/combobox-with-api": "^0.57.23",
17
+ "@box/storybook-utils": "^0.14.2",
18
+ "@types/lodash": "^4.17.14",
19
+ "react": "^18.3.0",
20
+ "react-dom": "^18.3.0",
21
+ "react-intl": "6.4.2"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "main": "./dist/esm/index.js",
30
+ "module": "./dist/esm/index.js",
31
+ "types": "./dist/types/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "require": "./dist/esm/index.js",
35
+ "import": "./dist/esm/index.js",
36
+ "types": "./dist/types/index.d.ts"
37
+ },
38
+ "./*": {
39
+ "require": "./dist/esm/*",
40
+ "import": "./dist/esm/*",
41
+ "types": "./dist/types/*"
42
+ },
43
+ "./i18n/*": {
44
+ "require": "./dist/i18n/*",
45
+ "import": "./dist/i18n/*"
46
+ }
47
+ },
48
+ "sideEffects": [
49
+ "**/*.css"
50
+ ],
51
+ "license": "SEE LICENSE IN LICENSE"
52
+ }