goobs-frontend 0.7.53

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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +190 -0
  3. package/package.json +122 -0
  4. package/src/app/_app.tsx +8 -0
  5. package/src/atoms/helperfooter.ts +21 -0
  6. package/src/components/Button/index.tsx +241 -0
  7. package/src/components/ConfirmationCodeInput/index.tsx +108 -0
  8. package/src/components/ConfirmationCodeInput/utils/useCodeConfirmation.tsx +129 -0
  9. package/src/components/Content/Structure/animations.tsx +106 -0
  10. package/src/components/Content/Structure/button/useButton.tsx +80 -0
  11. package/src/components/Content/Structure/confirmationinput/useConfirmationInput.tsx +56 -0
  12. package/src/components/Content/Structure/image/useImage.tsx +62 -0
  13. package/src/components/Content/Structure/link/useLink.tsx +60 -0
  14. package/src/components/Content/Structure/radiogroup/useGridRadioGroup.tsx +62 -0
  15. package/src/components/Content/Structure/styledcomponent/useStyledComponent.tsx +96 -0
  16. package/src/components/Content/Structure/typography/useGridTypography.tsx +53 -0
  17. package/src/components/Content/index.tsx +147 -0
  18. package/src/components/Form/Popup/index.tsx +121 -0
  19. package/src/components/Grid/defaultconfig.tsx +131 -0
  20. package/src/components/Grid/index.tsx +265 -0
  21. package/src/components/Icons/Calendar.tsx +21 -0
  22. package/src/components/Icons/DownArrowFilled.tsx +9 -0
  23. package/src/components/Icons/Drag.tsx +9 -0
  24. package/src/components/Icons/FavoriteIcon.tsx +24 -0
  25. package/src/components/Icons/Info.tsx +12 -0
  26. package/src/components/Icons/Search.tsx +29 -0
  27. package/src/components/Icons/ShowHideEye.tsx +16 -0
  28. package/src/components/RadioGroup/index.tsx +96 -0
  29. package/src/components/StyledComponent/adornments.tsx +118 -0
  30. package/src/components/StyledComponent/helperfooter/useHelperFooter.tsx +411 -0
  31. package/src/components/StyledComponent/hooks/useDropdown.tsx +144 -0
  32. package/src/components/StyledComponent/hooks/usePassword.tsx +23 -0
  33. package/src/components/StyledComponent/hooks/usePhoneNumber.tsx +75 -0
  34. package/src/components/StyledComponent/hooks/useSearchbar.tsx +44 -0
  35. package/src/components/StyledComponent/hooks/useSplitButton.tsx +66 -0
  36. package/src/components/StyledComponent/index.tsx +404 -0
  37. package/src/components/Typography/index.tsx +268 -0
  38. package/src/index.ts +210 -0
  39. package/src/main.tsx +7 -0
  40. package/src/styles/Form/index.ts +7 -0
  41. package/src/styles/StyledComponent/Label/index.ts +76 -0
  42. package/src/styles/palette.ts +143 -0
  43. package/src/styles/typography.ts +184 -0
  44. package/src/types/async-lock.d.ts +35 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Matt Goluba
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # goobs-frontend
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.
4
+
5
+ The NPM repo is available here - https://www.npmjs.com/package/goobs-frontend
6
+
7
+ This entire repository is written in typescript and there is no need for a types/ install file
8
+
9
+ ## Version
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.
12
+
13
+ ## Integrating goobs-frontend with Next.js
14
+
15
+ This guide explains how to integrate the goobs-repo package with a Next.js project
16
+
17
+ **Step 1: Install the project**
18
+
19
+ In your Next.js project directory, run the following command to install goobs-repo
20
+
21
+ #### npm
22
+
23
+ ```bash
24
+ npm i goobs-frontend
25
+ ```
26
+
27
+ #### yarn
28
+
29
+ ```bash
30
+ yarn add goobs-frontend
31
+ ```
32
+
33
+ **Step 2: Update next.config.js**
34
+
35
+ We are using SWC; here is the minimum recommended configuration for next.config.js using our repository
36
+
37
+ ```bash
38
+ /** @type {import('next').NextConfig} */
39
+
40
+ const nextConfig = {
41
+ reactStrictMode: true,
42
+ swcMinify: true,
43
+ transpilePackages: ['goobs-frontend'],
44
+ }
45
+
46
+ export default nextConfig
47
+ ```
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
50
+
51
+ **Step 3: Implement into project and build to confirm functionality**
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.
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.
56
+
57
+ ## Components
58
+
59
+ The following components are within goobs-frontend
60
+
61
+ ### Button
62
+
63
+ 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
+
65
+ #### Capabilities Preview
66
+
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).
76
+
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
78
+
79
+ ### Grid
80
+
81
+ 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
+
83
+ #### Capabilities Preview
84
+
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.
88
+
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
90
+
91
+ ### Typography
92
+
93
+ The Typography component is a text component for rendering customizable typography.
94
+
95
+ #### Capabilities Preview
96
+
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.
102
+
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
104
+
105
+ ### StyledComponent
106
+
107
+ 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
+
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
151
+
152
+ ## Usage
153
+
154
+ To use the components and utilities in your project, you can import them from the `goobs-repo` package. For example:
155
+
156
+ ```jsx
157
+ import {
158
+ CustomButton,
159
+ CustomGrid,
160
+ StyledComponent
161
+ Typography,
162
+ RadioGroup,
163
+ ConfirmationCodeInputs
164
+ } from 'goobs-repo'
165
+ ```
166
+
167
+ Please refer to the individual component and utility files for more details on their usage and available props.
168
+
169
+ ## License
170
+
171
+ This project is licensed under the MIT License.
172
+
173
+ ## Feedback and Contributions
174
+
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).
176
+
177
+ If you would like to contribute to the project, please fork the repository and submit a pull request with your changes.
178
+
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.
180
+
181
+ ## Contact
182
+
183
+ For any questions or inquiries, please contact Matthew Goluba.
184
+
185
+ - Email - mkgoluba@technologiesunlimited.net
186
+ - LinkedIn - https://www.linkedin.com/in/matthew-goluba/
187
+
188
+ The website is in progress and will be shared here soon
189
+
190
+ Please email for the quickest response
package/package.json ADDED
@@ -0,0 +1,122 @@
1
+ {
2
+ "name": "goobs-frontend",
3
+ "version": "0.7.53",
4
+ "license": "MIT",
5
+ "main": "./src/index.ts",
6
+ "types": "./src/index.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./src/index.ts",
10
+ "require": "./src/index.ts"
11
+ }
12
+ },
13
+ "scripts": {
14
+ "dev": "next dev",
15
+ "build": "next build",
16
+ "start": "next start",
17
+ "lint": "next lint"
18
+ },
19
+ "peerDependencies": {
20
+ "react": "^17.0.0 || ^18.0.0",
21
+ "react-dom": "^17.0.0 || ^18.0.0"
22
+ },
23
+ "dependencies": {
24
+ "@emotion/cache": "^11.11.0",
25
+ "@emotion/react": "^11.11.4",
26
+ "@emotion/styled": "^11.11.5",
27
+ "@mui/icons-material": "^5.15.20",
28
+ "@mui/material": "^5.15.20",
29
+ "@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",
35
+ "lodash": "^4.17.21",
36
+ "mongodb": "^6.8.0",
37
+ "next": "14.2.4"
38
+ },
39
+ "devDependencies": {
40
+ "@next/eslint-plugin-next": "^14.2.4",
41
+ "@types/async-lock": "^1.4.2",
42
+ "@types/node": "^20.14.9",
43
+ "@types/react": "18.3.0",
44
+ "@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",
48
+ "eslint-config-next": "^14.2.4",
49
+ "eslint-config-prettier": "^9.1.0",
50
+ "eslint-plugin-prettier": "^5.1.3",
51
+ "prettier": "3.3.2",
52
+ "react": "^18.3.1",
53
+ "react-dom": "^18.3.1",
54
+ "typescript": "^5.5.2"
55
+ },
56
+ "files": [
57
+ "src"
58
+ ],
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "https://github.com/goobz22/goobs-repo.git"
62
+ },
63
+ "bugs": {
64
+ "url": "https://github.com/goobz22/goobs-repo/issues"
65
+ },
66
+ "homepage": "https://github.com/goobz22/goobs-repo#readme",
67
+ "keywords": [
68
+ "react",
69
+ "confirmationCodeInput",
70
+ "confirmationCode",
71
+ "radioButton",
72
+ "radioGroup",
73
+ "contentSection",
74
+ "reusablePopup",
75
+ "next.js",
76
+ "material-ui",
77
+ "node.js",
78
+ "formData",
79
+ "form",
80
+ "formStore",
81
+ "form-validation",
82
+ "form-submission",
83
+ "form-caching",
84
+ "redis-alternative",
85
+ "useState-alternative",
86
+ "jotai-alternative",
87
+ "button",
88
+ "grid",
89
+ "responsive",
90
+ "flexgrid",
91
+ "jsonStorage",
92
+ "localStorage",
93
+ "sessionStorage",
94
+ "fileStorage",
95
+ "typography",
96
+ "server-actions",
97
+ "form-store",
98
+ "form-data",
99
+ "client-actions",
100
+ "reusable-server-actions",
101
+ "responsive-grid",
102
+ "styled-component",
103
+ "input-component",
104
+ "input-validation",
105
+ "button-validation",
106
+ "form-validation",
107
+ "searchbar",
108
+ "dropdown",
109
+ "client-side-validation",
110
+ "server-side-validation",
111
+ "multilinetextfield",
112
+ "textfield",
113
+ "phonenumber",
114
+ "password",
115
+ "email",
116
+ "number"
117
+ ],
118
+ "resolutions": {
119
+ "string-width": "^4.2.3",
120
+ "strip-ansi": "^6.0.1"
121
+ }
122
+ }
@@ -0,0 +1,8 @@
1
+ import React from 'react'
2
+ import type { AppProps } from 'next/app'
3
+
4
+ const MyApp = ({ Component, pageProps }: AppProps) => {
5
+ return <Component {...pageProps} />
6
+ }
7
+
8
+ export default MyApp
@@ -0,0 +1,21 @@
1
+ import { atom } from 'jotai'
2
+
3
+ export interface HelperFooterMessage {
4
+ status?: 'error' | 'success'
5
+ statusMessage?: string
6
+ spreadMessage?: string
7
+ spreadMessagePriority?: number
8
+ formname?: string
9
+ required?: boolean
10
+ }
11
+
12
+ export const helperFooterAtom = atom<Record<string, HelperFooterMessage>>({
13
+ default: {
14
+ status: 'success',
15
+ statusMessage: '',
16
+ spreadMessage: '',
17
+ spreadMessagePriority: 0,
18
+ formname: '',
19
+ required: false,
20
+ },
21
+ })
@@ -0,0 +1,241 @@
1
+ 'use client'
2
+
3
+ import React, { useEffect, useState } from 'react'
4
+ import { Button, Box, ButtonProps } from '@mui/material'
5
+ import StarIcon from '@mui/icons-material/Star'
6
+ import Typography from '../Typography'
7
+ import { useAtom } from 'jotai'
8
+ import { helperFooterAtom, HelperFooterMessage } from '../../atoms/helperfooter'
9
+ import { red } from '../../styles/palette'
10
+
11
+ export type ButtonAlignment = 'left' | 'center' | 'right'
12
+
13
+ export interface CustomButtonProps
14
+ extends Omit<ButtonProps, 'color' | 'variant'> {
15
+ text?: string
16
+ backgroundcolor?: string
17
+ outlinecolor?: string
18
+ fontcolor?: string
19
+ fontlocation?: ButtonAlignment
20
+ fontvariant?:
21
+ | 'arapeyh1'
22
+ | 'arapeyh2'
23
+ | 'arapeyh3'
24
+ | 'arapeyh4'
25
+ | 'arapeyh5'
26
+ | 'arapeyh6'
27
+ | 'arapeyparagraph'
28
+ | 'arapeyhelperheader'
29
+ | 'arapeyhelperfooter'
30
+ | 'interh1'
31
+ | 'interh2'
32
+ | 'interh3'
33
+ | 'interh4'
34
+ | 'interh5'
35
+ | 'interh6'
36
+ | 'interparagraph'
37
+ | 'interhelperheader'
38
+ | 'interhelperfooter'
39
+ | 'merrih1'
40
+ | 'merrih2'
41
+ | 'merrih3'
42
+ | 'merrih4'
43
+ | 'merrih5'
44
+ | 'merrih6'
45
+ | 'merriparagraph'
46
+ | 'merrihelperheader'
47
+ | 'merrihelperfooter'
48
+ icon?: React.ReactNode | false
49
+ iconcolor?: string
50
+ iconsize?: string
51
+ iconlocation?: 'left' | 'top' | 'right'
52
+ variant?: 'text' | 'outlined' | 'contained'
53
+ onClick?: () => void
54
+ helperfooter?: HelperFooterMessage
55
+ width?: string
56
+ formname?: string
57
+ name?: string
58
+ onFormSubmit?: (isSubmitted: boolean) => void
59
+ }
60
+
61
+ /**
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.
66
+ */
67
+ const CustomButton: React.FC<CustomButtonProps> = props => {
68
+ const {
69
+ text,
70
+ variant,
71
+ fontvariant = 'merriparagraph',
72
+ icon,
73
+ iconlocation,
74
+ iconsize,
75
+ type,
76
+ onClick,
77
+ fontcolor,
78
+ name,
79
+ formname,
80
+ outlinecolor,
81
+ backgroundcolor,
82
+ fontlocation,
83
+ iconcolor,
84
+ width,
85
+ onFormSubmit,
86
+ } = props
87
+
88
+ const [helperFooterAtomValue] = useAtom(helperFooterAtom)
89
+ const [errorMessage, setErrorMessage] = useState<string | undefined>(
90
+ undefined
91
+ )
92
+ const [isFormValid, setIsFormValid] = useState<boolean>(true)
93
+ const [isFormSubmitted, setIsFormSubmitted] = useState<boolean>(false)
94
+
95
+ /**
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.
100
+ */
101
+ const updateFormValidation = () => {
102
+ if (formname) {
103
+ const relevantFooters = Object.values(helperFooterAtomValue).filter(
104
+ footer => footer?.formname === formname
105
+ )
106
+
107
+ const errorFooters = relevantFooters.filter(
108
+ footer => footer?.status === 'error'
109
+ )
110
+
111
+ const emptyRequiredFields = relevantFooters.filter(
112
+ footer =>
113
+ footer?.required && (!footer.status || footer.status === 'error')
114
+ )
115
+
116
+ if (errorFooters.length > 0) {
117
+ const highestPriorityError = errorFooters.reduce((prev, current) =>
118
+ (prev.spreadMessagePriority || Infinity) <
119
+ (current.spreadMessagePriority || Infinity)
120
+ ? prev
121
+ : current
122
+ )
123
+ setErrorMessage(highestPriorityError.spreadMessage)
124
+ setIsFormValid(false)
125
+ } else if (emptyRequiredFields.length > 0) {
126
+ setErrorMessage('Please fill in all required fields.')
127
+ setIsFormValid(false)
128
+ } else {
129
+ setErrorMessage(undefined)
130
+ setIsFormValid(true)
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * useEffect hook that triggers the updateFormValidation function whenever the
137
+ * helperFooterAtomValue or formname changes.
138
+ */
139
+ useEffect(() => {
140
+ updateFormValidation()
141
+ }, [helperFooterAtomValue, formname])
142
+
143
+ /**
144
+ * useEffect hook that calls the onFormSubmit callback with the current isFormSubmitted state
145
+ * whenever the isFormSubmitted state or onFormSubmit prop changes.
146
+ */
147
+ useEffect(() => {
148
+ if (onFormSubmit) {
149
+ onFormSubmit(isFormSubmitted)
150
+ }
151
+ }, [isFormSubmitted, onFormSubmit])
152
+
153
+ /**
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.
157
+ * @returns The rendered icon element or null.
158
+ */
159
+ const renderIcon = () => {
160
+ if (icon === false) {
161
+ return null
162
+ }
163
+ if (React.isValidElement(icon)) {
164
+ return React.cloneElement(icon as React.ReactElement, {
165
+ style: { fontSize: iconsize },
166
+ })
167
+ }
168
+ return <StarIcon style={{ fontSize: iconsize }} />
169
+ }
170
+
171
+ /**
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.
175
+ */
176
+ const handleButtonClick = async () => {
177
+ setIsFormSubmitted(true)
178
+
179
+ if (!isFormValid) {
180
+ return
181
+ }
182
+
183
+ if (onClick) {
184
+ onClick()
185
+ }
186
+ }
187
+
188
+ return (
189
+ <Box
190
+ display="flex"
191
+ flexDirection="column"
192
+ alignItems="center"
193
+ width={width}
194
+ >
195
+ <Button
196
+ disableElevation
197
+ variant={variant}
198
+ startIcon={null}
199
+ endIcon={null}
200
+ type={type}
201
+ name={name}
202
+ onClick={handleButtonClick}
203
+ style={{
204
+ minWidth: text ? 'auto' : 'fit-content',
205
+ paddingLeft: text ? '8px' : '0',
206
+ paddingRight: text ? '8px' : '0',
207
+ justifyContent: fontlocation || 'center',
208
+ backgroundColor: backgroundcolor,
209
+ border: outlinecolor ? `1px solid ${outlinecolor}` : undefined,
210
+ color: iconcolor,
211
+ width: width,
212
+ }}
213
+ >
214
+ <Box display="flex" alignItems="center">
215
+ {iconlocation === 'left' && renderIcon()}
216
+ {text && (
217
+ <Typography
218
+ fontvariant={fontvariant}
219
+ fontcolor={fontcolor}
220
+ text={text}
221
+ />
222
+ )}
223
+ {iconlocation === 'right' && renderIcon()}
224
+ </Box>
225
+ </Button>
226
+ {isFormSubmitted && errorMessage && (
227
+ <Typography
228
+ fontvariant="merrihelperfooter"
229
+ fontcolor={red.main}
230
+ text={errorMessage}
231
+ marginTop={0.5}
232
+ marginBottom={0}
233
+ align="center"
234
+ width="100%"
235
+ />
236
+ )}
237
+ </Box>
238
+ )
239
+ }
240
+
241
+ export default CustomButton