@gpa-gemstone/react-forms 1.1.50 → 1.1.52

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.
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { ColorResult } from 'react-color';
3
+ interface IProps {
4
+ CurrentColor: string;
5
+ Colors: string[];
6
+ OnColorChange: (updatedColor: ColorResult) => void;
7
+ Triangle?: ('hide' | 'top');
8
+ BtnText?: string;
9
+ }
10
+ declare const ColorPicker: React.FunctionComponent<IProps>;
11
+ export default ColorPicker;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ //******************************************************************************************************
3
+ // ColorPicker.tsx - Gbtc
4
+ //
5
+ // Copyright © 2023, Grid Protection Alliance. All Rights Reserved.
6
+ //
7
+ // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
+ // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
+ // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
+ // file except in compliance with the License. You may obtain a copy of the License at:
11
+ //
12
+ // http://opensource.org/licenses/MIT
13
+ //
14
+ // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
+ // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
+ // License for the specific language governing permissions and limitations.
17
+ //
18
+ // Code Modification History:
19
+ // ----------------------------------------------------------------------------------------------------
20
+ // 03/05/2024 - Preston Crawford
21
+ // Generated original version of source code.
22
+ //
23
+ //******************************************************************************************************
24
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
25
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
26
+ return cooked;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ var React = require("react");
30
+ var react_color_1 = require("react-color");
31
+ var styled_components_1 = require("styled-components");
32
+ var helper_functions_1 = require("@gpa-gemstone/helper-functions");
33
+ var react_portal_1 = require("react-portal");
34
+ var WrapperDiv = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px;\n position: fixed;\n transition: opacity 0.3s ease-out;\n z-index: 99999;\n pointer-events: ", ";\n opacity: ", ";\n color: #fff; // Dark theme color\n background: #222; // Dark theme background\n top: ", ";\n left: ", ";\n border: 1px solid transparent;\n }\n"], ["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px;\n position: fixed;\n transition: opacity 0.3s ease-out;\n z-index: 99999;\n pointer-events: ", ";\n opacity: ", ";\n color: #fff; // Dark theme color\n background: #222; // Dark theme background\n top: ", ";\n left: ", ";\n border: 1px solid transparent;\n }\n"])), function (props) { return props.Show ? 'auto' : 'none'; }, function (props) { return props.Show ? "0.9" : "0"; }, function (props) { return props.Top + "px"; }, function (props) { return props.Left + "px"; });
35
+ var ColorPicker = function (props) {
36
+ var toolTip = React.useRef(null);
37
+ var _a = React.useState(0), top = _a[0], setTop = _a[1];
38
+ var _b = React.useState(0), left = _b[0], setLeft = _b[1];
39
+ var _c = React.useState(0), targetLeft = _c[0], setTargetLeft = _c[1];
40
+ var _d = React.useState(0), targetTop = _d[0], setTargetTop = _d[1];
41
+ var _e = React.useState(0), targetWidth = _e[0], setTargetWidth = _e[1];
42
+ var _f = React.useState(0), targetHeight = _f[0], setTargetHeight = _f[1];
43
+ var _g = React.useState(false), show = _g[0], setShow = _g[1];
44
+ React.useEffect(function () {
45
+ var target = document.querySelectorAll("[data-tooltip" + "=\"color-picker\"" + "]");
46
+ if (target.length === 0) {
47
+ setTargetHeight(0);
48
+ setTargetWidth(0);
49
+ setTargetLeft(-999);
50
+ setTargetTop(-999);
51
+ }
52
+ else {
53
+ var targetLocation = (0, helper_functions_1.GetNodeSize)(target[0]);
54
+ setTargetHeight(targetLocation.height);
55
+ setTargetWidth(targetLocation.width);
56
+ setTargetLeft(targetLocation.left);
57
+ setTargetTop(targetLocation.top);
58
+ }
59
+ }, []);
60
+ React.useLayoutEffect(function () {
61
+ var _a = UpdatePosition(), t = _a[0], l = _a[1];
62
+ setTop(t);
63
+ setLeft(l);
64
+ });
65
+ function UpdatePosition() {
66
+ if (toolTip.current === null)
67
+ return [-999, -999];
68
+ var colorPickerHeight = 280;
69
+ var colorPickerWidth = 180;
70
+ var tipLocation = (0, helper_functions_1.GetNodeSize)(toolTip.current);
71
+ var windowHeight = window.innerHeight;
72
+ var windowWidth = window.innerWidth;
73
+ var result = [0, 0];
74
+ //start by placing at the bottom of the button and rotating counter clockwise until there is enough space to fit the colorpicker
75
+ result[0] = targetTop + targetHeight;
76
+ result[1] = targetLeft + 0.5 * targetWidth - 0.5 * tipLocation.width;
77
+ //try to place colorpicker to the right of the button if there isnt enough room below
78
+ if (windowHeight - result[0] < colorPickerHeight) {
79
+ result[0] = targetTop + 0.5 * targetHeight - 0.5 * tipLocation.height;
80
+ result[1] = targetLeft + targetWidth;
81
+ //try to place colorpicker on the top of the button if there isnt enough room to the right
82
+ if (windowWidth - result[1] < colorPickerWidth) {
83
+ result[0] = targetTop - tipLocation.height;
84
+ result[1] = targetLeft + 0.5 * targetWidth - 0.5 * tipLocation.width;
85
+ //move colorpicker to the left of the button if there isnt enough space on the top
86
+ if (result[0] < 0) {
87
+ result[0] = targetTop + 0.5 * targetHeight - 0.5 * tipLocation.height;
88
+ result[1] = targetLeft - tipLocation.width;
89
+ }
90
+ }
91
+ }
92
+ return result;
93
+ }
94
+ return (React.createElement(React.Fragment, null,
95
+ React.createElement("button", { className: "btn btn-block", "data-tooltip": "color-picker", onMouseOver: function () { return setShow(true); }, onMouseOut: function () { return setShow(false); }, style: { backgroundColor: props.CurrentColor, borderColor: props.CurrentColor } }, props.BtnText ? props.BtnText : "Color"),
96
+ React.createElement(react_portal_1.Portal, null,
97
+ React.createElement(WrapperDiv, { Show: show, Top: top, Left: left, ref: toolTip, onMouseOver: function () { return setShow(true); }, onMouseOut: function () { return setShow(false); } },
98
+ React.createElement(react_color_1.BlockPicker, { color: props.CurrentColor, colors: props.Colors, onChangeComplete: function (updatedColor) {
99
+ props.OnColorChange(updatedColor);
100
+ }, triangle: props.Triangle ? props.Triangle : 'hide' })))));
101
+ };
102
+ exports.default = ColorPicker;
103
+ var templateObject_1;
package/lib/index.d.ts CHANGED
@@ -11,4 +11,5 @@ import MultiCheckBoxSelect from './MutliCheckBoxSelect';
11
11
  import DoubleInput from './DoubleInput';
12
12
  import TimePicker from './TimePicker';
13
13
  import StylableSelect from './StylableSelect';
14
- export { CheckBox, Input, DatePicker, Select, TextArea, DateRangePicker, EnumCheckBoxes, ArrayMultiSelect, ArrayCheckBoxes, MultiCheckBoxSelect, DoubleInput, TimePicker, StylableSelect };
14
+ import ColorPicker from './ColorPicker';
15
+ export { CheckBox, Input, DatePicker, Select, TextArea, DateRangePicker, EnumCheckBoxes, ArrayMultiSelect, ArrayCheckBoxes, MultiCheckBoxSelect, DoubleInput, TimePicker, StylableSelect, ColorPicker };
package/lib/index.js CHANGED
@@ -22,7 +22,7 @@
22
22
  //
23
23
  // ******************************************************************************************************
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.StylableSelect = exports.TimePicker = exports.DoubleInput = exports.MultiCheckBoxSelect = exports.ArrayCheckBoxes = exports.ArrayMultiSelect = exports.EnumCheckBoxes = exports.DateRangePicker = exports.TextArea = exports.Select = exports.DatePicker = exports.Input = exports.CheckBox = void 0;
25
+ exports.ColorPicker = exports.StylableSelect = exports.TimePicker = exports.DoubleInput = exports.MultiCheckBoxSelect = exports.ArrayCheckBoxes = exports.ArrayMultiSelect = exports.EnumCheckBoxes = exports.DateRangePicker = exports.TextArea = exports.Select = exports.DatePicker = exports.Input = exports.CheckBox = void 0;
26
26
  var CheckBox_1 = require("./CheckBox");
27
27
  exports.CheckBox = CheckBox_1.default;
28
28
  var Input_1 = require("./Input");
@@ -49,3 +49,5 @@ var TimePicker_1 = require("./TimePicker");
49
49
  exports.TimePicker = TimePicker_1.default;
50
50
  var StylableSelect_1 = require("./StylableSelect");
51
51
  exports.StylableSelect = StylableSelect_1.default;
52
+ var ColorPicker_1 = require("./ColorPicker");
53
+ exports.ColorPicker = ColorPicker_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-forms",
3
- "version": "1.1.50",
3
+ "version": "1.1.52",
4
4
  "description": "React Form modules for gpa webapps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -33,6 +33,7 @@
33
33
  "homepage": "https://github.com/GridProtectionAlliance/gpa-gemstone#readme",
34
34
  "devDependencies": {
35
35
  "@types/jest": "^27.0.0",
36
+ "@types/react-color": "^3.0.12",
36
37
  "@types/react-portal": "4.0.4",
37
38
  "@typescript-eslint/eslint-plugin": "^5.60.0",
38
39
  "@typescript-eslint/parser": "^5.60.0",
@@ -43,11 +44,12 @@
43
44
  "typescript": "4.4.4"
44
45
  },
45
46
  "dependencies": {
46
- "@gpa-gemstone/helper-functions": "0.0.27",
47
+ "@gpa-gemstone/helper-functions": "0.0.28",
47
48
  "@types/react": "^17.0.14",
48
49
  "@types/styled-components": "^5.1.11",
49
50
  "moment": "2.29.4",
50
51
  "react": "^18.2.0",
52
+ "react-color": "^2.19.3",
51
53
  "react-portal": "4.2.2",
52
54
  "styled-components": "5.3.3"
53
55
  },