@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
@@ -25,10 +25,10 @@ import {
25
25
  OnChangeValue,
26
26
  OptionsOrGroups,
27
27
  PropsValue,
28
- Select as ReactSelect,
28
+ SelectComponent as ReactSelect,
29
29
  SelectProps,
30
30
  StylesConfig,
31
- } from "./index";
31
+ } from "./select";
32
32
  import {SelectControlSettingsProvider} from "./select-control-settings-context";
33
33
  import {ButtonColor, ButtonVariant} from "../button/base-button";
34
34
  import {makeSelectInPopoverStyles} from "./styles";
@@ -131,6 +131,7 @@ export type SelectInPopoverRef<T, U extends boolean, V extends GroupBase<T>> = {
131
131
 
132
132
  type Props<T, U extends boolean, V extends GroupBase<T>> = {
133
133
  value?: PropsValue<T>;
134
+ isSearchable?: boolean;
134
135
  menuIsOpen?: boolean;
135
136
  autoFocus?: boolean;
136
137
  virtualized?: boolean;
@@ -139,6 +140,7 @@ type Props<T, U extends boolean, V extends GroupBase<T>> = {
139
140
  noOptionsMessage?: () => string | JSX.Element | null;
140
141
  options: OptionsOrGroups<T, V>;
141
142
  filterOption?: SelectProps<T, U, V>["filterOption"];
143
+ menuPortalTarget?: SelectProps<T, U, V>["menuPortalTarget"];
142
144
  inputValue?: string;
143
145
  disabled?: boolean;
144
146
  isCollectionMode?: U;
@@ -203,7 +205,11 @@ function SelectInPopoverInner<T, U extends boolean, V extends GroupBase<T>>(
203
205
  otherSelectProps,
204
206
  forbidValuesClearInCollnMode,
205
207
  isOptionDisabled,
208
+ isSearchable = true,
209
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
210
+ menuPortalTarget,
206
211
  popoverPlacement = "bottom-start",
212
+ ...rest
207
213
  } = props;
208
214
  const [visible, setVisible] = useControllableState({
209
215
  value: menuIsOpen,
@@ -381,9 +387,10 @@ function SelectInPopoverInner<T, U extends boolean, V extends GroupBase<T>>(
381
387
  {/*So in dom react-select will be a child of popover. */}
382
388
  <SelectControlSettingsProvider inPopover={true} getPopupContainerElement={undefined}>
383
389
  <ReactSelect<T, U, V>
390
+ {...rest}
384
391
  ref={selectRef}
385
392
  styles={styles}
386
- isSearchable={true}
393
+ isSearchable={isSearchable}
387
394
  onKeyDown={onKeyDown}
388
395
  autoFocus={autoFocus}
389
396
  onBlur={onBlur}
@@ -408,6 +415,7 @@ function SelectInPopoverInner<T, U extends boolean, V extends GroupBase<T>>(
408
415
  isClearable={!isCollectionMode && isClearable}
409
416
  formatGroupLabel={formatGroupLabel}
410
417
  formatOptionLabel={formatOptionLabel}
418
+ menuShouldBlockScroll={false}
411
419
  {...otherSelectProps}
412
420
  components={selectComponents}
413
421
  forbidValuesClearInCollnMode={forbidValuesClearInCollnMode}
@@ -0,0 +1,288 @@
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 {makeComponentsStyles, makeNonVirtualizedStyles, makeVirtualizedStyles, makeZIndexStyles} from "./styles";
34
+ import {countOptions, GroupBase, ReactSelectRefContext} from "./util";
35
+ import _ from "lodash";
36
+
37
+ export type {
38
+ ActionMeta,
39
+ GroupBase,
40
+ MenuListProps,
41
+ MenuProps,
42
+ ControlProps,
43
+ MultiValue,
44
+ MultiValueProps,
45
+ OnChangeValue,
46
+ OptionProps,
47
+ OptionsOrGroups,
48
+ PropsValue,
49
+ SingleValue,
50
+ SingleValueProps,
51
+ StylesConfig,
52
+ SelectInstance,
53
+ BaseSelectProps,
54
+ };
55
+
56
+ export {reactSelectComponents as components, MenuListVirtualized, createFilter};
57
+
58
+ function GroupVirtualized() {
59
+ return null;
60
+ }
61
+
62
+ export function combineStyles<T, U extends boolean, V extends GroupBase<T>>(styles: StylesConfig<T, U, V>[]) {
63
+ return styles.reduce(mergeStyles, {});
64
+ }
65
+
66
+ export type SelectProps<T = unknown, U extends boolean = boolean, V extends GroupBase<T> = GroupBase<T>> = Omit<
67
+ Omit<Omit<BaseSelectProps<T, U, V>, "isMulti">, "backspaceRemovesValue">,
68
+ "isDisabled"
69
+ > & {
70
+ virtualized?: boolean;
71
+ title?: string;
72
+ isCollectionMode?: U;
73
+ disabled?: boolean;
74
+ forbidValuesClearInCollnMode?: boolean;
75
+ };
76
+
77
+ const FAST_OPTION_USAGE_THRESHOLD = 200;
78
+
79
+ function useSelectComponents<T, U extends boolean, V extends GroupBase<T>>({
80
+ components,
81
+ optionsCount,
82
+ virtualized,
83
+ isCollectionMode,
84
+ forbidValuesClearInCollnMode,
85
+ }: {
86
+ components: SelectProps<T, U, V>["components"];
87
+ optionsCount: number;
88
+ virtualized: boolean;
89
+ isCollectionMode?: U;
90
+ forbidValuesClearInCollnMode?: boolean;
91
+ }) {
92
+ const shouldUseFastOption = optionsCount > FAST_OPTION_USAGE_THRESHOLD;
93
+ const shouldHideMultiValueRemove = isCollectionMode && forbidValuesClearInCollnMode;
94
+
95
+ return {
96
+ Menu,
97
+ DropdownIndicator,
98
+ ClearIndicator,
99
+ MultiValueRemove: shouldHideMultiValueRemove ? NoClearIndicator : ClearIndicator,
100
+ NoOptionsMessage,
101
+ GroupHeading,
102
+ Option: shouldUseFastOption ? Option : OptionSlow,
103
+ ...components,
104
+ Group: virtualized ? GroupVirtualized : components?.Group ? components.Group : reactSelectComponents.Group,
105
+ MenuList: virtualized
106
+ ? MenuListVirtualized
107
+ : components?.MenuList
108
+ ? components.MenuList
109
+ : reactSelectComponents.MenuList,
110
+ };
111
+ }
112
+
113
+ function useSelectStyles<T, U extends boolean, V extends GroupBase<T>>({
114
+ virtualized,
115
+ zIndex,
116
+ styles,
117
+ }: {
118
+ virtualized: boolean;
119
+ zIndex?: number;
120
+ styles?: SelectProps<T, U, V>["styles"];
121
+ }) {
122
+ return useMemo(() => {
123
+ return combineStyles<T, U, V>(
124
+ _.compact([
125
+ makeComponentsStyles<T, U, V>(),
126
+ virtualized ? makeVirtualizedStyles<T, U, V>() : makeNonVirtualizedStyles<T, U, V>(),
127
+ zIndex ? makeZIndexStyles<T, U, V>(zIndex) : null,
128
+ styles,
129
+ ])
130
+ );
131
+ }, [styles, virtualized, zIndex]);
132
+ }
133
+
134
+ export const SelectComponent = forwardRef(function Select<
135
+ T = unknown,
136
+ U extends boolean = boolean,
137
+ V extends GroupBase<T> = GroupBase<T>
138
+ >(
139
+ {
140
+ components,
141
+ isCollectionMode,
142
+ menuPortalTarget,
143
+ onKeyDown,
144
+ styles,
145
+ virtualized = true,
146
+ onMenuOpen,
147
+ onMenuClose,
148
+ onChange,
149
+ forbidValuesClearInCollnMode,
150
+ ...rest
151
+ }: SelectProps<T, U, V>,
152
+ forwardedRef: ForwardedRef<SelectInstance<T, U, V>>
153
+ ) {
154
+ const {getPopupContainerElement, zIndex} = useSelectControlSettings();
155
+ const [menuOpenState, setMenuOpenState] = useState(rest.defaultMenuIsOpen);
156
+ const optionsCount = useMemo(() => countOptions(rest.options), [rest.options]);
157
+
158
+ const onMenuOpenWrapped = useCallback(() => {
159
+ setMenuOpenState(true);
160
+ onMenuOpen && onMenuOpen();
161
+ }, [onMenuOpen]);
162
+
163
+ const onMenuCloseWrapped = useCallback(() => {
164
+ setMenuOpenState(false);
165
+ onMenuClose && onMenuClose();
166
+ }, [onMenuClose]);
167
+
168
+ const handleKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(
169
+ (e) => {
170
+ switch (e.key) {
171
+ case "Escape":
172
+ // we can't rely on "menuIsOpen" prop here, as user may not pass this prop and rely on internal component behavior instead.
173
+ if (menuOpenState) {
174
+ e.stopPropagation();
175
+ }
176
+ break;
177
+ case "Home":
178
+ e.preventDefault();
179
+ if (e.shiftKey) {
180
+ (e.target as HTMLInputElement).selectionStart = 0;
181
+ } else {
182
+ (e.target as HTMLInputElement).setSelectionRange(0, 0);
183
+ }
184
+ break;
185
+ case "End": {
186
+ e.preventDefault();
187
+ const len = (e.target as HTMLInputElement).value.length;
188
+ if (e.shiftKey) {
189
+ (e.target as HTMLInputElement).selectionEnd = len;
190
+ } else {
191
+ (e.target as HTMLInputElement).setSelectionRange(len, len);
192
+ }
193
+ break;
194
+ }
195
+ default:
196
+ }
197
+ onKeyDown && onKeyDown(e);
198
+ },
199
+ [onKeyDown, menuOpenState]
200
+ );
201
+
202
+ const selectRef = useRef<SelectInstance<T, U, V> | null>(null);
203
+ const composedRef = useComposedRefs(forwardedRef, selectRef);
204
+
205
+ const selectComponents = useSelectComponents({
206
+ components,
207
+ optionsCount,
208
+ virtualized,
209
+ isCollectionMode,
210
+ forbidValuesClearInCollnMode,
211
+ });
212
+
213
+ const combinedStyles = useSelectStyles({virtualized, zIndex, styles});
214
+
215
+ return (
216
+ <ReactSelectRefContext.Provider value={selectRef as RefObject<SelectInstance>}>
217
+ <BaseSelect<T, U, V>
218
+ ref={composedRef}
219
+ // There are places, where it is useful to override menuPortalTarget globally for all selects.
220
+ // When you are already in some popup. e.g. user input in buttons, relation filter popover.
221
+ menuPortalTarget={getPopupContainerElement ? getPopupContainerElement() : menuPortalTarget}
222
+ menuPlacement={"auto"}
223
+ styles={combinedStyles}
224
+ isMulti={isCollectionMode}
225
+ backspaceRemovesValue={isCollectionMode && !forbidValuesClearInCollnMode}
226
+ tabSelectsValue={false}
227
+ components={selectComponents}
228
+ {...rest}
229
+ onKeyDown={handleKeyDown}
230
+ onMenuOpen={onMenuOpenWrapped}
231
+ onMenuClose={onMenuCloseWrapped}
232
+ onChange={rest.disabled ? undefined : onChange}
233
+ isDisabled={rest.disabled}
234
+ />
235
+ </ReactSelectRefContext.Provider>
236
+ );
237
+ }) as <Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>>(
238
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
239
+ props: SelectProps<Option, IsMulti, Group> & {ref?: any}
240
+ ) => JSX.Element;
241
+
242
+ function CreatableSelectInner<T = unknown, U extends boolean = boolean, V extends GroupBase<T> = GroupBase<T>>(
243
+ {
244
+ components,
245
+ isCollectionMode,
246
+ menuPortalTarget,
247
+ styles = {},
248
+ virtualized = true,
249
+ forbidValuesClearInCollnMode,
250
+ ...rest
251
+ }: CreatableProps<T, U, V> & SelectProps<T, U, V>,
252
+ ref: ForwardedRef<SelectInstance<T, U, V>>
253
+ ) {
254
+ const optionsCount = useMemo(() => countOptions(rest.options), [rest.options]);
255
+
256
+ const selectComponents = useSelectComponents({
257
+ components,
258
+ optionsCount,
259
+ virtualized,
260
+ isCollectionMode,
261
+ forbidValuesClearInCollnMode,
262
+ });
263
+
264
+ const combinedStyles = useSelectStyles({virtualized, styles});
265
+
266
+ return (
267
+ <BaseCreatableSelect
268
+ ref={ref}
269
+ menuPortalTarget={menuPortalTarget}
270
+ menuPlacement={"auto"}
271
+ styles={combinedStyles}
272
+ isMulti={isCollectionMode}
273
+ backspaceRemovesValue={isCollectionMode}
274
+ tabSelectsValue={false}
275
+ components={selectComponents}
276
+ {...rest}
277
+ isDisabled={rest.disabled}
278
+ />
279
+ );
280
+ }
281
+
282
+ export const CreatableSelect = forwardRef(CreatableSelectInner) as <
283
+ T = unknown,
284
+ U extends boolean = boolean,
285
+ V extends GroupBase<T> = GroupBase<T>
286
+ >(
287
+ props: CreatableProps<T, U, V> & SelectProps<T, U, V>
288
+ ) => ReturnType<typeof CreatableSelectInner>;
@@ -48,7 +48,7 @@ const rootCss = css`
48
48
  box-sizing: border-box;
49
49
  min-height: 44px;
50
50
  min-width: 320px;
51
- max-width: min(calc(100vw - 40px), 400px);
51
+ max-width: min(calc(100vw - 40px), 480px);
52
52
  `;
53
53
 
54
54
  const rootLineCss = css`
@@ -13,8 +13,6 @@ export const toggleButtonCss = css`
13
13
  box-sizing: border-box;
14
14
  display: flex;
15
15
  align-items: center;
16
- min-height: 24px;
17
- font-size: ${textStyles.small.fontSize}px;
18
16
  border-radius: ${border.radius8}px;
19
17
 
20
18
  transition-property: border, background-color, color, opacity, box-shadow;
@@ -23,8 +21,6 @@ export const toggleButtonCss = css`
23
21
  color: ${themeVars.textColor};
24
22
  ${iconColorVar}: ${themeVars.colorIconButtonGhostNeutral};
25
23
 
26
- ${iconSizeVar}: 16px;
27
-
28
24
  border: 1.5px solid ${themeVars.colorBorderReactionsHover};
29
25
  background-color: ${themeVars.colorBgReactionsDefault};
30
26
 
@@ -37,13 +33,29 @@ export const toggleButtonCss = css`
37
33
  line-height: 16px;
38
34
  user-select: none;
39
35
 
36
+ &[data-size="small"] {
37
+ font-size: ${textStyles.small.fontSize}px;
38
+ line-height: 16px;
39
+ min-height: 24px;
40
+
41
+ ${iconSizeVar}: 16px;
42
+ }
43
+
40
44
  &[data-size="medium"] {
45
+ font-size: ${textStyles.regular.fontSize}px;
46
+ line-height: 20px;
41
47
  min-height: 28px;
48
+
49
+ ${iconSizeVar}: 18px;
42
50
  }
43
51
 
44
52
  &[data-size="large"] {
53
+ font-size: ${textStyles.regular.fontSize}px;
54
+ line-height: 20px;
45
55
  min-height: 32px;
46
56
  padding-inline: 7px;
57
+
58
+ ${iconSizeVar}: 18px;
47
59
  }
48
60
 
49
61
  &:not(:disabled, [aria-readonly="true"]) {
@@ -3,6 +3,7 @@ import {FC, ComponentProps, useMemo} from "react";
3
3
  import {ThemeColors} from "./design-system";
4
4
  import {useTheme} from "./theme-provider";
5
5
  import {Toggle} from "./toggle";
6
+ import {useIsPhone} from "./use-is-phone";
6
7
 
7
8
  const getBackgroundColors = (accentColor: string | undefined, theme: ThemeColors) => {
8
9
  return accentColor && chroma.valid(accentColor)
@@ -21,9 +22,17 @@ interface ToggleOnOffProps extends Omit<ComponentProps<typeof Toggle>, "backgrou
21
22
  }
22
23
 
23
24
  export const ToggleOnOff: FC<ToggleOnOffProps> = ({value, color, ...rest}) => {
25
+ const isPhone = useIsPhone();
24
26
  const theme = useTheme();
25
27
  const {enabledColor, disabledColor} = useMemo(() => getBackgroundColors(color, theme), [color, theme]);
26
- return <Toggle value={Boolean(value)} backgroundColor={value ? enabledColor : disabledColor} {...rest} />;
28
+ return (
29
+ <Toggle
30
+ value={Boolean(value)}
31
+ size={isPhone ? "large" : "medium"}
32
+ backgroundColor={value ? enabledColor : disabledColor}
33
+ {...rest}
34
+ />
35
+ );
27
36
  };
28
37
 
29
38
  interface ReduxFormToggleOnOffProps extends ToggleOnOffProps {