@synerise/ds-information-card 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.
- package/CHANGELOG.md +60 -0
- package/LICENSE.md +21 -0
- package/README.md +55 -0
- package/dist/InformationCard.d.ts +105 -0
- package/dist/InformationCard.js +252 -0
- package/dist/InformationCard.styles.d.ts +21 -0
- package/dist/InformationCard.styles.js +46 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/modules.d.js +1 -0
- package/package.json +48 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
## [0.1.5](https://github.com/Synerise/synerise-design/compare/@synerise/ds-information-card@0.1.4...@synerise/ds-information-card@0.1.5) (2022-07-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-information-card
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.1.4](https://github.com/Synerise/synerise-design/compare/@synerise/ds-information-card@0.1.3...@synerise/ds-information-card@0.1.4) (2022-07-08)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @synerise/ds-information-card
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [0.1.3](https://github.com/Synerise/synerise-design/compare/@synerise/ds-information-card@0.1.2...@synerise/ds-information-card@0.1.3) (2022-07-06)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @synerise/ds-information-card
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [0.1.2](https://github.com/Synerise/synerise-design/compare/@synerise/ds-information-card@0.1.1...@synerise/ds-information-card@0.1.2) (2022-06-23)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @synerise/ds-information-card
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## [0.1.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-information-card@0.1.0...@synerise/ds-information-card@0.1.1) (2022-06-17)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Bug Fixes
|
|
42
|
+
|
|
43
|
+
* **information-card:** bump ds-card version ([fa87d6b](https://github.com/Synerise/synerise-design/commit/fa87d6b9985212b0e40ccdbda564d8cab4d9c914))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# 0.1.0 (2022-06-15)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Bug Fixes
|
|
53
|
+
|
|
54
|
+
* **filter:** fixes closing info-card when clicking on it ([91eed3b](https://github.com/Synerise/synerise-design/commit/91eed3b7a5392c04ed618c9f7265608d6c39655e))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### Features
|
|
58
|
+
|
|
59
|
+
* **information-card:** create information-card component ([ee3ad8b](https://github.com/Synerise/synerise-design/commit/ee3ad8bdc8ec793250415d1e25b78ed3504e33d4))
|
|
60
|
+
* **information-card:** info-card component, stories, initial tests ([f5ff3f0](https://github.com/Synerise/synerise-design/commit/f5ff3f0c4435da14aba0db96a33b11f50146e6a3))
|
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,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: information-card
|
|
3
|
+
title: InformationCard
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
InformationCard UI Component
|
|
7
|
+
|
|
8
|
+
Information card shows details of an object or entity.
|
|
9
|
+
It should be used as an additional information (details) provider when user is selecting something using menu or dropdown.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
```
|
|
13
|
+
npm i @synerise/ds-information-card
|
|
14
|
+
or
|
|
15
|
+
yarn add @synerise/ds-information-card
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Development
|
|
19
|
+
|
|
20
|
+
```zsh
|
|
21
|
+
# lerna bootstrap # install all required reused shared lerna packages
|
|
22
|
+
yarn workspace @synerise/ds-information-card lint
|
|
23
|
+
yarn workspace @synerise/ds-information-card build
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
```js
|
|
28
|
+
import InformationCard from '@synerise/ds-information-card'
|
|
29
|
+
import Popover from 'antd/popover'
|
|
30
|
+
|
|
31
|
+
<Popover
|
|
32
|
+
defaultVisible={false}
|
|
33
|
+
placement="right"
|
|
34
|
+
content={() => <InformationCard title="Entity full name" subtitle="entity.id"/>}
|
|
35
|
+
>Entity short name</Popover>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Generally, components require being capable of rendering this and usually an additional effort is required to get them to support rendering.
|
|
39
|
+
See text's menu item element `packages/components/menu/src/Elements/Item/Text/Text.tsx`.
|
|
40
|
+
|
|
41
|
+
Note that `title` and `subtitle` are required props. For just a single line of text consider using just tooltip or popover.
|
|
42
|
+
|
|
43
|
+
### Usage with dropdown and other components relying on `rc-trigger` `getPopupContainer`
|
|
44
|
+
|
|
45
|
+
Some components render elements via portal, in such a case if tthey are listening for global events like click (for e.g. closing the dropdown) - developer using this component is responsible for proper handling of such a clicks. One of ways is making use of `overlayInnerClass` popover's class property to later.
|
|
46
|
+
By default class is `ignore-click-outside` (so looking for `domElement.closest('.ignore-click-outside')` to determine whether handler should be skipped should be fine).
|
|
47
|
+
|
|
48
|
+
## Demo
|
|
49
|
+
|
|
50
|
+
<iframe src="/storybook-static/iframe.html?id=components-information-card--default"></iframe>
|
|
51
|
+
|
|
52
|
+
## API
|
|
53
|
+
|
|
54
|
+
| Property | Description | Type | Default |
|
|
55
|
+
| --- | --- | --- | --- |
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { IconProps } from '@synerise/ds-icon/dist/cjs';
|
|
3
|
+
import { InlineAlertType } from '@synerise/ds-alert/dist/InlineAlert/InlineAlert.types';
|
|
4
|
+
import { SubtleTextAreaProps } from '@synerise/ds-subtle-form/dist/Elements/TextArea/TextArea.types';
|
|
5
|
+
import { Color, Size } from '@synerise/ds-avatar/dist/Avatar.types';
|
|
6
|
+
import 'rc-trigger/assets/index.less';
|
|
7
|
+
export declare type BadgeData = {
|
|
8
|
+
type?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
iconColor?: Color | IconProps['color'];
|
|
12
|
+
iconElement?: InformationCardProps['icon'];
|
|
13
|
+
iconSize?: Size | string;
|
|
14
|
+
avatarTooltipText?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Custom builder for badgeSlots with icon
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildIconBadge(data: BadgeData): JSX.Element;
|
|
20
|
+
export declare type InformationCardProps = {
|
|
21
|
+
/**
|
|
22
|
+
* custom jsx element for rendering in action button (bottom-right)
|
|
23
|
+
*/
|
|
24
|
+
actionButton?: boolean | (() => React.ReactNode);
|
|
25
|
+
/**
|
|
26
|
+
* default action button callback methodd
|
|
27
|
+
*/
|
|
28
|
+
actionButtonCallback?: () => void;
|
|
29
|
+
/**
|
|
30
|
+
* default action button tooltip
|
|
31
|
+
*/
|
|
32
|
+
actionButtonTooltipText?: string;
|
|
33
|
+
/**
|
|
34
|
+
* description in a tooltip shown when user (note renderBadge has to be provided)
|
|
35
|
+
*/
|
|
36
|
+
avatarTooltipText?: string;
|
|
37
|
+
/**
|
|
38
|
+
* content of the tooltip, it defaults to `SubtleForm.TextArea`
|
|
39
|
+
*/
|
|
40
|
+
children?: React.ReactNode | ((props?: SubtleTextAreaProps | null) => React.ReactNode);
|
|
41
|
+
/**
|
|
42
|
+
* subtitle's value to be copied when clicking on the copy button
|
|
43
|
+
*/
|
|
44
|
+
copyTooltip?: string;
|
|
45
|
+
/**
|
|
46
|
+
* feedback to the user once information card's subtitle has been copied
|
|
47
|
+
*/
|
|
48
|
+
copiedTooltip?: string;
|
|
49
|
+
/**
|
|
50
|
+
* when information-card's `children` prop is not provided,
|
|
51
|
+
* `defaultTextAreaProps` can be used to parametrize default textarea
|
|
52
|
+
*/
|
|
53
|
+
descriptionConfig?: SubtleTextAreaProps | null | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* render prop for rendering the bottom part of (by default section with a small text and an optional action button on the right)
|
|
56
|
+
*/
|
|
57
|
+
renderFooter?: () => JSX.Element;
|
|
58
|
+
/**
|
|
59
|
+
* additional feedback info to the user, when set to null - footer is hidden
|
|
60
|
+
*/
|
|
61
|
+
footerText?: string | React.ReactNode | null;
|
|
62
|
+
/**
|
|
63
|
+
* icon (note this needs to be pure SVG icon, it relies on `buildBadgeIcon` helper)
|
|
64
|
+
*/
|
|
65
|
+
icon?: React.ReactNode;
|
|
66
|
+
/**
|
|
67
|
+
* icon color to be applied to `icon` element
|
|
68
|
+
*/
|
|
69
|
+
iconColor?: string;
|
|
70
|
+
/**
|
|
71
|
+
* additional information shown between subtitle and description section.
|
|
72
|
+
* Can be used for warnings, errors, destructive actions, notices. See `buildExtraInfo` and alert `level` there.
|
|
73
|
+
*/
|
|
74
|
+
notice?: string | React.ReactNode;
|
|
75
|
+
/**
|
|
76
|
+
* Custom render prop for displaying. If set to `null` - badge won't be shown.
|
|
77
|
+
*/
|
|
78
|
+
renderBadge?: Function | null;
|
|
79
|
+
/**
|
|
80
|
+
* Second line. Required prop. Can be copied.
|
|
81
|
+
*/
|
|
82
|
+
subtitle: string;
|
|
83
|
+
/**
|
|
84
|
+
* Title of the information-card. Can be copied.
|
|
85
|
+
*/
|
|
86
|
+
title: string;
|
|
87
|
+
};
|
|
88
|
+
declare const InformationCard: React.ForwardRefExoticComponent<InformationCardProps & React.RefAttributes<HTMLDivElement>>;
|
|
89
|
+
export declare function buildInitialsBadge(name: string): JSX.Element;
|
|
90
|
+
/**
|
|
91
|
+
* helper for wrapping a notice
|
|
92
|
+
*/
|
|
93
|
+
export declare function buildExtraInfo(message: string, level?: InlineAlertType): JSX.Element;
|
|
94
|
+
/**
|
|
95
|
+
* Helper for returning initials. Handles cases such as John Smith, J. Smith, JS.
|
|
96
|
+
*/
|
|
97
|
+
export declare function getInitials(name: string): string;
|
|
98
|
+
declare type InitialsProps = React.PropsWithChildren<{
|
|
99
|
+
name?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Wrapper for obtaining an avatar based on initials
|
|
103
|
+
*/
|
|
104
|
+
export declare function Initials({ name, children }: InitialsProps): JSX.Element;
|
|
105
|
+
export default InformationCard;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
var _excluded = ["actionButton", "actionButtonTooltipText", "actionButtonCallback", "avatarTooltipText", "children", "copyTooltip", "copiedTooltip", "renderFooter", "renderBadge", "subtitle", "title", "notice", "footerText", "icon", "iconColor", "descriptionConfig"];
|
|
2
|
+
|
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
+
|
|
5
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
6
|
+
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import { Text } from '@synerise/ds-typography';
|
|
9
|
+
import Button from '@synerise/ds-button';
|
|
10
|
+
import Divider from '@synerise/ds-divider';
|
|
11
|
+
import Icon, { ArrowRuCircleM, SegmentM } from '@synerise/ds-icon/dist/cjs';
|
|
12
|
+
import Avatar, { ObjectAvatar } from '@synerise/ds-avatar';
|
|
13
|
+
import Card from '@synerise/ds-card';
|
|
14
|
+
import SubtleForm from '@synerise/ds-subtle-form';
|
|
15
|
+
import Tooltip from '@synerise/ds-tooltip';
|
|
16
|
+
import Copy from '@synerise/ds-description/dist/Row/Copy';
|
|
17
|
+
import { RowWrapper } from '@synerise/ds-description/dist/Row/DescriptionRow.styles';
|
|
18
|
+
import Badge from '@synerise/ds-badge';
|
|
19
|
+
import Alert from '@synerise/ds-alert';
|
|
20
|
+
import * as S from './InformationCard.styles';
|
|
21
|
+
import "rc-trigger/assets/index.css";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Custom builder for badgeSlots with icon
|
|
25
|
+
*/
|
|
26
|
+
export function buildIconBadge(data) {
|
|
27
|
+
var avatarExtra = {
|
|
28
|
+
object: {}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (data.avatarTooltipText) {
|
|
32
|
+
avatarExtra.object = {
|
|
33
|
+
description: data.avatarTooltipText
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return /*#__PURE__*/React.createElement(ObjectAvatar, _extends({}, avatarExtra, {
|
|
38
|
+
color: data.iconColor,
|
|
39
|
+
iconComponent: /*#__PURE__*/React.createElement(Icon, {
|
|
40
|
+
component: data.iconElement
|
|
41
|
+
})
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function renderChildren(renderChild, descriptionConfig) {
|
|
46
|
+
if (typeof renderChild === 'function') {
|
|
47
|
+
return renderChild(descriptionConfig);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return renderChild;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var InformationCard = React.forwardRef(function (_ref, ref) {
|
|
54
|
+
var actionButton = _ref.actionButton,
|
|
55
|
+
actionButtonTooltipText = _ref.actionButtonTooltipText,
|
|
56
|
+
actionButtonCallback = _ref.actionButtonCallback,
|
|
57
|
+
avatarTooltipText = _ref.avatarTooltipText,
|
|
58
|
+
children = _ref.children,
|
|
59
|
+
copyTooltip = _ref.copyTooltip,
|
|
60
|
+
copiedTooltip = _ref.copiedTooltip,
|
|
61
|
+
renderFooter = _ref.renderFooter,
|
|
62
|
+
_renderBadge = _ref.renderBadge,
|
|
63
|
+
subtitle = _ref.subtitle,
|
|
64
|
+
title = _ref.title,
|
|
65
|
+
notice = _ref.notice,
|
|
66
|
+
footerText = _ref.footerText,
|
|
67
|
+
_ref$icon = _ref.icon,
|
|
68
|
+
iconElement = _ref$icon === void 0 ? /*#__PURE__*/React.createElement(SegmentM, null) : _ref$icon,
|
|
69
|
+
iconColor = _ref.iconColor,
|
|
70
|
+
descriptionConfig = _ref.descriptionConfig,
|
|
71
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
72
|
+
|
|
73
|
+
var copyableSlot = function copyableSlot(content) {
|
|
74
|
+
return /*#__PURE__*/React.createElement(RowWrapper, {
|
|
75
|
+
copyable: true
|
|
76
|
+
}, /*#__PURE__*/React.createElement(S.Flex, {
|
|
77
|
+
style: {
|
|
78
|
+
backgroundColor: '',
|
|
79
|
+
alignItems: 'center'
|
|
80
|
+
}
|
|
81
|
+
}, /*#__PURE__*/React.createElement("span", null, content), /*#__PURE__*/React.createElement(Copy, {
|
|
82
|
+
copyValue: content,
|
|
83
|
+
texts: {
|
|
84
|
+
copyTooltip: copyTooltip != null ? copyTooltip : 'Copy to clipboard',
|
|
85
|
+
copiedTooltip: copiedTooltip != null ? copiedTooltip : 'Copied'
|
|
86
|
+
}
|
|
87
|
+
})));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
var cachedChildren = React.useMemo(function () {
|
|
91
|
+
return renderChildren(children, descriptionConfig);
|
|
92
|
+
}, [children, descriptionConfig]);
|
|
93
|
+
return /*#__PURE__*/React.createElement(S.InfoCardWrapper, {
|
|
94
|
+
ref: ref,
|
|
95
|
+
"aria-label": "information card",
|
|
96
|
+
className: "ds-info-card"
|
|
97
|
+
}, /*#__PURE__*/React.createElement(Card, {
|
|
98
|
+
background: "white" // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
,
|
|
101
|
+
renderBadge: function renderBadge() {
|
|
102
|
+
var _renderBadge$call;
|
|
103
|
+
|
|
104
|
+
return _renderBadge !== null && /*#__PURE__*/React.createElement("div", {
|
|
105
|
+
style: {
|
|
106
|
+
marginRight: '16px'
|
|
107
|
+
}
|
|
108
|
+
}, (_renderBadge$call = _renderBadge == null ? void 0 : _renderBadge.call(null)) != null ? _renderBadge$call : buildIconBadge({
|
|
109
|
+
iconElement: iconElement,
|
|
110
|
+
iconColor: iconColor,
|
|
111
|
+
avatarTooltipText: avatarTooltipText
|
|
112
|
+
}));
|
|
113
|
+
},
|
|
114
|
+
title: title ? copyableSlot(title) : /*#__PURE__*/React.createElement(React.Fragment, null),
|
|
115
|
+
description: subtitle ? copyableSlot(subtitle) : /*#__PURE__*/React.createElement(React.Fragment, null),
|
|
116
|
+
headerSideChildren: undefined,
|
|
117
|
+
compactHeader: false,
|
|
118
|
+
withoutPadding: true,
|
|
119
|
+
lively: false,
|
|
120
|
+
withHeader: true,
|
|
121
|
+
className: cachedChildren ? 'custom-description' : ''
|
|
122
|
+
}, (cachedChildren || descriptionConfig !== null || notice) && /*#__PURE__*/React.createElement(DescriptionField, {
|
|
123
|
+
extraInformation: notice || /*#__PURE__*/React.createElement(React.Fragment, null),
|
|
124
|
+
descriptionConfig: descriptionConfig
|
|
125
|
+
}), renderFooter && renderFooter() || (footerText || actionButton) && /*#__PURE__*/React.createElement(Footer, _extends({
|
|
126
|
+
text: footerText
|
|
127
|
+
}, props, {
|
|
128
|
+
actionButton: actionButton,
|
|
129
|
+
actionButtonCallback: actionButtonCallback,
|
|
130
|
+
actionButtonTooltipText: actionButtonTooltipText,
|
|
131
|
+
isCustomDescription: cachedChildren !== undefined
|
|
132
|
+
}))));
|
|
133
|
+
});
|
|
134
|
+
export function buildInitialsBadge(name) {
|
|
135
|
+
return /*#__PURE__*/React.createElement(Initials, {
|
|
136
|
+
name: name
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* helper for wrapping a notice
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
export function buildExtraInfo(message, level) {
|
|
144
|
+
return /*#__PURE__*/React.createElement(S.ExtraInfo, null, /*#__PURE__*/React.createElement(Alert.InlineAlert, {
|
|
145
|
+
type: level || 'warning',
|
|
146
|
+
message: message
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Helper for returning initials. Handles cases such as John Smith, J. Smith, JS.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
export function getInitials(name) {
|
|
154
|
+
var hasTokens = name.indexOf(' ') !== -1;
|
|
155
|
+
return name.substring(0, hasTokens ? 1 : 2) + (hasTokens ? name.charAt(name.lastIndexOf(' ') + 1) : '');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Wrapper for obtaining an avatar based on initials
|
|
160
|
+
*/
|
|
161
|
+
export function Initials(_ref2) {
|
|
162
|
+
var name = _ref2.name,
|
|
163
|
+
children = _ref2.children;
|
|
164
|
+
return /*#__PURE__*/React.createElement(Badge, null, /*#__PURE__*/React.createElement(Avatar, {
|
|
165
|
+
size: "medium",
|
|
166
|
+
shape: "circle",
|
|
167
|
+
backgroundColor: "blue"
|
|
168
|
+
}, name && getInitials(name) || children));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Returns default information card's description section.
|
|
173
|
+
*/
|
|
174
|
+
function DescriptionField(_ref3) {
|
|
175
|
+
var _ref3$extraInformatio = _ref3.extraInformation,
|
|
176
|
+
extraInformation = _ref3$extraInformatio === void 0 ? undefined : _ref3$extraInformatio,
|
|
177
|
+
descriptionConfig = _ref3.descriptionConfig;
|
|
178
|
+
|
|
179
|
+
// note: if popover containing this information card will have
|
|
180
|
+
// `destroyTooltipOnHide` (or `keepParent`) set to false, then description state hook will be getting reset
|
|
181
|
+
var _React$useState = React.useState(''),
|
|
182
|
+
description = _React$useState[0],
|
|
183
|
+
setDescription = _React$useState[1];
|
|
184
|
+
|
|
185
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
186
|
+
className: "information-card-description"
|
|
187
|
+
}, extraInformation, descriptionConfig && /*#__PURE__*/React.createElement(SubtleForm.TextArea, _extends({
|
|
188
|
+
minRows: 1,
|
|
189
|
+
value: description // hideLabel
|
|
190
|
+
,
|
|
191
|
+
onChange: function onChange(v) {
|
|
192
|
+
descriptionConfig.onChange && descriptionConfig.onChange(v);
|
|
193
|
+
setDescription(v);
|
|
194
|
+
},
|
|
195
|
+
placeholder: "placeholer",
|
|
196
|
+
label: "Label",
|
|
197
|
+
labelTooltip: "label tooltip",
|
|
198
|
+
suffixTooltip: "Edit"
|
|
199
|
+
}, descriptionConfig, descriptionConfig.error ? {
|
|
200
|
+
error: descriptionConfig.error,
|
|
201
|
+
errorText: function errorText(isErr, text) {
|
|
202
|
+
return isErr ? text : '';
|
|
203
|
+
}
|
|
204
|
+
} : {}, {
|
|
205
|
+
disabled: descriptionConfig.disabled
|
|
206
|
+
})));
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Tooltip helper for action button in footer
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
function withTooltip(Component, actionButtonTooltipText, props) {
|
|
214
|
+
// type is related to ds-tooltip's: shouldRenderDescription (it makes use of description prop only if tooltip type!=='default')
|
|
215
|
+
return /*#__PURE__*/React.createElement(Tooltip, _extends({
|
|
216
|
+
type: 'default',
|
|
217
|
+
title: actionButtonTooltipText
|
|
218
|
+
}, props), Component);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Renders footer part including handling action button with an optional tooltip
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
function Footer(_ref4) {
|
|
226
|
+
var _ref4$actionButton = _ref4.actionButton,
|
|
227
|
+
actionButton = _ref4$actionButton === void 0 ? false : _ref4$actionButton,
|
|
228
|
+
actionButtonCallback = _ref4.actionButtonCallback,
|
|
229
|
+
_ref4$actionButtonToo = _ref4.actionButtonTooltipText,
|
|
230
|
+
actionButtonTooltipText = _ref4$actionButtonToo === void 0 ? '' : _ref4$actionButtonToo,
|
|
231
|
+
_ref4$text = _ref4.text,
|
|
232
|
+
text = _ref4$text === void 0 ? '' : _ref4$text,
|
|
233
|
+
isCustomDescription = _ref4.isCustomDescription;
|
|
234
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
|
|
235
|
+
marginTop: isCustomDescription ? 16 : 8,
|
|
236
|
+
marginBottom: 0,
|
|
237
|
+
dashed: true
|
|
238
|
+
}), /*#__PURE__*/React.createElement(S.Flex, {
|
|
239
|
+
style: {
|
|
240
|
+
alignItems: 'center'
|
|
241
|
+
}
|
|
242
|
+
}, /*#__PURE__*/React.createElement(S.FlexGrow, null, text && /*#__PURE__*/React.createElement(Text, {
|
|
243
|
+
size: "xsmall"
|
|
244
|
+
}, text)), /*#__PURE__*/React.createElement(S.ActionButtonContainer, null, actionButton && actionButton === true && withTooltip( /*#__PURE__*/React.createElement(Button, {
|
|
245
|
+
color: "grey",
|
|
246
|
+
type: "secondary",
|
|
247
|
+
mode: "single-icon",
|
|
248
|
+
onClick: actionButtonCallback
|
|
249
|
+
}, /*#__PURE__*/React.createElement(ArrowRuCircleM, null)), actionButtonTooltipText) || typeof actionButton === 'function' && actionButton())));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export default InformationCard;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Flex: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
|
+
export declare const FlexGrow: import("styled-components").StyledComponent<"div", any, import("react").DetailedHTMLFactory<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
|
|
4
|
+
grow?: number | undefined;
|
|
5
|
+
}, never>;
|
|
6
|
+
export declare const ActionButtonContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
7
|
+
export declare const InfoCardWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
8
|
+
footerText?: string | undefined;
|
|
9
|
+
}, never>;
|
|
10
|
+
/**
|
|
11
|
+
* This component can be used to style container with popovers/tooltips to disable arrow.
|
|
12
|
+
*/
|
|
13
|
+
export declare const HidePopoverArrowWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
14
|
+
/**
|
|
15
|
+
* Should be mounted in application where.
|
|
16
|
+
*/
|
|
17
|
+
export declare const GlobalCSSHidePopoverArrow: import("styled-components").GlobalStyleComponent<{}, import("styled-components").DefaultTheme>;
|
|
18
|
+
export declare const ExtraInfo: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
19
|
+
export declare const TooltipComponentClassName: import("styled-components").StyledComponent<"div", any, Pick<import("@synerise/ds-tooltip/dist/Tooltip.types").default, "button" | "title" | "offset" | "description" | "icon" | "status" | "tutorials" | "tutorialAutoplay" | "tutorialAutoplaySpeed" | "timeToHideAfterClick"> & {
|
|
20
|
+
tooltipType: import("@synerise/ds-tooltip/dist/Tooltip.types").tooltipTypes;
|
|
21
|
+
}, never>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var _templateObject;
|
|
2
|
+
|
|
3
|
+
function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
|
|
4
|
+
|
|
5
|
+
import styled, { createGlobalStyle } from 'styled-components';
|
|
6
|
+
import { IconContainer, Container as CardContainer, PaddingWrapper, ChildrenContainer, HeaderContent, Header, Title } from '@synerise/ds-card/dist/Card/Card.styles';
|
|
7
|
+
import * as S from '@synerise/ds-tooltip/dist/Tooltip.styles';
|
|
8
|
+
import { AntdButton } from '@synerise/ds-button/dist/Button.styles';
|
|
9
|
+
export var Flex = styled.div.withConfig({
|
|
10
|
+
displayName: "InformationCardstyles__Flex",
|
|
11
|
+
componentId: "zxu5qa-0"
|
|
12
|
+
})(["display:flex;"]);
|
|
13
|
+
export var FlexGrow = styled.div.withConfig({
|
|
14
|
+
displayName: "InformationCardstyles__FlexGrow",
|
|
15
|
+
componentId: "zxu5qa-1"
|
|
16
|
+
})(["flex-grow:", ";margin-top:16px;margin-bottom:8px;"], function (_ref) {
|
|
17
|
+
var _ref$grow = _ref.grow,
|
|
18
|
+
grow = _ref$grow === void 0 ? 1 : _ref$grow;
|
|
19
|
+
return grow;
|
|
20
|
+
});
|
|
21
|
+
export var ActionButtonContainer = styled.div.withConfig({
|
|
22
|
+
displayName: "InformationCardstyles__ActionButtonContainer",
|
|
23
|
+
componentId: "zxu5qa-2"
|
|
24
|
+
})(["margin:8px 0 8px 0;"]);
|
|
25
|
+
export var InfoCardWrapper = styled.div.withConfig({
|
|
26
|
+
displayName: "InformationCardstyles__InfoCardWrapper",
|
|
27
|
+
componentId: "zxu5qa-3"
|
|
28
|
+
})(["margin-left:8px;", "{background-color:white;margin-bottom:1px;font-weight:400;min-width:250px;&.custom-description ", "{margin-top:8px;}padding:16px 16px 8px 16px;border-radius:3px;box-shadow:0 16px 32px 0 rgba(35,41,54,0.1);}", "{padding-top:0;}", "{padding:0 0 1px 0;margin-bottom:8px;}", "{align-self:center;margin-left:10px;margin-right:10px;}", "{margin:0;}", "", "{margin-bottom:0;font-size:14px;}", "{width:32px;height:32px;}.ds-button{background:transparent;}.btn-focus,.btn-focus:hover{box-shadow:unset;}"], CardContainer, ChildrenContainer, PaddingWrapper, Header, IconContainer, HeaderContent, Title, Title, AntdButton);
|
|
29
|
+
/**
|
|
30
|
+
* This component can be used to style container with popovers/tooltips to disable arrow.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
export var HidePopoverArrowWrapper = styled.div.withConfig({
|
|
34
|
+
displayName: "InformationCardstyles__HidePopoverArrowWrapper",
|
|
35
|
+
componentId: "zxu5qa-4"
|
|
36
|
+
})([".ant-popover-arrow-content,.ant-tooltip-arrow-content{display:none;}"]);
|
|
37
|
+
/**
|
|
38
|
+
* Should be mounted in application where.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
export var GlobalCSSHidePopoverArrow = createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n .ant-popover-arrow-content,.ant-tooltip-arrow-content {\n display: none;\n}"])));
|
|
42
|
+
export var ExtraInfo = styled.div.withConfig({
|
|
43
|
+
displayName: "InformationCardstyles__ExtraInfo",
|
|
44
|
+
componentId: "zxu5qa-5"
|
|
45
|
+
})(["margin-bottom:1px;"]);
|
|
46
|
+
export var TooltipComponentClassName = S.TooltipComponent;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, buildExtraInfo, buildIconBadge, buildInitialsBadge } from './InformationCard';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@synerise/ds-information-card",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"description": "InformationCard 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 --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
|
+
"lint": "eslint . --ext .ts --ext .tsx --max-warnings 0 --ignore-pattern dist",
|
|
25
|
+
"prepublish": "npm run build",
|
|
26
|
+
"test": "jest",
|
|
27
|
+
"test:watch": "npm run test -- --watchAll",
|
|
28
|
+
"types": "tsc --noEmit"
|
|
29
|
+
},
|
|
30
|
+
"sideEffects": [
|
|
31
|
+
"dist/style/*",
|
|
32
|
+
"*.less"
|
|
33
|
+
],
|
|
34
|
+
"types": "dist/index.d.ts",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@synerise/ds-alert": "^0.4.4",
|
|
37
|
+
"@synerise/ds-avatar": "^0.14.21",
|
|
38
|
+
"@synerise/ds-card": "^0.12.0",
|
|
39
|
+
"@synerise/ds-description": "^0.3.21",
|
|
40
|
+
"@synerise/ds-subtle-form": "^0.9.4",
|
|
41
|
+
"@synerise/ds-typography": "^0.12.2"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@synerise/ds-core": "^0.31.2",
|
|
45
|
+
"react": ">=16.9.0 < 17.0.0"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "41a4ccb4e6222516622347a45cb6c65faec250d9"
|
|
48
|
+
}
|