@synerise/ds-metric-card 1.1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 1.1.0 (2026-01-07)
7
+
8
+ ### Features
9
+
10
+ - **metric-card:** new component ([5fe50a7](https://github.com/Synerise/synerise-design/commit/5fe50a7b87592990d6e4be1e04599fce350a91fd))
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Synerise
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ ---
2
+ id: metric-card
3
+ title: MetricCard
4
+ ---
5
+
6
+ MetricCard UI Component
7
+
8
+ ## Installation
9
+ ```
10
+ npm i @synerise/ds-metric-card
11
+ or
12
+ yarn add @synerise/ds-metric-card
13
+ ```
14
+
15
+ ## Usage
16
+ ```
17
+ import MetricCard from '@synerise/ds-metric-card'
18
+
19
+ <MetricCard />
20
+
21
+ ```
22
+
23
+ ## Demo
24
+
25
+ <iframe src="/storybook-static/iframe.html?id=components-metric-card--default"></iframe>
26
+
27
+ ## API
28
+
29
+ Property | Description | Type | Default |
30
+ | ---------------- | ------------------------------------------------------ | ------------------------ | ------- |
31
+ | title | title of metric | ReactNode | - |
32
+ | headerRightSide | custom component to render | ReactNode | - |
33
+ | hoverValue | Value of the metric on hover | ReactNode | - |
34
+ | displayValue | value of metric with display | ReactNode | - |
35
+ | tooltip | render text of tooltip | ReactNode | - |
36
+ | tooltipConfig | all props for title tooltip | TooltipProps | - |
37
+ | greyBackground | set with grey background | boolean | - |
38
+ | isLoading | render skeleton | boolean | - |
39
+ | errorMessage | render inlineAlert with error text | ReactNode | - |
40
+ | copyValue | Value to copy after click on icon | string | - |
41
+ | texts | Copy icon texts | CopyTooltipTexts | - |
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { MetricCardProps } from './MetricCard.types';
3
+ declare const MetricCard: ({ title, headerRightSide, hoverValue, displayValue, tooltip, tooltipConfig, greyBackground, isLoading, errorMessage, copyValue, texts, ...htmlAttributes }: MetricCardProps) => React.JSX.Element;
4
+ export default MetricCard;
@@ -0,0 +1,72 @@
1
+ var _excluded = ["title", "headerRightSide", "hoverValue", "displayValue", "tooltip", "tooltipConfig", "greyBackground", "isLoading", "errorMessage", "copyValue", "texts"];
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ import React from 'react';
5
+ import Icon, { InfoFillS } from '@synerise/ds-icon';
6
+ import Tooltip from '@synerise/ds-tooltip';
7
+ import { Text } from '@synerise/ds-typography';
8
+ import * as S from './MetricCard.styles';
9
+ var MetricCard = function MetricCard(_ref) {
10
+ var title = _ref.title,
11
+ headerRightSide = _ref.headerRightSide,
12
+ hoverValue = _ref.hoverValue,
13
+ displayValue = _ref.displayValue,
14
+ tooltip = _ref.tooltip,
15
+ tooltipConfig = _ref.tooltipConfig,
16
+ greyBackground = _ref.greyBackground,
17
+ isLoading = _ref.isLoading,
18
+ errorMessage = _ref.errorMessage,
19
+ copyValue = _ref.copyValue,
20
+ texts = _ref.texts,
21
+ htmlAttributes = _objectWithoutPropertiesLoose(_ref, _excluded);
22
+ var hasValue = Boolean(hoverValue) || Boolean(displayValue);
23
+ var tooltipVisible = Boolean(tooltip || tooltipConfig);
24
+ var _React$useState = React.useState(false),
25
+ hover = _React$useState[0],
26
+ setHover = _React$useState[1];
27
+ var showSkeleton = isLoading && !hasValue && !errorMessage;
28
+ var showError = errorMessage && !hasValue && !isLoading;
29
+ var showContent = !showSkeleton && !showError;
30
+ return /*#__PURE__*/React.createElement(S.MetricContainer, _extends({
31
+ greyBackground: greyBackground
32
+ }, htmlAttributes), /*#__PURE__*/React.createElement(S.MetricHeaderBar, null, /*#__PURE__*/React.createElement(S.TitleWrapper, {
33
+ header: Boolean(headerRightSide)
34
+ }, /*#__PURE__*/React.createElement(Text, {
35
+ ellipsis: {
36
+ tooltip: title
37
+ }
38
+ }, title), tooltipVisible && /*#__PURE__*/React.createElement(Tooltip, _extends({
39
+ title: tooltip,
40
+ placement: "top",
41
+ trigger: "hover"
42
+ }, tooltipConfig), /*#__PURE__*/React.createElement(S.IconWrapper, null, /*#__PURE__*/React.createElement(Icon, {
43
+ size: 24,
44
+ component: /*#__PURE__*/React.createElement(InfoFillS, null)
45
+ })))), headerRightSide && /*#__PURE__*/React.createElement(S.HeaderRightSide, null, headerRightSide)), /*#__PURE__*/React.createElement(S.MetricContent, {
46
+ "data-testid": "ds-metric-card",
47
+ className: hover ? 'hovered' : '',
48
+ onMouseEnter: function onMouseEnter() {
49
+ return setHover(true);
50
+ },
51
+ onMouseLeave: function onMouseLeave() {
52
+ return setHover(false);
53
+ },
54
+ copyable: hasValue
55
+ }, showSkeleton && /*#__PURE__*/React.createElement(S.MetricSkeleton, {
56
+ size: "S",
57
+ width: "M",
58
+ height: 32,
59
+ numberOfSkeletons: 1
60
+ }), showError && /*#__PURE__*/React.createElement(S.MetricInlineAlert, {
61
+ type: "alert",
62
+ message: errorMessage
63
+ }), showContent && /*#__PURE__*/React.createElement(S.MetricValue, {
64
+ ellipsis: {
65
+ tooltip: hoverValue || displayValue
66
+ }
67
+ }, /*#__PURE__*/React.createElement(S.WrapperFormattedNumber, null, displayValue), /*#__PURE__*/React.createElement(S.WrapperNumber, null, hoverValue || displayValue)), typeof copyValue === 'string' && hover && /*#__PURE__*/React.createElement(S.WrapperCopyIcon, null, /*#__PURE__*/React.createElement(S.CopyIcon, {
68
+ copyValue: copyValue,
69
+ texts: texts
70
+ }))));
71
+ };
72
+ export default MetricCard;
@@ -0,0 +1,24 @@
1
+ export declare const WrapperFormattedNumber: import("styled-components").StyledComponent<"div", any, {}, never>;
2
+ export declare const WrapperNumber: import("styled-components").StyledComponent<"div", any, {}, never>;
3
+ export declare const MetricContainer: import("styled-components").StyledComponent<"div", any, {
4
+ greyBackground?: boolean;
5
+ }, never>;
6
+ export declare const CopyIcon: import("styled-components").StyledComponent<({ copyValue, texts, onMouseEnter, onMouseLeave, icon, placement, onCopy, ...rest }: import("@synerise/ds-copy-icon").CopyIconProps) => React.JSX.Element, any, {}, never>;
7
+ export declare const MetricSkeleton: import("styled-components").StyledComponent<({ size, numberOfSkeletons, width, height, className, }: import("@synerise/ds-skeleton").SkeletonProps) => React.JSX.Element, any, {}, never>;
8
+ export declare const MetricInlineAlert: import("styled-components").StyledComponent<({ className, type, message, withLink, withEmphasis, hoverButton, disabled, customIcon, ...rest }: import("@synerise/ds-inline-alert").InlineAlertProps) => React.JSX.Element, any, {}, never>;
9
+ export declare const MetricContent: import("styled-components").StyledComponent<"div", any, {
10
+ copyable?: boolean;
11
+ }, never>;
12
+ export declare const MetricValue: import("styled-components").StyledComponent<({ size, className, children, ellipsis, }: {
13
+ size?: import("@synerise/ds-typography").TextSize;
14
+ ellipsis?: import("@synerise/ds-typography/dist/Ellipsis").EllipsisProps;
15
+ children?: import("react").ReactNode;
16
+ className?: string;
17
+ }) => React.JSX.Element, any, {}, never>;
18
+ export declare const MetricHeaderBar: import("styled-components").StyledComponent<"div", any, {}, never>;
19
+ export declare const TitleWrapper: import("styled-components").StyledComponent<"div", any, {
20
+ header?: boolean;
21
+ }, never>;
22
+ export declare const IconWrapper: import("styled-components").StyledComponent<"span", any, {}, never>;
23
+ export declare const HeaderRightSide: import("styled-components").StyledComponent<"div", any, {}, never>;
24
+ export declare const WrapperCopyIcon: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,67 @@
1
+ import styled, { css } from 'styled-components';
2
+ import Copy from '@synerise/ds-copy-icon';
3
+ import InlineAlert from '@synerise/ds-inline-alert';
4
+ import Skeleton from '@synerise/ds-skeleton';
5
+ import { Text } from '@synerise/ds-typography';
6
+ export var WrapperFormattedNumber = styled.div.withConfig({
7
+ displayName: "MetricCardstyles__WrapperFormattedNumber",
8
+ componentId: "sc-1g748a8-0"
9
+ })(["display:inline;"]);
10
+ export var WrapperNumber = styled.div.withConfig({
11
+ displayName: "MetricCardstyles__WrapperNumber",
12
+ componentId: "sc-1g748a8-1"
13
+ })(["display:none;"]);
14
+ export var MetricContainer = styled.div.withConfig({
15
+ displayName: "MetricCardstyles__MetricContainer",
16
+ componentId: "sc-1g748a8-2"
17
+ })(["display:flex;flex-direction:column;background-color:", ";padding:8px 8px 14px 24px;gap:2px;width:100%;border-radius:5px;", ";"], function (props) {
18
+ return props.theme.palette.white;
19
+ }, function (props) {
20
+ return props.greyBackground ? "\n box-shadow: 0 4px 12px 0 rgba(35, 41, 54, 0.04);" : "\n box-shadow: 0 0 0 1px " + props.theme.palette['grey-200'];
21
+ });
22
+ export var CopyIcon = styled(Copy).withConfig({
23
+ displayName: "MetricCardstyles__CopyIcon",
24
+ componentId: "sc-1g748a8-3"
25
+ })(["margin-left:8px;visibility:hidden;opacity:0;transition:opacity 0.15s ease;"]);
26
+ export var MetricSkeleton = styled(Skeleton).withConfig({
27
+ displayName: "MetricCardstyles__MetricSkeleton",
28
+ componentId: "sc-1g748a8-4"
29
+ })(["padding:0 0 2px;width:50%;"]);
30
+ export var MetricInlineAlert = styled(InlineAlert).withConfig({
31
+ displayName: "MetricCardstyles__MetricInlineAlert",
32
+ componentId: "sc-1g748a8-5"
33
+ })(["padding:8px 0 2px;"]);
34
+ export var MetricContent = styled.div.withConfig({
35
+ displayName: "MetricCardstyles__MetricContent",
36
+ componentId: "sc-1g748a8-6"
37
+ })(["flex:1;min-width:0;display:flex;align-items:center;overflow:hidden;margin:0 4px 2px 0;", "{", "}&.hovered{", "{visibility:visible;opacity:1;}", "{display:none;}", "{display:inline;}}"], CopyIcon, function (props) {
38
+ return props.copyable && css(["cursor:pointer;"]);
39
+ }, CopyIcon, WrapperFormattedNumber, WrapperNumber);
40
+ export var MetricValue = styled(Text).withConfig({
41
+ displayName: "MetricCardstyles__MetricValue",
42
+ componentId: "sc-1g748a8-7"
43
+ })(["color:", ";font-size:32px;line-height:100%;padding-bottom:2px;align-items:center;cursor:pointer;font-weight:500;justify-content:start;"], function (props) {
44
+ return props.theme.palette['grey-800'];
45
+ });
46
+ export var MetricHeaderBar = styled.div.withConfig({
47
+ displayName: "MetricCardstyles__MetricHeaderBar",
48
+ componentId: "sc-1g748a8-8"
49
+ })(["display:flex;align-items:center;justify-content:space-between;"]);
50
+ export var TitleWrapper = styled.div.withConfig({
51
+ displayName: "MetricCardstyles__TitleWrapper",
52
+ componentId: "sc-1g748a8-9"
53
+ })(["flex:1;min-width:0;display:flex;align-items:center;min-height:32px;"]);
54
+ export var IconWrapper = styled.span.withConfig({
55
+ displayName: "MetricCardstyles__IconWrapper",
56
+ componentId: "sc-1g748a8-10"
57
+ })(["display:inline-block;color:", ";cursor:pointer;"], function (props) {
58
+ return props.theme.palette['grey-400'];
59
+ });
60
+ export var HeaderRightSide = styled.div.withConfig({
61
+ displayName: "MetricCardstyles__HeaderRightSide",
62
+ componentId: "sc-1g748a8-11"
63
+ })(["flex-shrink:0;display:flex;align-items:center;"]);
64
+ export var WrapperCopyIcon = styled.div.withConfig({
65
+ displayName: "MetricCardstyles__WrapperCopyIcon",
66
+ componentId: "sc-1g748a8-12"
67
+ })(["flex-shrink:0;display:flex;align-items:center;"]);
@@ -0,0 +1,20 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type TooltipProps } from '@synerise/ds-tooltip';
3
+ import { type WithHTMLAttributes } from '@synerise/ds-utils';
4
+ export type MetricCardProps = WithHTMLAttributes<HTMLDivElement, {
5
+ title?: ReactNode;
6
+ headerRightSide?: ReactNode;
7
+ hoverValue?: ReactNode;
8
+ displayValue?: ReactNode;
9
+ tooltip?: ReactNode;
10
+ tooltipConfig?: TooltipProps;
11
+ greyBackground?: boolean;
12
+ isLoading?: boolean;
13
+ errorMessage?: ReactNode;
14
+ copyValue?: string;
15
+ texts?: CopyTexts;
16
+ }>;
17
+ export type CopyTexts = {
18
+ copyTooltip?: ReactNode;
19
+ copiedTooltip?: ReactNode;
20
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export { default } from './MetricCard';
2
+ export type { MetricCardProps } from './MetricCard.types';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default } from './MetricCard';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@synerise/ds-metric-card",
3
+ "version": "1.1.0",
4
+ "description": "MetricCard UI Component for the Synerise Design System",
5
+ "license": "ISC",
6
+ "repository": "Synerise/synerise-design",
7
+ "main": "dist/index.js",
8
+ "files": [
9
+ "/dist",
10
+ "CHANGELOG.md",
11
+ "README.md",
12
+ "package.json",
13
+ "LICENSE.md"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "build": "npm run build:js && npm run build:css && npm run defs",
20
+ "build:css": "node ../../../scripts/style/less.js",
21
+ "build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
22
+ "build:watch": "npm run build:js -- --watch",
23
+ "defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
24
+ "prepublish": "npm run build",
25
+ "types": "tsc --noEmit",
26
+ "pack:ci": "npm pack --pack-destination ../../storybook/storybook-static/static",
27
+ "test": "jest",
28
+ "test:watch": "npm run test -- --watchAll",
29
+ "check:circular-dependencies": "madge --circular --extensions ts,tsx,js,jsx --ts-config tsconfig.json src/ --exclude '/dist/'",
30
+ "upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
31
+ },
32
+ "sideEffects": [
33
+ "dist/style/*",
34
+ "*.less"
35
+ ],
36
+ "types": "dist/index.d.ts",
37
+ "dependencies": {
38
+ "@synerise/ds-copy-icon": "^1.0.4",
39
+ "@synerise/ds-icon": "^1.9.2",
40
+ "@synerise/ds-inline-alert": "^1.1.3",
41
+ "@synerise/ds-skeleton": "^1.0.28",
42
+ "@synerise/ds-tooltip": "^1.3.3",
43
+ "@synerise/ds-typography": "^1.0.26"
44
+ },
45
+ "devDependencies": {
46
+ "@synerise/ds-utils": "^1.5.2"
47
+ },
48
+ "peerDependencies": {
49
+ "@synerise/ds-core": "*",
50
+ "react": ">=16.9.0 <= 18.3.1",
51
+ "react-intl": ">=3.12.0 <= 6.8",
52
+ "styled-components": "^5.3.3"
53
+ },
54
+ "gitHead": "f38e4b2dca1d43c39af0b189c93808de62c11e9b"
55
+ }