@sqrzro/ui 4.0.0-alpha.59 → 4.0.0-alpha.60

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.
@@ -0,0 +1,16 @@
1
+ import { InputProps } from '../../../forms/interfaces';
2
+ import type { ClassNameProps, ErrorableClassName } from '../../../styles/classnames/interfaces';
3
+ export interface ColorInputClassNames {
4
+ root: ErrorableClassName;
5
+ input: string;
6
+ icon: string;
7
+ label: string;
8
+ placeholder: string;
9
+ clear: string;
10
+ }
11
+ export interface ColorInputComponentProps {
12
+ placeholder?: string;
13
+ }
14
+ export type ColorInputProps = ClassNameProps<ColorInputClassNames> & InputProps<string | undefined, string> & ColorInputComponentProps;
15
+ declare function ColorInput({ classNames, classNameProps, hasError, name, onChange, placeholder, value, }: Readonly<ColorInputProps>): React.ReactElement;
16
+ export default ColorInput;
@@ -0,0 +1,13 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import Assistive from '../../../components/utility/Assistive';
4
+ import { useClassNames } from '../../../styles/context';
5
+ import tw from '../../../styles/classnames/utility/tw';
6
+ function ColorInput({ classNames, classNameProps, hasError, name, onChange, placeholder, value, }) {
7
+ const componentClassNames = useClassNames('colorInput', { props: classNameProps, states: { isError: hasError ?? false } }, classNames);
8
+ function handleClear() {
9
+ onChange?.({ target: { name, value: '' } });
10
+ }
11
+ return (_jsxs("div", { className: tw('relative', componentClassNames?.root), children: [_jsx("input", { className: tw('absolute inset-0 h-full w-full cursor-pointer opacity-0', componentClassNames?.input), name: name, onChange: onChange, type: "color", value: value || '' }), _jsx("i", { className: tw(componentClassNames?.icon), style: { backgroundColor: value || 'transparent' } }), value ? (_jsx("span", { className: tw(componentClassNames?.label), children: value.toUpperCase() })) : (_jsx("span", { className: tw(componentClassNames?.placeholder), children: placeholder || 'Select...' })), _jsx("span", { className: "absolute bottom-0 right-0 top-0 flex w-0 items-center justify-end", children: value ? (_jsx("button", { className: tw('flex-none', componentClassNames?.clear), onClick: handleClear, type: "button", children: _jsx(Assistive, { children: "Clear" }) })) : null })] }));
12
+ }
13
+ export default ColorInput;
@@ -1,7 +1,10 @@
1
1
  import type { EditableFormFieldComponentProps } from '../../interfaces';
2
+ import type { ColorInputComponentProps } from '../ColorInput';
2
3
  import type { DropdownComponentProps } from '../Dropdown';
3
4
  import type { TextAreaComponentProps } from '../TextArea';
4
5
  import type { TextInputComponentProps } from '../TextInput';
6
+ export type EditableColorFormFieldProps = EditableFormFieldComponentProps<string | undefined> & ColorInputComponentProps;
7
+ export declare function EditableColorFormField(props: Readonly<EditableColorFormFieldProps>): React.ReactElement;
5
8
  export type EditableDropdownFormFieldProps<T> = EditableFormFieldComponentProps<T | null> & DropdownComponentProps<T>;
6
9
  export declare function EditableDropdownFormField<T>(props: Readonly<EditableDropdownFormFieldProps<T>>): React.ReactElement;
7
10
  export type EditableTextAreaFormFieldProps = EditableFormFieldComponentProps<string> & TextAreaComponentProps;
@@ -1,10 +1,25 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback } from 'react';
3
+ import { useClassNames } from '../../../styles/context';
4
+ import tw from '../../../styles/classnames/utility/tw';
3
5
  import extractEditableInputProps from '../../utility/extract-editable-input-props';
6
+ import ColorInput from '../ColorInput';
4
7
  import Dropdown from '../Dropdown';
5
8
  import EditableFormField from '../EditableFormField';
6
9
  import TextArea from '../TextArea';
7
10
  import TextInput from '../TextInput';
11
+ export function EditableColorFormField(props) {
12
+ const classNames = useClassNames('colorInput');
13
+ const { fieldProps, inputProps } = extractEditableInputProps(props);
14
+ const renderInput = useCallback((renderProps) => (_jsx(ColorInput, { ...renderProps, ...inputProps })), [inputProps]);
15
+ const renderValue = useCallback((value) => {
16
+ if (!value) {
17
+ return '-';
18
+ }
19
+ return (_jsxs("div", { className: "relative flex items-center gap-2", children: [_jsx("span", { className: tw(classNames?.icon), style: { backgroundColor: value || 'transparent' } }), _jsx("span", { className: tw(classNames?.label), children: value.toUpperCase() })] }));
20
+ }, [fieldProps.value]);
21
+ return _jsx(EditableFormField, { ...fieldProps, render: renderInput, renderValue: renderValue });
22
+ }
8
23
  export function EditableDropdownFormField(props) {
9
24
  const { fieldProps, inputProps } = extractEditableInputProps(props);
10
25
  const renderInput = useCallback((renderProps) => (_jsx(Dropdown, { ...renderProps, ...inputProps })), [inputProps]);
@@ -1,5 +1,6 @@
1
1
  import type { FormFieldComponentProps } from '../../interfaces';
2
2
  import type { AutocompleteComponentProps } from '../Autocomplete';
3
+ import type { ColorInputComponentProps } from '../ColorInput';
3
4
  import type { CalendarInputComponentProps } from '../CalendarInput';
4
5
  import type { DropdownComponentProps } from '../Dropdown';
5
6
  import type { PointsInputComponentProps } from '../PointsInput';
@@ -13,6 +14,8 @@ export type AutocompleteFormFieldProps<T> = FormFieldComponentProps<T | null> &
13
14
  export declare function AutocompleteFormField<T>(props: Readonly<AutocompleteFormFieldProps<T>>): React.ReactElement;
14
15
  export type CalendarFormFieldProps = FormFieldComponentProps<Date | null> & CalendarInputComponentProps;
15
16
  export declare function CalendarFormField(props: Readonly<CalendarFormFieldProps>): React.ReactElement;
17
+ export type ColorFormFieldProps = FormFieldComponentProps<string> & ColorInputComponentProps;
18
+ export declare function ColorFormField(props: Readonly<ColorFormFieldProps>): React.ReactElement;
16
19
  export type CSVFormFieldProps = FormFieldComponentProps<string>;
17
20
  export declare function CSVFormField(props: Readonly<CSVFormFieldProps>): React.ReactElement;
18
21
  export type DropdownFormFieldProps<T> = FormFieldComponentProps<T | null> & DropdownComponentProps<T>;
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useCallback } from 'react';
3
3
  import extractInputProps from '../../utility/extract-input-props';
4
4
  import Autocomplete from '../Autocomplete';
5
+ import ColorInput from '../ColorInput';
5
6
  import CSVInput from '../CSVInput';
6
7
  import CalendarInput from '../CalendarInput';
7
8
  import Dropdown from '../Dropdown';
@@ -23,6 +24,11 @@ export function CalendarFormField(props) {
23
24
  const renderInput = useCallback((renderProps) => (_jsx(CalendarInput, { ...renderProps, ...inputProps })), [inputProps]);
24
25
  return _jsx(FormField, { ...fieldProps, render: renderInput });
25
26
  }
27
+ export function ColorFormField(props) {
28
+ const { fieldProps, inputProps } = extractInputProps(props);
29
+ const renderInput = useCallback((renderProps) => (_jsx(ColorInput, { ...renderProps, ...inputProps })), [inputProps]);
30
+ return _jsx(FormField, { ...fieldProps, render: renderInput });
31
+ }
26
32
  export function CSVFormField(props) {
27
33
  const { fieldProps, inputProps } = extractInputProps(props);
28
34
  const renderInput = useCallback((renderProps) => (_jsx(CSVInput, { ...renderProps, ...inputProps })), [inputProps]);
@@ -27,6 +27,7 @@ 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 { ColorInputClassNames } from '../../forms/components/ColorInput';
30
31
  import type { CSVInputClassNames } from '../../forms/components/CSVInput';
31
32
  import type { DropdownClassNames } from '../../forms/components/Dropdown';
32
33
  import type { EditableFormClassNames } from '../../forms/components/EditableForm';
@@ -49,6 +50,7 @@ export interface UIClassNames {
49
50
  badge?: ComponentClassNames<BadgeClassNames>;
50
51
  button?: ComponentClassNames<ButtonClassNames>;
51
52
  calendar?: ComponentClassNames<CalendarClassNames>;
53
+ colorInput?: ComponentClassNames<ColorInputClassNames>;
52
54
  container?: ComponentClassNames<ContainerClassNames>;
53
55
  csvInput?: ComponentClassNames<CSVInputClassNames>;
54
56
  dataTable?: ComponentClassNames<DataTableClassNames>;
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.59",
4
+ "version": "4.0.0-alpha.60",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "ISC",