@agility/plenum-ui 2.0.3 → 2.0.5

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,6 +1,7 @@
1
1
  import { IDynamicIconProps } from "@/stories/atoms/icons";
2
2
  import React from "react";
3
3
  import { IInputFieldProps, AcceptedInputTypes } from "@/stories/molecules/inputs/InputField";
4
+ import { INestedInputButtonProps } from "@/stories/molecules/inputs/NestedInputButton";
4
5
  export interface IFormInputWithAddonsProps extends Omit<IInputFieldProps, "type"> {
5
6
  leadIcon?: IDynamicIconProps;
6
7
  leadLabel?: string;
@@ -16,6 +17,7 @@ export interface IFormInputWithAddonsProps extends Omit<IInputFieldProps, "type"
16
17
  leadIconClassNames?: string;
17
18
  customIconClass?: string;
18
19
  type: AcceptedInputTypes;
20
+ addonBTN?: INestedInputButtonProps;
19
21
  }
20
22
  declare const FormInputWithAddons: React.FC<IFormInputWithAddonsProps>;
21
23
  export default FormInputWithAddons;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agility/plenum-ui",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -27,7 +27,7 @@ const NestedInputButton: React.FC<INestedInputButtonProps> = ({
27
27
  onClickHandler && onClickHandler()
28
28
  }
29
29
  const buttonStyle = cn(
30
- "relative inline-flex items-center space-x-2 px-4 py-2 border border-gray-300 text-sm font-medium focus:outline-none focus:ring-1 focus:ring-purple-500 focus:border-purple-500",
30
+ "relative flex items-center space-x-2 px-4 py-2 leading-5 border border-gray-300 text-sm font-medium focus:outline-none focus:ring-1 focus:ring-purple-500 focus:border-purple-500",
31
31
  {
32
32
  "rounded-r text-gray-500 -ml-px": align === "right"
33
33
  },
@@ -55,7 +55,7 @@ const NestedInputButton: React.FC<INestedInputButtonProps> = ({
55
55
  )
56
56
  return (
57
57
  <button {...{ ...buttonProps, className: buttonStyle, onClick: handleClick }}>
58
- {icon && <DynamicIcon {...{ ...icon, className: "text-gray-400" }} />}
58
+ {icon && <DynamicIcon {...{ ...icon, className: "text-gray-400 h-5 w-5" }} />}
59
59
  {ctaLabel && <span>{ctaLabel}</span>}
60
60
  </button>
61
61
  )
@@ -0,0 +1,47 @@
1
+ import type { Meta, StoryObj } from "@storybook/react"
2
+ import AnimatedFormInputWithAddons, { IAnimatedFormInputWithAddons } from "./AnimatedFormInputWithAddons"
3
+
4
+ const meta: Meta<typeof AnimatedFormInputWithAddons> = {
5
+ title: "Design System/organisms/Animated Form Input with Addons",
6
+ component: AnimatedFormInputWithAddons,
7
+ tags: ["autodocs"],
8
+ argTypes: {}
9
+ }
10
+ const DefaultArgs: IAnimatedFormInputWithAddons = {
11
+ id: "test",
12
+ containerStyles: "w-full",
13
+ label: {
14
+ display: "Input Label"
15
+ },
16
+ placeholder: "Placeholder",
17
+ handleChange: (value: string) => {
18
+ console.log(value)
19
+ },
20
+ type: "text",
21
+ value: "",
22
+ addonBTN: {
23
+ icon: { icon: "IconPencil" },
24
+ align: "right",
25
+ ctaLabel: "Edit",
26
+ onClickHandler: () => {
27
+ alert("clicked")
28
+ }
29
+ }
30
+ }
31
+
32
+ export default meta
33
+ type Story = StoryObj<typeof AnimatedFormInputWithAddons>
34
+
35
+ export const DefaultStory: Story = {
36
+ args: {
37
+ ...DefaultArgs
38
+ } as IAnimatedFormInputWithAddons
39
+ }
40
+
41
+ export const AnimatedFormInputWithAddonsStory: Story = {
42
+ args: {
43
+ ...DefaultArgs,
44
+ label: { display: "label with placeholder" },
45
+ placeholder: "Placeholder"
46
+ } as IAnimatedFormInputWithAddons
47
+ }
@@ -0,0 +1,99 @@
1
+ import React from "react"
2
+ import { default as cn } from "classnames"
3
+ import InputField, { IInputFieldProps } from "@/stories/molecules/inputs/InputField"
4
+ import InputCounter from "@/stories/molecules/inputs/InputCounter"
5
+ import { INestedInputButtonProps, NestedInputButton } from "@/stories/molecules"
6
+
7
+ interface ILabelProps extends React.DetailedHTMLProps<React.LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement> {
8
+ display: string
9
+ }
10
+
11
+ export interface IAnimatedFormInputWithAddons extends Omit<IInputFieldProps, "handleChange"> {
12
+ id: string
13
+ containerStyles?: string
14
+ message?: string
15
+ required?: boolean
16
+ isError?: boolean
17
+ isShowCounter?: boolean
18
+ maxLength?: number
19
+ label: ILabelProps
20
+ handleChange: (value: string) => void
21
+ labelClassName?: string
22
+ addonBTN: INestedInputButtonProps
23
+ }
24
+
25
+ const AnimatedFormInputWithAddons: React.FC<IAnimatedFormInputWithAddons> = (props: IAnimatedFormInputWithAddons) => {
26
+ const {
27
+ id,
28
+ containerStyles,
29
+ message,
30
+ required,
31
+ isError,
32
+ label,
33
+ value,
34
+ isShowCounter,
35
+ maxLength,
36
+ handleChange,
37
+ labelClassName,
38
+ addonBTN,
39
+ ...input
40
+ } = props
41
+
42
+ const [hasValue, setHasValue] = React.useState<boolean>(!!value)
43
+ const [valueLength, setValueLength] = React.useState<number>(0)
44
+
45
+ return (
46
+ <>
47
+ <div className={cn("group relative", containerStyles ? containerStyles : "")}>
48
+ <InputField
49
+ id={id}
50
+ isError={isError}
51
+ value={value}
52
+ handleChange={(v) => {
53
+ setHasValue(!!v)
54
+ setValueLength(v.length)
55
+ if (handleChange) handleChange(v)
56
+ }}
57
+ {...input}
58
+ />
59
+
60
+ {addonBTN && (
61
+ <div className="absolute top-0 bottom-0 right-0 flex items-center ">
62
+ <NestedInputButton {...addonBTN} />
63
+ </div>
64
+ )}
65
+ <div
66
+ className={cn(
67
+ "absolute z-10 ml-[3px] inline-block bg-white text-sm transition-all text-gray-500 left-1 px-1",
68
+ hasValue ? "!-top-[8px] !ml-[.172rem] !text-xs text-gray-600" : "top-[9px]",
69
+ "peer-placeholder-shown:!-top-[8px] peer-placeholder-shown:!ml-[.172rem] peer-placeholder-shown:!text-xs peer-placeholder-shown:text-gray-600",
70
+ "group-focus-within:!-top-[8px] group-focus-within:!bg-label-gradient-focus group-focus-within:!ml-[.172rem] group-focus-within:!text-xs group-focus-within:text-gray-600",
71
+
72
+ isError && "!text-red-600"
73
+ )}
74
+ >
75
+ <label htmlFor={id} className={labelClassName}>
76
+ {label.display}
77
+ {required && <span className="text-red-600 ml-1">*</span>}
78
+ </label>
79
+ </div>
80
+ <div className="flex flex-row space-x-3">
81
+ <div className="grow">
82
+ {message && (
83
+ <span className={cn("mt-1 block text-sm", isError ? "text-red-500" : "text-gray-500")}>
84
+ {message}
85
+ </span>
86
+ )}
87
+ </div>
88
+ {isShowCounter && (
89
+ <div className="shrink-0">
90
+ <InputCounter current={Number(valueLength)} limit={maxLength ?? 150} />
91
+ </div>
92
+ )}
93
+ </div>
94
+ </div>
95
+ </>
96
+ )
97
+ }
98
+
99
+ export default AnimatedFormInputWithAddons
@@ -0,0 +1,3 @@
1
+ import AnimatedFormInputWithAddons, { IAnimatedFormInputWithAddons } from "./AnimatedFormInputWithAddons"
2
+ export type { IAnimatedFormInputWithAddons }
3
+ export default AnimatedFormInputWithAddons
@@ -27,3 +27,22 @@ export const DefaultFormInputWithAddons: Story = {
27
27
  trailIcon: { icon: "IconSearch" }
28
28
  }
29
29
  }
30
+ export const FormInputWithAddonBTN: Story = {
31
+ args: {
32
+ id: "appSearch",
33
+ name: "appSearch",
34
+ addonOffset: 60,
35
+ labelClass: "text-gray-900",
36
+ addonBTN: {
37
+ icon: {
38
+ icon: "IconPencil",
39
+ className: "h-5 w-5 text-gray-400"
40
+ },
41
+ ctaLabel: "Edit",
42
+ align: "right",
43
+ onClickHandler: () => {
44
+ alert("Button Clicked")
45
+ }
46
+ }
47
+ }
48
+ }
@@ -2,6 +2,7 @@ import { DynamicIcon, IDynamicIconProps } from "@/stories/atoms/icons"
2
2
  import React, { useLayoutEffect, useRef, useState } from "react"
3
3
  import { default as cn } from "classnames"
4
4
  import InputField, { IInputFieldProps, AcceptedInputTypes } from "@/stories/molecules/inputs/InputField"
5
+ import NestedInputButton, { INestedInputButtonProps } from "@/stories/molecules/inputs/NestedInputButton"
5
6
 
6
7
  export interface IFormInputWithAddonsProps extends Omit<IInputFieldProps, "type"> {
7
8
  leadIcon?: IDynamicIconProps
@@ -18,6 +19,7 @@ export interface IFormInputWithAddonsProps extends Omit<IInputFieldProps, "type"
18
19
  leadIconClassNames?: string
19
20
  customIconClass?: string
20
21
  type: AcceptedInputTypes
22
+ addonBTN?: INestedInputButtonProps
21
23
  }
22
24
 
23
25
  const FormInputWithAddons: React.FC<IFormInputWithAddonsProps> = ({
@@ -43,6 +45,7 @@ const FormInputWithAddons: React.FC<IFormInputWithAddonsProps> = ({
43
45
  leadIconClassNames,
44
46
  customIconClass,
45
47
  type,
48
+ addonBTN,
46
49
  ...rest
47
50
  }) => {
48
51
  // #region logic to determine the width of the lead and or trailing labels in order to offset the input padding by the appropriate amount.
@@ -137,6 +140,11 @@ const FormInputWithAddons: React.FC<IFormInputWithAddonsProps> = ({
137
140
  {trailLabel && trailLabel}
138
141
  </label>
139
142
  )}
143
+ {addonBTN && (
144
+ <div className="absolute top-0 bottom-0 right-0 flex items-center ">
145
+ <NestedInputButton {...addonBTN} />
146
+ </div>
147
+ )}
140
148
  </div>
141
149
  </div>
142
150
  )