flowbite-react icon indicating copy to clipboard operation
flowbite-react copied to clipboard

Simplify the usage of spinner inside the Button component

Open rluders opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe.

Currently in order to have a Spinner inside a Button to indicate processing we need to manually build all the logic. Lets make it something present inside the component.

Describe the solution you'd like

Some ideas:

<Button type="submit" color="info" processing={true} processingText="Sending...">Send</Button>

Describe alternatives you've considered n/a

Additional context n/a

rluders avatar Jun 02 '22 16:06 rluders

Thoughts on <Button spinner spinnerText="Sending..">Send</Button> here? This is easy to implement.

tulup-conner avatar Jul 31 '22 21:07 tulup-conner

Yep, I think that it makes sense.

rluders avatar Aug 01 '22 06:08 rluders

I'm going to implement it.

aminlotfi avatar Jan 13 '23 13:01 aminlotfi

I had to position the spinner absolutely inside the button & add custom paddings based on the size.

Looks good, maybe for lg the spinner is too big.

import {
  Button as BaseButton,
  ButtonProps,
  Spinner,
  useTheme,
} from "flowbite-react";

export const Button = ({
  loadingText = "Načitávam...",
  children,
  isLoading,
  size,
  color = "primary",
  ...props
}: Partial<{ isLoading: boolean; loadingText: string }> & ButtonProps) => {
  return (
    <BaseButton
      disabled={isLoading}
      color={color}
      size={size}
      className="relative"
      {...props}
    >
      {isLoading ? (
        <>
          <Spinner
            size={size}
            color={color}
            className={`absolute ${size === "sm" ? "top-2.5" : "top-2"}`}
          />{" "}
          <span
            className={
              size === "lg" ? "pl-12" : size === "sm" ? "pl-6" : "pl-8"
            }
          >
            {loadingText}{" "}
          </span>
        </>
      ) : (
        children
      )}
    </BaseButton>
  );
};

image

MiroslavPetrik avatar Apr 17 '23 10:04 MiroslavPetrik

I updated the existing PR for this one. Maybe someone could test and review it.

rluders avatar Apr 17 '23 18:04 rluders

Hey, how can I use/install it? :) npm i flowbite flowbite-react is not working.

timootten avatar Apr 22 '23 14:04 timootten