opus-toolkit-components 1.9.1 → 1.9.3

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.
@@ -1,47 +1,47 @@
1
- export type IconComponent = (
2
- props: React.SVGProps<SVGSVGElement>,
3
- ) => JSX.Element;
4
-
5
- export type CustomComponent = (props: any) => JSX.Element;
6
-
7
- export interface InputProps
8
- extends React.InputHTMLAttributes<HTMLInputElement> {
9
- label: string;
10
- placeholder?: string;
11
- type?:
12
- | "text"
13
- | "email"
14
- | "password"
15
- | "number"
16
- | "search"
17
- | "tel"
18
- | "url"
19
- | "date"
20
- | "datetime-local"
21
- | "month"
22
- | "time"
23
- | "week"
24
- | string;
25
- tabIndex?: string | number;
26
- title?: string;
27
- name?: string;
28
- isValid?: boolean;
29
- errorMessage?: string;
30
- onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
31
- className?: string;
32
- value?: string | number;
33
- Icon?: IconComponent;
34
- iconPosition?: "left" | "right";
35
- isAnimated?: boolean;
36
- required?: boolean;
37
- hideLabel?: boolean;
38
- disabled?: boolean;
39
- shouldRenderCustomComponent?: boolean;
40
- customComponent?: CustomComponent;
41
- customComponentProps?: Record<string, any>;
42
- dataCy?: string;
43
- }
44
-
45
- export const Input: React.ForwardRefExoticComponent<
46
- InputProps & React.RefAttributes<HTMLInputElement>
47
- >;
1
+ export type IconComponent = (
2
+ props: React.SVGProps<SVGSVGElement>,
3
+ ) => JSX.Element;
4
+
5
+ export type CustomComponent = (props: any) => JSX.Element;
6
+
7
+ export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
8
+ label?: string;
9
+ placeholder?: string;
10
+ type?:
11
+ | "text"
12
+ | "email"
13
+ | "password"
14
+ | "number"
15
+ | "search"
16
+ | "tel"
17
+ | "url"
18
+ | "date"
19
+ | "datetime-local"
20
+ | "month"
21
+ | "time"
22
+ | "week"
23
+ | string;
24
+ tabIndex?: string | number;
25
+ title?: string;
26
+ name?: string;
27
+ isValid?: boolean;
28
+ errorMessage?: string;
29
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
30
+ className?: string;
31
+ outerClassName?: string;
32
+ value?: string | number;
33
+ Icon?: IconComponent;
34
+ iconPosition?: "left" | "right";
35
+ isAnimated?: boolean;
36
+ required?: boolean;
37
+ hideLabel?: boolean;
38
+ disabled?: boolean;
39
+ shouldRenderCustomComponent?: boolean;
40
+ customComponent?: CustomComponent;
41
+ customComponentProps?: Record<string, any>;
42
+ dataCy?: string;
43
+ }
44
+
45
+ export const Input: React.ForwardRefExoticComponent<
46
+ InputProps & React.RefAttributes<HTMLInputElement>
47
+ >;
package/lib/main.js CHANGED
@@ -1974,78 +1974,83 @@ __webpack_require__.r(__webpack_exports__);
1974
1974
 
1975
1975
 
1976
1976
 
1977
- /**
1978
- * Icon component type — any React component that renders an SVG.
1979
- * @typedef {(props: React.SVGProps<SVGSVGElement>) => JSX.Element} IconComponent
1977
+ /**
1978
+ * Icon component type — any React component that renders an SVG.
1979
+ * @typedef {(props: React.SVGProps<SVGSVGElement>) => JSX.Element} IconComponent
1980
1980
  */
1981
1981
 
1982
- /**
1983
- * Custom component type for supplementary UI below input.
1984
- * Must be a React component.
1985
- * @typedef {(props: any) => JSX.Element} CustomComponent
1982
+ /**
1983
+ * Custom component type for supplementary UI below input.
1984
+ * Must be a React component.
1985
+ * @typedef {(props: any) => JSX.Element} CustomComponent
1986
1986
  */
1987
1987
 
1988
- /**
1989
- * Input component props.
1990
- *
1991
- * @typedef {Object} InputProps
1992
- *
1993
- * @property {string} label
1994
- * Label displayed above the input.
1995
- *
1996
- * @property {string} [placeholder]
1997
- *
1998
- * @property {'text'|'email'|'password'|'number'|'search'|'tel'|'url'|'date'|'datetime-local'|'month'|'time'|'week'|string} [type]
1999
- * HTML input type.
2000
- *
2001
- * @property {string|number} [tabIndex]
2002
- *
2003
- * @property {string} [title]
2004
- *
2005
- * @property {string} [name]
2006
- *
2007
- * @property {boolean} [isValid]
2008
- * Whether the field is valid — shows error text if false.
2009
- *
2010
- * @property {string} [errorMessage]
2011
- *
2012
- * @property {(event: React.ChangeEvent<HTMLInputElement>) => void} [onChange]
2013
- * Change handler using your preferred full event signature.
2014
- *
2015
- * @property {string} [className]
2016
- *
2017
- * @property {string|number} [value]
2018
- *
2019
- * @property {IconComponent} [Icon]
2020
- *
2021
- * @property {'left'|'right'} [iconPosition]
2022
- * Icon placement inside the input.
2023
- *
2024
- * @property {boolean} [isAnimated]
2025
- * Enables focus animation on the icon.
2026
- *
2027
- * @property {boolean} [required]
2028
- *
2029
- * @property {boolean} [hideLabel]
2030
- * Hides the visible label while keeping the input accessible.
2031
- *
2032
- * @property {boolean} [disabled]
2033
- *
2034
- * @property {boolean} [shouldRenderCustomComponent]
2035
- *
2036
- * @property {CustomComponent} [customComponent]
2037
- *
2038
- * @property {Object<string, any>} [customComponentProps]
2039
- *
2040
- * @property {string} [dataCy]
2041
- * Override for auto-generated test selector.
1988
+ /**
1989
+ * Input component props.
1990
+ *
1991
+ * @typedef {Object} InputProps
1992
+ *
1993
+ * @property {string} [label]
1994
+ * Label displayed above the input.
1995
+ *
1996
+ * @property {string} [placeholder]
1997
+ *
1998
+ * @property {'text'|'email'|'password'|'number'|'search'|'tel'|'url'|'date'|'datetime-local'|'month'|'time'|'week'|string} [type]
1999
+ * HTML input type.
2000
+ *
2001
+ * @property {string|number} [tabIndex]
2002
+ *
2003
+ * @property {string} [title]
2004
+ *
2005
+ * @property {string} [name]
2006
+ *
2007
+ * @property {boolean} [isValid]
2008
+ * Whether the field is valid — shows error text if false.
2009
+ *
2010
+ * @property {string} [errorMessage]
2011
+ *
2012
+ * @property {(event: React.ChangeEvent<HTMLInputElement>) => void} [onChange]
2013
+ * Change handler using your preferred full event signature.
2014
+ *
2015
+ * @property {string} [className]
2016
+ * Extra class names applied to the input wrapper.
2017
+ *
2018
+ * @property {string} [outerClassName]
2019
+ * Extra class names applied to the outer container.
2020
+ * Passing an mb-* class overrides the default mb-4 spacing.
2021
+ *
2022
+ * @property {string|number} [value]
2023
+ *
2024
+ * @property {IconComponent} [Icon]
2025
+ *
2026
+ * @property {'left'|'right'} [iconPosition]
2027
+ * Icon placement inside the input.
2028
+ *
2029
+ * @property {boolean} [isAnimated]
2030
+ * Enables focus animation on the icon.
2031
+ *
2032
+ * @property {boolean} [required]
2033
+ *
2034
+ * @property {boolean} [hideLabel]
2035
+ * Hides the visible label while keeping the input accessible.
2036
+ *
2037
+ * @property {boolean} [disabled]
2038
+ *
2039
+ * @property {boolean} [shouldRenderCustomComponent]
2040
+ *
2041
+ * @property {CustomComponent} [customComponent]
2042
+ *
2043
+ * @property {Object<string, any>} [customComponentProps]
2044
+ *
2045
+ * @property {string} [dataCy]
2046
+ * Override for auto-generated test selector.
2042
2047
  */
2043
2048
 
2044
- /**
2045
- * ForwardRef Input component with complete JSDoc typings.
2046
- *
2047
- * @param {InputProps & React.InputHTMLAttributes<HTMLInputElement>} props
2048
- * @param {React.Ref<HTMLInputElement>} ref
2049
+ /**
2050
+ * ForwardRef Input component with complete JSDoc typings.
2051
+ *
2052
+ * @param {InputProps & React.InputHTMLAttributes<HTMLInputElement>} props
2053
+ * @param {React.Ref<HTMLInputElement>} ref
2049
2054
  */
2050
2055
 
2051
2056
  const Input = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)((_ref, ref) => {
@@ -2057,9 +2062,10 @@ const Input = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)((_r
2057
2062
  title = "",
2058
2063
  name,
2059
2064
  isValid = true,
2060
- errorMessage = `${label} is required`,
2065
+ errorMessage,
2061
2066
  onChange,
2062
2067
  className = "",
2068
+ outerClassName = "",
2063
2069
  value,
2064
2070
  Icon,
2065
2071
  // Icon component
@@ -2081,11 +2087,15 @@ const Input = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)((_r
2081
2087
  dataCy,
2082
2088
  ...rest
2083
2089
  } = _ref;
2090
+ const hasLabel = Boolean(label);
2091
+ const resolvedErrorMessage = errorMessage || (hasLabel ? `${label} is required` : "This field is required");
2092
+ const hasCustomBottomMargin = /\b(?:[a-z]+:)*mb-/.test(outerClassName);
2093
+ const outerClasses = `${hasCustomBottomMargin ? "" : "mb-4"} flex flex-col ${outerClassName}`.trim();
2084
2094
  const inputClasses = `${className} flex items-center rounded-md bg-[--color-input-bg] border ${isValid ? "border-[--color-stroke]" : "border-utilRed1000"} text-md font-normal text-[--color-text-strong] ${disabled ? "opacity-50 cursor-not-allowed" : ""}`;
2085
2095
  const iconClasses = `h-5 w-5 ${isAnimated ? "transition-transform duration-200 group-focus-within:scale-125" : ""} text-[--color-text-weak]`;
2086
2096
  return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsxs)("div", {
2087
- className: "mb-4 flex flex-col",
2088
- children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
2097
+ className: outerClasses,
2098
+ children: [hasLabel && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsxs)(_Text_Text__WEBPACK_IMPORTED_MODULE_1__["default"], {
2089
2099
  as: "label",
2090
2100
  variant: "label",
2091
2101
  htmlFor: name,
@@ -2120,7 +2130,7 @@ const Input = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)((_r
2120
2130
  name,
2121
2131
  dataCy
2122
2132
  }),
2123
- "aria-label": hideLabel ? label : undefined,
2133
+ "aria-label": hideLabel && hasLabel ? label : undefined,
2124
2134
  "aria-invalid": !isValid,
2125
2135
  "aria-describedby": !isValid ? `${name}-error` : undefined,
2126
2136
  ...rest
@@ -2135,7 +2145,7 @@ const Input = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)((_r
2135
2145
  variant: "small",
2136
2146
  id: `${name}-error`,
2137
2147
  className: "text-[--color-util-red]",
2138
- children: errorMessage
2148
+ children: resolvedErrorMessage
2139
2149
  }), shouldRenderCustomComponent && customComponent && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(customComponent, {
2140
2150
  ...customComponentProps
2141
2151
  })]