@scaleflex/ui-tw 0.0.144 → 0.0.146

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,5 +1,5 @@
1
1
  import React from 'react';
2
2
  import { FieldValues, Path } from 'react-hook-form';
3
3
  import type { FormFieldGroupProps } from '../form.types';
4
- declare function FormFieldGroup<TFieldValues extends FieldValues, TName extends Path<TFieldValues>>({ control, name, label, description, size, readOnly, disabled, tooltip, disabledTooltip, highlight, horizontal, horizontalLabelWidth, children, }: FormFieldGroupProps<TFieldValues, TName>): React.JSX.Element;
4
+ declare function FormFieldGroup<TFieldValues extends FieldValues, TName extends Path<TFieldValues>>({ control, name, label, description, size, readOnly, disabled, tooltip, disabledTooltip, highlight, horizontal, horizontalLabelWidth, showCharCount, maxLength, children, }: FormFieldGroupProps<TFieldValues, TName>): React.JSX.Element;
5
5
  export { FormFieldGroup };
@@ -1,7 +1,10 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import { cn } from '@scaleflex/ui-tw/utils/cn';
2
5
  import React from 'react';
3
6
  import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '../form.component';
4
- import { labelHeightVariants } from '../form.constants';
7
+ import { formMessageSizeOptions, labelHeightVariants } from '../form.constants';
5
8
  function FormFieldGroup(_ref) {
6
9
  var control = _ref.control,
7
10
  name = _ref.name,
@@ -19,6 +22,9 @@ function FormFieldGroup(_ref) {
19
22
  _ref$horizontal = _ref.horizontal,
20
23
  horizontal = _ref$horizontal === void 0 ? false : _ref$horizontal,
21
24
  horizontalLabelWidth = _ref.horizontalLabelWidth,
25
+ _ref$showCharCount = _ref.showCharCount,
26
+ showCharCount = _ref$showCharCount === void 0 ? false : _ref$showCharCount,
27
+ maxLength = _ref.maxLength,
22
28
  children = _ref.children;
23
29
  return /*#__PURE__*/React.createElement(FormField, {
24
30
  control: control,
@@ -26,25 +32,33 @@ function FormFieldGroup(_ref) {
26
32
  disabled: disabled,
27
33
  render: function render(_ref2) {
28
34
  var field = _ref2.field;
35
+ var charCount = typeof field.value === 'string' ? field.value.length : 0;
36
+ var showLabelRow = label || showCharCount;
29
37
  return /*#__PURE__*/React.createElement(FormItem, {
30
38
  className: "group",
31
39
  horizontal: horizontal,
32
40
  firstColumnWidth: horizontalLabelWidth,
33
41
  "data-disabled": disabled,
34
42
  "data-highlight": highlight
35
- }, label && /*#__PURE__*/React.createElement(FormLabel, {
36
- className: cn(horizontal && 'self-start', horizontal && labelHeightVariants[size]),
43
+ }, showLabelRow && /*#__PURE__*/React.createElement("div", {
44
+ className: cn('flex items-center justify-between gap-2', horizontal && labelHeightVariants[size])
45
+ }, label ? /*#__PURE__*/React.createElement(FormLabel, {
46
+ className: cn(horizontal && 'self-start'),
37
47
  size: size,
38
48
  tooltip: tooltip,
39
49
  disabledTooltip: disabledTooltip,
40
50
  disabled: disabled
41
- }, label), /*#__PURE__*/React.createElement("div", {
51
+ }, label) : /*#__PURE__*/React.createElement("span", null), showCharCount && /*#__PURE__*/React.createElement("span", {
52
+ className: cn('text-muted-foreground shrink-0 tabular-nums', 'group-data-[disabled=true]:opacity-50', maxLength && charCount >= maxLength && 'text-destructive-foreground', formMessageSizeOptions[size])
53
+ }, maxLength ? "".concat(charCount, " / ").concat(maxLength) : charCount)), /*#__PURE__*/React.createElement("div", {
42
54
  className: "grid gap-1.5"
43
- }, /*#__PURE__*/React.createElement(FormControl, null, children(field, {
55
+ }, /*#__PURE__*/React.createElement(FormControl, null, children(field, _objectSpread({
44
56
  size: size,
45
57
  readOnly: readOnly,
46
58
  disabled: disabled
47
- })), description && /*#__PURE__*/React.createElement(FormDescription, {
59
+ }, maxLength !== undefined && {
60
+ maxLength: maxLength
61
+ }))), description && /*#__PURE__*/React.createElement(FormDescription, {
48
62
  size: size
49
63
  }, description), /*#__PURE__*/React.createElement(FormMessage, {
50
64
  size: size
@@ -10,7 +10,9 @@ function FormInputField(_ref) {
10
10
  return /*#__PURE__*/React.createElement(FormFieldGroup, rest, function (field, args) {
11
11
  return /*#__PURE__*/React.createElement(Input, _extends({
12
12
  placeholder: inputProps === null || inputProps === void 0 ? void 0 : inputProps.placeholder
13
- }, args, field, inputProps));
13
+ }, args, field, {
14
+ maxLength: args === null || args === void 0 ? void 0 : args.maxLength
15
+ }, inputProps));
14
16
  });
15
17
  }
16
18
  export { FormInputField };
@@ -10,7 +10,9 @@ function FormTextareaField(_ref) {
10
10
  return /*#__PURE__*/React.createElement(FormFieldGroup, rest, function (field, args) {
11
11
  return /*#__PURE__*/React.createElement(Textarea, _extends({
12
12
  placeholder: textareaProps === null || textareaProps === void 0 ? void 0 : textareaProps.placeholder
13
- }, field, args, textareaProps));
13
+ }, field, args, {
14
+ maxLength: args === null || args === void 0 ? void 0 : args.maxLength
15
+ }, textareaProps));
14
16
  });
15
17
  }
16
18
  export { FormTextareaField };
@@ -25,6 +25,7 @@ export interface FormFieldArgs {
25
25
  size?: FormSizeType;
26
26
  readOnly?: boolean;
27
27
  disabled?: boolean;
28
+ maxLength?: number;
28
29
  }
29
30
  interface FormBaseFieldProps {
30
31
  label?: ReactElement | string;
@@ -33,6 +34,8 @@ interface FormBaseFieldProps {
33
34
  disabled?: boolean;
34
35
  tooltip?: ReactElement | string;
35
36
  disabledTooltip?: ReactElement | string;
37
+ showCharCount?: boolean;
38
+ maxLength?: number;
36
39
  }
37
40
  export interface FormFieldGroupProps<TFieldValues extends FieldValues, TName extends Path<TFieldValues>> extends UseControllerProps<TFieldValues, TName>, FormBaseFieldProps {
38
41
  children: (field: ControllerRenderProps<TFieldValues, TName>, args?: FormFieldArgs) => ReactNode;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { HighlightTextProps } from './highlight-text.types';
3
+ declare function HighlightText({ text, highlight, variant, highlightClassName, className, ...props }: HighlightTextProps): React.JSX.Element;
4
+ export { HighlightText };
@@ -0,0 +1,36 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["text", "highlight", "variant", "highlightClassName", "className"];
4
+ import { cn } from '@scaleflex/ui-tw/utils/cn';
5
+ import React from 'react';
6
+ import { highlightVariants } from './highlight-text.constants';
7
+ import { escapeRegExp } from './highlight-text.utils';
8
+ function HighlightText(_ref) {
9
+ var text = _ref.text,
10
+ highlight = _ref.highlight,
11
+ variant = _ref.variant,
12
+ highlightClassName = _ref.highlightClassName,
13
+ className = _ref.className,
14
+ props = _objectWithoutProperties(_ref, _excluded);
15
+ if (!(highlight !== null && highlight !== void 0 && highlight.trim())) {
16
+ return /*#__PURE__*/React.createElement("span", _extends({
17
+ "data-slot": "highlight-text",
18
+ className: className
19
+ }, props), text);
20
+ }
21
+ var regex = new RegExp("(".concat(escapeRegExp(highlight), ")"), 'gi');
22
+ var parts = text.split(regex);
23
+ var normalizedHighlight = highlight.toLowerCase();
24
+ return /*#__PURE__*/React.createElement("span", _extends({
25
+ "data-slot": "highlight-text",
26
+ className: className
27
+ }, props), parts.map(function (part, i) {
28
+ return part.toLowerCase() === normalizedHighlight ? /*#__PURE__*/React.createElement("mark", {
29
+ key: i,
30
+ className: cn(highlightVariants({
31
+ variant: variant
32
+ }), highlightClassName)
33
+ }, part) : part;
34
+ }));
35
+ }
36
+ export { HighlightText };
@@ -0,0 +1,3 @@
1
+ export declare const highlightVariants: (props?: ({
2
+ variant?: "info" | "success" | "warning" | "primary" | "destructive" | null | undefined;
3
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
@@ -0,0 +1,15 @@
1
+ import { cva } from 'class-variance-authority';
2
+ export var highlightVariants = cva('text-inherit', {
3
+ variants: {
4
+ variant: {
5
+ primary: 'bg-primary/30',
6
+ warning: 'bg-warning/30',
7
+ success: 'bg-success/30',
8
+ info: 'bg-info/30',
9
+ destructive: 'bg-destructive/30'
10
+ }
11
+ },
12
+ defaultVariants: {
13
+ variant: 'primary'
14
+ }
15
+ });
@@ -0,0 +1,8 @@
1
+ import { VariantProps } from 'class-variance-authority';
2
+ import { HTMLAttributes } from 'react';
3
+ import { highlightVariants } from './highlight-text.constants';
4
+ export interface HighlightTextProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'>, VariantProps<typeof highlightVariants> {
5
+ text: string;
6
+ highlight: string;
7
+ highlightClassName?: string;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function escapeRegExp(string: string): string;
@@ -0,0 +1,3 @@
1
+ export function escapeRegExp(string) {
2
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
3
+ }
@@ -0,0 +1,3 @@
1
+ export { HighlightText } from './highlight-text.component';
2
+ export type { HighlightTextProps } from './highlight-text.types';
3
+ export { highlightVariants } from './highlight-text.constants';
@@ -0,0 +1,2 @@
1
+ export { HighlightText } from './highlight-text.component';
2
+ export { highlightVariants } from './highlight-text.constants';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleflex/ui-tw",
3
- "version": "0.0.144",
3
+ "version": "0.0.146",
4
4
  "author": "scaleflex",
5
5
  "repository": "github:scaleflex/ui",
6
6
  "homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
@@ -29,7 +29,7 @@
29
29
  "@radix-ui/react-switch": "^1.0.1",
30
30
  "@radix-ui/react-tabs": "^1.1.13",
31
31
  "@radix-ui/react-tooltip": "^1.2.6",
32
- "@scaleflex/icons-tw": "^0.0.144",
32
+ "@scaleflex/icons-tw": "^0.0.146",
33
33
  "@tanstack/react-table": "^8.21.3",
34
34
  "@types/lodash.merge": "^4.6.9",
35
35
  "class-variance-authority": "^0.7.1",
@@ -11,7 +11,6 @@ var _excluded = ["className"],
11
11
  _excluded7 = ["className"],
12
12
  _excluded8 = ["className"];
13
13
  import * as TabsPrimitive from '@radix-ui/react-tabs';
14
- import { focusRingClassNames } from '@scaleflex/ui-tw/styles/shared-classes';
15
14
  import { cn } from '@scaleflex/ui-tw/utils/cn';
16
15
  import * as React from 'react';
17
16
 
@@ -40,7 +39,7 @@ function TabsTrigger(_ref3) {
40
39
  props = _objectWithoutProperties(_ref3, _excluded3);
41
40
  return /*#__PURE__*/React.createElement(TabsPrimitive.Trigger, _extends({
42
41
  "data-slot": "tabs-trigger",
43
- className: cn(focusRingClassNames, 'inline-flex cursor-pointer items-center justify-center disabled:pointer-events-none disabled:opacity-50', className)
42
+ className: cn('inline-flex cursor-pointer items-center justify-center disabled:pointer-events-none disabled:opacity-50', 'focus-visible:outline-ring/50 focus-visible:outline-2 focus-visible:outline-offset-4', className)
44
43
  }, props));
45
44
  }
46
45
  function TabsContent(_ref4) {