goobs-frontend 0.7.53 → 0.7.55

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.
Files changed (42) hide show
  1. package/README.md +68 -87
  2. package/package.json +29 -33
  3. package/src/components/Accordion/index.tsx +44 -0
  4. package/src/components/Button/index.tsx +89 -37
  5. package/src/components/Card/index.tsx +251 -0
  6. package/src/components/Card/variants/defaultconfig/index.tsx +237 -0
  7. package/src/components/Card/variants/detailedpricingsummary/index.tsx +179 -0
  8. package/src/components/Card/variants/inventory/index.tsx +172 -0
  9. package/src/components/Card/variants/product/index.tsx +243 -0
  10. package/src/components/Card/variants/productsummary/index.tsx +143 -0
  11. package/src/components/Card/variants/simplepricingsummary/index.tsx +131 -0
  12. package/src/components/CodeCopy/index.tsx +118 -0
  13. package/src/components/ConfirmationCodeInput/utils/useCodeConfirmation.tsx +31 -10
  14. package/src/components/Content/Structure/card/useCard.tsx +45 -0
  15. package/src/components/Content/Structure/codecopy/useCodeCopy.tsx +54 -0
  16. package/src/components/Content/Structure/pricing/usePricing.tsx +40 -0
  17. package/src/components/Content/Structure/stepper/useStepper.tsx +47 -0
  18. package/src/components/Content/Structure/styledcomponent/useStyledComponent.tsx +0 -2
  19. package/src/components/Content/Structure/transferlist/useTransferList.tsx +52 -0
  20. package/src/components/Content/index.tsx +76 -99
  21. package/src/components/Form/Popup/index.tsx +128 -94
  22. package/src/components/Grid/index.tsx +29 -30
  23. package/src/components/Nav/HorizontalVariant/index.tsx +206 -0
  24. package/src/components/Nav/VerticalVariant/index.tsx +423 -0
  25. package/src/components/Nav/index.tsx +143 -0
  26. package/src/components/PricingTable/defaultconfig.tsx +287 -0
  27. package/src/components/PricingTable/index.tsx +337 -0
  28. package/src/components/RadioGroup/index.tsx +11 -19
  29. package/src/components/Stepper/index.tsx +126 -0
  30. package/src/components/StyledComponent/adornments.tsx +11 -7
  31. package/src/components/StyledComponent/helperfooter/useHelperFooter.tsx +110 -120
  32. package/src/components/StyledComponent/hooks/usePhoneNumber.tsx +5 -26
  33. package/src/components/StyledComponent/hooks/useSearchbar.tsx +16 -16
  34. package/src/components/StyledComponent/index.tsx +120 -44
  35. package/src/components/Toolbar/index.tsx +139 -0
  36. package/src/components/Tooltip/index.tsx +63 -0
  37. package/src/components/TransferList/index.tsx +207 -0
  38. package/src/components/Typography/index.tsx +23 -2
  39. package/src/index.ts +64 -6
  40. package/src/atoms/helperfooter.ts +0 -21
  41. package/src/main.tsx +0 -7
  42. package/src/types/async-lock.d.ts +0 -35
package/README.md CHANGED
@@ -1,22 +1,22 @@
1
1
  # goobs-frontend
2
2
 
3
- goobs-frontend previously known as goobs-repo is a collection of reusable components and utilities for building web applications with React and Next.js. It provides a set of tools to streamline development and enhance functionality.
3
+ goobs-frontend, previously known as goobs-repo, is a comprehensive React-based UI library built on Material-UI. It offers a wide range of customizable components for building responsive and consistent user interfaces with advanced features like form validation, theming, and code syntax highlighting.
4
4
 
5
5
  The NPM repo is available here - https://www.npmjs.com/package/goobs-frontend
6
6
 
7
- This entire repository is written in typescript and there is no need for a types/ install file
7
+ This entire repository is written in TypeScript, and there is no need for a separate types installation.
8
8
 
9
9
  ## Version
10
10
 
11
- This is a beta release of the tools. It is available via npm to ensure functionality is as expected. We will iron out any kinks and expect version v1 to be production-ready for all components, while some components are already production-ready. Installation confirmed working with install instructions below.
11
+ This is a beta release of the tools. It is available via npm to ensure functionality is as expected. We will iron out any kinks and expect version v1 to be production-ready for all components, while some components are already production-ready. Installation is confirmed working with the install instructions below.
12
12
 
13
13
  ## Integrating goobs-frontend with Next.js
14
14
 
15
- This guide explains how to integrate the goobs-repo package with a Next.js project
15
+ This guide explains how to integrate the goobs-frontend package with a Next.js project.
16
16
 
17
17
  **Step 1: Install the project**
18
18
 
19
- In your Next.js project directory, run the following command to install goobs-repo
19
+ In your Next.js project directory, run the following command to install goobs-frontend:
20
20
 
21
21
  #### npm
22
22
 
@@ -32,9 +32,9 @@ yarn add goobs-frontend
32
32
 
33
33
  **Step 2: Update next.config.js**
34
34
 
35
- We are using SWC; here is the minimum recommended configuration for next.config.js using our repository
35
+ We are using SWC; here is the minimum recommended configuration for next.config.js using our repository:
36
36
 
37
- ```bash
37
+ ```javascript
38
38
  /** @type {import('next').NextConfig} */
39
39
 
40
40
  const nextConfig = {
@@ -46,125 +46,106 @@ const nextConfig = {
46
46
  export default nextConfig
47
47
  ```
48
48
 
49
- which you can see more information on how we got here and how it was incorrectly done in previous versions via - https://github.com/goobz22/goobs-frontend/discussions/21
49
+ You can see more information on how we got here and how it was incorrectly done in previous versions via - https://github.com/goobz22/goobs-frontend/discussions/21
50
50
 
51
51
  **Step 3: Implement into project and build to confirm functionality**
52
52
 
53
- All components should be successfully building as of this release and are being used within production in one way or another. The props may not all work exactly as expected but as I go through and find a way to document each of the components further I will sus out what needs removed and or implemented now or in future versions.
53
+ All components should be successfully building as of this release and are being used within production in one way or another. The props may not all work exactly as expected, but as we go through and find a way to document each of the components further, we will determine what needs to be removed or implemented now or in future versions.
54
54
 
55
- This readme update along side the following documentation updates are all a push to better document the usage of this project and is a hard requirement to move from .7-beta of this product and to move onto .8-beta as I am getting ready for release and establishing a product version release methodology.
55
+ This README update, along with the following documentation updates, are all part of a push to better document the usage of this project. It is a hard requirement to move from .7-beta of this product to .8-beta as we are getting ready for release and establishing a product version release methodology.
56
56
 
57
57
  ## Components
58
58
 
59
- The following components are within goobs-frontend
59
+ The following components are available within goobs-frontend:
60
+
61
+ ### Accordion
62
+
63
+ The Accordion component provides an expandable panel for organizing and presenting content in a collapsible manner.
60
64
 
61
65
  ### Button
62
66
 
63
67
  The Button component is a customizable button with support for icons, variants, and styling props. It provides a flexible and reusable way to create buttons in your application.
64
68
 
65
- #### Capabilities Preview
69
+ ### Card
70
+
71
+ The Card component offers various card layouts for displaying content, including product cards, pricing cards, and more.
72
+
73
+ ### CodeCopy
74
+
75
+ The CodeCopy component renders a code block with syntax highlighting and a copy-to-clipboard functionality.
76
+
77
+ ### ConfirmationCodeInput
78
+
79
+ The ConfirmationCodeInput component provides an input field for entering confirmation codes, often used in two-factor authentication scenarios.
80
+
81
+ ### Content
82
+
83
+ The Content component is a flexible container for rendering various types of content within your application.
66
84
 
67
- - text (optional): The text to display on the button.
68
- - variant (optional): The variant of the button (e.g., 'contained', 'outlined', 'text').
69
- - fontsize (optional): The font size of the button text.
70
- - icon (optional): The icon to display on the button.
71
- - iconlocation (optional): The location of the icon ('left' or 'right').
72
- - type (optional): The type of the button (e.g., 'button', 'submit', 'reset').
73
- - onClick (optional): The function to be called when the button is clicked.
74
- - fontcolor (optional): The color of the button text.
75
- - helperfooter (optional): An object containing helper footer properties (status, statusMessage).
85
+ ### Form
76
86
 
77
- The usage of the button component and these props will be documented before release of v.8. within this wiki - https://github.com/goobz22/goobs-repo/wiki/Button
87
+ The Form component includes the PopupForm subcomponent, which renders a customizable popup form.
78
88
 
79
89
  ### Grid
80
90
 
81
91
  The Grid component is a highly customizable and flexible grid system built with React and Material-UI. It allows you to create complex grid layouts with ease, providing a wide range of configuration options for grids, rows, columns, and cells.
82
92
 
83
- #### Capabilities Preview
93
+ ### Nav
84
94
 
85
- - gridconfig: An object or an array of objects representing the grid configuration. It includes properties such as grid name, margins, width, and animation.
86
- - columnconfig: An array of objects representing the column configuration. Each object includes properties such as the row and column position, grid name, alignment, column width, margins, animation, and custom component.
87
- - cellconfig (optional): An object representing the cell configuration. It includes properties such as border style and minimum height.
95
+ The Nav component provides navigation functionality, including both horizontal and vertical navigation options.
88
96
 
89
- The usage of the grid component and these props will be documented before release of v.8. within this wiki - https://github.com/goobz22/goobs-repo/wiki/Grid
97
+ ### PricingTable
90
98
 
91
- ### Typography
99
+ The PricingTable component renders a customizable pricing table for displaying product or service pricing information.
92
100
 
93
- The Typography component is a text component for rendering customizable typography.
101
+ ### RadioGroup
94
102
 
95
- #### Capabilities Preview
103
+ The RadioGroup component renders a group of radio buttons for selecting a single option from multiple choices.
96
104
 
97
- - text (optional): The text content to be rendered.
98
- - fontvariant (optional): The variant of the typography component.
99
- - fontcolor (optional): The color of the typography text.
100
- - columnconfig (optional): The configuration object for the grid column.
101
- - cellconfig (optional): The configuration object for the grid cell.
105
+ ### Stepper
102
106
 
103
- The usage of the typography component and these props will be documented before release of v.8. within this wiki - https://github.com/goobz22/goobs-repo/wiki/Typography
107
+ The Stepper component provides a step-by-step interface for guiding users through a process or workflow.
104
108
 
105
109
  ### StyledComponent
106
110
 
107
111
  The StyledComponent is a versatile and customizable input component built with React and Material-UI. It provides a range of input variants and supports various styling options to match your application's design requirements.
108
112
 
109
- #### Capabilities Preview
110
-
111
- - name (optional): The name of the input field.
112
- - outlinecolor (optional): The color of the input outline.
113
- - iconcolor (optional): The color of the input icons.
114
- - backgroundcolor (optional): The background color of the input.
115
- - combinedfontcolor (optional): The color of the input text and label when combined.
116
- - unshrunkfontcolor (optional): The color of the label when not shrunk.
117
- - shrunkfontcolor (optional): The color of the label when shrunk.
118
- - endAdornmentMarginRight (optional): The right margin of the end adornment.
119
- - autoComplete (optional): The autocomplete attribute for the input.
120
- - componentvariant (optional): The variant of the input component (e.g., 'textfield', 'phonenumber', 'password', 'dropdown', 'searchbar').
121
- - options (optional): An array of options for the dropdown variant.
122
- - helperfooter (optional): An object containing helper footer properties (status, statusMessage).
123
- - placeholder (optional): The placeholder text for the input.
124
- - minRows (optional): The minimum number of rows for the multiline textfield variant.
125
- - formname (optional): The name of the form associated with the input.
126
- - label (optional): The label text for the input.
127
- - shrunklabellocation (optional): The location of the shrunk label ('onnotch', 'above', 'left').
128
- - value (optional): The value of the input.
129
- - onChange (optional): The function to be called when the input value changes.
130
- - defaultValue (optional): The default value of the input.
131
- - inputRef (optional): The ref object for the input element.
132
- - columnconfig (optional): The configuration object for the grid column.
133
- - serverActionValidation (optional): An async function that performs server-side validation on the input value.
134
-
135
- #### Hooks
136
-
137
- The StyledComponent utilizes several custom hooks to enhance its functionality:
138
-
139
- - src/hooks/styledcomponent/useDropdown.tsx: Handles the dropdown functionality, including opening/closing the dropdown, filtering options, and selecting an option.
140
- - src/hooks/styledcomponent/usePhoneNumber.tsx: Handles phone number formatting and updating the input value.
141
- - src/hooks/styledcomponent/usePassword.tsx: Handles password visibility toggling.
142
- - src/hooks/styledcomponent/useSearchbar.tsx: Handles the searchbar functionality, including filtering options based on the search query.
143
-
144
- #### Validation
145
-
146
- The StyledComponent supports both client-side and server-side validation. Client-side validation is handled by the component itself, while server-side validation is performed through the serverActionValidation prop.
147
-
148
- When the serverActionValidation prop is provided, the component debounces the validation function to optimize performance. The validation result is then displayed in the helper footer message.
149
-
150
- The usage of the StyledComponent component and these props will be documented before release of v.8. within this wiki - https://github.com/goobz22/goobs-frontend/wiki/StyledComponent
113
+ ### Toolbar
114
+
115
+ The Toolbar component offers a customizable toolbar for use in various UI scenarios.
116
+
117
+ ### TransferList
118
+
119
+ The TransferList component provides a dual-list interface for transferring items between two lists.
120
+
121
+ ### Typography
122
+
123
+ The Typography component is a text component for rendering customizable typography.
151
124
 
152
125
  ## Usage
153
126
 
154
- To use the components and utilities in your project, you can import them from the `goobs-repo` package. For example:
127
+ To use the components and utilities in your project, you can import them from the `goobs-frontend` package. For example:
155
128
 
156
129
  ```jsx
157
130
  import {
158
131
  CustomButton,
159
132
  CustomGrid,
160
- StyledComponent
133
+ StyledComponent,
161
134
  Typography,
162
135
  RadioGroup,
163
- ConfirmationCodeInputs
164
- } from 'goobs-repo'
136
+ ConfirmationCodeInput,
137
+ Card,
138
+ CodeCopy,
139
+ Nav,
140
+ PricingTable,
141
+ CustomStepper,
142
+ CustomToolbar,
143
+ TransferList,
144
+ Accordion,
145
+ } from 'goobs-frontend'
165
146
  ```
166
147
 
167
- Please refer to the individual component and utility files for more details on their usage and available props.
148
+ Please refer to the individual component and utility files for more details on their usage and available props. We are in the process of documenting each component in the [GitHub wiki](https://github.com/goobz22/goobs-frontend/wiki).
168
149
 
169
150
  ## License
170
151
 
@@ -172,11 +153,11 @@ This project is licensed under the MIT License.
172
153
 
173
154
  ## Feedback and Contributions
174
155
 
175
- We welcome feedback, bug reports, and contributions. If you encounter any issues or have feature requests, please open an issue on the [GitHub repository](https://github.com/goobz22/goobs-repo/issues).
156
+ We welcome feedback, bug reports, and contributions. If you encounter any issues or have feature requests, please open an issue on the [GitHub repository](https://github.com/goobz22/goobs-frontend/issues).
176
157
 
177
158
  If you would like to contribute to the project, please fork the repository and submit a pull request with your changes.
178
159
 
179
- If you would like to request a this ported over to a different design system, a feature/capability or more information on this project please reach out to Matthew Goluba.
160
+ If you would like to request this ported over to a different design system, a feature/capability, or more information on this project, please reach out to Matthew Goluba.
180
161
 
181
162
  ## Contact
182
163
 
@@ -185,6 +166,6 @@ For any questions or inquiries, please contact Matthew Goluba.
185
166
  - Email - mkgoluba@technologiesunlimited.net
186
167
  - LinkedIn - https://www.linkedin.com/in/matthew-goluba/
187
168
 
188
- The website is in progress and will be shared here soon
169
+ The website is in progress and will be shared here soon.
189
170
 
190
- Please email for the quickest response
171
+ Please email for the quickest response.
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "goobs-frontend",
3
- "version": "0.7.53",
3
+ "version": "0.7.55",
4
+ "description": "A comprehensive React-based UI library built on Material-UI, offering a wide range of customizable components including grids, typography, buttons, cards, forms, navigation, pricing tables, steppers, tooltips, accordions, and more. Designed for building responsive and consistent user interfaces with advanced features like form validation, theming, and code syntax highlighting.",
4
5
  "license": "MIT",
5
6
  "main": "./src/index.ts",
6
7
  "types": "./src/index.ts",
@@ -27,28 +28,23 @@
27
28
  "@mui/icons-material": "^5.15.20",
28
29
  "@mui/material": "^5.15.20",
29
30
  "@types/lodash": "^4.17.5",
30
- "@types/mongodb": "^4.0.7",
31
- "async-lock": "^1.4.1",
32
- "aws4": "^1.13.0",
33
- "goobs-cache": "^1.0.1",
34
- "jotai": "^2.8.3",
31
+ "goobs-cache": "^1.2.1",
32
+ "highlight.js": "^11.9.0",
35
33
  "lodash": "^4.17.21",
36
- "mongodb": "^6.8.0",
37
34
  "next": "14.2.4"
38
35
  },
39
36
  "devDependencies": {
40
37
  "@next/eslint-plugin-next": "^14.2.4",
41
- "@types/async-lock": "^1.4.2",
42
38
  "@types/node": "^20.14.9",
43
39
  "@types/react": "18.3.0",
44
40
  "@types/react-dom": "^18.3.0",
45
- "@typescript-eslint/eslint-plugin": "^7.14.1",
46
- "@typescript-eslint/parser": "^7.14.1",
47
- "eslint": "8.57.0",
41
+ "@typescript-eslint/eslint-plugin": "^7.15.0",
42
+ "@typescript-eslint/parser": "^7.15.0",
43
+ "eslint": "^8.57.0",
48
44
  "eslint-config-next": "^14.2.4",
49
45
  "eslint-config-prettier": "^9.1.0",
50
46
  "eslint-plugin-prettier": "^5.1.3",
51
- "prettier": "3.3.2",
47
+ "prettier": "^3.3.2",
52
48
  "react": "^18.3.1",
53
49
  "react-dom": "^18.3.1",
54
50
  "typescript": "^5.5.2"
@@ -58,14 +54,13 @@
58
54
  ],
59
55
  "repository": {
60
56
  "type": "git",
61
- "url": "https://github.com/goobz22/goobs-repo.git"
57
+ "url": "https://github.com/goobz22/goobs-frontend.git"
62
58
  },
63
59
  "bugs": {
64
- "url": "https://github.com/goobz22/goobs-repo/issues"
60
+ "url": "https://github.com/goobz22/goobs-frontend/issues"
65
61
  },
66
- "homepage": "https://github.com/goobz22/goobs-repo#readme",
62
+ "homepage": "https://github.com/goobz22/goobs-frontend#readme",
67
63
  "keywords": [
68
- "react",
69
64
  "confirmationCodeInput",
70
65
  "confirmationCode",
71
66
  "radioButton",
@@ -77,27 +72,13 @@
77
72
  "node.js",
78
73
  "formData",
79
74
  "form",
80
- "formStore",
81
75
  "form-validation",
82
76
  "form-submission",
83
- "form-caching",
84
- "redis-alternative",
85
- "useState-alternative",
86
- "jotai-alternative",
87
77
  "button",
88
78
  "grid",
89
79
  "responsive",
90
80
  "flexgrid",
91
- "jsonStorage",
92
- "localStorage",
93
- "sessionStorage",
94
- "fileStorage",
95
81
  "typography",
96
- "server-actions",
97
- "form-store",
98
- "form-data",
99
- "client-actions",
100
- "reusable-server-actions",
101
82
  "responsive-grid",
102
83
  "styled-component",
103
84
  "input-component",
@@ -106,14 +87,29 @@
106
87
  "form-validation",
107
88
  "searchbar",
108
89
  "dropdown",
109
- "client-side-validation",
110
- "server-side-validation",
111
90
  "multilinetextfield",
112
91
  "textfield",
113
92
  "phonenumber",
114
93
  "password",
115
94
  "email",
116
- "number"
95
+ "number",
96
+ "card",
97
+ "pricing-table",
98
+ "navigation",
99
+ "stepper",
100
+ "tooltip",
101
+ "accordion",
102
+ "code-copy",
103
+ "syntax-highlighting",
104
+ "theming",
105
+ "customizable-components",
106
+ "react-components",
107
+ "ui-library",
108
+ "design-system",
109
+ "front-end",
110
+ "user-interface",
111
+ "responsive-design",
112
+ "typescript"
117
113
  ],
118
114
  "resolutions": {
119
115
  "string-width": "^4.2.3",
@@ -0,0 +1,44 @@
1
+ 'use client'
2
+
3
+ import React from 'react'
4
+ import { styled } from '@mui/material/styles'
5
+ import MuiAccordion, { AccordionProps } from '@mui/material/Accordion'
6
+ import MuiAccordionSummary, {
7
+ AccordionSummaryProps,
8
+ } from '@mui/material/AccordionSummary'
9
+ import MuiAccordionDetails from '@mui/material/AccordionDetails'
10
+ import { ExpandMore } from '@mui/icons-material'
11
+ import { black } from '../../styles/palette'
12
+
13
+ /**
14
+ * Custom styled Accordion component.
15
+ * Wraps MUI's Accordion with custom styling and disables gutters by default.
16
+ */
17
+ const Accordion = styled((props: AccordionProps) => (
18
+ <MuiAccordion disableGutters {...props} />
19
+ ))({})
20
+
21
+ /**
22
+ * Custom styled AccordionSummary component.
23
+ * Wraps MUI's AccordionSummary with custom styling and a custom expand icon.
24
+ */
25
+ const AccordionSummary = styled((props: AccordionSummaryProps) => (
26
+ <MuiAccordionSummary
27
+ expandIcon={<ExpandMore sx={{ color: black.main }} />}
28
+ {...props}
29
+ />
30
+ ))({
31
+ fontSize: '20px',
32
+ fontFamily: 'merriweather',
33
+ fontWeight: 500,
34
+ })
35
+
36
+ /**
37
+ * Custom styled AccordionDetails component.
38
+ * Wraps MUI's AccordionDetails with custom padding based on the theme's spacing.
39
+ */
40
+ const AccordionDetails = styled(MuiAccordionDetails)(({ theme }) => ({
41
+ padding: theme.spacing(2),
42
+ }))
43
+
44
+ export { Accordion, AccordionSummary, AccordionDetails }
@@ -1,22 +1,52 @@
1
1
  'use client'
2
2
 
3
- import React, { useEffect, useState } from 'react'
3
+ import React, { useEffect, useState, useCallback } from 'react'
4
4
  import { Button, Box, ButtonProps } from '@mui/material'
5
5
  import StarIcon from '@mui/icons-material/Star'
6
6
  import Typography from '../Typography'
7
- import { useAtom } from 'jotai'
8
- import { helperFooterAtom, HelperFooterMessage } from '../../atoms/helperfooter'
7
+ import { get, JSONValue } from 'goobs-cache'
9
8
  import { red } from '../../styles/palette'
10
9
 
10
+ /**
11
+ * Defines the possible alignment options for button content.
12
+ */
11
13
  export type ButtonAlignment = 'left' | 'center' | 'right'
12
14
 
15
+ /**
16
+ * Defines the structure of helper footer messages used for form validation.
17
+ */
18
+ export interface HelperFooterMessage {
19
+ /** Indicates whether the message represents an error or success state */
20
+ status: 'error' | 'success'
21
+ /** The message to display in the status area */
22
+ statusMessage: string
23
+ /** The message to spread across multiple components */
24
+ spreadMessage: string
25
+ /** Priority of the spread message for determining which message to show */
26
+ spreadMessagePriority: number
27
+ /** The name of the form this message is associated with */
28
+ formname: string
29
+ /** Indicates if the field associated with this message is required */
30
+ required: boolean
31
+ }
32
+
33
+ /**
34
+ * Props for the CustomButton component.
35
+ * Extends ButtonProps from Material-UI, omitting 'color' and 'variant'.
36
+ */
13
37
  export interface CustomButtonProps
14
38
  extends Omit<ButtonProps, 'color' | 'variant'> {
39
+ /** Text to display on the button */
15
40
  text?: string
41
+ /** Background color of the button */
16
42
  backgroundcolor?: string
43
+ /** Color of the button's outline */
17
44
  outlinecolor?: string
45
+ /** Color of the button's text */
18
46
  fontcolor?: string
47
+ /** Alignment of the button's text */
19
48
  fontlocation?: ButtonAlignment
49
+ /** Typography variant for the button's text */
20
50
  fontvariant?:
21
51
  | 'arapeyh1'
22
52
  | 'arapeyh2'
@@ -45,24 +75,31 @@ export interface CustomButtonProps
45
75
  | 'merriparagraph'
46
76
  | 'merrihelperheader'
47
77
  | 'merrihelperfooter'
78
+ /** Icon to display on the button. Set to false to hide the icon */
48
79
  icon?: React.ReactNode | false
80
+ /** Color of the icon */
49
81
  iconcolor?: string
82
+ /** Size of the icon */
50
83
  iconsize?: string
84
+ /** Position of the icon relative to the text */
51
85
  iconlocation?: 'left' | 'top' | 'right'
86
+ /** Style variant of the button */
52
87
  variant?: 'text' | 'outlined' | 'contained'
88
+ /** Function to call when the button is clicked */
53
89
  onClick?: () => void
90
+ /** Helper footer message for form validation */
54
91
  helperfooter?: HelperFooterMessage
92
+ /** Width of the button */
55
93
  width?: string
94
+ /** Name of the form this button is associated with */
56
95
  formname?: string
96
+ /** Name attribute for the button element */
57
97
  name?: string
58
- onFormSubmit?: (isSubmitted: boolean) => void
59
98
  }
60
99
 
61
100
  /**
62
- * CustomButton component renders a customizable button with various styling and functionality options.
63
- * It integrates with helper footers to display error messages and form validation status.
64
- * @param props The props for the CustomButton component.
65
- * @returns The rendered CustomButton component.
101
+ * CustomButton component renders a customizable button with integrated form validation.
102
+ * It displays error messages based on helper footers and form validation status.
66
103
  */
67
104
  const CustomButton: React.FC<CustomButtonProps> = props => {
68
105
  const {
@@ -82,25 +119,27 @@ const CustomButton: React.FC<CustomButtonProps> = props => {
82
119
  fontlocation,
83
120
  iconcolor,
84
121
  width,
85
- onFormSubmit,
86
122
  } = props
87
123
 
88
- const [helperFooterAtomValue] = useAtom(helperFooterAtom)
124
+ /** State for storing the current error message */
89
125
  const [errorMessage, setErrorMessage] = useState<string | undefined>(
90
126
  undefined
91
127
  )
128
+ /** State for tracking whether the associated form is valid */
92
129
  const [isFormValid, setIsFormValid] = useState<boolean>(true)
93
- const [isFormSubmitted, setIsFormSubmitted] = useState<boolean>(false)
130
+ /** State for storing helper footer messages */
131
+ const [helperFooterValue, setHelperFooterValue] = useState<
132
+ Record<string, HelperFooterMessage>
133
+ >({})
94
134
 
95
135
  /**
96
- * updateFormValidation function updates the form validation status and error message
97
- * based on the values in the helper footers associated with the current form.
98
- * It checks for error footers and empty required fields to determine the form's validity
99
- * and sets the error message accordingly.
136
+ * Updates the form validation status and error message based on helper footers.
137
+ * This function filters relevant footers, checks for errors and empty required fields,
138
+ * and updates the error message and form validity accordingly.
100
139
  */
101
- const updateFormValidation = () => {
140
+ const updateFormValidation = useCallback(() => {
102
141
  if (formname) {
103
- const relevantFooters = Object.values(helperFooterAtomValue).filter(
142
+ const relevantFooters = Object.values(helperFooterValue).filter(
104
143
  footer => footer?.formname === formname
105
144
  )
106
145
 
@@ -130,30 +169,46 @@ const CustomButton: React.FC<CustomButtonProps> = props => {
130
169
  setIsFormValid(true)
131
170
  }
132
171
  }
133
- }
172
+ }, [formname, helperFooterValue])
134
173
 
135
174
  /**
136
- * useEffect hook that triggers the updateFormValidation function whenever the
137
- * helperFooterAtomValue or formname changes.
175
+ * Fetches helper footer data from the cache when formname changes.
176
+ * This effect runs whenever the formname prop changes.
138
177
  */
139
178
  useEffect(() => {
140
- updateFormValidation()
141
- }, [helperFooterAtomValue, formname])
179
+ const fetchHelperFooter = async () => {
180
+ const helperFooterResult = await get('helperFooter', 'client')
181
+ if (
182
+ helperFooterResult &&
183
+ typeof helperFooterResult === 'object' &&
184
+ 'value' in helperFooterResult
185
+ ) {
186
+ setHelperFooterValue(
187
+ (helperFooterResult as JSONValue).value as Record<
188
+ string,
189
+ HelperFooterMessage
190
+ >
191
+ )
192
+ }
193
+ }
194
+
195
+ fetchHelperFooter()
196
+ }, [formname])
142
197
 
143
198
  /**
144
- * useEffect hook that calls the onFormSubmit callback with the current isFormSubmitted state
145
- * whenever the isFormSubmitted state or onFormSubmit prop changes.
199
+ * Triggers form validation whenever helperFooterValue changes.
200
+ * This effect ensures that the form validation is updated whenever
201
+ * the helper footer messages change.
146
202
  */
147
203
  useEffect(() => {
148
- if (onFormSubmit) {
149
- onFormSubmit(isFormSubmitted)
150
- }
151
- }, [isFormSubmitted, onFormSubmit])
204
+ updateFormValidation()
205
+ }, [updateFormValidation])
152
206
 
153
207
  /**
154
- * renderIcon function renders the icon element based on the provided icon prop.
155
- * It clones the icon element and applies the iconsize style if the icon is a valid React element.
156
- * If the icon prop is set to false, it returns null.
208
+ * Renders the icon element based on the provided icon prop.
209
+ * If the icon prop is false, it returns null.
210
+ * If the icon is a valid React element, it clones it with the specified size.
211
+ * Otherwise, it renders a default StarIcon.
157
212
  * @returns The rendered icon element or null.
158
213
  */
159
214
  const renderIcon = () => {
@@ -169,13 +224,10 @@ const CustomButton: React.FC<CustomButtonProps> = props => {
169
224
  }
170
225
 
171
226
  /**
172
- * handleButtonClick function is called when the button is clicked.
173
- * It sets the isFormSubmitted state to true and checks the form validity.
174
- * If the form is valid and an onClick handler is provided, it calls the onClick handler.
227
+ * Handles the button click event.
228
+ * If the form is valid and an onClick handler is provided, it calls the handler.
175
229
  */
176
230
  const handleButtonClick = async () => {
177
- setIsFormSubmitted(true)
178
-
179
231
  if (!isFormValid) {
180
232
  return
181
233
  }
@@ -223,7 +275,7 @@ const CustomButton: React.FC<CustomButtonProps> = props => {
223
275
  {iconlocation === 'right' && renderIcon()}
224
276
  </Box>
225
277
  </Button>
226
- {isFormSubmitted && errorMessage && (
278
+ {errorMessage && (
227
279
  <Typography
228
280
  fontvariant="merrihelperfooter"
229
281
  fontcolor={red.main}