@gisce/react-ooui 1.2.7 → 1.2.8
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/dist/helpers/formHelper.d.ts +2 -0
- package/dist/helpers/formHelper.d.ts.map +1 -1
- package/dist/react-ooui.es.js +1328 -1305
- package/dist/react-ooui.es.js.map +1 -1
- package/dist/react-ooui.umd.js +12 -12
- package/dist/react-ooui.umd.js.map +1 -1
- package/dist/widgets/custom/Tag.d.ts.map +1 -1
- package/dist/widgets/views/Tree.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/helpers/formHelper.ts +45 -0
- package/src/widgets/custom/Tag.tsx +12 -3
- package/src/widgets/views/Tree.tsx +2 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tag.d.ts","sourceRoot":"","sources":["Tag.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Tag.d.ts","sourceRoot":"","sources":["Tag.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAKtC,eAAO,MAAM,GAAG,UAAW,WAAW,sBAMrC,CAAC;AAEF,eAAO,MAAM,QAAQ,UAAW,GAAG,6BAiBlC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["Tree.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AAKvE,OAAO,EAAE,QAAQ,EAAU,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["Tree.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AAKvE,OAAO,EAAE,QAAQ,EAAU,MAAM,SAAS,CAAC;AAwB3C,aAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAChE,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7C,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IACtC,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,wBAAwB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AA8GF,iBAAS,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,YAAY,CA4M9C;AAED,eAAe,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -248,6 +248,7 @@ export const transformPlainMany2Ones = ({
|
|
|
248
248
|
|
|
249
249
|
export const colorFromString = (text: string) => {
|
|
250
250
|
let hash = 0;
|
|
251
|
+
text = text.toString().padEnd(10, '0');
|
|
251
252
|
for (let i = 0; i < text.length; i++) {
|
|
252
253
|
hash = text.charCodeAt(i) + ((hash << 5) - hash);
|
|
253
254
|
}
|
|
@@ -258,3 +259,47 @@ export const colorFromString = (text: string) => {
|
|
|
258
259
|
}
|
|
259
260
|
return hexColour;
|
|
260
261
|
}
|
|
262
|
+
|
|
263
|
+
export const colorTextFromBackground = (color: string) => {
|
|
264
|
+
function getRGB(c: string): number {
|
|
265
|
+
return parseInt(c, 16) || parseInt(c)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function getsRGB(c: string ) {
|
|
269
|
+
return getRGB(c) / 255 <= 0.03928
|
|
270
|
+
? getRGB(c) / 255 / 12.92
|
|
271
|
+
: Math.pow((getRGB(c) / 255 + 0.055) / 1.055, 2.4)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function getLuminance(hexColor: string) {
|
|
275
|
+
return (
|
|
276
|
+
0.2126 * getsRGB(hexColor.substr(1, 2)) +
|
|
277
|
+
0.7152 * getsRGB(hexColor.substr(3, 2)) +
|
|
278
|
+
0.0722 * getsRGB(hexColor.substr(-2))
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function getContrast(f: string, b: string) {
|
|
283
|
+
const L1 = getLuminance(f)
|
|
284
|
+
const L2 = getLuminance(b)
|
|
285
|
+
return (Math.max(L1, L2) + 0.05) / (Math.min(L1, L2) + 0.05)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function getTextColor(bgColor: string) {
|
|
289
|
+
const whiteContrast = getContrast(bgColor, '#ffffff')
|
|
290
|
+
const blackContrast = getContrast(bgColor, '#000000')
|
|
291
|
+
|
|
292
|
+
return whiteContrast > blackContrast ? '#ffffff' : '#000000'
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return getTextColor(color);
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export const colorsFromString = (text: string): any => {
|
|
300
|
+
const backgroundColor = colorFromString(text)
|
|
301
|
+
return {
|
|
302
|
+
backgroundColor,
|
|
303
|
+
textColor: colorTextFromBackground(backgroundColor)
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -2,7 +2,8 @@ import React from "react";
|
|
|
2
2
|
import Field from "@/common/Field";
|
|
3
3
|
import { WidgetProps } from "@/types";
|
|
4
4
|
import { Tag as AntdTag } from 'antd';
|
|
5
|
-
import {
|
|
5
|
+
import { isPresetStatusColor } from 'antd/lib/_util/colors'
|
|
6
|
+
import { colorFromString, colorTextFromBackground } from "@/helpers/formHelper";
|
|
6
7
|
|
|
7
8
|
export const Tag = (props: WidgetProps) => {
|
|
8
9
|
return (
|
|
@@ -14,11 +15,19 @@ export const Tag = (props: WidgetProps) => {
|
|
|
14
15
|
|
|
15
16
|
export const TagInput = (props: any) => {
|
|
16
17
|
const {ooui, value} = props;
|
|
18
|
+
let formattedValue = value;
|
|
19
|
+
let colorValue = value;
|
|
20
|
+
if (ooui.selectionValues.size) {
|
|
21
|
+
formattedValue = ooui.selectionValues.get(value);
|
|
22
|
+
} else if (Array.isArray(value)) {
|
|
23
|
+
colorValue = value[0];
|
|
24
|
+
formattedValue = value[1];
|
|
25
|
+
}
|
|
17
26
|
if (!value) {
|
|
18
27
|
return null
|
|
19
28
|
}
|
|
20
|
-
const color = ooui.colors === "auto" ? colorFromString(
|
|
29
|
+
const color = ooui.colors === "auto" ? colorFromString(colorValue) : ooui.colors[colorValue] || colorFromString(colorValue);
|
|
21
30
|
return (
|
|
22
|
-
<AntdTag color={color}
|
|
31
|
+
<AntdTag color={color} style={isPresetStatusColor(color) ? {} : {color: colorTextFromBackground(color)}}>{formattedValue}</AntdTag>
|
|
23
32
|
);
|
|
24
33
|
}
|
|
@@ -24,6 +24,7 @@ import { Many2oneTree } from "../base/many2one/Many2oneTree";
|
|
|
24
24
|
import { ReferenceTree } from "../base/ReferenceTree";
|
|
25
25
|
import dayjs from "dayjs";
|
|
26
26
|
import Avatar from "../custom/Avatar";
|
|
27
|
+
import { TagInput } from "../custom/Tag";
|
|
27
28
|
import { DatePickerConfig } from "@/common/DatePicker";
|
|
28
29
|
|
|
29
30
|
type Props = {
|
|
@@ -120,11 +121,7 @@ value: any,
|
|
|
120
121
|
ooui: any,
|
|
121
122
|
context: any
|
|
122
123
|
): React.ReactElement => {
|
|
123
|
-
return
|
|
124
|
-
<>
|
|
125
|
-
{value ? <Tag color={ooui.colors[value]}>{ooui.selectionValues.get(value)}</Tag> : null}
|
|
126
|
-
</>
|
|
127
|
-
);
|
|
124
|
+
return <TagInput ooui={ooui} value={value} />
|
|
128
125
|
};
|
|
129
126
|
|
|
130
127
|
const SelectionComponent = (
|