@laser-ui/components 1.1.1 → 1.2.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
4
 
5
+ # [1.2.0](https://github.com/laser-ui/laser-ui/compare/v1.1.1...v1.2.0) (2024-09-12)
6
+
7
+ ### Features
8
+
9
+ - **components:** form support `labelWrap` ([ffeb41a](https://github.com/laser-ui/laser-ui/commit/ffeb41afb4531e33b53343f245190dfa34872188))
10
+
11
+ ### Performance Improvements
12
+
13
+ - **components:** optimize `Validators.required` ([39f452c](https://github.com/laser-ui/laser-ui/commit/39f452ce964b28fe3271c0016290a8a7667cdcf0))
14
+
5
15
  ## [1.1.1](https://github.com/laser-ui/laser-ui/compare/v1.1.0...v1.1.1) (2024-08-30)
6
16
 
7
17
  ### Bug Fixes
package/form/Form.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { __rest } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { isUndefined } from 'lodash';
3
4
  import { useEffect, useRef } from 'react';
4
5
  import { FormItem } from './FormItem';
5
6
  import { CLASSES, FormContext } from './vars';
@@ -7,7 +8,7 @@ import { ConfigProvider } from '../config-provider';
7
8
  import { useComponentProps, useScopedProps, useStyled } from '../hooks';
8
9
  import { mergeCS } from '../utils';
9
10
  export const Form = (props) => {
10
- const _a = useComponentProps('Form', props), { children, styleOverrides, styleProvider, vertical = false, labelWidth, labelColon, requiredType = 'required', feedbackIcon = false, size: sizeProp } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "vertical", "labelWidth", "labelColon", "requiredType", "feedbackIcon", "size"]);
11
+ const _a = useComponentProps('Form', props), { children, styleOverrides, styleProvider, vertical = false, labelWidth, labelWrap = false, labelColon, requiredType = 'required', feedbackIcon = false, size: sizeProp } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "vertical", "labelWidth", "labelWrap", "labelColon", "requiredType", "feedbackIcon", "size"]);
11
12
  const styled = useStyled(CLASSES, { form: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.form }, styleOverrides);
12
13
  const formRef = useRef(null);
13
14
  const { size } = useScopedProps({ size: sizeProp });
@@ -35,6 +36,7 @@ export const Form = (props) => {
35
36
  }, children: _jsx(ConfigProvider, { context: { componentSize: size }, children: _jsx(FormContext.Provider, { value: {
36
37
  vertical,
37
38
  labelWidth: labelWidth !== null && labelWidth !== void 0 ? labelWidth : (vertical ? undefined : 'auto'),
39
+ labelWrap: isUndefined(labelWidth) ? false : labelWrap,
38
40
  labelColon: labelColon !== null && labelColon !== void 0 ? labelColon : !vertical,
39
41
  requiredType,
40
42
  feedbackIcon,
package/form/FormItem.js CHANGED
@@ -4,7 +4,7 @@ import CancelFilled from '@material-design-icons/svg/filled/cancel.svg?react';
4
4
  import CheckCircleFilled from '@material-design-icons/svg/filled/check_circle.svg?react';
5
5
  import ErrorFilled from '@material-design-icons/svg/filled/error.svg?react';
6
6
  import HelpOutlineOutlined from '@material-design-icons/svg/outlined/help_outline.svg?react';
7
- import { isBoolean, isFunction, isNull, isNumber, isString } from 'lodash';
7
+ import { isBoolean, isFunction, isNull, isNumber, isString, isUndefined } from 'lodash';
8
8
  import { useContext, useId, useRef } from 'react';
9
9
  import { FormError } from './internal/FormError';
10
10
  import { Validators } from './model/validators';
@@ -22,7 +22,7 @@ const ValidateState = {
22
22
  Pending: 4,
23
23
  };
24
24
  export function FormItem(props) {
25
- const _a = useComponentProps('FormItem', props), { children, styleOverrides, styleProvider, formControls, label, labelWidth: labelWidthProp, labelExtra: labelExtraProp, labelFor, required: requiredProp } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "formControls", "label", "labelWidth", "labelExtra", "labelFor", "required"]);
25
+ const _a = useComponentProps('FormItem', props), { children, styleOverrides, styleProvider, formControls, label, labelWidth: labelWidthProp, labelWrap: labelWrapProp, labelExtra: labelExtraProp, labelFor, required: requiredProp } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "formControls", "label", "labelWidth", "labelWrap", "labelExtra", "labelFor", "required"]);
26
26
  const styled = useStyled(CLASSES, { form: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.form }, styleOverrides);
27
27
  const { t } = useTranslation();
28
28
  const formContext = useContext(FormContext);
@@ -31,6 +31,7 @@ export function FormItem(props) {
31
31
  const uniqueId = useId();
32
32
  const getErrorId = (controlName) => `${controlName}-error-${uniqueId}`;
33
33
  const labelWidth = labelWidthProp !== null && labelWidthProp !== void 0 ? labelWidthProp : formContext.labelWidth;
34
+ const labelWrap = isUndefined(labelWidth) ? false : (labelWrapProp !== null && labelWrapProp !== void 0 ? labelWrapProp : formContext.labelWrap);
34
35
  const formControlProviders = (() => {
35
36
  const obj = {};
36
37
  Object.keys(formControls !== null && formControls !== void 0 ? formControls : {}).forEach((controlName) => {
@@ -149,9 +150,9 @@ export function FormItem(props) {
149
150
  className: restProps.className,
150
151
  style: restProps.style,
151
152
  }), { ref: divRef, children: _jsxs("div", Object.assign({}, styled('form__item-container'), { children: [labelWidth !== 0 && (_jsx("div", Object.assign({}, mergeCS(styled('form__item-label-wrapper'), {
152
- style: { width: formContext.vertical ? '100%' : labelWidth === 'auto' ? 'var(--label-width)' : labelWidth },
153
+ style: { width: formContext.vertical ? undefined : labelWidth === 'auto' ? 'var(--label-width)' : labelWidth },
153
154
  }), { children: label && (_jsxs("label", Object.assign({}, styled('form__item-label', {
154
- 'form__item-label--auto': !formContext.vertical && labelWidth === 'auto',
155
+ 'form__item-label--wrap': labelWrap,
155
156
  'form__item-label--required': formContext.requiredType === 'required' && required,
156
157
  'form__item-label--colon': formContext.labelColon,
157
158
  }), { htmlFor: labelFor, "data-l-form-label": true, children: [label, (labelExtra || (formContext.requiredType === 'optional' && !required)) && (_jsxs("div", Object.assign({}, styled('form__item-label-extra'), { children: [formContext.requiredType === 'optional' && !required && _jsx("span", { children: t('Form', 'Optional') }), labelExtra] })))] }))) }))), _jsxs("div", Object.assign({}, mergeCS(styled('form__item-content'), {
@@ -1,4 +1,4 @@
1
- import { isArray, isNull, isNumber, isString } from 'lodash';
1
+ import { isArray, isNumber, isString } from 'lodash';
2
2
  export class Validators {
3
3
  static min(min) {
4
4
  return (control) => {
@@ -29,7 +29,7 @@ export class Validators {
29
29
  };
30
30
  }
31
31
  static required(control) {
32
- const isEmpty = isArray(control.value) || isString(control.value) ? control.value.length === 0 : isNull(control.value) ? true : false;
32
+ const isEmpty = control.value == null || ((isArray(control.value) || isString(control.value)) && control.value.length === 0);
33
33
  return isEmpty ? { required: true } : null;
34
34
  }
35
35
  static email(control) {
package/form/types.d.ts CHANGED
@@ -23,6 +23,7 @@ export interface FormControlProvider {
23
23
  export interface FormContextData {
24
24
  vertical: boolean;
25
25
  labelWidth: number | string | undefined;
26
+ labelWrap: boolean;
26
27
  labelColon: boolean;
27
28
  requiredType: 'required' | 'optional' | 'hidden';
28
29
  feedbackIcon: boolean | {
@@ -35,6 +36,7 @@ export interface FormContextData {
35
36
  export interface FormProps extends BaseProps<'form', typeof CLASSES>, React.FormHTMLAttributes<HTMLFormElement> {
36
37
  vertical?: boolean;
37
38
  labelWidth?: number | string;
39
+ labelWrap?: boolean;
38
40
  labelColon?: boolean;
39
41
  requiredType?: 'required' | 'optional' | 'hidden';
40
42
  feedbackIcon?: boolean | {
@@ -54,6 +56,7 @@ export interface FormItemProps<T extends {
54
56
  formControls?: T;
55
57
  label?: React.ReactNode;
56
58
  labelWidth?: number | string;
59
+ labelWrap?: boolean;
57
60
  labelExtra?: {
58
61
  title: string;
59
62
  icon?: React.ReactElement;
package/form/vars.d.ts CHANGED
@@ -11,7 +11,7 @@ export declare const CLASSES: {
11
11
  'form__item-container': string;
12
12
  'form__item-label-wrapper': string;
13
13
  'form__item-label': string;
14
- 'form__item-label--auto': string;
14
+ 'form__item-label--wrap': string;
15
15
  'form__item-label--required': string;
16
16
  'form__item-label--colon': string;
17
17
  'form__item-label-extra': string;
package/form/vars.js CHANGED
@@ -9,7 +9,7 @@ export const CLASSES = {
9
9
  'form__item-container': '^form__item-container',
10
10
  'form__item-label-wrapper': '^form__item-label-wrapper',
11
11
  'form__item-label': '^form__item-label',
12
- 'form__item-label--auto': '^form__item-label--auto',
12
+ 'form__item-label--wrap': '^form__item-label--wrap',
13
13
  'form__item-label--required': '^form__item-label--required',
14
14
  'form__item-label--colon': '^form__item-label--colon',
15
15
  'form__item-label-extra': '^form__item-label-extra',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laser-ui/components",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "React components.",
5
5
  "keywords": [
6
6
  "ui",
@@ -40,5 +40,5 @@
40
40
  "access": "public",
41
41
  "directory": "../../dist/libs/components"
42
42
  },
43
- "gitHead": "5d76520ca057de8e9b23faa06ad88d5e7429d64d"
43
+ "gitHead": "b972aaf248e60ba8e9c9d5e09e07ab46116f4ad8"
44
44
  }