@sqrzro/ui 4.0.0-alpha.74 → 4.0.0-alpha.75
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.
- package/dist/forms/components/CheckboxInput/index.d.ts +12 -0
- package/dist/forms/components/CheckboxInput/index.js +15 -0
- package/dist/forms/components/ChkRad/index.d.ts +18 -0
- package/dist/forms/components/ChkRad/index.js +22 -0
- package/dist/forms/components/EditableForm/index.d.ts +2 -1
- package/dist/forms/components/EditableForm/index.js +1 -1
- package/dist/forms/components/EditableFormFields/index.d.ts +3 -0
- package/dist/forms/components/EditableFormFields/index.js +15 -0
- package/dist/forms/components/Form/index.d.ts +1 -0
- package/dist/forms/components/Form/index.js +1 -1
- package/dist/forms/components/FormFields/index.d.ts +3 -0
- package/dist/forms/components/FormFields/index.js +6 -0
- package/dist/forms/hooks/useEditableForm.js +7 -6
- package/dist/forms/hooks/useForm.js +1 -0
- package/dist/styles/classnames/config.d.ts +4 -0
- package/dist/styles/icons/config.d.ts +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DropdownObject, InputProps } from '../../../forms/interfaces';
|
|
2
|
+
import type { ClassNameProps, ErrorableClassName } from '../../../styles/classnames/interfaces';
|
|
3
|
+
export interface CheckboxInputClassNames {
|
|
4
|
+
root: ErrorableClassName;
|
|
5
|
+
item: ErrorableClassName;
|
|
6
|
+
}
|
|
7
|
+
export interface CheckboxInputComponentProps<T> {
|
|
8
|
+
options?: DropdownObject<T>[];
|
|
9
|
+
}
|
|
10
|
+
export type CheckboxInputProps<T> = ClassNameProps<CheckboxInputClassNames> & InputProps<T[]> & CheckboxInputComponentProps<T>;
|
|
11
|
+
declare function CheckboxInput<T>({ classNames, classNameProps, hasError, name, onChange, options, value, }: CheckboxInputProps<T>): React.ReactElement;
|
|
12
|
+
export default CheckboxInput;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { toggleArrayItem } from '@sqrzro/utility';
|
|
4
|
+
import { useClassNames } from '../../../styles/context';
|
|
5
|
+
import ChkRad from '../ChkRad';
|
|
6
|
+
function CheckboxInput({ classNames, classNameProps, hasError, name, onChange, options = [], value, }) {
|
|
7
|
+
const componentClassNames = useClassNames('checkboxInput', { props: classNameProps, states: { isError: hasError ?? false } }, classNames);
|
|
8
|
+
function handleChange(id) {
|
|
9
|
+
return () => {
|
|
10
|
+
onChange?.({ target: { name, value: toggleArrayItem(value || [], id) } });
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return (_jsx("ul", { className: componentClassNames?.root, role: "listbox", children: options.map((item) => (_jsx("li", { children: _jsx(ChkRad, { classNameProps: classNameProps, label: item.label, name: `${name}[]`, onChange: handleChange(item.value), value: value?.includes(item.value) ?? false }) }, String(item.value)))) }));
|
|
14
|
+
}
|
|
15
|
+
export default CheckboxInput;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InputProps } from '../../../forms/interfaces';
|
|
2
|
+
import { CheckableClassName, ClassNameProps } from '../../../styles/classnames/interfaces';
|
|
3
|
+
export interface ChkRadClassNames {
|
|
4
|
+
details: string;
|
|
5
|
+
icon: CheckableClassName;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ChkRadProps extends ClassNameProps<ChkRadClassNames>, InputProps<boolean> {
|
|
9
|
+
details?: React.ReactNode;
|
|
10
|
+
label: React.ReactNode;
|
|
11
|
+
type?: 'checkbox' | 'radio';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Either a checkbox or a radio button. The onChange event will return a string of the value of
|
|
15
|
+
* the checked item.
|
|
16
|
+
*/
|
|
17
|
+
declare function ChkRad({ classNames, classNameProps, details, id, isDisabled, name, label, onChange, type, value, }: Readonly<ChkRadProps>): React.ReactElement;
|
|
18
|
+
export default ChkRad;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
import { useClassNames, useIcon } from '../../../styles/context';
|
|
5
|
+
import tw from '../../../styles/classnames/utility/tw';
|
|
6
|
+
import Assistive from '../../../components/utility/Assistive';
|
|
7
|
+
/**
|
|
8
|
+
* Either a checkbox or a radio button. The onChange event will return a string of the value of
|
|
9
|
+
* the checked item.
|
|
10
|
+
*/
|
|
11
|
+
function ChkRad({ classNames, classNameProps, details, id, isDisabled, name, label, onChange, type = 'checkbox', value, }) {
|
|
12
|
+
const componentClassNames = useClassNames('chkrad', { props: classNameProps, states: { isChecked: value ?? false } }, classNames);
|
|
13
|
+
const CheckedIcon = useIcon('chkrad.checked');
|
|
14
|
+
const ref = useRef(null);
|
|
15
|
+
function handleChange(event) {
|
|
16
|
+
if (onChange) {
|
|
17
|
+
onChange({ target: { name, value: event.target.checked } });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return (_jsxs("label", { className: tw('flex cursor-pointer', isDisabled ? 'pointer-events-none opacity-30' : null), "data-testid": "chkrad-root", children: [_jsx(Assistive, { children: _jsx("input", { checked: Boolean(value), disabled: isDisabled, id: id || name, name: name, onChange: handleChange, type: type }) }), _jsx("span", { className: componentClassNames?.icon, children: CheckedIcon && value ? _jsx(CheckedIcon, {}) : null }), _jsxs("div", { ref: ref, className: tw(componentClassNames?.label), children: [label, details ? _jsx("div", { className: tw(componentClassNames?.details), children: details }) : null] })] }));
|
|
21
|
+
}
|
|
22
|
+
export default ChkRad;
|
|
@@ -3,8 +3,9 @@ import type { SimpleActionObject } from '../../../utility/interfaces';
|
|
|
3
3
|
import type { EditingStatus } from '../../interfaces';
|
|
4
4
|
import type { FormProps } from '../Form';
|
|
5
5
|
export interface EditableFormClassNames {
|
|
6
|
-
actions: string;
|
|
7
6
|
root: string;
|
|
7
|
+
errors: string;
|
|
8
|
+
actions: string;
|
|
8
9
|
header: string;
|
|
9
10
|
title: string;
|
|
10
11
|
description: string;
|
|
@@ -13,7 +13,7 @@ function EditableForm({ classNameProps, classNames, children, formProps, onCance
|
|
|
13
13
|
onEdit?.();
|
|
14
14
|
setStatus?.('EDITING');
|
|
15
15
|
}
|
|
16
|
-
return (_jsxs(Form, { ...formProps, classNames: { root: componentClassNames?.root }, children: [title ? (_jsx("header", { className: componentClassNames?.header, children: _jsx("legend", { className: componentClassNames?.title, children: title }) })) : null, _jsxs("div", { className: componentClassNames?.content, children: [children, _jsx("footer", { className: componentClassNames?.actions, children: _jsx(ActionList, { actions: status === 'EDITING'
|
|
16
|
+
return (_jsxs(Form, { ...formProps, classNames: { root: componentClassNames?.root, errors: componentClassNames?.errors }, children: [title ? (_jsx("header", { className: componentClassNames?.header, children: _jsx("legend", { className: componentClassNames?.title, children: title }) })) : null, _jsxs("div", { className: componentClassNames?.content, children: [children, _jsx("footer", { className: componentClassNames?.actions, children: _jsx(ActionList, { actions: status === 'EDITING'
|
|
17
17
|
? [
|
|
18
18
|
{ label: 'Cancel', onClick: setCancelled },
|
|
19
19
|
{ isSubmittable: true, label: 'Save' },
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { EditableFormFieldComponentProps } from '../../interfaces';
|
|
2
|
+
import type { CheckboxInputComponentProps } from '../CheckboxInput';
|
|
2
3
|
import type { ColorInputComponentProps } from '../ColorInput';
|
|
3
4
|
import type { DropdownComponentProps } from '../Dropdown';
|
|
4
5
|
import type { ImageInputComponentProps } from '../ImageInput';
|
|
5
6
|
import type { SwitchComponentProps } from '../Switch';
|
|
6
7
|
import type { TextAreaComponentProps } from '../TextArea';
|
|
7
8
|
import type { TextInputComponentProps } from '../TextInput';
|
|
9
|
+
export type EditableCheckboxFormFieldProps<T> = EditableFormFieldComponentProps<T[]> & CheckboxInputComponentProps<T>;
|
|
10
|
+
export declare function EditableCheckboxFormField<T>(props: Readonly<EditableCheckboxFormFieldProps<T>>): React.ReactElement;
|
|
8
11
|
export type EditableColorFormFieldProps = EditableFormFieldComponentProps<string | undefined> & ColorInputComponentProps;
|
|
9
12
|
export declare function EditableColorFormField(props: Readonly<EditableColorFormFieldProps>): React.ReactElement;
|
|
10
13
|
export type EditableDropdownFormFieldProps<T> = EditableFormFieldComponentProps<T | null> & DropdownComponentProps<T>;
|
|
@@ -3,6 +3,7 @@ import { useCallback } from 'react';
|
|
|
3
3
|
import { useClassNames } from '../../../styles/context';
|
|
4
4
|
import tw from '../../../styles/classnames/utility/tw';
|
|
5
5
|
import extractEditableInputProps from '../../utility/extract-editable-input-props';
|
|
6
|
+
import CheckboxInput from '../CheckboxInput';
|
|
6
7
|
import ColorInput from '../ColorInput';
|
|
7
8
|
import Dropdown from '../Dropdown';
|
|
8
9
|
import EditableFormField from '../EditableFormField';
|
|
@@ -10,6 +11,20 @@ import ImageInput from '../ImageInput';
|
|
|
10
11
|
import Switch from '../Switch';
|
|
11
12
|
import TextArea from '../TextArea';
|
|
12
13
|
import TextInput from '../TextInput';
|
|
14
|
+
export function EditableCheckboxFormField(props) {
|
|
15
|
+
const classNames = useClassNames('checkboxInput');
|
|
16
|
+
const { fieldProps, inputProps } = extractEditableInputProps(props);
|
|
17
|
+
const renderInput = useCallback((renderProps) => (_jsx(CheckboxInput, { ...renderProps, ...inputProps })), [inputProps]);
|
|
18
|
+
const renderValue = useCallback((value) => {
|
|
19
|
+
if (!value) {
|
|
20
|
+
return '-';
|
|
21
|
+
}
|
|
22
|
+
return (_jsx("ul", { className: classNames?.root, role: "listbox", children: props.options
|
|
23
|
+
?.filter((option) => value.includes(option.value))
|
|
24
|
+
.map((option) => (_jsx("li", { className: classNames?.item, children: option.label }, String(option.value)))) }));
|
|
25
|
+
}, [fieldProps.value]);
|
|
26
|
+
return _jsx(EditableFormField, { ...fieldProps, render: renderInput, renderValue: renderValue });
|
|
27
|
+
}
|
|
13
28
|
export function EditableColorFormField(props) {
|
|
14
29
|
const classNames = useClassNames('colorInput');
|
|
15
30
|
const { fieldProps, inputProps } = extractEditableInputProps(props);
|
|
@@ -5,6 +5,6 @@ import tw from '../../../styles/classnames/utility/tw';
|
|
|
5
5
|
import { InfoPanel } from '../../../components';
|
|
6
6
|
function Form({ action, children, classNames, classNameProps, id, onSubmit, uncaughtErrors, ref, }) {
|
|
7
7
|
const componentClassNames = useClassNames('form', { props: classNameProps }, classNames);
|
|
8
|
-
return (_jsxs("form", { ref: ref, action: action, className: tw(componentClassNames?.root), id: id, onSubmit: onSubmit, children: [uncaughtErrors && Object.keys(uncaughtErrors).length ? (_jsx(InfoPanel, { variant: "error", children: Object.values(uncaughtErrors).map((item, index) => (_jsx("p", { children: item }, index))) })) : null, children] }));
|
|
8
|
+
return (_jsxs("form", { ref: ref, action: action, className: tw(componentClassNames?.root), id: id, onSubmit: onSubmit, children: [uncaughtErrors && Object.keys(uncaughtErrors).length ? (_jsx("div", { className: tw(componentClassNames?.errors), children: _jsx(InfoPanel, { variant: "error", children: Object.values(uncaughtErrors).map((item, index) => (_jsx("p", { children: item }, index))) }) })) : null, children] }));
|
|
9
9
|
}
|
|
10
10
|
export default Form;
|
|
@@ -2,6 +2,7 @@ import type { FormFieldComponentProps } from '../../interfaces';
|
|
|
2
2
|
import type { AutocompleteComponentProps } from '../Autocomplete';
|
|
3
3
|
import type { ColorInputComponentProps } from '../ColorInput';
|
|
4
4
|
import type { CalendarInputComponentProps } from '../CalendarInput';
|
|
5
|
+
import type { CheckboxInputComponentProps } from '../CheckboxInput';
|
|
5
6
|
import type { DropdownComponentProps } from '../Dropdown';
|
|
6
7
|
import type { ImageInputComponentProps } from '../ImageInput';
|
|
7
8
|
import type { PointsInputComponentProps } from '../PointsInput';
|
|
@@ -15,6 +16,8 @@ export type AutocompleteFormFieldProps<T> = FormFieldComponentProps<T | null> &
|
|
|
15
16
|
export declare function AutocompleteFormField<T>(props: Readonly<AutocompleteFormFieldProps<T>>): React.ReactElement;
|
|
16
17
|
export type CalendarFormFieldProps = FormFieldComponentProps<Date | null> & CalendarInputComponentProps;
|
|
17
18
|
export declare function CalendarFormField(props: Readonly<CalendarFormFieldProps>): React.ReactElement;
|
|
19
|
+
export type CheckboxFormFieldProps<T> = FormFieldComponentProps<T[]> & CheckboxInputComponentProps<T>;
|
|
20
|
+
export declare function CheckboxFormField<T>(props: Readonly<CheckboxFormFieldProps<T>>): React.ReactElement;
|
|
18
21
|
export type ColorFormFieldProps = FormFieldComponentProps<string> & ColorInputComponentProps;
|
|
19
22
|
export declare function ColorFormField(props: Readonly<ColorFormFieldProps>): React.ReactElement;
|
|
20
23
|
export type CSVFormFieldProps = FormFieldComponentProps<string>;
|
|
@@ -5,6 +5,7 @@ import Autocomplete from '../Autocomplete';
|
|
|
5
5
|
import ColorInput from '../ColorInput';
|
|
6
6
|
import CSVInput from '../CSVInput';
|
|
7
7
|
import CalendarInput from '../CalendarInput';
|
|
8
|
+
import CheckboxInput from '../CheckboxInput';
|
|
8
9
|
import Dropdown from '../Dropdown';
|
|
9
10
|
import FormField from '../FormField';
|
|
10
11
|
import ImageInput from '../ImageInput';
|
|
@@ -25,6 +26,11 @@ export function CalendarFormField(props) {
|
|
|
25
26
|
const renderInput = useCallback((renderProps) => (_jsx(CalendarInput, { ...renderProps, ...inputProps })), [inputProps]);
|
|
26
27
|
return _jsx(FormField, { ...fieldProps, render: renderInput });
|
|
27
28
|
}
|
|
29
|
+
export function CheckboxFormField(props) {
|
|
30
|
+
const { fieldProps, inputProps } = extractInputProps(props);
|
|
31
|
+
const renderInput = useCallback((renderProps) => (_jsx(CheckboxInput, { ...renderProps, ...inputProps })), [inputProps]);
|
|
32
|
+
return _jsx(FormField, { ...fieldProps, render: renderInput });
|
|
33
|
+
}
|
|
28
34
|
export function ColorFormField(props) {
|
|
29
35
|
const { fieldProps, inputProps } = extractInputProps(props);
|
|
30
36
|
const renderInput = useCallback((renderProps) => (_jsx(ColorInput, { ...renderProps, ...inputProps })), [inputProps]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState } from 'react';
|
|
2
2
|
import useForm from './useForm';
|
|
3
3
|
function useEditableForm({ defaultStatus, onCancel, onEdit, onSuccess, title, ...args }) {
|
|
4
4
|
const [status, setStatus] = useState(defaultStatus ?? null);
|
|
@@ -17,18 +17,19 @@ function useEditableForm({ defaultStatus, onCancel, onEdit, onSuccess, title, ..
|
|
|
17
17
|
const fieldProps = useFormReturn.fieldProps(name, label);
|
|
18
18
|
return { ...fieldProps, status };
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
|
|
20
|
+
function handleCancel() {
|
|
21
|
+
if (onCancel) {
|
|
22
|
+
onCancel();
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
useFormReturn.resetForm();
|
|
25
|
+
}
|
|
25
26
|
return {
|
|
26
27
|
...useFormReturn,
|
|
27
28
|
actionProps: { status, setStatus },
|
|
28
29
|
fieldProps: editableFieldProps,
|
|
29
30
|
formProps: {
|
|
30
31
|
formProps: useFormReturn.formProps,
|
|
31
|
-
onCancel,
|
|
32
|
+
onCancel: handleCancel,
|
|
32
33
|
onEdit,
|
|
33
34
|
status,
|
|
34
35
|
setStatus,
|
|
@@ -27,6 +27,8 @@ import type { FilterClearButtonClassNames } from '../../filters/components/Filte
|
|
|
27
27
|
import type { FilterItemClassNames } from '../../filters/components/FilterItem';
|
|
28
28
|
import type { FilterPanelClassNames } from '../../filters/components/FilterPanel';
|
|
29
29
|
import type { SearchFilterClassNames } from '../../filters/filters/SearchFilter';
|
|
30
|
+
import type { CheckboxInputClassNames } from '../../forms/components/CheckboxInput';
|
|
31
|
+
import type { ChkRadClassNames } from '../../forms/components/ChkRad';
|
|
30
32
|
import type { ColorInputClassNames } from '../../forms/components/ColorInput';
|
|
31
33
|
import type { CSVInputClassNames } from '../../forms/components/CSVInput';
|
|
32
34
|
import type { DropdownClassNames } from '../../forms/components/Dropdown';
|
|
@@ -51,6 +53,8 @@ export interface UIClassNames {
|
|
|
51
53
|
badge?: ComponentClassNames<BadgeClassNames>;
|
|
52
54
|
button?: ComponentClassNames<ButtonClassNames>;
|
|
53
55
|
calendar?: ComponentClassNames<CalendarClassNames>;
|
|
56
|
+
checkboxInput?: ComponentClassNames<CheckboxInputClassNames>;
|
|
57
|
+
chkrad?: ComponentClassNames<ChkRadClassNames>;
|
|
54
58
|
colorInput?: ComponentClassNames<ColorInputClassNames>;
|
|
55
59
|
container?: ComponentClassNames<ContainerClassNames>;
|
|
56
60
|
csvInput?: ComponentClassNames<CSVInputClassNames>;
|
|
@@ -3,6 +3,7 @@ export interface UIIcons {
|
|
|
3
3
|
'appNavigation.menu'?: IconComponent;
|
|
4
4
|
'calendar.previous'?: IconComponent;
|
|
5
5
|
'calendar.next'?: IconComponent;
|
|
6
|
+
'chkrad.checked'?: IconComponent;
|
|
6
7
|
'csvInput.upload'?: IconComponent;
|
|
7
8
|
'csvInput.success'?: IconComponent;
|
|
8
9
|
'collection.empty'?: 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.
|
|
4
|
+
"version": "4.0.0-alpha.75",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "ISC",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"react-dom": "^19.2.8",
|
|
58
58
|
"tailwind-merge": "^3.6.0",
|
|
59
59
|
"use-deep-compare-effect": "^1.8.1",
|
|
60
|
-
"@sqrzro/
|
|
61
|
-
"@sqrzro/
|
|
60
|
+
"@sqrzro/addons": "^4.0.0-alpha.14",
|
|
61
|
+
"@sqrzro/utility": "^4.0.0-alpha.21"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@storybook/addon-a11y": "^10.5.3",
|