@kakadu/components 6.17.1 → 6.18.0

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.
@@ -3,6 +3,7 @@ type GaugeDisplayProperties = {
3
3
  readonly label: string;
4
4
  readonly size?: 'small' | 'medium' | 'large';
5
5
  readonly percentage?: number;
6
+ readonly isInverted?: boolean;
6
7
  readonly showSymbol?: boolean;
7
8
  readonly isAnimated?: boolean;
8
9
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../jsx-runtime-CZa898vN.js"),s=require("react"),M=require("@kuma-ui/core"),x=require("./text.js"),R=require("./flex.js"),N={0:["#D60D43"],15:["#D60D43","#FFCD45"],30:["#D6460D","#ffda54"],50:["#D6860D","#F1DC3B","#CEE838"],65:["#D6BE0D","#FFD045","#6DE838"],80:["#D9E838","#93E838","#3EE838"],100:["#55EB62","#38E99A","#5EEA52"]},P=Object.keys(N).map(t=>Number.parseInt(t,10)).sort((t,n)=>n-t);function g({label:t,size:n,percentage:o=0,showSymbol:d=!0,isAnimated:p}){const[j,m]=s.useState(o);s.useEffect(()=>{if(p){m(0);const u=300,i=10,q=30,E=.65,f=[];let h=u;for(let c=0;c<o;c+=1){const F=(c+1)/o,D=Math.min(Math.max((F-E)/(1-E),0),1),$=1-(1-D)*(1-D);h+=i+q*$,f.push(setTimeout(()=>{m(c+1)},h))}return()=>{for(const c of f)clearTimeout(c)}}m(o)},[p,o]);const r=s.useMemo(()=>Math.max(0,Math.min(100,j)),[j]),v=s.useMemo(()=>r/100,[r]),a=s.useMemo(()=>{for(const u of P)if(r>=u)return N[u];return[]},[r]),k=s.useMemo(()=>a.length,[a]),y=s.useMemo(()=>a.at(0),[a]),C=s.useMemo(()=>a.at(-1),[a]),b=s.useMemo(()=>a.map((u,i)=>`${u} ${Math.round(i/k*100)}%`).join(", "),[a,k]),l=s.useMemo(()=>Math.round(r),[r]);return e.jsxRuntimeExports.jsxs("div",{style:{"--percentage":`${l}%`,"--percentage-factor":v,"--gradient":b,"--start-color":y,"--end-color":C},role:"meter","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":t,className:M.cx("kakadu-components-3163931049",n==="small"&&"kakadu-components-1272093092",n==="large"&&"kakadu-components-553520060"),children:[l>0?e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-707327569"}):null,e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2636723344",children:e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2810161405"})}),e.jsxRuntimeExports.jsxs("div",{className:"kakadu-components-114088345",children:[e.jsxRuntimeExports.jsx("span",{className:M.cx("kakadu-components-3402528359",d&&"kakadu-components-3473805935"),children:l}),d?e.jsxRuntimeExports.jsx(x.Span,{className:"kakadu-components-810313368",children:"%"}):null]}),l>0&&l<100?e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-967240013",children:e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-3225063030"})}):null]})}function S({title:t,description:n,...o}){return!t&&!n?e.jsxRuntimeExports.jsx(g,{...o}):e.jsxRuntimeExports.jsxs(R.default,{preset:"center",gap:1.5,children:[e.jsxRuntimeExports.jsx(g,{...o}),e.jsxRuntimeExports.jsxs(R.default,{preset:"center",gap:.25,children:[t?e.jsxRuntimeExports.jsx(x.Label,{className:"kakadu-components-1477072149",children:t}):null,n?e.jsxRuntimeExports.jsx(x.Span,{className:"kakadu-components-2235337211",children:n}):null]})]})}exports.default=S;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../jsx-runtime-CZa898vN.js"),a=require("react"),N=require("@kuma-ui/core"),P=require("../utilities/clamp.js"),x=require("./text.js"),g=require("./flex.js"),M={0:["#D60D43"],15:["#D60D43","#FFCD45"],30:["#D6460D","#ffda54"],50:["#D6860D","#F1DC3B","#CEE838"],65:["#D6BE0D","#FFD045","#6DE838"],80:["#D9E838","#93E838","#3EE838"],100:["#55EB62","#38E99A","#5EEA52"]},S=Object.keys(M).map(s=>Number.parseInt(s,10)).sort((s,t)=>t-s);function v({label:s,size:t,percentage:n=0,isInverted:y,showSymbol:d=!0,isAnimated:p}){const[j,l]=a.useState(n);a.useEffect(()=>{if(p){l(0);const u=300,i=10,F=30,f=.65,D=[];let h=u;for(let c=0;c<n;c+=1){const _=(c+1)/n,R=Math.min(Math.max((_-f)/(1-f),0),1),$=1-(1-R)*(1-R);h+=i+F*$,D.push(setTimeout(()=>{l(c+1)},h))}return()=>{for(const c of D)clearTimeout(c)}}l(n)},[p,n]);const k=a.useMemo(()=>P.default(j,0,100),[j]),m=Math.round(k),r=y?100-m:m,o=a.useMemo(()=>{for(const u of S)if(r>=u)return M[u];return[]},[r]),E=a.useMemo(()=>o.length,[o]),C=a.useMemo(()=>o.at(0),[o]),b=a.useMemo(()=>o.at(-1),[o]),q=a.useMemo(()=>o.map((u,i)=>`${u} ${Math.round(i/E*100)}%`).join(", "),[o,E]);return e.jsxRuntimeExports.jsxs("div",{style:{"--percentage":`${r}%`,"--percentage-factor":r/100,"--gradient":q,"--start-color":C,"--end-color":b},role:"meter","aria-valuenow":k,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s,className:N.cx("kakadu-components-3163931049",t==="small"&&"kakadu-components-1272093092",t==="large"&&"kakadu-components-553520060"),children:[r>0?e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-707327569"}):null,e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2636723344",children:e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2810161405"})}),e.jsxRuntimeExports.jsxs("div",{className:"kakadu-components-114088345",children:[e.jsxRuntimeExports.jsx("span",{className:N.cx("kakadu-components-3402528359",d&&"kakadu-components-3473805935"),children:m}),d?e.jsxRuntimeExports.jsx(x.Span,{className:"kakadu-components-810313368",children:"%"}):null]}),r>0&&r<100?e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-967240013",children:e.jsxRuntimeExports.jsx("div",{className:"kakadu-components-3225063030"})}):null]})}function T({title:s,description:t,...n}){return!s&&!t?e.jsxRuntimeExports.jsx(v,{...n}):e.jsxRuntimeExports.jsxs(g.default,{preset:"center",gap:1.5,children:[e.jsxRuntimeExports.jsx(v,{...n}),e.jsxRuntimeExports.jsxs(g.default,{preset:"center",gap:.25,children:[s?e.jsxRuntimeExports.jsx(x.Label,{className:"kakadu-components-1477072149",children:s}):null,t?e.jsxRuntimeExports.jsx(x.Span,{className:"kakadu-components-2235337211",children:t}):null]})]})}exports.default=T;
@@ -1,9 +1,10 @@
1
1
  import { j as e } from "../jsx-runtime-z6PQ6F3d.mjs";
2
- import { useState as $, useEffect as G, useMemo as t } from "react";
3
- import { cx as E } from "@kuma-ui/core";
4
- import { Label as L, Span as v } from "./text.mjs";
5
- import N from "./flex.mjs";
6
- const C = {
2
+ import { useState as G, useEffect as L, useMemo as l } from "react";
3
+ import { cx as N } from "@kuma-ui/core";
4
+ import R from "../utilities/clamp.mjs";
5
+ import { Label as A, Span as C } from "./text.mjs";
6
+ import g from "./flex.mjs";
7
+ const y = {
7
8
  /* eslint-disable @typescript-eslint/naming-convention */
8
9
  0: ["#D60D43"],
9
10
  15: ["#D60D43", "#FFCD45"],
@@ -13,68 +14,69 @@ const C = {
13
14
  80: ["#D9E838", "#93E838", "#3EE838"],
14
15
  100: ["#55EB62", "#38E99A", "#5EEA52"]
15
16
  /* eslint-enable @typescript-eslint/naming-convention */
16
- }, A = Object.keys(C).map((a) => Number.parseInt(a, 10)).sort((a, s) => s - a);
17
- function g({
18
- label: a,
19
- size: s,
20
- percentage: n = 0,
17
+ }, I = Object.keys(y).map((s) => Number.parseInt(s, 10)).sort((s, a) => a - s);
18
+ function v({
19
+ label: s,
20
+ size: a,
21
+ percentage: o = 0,
22
+ isInverted: b,
21
23
  showSymbol: i = !0,
22
24
  isAnimated: k
23
25
  }) {
24
- const [p, m] = $(n);
25
- G(() => {
26
+ const [p, u] = G(o);
27
+ L(() => {
26
28
  if (k) {
27
- m(0);
28
- const c = 300, d = 10, B = 30, f = 0.65, h = [];
29
- let j = c;
30
- for (let l = 0; l < n; l += 1) {
31
- const P = (l + 1) / n, D = Math.min(Math.max((P - f) / (1 - f), 0), 1), T = 1 - (1 - D) * (1 - D);
32
- j += d + B * T, h.push(setTimeout(() => {
33
- m(l + 1);
34
- }, j));
29
+ u(0);
30
+ const r = 300, d = 10, P = 30, j = 0.65, D = [];
31
+ let h = r;
32
+ for (let c = 0; c < o; c += 1) {
33
+ const T = (c + 1) / o, E = Math.min(Math.max((T - j) / (1 - j), 0), 1), $ = 1 - (1 - E) * (1 - E);
34
+ h += d + P * $, D.push(setTimeout(() => {
35
+ u(c + 1);
36
+ }, h));
35
37
  }
36
38
  return () => {
37
- for (const l of h)
38
- clearTimeout(l);
39
+ for (const c of D)
40
+ clearTimeout(c);
39
41
  };
40
42
  }
41
- m(n);
42
- }, [k, n]);
43
- const r = t(() => Math.max(0, Math.min(100, p)), [p]), y = t(() => r / 100, [r]), o = t(() => {
44
- for (const c of A)
45
- if (r >= c)
46
- return C[c];
43
+ u(o);
44
+ }, [k, o]);
45
+ const x = l(() => R(p, 0, 100), [p]), m = Math.round(x), t = b ? 100 - m : m, n = l(() => {
46
+ for (const r of I)
47
+ if (t >= r)
48
+ return y[r];
47
49
  return [];
48
- }, [r]), x = t(() => o.length, [o]), M = t(() => o.at(0), [o]), F = t(() => o.at(-1), [o]), b = t(() => o.map((c, d) => `${c} ${Math.round(d / x * 100)}%`).join(", "), [o, x]), u = t(() => Math.round(r), [r]);
50
+ }, [t]), f = l(() => n.length, [n]), F = l(() => n.at(0), [n]), M = l(() => n.at(-1), [n]), B = l(() => n.map((r, d) => `${r} ${Math.round(d / f * 100)}%`).join(", "), [n, f]);
49
51
  return /* @__PURE__ */ e.jsxs("div", { style: {
50
- "--percentage": `${u}%`,
51
- "--percentage-factor": y,
52
- "--gradient": b,
53
- "--start-color": M,
54
- "--end-color": F
55
- }, role: "meter", "aria-valuenow": r, "aria-valuemin": 0, "aria-valuemax": 100, "aria-label": a, className: E("kakadu-components-3163931049", s === "small" && "kakadu-components-1272093092", s === "large" && "kakadu-components-553520060"), children: [
56
- u > 0 ? /* @__PURE__ */ e.jsx("div", { className: "kakadu-components-707327569" }) : null,
52
+ "--percentage": `${t}%`,
53
+ "--percentage-factor": t / 100,
54
+ "--gradient": B,
55
+ "--start-color": F,
56
+ "--end-color": M
57
+ }, role: "meter", "aria-valuenow": x, "aria-valuemin": 0, "aria-valuemax": 100, "aria-label": s, className: N("kakadu-components-3163931049", a === "small" && "kakadu-components-1272093092", a === "large" && "kakadu-components-553520060"), children: [
58
+ t > 0 ? /* @__PURE__ */ e.jsx("div", { className: "kakadu-components-707327569" }) : null,
57
59
  /* @__PURE__ */ e.jsx("div", { className: "kakadu-components-2636723344", children: /* @__PURE__ */ e.jsx("div", { className: "kakadu-components-2810161405" }) }),
58
60
  /* @__PURE__ */ e.jsxs("div", { className: "kakadu-components-114088345", children: [
59
- /* @__PURE__ */ e.jsx("span", { className: E("kakadu-components-3402528359", i && "kakadu-components-3473805935"), children: u }),
60
- i ? /* @__PURE__ */ e.jsx(v, { className: "kakadu-components-810313368", children: "%" }) : null
61
+ /* @__PURE__ */ e.jsx("span", { className: N("kakadu-components-3402528359", i && "kakadu-components-3473805935"), children: m }),
62
+ i ? /* @__PURE__ */ e.jsx(C, { className: "kakadu-components-810313368", children: "%" }) : null
61
63
  ] }),
62
- u > 0 && u < 100 ? /* @__PURE__ */ e.jsx("div", { className: "kakadu-components-967240013", children: /* @__PURE__ */ e.jsx("div", { className: "kakadu-components-3225063030" }) }) : null
64
+ t > 0 && t < 100 ? /* @__PURE__ */ e.jsx("div", { className: "kakadu-components-967240013", children: /* @__PURE__ */ e.jsx("div", { className: "kakadu-components-3225063030" }) }) : null
63
65
  ] });
64
66
  }
65
- function q({
66
- title: a,
67
- description: s,
68
- ...n
67
+ function J({
68
+ title: s,
69
+ description: a,
70
+ ...o
69
71
  }) {
70
- return !a && !s ? /* @__PURE__ */ e.jsx(g, { ...n }) : /* @__PURE__ */ e.jsxs(N, { preset: "center", gap: 1.5, children: [
71
- /* @__PURE__ */ e.jsx(g, { ...n }),
72
- /* @__PURE__ */ e.jsxs(N, { preset: "center", gap: 0.25, children: [
73
- a ? /* @__PURE__ */ e.jsx(L, { className: "kakadu-components-1477072149", children: a }) : null,
74
- s ? /* @__PURE__ */ e.jsx(v, { className: "kakadu-components-2235337211", children: s }) : null
72
+ return !s && !a ? /* @__PURE__ */ e.jsx(v, { ...o }) : /* @__PURE__ */ e.jsxs(g, { preset: "center", gap: 1.5, children: [
73
+ /* @__PURE__ */ e.jsx(v, { ...o }),
74
+ /* @__PURE__ */ e.jsxs(g, { preset: "center", gap: 0.25, children: [
75
+ s ? /* @__PURE__ */ e.jsx(A, { className: "kakadu-components-1477072149", children: s }) : null,
76
+ a ? /* @__PURE__ */ e.jsx(C, { className: "kakadu-components-2235337211", children: a }) : null
75
77
  ] })
76
78
  ] });
77
79
  }
78
80
  export {
79
- q as default
81
+ J as default
80
82
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakadu/components",
3
- "version": "6.17.1",
3
+ "version": "6.18.0",
4
4
  "description": "Kakadu components library",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",