ish-ui 1.3.5 → 1.3.6

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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright ish group pty ltd 2023.
2
+ * Copyright ish group pty ltd 2026.
3
3
  *
4
4
  * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
5
5
  *
@@ -23,10 +23,9 @@ import React, { useCallback, useContext, useEffect, useMemo, useRef, useState }
23
23
  import CloseIcon from '@mui/icons-material/Close';
24
24
  import ExpandMore from '@mui/icons-material/ExpandMore';
25
25
  import { ListboxComponent, useSelectStyles } from './SelectCustomComponents';
26
- import EditInPlaceFieldBase from './EditInPlaceFieldBase';
26
+ import EditInPlaceFieldBase from '../formFields/EditInPlaceFieldBase';
27
27
  import { makeAppStyles } from '../styles';
28
- import { getHighlightedPartLabel, stubComponent } from '../utils';
29
- import { usePrevious } from '../utils/hooks';
28
+ import { getHighlightedPartLabel, stubComponent, usePrevious } from '../utils';
30
29
  const useStyles = makeAppStyles()({
31
30
  popper: {
32
31
  zIndex: 1400
@@ -52,6 +51,7 @@ function EditInPlaceSearchSelect({ label, disabled, className, labelAdornment, i
52
51
  const { classes: ownClasses, cx } = useStyles();
53
52
  const { classes: selectClasses } = useSelectStyles();
54
53
  const classes = Object.assign(Object.assign({}, selectClasses), ownClasses);
54
+ const hasCustomListbox = !(categoryKey || inline);
55
55
  const sortedItems = useMemo(() => {
56
56
  const sorted = items && (sort
57
57
  ? [...items].sort(typeof sort === 'function'
@@ -216,13 +216,16 @@ function EditInPlaceSearchSelect({ label, disabled, className, labelAdornment, i
216
216
  return option[selectValueMark] === value;
217
217
  };
218
218
  const renderOption = (optionProps, data) => {
219
- if (typeof itemRenderer === 'function') {
220
- return [itemRenderer(getHighlightedPartLabel(getOptionLabel(data), searchValue), data, searchValue, optionProps), optionProps];
219
+ const optionLabel = getOptionLabel(data);
220
+ const hasItemRenderrer = typeof itemRenderer === 'function';
221
+ const highlightedPart = getHighlightedPartLabel(optionLabel, searchValue, hasCustomListbox || hasItemRenderrer ? undefined : optionProps);
222
+ if (!hasCustomListbox) {
223
+ return hasItemRenderrer ? itemRenderer(highlightedPart, data, searchValue, optionProps) : highlightedPart;
221
224
  }
222
- if (inline || categoryKey) {
223
- return getHighlightedPartLabel(getOptionLabel(data), searchValue, optionProps);
225
+ if (hasItemRenderrer) {
226
+ return [itemRenderer(highlightedPart, data, searchValue, optionProps), optionProps];
224
227
  }
225
- return [getHighlightedPartLabel(getOptionLabel(data), searchValue), optionProps];
228
+ return [highlightedPart, optionProps];
226
229
  };
227
230
  const selectedOption = useMemo(() => sortedItems.find(i => multiple
228
231
  ? (input.value || []).includes(i[selectValueMark])
@@ -266,13 +269,12 @@ function EditInPlaceSearchSelect({ label, disabled, className, labelAdornment, i
266
269
  ? valueRenderer(displayedValue, valueForRender, searchValue, { value: valueForRender && valueForRender[selectValueMark] })
267
270
  : null;
268
271
  }, [selectedOption, searchValue, displayedValue, selectValueMark, returnType, valueRenderer, input.value]);
269
- const renderIcons = useMemo(() => !disabled && (loading
270
- ? React.createElement(CircularProgress, { size: 24, thickness: 4, className: fieldClasses.loading })
271
- : (React.createElement("div", null,
272
- allowEmpty && input.value && (React.createElement(IconButton, { size: "small", onClick: onClear, color: "inherit" },
273
- React.createElement(CloseIcon, { fontSize: "inherit" }))),
274
- editIcon === undefined ? React.createElement(IconButton, { size: "small", color: "inherit", className: cx(classes.expandIcon, 'pl-0 pr-0', inline && 'p-0'), disableRipple: true },
275
- React.createElement(ExpandMore, { className: inline && 'fsInherit' })) : editIcon))), [disabled, loading, inline, allowEmpty, input.value]);
272
+ const renderLoading = useMemo(() => React.createElement(CircularProgress, Object.assign({}, inline ? { sx: { padding: 0.5 } } : {}, { size: 24, thickness: 4, className: fieldClasses.loading })), [fieldClasses.loading, inline]);
273
+ const renderIcons = useMemo(() => !disabled && (React.createElement("div", null,
274
+ allowEmpty && input.value && (React.createElement(IconButton, { size: "small", onClick: onClear, color: "inherit" },
275
+ React.createElement(CloseIcon, { fontSize: "inherit" }))),
276
+ editIcon === undefined ? React.createElement(IconButton, { size: "small", color: "inherit", className: cx(classes.expandIcon, 'pl-0 pr-0', inline && 'p-0'), disableRipple: true },
277
+ React.createElement(ExpandMore, { className: inline && 'fsInherit' })) : editIcon)), [disabled, inline, allowEmpty, input.value]);
276
278
  const inputValue = useMemo(() => {
277
279
  if (multiple) {
278
280
  return (input.value || []).map(v => sortedItems.find(s => s[selectValueMark] === v));
@@ -285,7 +287,7 @@ function EditInPlaceSearchSelect({ label, disabled, className, labelAdornment, i
285
287
  const renderInput = useCallback((_a) => {
286
288
  var { slotProps: { input: InputProps, htmlInput: inputProps } } = _a, params = __rest(_a, ["slotProps"]);
287
289
  const value = (isEditing ? searchValue : (typeof displayedValue === 'string' ? displayedValue : ''));
288
- return (React.createElement(EditInPlaceFieldBase, Object.assign({}, params, { variant: variant, key: input.name, name: input.name, value: value, error: error, invalid: hasError || invalid, inline: inline, label: label, warning: warning, fieldClasses: fieldClasses, rightAligned: rightAligned, shrink: Boolean(label || input.value), labelAdornment: labelAdornment, placeholder: renderedPlaceholder, editIcon: !hideEditIcon && renderIcons, InputProps: Object.assign(Object.assign({}, InputProps), { endAdornment: null, onChange: handleInputChange, onFocus: edit, onClick: onEditButtonFocus, onBlur,
290
+ return (React.createElement(EditInPlaceFieldBase, Object.assign({}, params, { variant: variant, key: input.name, name: input.name, value: value, error: error, invalid: hasError || invalid, inline: inline, label: label, warning: warning, fieldClasses: fieldClasses, rightAligned: rightAligned, shrink: Boolean(label || input.value), labelAdornment: labelAdornment, placeholder: renderedPlaceholder, editIcon: loading ? renderLoading : (!hideEditIcon && renderIcons), InputProps: Object.assign(Object.assign({}, InputProps), { endAdornment: null, onChange: handleInputChange, onFocus: edit, onClick: onEditButtonFocus, onBlur,
289
291
  disableUnderline, classes: {
290
292
  underline: fieldClasses.underline,
291
293
  input: cx(disabled && classes.readonly, fieldClasses.text),
@@ -300,7 +302,7 @@ function EditInPlaceSearchSelect({ label, disabled, className, labelAdornment, i
300
302
  inputProps.ref.current = ref === null || ref === void 0 ? void 0 : ref.node;
301
303
  }, classes: {
302
304
  select: cx('cursor-text', fieldClasses.text)
303
- }, onFocus: edit, value: (returnType === 'object' ? input.value[selectValueMark] : input.value) || '', endAdornment: React.createElement(InputAdornment, { position: "end", className: 'd-none' }, renderIcons), IconComponent: stubComponent }), renderValue)
305
+ }, onFocus: edit, value: (returnType === 'object' ? input.value[selectValueMark] : input.value) || '', endAdornment: loading ? renderLoading : React.createElement(InputAdornment, { position: "end", className: 'd-none' }, renderIcons), IconComponent: stubComponent }), renderValue)
304
306
  : null })));
305
307
  }, [
306
308
  variant,
@@ -354,7 +356,7 @@ function EditInPlaceSearchSelect({ label, disabled, className, labelAdornment, i
354
356
  popper: classes.popper,
355
357
  groupUl: 'm-0'
356
358
  }, groupBy: categoryKey && (option => option[categoryKey]), renderOption: renderOption, getOptionLabel: getOptionLabel, filterOptions: filterItems, slots: {
357
- listbox: inline || categoryKey ? undefined : ListBoxAdapter,
359
+ listbox: hasCustomListbox ? ListBoxAdapter : undefined,
358
360
  popper: categoryKey ? undefined : PopperAdapter,
359
361
  }, renderInput: renderInput, disableListWrap: true, openOnFocus: true, fullWidth: true }))));
360
362
  }
@@ -11,12 +11,12 @@ export declare const useSelectStyles: (params: void, muiStyleOverridesParams?: {
11
11
  };
12
12
  interface ListRowProps {
13
13
  data: {
14
- children: [
14
+ children: Array<[
15
15
  [
16
16
  React.ReactNode
17
17
  ],
18
18
  React.HTMLAttributes<HTMLLIElement>
19
- ];
19
+ ]>;
20
20
  selectAdornment: EditInPlaceSearchSelectFieldProps<any, any>['selectAdornment'];
21
21
  };
22
22
  index: number;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright ish group pty ltd 2023.
2
+ * Copyright ish group pty ltd 2026.
3
3
  *
4
4
  * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
5
5
  *
@@ -34,8 +34,8 @@ import { List } from 'react-window';
34
34
  import { green } from '@mui/material/colors';
35
35
  import { ListItemButton } from '@mui/material';
36
36
  import Tooltip from '@mui/material/Tooltip';
37
- import { makeAppStyles } from '../styles';
38
37
  import { useStyles } from 'tss-react/mui';
38
+ import { makeAppStyles } from '../styles';
39
39
  export const useSelectStyles = makeAppStyles()((theme, p, classes) => ({
40
40
  bottomMargin: {
41
41
  marginBottom: `${theme.spacing(1) + 1}`
@@ -132,10 +132,15 @@ export const useSelectStyles = makeAppStyles()((theme, p, classes) => ({
132
132
  }
133
133
  },
134
134
  }));
135
- export const ListRow = React.memo(({ data: { children, selectAdornment }, index, style }) => React.createElement(ListItemButton, Object.assign({}, children[index][1], { selected: children[index][1]['aria-selected'], style: style, key: index }), (((selectAdornment === null || selectAdornment === void 0 ? void 0 : selectAdornment.position) === 'start' && index === 0)
136
- || ((selectAdornment === null || selectAdornment === void 0 ? void 0 : selectAdornment.position) === 'end' && index === children.length))
137
- ? selectAdornment.content
138
- : children[index][0]));
135
+ export const ListRow = React.memo(({ data: { children, selectAdornment }, index, style }) => {
136
+ if (!children[index])
137
+ return null;
138
+ const [content, props] = children[index];
139
+ return React.createElement(ListItemButton, Object.assign({ component: 'li' }, props, { selected: Boolean(props['aria-selected']), style: style, key: index }), (((selectAdornment === null || selectAdornment === void 0 ? void 0 : selectAdornment.position) === 'start' && index === 0)
140
+ || ((selectAdornment === null || selectAdornment === void 0 ? void 0 : selectAdornment.position) === 'end' && index === children.length))
141
+ ? selectAdornment.content
142
+ : content);
143
+ });
139
144
  export const ListboxComponent = React.forwardRef((props, ref) => {
140
145
  const { children, rowHeight, remoteRowCount, loadMoreRows, classes, loading, selectAdornment, fieldClasses, ownerState } = props, other = __rest(props, ["children", "rowHeight", "remoteRowCount", "loadMoreRows", "classes", "loading", "selectAdornment", "fieldClasses", "ownerState"]);
141
146
  const { cx } = useStyles();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ish-ui",
3
3
  "sideEffects": false,
4
- "version": "1.3.5",
4
+ "version": "1.3.6",
5
5
  "description": "UI elements for onCourse and other ish apps",
6
6
  "main": "main.ts",
7
7
  "devDependencies": {