ag-common 0.0.528 → 0.0.529

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.
@@ -74,6 +74,7 @@ const ListItemStyle = styled_1.default.div `
74
74
  &[data-selected='true'] {
75
75
  opacity: 1 !important;
76
76
  background-color: ${colours_1.colours.orangeRed} !important;
77
+ cursor: default;
77
78
  }
78
79
  &[data-selected='false'] {
79
80
  &:hover {
@@ -156,7 +157,7 @@ function DropdownList(p) {
156
157
  setOpen(!open);
157
158
  } },
158
159
  react_1.default.createElement(DropItems, { "data-open": open, style: style, "data-bounced": bounced }, open &&
159
- options.map((s, i) => (react_1.default.createElement(ListItem, { key: p.renderF(s).key, render: p.renderF(s), onChange: () => p.onChange(s, i), selected: s === state })))),
160
+ options.map((s, i) => (react_1.default.createElement(ListItem, { key: typeof s === 'string' ? s : p.renderF(s).key, render: p.renderF(s), onChange: () => p.onChange(s, i), selected: s === state })))),
160
161
  openDisplay));
161
162
  }
162
163
  exports.DropdownList = DropdownList;
@@ -44,7 +44,7 @@ const Content = styled_1.default.div `
44
44
  margin: auto;
45
45
  display: flex;
46
46
  flex-flow: column;
47
- justify-content: flex-start;
47
+ justify-content: space-evenly;
48
48
  align-items: center;
49
49
  max-height: calc(100vh - 20rem);
50
50
  overflow-y: auto;
@@ -62,11 +62,10 @@ const Content = styled_1.default.div `
62
62
  `;
63
63
  const Row = styled_1.default.div `
64
64
  width: 100%;
65
- cursor: pointer;
66
65
  `;
67
66
  const SearchBase = (p) => {
68
67
  var _a, _b, _c, _d;
69
- const { maxDisplayItems = 20 } = p;
68
+ const { maxDisplayItems = 1000 } = p;
70
69
  const [searchText, setSearchText] = (0, react_1.useState)((_a = p.defaultValue) !== null && _a !== void 0 ? _a : '');
71
70
  const resWrap = (foundItem, target) => {
72
71
  var _a, _b;
@@ -78,13 +77,17 @@ const SearchBase = (p) => {
78
77
  }
79
78
  };
80
79
  const filteredItemsRaw = p.displayItems.filter((i) => p.willDisplayItem(searchText, i));
81
- const { part: filteredItems } = (0, array_1.take)(filteredItemsRaw, maxDisplayItems);
80
+ const { part: filteredItems } = (0, array_1.take)(filteredItemsRaw, maxDisplayItems < 0 ? filteredItemsRaw.length : maxDisplayItems);
81
+ const outdiff = filteredItems.length !== p.displayItems.length;
82
82
  const showText = (_d = (_c = (_b = p.texts) === null || _b === void 0 ? void 0 : _b.totalItems) === null || _c === void 0 ? void 0 : _c.call(_b, filteredItems.length, p.displayItems.length)) !== null && _d !== void 0 ? _d : `Showing ${filteredItems.length} out of ${p.displayItems.length} total
83
83
  items`;
84
84
  return (react_1.default.createElement(Base, { className: p.className },
85
85
  react_1.default.createElement(SearchBox_1.SearchBox, Object.assign({}, p, { searchText: searchText, setSearchText: setSearchText })),
86
86
  react_1.default.createElement(Content, { "data-hasitems": !!filteredItems.length, "data-type": "content" },
87
- filteredItems.map((item, index) => (react_1.default.createElement(Row, { key: p.getKeyF(item), onClick: (e) => resWrap(item, e.target) }, p.renderItem({ searchText, item, index })))),
88
- searchText && react_1.default.createElement(Row, null, showText))));
87
+ filteredItems.map((item, index) => (0, react_1.cloneElement)(p.renderItem({ searchText, item, index }), {
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+ onClick: (e) => resWrap(item, e.target),
90
+ })),
91
+ outdiff && react_1.default.createElement(Row, null, showText))));
89
92
  };
90
93
  exports.SearchBase = SearchBase;
@@ -57,6 +57,7 @@ const MagnifyIcon = styled_1.default.div `
57
57
  height: 1.5rem;
58
58
  margin-right: 0.5rem;
59
59
  cursor: pointer;
60
+ margin-left: 0.5rem;
60
61
  `;
61
62
  const CrossIconStyled = (0, styled_1.default)(icons_1.CrossIcon) `
62
63
  position: absolute;
@@ -65,6 +66,10 @@ const CrossIconStyled = (0, styled_1.default)(icons_1.CrossIcon) `
65
66
  right: 2rem;
66
67
  }
67
68
  `;
69
+ const TextEditStyled = (0, styled_1.default)(TextEdit_1.TextEdit) `
70
+ padding: 0;
71
+ height: 2.5rem;
72
+ `;
68
73
  exports.SearchBox = (0, react_1.forwardRef)((p, ref) => {
69
74
  const textEditRef = (0, react_1.createRef)();
70
75
  (0, react_1.useImperativeHandle)(ref, () => ({
@@ -84,7 +89,7 @@ exports.SearchBox = (0, react_1.forwardRef)((p, ref) => {
84
89
  (_a = textEditRef === null || textEditRef === void 0 ? void 0 : textEditRef.current) === null || _a === void 0 ? void 0 : _a.setValue(p.searchText);
85
90
  }, [p.searchText, textEditRef]);
86
91
  return (react_1.default.createElement(Base, Object.assign({ "data-type": "search", className: p.className }, (0, dom_1.filterDataProps)(p)),
87
- react_1.default.createElement(TextEdit_1.TextEdit, { ref: textEditRef, placeholder: p.placeholderText, defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(MagnifyIcon, { onClick: () => { var _a; return p.setSearchText(((_a = textEditRef === null || textEditRef === void 0 ? void 0 : textEditRef.current) === null || _a === void 0 ? void 0 : _a.getValue()) || '', true); } },
92
+ react_1.default.createElement(TextEditStyled, { ref: textEditRef, placeholder: p.placeholderText, defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(MagnifyIcon, { onClick: () => { var _a; return p.setSearchText(((_a = textEditRef === null || textEditRef === void 0 ? void 0 : textEditRef.current) === null || _a === void 0 ? void 0 : _a.getValue()) || '', true); } },
88
93
  react_1.default.createElement(icons_1.Magnify, null)), noGrow: true, allowUndo: false, onClickOutsideWithNoValue: null, onSubmit: (v, enterPressed) => (0, debounce_1.debounce)(() => {
89
94
  p.setSearchText(v, enterPressed);
90
95
  }, { key: 'pagesearch', time: 200 }), defaultValue: p.defaultValue }),
@@ -4,12 +4,13 @@ export interface ISearchDialog<T> {
4
4
  placeholderText?: string;
5
5
  /**
6
6
  * method run to render each filtered item
7
+ * will inject onClick handler
7
8
  */
8
9
  renderItem: ({ searchText, item, index, }: {
9
10
  searchText: string;
10
11
  item: T;
11
12
  index: number;
12
- }) => JSX.Element | string;
13
+ }) => JSX.Element;
13
14
  /**
14
15
  * all potential items
15
16
  */
@@ -18,7 +19,7 @@ export interface ISearchDialog<T> {
18
19
  * run to filter items by search text
19
20
  */
20
21
  willDisplayItem: (searchText: string, item: T) => boolean;
21
- /** how many search items to return at most. default 20 */
22
+ /** how many search items to return at most. default 1000. if -1 will return all */
22
23
  maxDisplayItems?: number;
23
24
  /**
24
25
  * get unique render key
@@ -53,6 +53,7 @@ const basecss = (0, react_1.css) `
53
53
  resize: none;
54
54
  overflow: hidden;
55
55
  background-color: white;
56
+ color: black;
56
57
  font-size: inherit;
57
58
  font-weight: inherit;
58
59
  font-family: inherit;
@@ -67,7 +68,7 @@ const ValueTextArea = styled_1.default.textarea `
67
68
  }
68
69
  `;
69
70
  const ValueTextBox = styled_1.default.input `
70
- ${basecss}
71
+ ${basecss};
71
72
  `;
72
73
  const ValueBoxEdit = (0, styled_1.default)(common_2.ValueBox) `
73
74
  border: solid 1px #ccc;
@@ -31,6 +31,7 @@ exports.ValueBox = styled_1.default.div `
31
31
  exports.valueCss = (0, react_1.css) `
32
32
  width: 100%;
33
33
  height: 100%;
34
+ padding: 0;
34
35
  word-break: break-all;
35
36
  font-size: inherit;
36
37
  font-weight: inherit;
@@ -8,7 +8,7 @@ export type ITimelineItem = {
8
8
  checked: false;
9
9
  disabled?: boolean;
10
10
  });
11
- export declare const Timeline: ({ lineColour, items, onClick, maxCircleSize, className, bgColour, titleHover, showTitles, }: {
11
+ export declare const Timeline: ({ lineColour, items, onClick, maxCircleSize, className, bgColour, showTitles, }: {
12
12
  /** default min(5vw,3rem) */
13
13
  maxCircleSize?: string | undefined;
14
14
  /** default #ccc */
@@ -18,7 +18,6 @@ export declare const Timeline: ({ lineColour, items, onClick, maxCircleSize, cla
18
18
  className?: string | undefined;
19
19
  /** used for behind icons. default white */
20
20
  bgColour?: string | undefined;
21
- titleHover?: ((i: ITimelineItem) => string) | undefined;
22
21
  /** if true, will show titles under timeline. default true */
23
22
  showTitles?: boolean | undefined;
24
23
  }) => React.JSX.Element;
@@ -29,8 +29,8 @@ const Line = styled_1.default.div `
29
29
  position: absolute;
30
30
  top: 45%;
31
31
  height: 10%;
32
- left: 0;
33
- right: 0;
32
+ left: 1px;
33
+ right: 1px;
34
34
  `;
35
35
  const Item = styled_1.default.div `
36
36
  z-index: 1;
@@ -43,7 +43,7 @@ const Item = styled_1.default.div `
43
43
  const Title = styled_1.default.span `
44
44
  text-align: center;
45
45
  `;
46
- const Timeline = ({ lineColour = '#ccc', items, onClick, maxCircleSize = 'min(5vw,3rem)', className, bgColour = 'white', titleHover, showTitles = true, }) => {
46
+ const Timeline = ({ lineColour = '#ccc', items, onClick, maxCircleSize = 'min(5vw,3rem)', className, bgColour = 'white', showTitles = true, }) => {
47
47
  const firstFalse = items.findIndex((i) => !i.checked && !i.disabled);
48
48
  const lastTrue = (0, array_1.findLastIndex)(items, (i) => i.checked);
49
49
  return (react_1.default.createElement(Base, { className: className },
@@ -51,7 +51,7 @@ const Timeline = ({ lineColour = '#ccc', items, onClick, maxCircleSize = 'min(5v
51
51
  react_1.default.createElement(Line, { style: { backgroundColor: lineColour } }),
52
52
  items.map((p, index) => {
53
53
  const enabled = index === lastTrue || index === firstFalse;
54
- return (react_1.default.createElement(Item, { key: p.key, title: titleHover === null || titleHover === void 0 ? void 0 : titleHover(p) },
54
+ return (react_1.default.createElement(Item, { key: p.key, title: p === null || p === void 0 ? void 0 : p.title },
55
55
  react_1.default.createElement(Icon_1.Icon, { style: {
56
56
  maxWidth: maxCircleSize,
57
57
  cursor: enabled ? 'pointer' : 'default',
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import type { User } from '../../helpers/jwt';
3
2
  export interface IUserImage {
4
3
  image?: string;
5
4
  className?: string;
@@ -9,6 +8,10 @@ export interface IUserImage {
9
8
  export declare const UserImage: ({ image, className, title, }: IUserImage) => React.JSX.Element;
10
9
  export interface IUserProfileImage {
11
10
  className?: string;
12
- user?: Pick<User, 'picture' | 'fullname' | 'userId'>;
11
+ user?: {
12
+ picture: string;
13
+ fullname: string;
14
+ userId: string;
15
+ };
13
16
  }
14
17
  export declare const UserProfileImage: ({ className, user }: IUserProfileImage) => React.JSX.Element;
@@ -31,7 +31,6 @@ exports.UserProfileImage = exports.UserImage = void 0;
31
31
  const styled_1 = __importDefault(require("@emotion/styled"));
32
32
  const react_1 = __importStar(require("react"));
33
33
  const array_1 = require("../../../common/helpers/array");
34
- const log_1 = require("../../../common/helpers/log");
35
34
  const UserOutline_1 = require("../../icons/UserOutline");
36
35
  const Base = styled_1.default.div `
37
36
  width: 2.5rem;
@@ -40,28 +39,58 @@ const Base = styled_1.default.div `
40
39
  border: solid 1px white;
41
40
  overflow: hidden;
42
41
  position: relative;
42
+
43
+ @keyframes color {
44
+ 0% {
45
+ fill: #bbb;
46
+ }
47
+ 50% {
48
+ fill: #aaa;
49
+ }
50
+ 100% {
51
+ fill: #bbb;
52
+ }
53
+ }
54
+ svg {
55
+ transition: all 1s;
56
+ }
57
+ &[data-fail='0'] {
58
+ svg {
59
+ fill: white;
60
+ }
61
+ }
62
+ &[data-fail='0.5'] {
63
+ svg {
64
+ animation-name: color;
65
+ animation-duration: 2s;
66
+ animation-iteration-count: infinite;
67
+ }
68
+ }
69
+ &[data-fail='1'] {
70
+ svg {
71
+ fill: #333;
72
+ }
73
+ }
43
74
  `;
44
75
  const Img = styled_1.default.img `
45
76
  width: 2.5rem;
46
77
  height: 2.5rem;
78
+ position: absolute;
79
+ top: 0;
80
+ left: 0;
47
81
  `;
48
- const images = {
49
- domains: ['platform-lookaside.fbsbx.com', 'lh3.googleusercontent.com'],
50
- };
51
82
  const UserImage = ({ image, className, title = 'user image', }) => {
52
- const [fallback, setFallback] = (0, react_1.useState)(false);
53
- return (react_1.default.createElement(Base, { className: className, title: title },
54
- image && !fallback && (react_1.default.createElement(Img, { alt: "user", src: image, onError: () => setFallback(true) })),
55
- (!image || fallback) && UserOutline_1.UserOutline));
83
+ const [failed, setFailed] = (0, react_1.useState)(0);
84
+ (0, react_1.useEffect)(() => {
85
+ setFailed(0.5);
86
+ }, []);
87
+ return (react_1.default.createElement(Base, { className: className, title: title, "data-fail": failed },
88
+ UserOutline_1.UserOutline,
89
+ failed !== 1 && (react_1.default.createElement(Img, { alt: "user", src: image, onError: () => setFailed(1) }))));
56
90
  };
57
91
  exports.UserImage = UserImage;
58
92
  const UserProfileImage = ({ className, user }) => {
59
93
  const image = user === null || user === void 0 ? void 0 : user.picture;
60
- if (image) {
61
- if (!images.domains.find((i) => image.includes(i))) {
62
- (0, log_1.warn)(`bad domain:${image}`);
63
- }
64
- }
65
94
  const titleA = [user === null || user === void 0 ? void 0 : user.fullname, user === null || user === void 0 ? void 0 : user.userId].filter(array_1.notEmpty);
66
95
  const title = titleA.length === 0 ? '' : titleA.join(' - ');
67
96
  return react_1.default.createElement(exports.UserImage, { image: image, title: title, className: className });
@@ -8,6 +8,6 @@ const react_1 = __importDefault(require("react"));
8
8
  const Checkmark = ({ style, }) => {
9
9
  var _a;
10
10
  return (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "2 2 20 20", style: Object.assign(Object.assign({}, style), { fill: undefined }) },
11
- react_1.default.createElement("path", { stroke: (_a = style === null || style === void 0 ? void 0 : style.fill) !== null && _a !== void 0 ? _a : '#000', strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M8 12.333 10.461 15 16 9m5 3a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" })));
11
+ react_1.default.createElement("path", { fill: "none", stroke: (_a = style === null || style === void 0 ? void 0 : style.fill) !== null && _a !== void 0 ? _a : '#000', strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M8 12.333 10.461 15 16 9m5 3a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" })));
12
12
  };
13
13
  exports.Checkmark = Checkmark;
@@ -8,6 +8,6 @@ const react_1 = __importDefault(require("react"));
8
8
  const Circle = ({ style, dotted = false, }) => {
9
9
  var _a;
10
10
  return (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "2 2 20 20", style: Object.assign(Object.assign({}, style), { fill: undefined }) },
11
- react_1.default.createElement("path", { stroke: (_a = style === null || style === void 0 ? void 0 : style.fill) !== null && _a !== void 0 ? _a : '#000', strokeLinecap: "round", strokeLinejoin: "round", strokeDasharray: !dotted ? '' : '4 4', strokeWidth: "2", d: "M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" })));
11
+ react_1.default.createElement("path", { fill: "none", stroke: (_a = style === null || style === void 0 ? void 0 : style.fill) !== null && _a !== void 0 ? _a : '#000', strokeLinecap: "round", strokeLinejoin: "round", strokeDasharray: !dotted ? '' : '4 4', strokeWidth: "2", d: "M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" })));
12
12
  };
13
13
  exports.Circle = Circle;
@@ -11,6 +11,6 @@ const Warning = ({ className }) => (react_1.default.createElement("svg", { xmlns
11
11
  react_1.default.createElement("linearGradient", { id: "a", x2: "0", y1: "45.47", y2: "-.599", gradientTransform: "matrix(1.31117 0 0 1.30239 737.39 159.91)", gradientUnits: "userSpaceOnUse" },
12
12
  react_1.default.createElement("stop", { stopColor: "#ffc515" }),
13
13
  react_1.default.createElement("stop", { offset: "1", stopColor: "#ffd55b" }))),
14
- react_1.default.createElement("path", { fill: "white", stroke: "url(#a)", strokeWidth: "4px", d: "m797.94 212.01-25.607-48c-.736-1.333-2.068-2.074-3.551-2.074s-2.822.889-3.569 2.222l-25.417 48c-.598 1.185-.605 2.815.132 4s1.921 1.778 3.404 1.778h51.02c1.483 0 2.821-.741 3.42-1.926.747-1.185.753-2.667.165-4", transform: "translate(-627.02 -130.8) scale(.85714)" }),
14
+ react_1.default.createElement("path", { fill: "none", stroke: "url(#a)", strokeWidth: "4px", d: "m797.94 212.01-25.607-48c-.736-1.333-2.068-2.074-3.551-2.074s-2.822.889-3.569 2.222l-25.417 48c-.598 1.185-.605 2.815.132 4s1.921 1.778 3.404 1.778h51.02c1.483 0 2.821-.741 3.42-1.926.747-1.185.753-2.667.165-4", transform: "translate(-627.02 -130.8) scale(.85714)" }),
15
15
  react_1.default.createElement("path", { fillOpacity: ".75", stroke: "#40330d", strokeWidth: ".90168", d: "M31.996 24.239a1.93 1.93 0 0 0-1.926 1.92v11.559c0 1.06.855 1.92 1.926 1.92a1.929 1.929 0 0 0 1.925-1.92v-11.56c0-1.06-.853-1.92-1.925-1.92zm0 19.249c-1.064 0-1.926.86-1.926 1.925 0 1.064.86 1.925 1.926 1.925 1.064 0 1.925-.86 1.925-1.925a1.922 1.922 0 0 0-1.925-1.925z" })));
16
16
  exports.Warning = Warning;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.528",
2
+ "version": "0.0.529",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",