diff --git a/package-lock.json b/package-lock.json index f14801a8..e218c17b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@xola/ui-kit", - "version": "2.1.6", + "version": "2.1.13", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@xola/ui-kit", - "version": "2.1.6", + "version": "2.1.13", "license": "MIT", "dependencies": { "@headlessui/react": "^1.4.0", diff --git a/package.json b/package.json index f57fdd02..24139813 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xola/ui-kit", - "version": "2.1.6", + "version": "2.1.13", "description": "Xola UI Kit", "license": "MIT", "files": [ diff --git a/src/components/Breakdown.jsx b/src/components/Breakdown.jsx index 08a42213..62e0de96 100644 --- a/src/components/Breakdown.jsx +++ b/src/components/Breakdown.jsx @@ -1,6 +1,7 @@ import clsx from "clsx"; import PropTypes from "prop-types"; import React, { createContext, useContext } from "react"; +import { isNumber } from "lodash"; import { Currency } from "./Utilities/Currency"; const colors = { @@ -37,7 +38,7 @@ const BreakdownItem = ({ children, info, methodIcon, secondary, value, className return ( - + {methodIcon} {children} @@ -49,9 +50,13 @@ const BreakdownItem = ({ children, info, methodIcon, secondary, value, className - - {value} - + {isNumber(value) ? ( + + {value} + + ) : ( + {value} + )} ); diff --git a/src/components/Buttons/Button.jsx b/src/components/Buttons/Button.jsx index aa0044ff..7b90e8ad 100644 --- a/src/components/Buttons/Button.jsx +++ b/src/components/Buttons/Button.jsx @@ -2,7 +2,7 @@ import clsx from "clsx"; import PropTypes from "prop-types"; import React from "react"; -const colors = { +export const colors = { standard: { common: "border-transparent text-white", // Common classes for each style primary: "bg-primary hover:bg-primary-darker disabled:bg-primary active:bg-primary", diff --git a/src/components/Buttons/SubmitButton.jsx b/src/components/Buttons/SubmitButton.jsx index 4fcaf06f..ef90f042 100644 --- a/src/components/Buttons/SubmitButton.jsx +++ b/src/components/Buttons/SubmitButton.jsx @@ -1,9 +1,10 @@ import { Transition } from "@headlessui/react"; import clsx from "clsx"; import PropTypes from "prop-types"; -import React from "react"; +import React, { useState, useEffect } from "react"; import { Spinner } from "../Spinner"; -import { Button } from "./Button"; +import { CheckIcon } from "../../icons/CheckIcon"; +import { Button, colors } from "./Button"; const loadingColors = { primary: "!bg-primary-light", @@ -14,32 +15,72 @@ const loadingColors = { danger: "!bg-danger-light", }; -export const SubmitButton = ({ color = "primary", isLoading, className, children, ...rest }) => { +export const SubmitButton = ({ + color = "primary", + isLoading, + isSuccess, + disabled = false, + className, + variant = "standard", + children, + ...rest +}) => { + const [showSuccess, setShowSuccess] = useState(false); + + useEffect(() => { + if (isSuccess && !isLoading) { + setShowSuccess(true); + const timer = setTimeout(() => setShowSuccess(false), 3000); + return () => clearTimeout(timer); + } + + if (isLoading && showSuccess) { + setShowSuccess(false); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isSuccess, isLoading]); + + const showTransition = isLoading || showSuccess; + return ( ); }; @@ -47,4 +88,8 @@ export const SubmitButton = ({ color = "primary", isLoading, className, children SubmitButton.propTypes = { ...Button.propTypes, isLoading: PropTypes.bool, + isSuccess: PropTypes.bool, + variant: PropTypes.oneOf(Object.keys(colors)), + // eslint-disable-next-line react/boolean-prop-naming + disabled: PropTypes.bool, }; diff --git a/src/components/DatePicker/DatePickerPopover.jsx b/src/components/DatePicker/DatePickerPopover.jsx index 00ecf55b..eeb95d37 100644 --- a/src/components/DatePicker/DatePickerPopover.jsx +++ b/src/components/DatePicker/DatePickerPopover.jsx @@ -1,6 +1,6 @@ import clsx from "clsx"; import PropTypes from "prop-types"; -import React, { cloneElement, forwardRef, useState } from "react"; +import React, { cloneElement, forwardRef, useEffect, useState } from "react"; import { CalendarIcon, DownArrowIcon } from "../.."; import { formatDate } from "../../helpers/date"; import { Input } from "../Forms/Input"; @@ -42,11 +42,13 @@ export const DatePickerPopover = ({ }; const handleClickOutside = () => { - // Revert back to the original value because the user didn't apply the changes - onChange(originalValue); toggleVisibility(); }; + useEffect(() => { + setOriginalValue(value); + }, [value]); + return ( -
+
{position === "right" ? : null}
- + {showArrow && } diff --git a/src/stories/Forms/SubmitButton.stories.js b/src/stories/Forms/SubmitButton.stories.js index c448e0c7..6432dd55 100644 --- a/src/stories/Forms/SubmitButton.stories.js +++ b/src/stories/Forms/SubmitButton.stories.js @@ -35,14 +35,24 @@ const SubmitButtonStories = { export const Default = ({ isLoading, ...rest }) => { const [showLoading, setShowLoading] = useState(isLoading); + const [showSuccess, setShowSuccess] = useState(false); + + const handleClick = () => { + setShowLoading(!showLoading); + setTimeout(() => { + setShowSuccess(true); + setShowLoading(false); + }, 2000); + }; + return (
- setShowLoading(!showLoading)}> + Submit - setShowLoading(!showLoading)}> + Button with really long text
@@ -51,7 +61,8 @@ export const Default = ({ isLoading, ...rest }) => { {...rest} color="success" isLoading={showLoading} - onClick={() => setShowLoading(!showLoading)} + isSuccess={showSuccess} + onClick={handleClick} > Submit @@ -59,8 +70,9 @@ export const Default = ({ isLoading, ...rest }) => { setShowLoading(!showLoading)} + onClick={handleClick} > Button with really long text @@ -68,18 +80,21 @@ export const Default = ({ isLoading, ...rest }) => {
setShowLoading(!showLoading)} + onClick={handleClick} > Submit setShowLoading(!showLoading)} + onClick={handleClick} + > Button with really long text