@canonical/maas-react-components 1.0.1 → 1.2.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,8 +1,8 @@
1
- import { jsxs as _, jsx as f, Fragment as j } from "react/jsx-runtime";
2
- import { useRef as k, useState as E, useEffect as O, useCallback as B } from "react";
3
- import { useListener as M } from "@canonical/react-components";
4
- function D(t) {
5
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
1
+ import { jsxs as _, jsx as d, Fragment as $ } from "react/jsx-runtime";
2
+ import { useRef as E, useState as j, useEffect as O, useCallback as B } from "react";
3
+ import { useListener as M, Link as D } from "@canonical/react-components";
4
+ function L(e) {
5
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
6
6
  }
7
7
  var y = { exports: {} };
8
8
  /*!
@@ -10,39 +10,39 @@ var y = { exports: {} };
10
10
  Licensed under the MIT License (MIT), see
11
11
  http://jedwatson.github.io/classnames
12
12
  */
13
- (function(t) {
13
+ (function(e) {
14
14
  (function() {
15
- var s = {}.hasOwnProperty;
16
- function a() {
17
- for (var r = [], n = 0; n < arguments.length; n++) {
18
- var e = arguments[n];
19
- if (e) {
20
- var l = typeof e;
15
+ var r = {}.hasOwnProperty;
16
+ function s() {
17
+ for (var n = [], o = 0; o < arguments.length; o++) {
18
+ var t = arguments[o];
19
+ if (t) {
20
+ var l = typeof t;
21
21
  if (l === "string" || l === "number")
22
- r.push(e);
23
- else if (Array.isArray(e)) {
24
- if (e.length) {
25
- var i = a.apply(null, e);
26
- i && r.push(i);
22
+ n.push(t);
23
+ else if (Array.isArray(t)) {
24
+ if (t.length) {
25
+ var i = s.apply(null, t);
26
+ i && n.push(i);
27
27
  }
28
28
  } else if (l === "object") {
29
- if (e.toString !== Object.prototype.toString && !e.toString.toString().includes("[native code]")) {
30
- r.push(e.toString());
29
+ if (t.toString !== Object.prototype.toString && !t.toString.toString().includes("[native code]")) {
30
+ n.push(t.toString());
31
31
  continue;
32
32
  }
33
- for (var d in e)
34
- s.call(e, d) && e[d] && r.push(d);
33
+ for (var u in t)
34
+ r.call(t, u) && t[u] && n.push(u);
35
35
  }
36
36
  }
37
37
  }
38
- return r.join(" ");
38
+ return n.join(" ");
39
39
  }
40
- t.exports ? (a.default = a, t.exports = a) : window.classNames = a;
40
+ e.exports ? (s.default = s, e.exports = s) : window.classNames = s;
41
41
  })();
42
42
  })(y);
43
43
  var W = y.exports;
44
- const F = /* @__PURE__ */ D(W);
45
- const m = {
44
+ const k = /* @__PURE__ */ L(W);
45
+ const f = {
46
46
  caution: "#F99B11",
47
47
  light: "#F7F7F7",
48
48
  linkFaded: "#D3E4ED",
@@ -51,15 +51,15 @@ const m = {
51
51
  positiveFaded: "#B7CCB9",
52
52
  positiveMid: "#4DAB4D",
53
53
  positive: "#0E8420"
54
- }, H = [
55
- m.link,
56
- m.positive,
57
- m.negative,
58
- m.caution
59
- ], A = m.linkFaded, R = m.caution, z = m.light, C = 2, w = 1, S = (t, s, a) => {
60
- var e, l;
61
- const r = ((l = (e = t == null ? void 0 : t.current) == null ? void 0 : e.getBoundingClientRect()) == null ? void 0 : l.width) || 0, n = r > s * C ? r / s : C;
62
- a(n);
54
+ }, J = [
55
+ f.link,
56
+ f.positive,
57
+ f.negative,
58
+ f.caution
59
+ ], A = f.linkFaded, R = f.caution, z = f.light, C = 2, w = 1, S = (e, r, s) => {
60
+ var t, l;
61
+ const n = ((l = (t = e == null ? void 0 : e.current) == null ? void 0 : t.getBoundingClientRect()) == null ? void 0 : l.width) || 0, o = n > r * C ? n / r : C;
62
+ s(o);
63
63
  }, p = {
64
64
  bar: "meter-bar",
65
65
  container: "meter-container",
@@ -67,122 +67,123 @@ const m = {
67
67
  label: "meter-label",
68
68
  meteroverflow: "meter-overflow",
69
69
  segments: "meter-segments"
70
- }, L = ({
71
- data: t,
72
- datumWidths: s,
73
- maximum: a,
74
- overColor: r,
75
- segmentWidth: n,
76
- separatorColor: e
70
+ }, I = ({
71
+ data: e,
72
+ datumWidths: r,
73
+ maximum: s,
74
+ overColor: n,
75
+ segmentWidth: o,
76
+ separatorColor: t
77
77
  }) => {
78
- const l = () => t.reduce((u, o) => u + o.value, 0) > a, i = (u, o) => ({
79
- backgroundColor: u.color,
80
- left: `${s.reduce(
81
- (v, c, h) => o > h ? v + c : v,
78
+ const l = () => e.reduce((m, a) => m + a.value, 0) > s, i = (m, a) => ({
79
+ backgroundColor: m.color,
80
+ left: `${r.reduce(
81
+ (v, c, h) => a > h ? v + c : v,
82
82
  0
83
83
  )}%`,
84
- width: `${s[o]}%`
85
- }), d = () => ({
84
+ width: `${r[a]}%`
85
+ }), u = () => ({
86
86
  background: `repeating-linear-gradient(
87
87
  to right,
88
88
  transparent 0,
89
- transparent ${n - w}px,
90
- ${e} ${n - w}px,
91
- ${e} ${n}px
89
+ transparent ${o - w}px,
90
+ ${t} ${o - w}px,
91
+ ${t} ${o}px
92
92
  )`
93
93
  });
94
- return /* @__PURE__ */ _(j, { children: [
95
- l() ? /* @__PURE__ */ f(
94
+ return /* @__PURE__ */ _($, { children: [
95
+ l() ? /* @__PURE__ */ d(
96
96
  "div",
97
97
  {
98
98
  className: "p-meter__filled",
99
99
  "data-testid": p.meteroverflow,
100
- style: { backgroundColor: r, width: "100%" }
100
+ style: { backgroundColor: n, width: "100%" }
101
101
  }
102
- ) : t.map((u, o) => /* @__PURE__ */ f(
102
+ ) : e.map((m, a) => /* @__PURE__ */ d(
103
103
  "div",
104
104
  {
105
105
  className: "p-meter__filled",
106
106
  "data-testid": p.filled,
107
- style: i(u, o)
107
+ style: i(m, a)
108
108
  },
109
- `meter-${o}`
109
+ `meter-${a}`
110
110
  )),
111
- n > 0 && /* @__PURE__ */ f(
111
+ o > 0 && /* @__PURE__ */ d(
112
112
  "div",
113
113
  {
114
114
  className: "p-meter__separators",
115
115
  "data-testid": p.segments,
116
- style: d()
116
+ style: u()
117
117
  }
118
118
  )
119
119
  ] });
120
- }, I = ({
121
- labelClassName: t,
122
- label: s
123
- }) => /* @__PURE__ */ f(
120
+ }, P = ({
121
+ labelClassName: e,
122
+ label: r
123
+ }) => /* @__PURE__ */ d(
124
124
  "div",
125
125
  {
126
- className: F("p-meter__label", t),
126
+ className: k("p-meter__label", e),
127
127
  "data-testid": p.label,
128
- children: s
128
+ children: r
129
129
  }
130
- ), J = ({
131
- className: t,
132
- data: s,
133
- emptyColor: a = A,
134
- label: r,
135
- labelClassName: n,
136
- max: e,
130
+ ), K = ({
131
+ className: e,
132
+ data: r,
133
+ emptyColor: s = A,
134
+ label: n,
135
+ labelClassName: o,
136
+ max: t,
137
137
  overColor: l = R,
138
138
  segmented: i = !1,
139
- separatorColor: d = z,
140
- small: u = !1
139
+ separatorColor: u = z,
140
+ small: m = !1
141
141
  }) => {
142
- const o = k(null), v = s.reduce((g, x) => g + x.value, 0), c = e || v, h = s.map((g) => g.value / c * 100), [N, b] = E(0);
142
+ const a = E(null), v = r.reduce((g, N) => g + N.value, 0), c = t || v, h = r.map((g) => g.value / c * 100), [F, b] = j(0);
143
143
  O(() => {
144
- i && S(o, c, b);
144
+ i && S(a, c, b);
145
145
  }, [c, i]);
146
- const $ = B(() => {
147
- S(o, c, b);
148
- }, [o, c, b]);
149
- return M(window, $, "resize", !0, i), /* @__PURE__ */ _(
146
+ const x = B(() => {
147
+ S(a, c, b);
148
+ }, [a, c, b]);
149
+ return M(window, x, "resize", !0, i), /* @__PURE__ */ _(
150
150
  "div",
151
151
  {
152
- className: F("p-meter", { "p-meter--small": u }, t),
152
+ className: k("p-meter", { "p-meter--small": m }, e),
153
153
  "data-testid": p.container,
154
- ref: o,
154
+ ref: a,
155
155
  children: [
156
- /* @__PURE__ */ f(
156
+ /* @__PURE__ */ d(
157
157
  "div",
158
158
  {
159
159
  className: "p-meter__bar",
160
160
  "data-testid": p.bar,
161
- style: { backgroundColor: a },
162
- children: /* @__PURE__ */ f(
163
- L,
161
+ style: { backgroundColor: s },
162
+ children: /* @__PURE__ */ d(
163
+ I,
164
164
  {
165
- data: s,
165
+ data: r,
166
166
  datumWidths: h,
167
167
  maximum: c,
168
168
  overColor: l,
169
- segmentWidth: N,
170
- separatorColor: d
169
+ segmentWidth: F,
170
+ separatorColor: u
171
171
  }
172
172
  )
173
173
  }
174
174
  ),
175
- r && /* @__PURE__ */ f(I, { label: r, labelClassName: n })
175
+ n && /* @__PURE__ */ d(P, { label: n, labelClassName: o })
176
176
  ]
177
177
  }
178
178
  );
179
- };
179
+ }, Q = ({ children: e, to: r, ...s }) => /* @__PURE__ */ d(D, { ...s, href: r, rel: "noreferrer noopener", target: "_blank", children: e });
180
180
  export {
181
- J as Meter,
181
+ Q as ExternalLink,
182
+ K as Meter,
182
183
  A as defaultEmptyColor,
183
- H as defaultFilledColors,
184
+ J as defaultFilledColors,
184
185
  R as defaultOverColor,
185
186
  z as defaultSeparatorColor,
186
- m as meterColor,
187
+ f as meterColor,
187
188
  p as testIds
188
189
  };
@@ -1,11 +1,11 @@
1
- (function(n,s){typeof exports=="object"&&typeof module<"u"?s(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"],s):(n=typeof globalThis<"u"?globalThis:n||self,s(n["@canonical/maas-react-components"]={},n["react/jsx-runtime"],n.React,n.reactComponents))})(this,function(n,s,h,E){"use strict";function M(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var S={exports:{}};/*!
1
+ (function(n,r){typeof exports=="object"&&typeof module<"u"?r(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"],r):(n=typeof globalThis<"u"?globalThis:n||self,r(n["@canonical/maas-react-components"]={},n["react/jsx-runtime"],n.React,n["@canonical/react-components"]))})(this,function(n,r,h,S){"use strict";function $(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(t){(function(){var r={}.hasOwnProperty;function i(){for(var o=[],a=0;a<arguments.length;a++){var e=arguments[a];if(e){var c=typeof e;if(c==="string"||c==="number")o.push(e);else if(Array.isArray(e)){if(e.length){var u=i.apply(null,e);u&&o.push(u)}}else if(c==="object"){if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]")){o.push(e.toString());continue}for(var p in e)r.call(e,p)&&e[p]&&o.push(p)}}}return o.join(" ")}t.exports?(i.default=i,t.exports=i):window.classNames=i})()})(S);var k=S.exports;const w=M(k),I="",d={caution:"#F99B11",light:"#F7F7F7",linkFaded:"#D3E4ED",link:"#0066CC",negative:"#C7162B",positiveFaded:"#B7CCB9",positiveMid:"#4DAB4D",positive:"#0E8420"},B=[d.link,d.positive,d.negative,d.caution],_=d.linkFaded,F=d.caution,j=d.light,N=2,O=1,$=(t,r,i)=>{var e,c;const o=((c=(e=t==null?void 0:t.current)==null?void 0:e.getBoundingClientRect())==null?void 0:c.width)||0,a=o>r*N?o/r:N;i(a)},m={bar:"meter-bar",container:"meter-container",filled:"meter-filled",label:"meter-label",meteroverflow:"meter-overflow",segments:"meter-segments"},D=({data:t,datumWidths:r,maximum:i,overColor:o,segmentWidth:a,separatorColor:e})=>{const c=()=>t.reduce((v,l)=>v+l.value,0)>i,u=(v,l)=>({backgroundColor:v.color,left:`${r.reduce((C,f,b)=>l>b?C+f:C,0)}%`,width:`${r[l]}%`}),p=()=>({background:`repeating-linear-gradient(
5
+ */(function(e){(function(){var s={}.hasOwnProperty;function o(){for(var a=[],l=0;l<arguments.length;l++){var t=arguments[l];if(t){var c=typeof t;if(c==="string"||c==="number")a.push(t);else if(Array.isArray(t)){if(t.length){var u=o.apply(null,t);u&&a.push(u)}}else if(c==="object"){if(t.toString!==Object.prototype.toString&&!t.toString.toString().includes("[native code]")){a.push(t.toString());continue}for(var m in t)s.call(t,m)&&t[m]&&a.push(m)}}}return a.join(" ")}e.exports?(o.default=o,e.exports=o):window.classNames=o})()})(w);var M=w.exports;const _=$(M),I="",d={caution:"#F99B11",light:"#F7F7F7",linkFaded:"#D3E4ED",link:"#0066CC",negative:"#C7162B",positiveFaded:"#B7CCB9",positiveMid:"#4DAB4D",positive:"#0E8420"},B=[d.link,d.positive,d.negative,d.caution],k=d.linkFaded,F=d.caution,j=d.light,E=2,N=1,O=(e,s,o)=>{var t,c;const a=((c=(t=e==null?void 0:e.current)==null?void 0:t.getBoundingClientRect())==null?void 0:c.width)||0,l=a>s*E?a/s:E;o(l)},p={bar:"meter-bar",container:"meter-container",filled:"meter-filled",label:"meter-label",meteroverflow:"meter-overflow",segments:"meter-segments"},x=({data:e,datumWidths:s,maximum:o,overColor:a,segmentWidth:l,separatorColor:t})=>{const c=()=>e.reduce((v,i)=>v+i.value,0)>o,u=(v,i)=>({backgroundColor:v.color,left:`${s.reduce((b,f,C)=>i>C?b+f:b,0)}%`,width:`${s[i]}%`}),m=()=>({background:`repeating-linear-gradient(
6
6
  to right,
7
7
  transparent 0,
8
- transparent ${a-O}px,
9
- ${e} ${a-O}px,
10
- ${e} ${a}px
11
- )`});return s.jsxs(s.Fragment,{children:[c()?s.jsx("div",{className:"p-meter__filled","data-testid":m.meteroverflow,style:{backgroundColor:o,width:"100%"}}):t.map((v,l)=>s.jsx("div",{className:"p-meter__filled","data-testid":m.filled,style:u(v,l)},`meter-${l}`)),a>0&&s.jsx("div",{className:"p-meter__separators","data-testid":m.segments,style:p()})]})},x=({labelClassName:t,label:r})=>s.jsx("div",{className:w("p-meter__label",t),"data-testid":m.label,children:r}),W=({className:t,data:r,emptyColor:i=_,label:o,labelClassName:a,max:e,overColor:c=F,segmented:u=!1,separatorColor:p=j,small:v=!1})=>{const l=h.useRef(null),C=r.reduce((y,z)=>y+z.value,0),f=e||C,b=r.map(y=>y.value/f*100),[q,g]=h.useState(0);h.useEffect(()=>{u&&$(l,f,g)},[f,u]);const A=h.useCallback(()=>{$(l,f,g)},[l,f,g]);return E.useListener(window,A,"resize",!0,u),s.jsxs("div",{className:w("p-meter",{"p-meter--small":v},t),"data-testid":m.container,ref:l,children:[s.jsx("div",{className:"p-meter__bar","data-testid":m.bar,style:{backgroundColor:i},children:s.jsx(D,{data:r,datumWidths:b,maximum:f,overColor:c,segmentWidth:q,separatorColor:p})}),o&&s.jsx(x,{label:o,labelClassName:a})]})};n.Meter=W,n.defaultEmptyColor=_,n.defaultFilledColors=B,n.defaultOverColor=F,n.defaultSeparatorColor=j,n.meterColor=d,n.testIds=m,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
8
+ transparent ${l-N}px,
9
+ ${t} ${l-N}px,
10
+ ${t} ${l}px
11
+ )`});return r.jsxs(r.Fragment,{children:[c()?r.jsx("div",{className:"p-meter__filled","data-testid":p.meteroverflow,style:{backgroundColor:a,width:"100%"}}):e.map((v,i)=>r.jsx("div",{className:"p-meter__filled","data-testid":p.filled,style:u(v,i)},`meter-${i}`)),l>0&&r.jsx("div",{className:"p-meter__separators","data-testid":p.segments,style:m()})]})},D=({labelClassName:e,label:s})=>r.jsx("div",{className:_("p-meter__label",e),"data-testid":p.label,children:s}),L=({className:e,data:s,emptyColor:o=k,label:a,labelClassName:l,max:t,overColor:c=F,segmented:u=!1,separatorColor:m=j,small:v=!1})=>{const i=h.useRef(null),b=s.reduce((y,z)=>y+z.value,0),f=t||b,C=s.map(y=>y.value/f*100),[q,g]=h.useState(0);h.useEffect(()=>{u&&O(i,f,g)},[f,u]);const A=h.useCallback(()=>{O(i,f,g)},[i,f,g]);return S.useListener(window,A,"resize",!0,u),r.jsxs("div",{className:_("p-meter",{"p-meter--small":v},e),"data-testid":p.container,ref:i,children:[r.jsx("div",{className:"p-meter__bar","data-testid":p.bar,style:{backgroundColor:o},children:r.jsx(x,{data:s,datumWidths:C,maximum:f,overColor:c,segmentWidth:q,separatorColor:m})}),a&&r.jsx(D,{label:a,labelClassName:l})]})},W=({children:e,to:s,...o})=>r.jsx(S.Link,{...o,href:s,rel:"noreferrer noopener",target:"_blank",children:e});n.ExternalLink=W,n.Meter=L,n.defaultEmptyColor=k,n.defaultFilledColors=B,n.defaultOverColor=F,n.defaultSeparatorColor=j,n.meterColor=d,n.testIds=p,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,2 @@
1
+ import { AriaAttributes, PropsWithChildren } from "react";
2
+ export declare const NestedFormGroup: ({ children, ...props }: PropsWithChildren & Pick<AriaAttributes, "aria-hidden">) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import type { Meta } from "@storybook/react";
2
+ import { NestedFormGroup } from ".";
3
+ declare const meta: Meta<typeof NestedFormGroup>;
4
+ export default meta;
5
+ export declare const Example: {
6
+ args: {
7
+ "aria-hidden": boolean;
8
+ };
9
+ };
10
+ export declare const ControlledExample: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from "./NestedFormGroup";
@@ -0,0 +1 @@
1
+ export * from "./NestedFormGroup";
@@ -0,0 +1,7 @@
1
+ import { LinkProps } from "@canonical/react-components";
2
+ import type { LinkProps as RouterLinkProps } from "react-router-dom";
3
+ type ExternalLinkProps = Pick<LinkProps, "children"> & Omit<RouterLinkProps, "children"> & {
4
+ to: string;
5
+ };
6
+ export declare const ExternalLink: ({ children, to, ...props }: ExternalLinkProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { Meta } from "@storybook/react";
2
+ import { ExternalLink } from ".";
3
+ declare const meta: Meta<typeof ExternalLink>;
4
+ export default meta;
5
+ export declare const Example: {
6
+ args: {
7
+ children: string;
8
+ to: string;
9
+ };
10
+ };
@@ -0,0 +1 @@
1
+ export * from "./ExternalLink";
@@ -1 +1,2 @@
1
1
  export * from "./Meter";
2
+ export * from "./ExternalLink";
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.0.1",
4
+ "version": "1.2.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/canonical/maas-react-components.git"
@@ -100,6 +100,7 @@
100
100
  "@types/react-dom": "^17.0.2 || ^18.0.0",
101
101
  "react": "18.2.0",
102
102
  "react-dom": "18.2.0",
103
+ "react-router-dom": "^6.0.0",
103
104
  "vanilla-framework": "^4.3.0"
104
105
  }
105
106
  }