@telia/teddy 0.1.6 → 0.1.7

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.
@@ -19,6 +19,7 @@ const components_drawer_index = require("./drawer/index.cjs");
19
19
  const components_image_image = require("./image/image.cjs");
20
20
  const components_chip_index = require("./chip/index.cjs");
21
21
  const components_datePicker_datePicker = require("./date-picker/date-picker.cjs");
22
+ const components_metricmeter_metricmeter = require("./metricmeter/metricmeter.cjs");
22
23
  const components_notification_notification = require("./notification/notification.cjs");
23
24
  const components_radioGroup_index = require("./radio-group/index.cjs");
24
25
  const components_box_box = require("./box/box.cjs");
@@ -73,6 +74,7 @@ exports.Drawer = components_drawer_index.Drawer;
73
74
  exports.Image = components_image_image.Image;
74
75
  exports.Chip = components_chip_index.Chip;
75
76
  exports.DatePicker = components_datePicker_datePicker.DatePicker;
77
+ exports.MetricMeter = components_metricmeter_metricmeter.MetricMeter;
76
78
  exports.Notification = components_notification_notification.Notification;
77
79
  exports.RadioGroup = components_radioGroup_index.RadioGroup;
78
80
  exports.Box = components_box_box.Box;
@@ -17,6 +17,7 @@ export * from './drawer';
17
17
  export * from './image';
18
18
  export * from './chip';
19
19
  export * from './date-picker';
20
+ export * from './metricmeter';
20
21
  export * from './modal';
21
22
  export * from './notification';
22
23
  export * from './radio-group';
@@ -17,6 +17,7 @@ import { Drawer } from "./drawer/index.js";
17
17
  import { Image } from "./image/image.js";
18
18
  import { Chip } from "./chip/index.js";
19
19
  import { DatePicker } from "./date-picker/date-picker.js";
20
+ import { MetricMeter } from "./metricmeter/metricmeter.js";
20
21
  import { Notification } from "./notification/notification.js";
21
22
  import { RadioGroup } from "./radio-group/index.js";
22
23
  import { Box } from "./box/box.js";
@@ -80,6 +81,7 @@ export {
80
81
  Label,
81
82
  Link,
82
83
  List,
84
+ MetricMeter,
83
85
  M as Modal,
84
86
  N as NavigationMenu,
85
87
  Notabene,
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const clsx = require("clsx");
4
+ const metricmeter = "_metricmeter_1wov3_1";
5
+ const metricmeter__svg = "_metricmeter__svg_1wov3_11";
6
+ const metricmeter__controls = "_metricmeter__controls_1wov3_28";
7
+ const metricmeter__button = "_metricmeter__button_1wov3_37";
8
+ const styles = {
9
+ metricmeter,
10
+ metricmeter__svg,
11
+ "metricmeter__svg-container": "_metricmeter__svg-container_1wov3_25",
12
+ metricmeter__controls,
13
+ metricmeter__button,
14
+ "metricmeter__button--decrease": "_metricmeter__button--decrease_1wov3_49",
15
+ "metricmeter__button--disabled": "_metricmeter__button--disabled_1wov3_53",
16
+ "metricmeter__label-container": "_metricmeter__label-container_1wov3_59",
17
+ "metricmeter__speed-label": "_metricmeter__speed-label_1wov3_66",
18
+ "metricmeter__speed-unit-label": "_metricmeter__speed-unit-label_1wov3_70"
19
+ };
20
+ const rootClassName = "metricmeter";
21
+ const css = (suffix) => {
22
+ if (suffix == null)
23
+ return "";
24
+ let tmp = null;
25
+ if (suffix.startsWith("_") || suffix.startsWith("-") || suffix === "") {
26
+ tmp = clsx([styles[`${rootClassName + suffix}`]], "");
27
+ } else {
28
+ tmp = clsx([styles[`${suffix}`]], "");
29
+ }
30
+ if (!tmp) {
31
+ console.warn("Could not find css class " + suffix + " for the root " + rootClassName);
32
+ }
33
+ return tmp;
34
+ };
35
+ exports.css = css;
@@ -0,0 +1 @@
1
+ export declare const css: (suffix: string | null) => string;
@@ -0,0 +1,35 @@
1
+ import clsx from "clsx";
2
+ const metricmeter = "_metricmeter_1wov3_1";
3
+ const metricmeter__svg = "_metricmeter__svg_1wov3_11";
4
+ const metricmeter__controls = "_metricmeter__controls_1wov3_28";
5
+ const metricmeter__button = "_metricmeter__button_1wov3_37";
6
+ const styles = {
7
+ metricmeter,
8
+ metricmeter__svg,
9
+ "metricmeter__svg-container": "_metricmeter__svg-container_1wov3_25",
10
+ metricmeter__controls,
11
+ metricmeter__button,
12
+ "metricmeter__button--decrease": "_metricmeter__button--decrease_1wov3_49",
13
+ "metricmeter__button--disabled": "_metricmeter__button--disabled_1wov3_53",
14
+ "metricmeter__label-container": "_metricmeter__label-container_1wov3_59",
15
+ "metricmeter__speed-label": "_metricmeter__speed-label_1wov3_66",
16
+ "metricmeter__speed-unit-label": "_metricmeter__speed-unit-label_1wov3_70"
17
+ };
18
+ const rootClassName = "metricmeter";
19
+ const css = (suffix) => {
20
+ if (suffix == null)
21
+ return "";
22
+ let tmp = null;
23
+ if (suffix.startsWith("_") || suffix.startsWith("-") || suffix === "") {
24
+ tmp = clsx([styles[`${rootClassName + suffix}`]], "");
25
+ } else {
26
+ tmp = clsx([styles[`${suffix}`]], "");
27
+ }
28
+ if (!tmp) {
29
+ console.warn("Could not find css class " + suffix + " for the root " + rootClassName);
30
+ }
31
+ return tmp;
32
+ };
33
+ export {
34
+ css
35
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const components_metricmeter_metricmeter = require("./metricmeter.cjs");
4
+ exports.MetricMeter = components_metricmeter_metricmeter.MetricMeter;
@@ -0,0 +1,2 @@
1
+ export { MetricMeter } from './metricmeter';
2
+ export type { MetricMeterProps } from './metricmeter';
@@ -0,0 +1,4 @@
1
+ import { MetricMeter } from "./metricmeter.js";
2
+ export {
3
+ MetricMeter
4
+ };
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const components_metricmeter_css = require("./css.cjs");
5
+ const React = require("react");
6
+ const MetricMeter = ({
7
+ title = null,
8
+ fillColor = "#4e0174",
9
+ backgroundColor = "#c4c4c4",
10
+ maxSpeed = 100,
11
+ minSpeed = 0,
12
+ speedDelta = 10,
13
+ initial = 0,
14
+ speedUnitLabel = "Mbps",
15
+ onSelectedValue = (e) => {
16
+ console.log(e);
17
+ }
18
+ }) => {
19
+ const [speed, setSpeed] = React.useState(initial);
20
+ const increaseSpeed = () => {
21
+ const delta = typeof speedDelta === "number" ? speedDelta : speedDelta(speed, true);
22
+ const newSpeed = Math.min(speed + delta, maxSpeed);
23
+ if (speed != newSpeed) {
24
+ setSpeed(newSpeed);
25
+ if (onSelectedValue) {
26
+ onSelectedValue(newSpeed);
27
+ }
28
+ }
29
+ };
30
+ const decreaseSpeed = () => {
31
+ const delta = typeof speedDelta === "number" ? speedDelta : speedDelta(speed, false);
32
+ const newSpeed = Math.max(speed - delta, minSpeed);
33
+ if (speed != newSpeed && newSpeed >= minSpeed) {
34
+ setSpeed(newSpeed);
35
+ if (onSelectedValue) {
36
+ onSelectedValue(newSpeed);
37
+ }
38
+ }
39
+ };
40
+ const radius = 152;
41
+ const circumference = 2 * 3.1415926535 * radius;
42
+ const start = 955.04417;
43
+ const end = 286.51317;
44
+ const spread = start - end;
45
+ let percentFilled = (speed - minSpeed) / (maxSpeed - minSpeed);
46
+ if (percentFilled === 0 && minSpeed > 0) {
47
+ percentFilled = 0.01;
48
+ }
49
+ const offset = start - spread * percentFilled;
50
+ const incrementalDisabled = speed === maxSpeed;
51
+ const decrementDisabled = speed === minSpeed;
52
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: components_metricmeter_css.css("metricmeter"), children: [
53
+ title && /* @__PURE__ */ jsxRuntime.jsx("h3", { children: title }),
54
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: components_metricmeter_css.css("__svg-container"), children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "100%", height: "100%", viewBox: "0 0 400 400", className: components_metricmeter_css.css("__svg"), children: [
55
+ /* @__PURE__ */ jsxRuntime.jsx(
56
+ "circle",
57
+ {
58
+ cx: "200",
59
+ cy: "200",
60
+ r: radius,
61
+ strokeWidth: "32",
62
+ stroke: backgroundColor,
63
+ fill: "none"
64
+ }
65
+ ),
66
+ /* @__PURE__ */ jsxRuntime.jsx(
67
+ "circle",
68
+ {
69
+ cx: "200",
70
+ cy: "200",
71
+ r: radius,
72
+ strokeWidth: "32.25",
73
+ stroke: fillColor,
74
+ fill: "none",
75
+ strokeDasharray: `${circumference}`,
76
+ strokeDashoffset: offset,
77
+ style: { transition: "stroke-dashoffset 0.222s ease-in-out" }
78
+ }
79
+ )
80
+ ] }) }),
81
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: components_metricmeter_css.css("__controls"), children: [
82
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: components_metricmeter_css.css("__button--decrease") + " " + components_metricmeter_css.css("__button") + (decrementDisabled ? " " + components_metricmeter_css.css("__button--disabled") : ""), onClick: decreaseSpeed, children: "—" }),
83
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: components_metricmeter_css.css("__label-container"), children: [
84
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: components_metricmeter_css.css("__speed-label"), children: speed }),
85
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: components_metricmeter_css.css("__speed-unit-label"), children: speedUnitLabel })
86
+ ] }),
87
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: components_metricmeter_css.css("__button") + (incrementalDisabled ? " " + components_metricmeter_css.css("__button--disabled") : ""), onClick: increaseSpeed, children: "+" })
88
+ ] })
89
+ ] });
90
+ };
91
+ exports.MetricMeter = MetricMeter;
92
+ exports.default = MetricMeter;
@@ -0,0 +1,15 @@
1
+ import { default as React } from 'react';
2
+
3
+ export interface MetricMeterProps {
4
+ title?: string;
5
+ fillColor?: string;
6
+ backgroundColor?: string;
7
+ maxSpeed?: number;
8
+ minSpeed?: number;
9
+ speedDelta?: number | ((speed: number, increasing: boolean) => number);
10
+ speedUnitLabel?: string;
11
+ initial?: number;
12
+ onSelectedValue: (value: number) => void;
13
+ }
14
+ export declare const MetricMeter: React.FC<MetricMeterProps>;
15
+ export default MetricMeter;
@@ -0,0 +1,92 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { css } from "./css.js";
3
+ import { useState } from "react";
4
+ const MetricMeter = ({
5
+ title = null,
6
+ fillColor = "#4e0174",
7
+ backgroundColor = "#c4c4c4",
8
+ maxSpeed = 100,
9
+ minSpeed = 0,
10
+ speedDelta = 10,
11
+ initial = 0,
12
+ speedUnitLabel = "Mbps",
13
+ onSelectedValue = (e) => {
14
+ console.log(e);
15
+ }
16
+ }) => {
17
+ const [speed, setSpeed] = useState(initial);
18
+ const increaseSpeed = () => {
19
+ const delta = typeof speedDelta === "number" ? speedDelta : speedDelta(speed, true);
20
+ const newSpeed = Math.min(speed + delta, maxSpeed);
21
+ if (speed != newSpeed) {
22
+ setSpeed(newSpeed);
23
+ if (onSelectedValue) {
24
+ onSelectedValue(newSpeed);
25
+ }
26
+ }
27
+ };
28
+ const decreaseSpeed = () => {
29
+ const delta = typeof speedDelta === "number" ? speedDelta : speedDelta(speed, false);
30
+ const newSpeed = Math.max(speed - delta, minSpeed);
31
+ if (speed != newSpeed && newSpeed >= minSpeed) {
32
+ setSpeed(newSpeed);
33
+ if (onSelectedValue) {
34
+ onSelectedValue(newSpeed);
35
+ }
36
+ }
37
+ };
38
+ const radius = 152;
39
+ const circumference = 2 * 3.1415926535 * radius;
40
+ const start = 955.04417;
41
+ const end = 286.51317;
42
+ const spread = start - end;
43
+ let percentFilled = (speed - minSpeed) / (maxSpeed - minSpeed);
44
+ if (percentFilled === 0 && minSpeed > 0) {
45
+ percentFilled = 0.01;
46
+ }
47
+ const offset = start - spread * percentFilled;
48
+ const incrementalDisabled = speed === maxSpeed;
49
+ const decrementDisabled = speed === minSpeed;
50
+ return /* @__PURE__ */ jsxs("div", { className: css("metricmeter"), children: [
51
+ title && /* @__PURE__ */ jsx("h3", { children: title }),
52
+ /* @__PURE__ */ jsx("div", { className: css("__svg-container"), children: /* @__PURE__ */ jsxs("svg", { width: "100%", height: "100%", viewBox: "0 0 400 400", className: css("__svg"), children: [
53
+ /* @__PURE__ */ jsx(
54
+ "circle",
55
+ {
56
+ cx: "200",
57
+ cy: "200",
58
+ r: radius,
59
+ strokeWidth: "32",
60
+ stroke: backgroundColor,
61
+ fill: "none"
62
+ }
63
+ ),
64
+ /* @__PURE__ */ jsx(
65
+ "circle",
66
+ {
67
+ cx: "200",
68
+ cy: "200",
69
+ r: radius,
70
+ strokeWidth: "32.25",
71
+ stroke: fillColor,
72
+ fill: "none",
73
+ strokeDasharray: `${circumference}`,
74
+ strokeDashoffset: offset,
75
+ style: { transition: "stroke-dashoffset 0.222s ease-in-out" }
76
+ }
77
+ )
78
+ ] }) }),
79
+ /* @__PURE__ */ jsxs("div", { className: css("__controls"), children: [
80
+ /* @__PURE__ */ jsx("button", { className: css("__button--decrease") + " " + css("__button") + (decrementDisabled ? " " + css("__button--disabled") : ""), onClick: decreaseSpeed, children: "—" }),
81
+ /* @__PURE__ */ jsxs("div", { className: css("__label-container"), children: [
82
+ /* @__PURE__ */ jsx("p", { className: css("__speed-label"), children: speed }),
83
+ /* @__PURE__ */ jsx("p", { className: css("__speed-unit-label"), children: speedUnitLabel })
84
+ ] }),
85
+ /* @__PURE__ */ jsx("button", { className: css("__button") + (incrementalDisabled ? " " + css("__button--disabled") : ""), onClick: increaseSpeed, children: "+" })
86
+ ] })
87
+ ] });
88
+ };
89
+ export {
90
+ MetricMeter,
91
+ MetricMeter as default
92
+ };
package/dist/main.cjs CHANGED
@@ -19,6 +19,7 @@ const components_drawer_index = require("./components/drawer/index.cjs");
19
19
  const components_image_image = require("./components/image/image.cjs");
20
20
  const components_chip_index = require("./components/chip/index.cjs");
21
21
  const components_datePicker_datePicker = require("./components/date-picker/date-picker.cjs");
22
+ const components_metricmeter_metricmeter = require("./components/metricmeter/metricmeter.cjs");
22
23
  const components_notification_notification = require("./components/notification/notification.cjs");
23
24
  const components_radioGroup_index = require("./components/radio-group/index.cjs");
24
25
  const components_box_box = require("./components/box/box.cjs");
@@ -80,6 +81,7 @@ exports.Drawer = components_drawer_index.Drawer;
80
81
  exports.Image = components_image_image.Image;
81
82
  exports.Chip = components_chip_index.Chip;
82
83
  exports.DatePicker = components_datePicker_datePicker.DatePicker;
84
+ exports.MetricMeter = components_metricmeter_metricmeter.MetricMeter;
83
85
  exports.Notification = components_notification_notification.Notification;
84
86
  exports.RadioGroup = components_radioGroup_index.RadioGroup;
85
87
  exports.Box = components_box_box.Box;
package/dist/main.js CHANGED
@@ -17,6 +17,7 @@ import { Drawer } from "./components/drawer/index.js";
17
17
  import { Image } from "./components/image/image.js";
18
18
  import { Chip } from "./components/chip/index.js";
19
19
  import { DatePicker } from "./components/date-picker/date-picker.js";
20
+ import { MetricMeter } from "./components/metricmeter/metricmeter.js";
20
21
  import { Notification } from "./components/notification/notification.js";
21
22
  import { RadioGroup } from "./components/radio-group/index.js";
22
23
  import { Box } from "./components/box/box.js";
@@ -87,6 +88,7 @@ export {
87
88
  Label,
88
89
  Link,
89
90
  List,
91
+ MetricMeter,
90
92
  M as Modal,
91
93
  N as NavigationMenu,
92
94
  Notabene,
package/dist/style.css CHANGED
@@ -5666,6 +5666,78 @@
5666
5666
  position: absolute;
5667
5667
  top: 0;
5668
5668
  width: 0.0625rem;
5669
+ }._metricmeter_1wov3_1 {
5670
+ position: relative;
5671
+ display: flex;
5672
+ flex-direction: column;
5673
+ align-items: center;
5674
+ width: 256px;
5675
+ min-width: 256px;
5676
+ margin-left: 1rem;
5677
+ margin-right: 1rem;
5678
+ }
5679
+ ._metricmeter__svg_1wov3_11 {
5680
+ transform-origin: center center;
5681
+ fill: transparent;
5682
+ stroke-linecap: round;
5683
+ stroke-width: 32;
5684
+ stroke: #c4c4c4;
5685
+ stroke-dasharray: 668.531, 955.04417;
5686
+ rotate: 144deg;
5687
+ }
5688
+ ._metricmeter_1wov3_1 h3 {
5689
+ margin-bottom: 0;
5690
+ font-size: 22px;
5691
+ font-weight: var(--teddy-typography-weight-normal);
5692
+ }
5693
+ ._metricmeter__svg-container_1wov3_25 {
5694
+ max-width: 148px;
5695
+ }
5696
+ ._metricmeter__controls_1wov3_28 {
5697
+ position: absolute;
5698
+ margin-top: 0.5em;
5699
+ top: calc(50% - 0.5rem);
5700
+ display: flex;
5701
+ align-items: center;
5702
+ justify-content: space-between;
5703
+ width: 256px; /* Total width: 160 (text) + 42 (button -) + 42 (button +) + 8px spacing as the figma says 256px total width */
5704
+ }
5705
+ ._metricmeter__button_1wov3_37 {
5706
+ width: 42px;
5707
+ height: 40px;
5708
+ background-color: unset;
5709
+ border: var(--teddy-color-purple-700) 1px solid;
5710
+ color: var(--teddy-color-purple-700);
5711
+ border-radius: 50px;
5712
+ cursor: pointer;
5713
+ font-size: var(--teddy-typography-scale-400);
5714
+ font-weight: var(--teddy-typography-weight-normal);
5715
+ user-select: none;
5716
+ }
5717
+ ._metricmeter__button--decrease_1wov3_49 {
5718
+ font-size: var(--teddy-typography-scale-75);
5719
+ font-weight: var(--teddy-typography-weight-bold);
5720
+ }
5721
+ ._metricmeter__button--disabled_1wov3_53 {
5722
+ cursor: default;
5723
+ border: 0;
5724
+ color: var(--teddy-color-text-weak);
5725
+ background-color: var(--teddy-color-background-interactive-disabled);
5726
+ }
5727
+ ._metricmeter__label-container_1wov3_59 {
5728
+ flex: 0 0 160px;
5729
+ text-align: center;
5730
+ }
5731
+ ._metricmeter__label-container_1wov3_59 p {
5732
+ margin: 0;
5733
+ }
5734
+ ._metricmeter__speed-label_1wov3_66 {
5735
+ font-weight: var(--teddy-typography-weight-bold);
5736
+ font-size: var(--teddy-typography-scale-100);
5737
+ }
5738
+ ._metricmeter__speed-unit-label_1wov3_70 {
5739
+ font-size: var(--teddy-typography-scale-75);
5740
+ font-weight: var(--teddy-typography-weight-normal);
5669
5741
  }:root {
5670
5742
  --teddy-border-radius-xs: 2px;
5671
5743
  --teddy-border-radius-sm: 4px;
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "pnpm": ">=9"
21
21
  },
22
22
  "private": false,
23
- "version": "0.1.6",
23
+ "version": "0.1.7",
24
24
  "sideEffects": [
25
25
  "**/*.css"
26
26
  ],