@tap-payments/os-micro-frontend-shared 0.1.429 → 0.1.430

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.
@@ -24,7 +24,7 @@ export declare const ColorSchemeButton: import("@emotion/styled").StyledComponen
24
24
  }, {}, {}>;
25
25
  export declare const ColorSchemeList: import("@emotion/styled").StyledComponent<import("@mui/material/MenuList").MenuListOwnProps & import("@mui/material").ListOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, "ref"> & {
26
26
  ref?: ((instance: HTMLUListElement | null) => void) | import("react").RefObject<HTMLUListElement> | null | undefined;
27
- }, "autoFocus" | "children" | keyof import("@mui/material/OverridableComponent").CommonProps | "sx" | "variant" | "dense" | "subheader" | "disablePadding" | "autoFocusItem" | "disabledItemsFocusable" | "disableListWrap"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
27
+ }, "autoFocus" | "children" | keyof import("@mui/material/OverridableComponent").CommonProps | "sx" | "variant" | "dense" | "autoFocusItem" | "disabledItemsFocusable" | "disableListWrap" | "disablePadding" | "subheader"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
28
28
  export declare const StyledInput: import("@emotion/styled").StyledComponent<{
29
29
  variant?: import("@mui/material/TextField").TextFieldVariants | undefined;
30
30
  } & Omit<import("@mui/material/TextField").FilledTextFieldProps | import("@mui/material/TextField").OutlinedTextFieldProps | import("@mui/material/TextField").StandardTextFieldProps, "variant"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
@@ -1,6 +1,14 @@
1
1
  import { SelectProps } from '../FormSelect/type';
2
2
  interface MultiSelectProps extends SelectProps {
3
3
  getOptionLabel?: (option: any) => string;
4
+ /** When true, shows a search input inside the dropdown to filter options by label */
5
+ showSearchInput?: boolean;
6
+ /** Placeholder for the search input */
7
+ searchPlaceholder?: string;
8
+ /** When true, shows the checkbox next to each option. Set to false to hide. Defaults to true. */
9
+ showCheckbox?: boolean;
10
+ /** When provided, options for which this returns true are disabled */
11
+ getOptionDisabled?: (option: any) => boolean;
4
12
  }
5
- export default function MultiSelect({ name, helperText, getOptionValue, renderOption, isOptionEqualToValue, ...props }: MultiSelectProps): import("react/jsx-runtime").JSX.Element;
13
+ export default function MultiSelect({ name, helperText, getOptionValue, getOptionLabel, renderOption, isOptionEqualToValue, getOptionDisabled, showSearchInput, searchPlaceholder, showCheckbox, options, ...props }: Readonly<MultiSelectProps>): import("react/jsx-runtime").JSX.Element;
6
14
  export {};
@@ -10,35 +10,57 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { useMemo, useState } from 'react';
13
14
  import { Box, MenuItem } from '@mui/material';
14
15
  import { Controller, useFormContext } from 'react-hook-form';
15
16
  import SelectBaseMultiple from '../../../InputBase/SelectBase/SelectBaseMultiple';
16
- import { CheckboxStyled } from './style';
17
+ import { CheckboxStyled, SearchInputStyled, SearchMenuItemStyled } from './style';
18
+ import { searchIcon } from '../../../../constants/index.js';
17
19
  export default function MultiSelect(_a) {
18
- var { name, helperText, getOptionValue, renderOption, isOptionEqualToValue } = _a, props = __rest(_a, ["name", "helperText", "getOptionValue", "renderOption", "isOptionEqualToValue"]);
20
+ var { name, helperText, getOptionValue, getOptionLabel, renderOption, isOptionEqualToValue, getOptionDisabled, showSearchInput = false, searchPlaceholder = 'Search', showCheckbox = true, options } = _a, props = __rest(_a, ["name", "helperText", "getOptionValue", "getOptionLabel", "renderOption", "isOptionEqualToValue", "getOptionDisabled", "showSearchInput", "searchPlaceholder", "showCheckbox", "options"]);
19
21
  const { control } = useFormContext();
22
+ const [searchValue, setSearchValue] = useState('');
23
+ const filteredOptions = useMemo(() => {
24
+ if (!showSearchInput || !searchValue.trim())
25
+ return options !== null && options !== void 0 ? options : [];
26
+ const query = searchValue.toLowerCase().trim();
27
+ return (options !== null && options !== void 0 ? options : []).filter((option) => {
28
+ var _a;
29
+ const label = (_a = (getOptionLabel ? getOptionLabel(option) : option === null || option === void 0 ? void 0 : option.label)) !== null && _a !== void 0 ? _a : '';
30
+ return String(label).toLowerCase().includes(query);
31
+ });
32
+ }, [options, showSearchInput, searchValue, getOptionLabel]);
20
33
  return (_jsx(Controller, { name: name, control: control, render: ({ field, fieldState }) => {
21
- var _a, _b;
22
- return (_jsx(SelectBaseMultiple, Object.assign({}, props, field, { hasError: !!fieldState.error, helperText: helperText !== null && helperText !== void 0 ? helperText : (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message, onChange: (e) => {
34
+ var _a;
35
+ return (_jsxs(SelectBaseMultiple, Object.assign({}, props, field, { options: options, getOptionLabel: getOptionLabel, hasError: !!fieldState.error, helperText: helperText !== null && helperText !== void 0 ? helperText : (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message, onChange: (e) => {
23
36
  field.onChange(e);
24
- } }, { children: (_b = props.options) === null || _b === void 0 ? void 0 : _b.map((option) => {
25
- var _a, _b, _c;
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- const isSelected = (_a = field.value) === null || _a === void 0 ? void 0 : _a.some((v) => {
28
- if (isOptionEqualToValue) {
29
- return isOptionEqualToValue(v, option);
37
+ }, MenuProps: Object.assign(Object.assign({}, props.MenuProps), { autoFocus: false, disableEnforceFocus: true }) }, { children: [showSearchInput && (_jsx(SearchMenuItemStyled, Object.assign({ disabled: true, onPointerDown: (e) => e.stopPropagation(), style: { backgroundColor: '#fff' } }, { children: _jsx(Box, Object.assign({ sx: { pointerEvents: 'auto', width: '100%' }, onPointerDown: (e) => e.stopPropagation() }, { children: _jsx(SearchInputStyled, { placeholder: searchPlaceholder, value: searchValue, onChange: (e) => setSearchValue(e.target.value), onKeyDown: (e) => e.stopPropagation(), onKeyUp: (e) => e.stopPropagation(), disableUnderline: true, fullWidth: true, inputProps: { 'aria-label': searchPlaceholder }, endAdornment: _jsx(Box, { component: "img", src: searchIcon, alt: "search", sx: { width: 14, height: 14, flexShrink: 0 } }) }) })) }))), filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map((option) => {
38
+ var _a, _b, _c;
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ const isSelected = (_a = field.value) === null || _a === void 0 ? void 0 : _a.some((v) => {
41
+ if (isOptionEqualToValue) {
42
+ return isOptionEqualToValue(v, option);
43
+ }
44
+ return (v === null || v === void 0 ? void 0 : v.id) === (option === null || option === void 0 ? void 0 : option.id);
45
+ });
46
+ const isDisabled = getOptionDisabled ? getOptionDisabled(option) : false;
47
+ const optionLabel = getOptionLabel ? getOptionLabel(option) : option.label;
48
+ let optionContent;
49
+ if (renderOption) {
50
+ optionContent = renderOption(option);
30
51
  }
31
- return (v === null || v === void 0 ? void 0 : v.id) === (option === null || option === void 0 ? void 0 : option.id);
32
- });
33
- return (_jsx(MenuItem, Object.assign({ value: (_b = (getOptionValue ? getOptionValue(option) : option === null || option === void 0 ? void 0 : option.id)) !== null && _b !== void 0 ? _b : '', sx: {
34
- fontSize: '12px',
35
- backgroundColor: (theme) => (isSelected ? '#F8F8F8 !important' : theme.palette.common.white),
36
- } }, { children: renderOption ? (renderOption(option)) : (_jsxs(Box, Object.assign({ sx: {
37
- display: 'flex',
38
- alignItems: 'center',
39
- width: '100%',
40
- gap: '8px',
41
- } }, { children: [_jsx(CheckboxStyled, { checked: isSelected }), props.getOptionLabel ? props.getOptionLabel(option) : option.label] }))) }), (_c = (getOptionValue ? getOptionValue(option) : option === null || option === void 0 ? void 0 : option.id)) !== null && _c !== void 0 ? _c : ''));
42
- }) })));
52
+ else {
53
+ optionContent = optionLabel;
54
+ }
55
+ return (_jsx(MenuItem, Object.assign({ value: (_b = (getOptionValue ? getOptionValue(option) : option === null || option === void 0 ? void 0 : option.id)) !== null && _b !== void 0 ? _b : '', disabled: isDisabled, sx: {
56
+ fontSize: '12px',
57
+ backgroundColor: (theme) => (isSelected ? '#F8F8F8 !important' : theme.palette.common.white),
58
+ } }, { children: showCheckbox ? (_jsxs(Box, Object.assign({ sx: {
59
+ display: 'flex',
60
+ alignItems: 'center',
61
+ width: '100%',
62
+ gap: '8px',
63
+ } }, { children: [_jsx(CheckboxStyled, { checked: isSelected }), optionContent] }))) : (optionContent) }), (_c = (getOptionValue ? getOptionValue(option) : option === null || option === void 0 ? void 0 : option.id)) !== null && _c !== void 0 ? _c : ''));
64
+ })] })));
43
65
  } }));
44
66
  }
@@ -1 +1,6 @@
1
+ /// <reference types="react" />
1
2
  export declare const CheckboxStyled: import("@emotion/styled").StyledComponent<import("@mui/material").CheckboxProps & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
3
+ export declare const SearchInputStyled: import("@emotion/styled").StyledComponent<import("@mui/material/Input").InputProps & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
4
+ export declare const SearchMenuItemStyled: import("@emotion/styled").StyledComponent<import("@mui/material/MenuItem").MenuItemOwnProps & Omit<import("@mui/material").ButtonBaseOwnProps, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "ref"> & {
5
+ ref?: ((instance: HTMLLIElement | null) => void) | import("react").RefObject<HTMLLIElement> | null | undefined;
6
+ }, "disabled" | "classes" | "autoFocus" | "className" | "style" | "tabIndex" | "children" | "selected" | "sx" | "dense" | "action" | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "TouchRippleProps" | "touchRippleRef" | "disableGutters" | "divider"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
@@ -1,4 +1,6 @@
1
1
  import Checkbox from '../../../Checkbox';
2
+ import MenuItem from '@mui/material/MenuItem';
3
+ import Input from '@mui/material/Input';
2
4
  import { styled } from '@mui/material/styles';
3
5
  export const CheckboxStyled = styled(Checkbox)(() => ({
4
6
  padding: 0,
@@ -7,3 +9,48 @@ export const CheckboxStyled = styled(Checkbox)(() => ({
7
9
  height: 12,
8
10
  },
9
11
  }));
12
+ export const SearchInputStyled = styled(Input)(({ theme }) => ({
13
+ width: '100%',
14
+ height: 36,
15
+ padding: '8px 8px 8px 12px',
16
+ borderRadius: 4,
17
+ backgroundColor: theme.palette.common.white,
18
+ border: '1px solid #F2F2F2',
19
+ boxSizing: 'border-box',
20
+ '&:hover': {
21
+ borderColor: '#F2F2F2',
22
+ },
23
+ '&.Mui-focused': {
24
+ borderColor: '#F2F2F2',
25
+ backgroundColor: theme.palette.common.white,
26
+ },
27
+ '&:before, &:after': {
28
+ display: 'none',
29
+ },
30
+ '& input': {
31
+ padding: 0,
32
+ fontSize: 10,
33
+ },
34
+ '& .MuiInputBase-input': {
35
+ paddingRight: 4,
36
+ },
37
+ }));
38
+ export const SearchMenuItemStyled = styled(MenuItem)(({ theme }) => ({
39
+ opacity: 1,
40
+ paddingTop: 0,
41
+ paddingBottom: 0,
42
+ marginBottom: 8,
43
+ minHeight: 'auto',
44
+ pointerEvents: 'none',
45
+ backgroundColor: theme.palette.common.white,
46
+ '&:hover': {
47
+ backgroundColor: theme.palette.common.white,
48
+ },
49
+ '&.Mui-focusVisible': {
50
+ backgroundColor: theme.palette.common.white,
51
+ },
52
+ '&.Mui-disabled': {
53
+ backgroundColor: theme.palette.common.white,
54
+ opacity: 1,
55
+ },
56
+ }));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tap-payments/os-micro-frontend-shared",
3
3
  "description": "Shared components and utilities for Tap Payments micro frontends",
4
- "version": "0.1.429",
4
+ "version": "0.1.430",
5
5
  "testVersion": 0,
6
6
  "type": "module",
7
7
  "main": "build/index.js",