@sqrzro/ui 4.0.0-alpha.44 → 4.0.0-alpha.46

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.
@@ -32,6 +32,7 @@ async function CollectionComponent({ data, defaultFilters, emptyMessageProps, fi
32
32
  const componentEmptyMessageProps = checkHasFilters(awaitedSearchParams)
33
33
  ? {
34
34
  children: messages.EMPTY_FILTER_DESCRIPTION,
35
+ icon: emptyMessageProps?.icon ?? null,
35
36
  title: messages.EMPTY_FILTER_TITLE,
36
37
  }
37
38
  : emptyMessageProps;
@@ -7,7 +7,7 @@ function getNamesFromIDs(ids, data) {
7
7
  const set = new Set(ids);
8
8
  return data
9
9
  .filter((item) => set.has(item.value))
10
- .map((item) => item.$data?.label || item.label);
10
+ .map((item) => item.$data?.label || String(item.label));
11
11
  }
12
12
  const LENGTH_OF_YEAR = 4;
13
13
  const PAD = 2;
@@ -7,5 +7,5 @@ export interface AutocompleteComponentProps<T> extends DropdownComponentProps<T>
7
7
  selected?: DropdownObject<T> | null;
8
8
  }
9
9
  export type AutocompleteProps<T> = ClassNameProps<DropdownClassNames> & InputProps<T | null> & AutocompleteComponentProps<T>;
10
- declare function Autocomplete<T>({ hasError, isDisabled, isLoading, isOptional, name, onChange, onSearch, options, selected, placeholder, value, }: Readonly<AutocompleteProps<T>>): React.ReactElement;
10
+ declare function Autocomplete<T>({ hasError, isDisabled, name, onChange, onSearch, options, selected, placeholder, value, }: Readonly<AutocompleteProps<T>>): React.ReactElement;
11
11
  export default Autocomplete;
@@ -3,10 +3,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Fragment, useRef, useState } from 'react';
4
4
  import Popover from '../../../components/utility/Popover';
5
5
  import useClickOutside from '../../../hooks/useClickOutside';
6
- import DropdownList from '../DropdownList';
7
6
  import StaticTextInput from '../StaticTextInput';
8
7
  import TextInput from '../TextInput';
9
- function Autocomplete({ hasError, isDisabled, isLoading, isOptional, name, onChange, onSearch, options, selected, placeholder, value, }) {
8
+ import AutocompleteList from '../AutocompleteList';
9
+ function Autocomplete({ hasError, isDisabled, name, onChange, onSearch, options, selected, placeholder, value, }) {
10
10
  const inputRef = useRef(null);
11
11
  const [search, setSearch] = useState('');
12
12
  const [isOpen, setIsOpen, ref] = useClickOutside();
@@ -32,6 +32,6 @@ function Autocomplete({ hasError, isDisabled, isLoading, isOptional, name, onCha
32
32
  inputRef.current?.focus();
33
33
  }, 10);
34
34
  }
35
- return (_jsx("div", { ref: ref, className: "relative", children: selected ? (_jsx(StaticTextInput, { details: selected.details, hasError: hasError, isDisabled: isDisabled, isOptional: isOptional, label: selected.label, name: name, onClick: handleReset, placeholder: placeholder || 'Select...', value: value ? String(value) : '' })) : (_jsxs(Fragment, { children: [_jsx(TextInput, { ref: inputRef, hasError: hasError, isDisabled: isDisabled, name: `${name}_search`, onChange: handleSearch, onFocus: () => setIsOpen(Boolean(options?.length)), placeholder: "Start typing...", value: search }), _jsx(Popover, { align: "center", isOpen: isOpen, isScrollable: true, children: options?.length ? (_jsx(DropdownList, { name: name, onChange: handleChange, options: options ?? [], value: value })) : isLoading ? (_jsx("div", { children: "Loading..." })) : (_jsx("div", { children: "No results" })) })] })) }));
35
+ return (_jsx("div", { ref: ref, className: "relative", children: selected ? (_jsx(StaticTextInput, { details: selected.details, hasError: hasError, isDisabled: isDisabled, isOptional: true, label: selected.label, name: name, onClear: handleReset, placeholder: placeholder || 'Select...', value: value ? String(value) : '' })) : (_jsxs(Fragment, { children: [_jsx(TextInput, { ref: inputRef, hasError: hasError, isDisabled: isDisabled, name: `${name}_search`, onChange: handleSearch, onFocus: () => setIsOpen(true), placeholder: "Start typing...", value: search }), _jsx(Popover, { align: "center", isOpen: isOpen && search.length >= 3, isScrollable: true, children: _jsx(AutocompleteList, { name: name, onChange: handleChange, options: options, search: search, value: value }) })] })) }));
36
36
  }
37
37
  export default Autocomplete;
@@ -0,0 +1,7 @@
1
+ import type { DropdownObject, InputProps } from '../../interfaces';
2
+ interface AutocompleteListProps<T> extends InputProps<T | null> {
3
+ options?: DropdownObject<T>[];
4
+ search: string;
5
+ }
6
+ declare function AutocompleteList<T>({ name, onChange, options, search, value, }: AutocompleteListProps<T>): React.ReactElement | null;
7
+ export default AutocompleteList;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment } from 'react';
3
+ import DropdownList from '../DropdownList';
4
+ function AutocompleteList({ name, onChange, options, search, value, }) {
5
+ if (!options?.length) {
6
+ return (_jsx(DropdownList, { name: name, options: [
7
+ {
8
+ label: (_jsxs(Fragment, { children: ["No results found for ", _jsx("strong", { children: search })] })),
9
+ value: null,
10
+ },
11
+ ] }));
12
+ }
13
+ return _jsx(DropdownList, { name: name, onChange: onChange, options: options, value: value });
14
+ }
15
+ export default AutocompleteList;
@@ -10,7 +10,7 @@ function findByValue(options, value) {
10
10
  return options.find((item) => item.value === value);
11
11
  }
12
12
  export function renderLabel(options, value) {
13
- return findByValue(options, value)?.label || '';
13
+ return String(findByValue(options, value)?.label || '');
14
14
  }
15
15
  export function renderDetails(options, value) {
16
16
  return findByValue(options, value)?.details || '';
@@ -1,9 +1,10 @@
1
1
  'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useClassNames } from '../../../styles/context';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useClassNames, useIcon } from '../../../styles/context';
4
4
  import tw from '../../../styles/classnames/utility/tw';
5
5
  function FormError({ children, classNames, classNameProps, id, isAssistive, }) {
6
6
  const componentClassNames = useClassNames('formField', { props: classNameProps }, classNames);
7
- return (_jsx("div", { className: tw(componentClassNames?.error, isAssistive ? 'sr-only' : null), id: `${id}_err`, children: children }));
7
+ const Icon = useIcon('formField.error');
8
+ return (_jsxs("div", { className: tw(componentClassNames?.error, isAssistive ? 'sr-only' : null), id: `${id}_err`, children: [Icon ? (_jsx("div", { className: "h-5 w-5", children: _jsx(Icon, {}) })) : null, children] }));
8
9
  }
9
10
  export default FormError;
@@ -10,7 +10,7 @@ export interface StaticTextInputClassNames {
10
10
  }
11
11
  export interface StaticTextInputProps extends ClassNameProps<StaticTextInputClassNames>, Omit<InputProps<string[] | string, string[] | string>, 'onChange'> {
12
12
  details?: string | null;
13
- label: string;
13
+ label: React.ReactNode;
14
14
  icon?: React.ReactNode;
15
15
  isOptional?: boolean;
16
16
  onClear?: () => void;
@@ -16,6 +16,6 @@ function StaticTextInput({ classNames, classNameProps, details, hasError, icon,
16
16
  function handleClear() {
17
17
  onClear?.();
18
18
  }
19
- return (_jsxs("div", { className: tw('relative', componentClassNames?.root, isDisabled ? 'pointer-events-none opacity-30' : null), children: [_jsx("input", { name: name, type: "hidden", value: value ? value.toString() : '' }), label ? (_jsxs(Fragment, { children: [_jsx("span", { className: componentClassNames?.label, children: label }), details ? (_jsx("small", { className: componentClassNames?.details, children: details })) : null] })) : (_jsx("span", { className: componentClassNames?.placeholder, children: placeholder })), onClick ? (_jsx("button", { className: "absolute -bottom-px -left-px -right-px -top-px", disabled: isDisabled, onClick: onClick, onKeyDown: onKeyDown, tabIndex: 0, type: "button", children: _jsx(Assistive, { children: "Toggle" }) })) : null, _jsxs("div", { className: "absolute bottom-0 right-1 top-0 flex w-0 items-center justify-end", children: [isOptional && hasValue(value) ? (_jsxs("button", { className: tw('flex-none', componentClassNames?.clear), onClick: handleClear, type: "button", children: [ClearIcon ? _jsx(ClearIcon, {}) : null, _jsx(Assistive, { children: "Clear" })] })) : null, icon && !isDisabled ? (_jsx("div", { className: tw('pointer-events-none flex-none bg-red-300', componentClassNames?.icon), children: icon })) : null] })] }));
19
+ return (_jsxs("div", { className: tw('relative', componentClassNames?.root, isDisabled ? 'pointer-events-none opacity-30' : null), children: [_jsx("input", { name: name, type: "hidden", value: value ? value.toString() : '' }), label ? (_jsxs(Fragment, { children: [_jsx("span", { className: componentClassNames?.label, children: label }), details ? (_jsx("small", { className: componentClassNames?.details, children: details })) : null] })) : (_jsx("span", { className: componentClassNames?.placeholder, children: placeholder })), onClick ? (_jsx("button", { className: "absolute -bottom-px -left-px -right-px -top-px", disabled: isDisabled, onClick: onClick, onKeyDown: onKeyDown, tabIndex: 0, type: "button", children: _jsx(Assistive, { children: "Toggle" }) })) : null, _jsxs("div", { className: "absolute bottom-0 right-1 top-0 flex w-0 items-center justify-end", children: [isOptional && hasValue(value) ? (_jsxs("button", { className: tw('flex-none', componentClassNames?.clear), onClick: handleClear, type: "button", children: [ClearIcon ? _jsx(ClearIcon, {}) : null, _jsx(Assistive, { children: "Clear" })] })) : null, icon && !isDisabled ? (_jsx("div", { className: tw('pointer-events-none flex-none', componentClassNames?.icon), children: icon })) : null] })] }));
20
20
  }
21
21
  export default StaticTextInput;
@@ -7,7 +7,7 @@ export interface DropdownObject<T = string> {
7
7
  $data?: Record<string, string>;
8
8
  details?: string | null;
9
9
  isDisabled?: boolean;
10
- label: string;
10
+ label: React.ReactNode;
11
11
  value: T;
12
12
  }
13
13
  export type EditingStatus = 'CANCELLED' | 'EDITING' | 'SAVED';
@@ -10,6 +10,7 @@ export interface UIIcons {
10
10
  'filter.clear'?: IconComponent;
11
11
  'filter.panel'?: IconComponent;
12
12
  'filter.search'?: IconComponent;
13
+ 'formField.error'?: IconComponent;
13
14
  'passwordComplexity.invalid'?: IconComponent;
14
15
  'passwordComplexity.valid'?: IconComponent;
15
16
  'passwordInput.hidden'?: IconComponent;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqrzro/ui",
3
3
  "type": "module",
4
- "version": "4.0.0-alpha.44",
4
+ "version": "4.0.0-alpha.46",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "ISC",