@babylonjs/shared-ui-components 8.16.0 → 8.16.1
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/fluent/hoc/dropdownPropertyLine.d.ts +0 -1
- package/fluent/hoc/dropdownPropertyLine.js +1 -1
- package/fluent/hoc/dropdownPropertyLine.js.map +1 -1
- package/fluent/hoc/gradientList.d.ts +14 -0
- package/fluent/hoc/gradientList.js +76 -0
- package/fluent/hoc/gradientList.js.map +1 -0
- package/fluent/hoc/inputPropertyLine.d.ts +11 -1
- package/fluent/hoc/inputPropertyLine.js +9 -7
- package/fluent/hoc/inputPropertyLine.js.map +1 -1
- package/fluent/primitives/colorPicker.js +1 -1
- package/fluent/primitives/colorPicker.js.map +1 -1
- package/fluent/primitives/gradient.d.ts +28 -0
- package/fluent/primitives/gradient.js +86 -0
- package/fluent/primitives/gradient.js.map +1 -0
- package/fluent/primitives/input.d.ts +2 -6
- package/fluent/primitives/input.js +10 -7
- package/fluent/primitives/input.js.map +1 -1
- package/fluent/primitives/list.d.ts +26 -0
- package/fluent/primitives/list.js +43 -0
- package/fluent/primitives/list.js.map +1 -0
- package/fluent/primitives/messageBar.js +2 -2
- package/fluent/primitives/messageBar.js.map +1 -1
- package/fluent/primitives/syncedSlider.d.ts +6 -1
- package/fluent/primitives/syncedSlider.js +28 -11
- package/fluent/primitives/syncedSlider.js.map +1 -1
- package/lines/optionsLineComponent.d.ts +1 -1
- package/lines/optionsLineComponent.js.map +1 -1
- package/lines/textInputLineComponent.js +2 -2
- package/lines/textInputLineComponent.js.map +1 -1
- package/package.json +1 -1
- package/components/lines/ColorLineComponent.d.ts +0 -38
- package/components/lines/ColorLineComponent.js +0 -147
- package/components/lines/ColorLineComponent.js.map +0 -1
- package/components/lines/ColorLineComponent.module.scss +0 -67
- package/lines/iconButtonLineComponent.d.ts +0 -11
- package/lines/iconButtonLineComponent.js +0 -11
- package/lines/iconButtonLineComponent.js.map +0 -1
@@ -3,7 +3,6 @@ import type { AcceptedDropdownValue, DropdownProps } from "../primitives/dropdow
|
|
3
3
|
import type { PropertyLineProps } from "./propertyLine.js";
|
4
4
|
import type { FunctionComponent } from "react";
|
5
5
|
type DropdownPropertyLineProps<V extends AcceptedDropdownValue> = Omit<DropdownProps<V>, "includeNullAs"> & PropertyLineProps;
|
6
|
-
export declare const NullableDropdownPropertyLine: FunctionComponent<DropdownPropertyLineProps<AcceptedDropdownValue>>;
|
7
6
|
/**
|
8
7
|
* Dropdown component for explicitly defined number values.
|
9
8
|
* If value can be undefined, use OptionalNumberDropdownPropertyLine instead.
|
@@ -9,7 +9,7 @@ import { PropertyLine } from "./propertyLine.js";
|
|
9
9
|
const DropdownPropertyLine = (props) => {
|
10
10
|
return (_jsx(PropertyLine, { ...props, children: _jsx(Dropdown, { ...props }) }));
|
11
11
|
};
|
12
|
-
|
12
|
+
const NullableDropdownPropertyLine = (props) => _jsx(DropdownPropertyLine, { ...props, includeNullAs: "null" });
|
13
13
|
const OptionalDropdownPropertyLine = (props) => _jsx(DropdownPropertyLine, { ...props, includeNullAs: "undefined" });
|
14
14
|
/**
|
15
15
|
* Dropdown component for explicitly defined number values.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"dropdownPropertyLine.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/hoc/dropdownPropertyLine.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAM9C;;;;GAIG;AACH,MAAM,oBAAoB,GAAgF,CAAC,KAAK,EAAE,EAAE;IAChH,OAAO,CACH,KAAC,YAAY,OAAK,KAAK,YACnB,KAAC,QAAQ,OAAK,KAAK,GAAI,GACZ,CAClB,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,
|
1
|
+
{"version":3,"file":"dropdownPropertyLine.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/hoc/dropdownPropertyLine.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAM9C;;;;GAIG;AACH,MAAM,oBAAoB,GAAgF,CAAC,KAAK,EAAE,EAAE;IAChH,OAAO,CACH,KAAC,YAAY,OAAK,KAAK,YACnB,KAAC,QAAQ,OAAK,KAAK,GAAI,GACZ,CAClB,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAAwE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAC,oBAAoB,OAAK,KAAK,EAAE,aAAa,EAAC,MAAM,GAAG,CAAC;AAC9K,MAAM,4BAA4B,GAAwE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAC,oBAAoB,OAAK,KAAK,EAAE,aAAa,EAAC,WAAW,GAAG,CAAC;AAEnL;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,oBAA4E,CAAC;AACvH;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,oBAA4E,CAAC;AAEvH;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,4BAA8F,CAAC;AACjJ;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,4BAA8F,CAAC;AAEjJ;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,4BAAgG,CAAC;AACnJ;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,4BAAgG,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Dropdown } from \"../primitives/dropdown\";\r\nimport type { AcceptedDropdownValue, DropdownProps } from \"../primitives/dropdown\";\r\nimport { PropertyLine } from \"./propertyLine\";\r\nimport type { PropertyLineProps } from \"./propertyLine\";\r\nimport type { FunctionComponent } from \"react\";\r\n\r\ntype DropdownPropertyLineProps<V extends AcceptedDropdownValue> = Omit<DropdownProps<V>, \"includeNullAs\"> & PropertyLineProps;\r\n\r\n/**\r\n * Wraps a dropdown in a property line\r\n * @param props - PropertyLineProps and DropdownProps\r\n * @returns property-line wrapped dropdown\r\n */\r\nconst DropdownPropertyLine: FunctionComponent<DropdownProps<AcceptedDropdownValue> & PropertyLineProps> = (props) => {\r\n return (\r\n <PropertyLine {...props}>\r\n <Dropdown {...props} />\r\n </PropertyLine>\r\n );\r\n};\r\n\r\nconst NullableDropdownPropertyLine: FunctionComponent<DropdownPropertyLineProps<AcceptedDropdownValue>> = (props) => <DropdownPropertyLine {...props} includeNullAs=\"null\" />;\r\nconst OptionalDropdownPropertyLine: FunctionComponent<DropdownPropertyLineProps<AcceptedDropdownValue>> = (props) => <DropdownPropertyLine {...props} includeNullAs=\"undefined\" />;\r\n\r\n/**\r\n * Dropdown component for explicitly defined number values.\r\n * If value can be undefined, use OptionalNumberDropdownPropertyLine instead.\r\n * If value can be null, use NullableNumberDropdownPropertyLine instead.\r\n */\r\nexport const NumberDropdownPropertyLine = DropdownPropertyLine as FunctionComponent<DropdownPropertyLineProps<number>>;\r\n/**\r\n * Dropdown component for explicitly defined string values.\r\n * If value can be undefined, use OptionalStringDropdownPropertyLine instead.\r\n * If value can be null, use NullableStringDropdownPropertyLine instead.\r\n */\r\nexport const StringDropdownPropertyLine = DropdownPropertyLine as FunctionComponent<DropdownPropertyLineProps<string>>;\r\n\r\n/**\r\n * Dropdown component for Nullable<number> values.\r\n */\r\nexport const NullableNumberDropdownPropertyLine = NullableDropdownPropertyLine as FunctionComponent<DropdownPropertyLineProps<Nullable<number>>>;\r\n/**\r\n * Dropdown component for Nullable<string> values.\r\n */\r\nexport const NullableStringDropdownPropertyLine = NullableDropdownPropertyLine as FunctionComponent<DropdownPropertyLineProps<Nullable<string>>>;\r\n\r\n/**\r\n * Dropdown component for number | undefined values\r\n */\r\nexport const OptionalNumberDropdownPropertyLine = OptionalDropdownPropertyLine as FunctionComponent<DropdownPropertyLineProps<number | undefined>>;\r\n/**\r\n * Dropdown component for string | undefined values\r\n */\r\nexport const OptionalStringDropdownPropertyLine = OptionalDropdownPropertyLine as FunctionComponent<DropdownPropertyLineProps<string | undefined>>;\r\n"]}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { FunctionComponent } from "react";
|
2
|
+
import { Color3Gradient, ColorGradient as Color4Gradient, FactorGradient } from "@babylonjs/core/Misc/gradients.js";
|
3
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
4
|
+
type GradientListProps<T extends FactorGradient | Color3Gradient | Color4Gradient> = {
|
5
|
+
label: string;
|
6
|
+
gradients: Nullable<Array<T>>;
|
7
|
+
addGradient: (step?: T) => void;
|
8
|
+
removeGradient: (step: T) => void;
|
9
|
+
onChange: (newGradient: T) => void;
|
10
|
+
};
|
11
|
+
export declare const FactorGradientList: FunctionComponent<GradientListProps<FactorGradient>>;
|
12
|
+
export declare const Color3GradientList: FunctionComponent<GradientListProps<Color3Gradient>>;
|
13
|
+
export declare const Color4GradientList: FunctionComponent<GradientListProps<Color4Gradient>>;
|
14
|
+
export {};
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { List } from "../primitives/list.js";
|
3
|
+
import { Color3GradientComponent, Color4GradientComponent, FactorGradientComponent } from "../primitives/gradient.js";
|
4
|
+
import { Color3Gradient, ColorGradient as Color4Gradient, FactorGradient } from "@babylonjs/core/Misc/gradients.js";
|
5
|
+
import { Color3, Color4 } from "@babylonjs/core/Maths/math.color.js";
|
6
|
+
// Convert gradients to LineList items and sort by gradient value
|
7
|
+
function GradientsToListItems(gradients) {
|
8
|
+
return (gradients?.map((gradient, index) => ({
|
9
|
+
id: index,
|
10
|
+
data: gradient,
|
11
|
+
sortBy: gradient.gradient,
|
12
|
+
})) ?? []);
|
13
|
+
}
|
14
|
+
const GradientList = (props) => {
|
15
|
+
const { gradients, type } = props;
|
16
|
+
const items = GradientsToListItems(gradients);
|
17
|
+
const deleteStep = (step) => {
|
18
|
+
props.removeGradient(step);
|
19
|
+
};
|
20
|
+
const addNewStep = () => {
|
21
|
+
if (items.length === 0) {
|
22
|
+
props.addGradient(); // Default
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
switch (props.type) {
|
26
|
+
case "Factor": {
|
27
|
+
const newStep = new FactorGradient(1, 1, 1);
|
28
|
+
props.addGradient(newStep);
|
29
|
+
break;
|
30
|
+
}
|
31
|
+
case "Color3": {
|
32
|
+
const newStepColor3 = new Color3Gradient(1, Color3.White());
|
33
|
+
props.addGradient(newStepColor3);
|
34
|
+
break;
|
35
|
+
}
|
36
|
+
case "Color4": {
|
37
|
+
const newStepColor = new Color4Gradient(1, new Color4(1, 1, 1, 1), new Color4(1, 1, 1, 1));
|
38
|
+
props.addGradient(newStepColor);
|
39
|
+
break;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
};
|
44
|
+
return (_jsx("div", { children: _jsx(List, { addButtonLabel: items.length > 0 ? `Add new ${props.label}` : `Use ${props.label}s`, items: items, onDelete: (item) => deleteStep(item.data), onAdd: addNewStep, renderItem: (item) => {
|
45
|
+
const gradient = item.data;
|
46
|
+
switch (props.type) {
|
47
|
+
case "Factor":
|
48
|
+
return (_jsx(FactorGradientComponent, { value: gradient, onChange: (newGradient) => {
|
49
|
+
item.data.gradient = newGradient.gradient;
|
50
|
+
item.data.factor1 = newGradient.factor1;
|
51
|
+
item.data.factor2 = newGradient.factor2;
|
52
|
+
props.onChange(newGradient);
|
53
|
+
} }));
|
54
|
+
case "Color3":
|
55
|
+
return (_jsx(Color3GradientComponent, { value: gradient, onChange: (newGradient) => {
|
56
|
+
item.data.gradient = newGradient.gradient;
|
57
|
+
item.data.color = newGradient.color;
|
58
|
+
props.onChange(newGradient);
|
59
|
+
} }));
|
60
|
+
case "Color4":
|
61
|
+
return (_jsx(Color4GradientComponent, { value: gradient, onChange: (newGradient) => {
|
62
|
+
item.data.gradient = newGradient.gradient;
|
63
|
+
item.data.color1 = newGradient.color1;
|
64
|
+
item.data.color2 = newGradient.color2;
|
65
|
+
props.onChange(newGradient);
|
66
|
+
} }));
|
67
|
+
}
|
68
|
+
} }, type) }));
|
69
|
+
};
|
70
|
+
const FactorGradientCast = GradientList;
|
71
|
+
const Color3GradientCast = GradientList;
|
72
|
+
const Color4GradientCast = GradientList;
|
73
|
+
export const FactorGradientList = (props) => _jsx(FactorGradientCast, { ...props, type: "Factor" });
|
74
|
+
export const Color3GradientList = (props) => _jsx(Color3GradientCast, { ...props, type: "Color3" });
|
75
|
+
export const Color4GradientList = (props) => _jsx(Color4GradientCast, { ...props, type: "Color4" });
|
76
|
+
//# sourceMappingURL=gradientList.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"gradientList.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/hoc/gradientList.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACnH,OAAO,EAAE,cAAc,EAAE,aAAa,IAAI,cAAc,EAAE,cAAc,EAAE,0CAA4B;AAGtG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,4CAA8B;AAYvD,iEAAiE;AACjE,SAAS,oBAAoB,CAAC,SAA0C;IACpE,OAAO,CACH,SAAS,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACjC,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,QAAQ,CAAC,QAAQ;KAC5B,CAAC,CAAC,IAAI,EAAE,CACZ,CAAC;AACN,CAAC;AAED,MAAM,YAAY,GAAqH,CAAC,KAAK,EAAE,EAAE;IAC7I,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAClC,MAAM,KAAK,GAAG,oBAAoB,CAAC,SAA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,CAAC,QAAQ,CAAC;gCAC1C,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;gCACtC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;gCACtC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;4BAChC,CAAC,GACH,CACL,CAAC;gBACV,CAAC;YACL,CAAC,IA7CI,IAAI,CA8CX,GACA,CACT,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,YAAyF,CAAC;AACrH,MAAM,kBAAkB,GAAG,YAAyF,CAAC;AACrH,MAAM,kBAAkB,GAAG,YAAyF,CAAC;AAErH,MAAM,CAAC,MAAM,kBAAkB,GAAyD,CAAC,KAAK,EAAE,EAAE,CAAC,KAAC,kBAAkB,OAAK,KAAK,EAAE,IAAI,EAAC,QAAQ,GAAG,CAAC;AACnJ,MAAM,CAAC,MAAM,kBAAkB,GAAyD,CAAC,KAAK,EAAE,EAAE,CAAC,KAAC,kBAAkB,OAAK,KAAK,EAAE,IAAI,EAAC,QAAQ,GAAG,CAAC;AACnJ,MAAM,CAAC,MAAM,kBAAkB,GAAyD,CAAC,KAAK,EAAE,EAAE,CAAC,KAAC,kBAAkB,OAAK,KAAK,EAAE,IAAI,EAAC,QAAQ,GAAG,CAAC","sourcesContent":["import type { FunctionComponent } from \"react\";\r\n\r\nimport { List } from \"../primitives/list\";\r\nimport { Color3GradientComponent, Color4GradientComponent, FactorGradientComponent } from \"../primitives/gradient\";\r\nimport { Color3Gradient, ColorGradient as Color4Gradient, FactorGradient } from \"core/Misc/gradients\";\r\nimport type { IValueGradient } from \"core/Misc/gradients\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\n\r\ntype GradientTypes = \"Factor\" | \"Color3\" | \"Color4\";\r\n\r\ntype GradientListProps<T extends FactorGradient | Color3Gradient | Color4Gradient> = {\r\n label: string;\r\n gradients: Nullable<Array<T>>;\r\n addGradient: (step?: T) => void;\r\n removeGradient: (step: T) => void;\r\n onChange: (newGradient: T) => void;\r\n};\r\n\r\n// Convert gradients to LineList items and sort by gradient value\r\nfunction GradientsToListItems(gradients: Nullable<Array<IValueGradient>>) {\r\n return (\r\n gradients?.map((gradient, index) => ({\r\n id: index,\r\n data: gradient,\r\n sortBy: gradient.gradient,\r\n })) ?? []\r\n );\r\n}\r\n\r\nconst GradientList: FunctionComponent<GradientListProps<FactorGradient | Color3Gradient | Color4Gradient> & { type: GradientTypes }> = (props) => {\r\n const { gradients, type } = props;\r\n const items = GradientsToListItems(gradients);\r\n\r\n const deleteStep = (step: FactorGradient | Color3Gradient | Color4Gradient) => {\r\n props.removeGradient(step);\r\n };\r\n\r\n const addNewStep = () => {\r\n if (items.length === 0) {\r\n props.addGradient(); // Default\r\n } else {\r\n switch (props.type) {\r\n case \"Factor\": {\r\n const newStep = new FactorGradient(1, 1, 1);\r\n props.addGradient(newStep);\r\n break;\r\n }\r\n case \"Color3\": {\r\n const newStepColor3 = new Color3Gradient(1, Color3.White());\r\n props.addGradient(newStepColor3);\r\n break;\r\n }\r\n case \"Color4\": {\r\n const newStepColor = new Color4Gradient(1, new Color4(1, 1, 1, 1), new Color4(1, 1, 1, 1));\r\n props.addGradient(newStepColor);\r\n break;\r\n }\r\n }\r\n }\r\n };\r\n\r\n return (\r\n <div>\r\n <List\r\n key={type}\r\n addButtonLabel={items.length > 0 ? `Add new ${props.label}` : `Use ${props.label}s`}\r\n items={items}\r\n onDelete={(item) => deleteStep(item.data)}\r\n onAdd={addNewStep}\r\n renderItem={(item) => {\r\n const gradient = item.data;\r\n switch (props.type) {\r\n case \"Factor\":\r\n return (\r\n <FactorGradientComponent\r\n value={gradient}\r\n onChange={(newGradient: FactorGradient) => {\r\n item.data.gradient = newGradient.gradient;\r\n item.data.factor1 = newGradient.factor1;\r\n item.data.factor2 = newGradient.factor2;\r\n props.onChange(newGradient);\r\n }}\r\n />\r\n );\r\n\r\n case \"Color3\":\r\n return (\r\n <Color3GradientComponent\r\n value={gradient}\r\n onChange={(newGradient: Color3Gradient) => {\r\n item.data.gradient = newGradient.gradient;\r\n item.data.color = newGradient.color;\r\n props.onChange(newGradient);\r\n }}\r\n />\r\n );\r\n case \"Color4\":\r\n return (\r\n <Color4GradientComponent\r\n value={gradient}\r\n onChange={(newGradient: Color4Gradient) => {\r\n item.data.gradient = newGradient.gradient;\r\n item.data.color1 = newGradient.color1;\r\n item.data.color2 = newGradient.color2;\r\n props.onChange(newGradient);\r\n }}\r\n />\r\n );\r\n }\r\n }}\r\n />\r\n </div>\r\n );\r\n};\r\n\r\nconst FactorGradientCast = GradientList as FunctionComponent<GradientListProps<FactorGradient> & { type: \"Factor\" }>;\r\nconst Color3GradientCast = GradientList as FunctionComponent<GradientListProps<Color3Gradient> & { type: \"Color3\" }>;\r\nconst Color4GradientCast = GradientList as FunctionComponent<GradientListProps<Color4Gradient> & { type: \"Color4\" }>;\r\n\r\nexport const FactorGradientList: FunctionComponent<GradientListProps<FactorGradient>> = (props) => <FactorGradientCast {...props} type=\"Factor\" />;\r\nexport const Color3GradientList: FunctionComponent<GradientListProps<Color3Gradient>> = (props) => <Color3GradientCast {...props} type=\"Color3\" />;\r\nexport const Color4GradientList: FunctionComponent<GradientListProps<Color4Gradient>> = (props) => <Color4GradientCast {...props} type=\"Color4\" />;\r\n"]}
|
@@ -1,5 +1,15 @@
|
|
1
1
|
import type { PropertyLineProps } from "./propertyLine.js";
|
2
2
|
import type { FunctionComponent } from "react";
|
3
3
|
import type { InputProps } from "../primitives/input.js";
|
4
|
+
/**
|
5
|
+
* Wraps a text input in a property line
|
6
|
+
* @param props - PropertyLineProps and InputProps
|
7
|
+
* @returns property-line wrapped input component
|
8
|
+
*/
|
4
9
|
export declare const TextInputPropertyLine: FunctionComponent<InputProps<string> & PropertyLineProps>;
|
5
|
-
|
10
|
+
/**
|
11
|
+
* Wraps a number input in a property line
|
12
|
+
* @param props - PropertyLineProps and InputProps
|
13
|
+
* @returns property-line wrapped input component
|
14
|
+
*/
|
15
|
+
export declare const NumberInputPropertyLine: FunctionComponent<InputProps<number> & PropertyLineProps>;
|
@@ -1,14 +1,16 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { PropertyLine } from "./propertyLine.js";
|
3
|
-
import {
|
3
|
+
import { NumberInput, TextInput } from "../primitives/input.js";
|
4
4
|
/**
|
5
|
-
* Wraps
|
5
|
+
* Wraps a text input in a property line
|
6
6
|
* @param props - PropertyLineProps and InputProps
|
7
7
|
* @returns property-line wrapped input component
|
8
8
|
*/
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
export const TextInputPropertyLine = (props) => (_jsx(PropertyLine, { ...props, children: _jsx(TextInput, { ...props }) }));
|
10
|
+
/**
|
11
|
+
* Wraps a number input in a property line
|
12
|
+
* @param props - PropertyLineProps and InputProps
|
13
|
+
* @returns property-line wrapped input component
|
14
|
+
*/
|
15
|
+
export const NumberInputPropertyLine = (props) => (_jsx(PropertyLine, { ...props, children: _jsx(NumberInput, { ...props }) }));
|
14
16
|
//# sourceMappingURL=inputPropertyLine.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"inputPropertyLine.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/hoc/inputPropertyLine.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"inputPropertyLine.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/hoc/inputPropertyLine.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAG7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA8D,CAAC,KAAK,EAAE,EAAE,CAAC,CACvG,KAAC,YAAY,OAAK,KAAK,YACnB,KAAC,SAAS,OAAK,KAAK,GAAI,GACb,CAClB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA8D,CAAC,KAAK,EAAE,EAAE,CAAC,CACzG,KAAC,YAAY,OAAK,KAAK,YACnB,KAAC,WAAW,OAAK,KAAK,GAAI,GACf,CAClB,CAAC","sourcesContent":["import { PropertyLine } from \"./propertyLine\";\r\nimport type { PropertyLineProps } from \"./propertyLine\";\r\nimport type { FunctionComponent } from \"react\";\r\nimport { NumberInput, TextInput } from \"../primitives/input\";\r\nimport type { InputProps } from \"../primitives/input\";\r\n\r\n/**\r\n * Wraps a text input in a property line\r\n * @param props - PropertyLineProps and InputProps\r\n * @returns property-line wrapped input component\r\n */\r\nexport const TextInputPropertyLine: FunctionComponent<InputProps<string> & PropertyLineProps> = (props) => (\r\n <PropertyLine {...props}>\r\n <TextInput {...props} />\r\n </PropertyLine>\r\n);\r\n\r\n/**\r\n * Wraps a number input in a property line\r\n * @param props - PropertyLineProps and InputProps\r\n * @returns property-line wrapped input component\r\n */\r\nexport const NumberInputPropertyLine: FunctionComponent<InputProps<number> & PropertyLineProps> = (props) => (\r\n <PropertyLine {...props}>\r\n <NumberInput {...props} />\r\n </PropertyLine>\r\n);\r\n"]}
|
@@ -66,7 +66,7 @@ export const ColorPickerPopup = (props) => {
|
|
66
66
|
align: "start",
|
67
67
|
overflowBoundary: document.body,
|
68
68
|
autoSize: true,
|
69
|
-
}, open: popoverOpen, trapFocus: true, onOpenChange: (_, data) => setPopoverOpen(data.open), children: [_jsx(PopoverTrigger, { disableButtonEnhancement: true, children: _jsx(ColorSwatch, { size: "small", color: color.toHexString(), value: color.toHexString().slice(1) }) }), _jsx(PopoverSurface, { children: _jsxs("div", { className: classes.colorPickerContainer, children: [_jsxs(ColorPicker, { color: rgbaToHsv(color), onColorChange: handleColorPickerChange, children: [_jsx(ColorArea, { inputX: { "aria-label": "Saturation" }, inputY: { "aria-label": "Brightness" } }), _jsx(ColorSlider, { "aria-label": "Hue" }), color instanceof Color4 && _jsx(AlphaSlider, { "aria-label": "Alpha" })] }), _jsxs("div", { className: classes.container, children: [_jsxs("div", { className: classes.row, children: [_jsx("div", { className: classes.previewColor, style: { backgroundColor: color.toHexString() } }), _jsx(InputHexField, { label: "Gamma Hex", value: color, isLinearMode: props.isLinearMode, onChange: handleChange }), _jsx(InputHexField, { label: "Linear Hex", linearHex: true, isLinearMode: props.isLinearMode, value: color, onChange: handleChange })] }), _jsxs("div", { className: classes.row, children: [_jsx(InputRgbField, { label: "Red", color: color, rgbKey: "r", onChange: handleChange }), _jsx(InputRgbField, { label: "Green", color: color, rgbKey: "g", onChange: handleChange }), _jsx(InputRgbField, { label: "Blue", color: color, rgbKey: "b", onChange: handleChange }), _jsx(InputAlphaField, { color: color, onChange: handleChange })] }), _jsxs("div", { className: classes.row, children: [_jsx(InputHsvField, { label: "Hue", color: color, hsvKey: "h", max: 360, onChange: handleChange }), _jsx(InputHsvField, { label: "Saturation", color: color, hsvKey: "s", max: 100, scale: 100, onChange: handleChange }), _jsx(InputHsvField, { label: "Value", color: color, hsvKey: "v", max: 100, scale: 100, onChange: handleChange })] })] })] }) })] }));
|
69
|
+
}, open: popoverOpen, trapFocus: true, onOpenChange: (_, data) => setPopoverOpen(data.open), children: [_jsx(PopoverTrigger, { disableButtonEnhancement: true, children: _jsx(ColorSwatch, { borderColor: tokens.colorNeutralShadowKeyDarker, size: "small", color: color.toHexString(), value: color.toHexString().slice(1) }) }), _jsx(PopoverSurface, { children: _jsxs("div", { className: classes.colorPickerContainer, children: [_jsxs(ColorPicker, { color: rgbaToHsv(color), onColorChange: handleColorPickerChange, children: [_jsx(ColorArea, { inputX: { "aria-label": "Saturation" }, inputY: { "aria-label": "Brightness" } }), _jsx(ColorSlider, { "aria-label": "Hue" }), color instanceof Color4 && _jsx(AlphaSlider, { "aria-label": "Alpha" })] }), _jsxs("div", { className: classes.container, children: [_jsxs("div", { className: classes.row, children: [_jsx("div", { className: classes.previewColor, style: { backgroundColor: color.toHexString() } }), _jsx(InputHexField, { label: "Gamma Hex", value: color, isLinearMode: props.isLinearMode, onChange: handleChange }), _jsx(InputHexField, { label: "Linear Hex", linearHex: true, isLinearMode: props.isLinearMode, value: color, onChange: handleChange })] }), _jsxs("div", { className: classes.row, children: [_jsx(InputRgbField, { label: "Red", color: color, rgbKey: "r", onChange: handleChange }), _jsx(InputRgbField, { label: "Green", color: color, rgbKey: "g", onChange: handleChange }), _jsx(InputRgbField, { label: "Blue", color: color, rgbKey: "b", onChange: handleChange }), _jsx(InputAlphaField, { color: color, onChange: handleChange })] }), _jsxs("div", { className: classes.row, children: [_jsx(InputHsvField, { label: "Hue", color: color, hsvKey: "h", max: 360, onChange: handleChange }), _jsx(InputHsvField, { label: "Saturation", color: color, hsvKey: "s", max: 100, scale: 100, onChange: handleChange }), _jsx(InputHsvField, { label: "Value", color: color, hsvKey: "v", max: 100, scale: 100, onChange: handleChange })] })] })] }) })] }));
|
70
70
|
};
|
71
71
|
/**
|
72
72
|
* Component which displays the passed in color's HEX value, either in linearSpace (if linearHex is true) or in gamma space
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"colorPicker.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/colorPicker.tsx"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,yDAAyD;AACzD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EACH,KAAK,EACL,KAAK,EACL,UAAU,EACV,KAAK,EACL,WAAW,EACX,WAAW,EACX,SAAS,EACT,WAAW,EACX,SAAS,EACT,IAAI,EACJ,UAAU,EACV,OAAO,EACP,cAAc,EACd,cAAc,EACd,MAAM,EACN,WAAW,EACX,WAAW,GACd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM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GAEE,CAChB,IACC,EACN,KAAC,UAAU,IACP,QAAQ,EAAE,KAAK,YAAY,MAAM,EACjC,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,CAAC,EACN,SAAS,EAAE,OAAO,CAAC,UAAU,EAC7B,KAAK,EAAE,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAC5C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,EAAE,GACR,IACA,CACT,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,OAAO,CAAC;AAE7B,SAAS,SAAS,CAAC,KAAsD;IACrE,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IACtB,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;AACxD,CAAC","sourcesContent":["/* eslint-disable jsdoc/require-returns */\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { useState, useEffect, useCallback } from \"react\";\r\nimport type { FunctionComponent, ChangeEvent } from \"react\";\r\nimport {\r\n Input,\r\n Label,\r\n SpinButton,\r\n useId,\r\n ColorPicker,\r\n ColorSlider,\r\n ColorArea,\r\n AlphaSlider,\r\n InfoLabel,\r\n Link,\r\n makeStyles,\r\n Popover,\r\n PopoverSurface,\r\n PopoverTrigger,\r\n tokens,\r\n Body1Strong,\r\n ColorSwatch,\r\n} from \"@fluentui/react-components\";\r\nimport type { SpinButtonChangeEvent, SpinButtonOnChangeData, ColorPickerProps as FluentColorPickerProps, InputOnChangeData } from \"@fluentui/react-components\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { BaseComponentProps } from \"../hoc/propertyLine\";\r\n\r\nconst useColorPickerStyles = makeStyles({\r\n colorPickerContainer: {\r\n width: \"325px\",\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n gap: tokens.spacingVerticalMNudge, // 10px\r\n overflow: \"visible\",\r\n },\r\n previewColor: {\r\n width: \"50px\",\r\n height: \"50px\",\r\n borderRadius: tokens.borderRadiusMedium,\r\n border: `${tokens.spacingVerticalXXS} solid ${tokens.colorNeutralShadowKeyLighter}`,\r\n \"@media (forced-colors: active)\": {\r\n forcedColorAdjust: \"none\", // ensures elmement maintains color in high constrast mode\r\n },\r\n },\r\n row: {\r\n display: \"flex\",\r\n flexDirection: \"row\",\r\n gap: tokens.spacingVerticalM, // 12px\r\n alignItems: \"center\",\r\n },\r\n colorFieldWrapper: {\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n gap: tokens.spacingVerticalSNudge, // 6px\r\n },\r\n input: {\r\n width: \"80px\",\r\n },\r\n spinButton: {\r\n minWidth: \"60px\",\r\n },\r\n container: {\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n gap: tokens.spacingVerticalL, // 16px\r\n },\r\n});\r\n\r\nexport type ColorPickerProps<C extends Color3 | Color4> = {\r\n isLinearMode?: boolean;\r\n} & BaseComponentProps<C>;\r\n\r\nexport const ColorPickerPopup: FunctionComponent<ColorPickerProps<Color3 | Color4>> = (props) => {\r\n const classes = useColorPickerStyles();\r\n const [color, setColor] = useState(props.value);\r\n\r\n const [popoverOpen, setPopoverOpen] = useState(false);\r\n\r\n useEffect(() => {\r\n setColor(props.value); // Ensures the trigger color updates when props.value changes\r\n }, [props.value]);\r\n\r\n const handleColorPickerChange: FluentColorPickerProps[\"onColorChange\"] = (_, data) => {\r\n let color: Color3 | Color4 = Color3.FromHSV(data.color.h, data.color.s, data.color.v);\r\n if (props.value instanceof Color4) {\r\n color = Color4.FromColor3(color, data.color.a ?? 1);\r\n }\r\n handleChange(color);\r\n };\r\n\r\n const handleChange = (newColor: Color3 | Color4) => {\r\n setColor(newColor);\r\n props.onChange(newColor); // Ensures the parent is notified when color changes from within colorPicker\r\n };\r\n\r\n return (\r\n <Popover\r\n positioning={{\r\n align: \"start\",\r\n overflowBoundary: document.body,\r\n autoSize: true,\r\n }}\r\n open={popoverOpen}\r\n trapFocus\r\n onOpenChange={(_, data) => setPopoverOpen(data.open)}\r\n >\r\n <PopoverTrigger disableButtonEnhancement>\r\n <ColorSwatch size=\"small\" color={color.toHexString()} value={color.toHexString().slice(1)} />\r\n </PopoverTrigger>\r\n\r\n <PopoverSurface>\r\n <div className={classes.colorPickerContainer}>\r\n <ColorPicker color={rgbaToHsv(color)} onColorChange={handleColorPickerChange}>\r\n <ColorArea inputX={{ \"aria-label\": \"Saturation\" }} inputY={{ \"aria-label\": \"Brightness\" }} />\r\n <ColorSlider aria-label=\"Hue\" />\r\n {color instanceof Color4 && <AlphaSlider aria-label=\"Alpha\" />}\r\n </ColorPicker>\r\n <div className={classes.container}>\r\n {/* Top Row: Preview, Gamma Hex, Linear Hex */}\r\n <div className={classes.row}>\r\n <div className={classes.previewColor} style={{ backgroundColor: color.toHexString() }} />\r\n <InputHexField label=\"Gamma Hex\" value={color} isLinearMode={props.isLinearMode} onChange={handleChange} />\r\n <InputHexField label=\"Linear Hex\" linearHex={true} isLinearMode={props.isLinearMode} value={color} onChange={handleChange} />\r\n </div>\r\n\r\n {/* Middle Row: Red, Green, Blue, Alpha */}\r\n <div className={classes.row}>\r\n <InputRgbField label=\"Red\" color={color} rgbKey=\"r\" onChange={handleChange} />\r\n <InputRgbField label=\"Green\" color={color} rgbKey=\"g\" onChange={handleChange} />\r\n <InputRgbField label=\"Blue\" color={color} rgbKey=\"b\" onChange={handleChange} />\r\n <InputAlphaField color={color} onChange={handleChange} />\r\n </div>\r\n\r\n {/* Bottom Row: Hue, Saturation, Value */}\r\n <div className={classes.row}>\r\n <InputHsvField label=\"Hue\" color={color} hsvKey=\"h\" max={360} onChange={handleChange} />\r\n <InputHsvField label=\"Saturation\" color={color} hsvKey=\"s\" max={100} scale={100} onChange={handleChange} />\r\n <InputHsvField label=\"Value\" color={color} hsvKey=\"v\" max={100} scale={100} onChange={handleChange} />\r\n </div>\r\n </div>\r\n </div>\r\n </PopoverSurface>\r\n </Popover>\r\n );\r\n};\r\n\r\ntype HsvKey = \"h\" | \"s\" | \"v\";\r\nexport type InputHexProps = BaseComponentProps<Color3 | Color4> & {\r\n label?: string;\r\n linearHex?: boolean;\r\n isLinearMode?: boolean;\r\n};\r\n/**\r\n * Component which displays the passed in color's HEX value, either in linearSpace (if linearHex is true) or in gamma space\r\n * When the hex color is changed by user, component calculates the new Color3/4 value and calls onChange\r\n *\r\n * Component uses the isLinearMode boolean to display an informative label regarding linear / gamma space\r\n * @param props - The properties for the InputHexField component.\r\n * @returns\r\n */\r\nexport const InputHexField: FunctionComponent<InputHexProps> = (props) => {\r\n const id = useId(\"hex-input\");\r\n const styles = useColorPickerStyles();\r\n const { label, value, onChange, linearHex, isLinearMode } = props;\r\n\r\n const handleChange = (e: ChangeEvent<HTMLInputElement>, _: InputOnChangeData) => {\r\n // If linearHint (aka PBR material, ensure the other values are displayed in gamma even if linear hex changes)\r\n const value = e.target.value;\r\n if (value != \"\" && /^[0-9A-Fa-f]+$/g.test(value) == false) {\r\n return;\r\n }\r\n onChange(Color3.FromHexString(value).toGammaSpace());\r\n };\r\n return (\r\n <div className={styles.colorFieldWrapper}>\r\n {props.linearHex ? (\r\n <InfoLabel\r\n htmlFor={id}\r\n info={\r\n !isLinearMode ? (\r\n <> This color picker is attached to an entity whose color is stored in gamma space, so we are showing linear hex in disabled view </>\r\n ) : (\r\n <>\r\n This color picker is attached to an entity whose color is stored in linear space (ex: PBR Material), and Babylon converts the color to gamma space\r\n before rendering on screen because the human eye is best at processing colors in gamma space. We thus also want to display the color picker in gamma\r\n space so that the color chosen here will match the color seen in your entity.\r\n <br />\r\n If you want to copy/paste the HEX into your code, you can either use\r\n <Body1Strong>Color3.FromHexString(LINEAR_HEX)</Body1Strong>\r\n <br />\r\n or\r\n <br />\r\n <Body1Strong>Color3.FromHexString(GAMMA_HEX).toLinearSpace()</Body1Strong>\r\n <br />\r\n <br />\r\n <Link href=\"https://doc.babylonjs.com/preparingArtForBabylon/controllingColorSpace/\"> Read more in our docs! </Link>\r\n </>\r\n )\r\n }\r\n >\r\n {label}\r\n </InfoLabel>\r\n ) : (\r\n <Label htmlFor={id}>{label}</Label>\r\n )}\r\n <Input\r\n disabled={linearHex ? !isLinearMode : false}\r\n className={styles.input}\r\n value={linearHex ? value.toLinearSpace().toHexString() : value.toHexString()}\r\n id={id}\r\n onChange={handleChange}\r\n />\r\n </div>\r\n );\r\n};\r\n\r\ntype RgbKey = \"r\" | \"g\" | \"b\";\r\ntype InputRgbFieldProps = {\r\n color: Color3 | Color4;\r\n label: string;\r\n rgbKey: RgbKey;\r\n onChange: (color: Color3 | Color4) => void;\r\n};\r\n\r\nconst InputRgbField: FunctionComponent<InputRgbFieldProps> = (props) => {\r\n const { color, onChange, label, rgbKey } = props;\r\n const id = useId(`${label.toLowerCase()}-input`);\r\n const classes = useColorPickerStyles();\r\n\r\n const handleChange = useCallback(\r\n (_: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => {\r\n const val = data.value ?? parseFloat(data.displayValue ?? \"\");\r\n\r\n if (val === null || Number.isNaN(val) || !NUMBER_REGEX.test(val.toString())) {\r\n return;\r\n }\r\n\r\n const newColor = color.clone();\r\n newColor[rgbKey] = val / 255.0; // Convert to 0-1 range\r\n onChange(newColor);\r\n },\r\n [color]\r\n );\r\n\r\n return (\r\n <div className={classes.colorFieldWrapper}>\r\n <Label htmlFor={id}>{label}</Label>\r\n <SpinButton className={classes.spinButton} min={0} max={255} value={color[rgbKey] * 255.0} step={1} id={id} onChange={handleChange} name={rgbKey} />\r\n </div>\r\n );\r\n};\r\n\r\ntype InputHsvFieldProps = {\r\n color: Color3 | Color4;\r\n label: string;\r\n hsvKey: HsvKey;\r\n onChange: (color: Color3 | Color4) => void;\r\n max: number;\r\n scale?: number;\r\n};\r\n\r\n/**\r\n * In the HSV (Hue, Saturation, Value) color model, Hue (H) ranges from 0 to 360 degrees, representing the color's position on the color wheel.\r\n * Saturation (S) ranges from 0 to 100%, indicating the intensity or purity of the color, with 0 being shades of gray and 100 being a fully saturated color.\r\n * Value (V) ranges from 0 to 100%, representing the brightness of the color, with 0 being black and 100 being the brightest.\r\n * @param props - The properties for the InputHsvField component.\r\n */\r\nexport const InputHsvField: FunctionComponent<InputHsvFieldProps> = (props) => {\r\n const { color, label, hsvKey, max, scale = 1 } = props;\r\n\r\n const id = useId(`${label.toLowerCase()}-input`);\r\n const classes = useColorPickerStyles();\r\n\r\n const handleChange = useCallback(\r\n (_: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => {\r\n const val = data.value ?? parseFloat(data.displayValue ?? \"\");\r\n\r\n if (val === null || Number.isNaN(val) || !NUMBER_REGEX.test(val.toString())) {\r\n return;\r\n }\r\n\r\n // Convert current color to HSV, update the new hsv value, then call onChange prop\r\n const hsv = rgbaToHsv(color);\r\n hsv[hsvKey] = val / scale;\r\n let newColor: Color3 | Color4 = Color3.FromHSV(hsv.h, hsv.s, hsv.v);\r\n if (color instanceof Color4) {\r\n newColor = Color4.FromColor3(newColor, color.a ?? 1);\r\n }\r\n props.onChange(newColor);\r\n },\r\n [color]\r\n );\r\n\r\n return (\r\n <div className={classes.colorFieldWrapper}>\r\n <Label htmlFor={id}>{label}</Label>\r\n <SpinButton className={classes.spinButton} min={0} max={max} value={rgbaToHsv(color)[hsvKey] * scale} step={1} id={id} onChange={handleChange} name={hsvKey} />\r\n </div>\r\n );\r\n};\r\n\r\ntype InputAlphaProps = {\r\n color: Color3 | Color4;\r\n onChange: (color: Color4) => void;\r\n};\r\n\r\n/**\r\n * Displays the alpha value of a color, either in the disabled state (if color is Color3) or as a spin button (if color is Color4).\r\n * @param props\r\n * @returns\r\n */\r\nconst InputAlphaField: FunctionComponent<InputAlphaProps> = (props) => {\r\n const classes = useColorPickerStyles();\r\n const id = useId(\"alpha-input\");\r\n const { color } = props;\r\n\r\n const onChange = (_: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => {\r\n const value = data.value ?? parseFloat(data.displayValue ?? \"\");\r\n\r\n if (Number.isNaN(value) || value < 0 || value > 1) {\r\n return;\r\n }\r\n\r\n if (color instanceof Color4) {\r\n const newColor = color.clone();\r\n newColor.a = value;\r\n return newColor;\r\n } else {\r\n return Color4.FromColor3(color, value);\r\n }\r\n };\r\n\r\n return (\r\n <div className={classes.colorFieldWrapper}>\r\n <div className={classes.row}>\r\n <Label htmlFor={id}>Alpha</Label>\r\n {color instanceof Color3 && (\r\n <InfoLabel\r\n htmlFor={id}\r\n info={\r\n <>\r\n Because this color picker is representing a Color3, we do not permit modifying alpha from the color picker. You can however modify the material's\r\n alpha property directly, either in code via material.alpha OR via inspector's transparency section.\r\n </>\r\n }\r\n ></InfoLabel>\r\n )}\r\n </div>\r\n <SpinButton\r\n disabled={color instanceof Color3}\r\n min={0}\r\n max={1}\r\n className={classes.spinButton}\r\n value={color instanceof Color3 ? 1 : color.a}\r\n step={0.01}\r\n onChange={onChange}\r\n id={id}\r\n />\r\n </div>\r\n );\r\n};\r\n\r\nconst NUMBER_REGEX = /^\\d+$/;\r\n\r\nfunction rgbaToHsv(color: { r: number; g: number; b: number; a?: number }): { h: number; s: number; v: number; a?: number } {\r\n const c = new Color3(color.r, color.g, color.b);\r\n const hsv = c.toHSV();\r\n return { h: hsv.r, s: hsv.g, v: hsv.b, a: color.a };\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"colorPicker.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/colorPicker.tsx"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,yDAAyD;AACzD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;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AK,EAAE,KAAK,CAAC,CAAC;QAC3C,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,CACH,eAAK,SAAS,EAAE,OAAO,CAAC,iBAAiB,aACrC,eAAK,SAAS,EAAE,OAAO,CAAC,GAAG,aACvB,KAAC,KAAK,IAAC,OAAO,EAAE,EAAE,sBAAe,EAChC,KAAK,YAAY,MAAM,IAAI,CACxB,KAAC,SAAS,IACN,OAAO,EAAE,EAAE,EACX,IAAI,EACA,sRAGG,GAEE,CAChB,IACC,EACN,KAAC,UAAU,IACP,QAAQ,EAAE,KAAK,YAAY,MAAM,EACjC,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,CAAC,EACN,SAAS,EAAE,OAAO,CAAC,UAAU,EAC7B,KAAK,EAAE,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAC5C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,EAAE,GACR,IACA,CACT,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,OAAO,CAAC;AAE7B,SAAS,SAAS,CAAC,KAAsD;IACrE,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IACtB,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;AACxD,CAAC","sourcesContent":["/* eslint-disable jsdoc/require-returns */\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { useState, useEffect, useCallback } from \"react\";\r\nimport type { FunctionComponent, ChangeEvent } from \"react\";\r\nimport {\r\n Input,\r\n Label,\r\n SpinButton,\r\n useId,\r\n ColorPicker,\r\n ColorSlider,\r\n ColorArea,\r\n AlphaSlider,\r\n InfoLabel,\r\n Link,\r\n makeStyles,\r\n Popover,\r\n PopoverSurface,\r\n PopoverTrigger,\r\n tokens,\r\n Body1Strong,\r\n ColorSwatch,\r\n} from \"@fluentui/react-components\";\r\nimport type { SpinButtonChangeEvent, SpinButtonOnChangeData, ColorPickerProps as FluentColorPickerProps, InputOnChangeData } from \"@fluentui/react-components\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { BaseComponentProps } from \"../hoc/propertyLine\";\r\n\r\nconst useColorPickerStyles = makeStyles({\r\n colorPickerContainer: {\r\n width: \"325px\",\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n gap: tokens.spacingVerticalMNudge, // 10px\r\n overflow: \"visible\",\r\n },\r\n previewColor: {\r\n width: \"50px\",\r\n height: \"50px\",\r\n borderRadius: tokens.borderRadiusMedium,\r\n border: `${tokens.spacingVerticalXXS} solid ${tokens.colorNeutralShadowKeyLighter}`,\r\n \"@media (forced-colors: active)\": {\r\n forcedColorAdjust: \"none\", // ensures elmement maintains color in high constrast mode\r\n },\r\n },\r\n row: {\r\n display: \"flex\",\r\n flexDirection: \"row\",\r\n gap: tokens.spacingVerticalM, // 12px\r\n alignItems: \"center\",\r\n },\r\n colorFieldWrapper: {\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n gap: tokens.spacingVerticalSNudge, // 6px\r\n },\r\n input: {\r\n width: \"80px\",\r\n },\r\n spinButton: {\r\n minWidth: \"60px\",\r\n },\r\n container: {\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n gap: tokens.spacingVerticalL, // 16px\r\n },\r\n});\r\n\r\nexport type ColorPickerProps<C extends Color3 | Color4> = {\r\n isLinearMode?: boolean;\r\n} & BaseComponentProps<C>;\r\n\r\nexport const ColorPickerPopup: FunctionComponent<ColorPickerProps<Color3 | Color4>> = (props) => {\r\n const classes = useColorPickerStyles();\r\n const [color, setColor] = useState(props.value);\r\n\r\n const [popoverOpen, setPopoverOpen] = useState(false);\r\n\r\n useEffect(() => {\r\n setColor(props.value); // Ensures the trigger color updates when props.value changes\r\n }, [props.value]);\r\n\r\n const handleColorPickerChange: FluentColorPickerProps[\"onColorChange\"] = (_, data) => {\r\n let color: Color3 | Color4 = Color3.FromHSV(data.color.h, data.color.s, data.color.v);\r\n if (props.value instanceof Color4) {\r\n color = Color4.FromColor3(color, data.color.a ?? 1);\r\n }\r\n handleChange(color);\r\n };\r\n\r\n const handleChange = (newColor: Color3 | Color4) => {\r\n setColor(newColor);\r\n props.onChange(newColor); // Ensures the parent is notified when color changes from within colorPicker\r\n };\r\n\r\n return (\r\n <Popover\r\n positioning={{\r\n align: \"start\",\r\n overflowBoundary: document.body,\r\n autoSize: true,\r\n }}\r\n open={popoverOpen}\r\n trapFocus\r\n onOpenChange={(_, data) => setPopoverOpen(data.open)}\r\n >\r\n <PopoverTrigger disableButtonEnhancement>\r\n <ColorSwatch borderColor={tokens.colorNeutralShadowKeyDarker} size=\"small\" color={color.toHexString()} value={color.toHexString().slice(1)} />\r\n </PopoverTrigger>\r\n\r\n <PopoverSurface>\r\n <div className={classes.colorPickerContainer}>\r\n <ColorPicker color={rgbaToHsv(color)} onColorChange={handleColorPickerChange}>\r\n <ColorArea inputX={{ \"aria-label\": \"Saturation\" }} inputY={{ \"aria-label\": \"Brightness\" }} />\r\n <ColorSlider aria-label=\"Hue\" />\r\n {color instanceof Color4 && <AlphaSlider aria-label=\"Alpha\" />}\r\n </ColorPicker>\r\n <div className={classes.container}>\r\n {/* Top Row: Preview, Gamma Hex, Linear Hex */}\r\n <div className={classes.row}>\r\n <div className={classes.previewColor} style={{ backgroundColor: color.toHexString() }} />\r\n <InputHexField label=\"Gamma Hex\" value={color} isLinearMode={props.isLinearMode} onChange={handleChange} />\r\n <InputHexField label=\"Linear Hex\" linearHex={true} isLinearMode={props.isLinearMode} value={color} onChange={handleChange} />\r\n </div>\r\n\r\n {/* Middle Row: Red, Green, Blue, Alpha */}\r\n <div className={classes.row}>\r\n <InputRgbField label=\"Red\" color={color} rgbKey=\"r\" onChange={handleChange} />\r\n <InputRgbField label=\"Green\" color={color} rgbKey=\"g\" onChange={handleChange} />\r\n <InputRgbField label=\"Blue\" color={color} rgbKey=\"b\" onChange={handleChange} />\r\n <InputAlphaField color={color} onChange={handleChange} />\r\n </div>\r\n\r\n {/* Bottom Row: Hue, Saturation, Value */}\r\n <div className={classes.row}>\r\n <InputHsvField label=\"Hue\" color={color} hsvKey=\"h\" max={360} onChange={handleChange} />\r\n <InputHsvField label=\"Saturation\" color={color} hsvKey=\"s\" max={100} scale={100} onChange={handleChange} />\r\n <InputHsvField label=\"Value\" color={color} hsvKey=\"v\" max={100} scale={100} onChange={handleChange} />\r\n </div>\r\n </div>\r\n </div>\r\n </PopoverSurface>\r\n </Popover>\r\n );\r\n};\r\n\r\ntype HsvKey = \"h\" | \"s\" | \"v\";\r\nexport type InputHexProps = BaseComponentProps<Color3 | Color4> & {\r\n label?: string;\r\n linearHex?: boolean;\r\n isLinearMode?: boolean;\r\n};\r\n/**\r\n * Component which displays the passed in color's HEX value, either in linearSpace (if linearHex is true) or in gamma space\r\n * When the hex color is changed by user, component calculates the new Color3/4 value and calls onChange\r\n *\r\n * Component uses the isLinearMode boolean to display an informative label regarding linear / gamma space\r\n * @param props - The properties for the InputHexField component.\r\n * @returns\r\n */\r\nexport const InputHexField: FunctionComponent<InputHexProps> = (props) => {\r\n const id = useId(\"hex-input\");\r\n const styles = useColorPickerStyles();\r\n const { label, value, onChange, linearHex, isLinearMode } = props;\r\n\r\n const handleChange = (e: ChangeEvent<HTMLInputElement>, _: InputOnChangeData) => {\r\n // If linearHint (aka PBR material, ensure the other values are displayed in gamma even if linear hex changes)\r\n const value = e.target.value;\r\n if (value != \"\" && /^[0-9A-Fa-f]+$/g.test(value) == false) {\r\n return;\r\n }\r\n onChange(Color3.FromHexString(value).toGammaSpace());\r\n };\r\n return (\r\n <div className={styles.colorFieldWrapper}>\r\n {props.linearHex ? (\r\n <InfoLabel\r\n htmlFor={id}\r\n info={\r\n !isLinearMode ? (\r\n <> This color picker is attached to an entity whose color is stored in gamma space, so we are showing linear hex in disabled view </>\r\n ) : (\r\n <>\r\n This color picker is attached to an entity whose color is stored in linear space (ex: PBR Material), and Babylon converts the color to gamma space\r\n before rendering on screen because the human eye is best at processing colors in gamma space. We thus also want to display the color picker in gamma\r\n space so that the color chosen here will match the color seen in your entity.\r\n <br />\r\n If you want to copy/paste the HEX into your code, you can either use\r\n <Body1Strong>Color3.FromHexString(LINEAR_HEX)</Body1Strong>\r\n <br />\r\n or\r\n <br />\r\n <Body1Strong>Color3.FromHexString(GAMMA_HEX).toLinearSpace()</Body1Strong>\r\n <br />\r\n <br />\r\n <Link href=\"https://doc.babylonjs.com/preparingArtForBabylon/controllingColorSpace/\"> Read more in our docs! </Link>\r\n </>\r\n )\r\n }\r\n >\r\n {label}\r\n </InfoLabel>\r\n ) : (\r\n <Label htmlFor={id}>{label}</Label>\r\n )}\r\n <Input\r\n disabled={linearHex ? !isLinearMode : false}\r\n className={styles.input}\r\n value={linearHex ? value.toLinearSpace().toHexString() : value.toHexString()}\r\n id={id}\r\n onChange={handleChange}\r\n />\r\n </div>\r\n );\r\n};\r\n\r\ntype RgbKey = \"r\" | \"g\" | \"b\";\r\ntype InputRgbFieldProps = {\r\n color: Color3 | Color4;\r\n label: string;\r\n rgbKey: RgbKey;\r\n onChange: (color: Color3 | Color4) => void;\r\n};\r\n\r\nconst InputRgbField: FunctionComponent<InputRgbFieldProps> = (props) => {\r\n const { color, onChange, label, rgbKey } = props;\r\n const id = useId(`${label.toLowerCase()}-input`);\r\n const classes = useColorPickerStyles();\r\n\r\n const handleChange = useCallback(\r\n (_: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => {\r\n const val = data.value ?? parseFloat(data.displayValue ?? \"\");\r\n\r\n if (val === null || Number.isNaN(val) || !NUMBER_REGEX.test(val.toString())) {\r\n return;\r\n }\r\n\r\n const newColor = color.clone();\r\n newColor[rgbKey] = val / 255.0; // Convert to 0-1 range\r\n onChange(newColor);\r\n },\r\n [color]\r\n );\r\n\r\n return (\r\n <div className={classes.colorFieldWrapper}>\r\n <Label htmlFor={id}>{label}</Label>\r\n <SpinButton className={classes.spinButton} min={0} max={255} value={color[rgbKey] * 255.0} step={1} id={id} onChange={handleChange} name={rgbKey} />\r\n </div>\r\n );\r\n};\r\n\r\ntype InputHsvFieldProps = {\r\n color: Color3 | Color4;\r\n label: string;\r\n hsvKey: HsvKey;\r\n onChange: (color: Color3 | Color4) => void;\r\n max: number;\r\n scale?: number;\r\n};\r\n\r\n/**\r\n * In the HSV (Hue, Saturation, Value) color model, Hue (H) ranges from 0 to 360 degrees, representing the color's position on the color wheel.\r\n * Saturation (S) ranges from 0 to 100%, indicating the intensity or purity of the color, with 0 being shades of gray and 100 being a fully saturated color.\r\n * Value (V) ranges from 0 to 100%, representing the brightness of the color, with 0 being black and 100 being the brightest.\r\n * @param props - The properties for the InputHsvField component.\r\n */\r\nexport const InputHsvField: FunctionComponent<InputHsvFieldProps> = (props) => {\r\n const { color, label, hsvKey, max, scale = 1 } = props;\r\n\r\n const id = useId(`${label.toLowerCase()}-input`);\r\n const classes = useColorPickerStyles();\r\n\r\n const handleChange = useCallback(\r\n (_: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => {\r\n const val = data.value ?? parseFloat(data.displayValue ?? \"\");\r\n\r\n if (val === null || Number.isNaN(val) || !NUMBER_REGEX.test(val.toString())) {\r\n return;\r\n }\r\n\r\n // Convert current color to HSV, update the new hsv value, then call onChange prop\r\n const hsv = rgbaToHsv(color);\r\n hsv[hsvKey] = val / scale;\r\n let newColor: Color3 | Color4 = Color3.FromHSV(hsv.h, hsv.s, hsv.v);\r\n if (color instanceof Color4) {\r\n newColor = Color4.FromColor3(newColor, color.a ?? 1);\r\n }\r\n props.onChange(newColor);\r\n },\r\n [color]\r\n );\r\n\r\n return (\r\n <div className={classes.colorFieldWrapper}>\r\n <Label htmlFor={id}>{label}</Label>\r\n <SpinButton className={classes.spinButton} min={0} max={max} value={rgbaToHsv(color)[hsvKey] * scale} step={1} id={id} onChange={handleChange} name={hsvKey} />\r\n </div>\r\n );\r\n};\r\n\r\ntype InputAlphaProps = {\r\n color: Color3 | Color4;\r\n onChange: (color: Color4) => void;\r\n};\r\n\r\n/**\r\n * Displays the alpha value of a color, either in the disabled state (if color is Color3) or as a spin button (if color is Color4).\r\n * @param props\r\n * @returns\r\n */\r\nconst InputAlphaField: FunctionComponent<InputAlphaProps> = (props) => {\r\n const classes = useColorPickerStyles();\r\n const id = useId(\"alpha-input\");\r\n const { color } = props;\r\n\r\n const onChange = (_: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => {\r\n const value = data.value ?? parseFloat(data.displayValue ?? \"\");\r\n\r\n if (Number.isNaN(value) || value < 0 || value > 1) {\r\n return;\r\n }\r\n\r\n if (color instanceof Color4) {\r\n const newColor = color.clone();\r\n newColor.a = value;\r\n return newColor;\r\n } else {\r\n return Color4.FromColor3(color, value);\r\n }\r\n };\r\n\r\n return (\r\n <div className={classes.colorFieldWrapper}>\r\n <div className={classes.row}>\r\n <Label htmlFor={id}>Alpha</Label>\r\n {color instanceof Color3 && (\r\n <InfoLabel\r\n htmlFor={id}\r\n info={\r\n <>\r\n Because this color picker is representing a Color3, we do not permit modifying alpha from the color picker. You can however modify the material's\r\n alpha property directly, either in code via material.alpha OR via inspector's transparency section.\r\n </>\r\n }\r\n ></InfoLabel>\r\n )}\r\n </div>\r\n <SpinButton\r\n disabled={color instanceof Color3}\r\n min={0}\r\n max={1}\r\n className={classes.spinButton}\r\n value={color instanceof Color3 ? 1 : color.a}\r\n step={0.01}\r\n onChange={onChange}\r\n id={id}\r\n />\r\n </div>\r\n );\r\n};\r\n\r\nconst NUMBER_REGEX = /^\\d+$/;\r\n\r\nfunction rgbaToHsv(color: { r: number; g: number; b: number; a?: number }): { h: number; s: number; v: number; a?: number } {\r\n const c = new Color3(color.r, color.g, color.b);\r\n const hsv = c.toHSV();\r\n return { h: hsv.r, s: hsv.g, v: hsv.b, a: color.a };\r\n}\r\n"]}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import type { FunctionComponent } from "react";
|
2
|
+
import type { BaseComponentProps } from "../hoc/propertyLine.js";
|
3
|
+
import { Color3Gradient, ColorGradient as Color4Gradient, FactorGradient } from "@babylonjs/core/Misc/gradients.js";
|
4
|
+
import { GradientBlockColorStep } from "@babylonjs/core/Materials/Node/Blocks/gradientBlock.js";
|
5
|
+
/**
|
6
|
+
* Component wrapper for FactorGradient that provides slider inputs for factor1, factor2, and gradient step
|
7
|
+
* @param props - Component props containing FactorGradient value and change handler
|
8
|
+
* @returns A React component
|
9
|
+
*/
|
10
|
+
export declare const FactorGradientComponent: FunctionComponent<BaseComponentProps<FactorGradient>>;
|
11
|
+
/**
|
12
|
+
* Component wrapper for Color3Gradient that provides color picker and gradient step slider
|
13
|
+
* @param props - Component props containing Color3Gradient value and change handler
|
14
|
+
* @returns A React component
|
15
|
+
*/
|
16
|
+
export declare const Color3GradientComponent: FunctionComponent<BaseComponentProps<Color3Gradient>>;
|
17
|
+
/**
|
18
|
+
* Component wrapper for Color4Gradient that provides color pickers for color1, color2, and gradient step slider
|
19
|
+
* @param props - Component props containing Color4Gradient value and change handler
|
20
|
+
* @returns A React component
|
21
|
+
*/
|
22
|
+
export declare const Color4GradientComponent: FunctionComponent<BaseComponentProps<Color4Gradient>>;
|
23
|
+
/**
|
24
|
+
* Component wrapper for GradientBlockColorStep that provides color picker and step slider
|
25
|
+
* @param props - Component props containing GradientBlockColorStep value and change handler
|
26
|
+
* @returns A React component
|
27
|
+
*/
|
28
|
+
export declare const ColorStepGradientComponent: FunctionComponent<BaseComponentProps<GradientBlockColorStep>>;
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { useEffect, useState } from "react";
|
3
|
+
import { makeStyles, tokens } from "@fluentui/react-components";
|
4
|
+
import { SyncedSliderInput } from "./syncedSlider.js";
|
5
|
+
import { Color3, Color4 } from "@babylonjs/core/Maths/math.color.js";
|
6
|
+
import { ColorPickerPopup } from "./colorPicker.js";
|
7
|
+
import { Color3Gradient, ColorGradient as Color4Gradient, FactorGradient } from "@babylonjs/core/Misc/gradients.js";
|
8
|
+
import { GradientBlockColorStep } from "@babylonjs/core/Materials/Node/Blocks/gradientBlock.js";
|
9
|
+
const useGradientStyles = makeStyles({
|
10
|
+
container: {
|
11
|
+
display: "flex",
|
12
|
+
alignItems: "center",
|
13
|
+
gap: tokens.spacingHorizontalS,
|
14
|
+
width: "100%",
|
15
|
+
},
|
16
|
+
// Wrapper for each slider to control its size
|
17
|
+
valueWrapper: {
|
18
|
+
flex: "0 1 auto", // Don't grow, can shrink, size based on content
|
19
|
+
alignContent: "center",
|
20
|
+
minWidth: "80px", // Minimum width to keep usable
|
21
|
+
maxWidth: "100px", // Maximum width to prevent them from getting too wide
|
22
|
+
},
|
23
|
+
// Wrapper for color pickers - much smaller since they're just swatches
|
24
|
+
colorWrapper: {
|
25
|
+
alignContent: "center",
|
26
|
+
// No flex properties - just take natural size
|
27
|
+
},
|
28
|
+
// Wrapper for the step slider to take remaining space
|
29
|
+
stepSliderWrapper: {
|
30
|
+
flex: "1 0 auto", // Can grow, don't shrink, size based on content
|
31
|
+
minWidth: "100px",
|
32
|
+
},
|
33
|
+
});
|
34
|
+
/**
|
35
|
+
* Gradient component that displays 1 or 2 color or number inputs next to a slider
|
36
|
+
* @param props - Component props containing gradient value and change handlers
|
37
|
+
* @returns A React component
|
38
|
+
*/
|
39
|
+
const Gradient = (props) => {
|
40
|
+
const [gradient, setGradient] = useState(props.value);
|
41
|
+
const classes = useGradientStyles();
|
42
|
+
useEffect(() => {
|
43
|
+
setGradient(props.value); // Re-render if props.value changes
|
44
|
+
}, [props.value]);
|
45
|
+
const gradientChange = (newGradient) => {
|
46
|
+
setGradient(newGradient);
|
47
|
+
props.onChange(newGradient);
|
48
|
+
};
|
49
|
+
return (_jsxs("div", { id: "gradientContainer", className: classes.container, children: [_jsx("div", { className: gradient.value1 instanceof Color3 || gradient.value1 instanceof Color4 ? classes.colorWrapper : classes.valueWrapper, children: gradient.value1 instanceof Color3 || gradient.value1 instanceof Color4 ? (_jsx(ColorPickerPopup, { value: gradient.value1, onChange: (color) => gradientChange({ ...gradient, value1: color }) })) : (_jsx(SyncedSliderInput, { step: 0.01, value: gradient.value1, onChange: (val) => gradientChange({ ...gradient, value1: val }) })) }), gradient.value2 !== undefined && (_jsx("div", { className: gradient.value2 instanceof Color3 || gradient.value2 instanceof Color4 ? classes.colorWrapper : classes.valueWrapper, children: gradient.value2 instanceof Color3 || gradient.value2 instanceof Color4 ? (_jsx(ColorPickerPopup, { value: gradient.value2, onChange: (color) => gradientChange({ ...gradient, value2: color }) })) : (_jsx(SyncedSliderInput, { step: 0.01, value: gradient.value2, onChange: (val) => gradientChange({ ...gradient, value2: val }) })) })), _jsx("div", { className: classes.stepSliderWrapper, children: _jsx(SyncedSliderInput, { notifyOnlyOnRelease: true, min: 0, max: 1, step: 0.01, value: gradient.step, onChange: (val) => gradientChange({ ...gradient, step: val }) }) })] }));
|
50
|
+
};
|
51
|
+
const FactorGradientCast = Gradient;
|
52
|
+
const Color3GradientCast = Gradient;
|
53
|
+
const Color4GradientCast = Gradient;
|
54
|
+
/**
|
55
|
+
* Component wrapper for FactorGradient that provides slider inputs for factor1, factor2, and gradient step
|
56
|
+
* @param props - Component props containing FactorGradient value and change handler
|
57
|
+
* @returns A React component
|
58
|
+
*/
|
59
|
+
export const FactorGradientComponent = (props) => {
|
60
|
+
return (_jsx(FactorGradientCast, { ...props, value: { value1: props.value.factor1, value2: props.value.factor2, step: props.value.gradient }, onChange: (gradient) => props.onChange(new FactorGradient(gradient.step, gradient.value1, gradient.value2)) }));
|
61
|
+
};
|
62
|
+
/**
|
63
|
+
* Component wrapper for Color3Gradient that provides color picker and gradient step slider
|
64
|
+
* @param props - Component props containing Color3Gradient value and change handler
|
65
|
+
* @returns A React component
|
66
|
+
*/
|
67
|
+
export const Color3GradientComponent = (props) => {
|
68
|
+
return (_jsx(Color3GradientCast, { ...props, value: { value1: props.value.color, step: props.value.gradient }, onChange: (gradient) => props.onChange(new Color3Gradient(gradient.step, gradient.value1)) }));
|
69
|
+
};
|
70
|
+
/**
|
71
|
+
* Component wrapper for Color4Gradient that provides color pickers for color1, color2, and gradient step slider
|
72
|
+
* @param props - Component props containing Color4Gradient value and change handler
|
73
|
+
* @returns A React component
|
74
|
+
*/
|
75
|
+
export const Color4GradientComponent = (props) => {
|
76
|
+
return (_jsx(Color4GradientCast, { ...props, value: { value1: props.value.color1, value2: props.value.color2, step: props.value.gradient }, onChange: (gradient) => props.onChange(new Color4Gradient(gradient.step, gradient.value1, gradient.value2)) }));
|
77
|
+
};
|
78
|
+
/**
|
79
|
+
* Component wrapper for GradientBlockColorStep that provides color picker and step slider
|
80
|
+
* @param props - Component props containing GradientBlockColorStep value and change handler
|
81
|
+
* @returns A React component
|
82
|
+
*/
|
83
|
+
export const ColorStepGradientComponent = (props) => {
|
84
|
+
return (_jsx(Color3GradientCast, { ...props, value: { value1: props.value.color, step: props.value.step }, onChange: (gradient) => props.onChange(new GradientBlockColorStep(gradient.step, gradient.value1)) }));
|
85
|
+
};
|
86
|
+
//# sourceMappingURL=gradient.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"gradient.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/gradient.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,4CAA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AQ,CAAC,IAAI,sBAAsB,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,GACpG,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { FunctionComponent } from \"react\";\r\nimport { useEffect, useState } from \"react\";\r\nimport { makeStyles, tokens } from \"@fluentui/react-components\";\r\n\r\nimport { SyncedSliderInput } from \"./syncedSlider\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport { ColorPickerPopup } from \"./colorPicker\";\r\nimport type { BaseComponentProps } from \"../hoc/propertyLine\";\r\nimport { Color3Gradient, ColorGradient as Color4Gradient, FactorGradient } from \"core/Misc/gradients\";\r\nimport { GradientBlockColorStep } from \"core/Materials/Node/Blocks/gradientBlock\";\r\n\r\nconst useGradientStyles = makeStyles({\r\n container: {\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n gap: tokens.spacingHorizontalS,\r\n width: \"100%\",\r\n },\r\n // Wrapper for each slider to control its size\r\n valueWrapper: {\r\n flex: \"0 1 auto\", // Don't grow, can shrink, size based on content\r\n alignContent: \"center\",\r\n minWidth: \"80px\", // Minimum width to keep usable\r\n maxWidth: \"100px\", // Maximum width to prevent them from getting too wide\r\n },\r\n // Wrapper for color pickers - much smaller since they're just swatches\r\n colorWrapper: {\r\n alignContent: \"center\",\r\n // No flex properties - just take natural size\r\n },\r\n // Wrapper for the step slider to take remaining space\r\n stepSliderWrapper: {\r\n flex: \"1 0 auto\", // Can grow, don't shrink, size based on content\r\n minWidth: \"100px\",\r\n },\r\n});\r\n\r\ntype GradientProps<T extends number | Color3 | Color4> = {\r\n value1: T;\r\n value2?: T;\r\n step: number;\r\n};\r\n\r\n/**\r\n * Gradient component that displays 1 or 2 color or number inputs next to a slider\r\n * @param props - Component props containing gradient value and change handlers\r\n * @returns A React component\r\n */\r\nconst Gradient: FunctionComponent<BaseComponentProps<GradientProps<number | Color3 | Color4>>> = (props) => {\r\n const [gradient, setGradient] = useState(props.value);\r\n const classes = useGradientStyles();\r\n\r\n useEffect(() => {\r\n setGradient(props.value); // Re-render if props.value changes\r\n }, [props.value]);\r\n\r\n const gradientChange = (newGradient: GradientProps<number | Color3 | Color4>) => {\r\n setGradient(newGradient);\r\n props.onChange(newGradient);\r\n };\r\n return (\r\n <div id=\"gradientContainer\" className={classes.container}>\r\n <div className={gradient.value1 instanceof Color3 || gradient.value1 instanceof Color4 ? classes.colorWrapper : classes.valueWrapper}>\r\n {gradient.value1 instanceof Color3 || gradient.value1 instanceof Color4 ? (\r\n <ColorPickerPopup value={gradient.value1} onChange={(color) => gradientChange({ ...gradient, value1: color })} />\r\n ) : (\r\n <SyncedSliderInput step={0.01} value={gradient.value1} onChange={(val) => gradientChange({ ...gradient, value1: val })} />\r\n )}\r\n </div>\r\n {gradient.value2 !== undefined && (\r\n <div className={gradient.value2 instanceof Color3 || gradient.value2 instanceof Color4 ? classes.colorWrapper : classes.valueWrapper}>\r\n {gradient.value2 instanceof Color3 || gradient.value2 instanceof Color4 ? (\r\n <ColorPickerPopup value={gradient.value2} onChange={(color) => gradientChange({ ...gradient, value2: color })} />\r\n ) : (\r\n <SyncedSliderInput step={0.01} value={gradient.value2} onChange={(val) => gradientChange({ ...gradient, value2: val })} />\r\n )}\r\n </div>\r\n )}\r\n\r\n <div className={classes.stepSliderWrapper}>\r\n <SyncedSliderInput notifyOnlyOnRelease={true} min={0} max={1} step={0.01} value={gradient.step} onChange={(val) => gradientChange({ ...gradient, step: val })} />\r\n </div>\r\n </div>\r\n );\r\n};\r\n\r\nconst FactorGradientCast = Gradient as FunctionComponent<BaseComponentProps<GradientProps<number>>>;\r\nconst Color3GradientCast = Gradient as FunctionComponent<BaseComponentProps<GradientProps<Color3>>>;\r\nconst Color4GradientCast = Gradient as FunctionComponent<BaseComponentProps<GradientProps<Color4>>>;\r\n\r\n/**\r\n * Component wrapper for FactorGradient that provides slider inputs for factor1, factor2, and gradient step\r\n * @param props - Component props containing FactorGradient value and change handler\r\n * @returns A React component\r\n */\r\nexport const FactorGradientComponent: FunctionComponent<BaseComponentProps<FactorGradient>> = (props) => {\r\n return (\r\n <FactorGradientCast\r\n {...props}\r\n value={{ value1: props.value.factor1, value2: props.value.factor2, step: props.value.gradient }}\r\n onChange={(gradient) => props.onChange(new FactorGradient(gradient.step, gradient.value1, gradient.value2))}\r\n />\r\n );\r\n};\r\n/**\r\n * Component wrapper for Color3Gradient that provides color picker and gradient step slider\r\n * @param props - Component props containing Color3Gradient value and change handler\r\n * @returns A React component\r\n */\r\nexport const Color3GradientComponent: FunctionComponent<BaseComponentProps<Color3Gradient>> = (props) => {\r\n return (\r\n <Color3GradientCast\r\n {...props}\r\n value={{ value1: props.value.color, step: props.value.gradient }}\r\n onChange={(gradient) => props.onChange(new Color3Gradient(gradient.step, gradient.value1))}\r\n />\r\n );\r\n};\r\n/**\r\n * Component wrapper for Color4Gradient that provides color pickers for color1, color2, and gradient step slider\r\n * @param props - Component props containing Color4Gradient value and change handler\r\n * @returns A React component\r\n */\r\nexport const Color4GradientComponent: FunctionComponent<BaseComponentProps<Color4Gradient>> = (props) => {\r\n return (\r\n <Color4GradientCast\r\n {...props}\r\n value={{ value1: props.value.color1, value2: props.value.color2, step: props.value.gradient }}\r\n onChange={(gradient) => props.onChange(new Color4Gradient(gradient.step, gradient.value1, gradient.value2))}\r\n />\r\n );\r\n};\r\n/**\r\n * Component wrapper for GradientBlockColorStep that provides color picker and step slider\r\n * @param props - Component props containing GradientBlockColorStep value and change handler\r\n * @returns A React component\r\n */\r\nexport const ColorStepGradientComponent: FunctionComponent<BaseComponentProps<GradientBlockColorStep>> = (props) => {\r\n return (\r\n <Color3GradientCast\r\n {...props}\r\n value={{ value1: props.value.color, step: props.value.step }}\r\n onChange={(gradient) => props.onChange(new GradientBlockColorStep(gradient.step, gradient.value1))}\r\n />\r\n );\r\n};\r\n"]}
|
@@ -6,9 +6,5 @@ export type InputProps<T extends string | number> = BaseComponentProps<T> & {
|
|
6
6
|
min?: number;
|
7
7
|
max?: number;
|
8
8
|
};
|
9
|
-
|
10
|
-
|
11
|
-
* @param props
|
12
|
-
* @returns
|
13
|
-
*/
|
14
|
-
export declare const Input: FunctionComponent<InputProps<string | number>>;
|
9
|
+
export declare const NumberInput: FunctionComponent<InputProps<number>>;
|
10
|
+
export declare const TextInput: FunctionComponent<InputProps<string>>;
|
@@ -5,11 +5,11 @@ const useInputStyles = makeStyles({
|
|
5
5
|
text: {
|
6
6
|
height: "auto",
|
7
7
|
textAlign: "right",
|
8
|
+
minWidth: "100px", // Min width for text input
|
8
9
|
},
|
9
|
-
|
10
|
+
number: {
|
10
11
|
height: "auto",
|
11
|
-
|
12
|
-
flexShrink: 0,
|
12
|
+
minWidth: "40px", // Min width for number input
|
13
13
|
},
|
14
14
|
});
|
15
15
|
/**
|
@@ -17,22 +17,25 @@ const useInputStyles = makeStyles({
|
|
17
17
|
* @param props
|
18
18
|
* @returns
|
19
19
|
*/
|
20
|
-
|
20
|
+
const Input = (props) => {
|
21
21
|
const classes = useInputStyles();
|
22
22
|
const [value, setValue] = useState(props.value ?? "");
|
23
|
-
const type = typeof props.value === "number" ? "number" : "text";
|
24
23
|
useEffect(() => {
|
25
24
|
setValue(props.value ?? ""); // Update local state when props.value changes
|
26
25
|
}, [props.value]);
|
27
26
|
const handleChange = (event, _) => {
|
28
27
|
event.stopPropagation(); // Prevent event propagation
|
29
|
-
const value = type === "number" ? Number(event.target.value) : String(event.target.value);
|
28
|
+
const value = props.type === "number" ? Number(event.target.value) : String(event.target.value);
|
30
29
|
props.onChange(value); // Call the original onChange handler passed as prop
|
31
30
|
setValue(value); // Update local state with the new value
|
32
31
|
};
|
33
32
|
const handleKeyDown = (event) => {
|
34
33
|
event.stopPropagation(); // Prevent event propagation
|
35
34
|
};
|
36
|
-
return (_jsx(FluentInput, { ...props,
|
35
|
+
return (_jsx(FluentInput, { ...props, size: "small", value: value.toString(), className: props.type === "number" ? classes.number : classes.text, onChange: handleChange, onKeyDown: handleKeyDown }));
|
37
36
|
};
|
37
|
+
const NumberInputCast = Input;
|
38
|
+
const TextInputCast = Input;
|
39
|
+
export const NumberInput = (props) => _jsx(NumberInputCast, { ...props, type: "number" });
|
40
|
+
export const TextInput = (props) => _jsx(TextInputCast, { ...props, type: "text" });
|
38
41
|
//# sourceMappingURL=input.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/input.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAG9E,MAAM,cAAc,GAAG,UAAU,CAAC;IAC9B,IAAI,EAAE;QACF,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,OAAO;
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/input.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAG9E,MAAM,cAAc,GAAG,UAAU,CAAC;IAC9B,IAAI,EAAE;QACF,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,OAAO,EAAE,2BAA2B;KACjD;IACD,MAAM,EAAE;QACJ,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,MAAM,EAAE,6BAA6B;KAClD;CACJ,CAAC,CAAC;AAQH;;;;GAIG;AACH,MAAM,KAAK,GAAiF,CAAC,KAAK,EAAE,EAAE;IAClG,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CA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AQ,GAAG,CAAC;AAC1H,MAAM,CAAC,MAAM,SAAS,GAA0C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAC,aAAa,OAAK,KAAK,EAAE,IAAI,EAAC,MAAM,GAAG,CAAC","sourcesContent":["import type { FunctionComponent, KeyboardEvent, ChangeEvent } from \"react\";\r\nimport { useEffect, useState } from \"react\";\r\n\r\nimport { Input as FluentInput, makeStyles } from \"@fluentui/react-components\";\r\nimport type { BaseComponentProps } from \"../hoc/propertyLine\";\r\n\r\nconst useInputStyles = makeStyles({\r\n text: {\r\n height: \"auto\",\r\n textAlign: \"right\",\r\n minWidth: \"100px\", // Min width for text input\r\n },\r\n number: {\r\n height: \"auto\",\r\n minWidth: \"40px\", // Min width for number input\r\n },\r\n});\r\n\r\nexport type InputProps<T extends string | number> = BaseComponentProps<T> & {\r\n step?: number;\r\n placeholder?: string;\r\n min?: number;\r\n max?: number;\r\n};\r\n/**\r\n * This is an input text box that stops propagation of change events and sets its width based on the type of input (text or number)\r\n * @param props\r\n * @returns\r\n */\r\nconst Input: FunctionComponent<InputProps<string | number> & { type: \"text\" | \"number\" }> = (props) => {\r\n const classes = useInputStyles();\r\n const [value, setValue] = useState(props.value ?? \"\");\r\n\r\n useEffect(() => {\r\n setValue(props.value ?? \"\"); // Update local state when props.value changes\r\n }, [props.value]);\r\n\r\n const handleChange = (event: ChangeEvent<HTMLInputElement>, _: unknown) => {\r\n event.stopPropagation(); // Prevent event propagation\r\n const value = props.type === \"number\" ? Number(event.target.value) : String(event.target.value);\r\n props.onChange(value); // Call the original onChange handler passed as prop\r\n setValue(value); // Update local state with the new value\r\n };\r\n\r\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\r\n event.stopPropagation(); // Prevent event propagation\r\n };\r\n\r\n return (\r\n <FluentInput\r\n {...props}\r\n size=\"small\"\r\n value={value.toString()}\r\n className={props.type === \"number\" ? classes.number : classes.text}\r\n onChange={handleChange}\r\n onKeyDown={handleKeyDown}\r\n />\r\n );\r\n};\r\n\r\nconst NumberInputCast = Input as FunctionComponent<InputProps<number> & { type: \"number\" }>;\r\nconst TextInputCast = Input as FunctionComponent<InputProps<string> & { type: \"text\" }>;\r\n\r\nexport const NumberInput: FunctionComponent<InputProps<number>> = (props) => <NumberInputCast {...props} type=\"number\" />;\r\nexport const TextInput: FunctionComponent<InputProps<string>> = (props) => <TextInputCast {...props} type=\"text\" />;\r\n"]}
|