ag-common 0.0.120 → 0.0.124

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.
@@ -4,7 +4,7 @@ exports.openApiImpl = void 0;
4
4
  /* eslint-disable no-new */
5
5
  const aws_cdk_lib_1 = require("aws-cdk-lib");
6
6
  const __1 = require("../..");
7
- const distinctBy_1 = require("../../common/helpers/distinctBy");
7
+ const array_1 = require("../../common/helpers/array");
8
8
  const log_1 = require("../../common/helpers/log");
9
9
  // eslint-disable-next-line
10
10
  const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]) => ({
@@ -49,8 +49,8 @@ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, }) => {
49
49
  seenPermissions.default = true;
50
50
  }
51
51
  //
52
- const readTables = (0, distinctBy_1.distinctBy)([...(((_a = def === null || def === void 0 ? void 0 : def.dynamo) === null || _a === void 0 ? void 0 : _a.reads) || []), ...(((_b = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _b === void 0 ? void 0 : _b.reads) || [])], (s) => s.shortName);
53
- const writeTables = (0, distinctBy_1.distinctBy)([...(((_c = def === null || def === void 0 ? void 0 : def.dynamo) === null || _c === void 0 ? void 0 : _c.writes) || []), ...(((_d = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _d === void 0 ? void 0 : _d.writes) || [])], (s) => s.shortName);
52
+ const readTables = (0, array_1.distinctBy)([...(((_a = def === null || def === void 0 ? void 0 : def.dynamo) === null || _a === void 0 ? void 0 : _a.reads) || []), ...(((_b = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _b === void 0 ? void 0 : _b.reads) || [])], (s) => s.shortName);
53
+ const writeTables = (0, array_1.distinctBy)([...(((_c = def === null || def === void 0 ? void 0 : def.dynamo) === null || _c === void 0 ? void 0 : _c.writes) || []), ...(((_d = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _d === void 0 ? void 0 : _d.writes) || [])], (s) => s.shortName);
54
54
  const policies = [...(def.policies || []), ...((lp === null || lp === void 0 ? void 0 : lp.policies) || [])].filter(__1.notEmpty);
55
55
  const layers = [...(def.layers || []), ...((lp === null || lp === void 0 ? void 0 : lp.layers) || [])].filter(__1.notEmpty);
56
56
  const env = Object.assign(Object.assign({}, (def.env || {})), ((lp === null || lp === void 0 ? void 0 : lp.env) || {}));
@@ -7,3 +7,11 @@ export declare const take: <T>(array: T[], num: number) => {
7
7
  export declare const chunk: <T>(array: T[], max: number) => T[][];
8
8
  export declare const partition: <T>(array: T[], func: (v: T) => boolean) => T[][] | null;
9
9
  export declare function notEmpty<TValue>(value: TValue | null | undefined | false): value is TValue;
10
+ /**
11
+ * return a distinct array of items determined by a key function
12
+ * @param data
13
+ * @param key
14
+ * @param ignoreEmpty
15
+ */
16
+ export declare function distinctBy<T, TY>(data: T[], key: (item: T) => TY, ignoreEmpty?: boolean): T[];
17
+ export declare const distinct: <T extends string | number>(arr: readonly T[]) => T[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.notEmpty = exports.partition = exports.chunk = exports.take = exports.flat = exports.toObject = void 0;
3
+ exports.distinct = exports.distinctBy = exports.notEmpty = exports.partition = exports.chunk = exports.take = exports.flat = exports.toObject = void 0;
4
4
  const toObject = (arr, keyF) => {
5
5
  const ret = {};
6
6
  if (!arr || !keyF) {
@@ -47,3 +47,37 @@ function notEmpty(value) {
47
47
  return value !== null && value !== undefined && value !== false;
48
48
  }
49
49
  exports.notEmpty = notEmpty;
50
+ /**
51
+ * return a distinct array of items determined by a key function
52
+ * @param data
53
+ * @param key
54
+ * @param ignoreEmpty
55
+ */
56
+ function distinctBy(data, key, ignoreEmpty) {
57
+ if (!data || data.length === 0) {
58
+ return data;
59
+ }
60
+ const hashSet = new Set();
61
+ return data.filter((x) => {
62
+ let keyVal;
63
+ if (typeof key === 'string') {
64
+ keyVal = x[key];
65
+ }
66
+ else {
67
+ keyVal = key(x);
68
+ }
69
+ if (!keyVal && ignoreEmpty) {
70
+ return false;
71
+ }
72
+ if (!hashSet.has(keyVal)) {
73
+ hashSet.add(keyVal);
74
+ return true;
75
+ }
76
+ return false;
77
+ });
78
+ }
79
+ exports.distinctBy = distinctBy;
80
+ const distinct = (arr) => [
81
+ ...new Set(arr),
82
+ ];
83
+ exports.distinct = distinct;
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * convert an ArrayBuffer (usually from file.arrayBuffer) to base64. Usually on client side before server send
4
+ * @param buffer
5
+ * @returns
6
+ */
7
+ export declare function arrayBufferToBase64(buffer: ArrayBuffer): string;
8
+ /**
9
+ * convert a base64 string to a binary Buffer. Usually on server side from client sent content
10
+ * @param raw
11
+ * @returns
12
+ */
13
+ export declare const base64ToBinary: (raw: string) => Buffer;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.base64ToBinary = exports.arrayBufferToBase64 = void 0;
4
+ const string_1 = require("./string");
5
+ function toBuffer(ab) {
6
+ const buffer = new Buffer(ab.byteLength);
7
+ const view = new Uint8Array(ab);
8
+ for (let i = 0; i < buffer.length; ++i) {
9
+ buffer[i] = view[i];
10
+ }
11
+ return buffer;
12
+ }
13
+ function toArrayBuffer(base64) {
14
+ const binary_string = (0, string_1.fromBase64)(base64);
15
+ const len = binary_string.length;
16
+ const bytes = new Uint8Array(len);
17
+ for (let i = 0; i < len; i += 1) {
18
+ bytes[i] = binary_string.charCodeAt(i);
19
+ }
20
+ return bytes.buffer;
21
+ }
22
+ /**
23
+ * convert an ArrayBuffer (usually from file.arrayBuffer) to base64. Usually on client side before server send
24
+ * @param buffer
25
+ * @returns
26
+ */
27
+ function arrayBufferToBase64(buffer) {
28
+ let binary = '';
29
+ const bytes = new Uint8Array(buffer);
30
+ const len = bytes.byteLength;
31
+ for (let i = 0; i < len; i += 1) {
32
+ binary += String.fromCharCode(bytes[i]);
33
+ }
34
+ return (0, string_1.toBase64)(binary);
35
+ }
36
+ exports.arrayBufferToBase64 = arrayBufferToBase64;
37
+ /**
38
+ * convert a base64 string to a binary Buffer. Usually on server side from client sent content
39
+ * @param raw
40
+ * @returns
41
+ */
42
+ const base64ToBinary = (raw) => toBuffer(toArrayBuffer(raw));
43
+ exports.base64ToBinary = base64ToBinary;
@@ -1,7 +1,7 @@
1
1
  export * from './array';
2
2
  export * from './async';
3
+ export * from './binary';
3
4
  export * from './date';
4
- export * from './distinctBy';
5
5
  export * from './email';
6
6
  export * from './func';
7
7
  export * from './generator';
@@ -12,8 +12,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./array"), exports);
14
14
  __exportStar(require("./async"), exports);
15
+ __exportStar(require("./binary"), exports);
15
16
  __exportStar(require("./date"), exports);
16
- __exportStar(require("./distinctBy"), exports);
17
17
  __exportStar(require("./email"), exports);
18
18
  __exportStar(require("./func"), exports);
19
19
  __exportStar(require("./generator"), exports);
@@ -14,7 +14,6 @@ const SClose = styled_components_1.default.div `
14
14
  cursor: pointer;
15
15
  background-color: white;
16
16
  top: 0;
17
- z-index: 1;
18
17
  right: 0;
19
18
  &:hover {
20
19
  opacity: 1;
@@ -25,7 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.ModalDropList = exports.Modal = exports.ModalItem = void 0;
26
26
  const react_1 = __importStar(require("react"));
27
27
  const styled_components_1 = __importDefault(require("styled-components"));
28
- const Close_1 = require("./Close");
28
+ const Close_1 = require("../Close");
29
29
  const useOnClickOutside_1 = require("../../helpers/useOnClickOutside");
30
30
  const FixedBackground = styled_components_1.default.div `
31
31
  position: fixed;
@@ -67,6 +67,9 @@ exports.ModalItem = styled_components_1.default.div `
67
67
  background-color: #eee;
68
68
  }
69
69
  `;
70
+ const CloseStyled = (0, styled_components_1.default)(Close_1.Close) `
71
+ z-index: 1;
72
+ `;
70
73
  const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'bottom', showCloseButton = true, closeOnMoveMouseOutside = false, className, closeOnClickOutside = true, }) => {
71
74
  const ref = (0, react_1.useRef)(null);
72
75
  (0, useOnClickOutside_1.useOnClickOutside)({ ref, moveMouseOutside: closeOnMoveMouseOutside }, () => {
@@ -79,7 +82,7 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'bott
79
82
  }
80
83
  return (react_1.default.createElement(FixedBackground, { className: className },
81
84
  react_1.default.createElement(ModalBase, { "data-position": position, "data-topposition": topPosition, ref: ref },
82
- showCloseButton && react_1.default.createElement(Close_1.Close, { onClick: () => setOpen(false) }),
85
+ showCloseButton && react_1.default.createElement(CloseStyled, { onClick: () => setOpen(false) }),
83
86
  children)));
84
87
  };
85
88
  exports.Modal = Modal;
@@ -85,7 +85,7 @@ const PromptModal = ({ wrapper, res, bottomText, topText, okText = 'OK', cancelT
85
85
  react_1.default.createElement(Content, null,
86
86
  topText && react_1.default.createElement(TopText, null, topText),
87
87
  react_1.default.createElement(BottomText, null, bottomText),
88
- react_1.default.createElement(TextInput_1.TextInput, { value: text, onChange: (c) => setText(c), type: "text", placeholder: placeholder }),
88
+ react_1.default.createElement(TextInput_1.TextInput, { value: text, onChange: (c) => setText(c), placeholder: placeholder, focus: true }),
89
89
  react_1.default.createElement(Bottom, { noGrow: true },
90
90
  react_1.default.createElement(Button_1.Button, { onClick: () => ret(text) }, okText),
91
91
  react_1.default.createElement(Button_1.Button, { invert: true, onClick: () => ret(undefined) }, cancelText))))));
@@ -1,11 +1,10 @@
1
1
  import React from 'react';
2
- import { InputTypes } from '../Input';
3
- export declare const TextInput: ({ type, placeholder, value, onChange, onKeyPress, label, disabled, className, }: {
2
+ export declare const TextInput: ({ placeholder, value, onChange, onKeyPress, label, disabled, className, focus, }: {
3
+ focus?: boolean | undefined;
4
4
  className?: string | undefined;
5
5
  disabled?: boolean | undefined;
6
6
  label?: string | JSX.Element | undefined;
7
7
  placeholder?: string | undefined;
8
- type: InputTypes;
9
8
  value: string;
10
9
  onChange: (value: string) => void;
11
10
  onKeyPress?: ((event: React.KeyboardEvent<HTMLInputElement>) => void) | undefined;
@@ -18,13 +18,36 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
21
24
  Object.defineProperty(exports, "__esModule", { value: true });
22
25
  exports.TextInput = void 0;
23
26
  const react_1 = __importStar(require("react"));
27
+ const styled_components_1 = __importDefault(require("styled-components"));
24
28
  const math_1 = require("../../../common/helpers/math");
25
- const Input_1 = require("../Input");
26
- const TextInput = ({ type = 'text', placeholder, value, onChange, onKeyPress, label, disabled = false, className, }) => {
29
+ const colours_1 = require("../../styles/colours");
30
+ const Base = styled_components_1.default.input `
31
+ font-size: 1.2rem;
32
+ border: solid 1px ${colours_1.colours.lightCharcoal};
33
+ border-radius: 0.5rem;
34
+ padding: 0.5rem;
35
+ width: calc(100% - 1.5rem);
36
+ &:disabled {
37
+ background-color: ${colours_1.colours.darker};
38
+ cursor: not-allowed;
39
+ }
40
+ `;
41
+ const TextInput = ({ placeholder, value, onChange, onKeyPress, label, disabled = false, className, focus, }) => {
27
42
  const [id] = (0, react_1.useState)((0, math_1.getRandomInt)(1000).toString());
28
- return (react_1.default.createElement(Input_1.Input, { className: className, disabled: disabled, id: id, label: label, type: type, placeholder: placeholder, required: true, value: value, onChange: (e) => onChange(e.target.value), onKeyPress: (e) => onKeyPress && onKeyPress(e) }));
43
+ const tiref = (0, react_1.useRef)(null);
44
+ (0, react_1.useEffect)(() => {
45
+ if (focus && (tiref === null || tiref === void 0 ? void 0 : tiref.current)) {
46
+ tiref.current.focus();
47
+ }
48
+ }, [focus]);
49
+ return (react_1.default.createElement(react_1.default.Fragment, null,
50
+ id && label ? react_1.default.createElement("label", { htmlFor: id }, label) : '',
51
+ react_1.default.createElement(Base, { ref: tiref, className: className, disabled: disabled, id: id, placeholder: placeholder, required: true, value: value, onChange: (e) => onChange(e.target.value), onKeyPress: (e) => onKeyPress && onKeyPress(e) })));
29
52
  };
30
53
  exports.TextInput = TextInput;
@@ -1,6 +1,7 @@
1
1
  export * from './BorderGradient';
2
2
  export * from './Button';
3
3
  export * from './Chevron';
4
+ export * from './Close';
4
5
  export * from './Confirm';
5
6
  export * from './Dropdown';
6
7
  export * from './DropdownList';
@@ -8,7 +9,6 @@ export * from './FlexColumn';
8
9
  export * from './FlexRow';
9
10
  export * from './HeadersRaw';
10
11
  export * from './Icon';
11
- export * from './Input';
12
12
  export * from './Loader';
13
13
  export * from './LoginButton';
14
14
  export * from './LogoutButton';
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./BorderGradient"), exports);
14
14
  __exportStar(require("./Button"), exports);
15
15
  __exportStar(require("./Chevron"), exports);
16
+ __exportStar(require("./Close"), exports);
16
17
  __exportStar(require("./Confirm"), exports);
17
18
  __exportStar(require("./Dropdown"), exports);
18
19
  __exportStar(require("./DropdownList"), exports);
@@ -20,7 +21,6 @@ __exportStar(require("./FlexColumn"), exports);
20
21
  __exportStar(require("./FlexRow"), exports);
21
22
  __exportStar(require("./HeadersRaw"), exports);
22
23
  __exportStar(require("./Icon"), exports);
23
- __exportStar(require("./Input"), exports);
24
24
  __exportStar(require("./Loader"), exports);
25
25
  __exportStar(require("./LoginButton"), exports);
26
26
  __exportStar(require("./LogoutButton"), exports);
@@ -18,8 +18,14 @@ const callOpenApi_1 = require("./callOpenApi");
18
18
  const node_cache_1 = __importDefault(require("node-cache"));
19
19
  let useCallOpenApiCache;
20
20
  const useCallOpenApi = (p) => {
21
- var _a, _b;
21
+ var _a;
22
+ if (!useCallOpenApiCache) {
23
+ useCallOpenApiCache = new node_cache_1.default({ stdTTL: p.cacheTtl || 120 });
24
+ }
22
25
  const ssrCached = (_a = p.ssrCacheItems) === null || _a === void 0 ? void 0 : _a.find((s) => s.cacheKey === p.cacheKey);
26
+ if (!useCallOpenApiCache.get(p.cacheKey) && ssrCached) {
27
+ useCallOpenApiCache.set(p.cacheKey, ssrCached);
28
+ }
23
29
  const defv = {
24
30
  data: undefined,
25
31
  url: '',
@@ -29,19 +35,16 @@ const useCallOpenApi = (p) => {
29
35
  loaded: false,
30
36
  reFetch: () => __awaiter(void 0, void 0, void 0, function* () { }),
31
37
  };
32
- const [data, setData] = (0, react_1.useState)(Object.assign(Object.assign({}, defv), { data: ssrCached ? (_b = ssrCached.prefillData) === null || _b === void 0 ? void 0 : _b.data : undefined, loaded: !!ssrCached }));
38
+ const cached = useCallOpenApiCache.get(p.cacheKey);
39
+ const [data, setData] = (0, react_1.useState)(Object.assign(Object.assign({}, defv), { data: cached, loaded: !!cached }));
33
40
  (0, react_1.useEffect)(() => {
34
41
  function run() {
35
42
  return __awaiter(this, void 0, void 0, function* () {
36
- if (!useCallOpenApiCache) {
37
- useCallOpenApiCache = new node_cache_1.default({ stdTTL: p.cacheTtl || 120 });
43
+ const resp = yield (0, callOpenApi_1.callOpenApi)(p);
44
+ if (useCallOpenApiCache) {
45
+ useCallOpenApiCache.set(p.cacheKey, resp.data);
38
46
  }
39
- let cached = useCallOpenApiCache.get(p.cacheKey) || undefined;
40
- if (!cached) {
41
- cached = yield (0, callOpenApi_1.callOpenApi)(p);
42
- useCallOpenApiCache.set(p.cacheKey, cached);
43
- }
44
- setData((d) => (Object.assign(Object.assign({}, cached), { loaded: true, loading: false, loadcount: d.loadcount + 1 })));
47
+ setData((d) => (Object.assign(Object.assign({}, resp), { loaded: true, loading: false, loadcount: d.loadcount + 1 })));
45
48
  });
46
49
  }
47
50
  const { error, loaded, loading, loadcount } = data;
@@ -51,7 +54,7 @@ const useCallOpenApi = (p) => {
51
54
  }
52
55
  setData((d) => (Object.assign(Object.assign({}, d), { loading: true })));
53
56
  void run();
54
- }, [data, p, setData]);
57
+ }, [cached, data, p, setData]);
55
58
  return Object.assign(Object.assign({}, data), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () {
56
59
  setData(defv);
57
60
  }) });
@@ -33,6 +33,14 @@ const useQueryStringRaw = ({ name, searchOverride, defaultValue, stringify, pars
33
33
  window.history.replaceState({}, '', loc);
34
34
  setStateRaw(v);
35
35
  };
36
+ (0, react_1.useEffect)(() => {
37
+ const parsed = new URLSearchParams(raw);
38
+ const g = parsed.get(name);
39
+ const newv = g ? parse(g) : defaultValue;
40
+ if (JSON.stringify(state) !== JSON.stringify(newv)) {
41
+ setStateRaw(newv);
42
+ }
43
+ }, [defaultValue, name, parse, raw, state]);
36
44
  return [state, setState];
37
45
  };
38
46
  exports.useQueryStringRaw = useQueryStringRaw;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export declare const HardOutline: (colour: string) => import("styled-components").FlattenSimpleInterpolation;
3
- export declare const Shadow: (colour: string) => import("styled-components").FlattenSimpleInterpolation;
3
+ export declare const Shadow: (colour?: string) => import("styled-components").FlattenSimpleInterpolation;
4
4
  export declare const NoTextSelect: import("styled-components").FlattenSimpleInterpolation;
5
5
  export declare const CssTransparentBlock: import("styled-components").FlattenSimpleInterpolation;
6
6
  export declare const FadeBottom: ({ height }: {
@@ -27,7 +27,11 @@ const HardOutline = (colour) => (0, styled_components_1.css) `
27
27
  drop-shadow(1px -1px 0px ${colour}) drop-shadow(-1px -1px 0px ${colour});
28
28
  `;
29
29
  exports.HardOutline = HardOutline;
30
- const Shadow = (colour) => (0, styled_components_1.css) `
30
+ const Shadow = (
31
+ /**
32
+ * colour of shadow, default #555
33
+ */
34
+ colour = '#555') => (0, styled_components_1.css) `
31
35
  filter: drop-shadow(1px 1px 0.5rem ${colour});
32
36
  `;
33
37
  exports.Shadow = Shadow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.120",
3
+ "version": "0.0.124",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
@@ -1,8 +0,0 @@
1
- /**
2
- * return a distinct array of items determined by a key function
3
- * @param data
4
- * @param key
5
- * @param ignoreEmpty
6
- */
7
- export declare function distinctBy<T, TY>(data: T[], key: (item: T) => TY, ignoreEmpty?: boolean): T[];
8
- export declare const distinct: <T>(arr: readonly T[]) => T[];
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.distinct = exports.distinctBy = void 0;
4
- /**
5
- * return a distinct array of items determined by a key function
6
- * @param data
7
- * @param key
8
- * @param ignoreEmpty
9
- */
10
- function distinctBy(data, key, ignoreEmpty) {
11
- if (!data || data.length === 0) {
12
- return data;
13
- }
14
- const hashSet = new Set();
15
- return data.filter((x) => {
16
- let keyVal;
17
- if (typeof key === 'string') {
18
- keyVal = x[key];
19
- }
20
- else {
21
- keyVal = key(x);
22
- }
23
- if (!keyVal && ignoreEmpty) {
24
- return false;
25
- }
26
- if (!hashSet.has(keyVal)) {
27
- hashSet.add(keyVal);
28
- return true;
29
- }
30
- return false;
31
- });
32
- }
33
- exports.distinctBy = distinctBy;
34
- const distinct = (arr) => [...new Set(arr)];
35
- exports.distinct = distinct;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- export declare type InputTypes = 'password' | 'email' | 'text' | 'textarea';
3
- export declare const Input: ({ label, type, placeholder, required, autoComplete, value, onChange, onKeyPress, id, disabled, className, }: {
4
- className?: string | undefined;
5
- disabled?: boolean | undefined;
6
- id?: string | undefined;
7
- label?: string | JSX.Element | undefined;
8
- type: InputTypes;
9
- placeholder?: string | undefined;
10
- required: boolean;
11
- autoComplete?: string | undefined;
12
- value: string;
13
- onChange: (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
14
- onKeyPress?: ((event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void) | undefined;
15
- }) => JSX.Element;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.Input = void 0;
26
- const styled_components_1 = __importStar(require("styled-components"));
27
- const react_1 = __importDefault(require("react"));
28
- const colours_1 = require("../../styles/colours");
29
- const inputcss = (0, styled_components_1.css) `
30
- font-size: 1.2rem;
31
- border: solid 1px ${colours_1.colours.lightCharcoal};
32
- border-radius: 0.5rem;
33
- padding: 0.5rem;
34
- width: calc(100% - 1.5rem);
35
- &:disabled {
36
- background-color: ${colours_1.colours.darker};
37
- cursor: not-allowed;
38
- }
39
- `;
40
- const SInput = styled_components_1.default.input `
41
- ${inputcss}
42
- `;
43
- const STextArea = styled_components_1.default.textarea `
44
- ${inputcss};
45
- resize: none;
46
- overflow-y: auto;
47
- `;
48
- const Input = ({ label, type, placeholder, required, autoComplete, value, onChange, onKeyPress, id, disabled, className, }) => {
49
- return (react_1.default.createElement(react_1.default.Fragment, null,
50
- id && label ? react_1.default.createElement("label", { htmlFor: id }, label) : '',
51
- type === 'textarea' && (react_1.default.createElement(STextArea, { className: className, disabled: disabled, id: id, placeholder: placeholder, required: required, autoComplete: autoComplete, value: value, onChange: onChange, onKeyPress: onKeyPress })),
52
- type !== 'textarea' && (react_1.default.createElement(SInput, { className: className, disabled: disabled, id: id, type: type, placeholder: placeholder, required: required, autoComplete: autoComplete, value: value, onChange: onChange, onKeyPress: onKeyPress }))));
53
- };
54
- exports.Input = Input;