@canonical/maas-react-components 1.0.0 → 1.0.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/README.md CHANGED
@@ -1,11 +1,23 @@
1
+ <div align="center">
2
+
1
3
  # MAAS React Components
2
4
 
3
- This project is a library of React components for use in MAAS UI projects.
5
+ <br />
6
+ <img src="https://assets.ubuntu.com/v1/142ae045-Canonical%20MAAS.png" alt="Canonical MAAS" width="180" />
7
+
8
+ <br />
9
+ <br />
10
+
11
+ Library of React components for use in MAAS UI projects.
4
12
 
5
- It contains components that are either specific to, or only used in MAAS. General purpose components should be added to
13
+ It contains components that are either specific to, or only used in MAAS. <br /> General purpose components should be added to
6
14
  [@canonical/react-components](https://github.com/canonical/react-components) instead.
7
15
 
8
- Read more in [Project philosophy and guidelines](GUIDELINES.md).
16
+ **[Storybook](https://canonical.github.io/maas-react-components/)** | **[Philosophy and guidelines](GUIDELINES.md)**
17
+
18
+ <hr />
19
+
20
+ </div>
9
21
 
10
22
  ## Getting started
11
23
 
@@ -0,0 +1,188 @@
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;
6
+ }
7
+ var y = { exports: {} };
8
+ /*!
9
+ Copyright (c) 2018 Jed Watson.
10
+ Licensed under the MIT License (MIT), see
11
+ http://jedwatson.github.io/classnames
12
+ */
13
+ (function(t) {
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;
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);
27
+ }
28
+ } else if (l === "object") {
29
+ if (e.toString !== Object.prototype.toString && !e.toString.toString().includes("[native code]")) {
30
+ r.push(e.toString());
31
+ continue;
32
+ }
33
+ for (var d in e)
34
+ s.call(e, d) && e[d] && r.push(d);
35
+ }
36
+ }
37
+ }
38
+ return r.join(" ");
39
+ }
40
+ t.exports ? (a.default = a, t.exports = a) : window.classNames = a;
41
+ })();
42
+ })(y);
43
+ var W = y.exports;
44
+ const F = /* @__PURE__ */ D(W);
45
+ const m = {
46
+ caution: "#F99B11",
47
+ light: "#F7F7F7",
48
+ linkFaded: "#D3E4ED",
49
+ link: "#0066CC",
50
+ negative: "#C7162B",
51
+ positiveFaded: "#B7CCB9",
52
+ positiveMid: "#4DAB4D",
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);
63
+ }, p = {
64
+ bar: "meter-bar",
65
+ container: "meter-container",
66
+ filled: "meter-filled",
67
+ label: "meter-label",
68
+ meteroverflow: "meter-overflow",
69
+ segments: "meter-segments"
70
+ }, L = ({
71
+ data: t,
72
+ datumWidths: s,
73
+ maximum: a,
74
+ overColor: r,
75
+ segmentWidth: n,
76
+ separatorColor: e
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,
82
+ 0
83
+ )}%`,
84
+ width: `${s[o]}%`
85
+ }), d = () => ({
86
+ background: `repeating-linear-gradient(
87
+ to right,
88
+ transparent 0,
89
+ transparent ${n - w}px,
90
+ ${e} ${n - w}px,
91
+ ${e} ${n}px
92
+ )`
93
+ });
94
+ return /* @__PURE__ */ _(j, { children: [
95
+ l() ? /* @__PURE__ */ f(
96
+ "div",
97
+ {
98
+ className: "p-meter__filled",
99
+ "data-testid": p.meteroverflow,
100
+ style: { backgroundColor: r, width: "100%" }
101
+ }
102
+ ) : t.map((u, o) => /* @__PURE__ */ f(
103
+ "div",
104
+ {
105
+ className: "p-meter__filled",
106
+ "data-testid": p.filled,
107
+ style: i(u, o)
108
+ },
109
+ `meter-${o}`
110
+ )),
111
+ n > 0 && /* @__PURE__ */ f(
112
+ "div",
113
+ {
114
+ className: "p-meter__separators",
115
+ "data-testid": p.segments,
116
+ style: d()
117
+ }
118
+ )
119
+ ] });
120
+ }, I = ({
121
+ labelClassName: t,
122
+ label: s
123
+ }) => /* @__PURE__ */ f(
124
+ "div",
125
+ {
126
+ className: F("p-meter__label", t),
127
+ "data-testid": p.label,
128
+ children: s
129
+ }
130
+ ), J = ({
131
+ className: t,
132
+ data: s,
133
+ emptyColor: a = A,
134
+ label: r,
135
+ labelClassName: n,
136
+ max: e,
137
+ overColor: l = R,
138
+ segmented: i = !1,
139
+ separatorColor: d = z,
140
+ small: u = !1
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);
143
+ O(() => {
144
+ i && S(o, c, b);
145
+ }, [c, i]);
146
+ const $ = B(() => {
147
+ S(o, c, b);
148
+ }, [o, c, b]);
149
+ return M(window, $, "resize", !0, i), /* @__PURE__ */ _(
150
+ "div",
151
+ {
152
+ className: F("p-meter", { "p-meter--small": u }, t),
153
+ "data-testid": p.container,
154
+ ref: o,
155
+ children: [
156
+ /* @__PURE__ */ f(
157
+ "div",
158
+ {
159
+ className: "p-meter__bar",
160
+ "data-testid": p.bar,
161
+ style: { backgroundColor: a },
162
+ children: /* @__PURE__ */ f(
163
+ L,
164
+ {
165
+ data: s,
166
+ datumWidths: h,
167
+ maximum: c,
168
+ overColor: l,
169
+ segmentWidth: N,
170
+ separatorColor: d
171
+ }
172
+ )
173
+ }
174
+ ),
175
+ r && /* @__PURE__ */ f(I, { label: r, labelClassName: n })
176
+ ]
177
+ }
178
+ );
179
+ };
180
+ export {
181
+ J as Meter,
182
+ A as defaultEmptyColor,
183
+ H as defaultFilledColors,
184
+ R as defaultOverColor,
185
+ z as defaultSeparatorColor,
186
+ m as meterColor,
187
+ p as testIds
188
+ };
@@ -0,0 +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:{}};/*!
2
+ Copyright (c) 2018 Jed Watson.
3
+ Licensed under the MIT License (MIT), see
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(
6
+ to right,
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"})});
@@ -0,0 +1 @@
1
+ export * from './src/lib/index'
@@ -0,0 +1,40 @@
1
+ export declare const meterColor: {
2
+ readonly caution: "#F99B11";
3
+ readonly light: "#F7F7F7";
4
+ readonly linkFaded: "#D3E4ED";
5
+ readonly link: "#0066CC";
6
+ readonly negative: "#C7162B";
7
+ readonly positiveFaded: "#B7CCB9";
8
+ readonly positiveMid: "#4DAB4D";
9
+ readonly positive: "#0E8420";
10
+ };
11
+ export declare const defaultFilledColors: ("#F99B11" | "#0066CC" | "#C7162B" | "#0E8420")[];
12
+ export declare const defaultEmptyColor: "#D3E4ED";
13
+ export declare const defaultOverColor: "#F99B11";
14
+ export declare const defaultSeparatorColor: "#F7F7F7";
15
+ type MeterDatum = {
16
+ color?: string;
17
+ value: number;
18
+ };
19
+ type Props = {
20
+ className?: string;
21
+ data: MeterDatum[];
22
+ emptyColor?: string;
23
+ label?: string | JSX.Element;
24
+ labelClassName?: string;
25
+ max?: number;
26
+ overColor?: string;
27
+ segmented?: boolean;
28
+ separatorColor?: string;
29
+ small?: boolean;
30
+ };
31
+ export declare const testIds: {
32
+ bar: string;
33
+ container: string;
34
+ filled: string;
35
+ label: string;
36
+ meteroverflow: string;
37
+ segments: string;
38
+ };
39
+ export declare const Meter: ({ className, data, emptyColor, label, labelClassName, max, overColor, segmented, separatorColor, small, }: Props) => JSX.Element;
40
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { Meta } from "@storybook/react";
2
+ import { Meter } from ".";
3
+ declare const meta: Meta<typeof Meter>;
4
+ export default meta;
5
+ export declare const Example: {
6
+ args: {
7
+ data: {
8
+ value: number;
9
+ color: string;
10
+ }[];
11
+ };
12
+ };
13
+ export declare const NoItems: {
14
+ args: {
15
+ data: never[];
16
+ };
17
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./Meter";
@@ -0,0 +1 @@
1
+ export * from "./Meter";
@@ -0,0 +1 @@
1
+ export * from "./elements";
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ .p-meter{margin-bottom:.75rem;padding-top:.375rem}.p-meter__bar{border-radius:.875rem;height:.875rem;overflow:hidden;position:relative;width:100%;border:1px solid #999}.p-meter__label{display:flex;justify-content:space-between;margin-bottom:-.125rem;padding-top:.25rem}.p-meter__filled{height:100%;position:absolute;width:0%}.p-meter__separators{height:100%;position:absolute;width:100%;z-index:1}.p-meter--small{margin-bottom:.875rem;padding-top:.375rem}.p-meter--small .p-meter__bar{border-radius:.75rem;height:.75rem;margin-bottom:.375rem}.p-meter--small .p-meter__label{margin-bottom:0;padding-top:0}
File without changes
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.0",
4
+ "version": "1.0.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/canonical/maas-react-components.git"
@@ -39,13 +39,25 @@
39
39
  "test:ui": "vitest --ui",
40
40
  "test:watch": "vitest",
41
41
  "semantic-release": "semantic-release",
42
- "semantic-release-dry-run": "semantic-release --dry-run --no-ci"
42
+ "semantic-release-dry-run": "semantic-release --dry-run --no-ci",
43
+ "storybook": "storybook dev -p 6006",
44
+ "build-storybook": "storybook build"
43
45
  },
44
46
  "devDependencies": {
45
47
  "@commitlint/cli": "^17.7.1",
46
48
  "@commitlint/config-conventional": "^17.7.0",
49
+ "@etchteam/storybook-addon-status": "^4.2.4",
47
50
  "@semantic-release/changelog": "^6.0.3",
48
51
  "@semantic-release/git": "^10.0.1",
52
+ "@storybook/addon-a11y": "^7.4.6",
53
+ "@storybook/addon-essentials": "^7.4.6",
54
+ "@storybook/addon-interactions": "^7.4.6",
55
+ "@storybook/addon-links": "^7.4.6",
56
+ "@storybook/addon-onboarding": "^1.0.8",
57
+ "@storybook/blocks": "^7.4.6",
58
+ "@storybook/react": "^7.4.6",
59
+ "@storybook/react-vite": "^7.4.6",
60
+ "@storybook/testing-library": "^0.2.2",
49
61
  "@testing-library/jest-dom": "^6.1.3",
50
62
  "@testing-library/react": "^14.0.0",
51
63
  "@testing-library/user-event": "^14.5.1",
@@ -62,11 +74,17 @@
62
74
  "eslint-plugin-prettier": "^5.0.0",
63
75
  "eslint-plugin-react": "^7.33.2",
64
76
  "eslint-plugin-react-hooks": "^4.6.0",
77
+ "eslint-plugin-storybook": "^0.6.14",
65
78
  "eslint-plugin-unused-imports": "^3.0.0",
66
79
  "husky": "8.0.0",
80
+ "jsdom": "^22.1.0",
67
81
  "prettier": "^3.0.3",
82
+ "prop-types": "^15.8.1",
68
83
  "sass": "^1.68.0",
84
+ "sb-addon-permutation-table": "^1.0.21",
69
85
  "semantic-release": "^22.0.5",
86
+ "storybook": "^7.4.6",
87
+ "storybook-addon-tags": "^0.0.1",
70
88
  "vite": "^4.4.9",
71
89
  "vite-plugin-dts": "^3.6.0",
72
90
  "vitest": "^0.34.5"
@@ -76,6 +94,7 @@
76
94
  "@types/react-dom": "18.2.6"
77
95
  },
78
96
  "peerDependencies": {
97
+ "classnames": "^2.3.2",
79
98
  "@canonical/react-components": "^0.47.0",
80
99
  "@types/react": "^17.0.2 || ^18.0.0",
81
100
  "@types/react-dom": "^17.0.2 || ^18.0.0",