Skip to content

Commit

Permalink
Error message update (#65)
Browse files Browse the repository at this point in the history
* Updated ErrorMessage component to have new props named showIcon,truncateMessage and maxLength

* updated Fieldv1

* updated ui-components and css versions
  • Loading branch information
Swathi-eGov authored May 21, 2024
1 parent 6ae3652 commit 8c9ff1c
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 85 deletions.
1 change: 1 addition & 0 deletions react/css/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ frontend/micro-ui/web/public/index.html
# Changelog
```bash
1.8.2-coreui.15 Updated ErrorMessage styles
1.8.2-coreui.14 updated dropdown checkbox css
1.8.2-coreui.13 added spacers
1.8.2-coreui.12 updated css for toast info and category option css
Expand Down
2 changes: 1 addition & 1 deletion react/css/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egovernments/digit-ui-css",
"version": "1.8.2-coreui.14",
"version": "1.8.2-coreui.15",
"license": "MIT",
"main": "dist/index.css",
"author": "Jagankumar <[email protected]>",
Expand Down
23 changes: 13 additions & 10 deletions react/css/src/digitv2/components/ErrorMessage.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
@import url("../index.scss");
@import url("../typography.scss");

.digit-error-message {
@extend .alert-error;
@extend .typography.text-body-s;
@apply block mb-md;
}
.digit-error-icon-message-wrap {
@apply flex w-full whitespace-pre-wrap break-words;
gap: theme(digitv2.spacers.spacer1);

.digit-employee-card {
.digit-error-icon{
@apply flex items-center;
width: theme(digitv2.spacers.spacer4);
height: theme(digitv2.lineHeight.lineheight2);
}
.digit-error-message {
@extend .typography.text-body-s;
font-size: 12px;
margin-top: -21px;
@extend .typography.body-s;
@apply w-full;
margin: theme(digitv2.spacers.spacer0);
color: theme(digitv2.lightTheme.alert-error)
}
}
}
18 changes: 0 additions & 18 deletions react/css/src/digitv2/components/fieldV1.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,4 @@
.digit-charcount {
@apply justify-end;
}

.digit-error {
@apply flex;
gap: theme(digitv2.spacers.spacer1);

.digit-error-icon{
@apply items-center;
display: flex;
width:theme(digitv2.spacers.spacer4);
height:1.37rem;
}
.digit-error-message {
@extend .typography.body-s;
@apply w-full;
margin: theme(digitv2.spacers.spacer0);
color: theme(digitv2.lightTheme.alert-error)
}
}
}
2 changes: 1 addition & 1 deletion react/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "webpack --mode production"
},
"dependencies": {
"@egovernments/digit-ui-components": "0.0.1-beta.22",
"@egovernments/digit-ui-components": "0.0.1-beta.23",
"@egovernments/digit-ui-libraries": "1.8.2-beta.1",
"@egovernments/digit-ui-module-common": "1.7.10",
"@egovernments/digit-ui-module-core": "1.8.1-beta.6",
Expand Down
2 changes: 1 addition & 1 deletion react/example/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
rel='stylesheet' type='text/css'>
<link
rel="stylesheet"
href="https://unpkg.com/@egovernments/[email protected].14/dist/index.css"
href="https://unpkg.com/@egovernments/[email protected].15/dist/index.css"
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#00bcd1" />
Expand Down
2 changes: 1 addition & 1 deletion react/modules/Project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"@egovernments/digit-ui-react-components": "1.8.1-beta.4",
"@egovernments/digit-ui-components": "0.0.1-beta.22",
"@egovernments/digit-ui-components": "0.0.1-beta.23",
"lodash": "^4.17.21",
"react": "17.0.2",
"react-date-range": "^1.4.0",
Expand Down
2 changes: 1 addition & 1 deletion react/modules/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prepublish": "yarn build"
},
"dependencies": {
"@egovernments/digit-ui-components": "0.0.1-beta.22",
"@egovernments/digit-ui-components": "0.0.1-beta.23",
"@egovernments/digit-ui-react-components": "1.8.1-beta.4",
"react": "17.0.2",
"react-dom": "17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion react/modules/sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"@egovernments/digit-ui-react-components": "1.8.1-beta.4",
"@egovernments/digit-ui-components": "0.0.1-beta.22",
"@egovernments/digit-ui-components": "0.0.1-beta.23",
"react": "17.0.2",
"react-date-range": "^1.4.0",
"react-dom": "17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@egovernments/digit-ui-module-sample": "0.0.1",
"@egovernments/digit-ui-react-components": "1.7.10",
"@egovernments/digit-ui-svg-components": "1.0.4",
"@egovernments/digit-ui-components": "0.0.1-beta.22",
"@egovernments/digit-ui-components": "0.0.1-beta.23",
"babel-loader": "8.1.0",
"clean-webpack-plugin": "4.0.0",
"css-loader": "5.2.6",
Expand Down
1 change: 1 addition & 0 deletions react/ui-components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ yarn storybook
# Changelog

```bash
0.0.1-beta.23 Updated ErrorMessage component to have new props named showIcon,truncateMessage and maxLength
0.0.1-beta.22 From this version of ui-components the Toast component will have a new prop named type, replacing the seperate props for info,warning and error
0.0.1-beta.21 Added categorySelectAllState in the nestedmultiselect variant of multiselectdropdown
0.0.1-beta.20 updated multiselectdropdown categoryselectall functionality and added key navigation for dropdown options
Expand Down
4 changes: 2 additions & 2 deletions react/ui-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egovernments/digit-ui-components",
"version": "0.0.1-beta.22",
"version": "0.0.1-beta.23",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.modern.js",
Expand Down Expand Up @@ -51,7 +51,7 @@
"dist"
],
"dependencies": {
"@egovernments/digit-ui-css": "1.8.2-coreui.14",
"@egovernments/digit-ui-css": "1.8.2-coreui.15",
"@egovernments/digit-ui-libraries": "1.8.1-beta.1",
"@egovernments/digit-ui-svg-components": "1.0.4",
"@googlemaps/js-api-loader": "1.13.10",
Expand Down
43 changes: 37 additions & 6 deletions react/ui-components/src/atoms/ErrorMessage.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
import React from "react";
import PropTypes from "prop-types";
import { SVG } from "./SVG";
import StringManipulator from "./StringManipulator";

const ErrorMessage = ({ message, className = "", style = {} }) => {
const ErrorMessage = ({
wrapperClassName = "",
wrapperStyles = {},
showIcon,
iconStyles = {},
message,
className = "",
style = {},
truncateMessage,
maxLength,
}) => {
return (
<React.Fragment>
<h2 className={`digit-error-message ${className}`} style={style}>
{message}
</h2>
</React.Fragment>
<div
className={`digit-error-icon-message-wrap ${
wrapperClassName ? wrapperClassName : ""
}`}
style={wrapperStyles}
>
{showIcon && (
<div className="digit-error-icon" style={iconStyles}>
<SVG.Info width="1rem" height="1rem" fill="#B91900" />
</div>
)}
<div className={`digit-error-message ${className}`} style={style}>
{truncateMessage
? StringManipulator(
"TOSENTENCECASE",
StringManipulator("TRUNCATESTRING", message, {
maxLength: maxLength || 256,
})
)
: StringManipulator("TOSENTENCECASE", message)}
</div>
</div>
);
};

ErrorMessage.propTypes = {
className: PropTypes.string,
style: PropTypes.object,
message: PropTypes.string,
showIcon: PropTypes.bool,
truncateMessage: PropTypes.bool,
};

export default ErrorMessage;
62 changes: 23 additions & 39 deletions react/ui-components/src/hoc/FieldV1.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,12 @@ const FieldV1 = ({
const renderDescriptionOrError = () => {
if (error) {
return (
<div
className="digit-error"
style={{
width: "100%",
whiteSpace: "pre-wrap",
wordBreak: "break-word",
marginTop: "0px",
display:"flex"
}}
>
<div className="digit-error-icon" style={{display:"flex"}}>
<SVG.Info width="1rem" height="1rem" fill="#B91900" />
</div>
<ErrorMessage
message={
StringManipulator(
"TOSENTENCECASE",
StringManipulator("TRUNCATESTRING", t(error), { maxLength: 256 })
)
}
/>
</div>
<ErrorMessage
message={t(error)}
truncateMessage={true}
maxLength={256}
showIcon={true}
/>
);
} else if (description) {
return (
Expand All @@ -122,14 +106,12 @@ const FieldV1 = ({
lineHeight: "1.5rem",
}}
>
{
StringManipulator(
"TOSENTENCECASE",
StringManipulator("TRUNCATESTRING", t(description), {
maxLength: 256,
})
)
}
{StringManipulator(
"TOSENTENCECASE",
StringManipulator("TRUNCATESTRING", t(description), {
maxLength: 256,
})
)}
</CardText>
);
}
Expand Down Expand Up @@ -239,7 +221,7 @@ const FieldV1 = ({
);
case "multiselectdropdown":
return (
<div style={{ display: "grid", gridAutoFlow: "row" ,width:"100%"}}>
<div style={{ display: "grid", gridAutoFlow: "row", width: "100%" }}>
<MultiSelectDropdown
options={populators?.options}
optionsKey={populators?.optionsKey}
Expand Down Expand Up @@ -369,20 +351,22 @@ const FieldV1 = ({
nonEditable ? "noneditable" : ""
} ${populators?.wrapLabel ? "wraplabel" : ""}`}
>
<div className={`label-container ${
populators?.wrapLabel ? "wraplabel" : ""
}`}>
<div
className={`label-container ${
populators?.wrapLabel ? "wraplabel" : ""
}`}
>
<div
className={`label-styles ${
populators?.wrapLabel ? "wraplabel" : ""
}`}
>
{StringManipulator(
"TOSENTENCECASE",
StringManipulator("TRUNCATESTRING", t(label), {
maxLength: 64,
})
)}
"TOSENTENCECASE",
StringManipulator("TRUNCATESTRING", t(label), {
maxLength: 64,
})
)}
</div>
<div style={{ color: "#B91900" }}>{required ? " * " : null}</div>
{infoMessage ? (
Expand Down
76 changes: 76 additions & 0 deletions react/ui-components/src/hoc/stories/ErrorMessage.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { Children } from "react";
import { ErrorMessage } from "../../atoms";
import { truncate } from "lodash";

export default {
title: "Atom-Groups/ErrorMessage",
component: ErrorMessage,
argTypes: {
wrapperClassName: {
control: "text",
},
wrapperStyles: {
control: { type: "object" },
},
showIcon: {
control: "boolean",
},
iconStyles: {
control: { type: "object" },
},
message: {
control: "text",
},
className: {
control: "text",
},
style: {
control: { type: "object" },
},
truncateMessage: {
control: "boolean",
},
maxLength:{
control:"text"
}
},
};

const Template = (args) => <ErrorMessage {...args} />;

const commonArgs = {
wrapperClassName: "",
wrapperStyles: {},
showIcon: false,
iconStyles: {},
message: "",
className: "",
style: {},
truncateMessage:false,
maxLength:""
};

// Default ErrorMessage
export const Default = Template.bind({});
Default.args = {
...commonArgs,
message: "Error Message",
};

// ErrorMessage with icon
export const WithIcon = Template.bind({});
WithIcon.args = {
...commonArgs,
message: "Error Message With Icon",
showIcon: true,
};

// ErrorMessage with icon
export const WithTruncateMessage = Template.bind({});
WithTruncateMessage.args = {
...commonArgs,
message: "Error with truncateMessage as true",
showIcon: true,
truncateMessage:true,
maxLength:10
};
4 changes: 2 additions & 2 deletions react/ui-components/yarn-error.log
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Trace:
npm manifest:
{
"name": "@egovernments/digit-ui-components",
"version": "0.0.1-beta.22",
"version": "0.0.1-beta.23",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.modern.js",
Expand Down Expand Up @@ -80,7 +80,7 @@ npm manifest:
"dist"
],
"dependencies": {
"@egovernments/digit-ui-css": "1.8.2-coreui.14",
"@egovernments/digit-ui-css": "1.8.2-coreui.15",
"@egovernments/digit-ui-libraries": "1.8.1-beta.1",
"@egovernments/digit-ui-svg-components": "1.0.4",
"@googlemaps/js-api-loader": "1.13.10",
Expand Down
Loading

0 comments on commit 8c9ff1c

Please sign in to comment.