@spark-ui/progress 0.1.0 → 0.2.1

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,24 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.2.1](https://github.com/adevinta/spark/compare/@spark-ui/progress@0.2.0...@spark-ui/progress@0.2.1) (2023-08-29)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **progress:** improve animation ([5ffcb1d](https://github.com/adevinta/spark/commit/5ffcb1dddebf1feb1f5634832ad0ca91a639ac10))
11
+ - **progress:** update styles ([4532c10](https://github.com/adevinta/spark/commit/4532c100361a6314e6de5be76f0e13b1017701a0))
12
+
13
+ # [0.2.0](https://github.com/adevinta/spark/compare/@spark-ui/progress@0.1.0...@spark-ui/progress@0.2.0) (2023-08-25)
14
+
15
+ ### Features
16
+
17
+ - **progress:** add documentation and tests ([19ac4e5](https://github.com/adevinta/spark/commit/19ac4e5f08d2dbb38415ae4ca4e2000d75a59506))
18
+ - **progress:** add label to progress component ([efa8f28](https://github.com/adevinta/spark/commit/efa8f289ef1dc7379a297d0c2c8e74c87b6194cc))
19
+ - **progress:** improve demo and API ([0387bc7](https://github.com/adevinta/spark/commit/0387bc7bc32b5f3bc976b9b9a172b1b62389ee4e))
20
+ - **progress:** remove not needed id ([62ec87a](https://github.com/adevinta/spark/commit/62ec87a90c2c384a5b98335d4f79b30cc76eb916))
21
+ - **progress:** update animation ([520f54a](https://github.com/adevinta/spark/commit/520f54af5f2586725cd56bc2434dae6d5385d968))
22
+ - **progress:** update deps and minor changes ([5fd0450](https://github.com/adevinta/spark/commit/5fd04503bc7d6d6ea76c2eb4e80340ad52946c76))
23
+
6
24
  # 0.1.0 (2023-08-21)
7
25
 
8
26
  ### Features
@@ -1,5 +1,7 @@
1
1
  import { ProgressProps as ProgressPrimitiveProps } from '@radix-ui/react-progress';
2
- export type ProgressProps = ProgressPrimitiveProps;
3
- export declare const Progress: import("react").ForwardRefExoticComponent<ProgressPrimitiveProps & {
2
+ export interface ProgressProps extends ProgressPrimitiveProps {
3
+ isIndeterminate?: boolean;
4
+ }
5
+ export declare const Progress: import("react").ForwardRefExoticComponent<ProgressProps & {
4
6
  children?: import("react").ReactNode;
5
7
  } & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,5 @@
1
+ import { ComponentPropsWithoutRef } from 'react';
2
+ export type ProgressBarProps = ComponentPropsWithoutRef<'div'>;
3
+ export declare const ProgressBar: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
4
+ children?: import("react").ReactNode;
5
+ } & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,8 @@
1
+ export interface ProgressContextValue {
2
+ value: number;
3
+ max: number;
4
+ isIndeterminate: boolean;
5
+ onLabelId: (id?: string) => void;
6
+ }
7
+ export declare const ProgressContext: import("react").Context<ProgressContextValue | null>;
8
+ export declare const useProgress: () => ProgressContextValue;
@@ -0,0 +1,5 @@
1
+ import { ComponentPropsWithoutRef } from 'react';
2
+ export type ProgressIndicatorProps = ComponentPropsWithoutRef<'div'>;
3
+ export declare const ProgressIndicator: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
4
+ children?: import("react").ReactNode;
5
+ } & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,5 @@
1
+ import { VariantProps } from 'class-variance-authority';
2
+ export declare const progressIndicatorStyles: (props?: ({
3
+ isIndeterminate?: boolean | null | undefined;
4
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
5
+ export type ProgressIndicatorStylesProps = VariantProps<typeof progressIndicatorStyles>;
@@ -0,0 +1,3 @@
1
+ import { ComponentPropsWithoutRef } from 'react';
2
+ export type ProgressLabelProps = ComponentPropsWithoutRef<'span'>;
3
+ export declare const ProgressLabel: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & import("react").RefAttributes<HTMLSpanElement>>;
package/dist/index.d.ts CHANGED
@@ -1 +1,13 @@
1
- export { Progress } from './Progress';
1
+ import { FC } from 'react';
2
+ import { ProgressProps } from './Progress';
3
+ import { ProgressBar } from './ProgressBar';
4
+ import { ProgressIndicator } from './ProgressIndicator';
5
+ import { ProgressLabel } from './ProgressLabel';
6
+ export { type ProgressBarProps } from './ProgressBar';
7
+ export { type ProgressLabelProps } from './ProgressLabel';
8
+ export { type ProgressIndicatorProps } from './ProgressIndicator';
9
+ export declare const Progress: FC<ProgressProps> & {
10
+ Label: typeof ProgressLabel;
11
+ Bar: typeof ProgressBar;
12
+ Indicator: typeof ProgressIndicator;
13
+ };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),s=require("@radix-ui/react-progress"),o=e.forwardRef(({value:t,...a},l)=>{const r=t??0;return e.createElement(s.Progress,{className:"relative h-sz-4 w-full transform-gpu overflow-hidden rounded-sm bg-on-background/dim-4",value:r,ref:l,...a},e.createElement(s.ProgressIndicator,{className:"h-full w-full bg-basic",style:{transform:`translateX(-${100-r}%)`}}))});exports.Progress=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),g=require("@radix-ui/react-progress"),m=require("class-variance-authority"),P=require("@radix-ui/react-id"),y=require("@spark-ui/use-merge-refs"),b=e.createContext(null),p=()=>{const r=e.useContext(b);if(!r)throw new Error("useProgress must be used within a Progress provider");return r},I=m.cva(["h-full w-full","bg-basic","transition-transform duration-400"],{variants:{isIndeterminate:{true:["absolute","-translate-x-1/2","animate-standalone-indeterminate-bar"],false:[]}}}),u=e.forwardRef(({className:r,style:a,...s},t)=>{const{value:n,max:l,isIndeterminate:o}=p(),i=(l-n)/l*100;return e.createElement(g.ProgressIndicator,{className:I({isIndeterminate:o,className:r}),style:{...a,...!o&&{transform:`translateX(-${i}%)`}},ref:t,...s})});u.displayName="Progress.Indicator";const f=e.forwardRef(({className:r,children:a=e.createElement(u,null),...s},t)=>e.createElement("div",{className:m.cx("relative h-sz-4 w-full transform-gpu overflow-hidden rounded-sm bg-on-background/dim-4",r),ref:t,...s},a));f.displayName="Progress.Bar";const v=e.forwardRef(({className:r,value:a,max:s=100,isIndeterminate:t=!1,children:n=e.createElement(f,null),...l},o)=>{const[i,d]=e.useState(),x=e.useMemo(()=>({value:a??0,max:s,isIndeterminate:t,onLabelId:d}),[s,a,t,d]);return e.createElement(b.Provider,{"data-spark-component":"progress",value:x},e.createElement(g.Progress,{ref:o,className:m.cx("flex flex-col gap-sm",r),value:a,"aria-labelledby":i,max:s,...l},n))});v.displayName="Progress";const N=e.forwardRef(({id:r,children:a,...s},t)=>{const n=P.useId(r),{onLabelId:l}=p(),o=e.useCallback(d=>{l(d?n:void 0)},[n,l]),i=y.useMergeRefs(t,o);return e.createElement("span",{id:n,className:"text-body-2 text-on-surface",ref:i,...s},a)});N.displayName="Progress.Label";const c=Object.assign(v,{Label:N,Bar:f,Indicator:u});c.Label.displayName="Progress.Label",c.Bar.displayName="Progress.Bar",exports.Progress=c;
package/dist/index.mjs CHANGED
@@ -1,9 +1,34 @@
1
- import e, { forwardRef as t } from "react";
2
- import { Progress as l, ProgressIndicator as n } from "@radix-ui/react-progress";
3
- const c = t(({ value: s, ...a }, o) => {
4
- const r = s ?? 0;
5
- return e.createElement(l, { className: "relative h-sz-4 w-full transform-gpu overflow-hidden rounded-sm bg-on-background/dim-4", value: r, ref: o, ...a }, e.createElement(n, { className: "h-full w-full bg-basic", style: { transform: `translateX(-${100 - r}%)` } }));
1
+ import l, { createContext as P, useContext as y, forwardRef as c, useState as I, useMemo as h, useCallback as E } from "react";
2
+ import { ProgressIndicator as w, Progress as L } from "@radix-ui/react-progress";
3
+ import { cva as B, cx as g } from "class-variance-authority";
4
+ import { useId as k } from "@radix-ui/react-id";
5
+ import { useMergeRefs as C } from "@spark-ui/use-merge-refs";
6
+ const p = P(null), b = () => {
7
+ const e = y(p);
8
+ if (!e)
9
+ throw new Error("useProgress must be used within a Progress provider");
10
+ return e;
11
+ }, M = B(["h-full w-full", "bg-basic", "transition-transform duration-400"], { variants: { isIndeterminate: { true: ["absolute", "-translate-x-1/2", "animate-standalone-indeterminate-bar"], false: [] } } }), d = c(({ className: e, style: a, ...r }, s) => {
12
+ const { value: t, max: n, isIndeterminate: o } = b(), m = (n - t) / n * 100;
13
+ return l.createElement(w, { className: M({ isIndeterminate: o, className: e }), style: { ...a, ...!o && { transform: `translateX(-${m}%)` } }, ref: s, ...r });
6
14
  });
15
+ d.displayName = "Progress.Indicator";
16
+ const u = c(({ className: e, children: a = l.createElement(d, null), ...r }, s) => l.createElement("div", { className: g("relative h-sz-4 w-full transform-gpu overflow-hidden rounded-sm bg-on-background/dim-4", e), ref: s, ...r }, a));
17
+ u.displayName = "Progress.Bar";
18
+ const N = c(({ className: e, value: a, max: r = 100, isIndeterminate: s = !1, children: t = l.createElement(u, null), ...n }, o) => {
19
+ const [m, i] = I(), x = h(() => ({ value: a ?? 0, max: r, isIndeterminate: s, onLabelId: i }), [r, a, s, i]);
20
+ return l.createElement(p.Provider, { "data-spark-component": "progress", value: x }, l.createElement(L, { ref: o, className: g("flex flex-col gap-sm", e), value: a, "aria-labelledby": m, max: r, ...n }, t));
21
+ });
22
+ N.displayName = "Progress";
23
+ const v = c(({ id: e, children: a, ...r }, s) => {
24
+ const t = k(e), { onLabelId: n } = b(), o = E((i) => {
25
+ n(i ? t : void 0);
26
+ }, [t, n]), m = C(s, o);
27
+ return l.createElement("span", { id: t, className: "text-body-2 text-on-surface", ref: m, ...r }, a);
28
+ });
29
+ v.displayName = "Progress.Label";
30
+ const f = Object.assign(N, { Label: v, Bar: u, Indicator: d });
31
+ f.Label.displayName = "Progress.Label", f.Bar.displayName = "Progress.Bar";
7
32
  export {
8
- c as Progress
33
+ f as Progress
9
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-ui/progress",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,7 +12,10 @@
12
12
  "build": "vite build"
13
13
  },
14
14
  "dependencies": {
15
- "@radix-ui/react-progress": "1.0.3"
15
+ "@radix-ui/react-id": "1.0.1",
16
+ "@radix-ui/react-progress": "1.0.3",
17
+ "@spark-ui/use-merge-refs": "^0.3.4",
18
+ "class-variance-authority": "0.7.0"
16
19
  },
17
20
  "peerDependencies": {
18
21
  "@spark-ui/theme-utils": "^3.0.2",
@@ -30,5 +33,5 @@
30
33
  },
31
34
  "homepage": "https://sparkui.vercel.app",
32
35
  "license": "MIT",
33
- "gitHead": "3b9aceb8fc1c0b62cad5536d6585b6300b4357d1"
36
+ "gitHead": "f620242462b456136fd398e593b6a1d8a6cbc0a5"
34
37
  }