ui icon indicating copy to clipboard operation
ui copied to clipboard

Add styles to Bar in Progress component

Open Judge-Paul opened this issue 1 year ago • 7 comments
trafficstars

I noticed I couldn't change the bar color on the progress component without altering the actual component

<ProgressPrimitive.Indicator
  className="h-full w-full flex-1 bg-primary transition-all"
  style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
/>

like this

<ProgressPrimitive.Indicator
  className="h-full w-full flex-1 bg-[#6160DC] transition-all"
  style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
/>

So to add styles to my bar I created a property barClassName and passed it as a prop to the component

const Progress = React.forwardRef<
  React.ElementRef<typeof ProgressPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
>(({ className, value, barClassName, ...props }, ref) => (
  <ProgressPrimitive.Root
    ref={ref}
    className={cn(
      "relative h-4 w-full overflow-hidden rounded-full bg-secondary",
      className,
    )}
    {...props}
  >
    <ProgressPrimitive.Indicator
      className={cn(
        "h-full w-full flex-1 bg-primary transition-all",
        barClassName,
      )}
      style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
    />
  </ProgressPrimitive.Root>
));

I also created an issue to add this to the radix primitive but if it isn't accepted, I was hoping you could create a workaround that will allow us to pass a barClassName or similar property to the component

Judge-Paul avatar Jan 27 '24 11:01 Judge-Paul

I changed it to look like this so I won't have to update the radix files

interface ExtraProps {
  barClassName?: string;
}

const Progress = React.forwardRef<
  React.ElementRef<typeof ProgressPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> & ExtraProps
>(({ className, value, barClassName, ...props }, ref) => (
  <ProgressPrimitive.Root
    ref={ref}
    className={cn(
      "relative h-4 w-full overflow-hidden rounded-full bg-secondary",
      className,
    )}
    {...props}
  >
    <ProgressPrimitive.Indicator
      className={cn(
        "h-full w-full flex-1 bg-primary transition-all",
        barClassName,
      )}
      style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
    />
  </ProgressPrimitive.Root>
));

Judge-Paul avatar Jan 28 '24 07:01 Judge-Paul

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Feb 19 '24 23:02 shadcn

@shadcn the issue wasn't reviewed (to the best of my knowledge)

Judge-Paul avatar Feb 20 '24 09:02 Judge-Paul

@Judge-Paul Agreed. Reopening this. (note: I know it says I closed but it was done via an action - sorry about that.

shadcn avatar Feb 20 '24 13:02 shadcn

@Judge-Paul Agreed. Reopening this. (note: I know it says I closed but it was done via an action - sorry about that.

@shadcn figured it was closed automatically, hopefully, you or any of the collaborators take a look at it.

Judge-Paul avatar Feb 20 '24 13:02 Judge-Paul

any update on this? ran into the same thing

cdeck95 avatar Apr 26 '24 19:04 cdeck95

I changed it to look like this so I won't have to update the radix files

interface ExtraProps {
  barClassName?: string;
}

const Progress = React.forwardRef<
  React.ElementRef<typeof ProgressPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> & ExtraProps
>(({ className, value, barClassName, ...props }, ref) => (
  <ProgressPrimitive.Root
    ref={ref}
    className={cn(
      "relative h-4 w-full overflow-hidden rounded-full bg-secondary",
      className,
    )}
    {...props}
  >
    <ProgressPrimitive.Indicator
      className={cn(
        "h-full w-full flex-1 bg-primary transition-all",
        barClassName,
      )}
      style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
    />
  </ProgressPrimitive.Root>
));

@cdeck95 you can just use this component, I doubt it's getting added any time soon

Judge-Paul avatar Apr 26 '24 20:04 Judge-Paul

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Jun 11 '24 23:06 shadcn