@canonical/maas-react-components 1.4.0 → 1.5.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.
@@ -1,10 +1,10 @@
1
- import { jsxs as C, jsx as n, Fragment as L } from "react/jsx-runtime";
2
- import { useRef as I, useState as M, useEffect as T, useCallback as j, cloneElement as D } from "react";
3
- import { useListener as O, Link as W, Tooltip as A, Button as S, Icon as $ } from "@canonical/react-components";
4
- function R(e) {
1
+ import { jsxs as h, jsx as t, Fragment as C } from "react/jsx-runtime";
2
+ import { useRef as I, useState as M, useEffect as T, useCallback as E, cloneElement as j } from "react";
3
+ import { useListener as D, Link as O, Tooltip as A, Button as x, Icon as B } from "@canonical/react-components";
4
+ function P(e) {
5
5
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
6
6
  }
7
- var B = { exports: {} };
7
+ var $ = { exports: {} };
8
8
  /*!
9
9
  Copyright (c) 2018 Jed Watson.
10
10
  Licensed under the MIT License (MIT), see
@@ -12,37 +12,37 @@ var B = { exports: {} };
12
12
  */
13
13
  (function(e) {
14
14
  (function() {
15
- var t = {}.hasOwnProperty;
15
+ var n = {}.hasOwnProperty;
16
16
  function a() {
17
- for (var s = [], r = 0; r < arguments.length; r++) {
18
- var o = arguments[r];
19
- if (o) {
20
- var p = typeof o;
21
- if (p === "string" || p === "number")
22
- s.push(o);
23
- else if (Array.isArray(o)) {
24
- if (o.length) {
25
- var d = a.apply(null, o);
26
- d && s.push(d);
17
+ for (var o = [], i = 0; i < arguments.length; i++) {
18
+ var s = arguments[i];
19
+ if (s) {
20
+ var m = typeof s;
21
+ if (m === "string" || m === "number")
22
+ o.push(s);
23
+ else if (Array.isArray(s)) {
24
+ if (s.length) {
25
+ var l = a.apply(null, s);
26
+ l && o.push(l);
27
27
  }
28
- } else if (p === "object") {
29
- if (o.toString !== Object.prototype.toString && !o.toString.toString().includes("[native code]")) {
30
- s.push(o.toString());
28
+ } else if (m === "object") {
29
+ if (s.toString !== Object.prototype.toString && !s.toString.toString().includes("[native code]")) {
30
+ o.push(s.toString());
31
31
  continue;
32
32
  }
33
- for (var u in o)
34
- t.call(o, u) && o[u] && s.push(u);
33
+ for (var c in s)
34
+ n.call(s, c) && s[c] && o.push(c);
35
35
  }
36
36
  }
37
37
  }
38
- return s.join(" ");
38
+ return o.join(" ");
39
39
  }
40
40
  e.exports ? (a.default = a, e.exports = a) : window.classNames = a;
41
41
  })();
42
- })(B);
43
- var z = B.exports;
44
- const c = /* @__PURE__ */ R(z);
45
- const v = {
42
+ })($);
43
+ var R = $.exports;
44
+ const p = /* @__PURE__ */ P(R);
45
+ const u = {
46
46
  caution: "#F99B11",
47
47
  light: "#F7F7F7",
48
48
  linkFaded: "#D3E4ED",
@@ -51,210 +51,224 @@ const v = {
51
51
  positiveFaded: "#B7CCB9",
52
52
  positiveMid: "#4DAB4D",
53
53
  positive: "#0E8420"
54
- }, _e = [
55
- v.link,
56
- v.positive,
57
- v.negative,
58
- v.caution
59
- ], H = v.linkFaded, P = v.caution, q = v.light, k = 2, w = 1, x = (e, t, a) => {
60
- var o, p;
61
- const s = ((p = (o = e == null ? void 0 : e.current) == null ? void 0 : o.getBoundingClientRect()) == null ? void 0 : p.width) || 0, r = s > t * k ? s / t : k;
62
- a(r);
63
- }, _ = {
54
+ }, ve = [
55
+ u.link,
56
+ u.positive,
57
+ u.negative,
58
+ u.caution
59
+ ], z = u.linkFaded, F = u.caution, b = u.light, L = 2, k = 1, w = (e, n) => {
60
+ var i, s;
61
+ const a = ((s = (i = e == null ? void 0 : e.current) == null ? void 0 : i.getBoundingClientRect()) == null ? void 0 : s.width) || 0;
62
+ return a > n * L ? a / n : L;
63
+ }, d = {
64
64
  bar: "meter-bar",
65
65
  container: "meter-container",
66
66
  filled: "meter-filled",
67
67
  label: "meter-label",
68
68
  meteroverflow: "meter-overflow",
69
69
  segments: "meter-segments"
70
- }, G = ({
70
+ }, H = ({
71
+ className: e,
72
+ children: n,
73
+ data: a,
74
+ max: o,
75
+ variant: i = "regular",
76
+ size: s = "regular",
77
+ ...m
78
+ }) => {
79
+ const l = I(null), c = a == null ? void 0 : a.reduce((N, y) => N + y.value, 0), g = o || c, _ = a.map((N) => N.value / g * 100), [f, v] = M(0);
80
+ T(() => {
81
+ v(i === "segmented" ? w(l, g) : 0);
82
+ }, [g, i]);
83
+ const S = E(() => {
84
+ v(w(l, g));
85
+ }, [l, g, v]);
86
+ return D(window, S, "resize", !0, i === "segmented"), /* @__PURE__ */ h(
87
+ "div",
88
+ {
89
+ className: p("p-meter", e, {
90
+ "p-meter--small": s === "small"
91
+ }),
92
+ "aria-label": m == null ? void 0 : m["aria-label"],
93
+ "data-testid": d.container,
94
+ ref: l,
95
+ children: [
96
+ /* @__PURE__ */ t(W, { children: /* @__PURE__ */ t(
97
+ q,
98
+ {
99
+ data: a,
100
+ datumWidths: _,
101
+ maximum: g,
102
+ overColor: F,
103
+ segmentWidth: f,
104
+ separatorColor: b
105
+ }
106
+ ) }),
107
+ n
108
+ ]
109
+ }
110
+ );
111
+ }, W = ({ children: e }) => /* @__PURE__ */ t(
112
+ "div",
113
+ {
114
+ className: "p-meter__bar",
115
+ "data-testid": d.bar,
116
+ style: { backgroundColor: z },
117
+ children: e
118
+ }
119
+ ), q = ({
71
120
  data: e,
72
- datumWidths: t,
121
+ datumWidths: n,
73
122
  maximum: a,
74
- overColor: s,
75
- segmentWidth: r,
76
- separatorColor: o
123
+ segmentWidth: o
77
124
  }) => {
78
- const p = () => e.reduce((g, l) => g + l.value, 0) > a, d = (g, l) => ({
79
- backgroundColor: g.color,
80
- left: `${t.reduce(
81
- (f, m, h) => l > h ? f + m : f,
125
+ const i = () => (e == null ? void 0 : e.reduce((l, c) => l + c.value, 0)) > a, s = (l, c) => ({
126
+ backgroundColor: l.color,
127
+ left: `${n == null ? void 0 : n.reduce(
128
+ (g, _, f) => c > f ? g + _ : g,
82
129
  0
83
130
  )}%`,
84
- width: `${t[l]}%`
85
- }), u = () => ({
131
+ width: `${n[c]}%`
132
+ }), m = () => ({
86
133
  background: `repeating-linear-gradient(
87
134
  to right,
88
135
  transparent 0,
89
- transparent ${r - w}px,
90
- ${o} ${r - w}px,
91
- ${o} ${r}px
136
+ transparent ${o - k}px,
137
+ ${b} ${o - k}px,
138
+ ${b} ${o}px
92
139
  )`
93
140
  });
94
- return /* @__PURE__ */ C(L, { children: [
95
- p() ? /* @__PURE__ */ n(
141
+ return /* @__PURE__ */ h(C, { children: [
142
+ i() ? /* @__PURE__ */ t(
96
143
  "div",
97
144
  {
98
145
  className: "p-meter__filled",
99
- "data-testid": _.meteroverflow,
100
- style: { backgroundColor: s, width: "100%" }
146
+ "data-testid": d.meteroverflow,
147
+ style: { backgroundColor: F, width: "100%" }
101
148
  }
102
- ) : e.map((g, l) => /* @__PURE__ */ n(
149
+ ) : e == null ? void 0 : e.map((l, c) => /* @__PURE__ */ t(
103
150
  "div",
104
151
  {
105
152
  className: "p-meter__filled",
106
- "data-testid": _.filled,
107
- style: d(g, l)
153
+ "data-testid": d.filled,
154
+ style: s(l, c)
108
155
  },
109
- `meter-${l}`
156
+ `meter-${c}`
110
157
  )),
111
- r > 0 && /* @__PURE__ */ n(
158
+ o > 0 && /* @__PURE__ */ t(
112
159
  "div",
113
160
  {
114
161
  className: "p-meter__separators",
115
- "data-testid": _.segments,
116
- style: u()
162
+ "data-testid": d.segments,
163
+ style: m()
117
164
  }
118
165
  )
119
166
  ] });
120
- }, J = ({
121
- labelClassName: e,
122
- label: t
123
- }) => /* @__PURE__ */ n(
167
+ }, G = ({
168
+ className: e,
169
+ children: n
170
+ }) => /* @__PURE__ */ t(
124
171
  "div",
125
172
  {
126
- className: c("p-meter__label", e),
127
- "data-testid": _.label,
128
- children: t
173
+ className: p("p-meter__label", e),
174
+ "data-testid": d.label,
175
+ children: n
129
176
  }
130
- ), fe = ({
131
- className: e,
132
- data: t,
133
- emptyColor: a = H,
134
- label: s,
135
- labelClassName: r,
136
- max: o,
137
- overColor: p = P,
138
- segmented: d = !1,
139
- separatorColor: u = q,
140
- small: g = !1
141
- }) => {
142
- const l = I(null), f = t.reduce((b, E) => b + E.value, 0), m = o || f, h = t.map((b) => b.value / m * 100), [F, N] = M(0);
143
- T(() => {
144
- d && x(l, m, N);
145
- }, [m, d]);
146
- const y = j(() => {
147
- x(l, m, N);
148
- }, [l, m, N]);
149
- return O(window, y, "resize", !0, d), /* @__PURE__ */ C(
150
- "div",
151
- {
152
- className: c("p-meter", { "p-meter--small": g }, e),
153
- "data-testid": _.container,
154
- ref: l,
155
- children: [
156
- /* @__PURE__ */ n(
157
- "div",
158
- {
159
- className: "p-meter__bar",
160
- "data-testid": _.bar,
161
- style: { backgroundColor: a },
162
- children: /* @__PURE__ */ n(
163
- G,
164
- {
165
- data: t,
166
- datumWidths: h,
167
- maximum: m,
168
- overColor: p,
169
- segmentWidth: F,
170
- separatorColor: u
171
- }
172
- )
173
- }
174
- ),
175
- s && /* @__PURE__ */ n(J, { label: s, labelClassName: r })
176
- ]
177
- }
178
- );
179
- }, he = ({ children: e, to: t, ...a }) => /* @__PURE__ */ n(W, { ...a, href: t, rel: "noreferrer noopener", target: "_blank", children: e }), K = ({ children: e }) => /* @__PURE__ */ n(L, { children: e }), Q = ({
177
+ );
178
+ H.Label = G;
179
+ const _e = ({ children: e, to: n, ...a }) => /* @__PURE__ */ t(O, { ...a, href: n, rel: "noreferrer noopener", target: "_blank", children: e }), J = ({ children: e }) => /* @__PURE__ */ t(C, { children: e }), K = ({
180
180
  isCollapsed: e,
181
- setIsCollapsed: t,
181
+ setIsCollapsed: n,
182
182
  className: a
183
- }) => /* @__PURE__ */ n(
183
+ }) => /* @__PURE__ */ t(
184
184
  A,
185
185
  {
186
186
  className: "p-side-navigation__tooltip-wrapper",
187
- message: /* @__PURE__ */ C(L, { children: [
187
+ message: /* @__PURE__ */ h(C, { children: [
188
188
  e ? "expand" : "collapse",
189
189
  "( ",
190
- /* @__PURE__ */ n("code", { children: "[" }),
190
+ /* @__PURE__ */ t("code", { children: "[" }),
191
191
  " )"
192
192
  ] }),
193
193
  position: "right",
194
194
  tooltipClassName: "p-side-navigation__tooltip",
195
- children: /* @__PURE__ */ n(
196
- S,
195
+ children: /* @__PURE__ */ t(
196
+ x,
197
197
  {
198
198
  appearance: "base",
199
199
  "aria-label": `${e ? "expand" : "collapse"} main navigation`,
200
- className: c(
200
+ className: p(
201
201
  "is-dense has-icon is-dark u-no-margin l-navigation-collapse-toggle",
202
202
  a
203
203
  ),
204
- onClick: (s) => {
205
- t(!e), s.stopPropagation(), s.currentTarget.blur();
204
+ onClick: (o) => {
205
+ n(!e), o.stopPropagation(), o.currentTarget.blur();
206
206
  },
207
- children: /* @__PURE__ */ n($, { light: !0, name: "sidebar-toggle" })
207
+ children: /* @__PURE__ */ t(B, { light: !0, name: "sidebar-toggle" })
208
208
  }
209
209
  )
210
210
  }
211
- ), U = ({ children: e }) => /* @__PURE__ */ n("div", { className: "p-panel__content", children: /* @__PURE__ */ n("nav", { className: "p-side-navigation--icons is-dark", children: e }) }), V = ({ children: e }) => /* @__PURE__ */ n("div", { className: "p-panel__controls u-no-margin--top", children: e }), X = ({ children: e }) => /* @__PURE__ */ n("div", { className: "l-navigation__drawer", children: /* @__PURE__ */ n("div", { className: "p-panel is-dark", children: e }) }), Y = ({ children: e }) => /* @__PURE__ */ n("div", { className: "p-panel__footer", children: e }), Z = ({ children: e }) => /* @__PURE__ */ n("div", { className: "p-panel__header", children: e }), ee = ({ light: e = !0, name: t }) => /* @__PURE__ */ n($, { className: "p-side-navigation__icon", light: e, name: t }), te = ({ children: e, className: t, hasActiveChild: a }) => /* @__PURE__ */ n("li", { className: c("p-side-navigation__item", t, { "has-active-child": a }), children: e }), ne = ({ children: e, id: t, variant: a = "base" }) => /* @__PURE__ */ n("span", { className: c("p-side-navigation__label", { "p-side-navigation__label--group": a === "group" }), id: t, children: e }), ae = ({
211
+ ), Q = ({ children: e }) => /* @__PURE__ */ t("div", { className: "p-panel__content", children: /* @__PURE__ */ t("nav", { className: "p-side-navigation--icons is-dark", children: e }) }), U = ({ children: e }) => /* @__PURE__ */ t("div", { className: "p-panel__controls u-no-margin--top", children: e }), V = ({ children: e }) => /* @__PURE__ */ t("div", { className: "l-navigation__drawer", children: /* @__PURE__ */ t("div", { className: "p-panel is-dark", children: e }) }), X = ({ children: e }) => /* @__PURE__ */ t("div", { className: "p-panel__footer", children: e }), Y = ({ children: e }) => /* @__PURE__ */ t("div", { className: "p-panel__header", children: e }), Z = ({ light: e = !0, name: n }) => /* @__PURE__ */ t(B, { className: "p-side-navigation__icon", light: e, name: n }), ee = ({ children: e, className: n, hasActiveChild: a }) => /* @__PURE__ */ t("li", { className: p("p-side-navigation__item", n, { "has-active-child": a }), children: e }), ne = ({ children: e, id: n, variant: a = "base" }) => /* @__PURE__ */ t("span", { className: p("p-side-navigation__label", { "p-side-navigation__label--group": a === "group" }), id: n, children: e }), te = ({
212
212
  as: e,
213
- ...t
214
- }) => /* @__PURE__ */ n(
213
+ ...n
214
+ }) => /* @__PURE__ */ t(
215
215
  e || "a",
216
216
  {
217
- className: c("p-side-navigation__link", t.className),
218
- ...t
217
+ className: p("p-side-navigation__link", n.className),
218
+ ...n
219
219
  }
220
- ), oe = ({ children: e, className: t }) => /* @__PURE__ */ n("ul", { className: c("p-side-navigation__list", t), children: e }), se = ({ as: e, children: t, className: a, ...s }) => /* @__PURE__ */ n(e || "a", { className: c("p-panel__logo", a), ...s, children: /* @__PURE__ */ n("div", { className: "p-navigation__tagged-logo", children: t }) }), ie = ({ children: e }) => D(e, { className: "p-panel__logo-icon p-navigation__logo-icon" }), re = ({ children: e, variant: t = "base" }) => /* @__PURE__ */ n(
220
+ ), ae = ({ children: e, className: n }) => /* @__PURE__ */ t("ul", { className: p("p-side-navigation__list", n), children: e }), oe = ({ as: e, children: n, className: a, ...o }) => /* @__PURE__ */ t(e || "a", { className: p("p-panel__logo", a), ...o, children: /* @__PURE__ */ t("div", { className: "p-navigation__tagged-logo", children: n }) }), se = ({ children: e }) => j(e, { className: "p-panel__logo-icon p-navigation__logo-icon" }), re = ({ children: e, variant: n = "base" }) => /* @__PURE__ */ t(
221
221
  "div",
222
222
  {
223
- className: c("p-panel__logo-name is-fading-when-collapsed", {
224
- "p-panel__logo-name--small": t === "small"
223
+ className: p("p-panel__logo-name is-fading-when-collapsed", {
224
+ "p-panel__logo-name--small": n === "small"
225
225
  }),
226
226
  children: e
227
227
  }
228
- ), le = ({ children: e }) => /* @__PURE__ */ n("div", { className: "p-navigation__logo-tag", children: e }), ce = ({ children: e }) => /* @__PURE__ */ n("span", { className: "p-panel__logo-text", children: e }), pe = ({ children: e, className: t, onClick: a }) => /* @__PURE__ */ n(S, { appearance: "base", className: c("p-side-navigation__button--menu has-icon is-dark", t), onClick: a, children: e }), de = ({ children: e }) => /* @__PURE__ */ n("span", { className: "p-side-navigation__text", children: e });
229
- const i = ({ children: e, className: t, isCollapsed: a }) => /* @__PURE__ */ n("header", { "aria-label": "main navigation", className: c("l-navigation is-maas", t, { "is-collapsed": a, "is-pinned": !a }), children: e }), me = ({ children: e, className: t }) => /* @__PURE__ */ n("header", { "aria-label": "navigation", className: "l-navigation-bar", children: /* @__PURE__ */ n("div", { className: c("p-panel is-dark", t), children: e }) });
230
- i.Header = Z;
231
- i.Banner = K;
232
- i.Drawer = X;
233
- i.Controls = V;
234
- i.CollapseToggle = Q;
235
- i.Content = U;
236
- i.Footer = Y;
237
- i.List = oe;
238
- i.Item = te;
239
- i.Link = ae;
240
- i.Text = de;
241
- i.Icon = ee;
242
- i.Label = ne;
243
- i.Logo = se;
244
- i.LogoTag = le;
245
- i.LogoIcon = ie;
246
- i.LogoName = re;
247
- i.LogoText = ce;
248
- me.MenuButton = pe;
228
+ ), ie = ({ children: e }) => /* @__PURE__ */ t("div", { className: "p-navigation__logo-tag", children: e }), le = ({ children: e }) => /* @__PURE__ */ t("span", { className: "p-panel__logo-text", children: e }), ce = ({
229
+ children: e,
230
+ className: n,
231
+ onClick: a
232
+ }) => /* @__PURE__ */ t(
233
+ x,
234
+ {
235
+ appearance: "base",
236
+ className: p(
237
+ "p-side-navigation__button--menu has-icon is-dark",
238
+ n
239
+ ),
240
+ onClick: (o) => {
241
+ a && a(o), o.stopPropagation(), o.currentTarget.blur();
242
+ },
243
+ children: e
244
+ }
245
+ ), pe = ({ children: e }) => /* @__PURE__ */ t("span", { className: "p-side-navigation__text", children: e });
246
+ const r = ({ children: e, className: n, isCollapsed: a }) => /* @__PURE__ */ t("header", { "aria-label": "main navigation", className: p("l-navigation is-maas", n, { "is-collapsed": a, "is-pinned": !a }), children: e }), me = ({ children: e, className: n }) => /* @__PURE__ */ t("header", { "aria-label": "navigation", className: "l-navigation-bar", children: /* @__PURE__ */ t("div", { className: p("p-panel is-dark", n), children: e }) });
247
+ r.Header = Y;
248
+ r.Banner = J;
249
+ r.Drawer = V;
250
+ r.Controls = U;
251
+ r.CollapseToggle = K;
252
+ r.Content = Q;
253
+ r.Footer = X;
254
+ r.List = ae;
255
+ r.Item = ee;
256
+ r.Link = te;
257
+ r.Text = pe;
258
+ r.Icon = Z;
259
+ r.Label = ne;
260
+ r.Logo = oe;
261
+ r.LogoTag = ie;
262
+ r.LogoIcon = se;
263
+ r.LogoName = re;
264
+ r.LogoText = le;
265
+ me.MenuButton = ce;
249
266
  export {
250
- he as ExternalLink,
251
- fe as Meter,
252
- i as Navigation,
267
+ _e as ExternalLink,
268
+ H as Meter,
269
+ r as Navigation,
253
270
  me as NavigationBar,
254
- H as defaultEmptyColor,
255
- _e as defaultFilledColors,
256
- P as defaultOverColor,
257
- q as defaultSeparatorColor,
258
- v as meterColor,
259
- _ as testIds
271
+ ve as defaultFilledColors,
272
+ u as meterColor,
273
+ d as testIds
260
274
  };
@@ -1,11 +1,11 @@
1
- (function(r,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react"),require("@canonical/react-components")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@canonical/react-components"],a):(r=typeof globalThis<"u"?globalThis:r||self,a(r["@canonical/maas-react-components"]={},r["react/jsx-runtime"],r.React,r["@canonical/react-components"]))})(this,function(r,a,N,f){"use strict";function I(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var w={exports:{}};/*!
1
+ (function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react"),require("@canonical/react-components")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@canonical/react-components"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l["@canonical/maas-react-components"]={},l["react/jsx-runtime"],l.React,l["@canonical/react-components"]))})(this,function(l,a,f,m){"use strict";function T(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var w={exports:{}};/*!
2
2
  Copyright (c) 2018 Jed Watson.
3
3
  Licensed under the MIT License (MIT), see
4
4
  http://jedwatson.github.io/classnames
5
- */(function(e){(function(){var t={}.hasOwnProperty;function n(){for(var l=[],i=0;i<arguments.length;i++){var o=arguments[i];if(o){var p=typeof o;if(p==="string"||p==="number")l.push(o);else if(Array.isArray(o)){if(o.length){var u=n.apply(null,o);u&&l.push(u)}}else if(p==="object"){if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]")){l.push(o.toString());continue}for(var _ in o)t.call(o,_)&&o[_]&&l.push(_)}}}return l.join(" ")}e.exports?(n.default=n,e.exports=n):window.classNames=n})()})(w);var M=w.exports;const c=I(M),le="",g={caution:"#F99B11",light:"#F7F7F7",linkFaded:"#D3E4ED",link:"#0066CC",negative:"#C7162B",positiveFaded:"#B7CCB9",positiveMid:"#4DAB4D",positive:"#0E8420"},x=[g.link,g.positive,g.negative,g.caution],y=g.linkFaded,S=g.caution,F=g.light,B=2,E=1,T=(e,t,n)=>{var o,p;const l=((p=(o=e==null?void 0:e.current)==null?void 0:o.getBoundingClientRect())==null?void 0:p.width)||0,i=l>t*B?l/t:B;n(i)},m={bar:"meter-bar",container:"meter-container",filled:"meter-filled",label:"meter-label",meteroverflow:"meter-overflow",segments:"meter-segments"},O=({data:e,datumWidths:t,maximum:n,overColor:l,segmentWidth:i,separatorColor:o})=>{const p=()=>e.reduce((h,d)=>h+d.value,0)>n,u=(h,d)=>({backgroundColor:h.color,left:`${t.reduce((b,v,C)=>d>C?b+v:b,0)}%`,width:`${t[d]}%`}),_=()=>({background:`repeating-linear-gradient(
5
+ */(function(e){(function(){var n={}.hasOwnProperty;function t(){for(var o=[],i=0;i<arguments.length;i++){var r=arguments[i];if(r){var g=typeof r;if(g==="string"||g==="number")o.push(r);else if(Array.isArray(r)){if(r.length){var c=t.apply(null,r);c&&o.push(c)}}else if(g==="object"){if(r.toString!==Object.prototype.toString&&!r.toString.toString().includes("[native code]")){o.push(r.toString());continue}for(var d in r)n.call(r,d)&&r[d]&&o.push(d)}}}return o.join(" ")}e.exports?(t.default=t,e.exports=t):window.classNames=t})()})(w);var M=w.exports;const p=T(M),se="",v={caution:"#F99B11",light:"#F7F7F7",linkFaded:"#D3E4ED",link:"#0066CC",negative:"#C7162B",positiveFaded:"#B7CCB9",positiveMid:"#4DAB4D",positive:"#0E8420"},$=[v.link,v.positive,v.negative,v.caution],I=v.linkFaded,C=v.caution,h=v.light,y=2,B=1,F=(e,n)=>{var i,r;const t=((r=(i=e==null?void 0:e.current)==null?void 0:i.getBoundingClientRect())==null?void 0:r.width)||0;return t>n*y?t/n:y},_={bar:"meter-bar",container:"meter-container",filled:"meter-filled",label:"meter-label",meteroverflow:"meter-overflow",segments:"meter-segments"},S=({className:e,children:n,data:t,max:o,variant:i="regular",size:r="regular",...g})=>{const c=f.useRef(null),d=t==null?void 0:t.reduce((k,oe)=>k+oe.value,0),u=o||d,b=t.map(k=>k.value/u*100),[L,N]=f.useState(0);f.useEffect(()=>{N(i==="segmented"?F(c,u):0)},[u,i]);const te=f.useCallback(()=>{N(F(c,u))},[c,u,N]);return m.useListener(window,te,"resize",!0,i==="segmented"),a.jsxs("div",{className:p("p-meter",e,{"p-meter--small":r==="small"}),"aria-label":g==null?void 0:g["aria-label"],"data-testid":_.container,ref:c,children:[a.jsx(E,{children:a.jsx(j,{data:t,datumWidths:b,maximum:u,overColor:C,segmentWidth:L,separatorColor:h})}),n]})},E=({children:e})=>a.jsx("div",{className:"p-meter__bar","data-testid":_.bar,style:{backgroundColor:I},children:e}),j=({data:e,datumWidths:n,maximum:t,segmentWidth:o})=>{const i=()=>(e==null?void 0:e.reduce((c,d)=>c+d.value,0))>t,r=(c,d)=>({backgroundColor:c.color,left:`${n==null?void 0:n.reduce((u,b,L)=>d>L?u+b:u,0)}%`,width:`${n[d]}%`}),g=()=>({background:`repeating-linear-gradient(
6
6
  to right,
7
7
  transparent 0,
8
- transparent ${i-E}px,
9
- ${o} ${i-E}px,
10
- ${o} ${i}px
11
- )`});return a.jsxs(a.Fragment,{children:[p()?a.jsx("div",{className:"p-meter__filled","data-testid":m.meteroverflow,style:{backgroundColor:l,width:"100%"}}):e.map((h,d)=>a.jsx("div",{className:"p-meter__filled","data-testid":m.filled,style:u(h,d)},`meter-${d}`)),i>0&&a.jsx("div",{className:"p-meter__separators","data-testid":m.segments,style:_()})]})},j=({labelClassName:e,label:t})=>a.jsx("div",{className:c("p-meter__label",e),"data-testid":m.label,children:t}),D=({className:e,data:t,emptyColor:n=y,label:l,labelClassName:i,max:o,overColor:p=S,segmented:u=!1,separatorColor:_=F,small:h=!1})=>{const d=N.useRef(null),b=t.reduce((k,re)=>k+re.value,0),v=o||b,C=t.map(k=>k.value/v*100),[oe,L]=N.useState(0);N.useEffect(()=>{u&&T(d,v,L)},[v,u]);const se=N.useCallback(()=>{T(d,v,L)},[d,v,L]);return f.useListener(window,se,"resize",!0,u),a.jsxs("div",{className:c("p-meter",{"p-meter--small":h},e),"data-testid":m.container,ref:d,children:[a.jsx("div",{className:"p-meter__bar","data-testid":m.bar,style:{backgroundColor:n},children:a.jsx(O,{data:t,datumWidths:C,maximum:v,overColor:p,segmentWidth:oe,separatorColor:_})}),l&&a.jsx(j,{label:l,labelClassName:i})]})},W=({children:e,to:t,...n})=>a.jsx(f.Link,{...n,href:t,rel:"noreferrer noopener",target:"_blank",children:e}),q=({children:e})=>a.jsx(a.Fragment,{children:e}),A=({isCollapsed:e,setIsCollapsed:t,className:n})=>a.jsx(f.Tooltip,{className:"p-side-navigation__tooltip-wrapper",message:a.jsxs(a.Fragment,{children:[e?"expand":"collapse","( ",a.jsx("code",{children:"["})," )"]}),position:"right",tooltipClassName:"p-side-navigation__tooltip",children:a.jsx(f.Button,{appearance:"base","aria-label":`${e?"expand":"collapse"} main navigation`,className:c("is-dense has-icon is-dark u-no-margin l-navigation-collapse-toggle",n),onClick:l=>{t(!e),l.stopPropagation(),l.currentTarget.blur()},children:a.jsx(f.Icon,{light:!0,name:"sidebar-toggle"})})}),P=({children:e})=>a.jsx("div",{className:"p-panel__content",children:a.jsx("nav",{className:"p-side-navigation--icons is-dark",children:e})}),z=({children:e})=>a.jsx("div",{className:"p-panel__controls u-no-margin--top",children:e}),H=({children:e})=>a.jsx("div",{className:"l-navigation__drawer",children:a.jsx("div",{className:"p-panel is-dark",children:e})}),G=({children:e})=>a.jsx("div",{className:"p-panel__footer",children:e}),J=({children:e})=>a.jsx("div",{className:"p-panel__header",children:e}),K=({light:e=!0,name:t})=>a.jsx(f.Icon,{className:"p-side-navigation__icon",light:e,name:t}),Q=({children:e,className:t,hasActiveChild:n})=>a.jsx("li",{className:c("p-side-navigation__item",t,{"has-active-child":n}),children:e}),U=({children:e,id:t,variant:n="base"})=>a.jsx("span",{className:c("p-side-navigation__label",{"p-side-navigation__label--group":n==="group"}),id:t,children:e}),V=({as:e,...t})=>{const n=e||"a";return a.jsx(n,{className:c("p-side-navigation__link",t.className),...t})},X=({children:e,className:t})=>a.jsx("ul",{className:c("p-side-navigation__list",t),children:e}),Y=({as:e,children:t,className:n,...l})=>{const i=e||"a";return a.jsx(i,{className:c("p-panel__logo",n),...l,children:a.jsx("div",{className:"p-navigation__tagged-logo",children:t})})},Z=({children:e})=>N.cloneElement(e,{className:"p-panel__logo-icon p-navigation__logo-icon"}),R=({children:e,variant:t="base"})=>a.jsx("div",{className:c("p-panel__logo-name is-fading-when-collapsed",{"p-panel__logo-name--small":t==="small"}),children:e}),ee=({children:e})=>a.jsx("div",{className:"p-navigation__logo-tag",children:e}),ae=({children:e})=>a.jsx("span",{className:"p-panel__logo-text",children:e}),te=({children:e,className:t,onClick:n})=>a.jsx(f.Button,{appearance:"base",className:c("p-side-navigation__button--menu has-icon is-dark",t),onClick:n,children:e}),ne=({children:e})=>a.jsx("span",{className:"p-side-navigation__text",children:e}),ie="",s=({children:e,className:t,isCollapsed:n})=>a.jsx("header",{"aria-label":"main navigation",className:c("l-navigation is-maas",t,{"is-collapsed":n,"is-pinned":!n}),children:e}),$=({children:e,className:t})=>a.jsx("header",{"aria-label":"navigation",className:"l-navigation-bar",children:a.jsx("div",{className:c("p-panel is-dark",t),children:e})});s.Header=J,s.Banner=q,s.Drawer=H,s.Controls=z,s.CollapseToggle=A,s.Content=P,s.Footer=G,s.List=X,s.Item=Q,s.Link=V,s.Text=ne,s.Icon=K,s.Label=U,s.Logo=Y,s.LogoTag=ee,s.LogoIcon=Z,s.LogoName=R,s.LogoText=ae,$.MenuButton=te,r.ExternalLink=W,r.Meter=D,r.Navigation=s,r.NavigationBar=$,r.defaultEmptyColor=y,r.defaultFilledColors=x,r.defaultOverColor=S,r.defaultSeparatorColor=F,r.meterColor=g,r.testIds=m,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
8
+ transparent ${o-B}px,
9
+ ${h} ${o-B}px,
10
+ ${h} ${o}px
11
+ )`});return a.jsxs(a.Fragment,{children:[i()?a.jsx("div",{className:"p-meter__filled","data-testid":_.meteroverflow,style:{backgroundColor:C,width:"100%"}}):e==null?void 0:e.map((c,d)=>a.jsx("div",{className:"p-meter__filled","data-testid":_.filled,style:r(c,d)},`meter-${d}`)),o>0&&a.jsx("div",{className:"p-meter__separators","data-testid":_.segments,style:g()})]})},D=({className:e,children:n})=>a.jsx("div",{className:p("p-meter__label",e),"data-testid":_.label,children:n});S.Label=D;const O=({children:e,to:n,...t})=>a.jsx(m.Link,{...t,href:n,rel:"noreferrer noopener",target:"_blank",children:e}),P=({children:e})=>a.jsx(a.Fragment,{children:e}),q=({isCollapsed:e,setIsCollapsed:n,className:t})=>a.jsx(m.Tooltip,{className:"p-side-navigation__tooltip-wrapper",message:a.jsxs(a.Fragment,{children:[e?"expand":"collapse","( ",a.jsx("code",{children:"["})," )"]}),position:"right",tooltipClassName:"p-side-navigation__tooltip",children:a.jsx(m.Button,{appearance:"base","aria-label":`${e?"expand":"collapse"} main navigation`,className:p("is-dense has-icon is-dark u-no-margin l-navigation-collapse-toggle",t),onClick:o=>{n(!e),o.stopPropagation(),o.currentTarget.blur()},children:a.jsx(m.Icon,{light:!0,name:"sidebar-toggle"})})}),A=({children:e})=>a.jsx("div",{className:"p-panel__content",children:a.jsx("nav",{className:"p-side-navigation--icons is-dark",children:e})}),z=({children:e})=>a.jsx("div",{className:"p-panel__controls u-no-margin--top",children:e}),H=({children:e})=>a.jsx("div",{className:"l-navigation__drawer",children:a.jsx("div",{className:"p-panel is-dark",children:e})}),W=({children:e})=>a.jsx("div",{className:"p-panel__footer",children:e}),G=({children:e})=>a.jsx("div",{className:"p-panel__header",children:e}),J=({light:e=!0,name:n})=>a.jsx(m.Icon,{className:"p-side-navigation__icon",light:e,name:n}),K=({children:e,className:n,hasActiveChild:t})=>a.jsx("li",{className:p("p-side-navigation__item",n,{"has-active-child":t}),children:e}),Q=({children:e,id:n,variant:t="base"})=>a.jsx("span",{className:p("p-side-navigation__label",{"p-side-navigation__label--group":t==="group"}),id:n,children:e}),U=({as:e,...n})=>{const t=e||"a";return a.jsx(t,{className:p("p-side-navigation__link",n.className),...n})},V=({children:e,className:n})=>a.jsx("ul",{className:p("p-side-navigation__list",n),children:e}),X=({as:e,children:n,className:t,...o})=>{const i=e||"a";return a.jsx(i,{className:p("p-panel__logo",t),...o,children:a.jsx("div",{className:"p-navigation__tagged-logo",children:n})})},Y=({children:e})=>f.cloneElement(e,{className:"p-panel__logo-icon p-navigation__logo-icon"}),Z=({children:e,variant:n="base"})=>a.jsx("div",{className:p("p-panel__logo-name is-fading-when-collapsed",{"p-panel__logo-name--small":n==="small"}),children:e}),R=({children:e})=>a.jsx("div",{className:"p-navigation__logo-tag",children:e}),ee=({children:e})=>a.jsx("span",{className:"p-panel__logo-text",children:e}),ae=({children:e,className:n,onClick:t})=>a.jsx(m.Button,{appearance:"base",className:p("p-side-navigation__button--menu has-icon is-dark",n),onClick:o=>{t&&t(o),o.stopPropagation(),o.currentTarget.blur()},children:e}),ne=({children:e})=>a.jsx("span",{className:"p-side-navigation__text",children:e}),re="",s=({children:e,className:n,isCollapsed:t})=>a.jsx("header",{"aria-label":"main navigation",className:p("l-navigation is-maas",n,{"is-collapsed":t,"is-pinned":!t}),children:e}),x=({children:e,className:n})=>a.jsx("header",{"aria-label":"navigation",className:"l-navigation-bar",children:a.jsx("div",{className:p("p-panel is-dark",n),children:e})});s.Header=G,s.Banner=P,s.Drawer=H,s.Controls=z,s.CollapseToggle=q,s.Content=A,s.Footer=W,s.List=V,s.Item=K,s.Link=U,s.Text=ne,s.Icon=J,s.Label=Q,s.Logo=X,s.LogoTag=R,s.LogoIcon=Y,s.LogoName=Z,s.LogoText=ee,x.MenuButton=ae,l.ExternalLink=O,l.Meter=S,l.Navigation=s,l.NavigationBar=x,l.defaultFilledColors=$,l.meterColor=v,l.testIds=_,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import * as React from "react";
2
2
  export declare const meterColor: {
3
3
  readonly caution: "#F99B11";
4
4
  readonly light: "#F7F7F7";
@@ -10,25 +10,17 @@ export declare const meterColor: {
10
10
  readonly positive: "#0E8420";
11
11
  };
12
12
  export declare const defaultFilledColors: ("#F99B11" | "#0066CC" | "#C7162B" | "#0E8420")[];
13
- export declare const defaultEmptyColor: "#D3E4ED";
14
- export declare const defaultOverColor: "#F99B11";
15
- export declare const defaultSeparatorColor: "#F7F7F7";
16
13
  type MeterDatum = {
17
14
  color?: string;
18
15
  value: number;
19
16
  };
20
- type Props = {
17
+ export interface MeterProps extends React.PropsWithChildren, React.ComponentProps<"div"> {
21
18
  className?: string;
22
19
  data: MeterDatum[];
23
- emptyColor?: string;
24
- label?: string | JSX.Element;
25
- labelClassName?: string;
26
20
  max?: number;
27
- overColor?: string;
28
- segmented?: boolean;
29
- separatorColor?: string;
30
- small?: boolean;
31
- };
21
+ variant?: "regular" | "segmented";
22
+ size?: "regular" | "small";
23
+ }
32
24
  export declare const testIds: {
33
25
  bar: string;
34
26
  container: string;
@@ -37,5 +29,13 @@ export declare const testIds: {
37
29
  meteroverflow: string;
38
30
  segments: string;
39
31
  };
40
- export declare const Meter: ({ className, data, emptyColor, label, labelClassName, max, overColor, segmented, separatorColor, small, }: Props) => JSX.Element;
41
- export {};
32
+ declare const Meter: {
33
+ ({ className, children, data, max, variant, size, ...props }: MeterProps): import("react/jsx-runtime").JSX.Element;
34
+ Label: ({ className, children, }: React.PropsWithChildren<Pick<MeterProps, "className">>) => import("react/jsx-runtime").JSX.Element;
35
+ };
36
+ export interface MeterSegmentProps extends Omit<MeterProps, "children"> {
37
+ datumWidths: number[];
38
+ maximum: number;
39
+ segmentWidth: number;
40
+ }
41
+ export { Meter };
@@ -2,7 +2,7 @@ import type { Meta } from "@storybook/react";
2
2
  import { Meter } from ".";
3
3
  declare const meta: Meta<typeof Meter>;
4
4
  export default meta;
5
- export declare const Example: {
5
+ export declare const Regular: {
6
6
  args: {
7
7
  data: {
8
8
  value: number;
@@ -10,6 +10,24 @@ export declare const Example: {
10
10
  }[];
11
11
  };
12
12
  };
13
+ export declare const Segmented: {
14
+ args: {
15
+ data: {
16
+ value: number;
17
+ color: string;
18
+ }[];
19
+ variant: string;
20
+ };
21
+ };
22
+ export declare const WithLabel: {
23
+ args: {
24
+ data: {
25
+ value: number;
26
+ color: string;
27
+ }[];
28
+ children: import("react/jsx-runtime").JSX.Element;
29
+ };
30
+ };
13
31
  export declare const NoItems: {
14
32
  args: {
15
33
  data: never[];
@@ -5,4 +5,4 @@ export interface NavigationMenuButtonProps {
5
5
  className?: string;
6
6
  onClick: ButtonProps["onClick"];
7
7
  }
8
- export declare const MenuButton: ({ children, className, onClick }: NavigationMenuButtonProps) => import("react/jsx-runtime").JSX.Element;
8
+ export declare const MenuButton: ({ children, className, onClick, }: NavigationMenuButtonProps) => import("react/jsx-runtime").JSX.Element;
@@ -31,5 +31,5 @@ export interface NavigationBarProps {
31
31
  }
32
32
  export declare const NavigationBar: {
33
33
  ({ children, className }: NavigationBarProps): import("react/jsx-runtime").JSX.Element;
34
- MenuButton: ({ children, className, onClick }: import("./MenuButton/MenuButton").NavigationMenuButtonProps) => import("react/jsx-runtime").JSX.Element;
34
+ MenuButton: ({ children, className, onClick, }: import("./MenuButton/MenuButton").NavigationMenuButtonProps) => import("react/jsx-runtime").JSX.Element;
35
35
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@canonical/maas-react-components",
3
3
  "description": "React components for use in MAAS UI projects.",
4
- "version": "1.4.0",
4
+ "version": "1.5.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/canonical/maas-react-components.git"