@canonical/maas-react-components 0.1.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,8 +1,64 @@
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>
21
+
22
+ ## Getting started
23
+
24
+ ### Installation
25
+
26
+ ```bash
27
+ npm install @canonical/maas-react-components
28
+ ```
29
+
30
+ or using yarn:
31
+
32
+ ```bash
33
+ yarn add @canonical/maas-react-components
34
+ ```
35
+
36
+ Add styles import to your app:
37
+
38
+ ```css
39
+ @import "@canonical/maas-react-components/dist/style.css";
40
+ ```
41
+
42
+ ## Development with `maas-react-components`
43
+
44
+ To see the changes you make to `maas-react-components` reflected in a consuming app immediately, follow these steps:
45
+
46
+ 1. In the `maas-react-components` directory, run the following command to create a symlink:
47
+
48
+ ```bash
49
+ yarn link
50
+ ```
51
+
52
+ 2. In the consuming repository (e.g., `maas-ui`), run the following command to use the local version of `maas-react-components`:
53
+
54
+ ```bash
55
+ yarn link "@canonical/maas-react-components"
56
+ ```
57
+
58
+ 3. Go back to `maas-react-components` directory and run the following command to start the build process with the watch flag:
59
+
60
+ ```bash
61
+ npm run build:watch
62
+ ```
63
+
64
+ 4. As you make changes to `maas-react-components` they will be automatically built and reflected in the consuming app.
@@ -1 +1,188 @@
1
-
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
+ };
@@ -1 +1,11 @@
1
- (function(n){typeof define=="function"&&define.amd?define(n):n()})(function(){"use strict"});
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}
package/package.json CHANGED
@@ -1,44 +1,105 @@
1
1
  {
2
2
  "name": "@canonical/maas-react-components",
3
3
  "description": "React components for use in MAAS UI projects.",
4
- "version": "0.1.0",
4
+ "version": "1.0.1",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/canonical/maas-react-components.git"
7
+ "url": "https://github.com/canonical/maas-react-components.git"
8
8
  },
9
9
  "bugs": {
10
10
  "url": "https://github.com/canonical/maas-react-components/issues"
11
11
  },
12
12
  "homepage": "https://github.com/canonical/maas-react-components#readme",
13
- "main": "src/lib/index.ts",
13
+ "main": "./dist/@canonical/maas-react-components.umd.js",
14
+ "module": "./dist/@canonical/maas-react-components.es.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/@canonical/maas-react-components.es.js",
20
+ "require": "./dist/@canonical/maas-react-components.umd.js"
21
+ },
22
+ "./dist/style.css": {
23
+ "import": "./dist/style.css",
24
+ "require": "./dist/style.css"
25
+ }
26
+ },
14
27
  "files": [
15
- "dist/**/*"
28
+ "dist"
16
29
  ],
17
30
  "license": "AGPL-3.0",
18
31
  "scripts": {
19
32
  "prepare": "husky install",
20
33
  "build": "tsc && vite build",
21
34
  "build:watch": "tsc && vite build --watch",
35
+ "lint": "eslint src && tsc --noEmit",
36
+ "lint:fix": "eslint --fix src",
37
+ "format": "prettier --write 'src/**/*.{ts,tsx,css,md,json}' --config ./.prettierrc",
22
38
  "test": "vitest run",
23
39
  "test:ui": "vitest --ui",
24
- "test:watch": "vitest"
40
+ "test:watch": "vitest",
41
+ "semantic-release": "semantic-release",
42
+ "semantic-release-dry-run": "semantic-release --dry-run --no-ci",
43
+ "storybook": "storybook dev -p 6006",
44
+ "build-storybook": "storybook build"
25
45
  },
26
46
  "devDependencies": {
27
47
  "@commitlint/cli": "^17.7.1",
28
48
  "@commitlint/config-conventional": "^17.7.0",
49
+ "@etchteam/storybook-addon-status": "^4.2.4",
50
+ "@semantic-release/changelog": "^6.0.3",
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",
29
61
  "@testing-library/jest-dom": "^6.1.3",
30
62
  "@testing-library/react": "^14.0.0",
31
63
  "@testing-library/user-event": "^14.5.1",
64
+ "@types/react-dom": "18.2.7",
65
+ "@typescript-eslint/eslint-plugin": "^6.7.3",
66
+ "@typescript-eslint/parser": "^6.7.3",
32
67
  "@vitejs/plugin-react": "^4.1.0",
68
+ "eslint": "^8.50.0",
69
+ "eslint-config-prettier": "^9.0.0",
70
+ "eslint-import-resolver-typescript": "^3.6.1",
71
+ "eslint-plugin-import": "^2.28.1",
72
+ "eslint-plugin-jsx-a11y": "^6.7.1",
73
+ "eslint-plugin-no-relative-import-paths": "^1.5.2",
74
+ "eslint-plugin-prettier": "^5.0.0",
75
+ "eslint-plugin-react": "^7.33.2",
76
+ "eslint-plugin-react-hooks": "^4.6.0",
77
+ "eslint-plugin-storybook": "^0.6.14",
78
+ "eslint-plugin-unused-imports": "^3.0.0",
33
79
  "husky": "8.0.0",
80
+ "jsdom": "^22.1.0",
81
+ "prettier": "^3.0.3",
82
+ "prop-types": "^15.8.1",
34
83
  "sass": "^1.68.0",
84
+ "sb-addon-permutation-table": "^1.0.21",
85
+ "semantic-release": "^22.0.5",
86
+ "storybook": "^7.4.6",
87
+ "storybook-addon-tags": "^0.0.1",
35
88
  "vite": "^4.4.9",
36
89
  "vite-plugin-dts": "^3.6.0",
37
90
  "vitest": "^0.34.5"
38
91
  },
39
- "dependencies": {
40
- "react": "^18.2.0",
41
- "react-dom": "^18.2.0",
92
+ "resolutions": {
93
+ "@types/react": "18.2.14",
94
+ "@types/react-dom": "18.2.6"
95
+ },
96
+ "peerDependencies": {
97
+ "classnames": "^2.3.2",
98
+ "@canonical/react-components": "^0.47.0",
99
+ "@types/react": "^17.0.2 || ^18.0.0",
100
+ "@types/react-dom": "^17.0.2 || ^18.0.0",
101
+ "react": "18.2.0",
102
+ "react-dom": "18.2.0",
42
103
  "vanilla-framework": "^4.3.0"
43
104
  }
44
105
  }
@@ -1 +0,0 @@
1
- export * from '../src/lib/index'
@@ -1,2 +0,0 @@
1
- declare const _default: import("vite").UserConfig;
2
- export default _default;
package/src/lib/index.ts DELETED
File without changes