@onerjs/shared-ui-components 8.43.1 → 8.43.3

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.
@@ -14,7 +14,7 @@ export declare const ColorPickerPopup: import("react").ForwardRefExoticComponent
14
14
  } & import("react").RefAttributes<HTMLButtonElement>>;
15
15
  export type InputHexProps = PrimitiveProps<Color3 | Color4> & {
16
16
  isLinear?: boolean;
17
- ispropertyLinear?: boolean;
17
+ isPropertyLinear?: boolean;
18
18
  };
19
19
  /**
20
20
  * Component which displays the passed in color's HEX value in the currently selected color space.
@@ -77,7 +77,12 @@ export const ColorPickerPopup = forwardRef((props, ref) => {
77
77
  /** Color in gamma space — used for visual elements (picker, preview, trigger) */
78
78
  const gammaColor = useMemo(() => (isPropertyLinear ? color.toGammaSpace() : color), [color, isPropertyLinear]);
79
79
  /** Color in the user-selected display space — used for numeric inputs (RGB, HSV, Hex) */
80
- const displayColor = useMemo(() => (isLinear === isPropertyLinear ? color : isLinear ? color.toLinearSpace() : color.toGammaSpace()), [color, isLinear, isPropertyLinear]);
80
+ const displayColor = useMemo(() => {
81
+ if (isLinear === isPropertyLinear) {
82
+ return color;
83
+ }
84
+ return isLinear ? color.toLinearSpace() : color.toGammaSpace();
85
+ }, [color, isLinear, isPropertyLinear]);
81
86
  const handleColorPickerChange = (_, data) => {
82
87
  // The visual picker always operates in gamma space, convert back to property space
83
88
  let gammaResult = Color3.FromHSV(data.color.h, data.color.s, data.color.v);
@@ -106,7 +111,7 @@ export const ColorPickerPopup = forwardRef((props, ref) => {
106
111
  }, options: [
107
112
  { label: "Int", value: 0 },
108
113
  { label: "Float", value: 1 },
109
- ], value: isFloat ? 1 : 0, onChange: (val) => setFloat(val === 1) })] }), _jsxs("div", { className: classes.inputRow, children: [_jsx(InputRgbField, { title: "Red", value: displayColor, rgbKey: "r", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputRgbField, { title: "Green", value: displayColor, rgbKey: "g", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputRgbField, { title: "Blue", value: displayColor, rgbKey: "b", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputAlphaField, { color: color, onChange: handleChange })] }), _jsxs("div", { className: classes.inputRow, children: [_jsx(InputHsvField, { title: "Hue", value: displayColor, hsvKey: "h", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputHsvField, { title: "Saturation", value: displayColor, hsvKey: "s", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputHsvField, { title: "Value", value: displayColor, hsvKey: "v", isFloat: isFloat, onChange: handleDisplayChange })] }), _jsx("div", { className: classes.inputRow, children: _jsx(InputHexField, { title: "Hexadecimal", value: displayColor, isLinear: isLinear, ispropertyLinear: isPropertyLinear, onChange: handleDisplayChange }) })] }) }));
114
+ ], value: isFloat ? 1 : 0, onChange: (val) => setFloat(val === 1) })] }), _jsxs("div", { className: classes.inputRow, children: [_jsx(InputRgbField, { title: "Red", value: displayColor, rgbKey: "r", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputRgbField, { title: "Green", value: displayColor, rgbKey: "g", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputRgbField, { title: "Blue", value: displayColor, rgbKey: "b", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputAlphaField, { color: color, onChange: handleChange })] }), _jsxs("div", { className: classes.inputRow, children: [_jsx(InputHsvField, { title: "Hue", value: displayColor, hsvKey: "h", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputHsvField, { title: "Saturation", value: displayColor, hsvKey: "s", isFloat: isFloat, onChange: handleDisplayChange }), _jsx(InputHsvField, { title: "Value", value: displayColor, hsvKey: "v", isFloat: isFloat, onChange: handleDisplayChange })] }), _jsx("div", { className: classes.inputRow, children: _jsx(InputHexField, { title: "Hexadecimal", value: displayColor, isLinear: isLinear, isPropertyLinear: isPropertyLinear, onChange: handleDisplayChange }) })] }) }));
110
115
  });
111
116
  /**
112
117
  * Converts a hex string to the same Color type as the original.
@@ -143,16 +148,16 @@ function colorFromHex(hex, original) {
143
148
  */
144
149
  export const InputHexField = (props) => {
145
150
  const classes = useColorPickerStyles();
146
- const { title, value, onChange, isLinear, ispropertyLinear } = props;
147
- const displayMismatchesproperty = (isLinear ?? false) !== (ispropertyLinear ?? false);
151
+ const { title, value, onChange, isLinear, isPropertyLinear } = props;
152
+ const displayMismatchesProperty = (isLinear ?? false) !== (isPropertyLinear ?? false);
148
153
  const displaySpace = isLinear ? "linear" : "gamma";
149
- const propertySpace = ispropertyLinear ? "linear" : "gamma";
154
+ const propertySpace = isPropertyLinear ? "linear" : "gamma";
150
155
  const isColor4 = value instanceof Color4;
151
156
  const colorClass = isColor4 ? "Color4" : "Color3";
152
157
  return (_jsx(TextInput, { className: classes.inputField, value: value.toHexString(), validator: ValidateColorHex, validateOnlyOnBlur: true, onChange: (val) => onChange(colorFromHex(val, value)), infoLabel: title
153
158
  ? {
154
159
  label: title,
155
- info: (_jsxs(Body1, { children: ["This hex value is in ", _jsx(Body1Strong, { children: displaySpace }), " space", displayMismatchesproperty ? (_jsxs(Body1, { children: [", but the property stores its color in ", _jsx(Body1Strong, { children: propertySpace }), " space.", _jsx("br", {}), _jsx("br", {}), "The color picker converts automatically, but if you copy this hex into code you will need to convert it:", _jsx("br", {}), _jsxs(Body1Strong, { children: [colorClass, ".FromHexString(\"", value.toHexString(), "\").", isLinear ? "toGammaSpace()" : "toLinearSpace()"] })] })) : (_jsxs(Body1, { children: [", which matches the property's stored color space.", _jsx("br", {}), _jsx("br", {}), "To copy this hex into code, use", _jsx("br", {}), _jsxs(Body1Strong, { children: [colorClass, ".FromHexString(\"", value.toHexString(), "\")"] })] })), _jsx("br", {}), _jsx("br", {}), _jsx(Link, { url: "https://doc.babylonjs.com/preparingArtForBabylon/controllingColorSpace/", value: "Read more in our docs!" })] })),
160
+ info: (_jsxs(Body1, { children: ["This hex value is in ", _jsx(Body1Strong, { children: displaySpace }), " space", displayMismatchesProperty ? (_jsxs(Body1, { children: [", but the property stores its color in ", _jsx(Body1Strong, { children: propertySpace }), " space.", _jsx("br", {}), _jsx("br", {}), "The color picker converts automatically, but if you copy this hex into code you will need to convert it:", _jsx("br", {}), _jsxs(Body1Strong, { children: [colorClass, ".FromHexString(\"", value.toHexString(), "\").", isLinear ? "toGammaSpace()" : "toLinearSpace()"] })] })) : (_jsxs(Body1, { children: [", which matches the property's stored color space.", _jsx("br", {}), _jsx("br", {}), "To copy this hex into code, use", _jsx("br", {}), _jsxs(Body1Strong, { children: [colorClass, ".FromHexString(\"", value.toHexString(), "\")"] })] })), _jsx("br", {}), _jsx("br", {}), _jsx(Link, { url: "https://doc.babylonjs.com/preparingArtForBabylon/controllingColorSpace/", value: "Read more in our docs!" })] })),
156
161
  }
157
162
  : undefined }));
158
163
  };
@@ -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,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE1F,OAAO,EAAE,WAAW,IAAI,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAExK,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,yCAA8B;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,WAAW,EA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V,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE;YACP,KAAK,EAAE,OAAO;YACd,IAAI,EACA,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,CACtB,KAAC,KAAK,wQAGE,CACX,CAAC,CAAC,CAAC,SAAS;SACpB,GACH,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["/* eslint-disable jsdoc/require-returns */\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { forwardRef, useState, useEffect, useCallback, useContext, useMemo } from \"react\";\r\nimport type { FunctionComponent } from \"react\";\r\nimport { ColorPicker as FluentColorPicker, ColorSlider, ColorArea, AlphaSlider, makeStyles, tokens, Body1Strong, ColorSwatch, Body1 } from \"@fluentui/react-components\";\r\nimport type { ColorPickerProps as FluentColorPickerProps } from \"@fluentui/react-components\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { PrimitiveProps } from \"./primitive\";\r\nimport { SpinButton } from \"./spinButton\";\r\nimport { TextInput } from \"./textInput\";\r\nimport { NumberDropdown } from \"./dropdown\";\r\nimport { ValidateColorHex } from \"./utils\";\r\nimport { Link } from \"./link\";\r\nimport { ToolContext } from \"../hoc/fluentToolWrapper\";\r\nimport { Popover } from \"./popover\";\r\n\r\nconst useColorPickerStyles = makeStyles({\r\n container: {\r\n width: \"350px\",\r\n display: \"flex\", // becomes a flexbox\r\n flexDirection: \"column\", // with children in a column\r\n alignItems: \"center\", // centers children horizontally\r\n justifyContent: \"center\", // centers children vertically (if height is set)\r\n gap: tokens.spacingVerticalM,\r\n overflow: \"visible\",\r\n },\r\n row: {\r\n flex: 1, // is a row in the container's flex column\r\n display: \"flex\", // becomes its own flexbox\r\n flexDirection: \"row\", // with children in a row\r\n gap: tokens.spacingHorizontalXL,\r\n alignItems: \"center\", // align items vertically\r\n width: \"100%\",\r\n },\r\n colorPicker: {\r\n flex: 1,\r\n width: \"350px\",\r\n height: \"350px\",\r\n },\r\n previewColor: {\r\n width: \"60px\",\r\n height: \"60px\",\r\n borderRadius: tokens.borderRadiusMedium, // 4px?\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 inputRow: {\r\n display: \"flex\",\r\n flexDirection: \"row\",\r\n flex: 1, // grow and fill available space\r\n justifyContent: \"center\",\r\n gap: \"10px\",\r\n width: \"100%\",\r\n },\r\n inputField: {\r\n flex: 1, // grow and fill available space\r\n width: \"auto\",\r\n minWidth: 0,\r\n gap: tokens.spacingVerticalSNudge, // 6px\r\n },\r\n trigger: {\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n },\r\n});\r\n\r\nexport type ColorPickerProps<C extends Color3 | Color4> = {\r\n isLinearMode?: boolean;\r\n} & PrimitiveProps<C>;\r\n\r\nexport const ColorPickerPopup = forwardRef<HTMLButtonElement, ColorPickerProps<Color3 | Color4>>((props, ref) => {\r\n ColorPickerPopup.displayName = \"ColorPickerPopup\";\r\n const { value, onChange, isLinearMode, ...rest } = props;\r\n const classes = useColorPickerStyles();\r\n const [color, setColor] = useState(value);\r\n const [isLinear, setIsLinear] = useState(isLinearMode ?? false);\r\n const [isFloat, setFloat] = useState(false);\r\n const { size } = useContext(ToolContext);\r\n useEffect(() => {\r\n setColor(value); // Ensures the trigger color updates when props.value changes\r\n }, [value]);\r\n\r\n const isPropertyLinear = isLinearMode ?? false;\r\n\r\n /** Color in gamma space — used for visual elements (picker, preview, trigger) */\r\n const gammaColor = useMemo(() => (isPropertyLinear ? color.toGammaSpace() : color), [color, isPropertyLinear]);\r\n\r\n /** Color in the user-selected display space — used for numeric inputs (RGB, HSV, Hex) */\r\n const displayColor = useMemo(() => (isLinear === isPropertyLinear ? color : isLinear ? color.toLinearSpace() : color.toGammaSpace()), [color, isLinear, isPropertyLinear]);\r\n\r\n const handleColorPickerChange: FluentColorPickerProps[\"onColorChange\"] = (_, data) => {\r\n // The visual picker always operates in gamma space, convert back to property space\r\n let gammaResult: Color3 | Color4 = Color3.FromHSV(data.color.h, data.color.s, data.color.v);\r\n if (value instanceof Color4) {\r\n gammaResult = Color4.FromColor3(gammaResult, data.color.a ?? 1);\r\n }\r\n handleChange(isPropertyLinear ? gammaResult.toLinearSpace() : gammaResult);\r\n };\r\n\r\n const handleChange = (newColor: Color3 | Color4) => {\r\n setColor(newColor);\r\n onChange(newColor); // Ensures the parent is notified when color changes from within colorPicker\r\n };\r\n\r\n const handleDisplayChange = (newDisplayColor: Color3 | Color4) => {\r\n const propertyColor = isLinear === isPropertyLinear ? newDisplayColor : isLinear ? newDisplayColor.toGammaSpace() : newDisplayColor.toLinearSpace();\r\n handleChange(propertyColor);\r\n };\r\n\r\n return (\r\n <Popover\r\n trigger={\r\n <ColorSwatch\r\n className={classes.trigger}\r\n ref={ref}\r\n {...rest}\r\n borderColor={tokens.colorNeutralShadowKeyDarker}\r\n size={size === \"small\" ? \"extra-small\" : \"small\"}\r\n shape=\"rounded\"\r\n color={gammaColor.toHexString()}\r\n value={gammaColor.toHexString().slice(1)}\r\n />\r\n }\r\n >\r\n <div className={classes.container}>\r\n <FluentColorPicker className={classes.colorPicker} color={rgbaToHsv(gammaColor)} 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 </FluentColorPicker>\r\n {/* Top Row: Preview, Color Space, Data Type */}\r\n <div className={classes.row}>\r\n <div className={classes.previewColor} style={{ backgroundColor: gammaColor.toHexString() }} />\r\n <NumberDropdown\r\n className={classes.inputField}\r\n infoLabel={{\r\n label: \"Color Space\",\r\n info: (\r\n <Body1>\r\n Choose which color space to display numeric values in. This property stores its color in{\" \"}\r\n <Body1Strong>{isPropertyLinear ? \"linear\" : \"gamma\"}</Body1Strong> space. The visual picker always shows gamma (screen-accurate) colors.\r\n </Body1>\r\n ),\r\n }}\r\n options={[\r\n { label: \"Gamma\", value: 0 },\r\n { label: \"Linear\", value: 1 },\r\n ]}\r\n value={isLinear ? 1 : 0}\r\n onChange={(val: number) => setIsLinear(val === 1)}\r\n />\r\n <NumberDropdown\r\n className={classes.inputField}\r\n infoLabel={{\r\n label: \"Data Type\",\r\n info: (\r\n <Body1>\r\n <Body1Strong>Int</Body1Strong> displays RGB channels as integers in the 0–255 range. <Body1Strong>Float</Body1Strong> displays them as decimals\r\n in the 0–1 range. This is display-only and does not affect the stored color.\r\n </Body1>\r\n ),\r\n }}\r\n options={[\r\n { label: \"Int\", value: 0 },\r\n { label: \"Float\", value: 1 },\r\n ]}\r\n value={isFloat ? 1 : 0}\r\n onChange={(val: number) => setFloat(val === 1)}\r\n />\r\n </div>\r\n\r\n {/* Middle Row: Red, Green, Blue, Alpha */}\r\n <div className={classes.inputRow}>\r\n <InputRgbField title=\"Red\" value={displayColor} rgbKey=\"r\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputRgbField title=\"Green\" value={displayColor} rgbKey=\"g\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputRgbField title=\"Blue\" value={displayColor} rgbKey=\"b\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputAlphaField color={color} onChange={handleChange} />\r\n </div>\r\n\r\n {/* Bottom Row: Hue, Saturation, Value */}\r\n <div className={classes.inputRow}>\r\n <InputHsvField title=\"Hue\" value={displayColor} hsvKey=\"h\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputHsvField title=\"Saturation\" value={displayColor} hsvKey=\"s\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputHsvField title=\"Value\" value={displayColor} hsvKey=\"v\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n </div>\r\n\r\n <div className={classes.inputRow}>\r\n <InputHexField title=\"Hexadecimal\" value={displayColor} isLinear={isLinear} ispropertyLinear={isPropertyLinear} onChange={handleDisplayChange} />\r\n </div>\r\n </div>\r\n </Popover>\r\n );\r\n});\r\n\r\nexport type InputHexProps = PrimitiveProps<Color3 | Color4> & {\r\n isLinear?: boolean;\r\n ispropertyLinear?: boolean;\r\n};\r\n\r\n/**\r\n * Converts a hex string to the same Color type as the original.\r\n * Supports \"#RGB\", \"#RRGGBB\", and \"#RRGGBBAA\" formats.\r\n * For Color4, honors alpha from \"#RRGGBBAA\" input or preserves the original alpha otherwise.\r\n * @param hex - The hex string to convert, in one of the supported formats.\r\n * @param original - The original color, used to determine whether to return a Color3 or Color4 and to preserve alpha if not specified in hex.\r\n * @returns A new Color3 or Color4 instance representing the hex color\r\n */\r\nfunction colorFromHex(hex: string, original: Color3 | Color4): Color3 | Color4 {\r\n const digits = hex.startsWith(\"#\") ? hex.slice(1) : hex;\r\n\r\n // Normalize short hex (RGB => RRGGBB)\r\n if (digits.length === 3) {\r\n hex = `#${digits[0]}${digits[0]}${digits[1]}${digits[1]}${digits[2]}${digits[2]}`;\r\n }\r\n\r\n // 8 hex digits = RRGGBBAA — use Color4.FromHexString which natively handles this\r\n if (digits.length === 8) {\r\n if (original instanceof Color4) {\r\n return Color4.FromHexString(hex);\r\n }\r\n return Color3.FromHexString(hex.slice(0, 7));\r\n }\r\n\r\n // 6 hex digits = RRGGBB (or normalized from 3)\r\n if (original instanceof Color4) {\r\n return Color4.FromColor3(Color3.FromHexString(hex), original.a);\r\n }\r\n return Color3.FromHexString(hex);\r\n}\r\n\r\n/**\r\n * Component which displays the passed in color's HEX value in the currently selected color space.\r\n * When the hex color is changed by user, component calculates the new Color3/4 value and calls onChange.\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 classes = useColorPickerStyles();\r\n const { title, value, onChange, isLinear, ispropertyLinear } = props;\r\n\r\n const displayMismatchesproperty = (isLinear ?? false) !== (ispropertyLinear ?? false);\r\n const displaySpace = isLinear ? \"linear\" : \"gamma\";\r\n const propertySpace = ispropertyLinear ? \"linear\" : \"gamma\";\r\n const isColor4 = value instanceof Color4;\r\n const colorClass = isColor4 ? \"Color4\" : \"Color3\";\r\n\r\n return (\r\n <TextInput\r\n className={classes.inputField}\r\n value={value.toHexString()}\r\n validator={ValidateColorHex}\r\n validateOnlyOnBlur\r\n onChange={(val) => onChange(colorFromHex(val, value))}\r\n infoLabel={\r\n title\r\n ? {\r\n label: title,\r\n info: (\r\n <Body1>\r\n This hex value is in <Body1Strong>{displaySpace}</Body1Strong> space\r\n {displayMismatchesproperty ? (\r\n <Body1>\r\n , but the property stores its color in <Body1Strong>{propertySpace}</Body1Strong> space.\r\n <br />\r\n <br />\r\n The color picker converts automatically, but if you copy this hex into code you will need to convert it:\r\n <br />\r\n <Body1Strong>\r\n {colorClass}.FromHexString(\"{value.toHexString()}\").{isLinear ? \"toGammaSpace()\" : \"toLinearSpace()\"}\r\n </Body1Strong>\r\n </Body1>\r\n ) : (\r\n <Body1>\r\n , which matches the property's stored color space.\r\n <br />\r\n <br />\r\n To copy this hex into code, use\r\n <br />\r\n <Body1Strong>\r\n {colorClass}.FromHexString(\"{value.toHexString()}\")\r\n </Body1Strong>\r\n </Body1>\r\n )}\r\n <br />\r\n <br />\r\n <Link url=\"https://doc.babylonjs.com/preparingArtForBabylon/controllingColorSpace/\" value=\"Read more in our docs!\" />\r\n </Body1>\r\n ),\r\n }\r\n : undefined\r\n }\r\n />\r\n );\r\n};\r\n\r\ntype RgbKey = \"r\" | \"g\" | \"b\";\r\ntype InputRgbFieldProps = PrimitiveProps<Color3 | Color4> & {\r\n rgbKey: RgbKey;\r\n isFloat: boolean;\r\n};\r\n\r\nconst InputRgbField: FunctionComponent<InputRgbFieldProps> = (props) => {\r\n const { value, onChange, title, rgbKey, isFloat } = props;\r\n const classes = useColorPickerStyles();\r\n\r\n const handleChange = useCallback(\r\n (val: number) => {\r\n const newColor = value.clone();\r\n newColor[rgbKey] = isFloat ? val : val / 255.0;\r\n onChange(newColor);\r\n },\r\n [value, onChange, rgbKey, isFloat]\r\n );\r\n\r\n return (\r\n <SpinButton\r\n key={`${rgbKey}-${isFloat ? \"float\" : \"int\"}`} // ensures remount when swapping between int/float, preserving min/max validation\r\n infoLabel={title ? { label: title } : undefined}\r\n className={classes.inputField}\r\n min={0}\r\n max={isFloat ? 1 : 255}\r\n value={isFloat ? value[rgbKey] : Math.round(value[rgbKey] * 255)}\r\n step={isFloat ? 0.01 : 1}\r\n forceInt={!isFloat}\r\n precision={isFloat ? 4 : undefined}\r\n onChange={handleChange}\r\n />\r\n );\r\n};\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\r\ntype HsvKey = \"h\" | \"s\" | \"v\";\r\ntype InputHsvFieldProps = PrimitiveProps<Color3 | Color4> & {\r\n hsvKey: HsvKey;\r\n isFloat: boolean;\r\n};\r\n\r\n// Internal HSV ranges: H ∈ [0,360], S ∈ [0,1], V ∈ [0,1]\r\n// Int mode display: H → 0-360, S → 0-100, V → 0-100\r\n// Float mode display: H → 0-1, S → 0-1, V → 0-1\r\nfunction getHsvDisplayParams(hsvKey: HsvKey, isFloat: boolean) {\r\n if (isFloat) {\r\n // All channels displayed as 0-1\r\n const internalMax = hsvKey === \"h\" ? 360 : 1;\r\n return { max: 1, toDisplay: (v: number) => v / internalMax, toInternal: (v: number) => v * internalMax, step: 0.01, forceInt: false, precision: 4 };\r\n }\r\n // Int mode\r\n const scale = hsvKey === \"h\" ? 1 : 100;\r\n const max = hsvKey === \"h\" ? 360 : 100;\r\n return { max, toDisplay: (v: number) => Math.round(v * scale), toInternal: (v: number) => v / scale, step: 1, forceInt: true, precision: undefined };\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 { value, title, hsvKey, isFloat, onChange } = props;\r\n\r\n const classes = useColorPickerStyles();\r\n const { max, toDisplay, toInternal, step, forceInt, precision } = getHsvDisplayParams(hsvKey, isFloat);\r\n\r\n const handleChange = useCallback(\r\n (val: number) => {\r\n const hsv = rgbaToHsv(value);\r\n hsv[hsvKey] = toInternal(val);\r\n let newColor: Color3 | Color4 = Color3.FromHSV(hsv.h, hsv.s, hsv.v);\r\n if (value instanceof Color4) {\r\n newColor = Color4.FromColor3(newColor, value.a ?? 1);\r\n }\r\n props.onChange(newColor);\r\n },\r\n [value, onChange, hsvKey, toInternal]\r\n );\r\n\r\n return (\r\n <SpinButton\r\n key={`${hsvKey}-${isFloat ? \"float\" : \"int\"}`} // ensures remount when swapping between int/float, preserving min/max validation\r\n infoLabel={title ? { label: title } : undefined}\r\n className={classes.inputField}\r\n min={0}\r\n max={max}\r\n value={toDisplay(rgbaToHsv(value)[hsvKey])}\r\n step={step}\r\n forceInt={forceInt}\r\n precision={precision}\r\n onChange={handleChange}\r\n />\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 { color, onChange } = props;\r\n\r\n const handleChange = useCallback(\r\n (value: number) => {\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 onChange(newColor);\r\n } else {\r\n onChange(Color4.FromColor3(color, value));\r\n }\r\n },\r\n [color, onChange]\r\n );\r\n\r\n return (\r\n <SpinButton\r\n disabled={color instanceof Color3}\r\n min={0}\r\n max={1}\r\n className={classes.inputField}\r\n value={color instanceof Color3 ? 1 : color.a}\r\n step={0.01}\r\n onChange={handleChange}\r\n infoLabel={{\r\n label: \"Alpha\",\r\n info:\r\n color instanceof Color3 ? (\r\n <Body1>\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 property's alpha\r\n property directly, either in code via property.alpha OR via inspector's transparency section.\r\n </Body1>\r\n ) : undefined,\r\n }}\r\n />\r\n );\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,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE1F,OAAO,EAAE,WAAW,IAAI,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAExK,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,yCAA8B;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,OAAO,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Y,EACtB,SAAS,EAAE;YACP,KAAK,EAAE,OAAO;YACd,IAAI,EACA,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,CACtB,KAAC,KAAK,wQAGE,CACX,CAAC,CAAC,CAAC,SAAS;SACpB,GACH,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["/* eslint-disable jsdoc/require-returns */\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { forwardRef, useState, useEffect, useCallback, useContext, useMemo } from \"react\";\r\nimport type { FunctionComponent } from \"react\";\r\nimport { ColorPicker as FluentColorPicker, ColorSlider, ColorArea, AlphaSlider, makeStyles, tokens, Body1Strong, ColorSwatch, Body1 } from \"@fluentui/react-components\";\r\nimport type { ColorPickerProps as FluentColorPickerProps } from \"@fluentui/react-components\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { PrimitiveProps } from \"./primitive\";\r\nimport { SpinButton } from \"./spinButton\";\r\nimport { TextInput } from \"./textInput\";\r\nimport { NumberDropdown } from \"./dropdown\";\r\nimport { ValidateColorHex } from \"./utils\";\r\nimport { Link } from \"./link\";\r\nimport { ToolContext } from \"../hoc/fluentToolWrapper\";\r\nimport { Popover } from \"./popover\";\r\n\r\nconst useColorPickerStyles = makeStyles({\r\n container: {\r\n width: \"350px\",\r\n display: \"flex\", // becomes a flexbox\r\n flexDirection: \"column\", // with children in a column\r\n alignItems: \"center\", // centers children horizontally\r\n justifyContent: \"center\", // centers children vertically (if height is set)\r\n gap: tokens.spacingVerticalM,\r\n overflow: \"visible\",\r\n },\r\n row: {\r\n flex: 1, // is a row in the container's flex column\r\n display: \"flex\", // becomes its own flexbox\r\n flexDirection: \"row\", // with children in a row\r\n gap: tokens.spacingHorizontalXL,\r\n alignItems: \"center\", // align items vertically\r\n width: \"100%\",\r\n },\r\n colorPicker: {\r\n flex: 1,\r\n width: \"350px\",\r\n height: \"350px\",\r\n },\r\n previewColor: {\r\n width: \"60px\",\r\n height: \"60px\",\r\n borderRadius: tokens.borderRadiusMedium, // 4px?\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 inputRow: {\r\n display: \"flex\",\r\n flexDirection: \"row\",\r\n flex: 1, // grow and fill available space\r\n justifyContent: \"center\",\r\n gap: \"10px\",\r\n width: \"100%\",\r\n },\r\n inputField: {\r\n flex: 1, // grow and fill available space\r\n width: \"auto\",\r\n minWidth: 0,\r\n gap: tokens.spacingVerticalSNudge, // 6px\r\n },\r\n trigger: {\r\n display: \"flex\",\r\n alignItems: \"center\",\r\n },\r\n});\r\n\r\nexport type ColorPickerProps<C extends Color3 | Color4> = {\r\n isLinearMode?: boolean;\r\n} & PrimitiveProps<C>;\r\n\r\nexport const ColorPickerPopup = forwardRef<HTMLButtonElement, ColorPickerProps<Color3 | Color4>>((props, ref) => {\r\n ColorPickerPopup.displayName = \"ColorPickerPopup\";\r\n const { value, onChange, isLinearMode, ...rest } = props;\r\n const classes = useColorPickerStyles();\r\n const [color, setColor] = useState(value);\r\n const [isLinear, setIsLinear] = useState(isLinearMode ?? false);\r\n const [isFloat, setFloat] = useState(false);\r\n const { size } = useContext(ToolContext);\r\n useEffect(() => {\r\n setColor(value); // Ensures the trigger color updates when props.value changes\r\n }, [value]);\r\n\r\n const isPropertyLinear = isLinearMode ?? false;\r\n\r\n /** Color in gamma space — used for visual elements (picker, preview, trigger) */\r\n const gammaColor = useMemo(() => (isPropertyLinear ? color.toGammaSpace() : color), [color, isPropertyLinear]);\r\n\r\n /** Color in the user-selected display space — used for numeric inputs (RGB, HSV, Hex) */\r\n const displayColor = useMemo(() => {\r\n if (isLinear === isPropertyLinear) {\r\n return color;\r\n }\r\n return isLinear ? color.toLinearSpace() : color.toGammaSpace();\r\n }, [color, isLinear, isPropertyLinear]);\r\n\r\n const handleColorPickerChange: FluentColorPickerProps[\"onColorChange\"] = (_, data) => {\r\n // The visual picker always operates in gamma space, convert back to property space\r\n let gammaResult: Color3 | Color4 = Color3.FromHSV(data.color.h, data.color.s, data.color.v);\r\n if (value instanceof Color4) {\r\n gammaResult = Color4.FromColor3(gammaResult, data.color.a ?? 1);\r\n }\r\n handleChange(isPropertyLinear ? gammaResult.toLinearSpace() : gammaResult);\r\n };\r\n\r\n const handleChange = (newColor: Color3 | Color4) => {\r\n setColor(newColor);\r\n onChange(newColor); // Ensures the parent is notified when color changes from within colorPicker\r\n };\r\n\r\n const handleDisplayChange = (newDisplayColor: Color3 | Color4) => {\r\n const propertyColor = isLinear === isPropertyLinear ? newDisplayColor : isLinear ? newDisplayColor.toGammaSpace() : newDisplayColor.toLinearSpace();\r\n handleChange(propertyColor);\r\n };\r\n\r\n return (\r\n <Popover\r\n trigger={\r\n <ColorSwatch\r\n className={classes.trigger}\r\n ref={ref}\r\n {...rest}\r\n borderColor={tokens.colorNeutralShadowKeyDarker}\r\n size={size === \"small\" ? \"extra-small\" : \"small\"}\r\n shape=\"rounded\"\r\n color={gammaColor.toHexString()}\r\n value={gammaColor.toHexString().slice(1)}\r\n />\r\n }\r\n >\r\n <div className={classes.container}>\r\n <FluentColorPicker className={classes.colorPicker} color={rgbaToHsv(gammaColor)} 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 </FluentColorPicker>\r\n {/* Top Row: Preview, Color Space, Data Type */}\r\n <div className={classes.row}>\r\n <div className={classes.previewColor} style={{ backgroundColor: gammaColor.toHexString() }} />\r\n <NumberDropdown\r\n className={classes.inputField}\r\n infoLabel={{\r\n label: \"Color Space\",\r\n info: (\r\n <Body1>\r\n Choose which color space to display numeric values in. This property stores its color in{\" \"}\r\n <Body1Strong>{isPropertyLinear ? \"linear\" : \"gamma\"}</Body1Strong> space. The visual picker always shows gamma (screen-accurate) colors.\r\n </Body1>\r\n ),\r\n }}\r\n options={[\r\n { label: \"Gamma\", value: 0 },\r\n { label: \"Linear\", value: 1 },\r\n ]}\r\n value={isLinear ? 1 : 0}\r\n onChange={(val: number) => setIsLinear(val === 1)}\r\n />\r\n <NumberDropdown\r\n className={classes.inputField}\r\n infoLabel={{\r\n label: \"Data Type\",\r\n info: (\r\n <Body1>\r\n <Body1Strong>Int</Body1Strong> displays RGB channels as integers in the 0–255 range. <Body1Strong>Float</Body1Strong> displays them as decimals\r\n in the 0–1 range. This is display-only and does not affect the stored color.\r\n </Body1>\r\n ),\r\n }}\r\n options={[\r\n { label: \"Int\", value: 0 },\r\n { label: \"Float\", value: 1 },\r\n ]}\r\n value={isFloat ? 1 : 0}\r\n onChange={(val: number) => setFloat(val === 1)}\r\n />\r\n </div>\r\n\r\n {/* Middle Row: Red, Green, Blue, Alpha */}\r\n <div className={classes.inputRow}>\r\n <InputRgbField title=\"Red\" value={displayColor} rgbKey=\"r\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputRgbField title=\"Green\" value={displayColor} rgbKey=\"g\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputRgbField title=\"Blue\" value={displayColor} rgbKey=\"b\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputAlphaField color={color} onChange={handleChange} />\r\n </div>\r\n\r\n {/* Bottom Row: Hue, Saturation, Value */}\r\n <div className={classes.inputRow}>\r\n <InputHsvField title=\"Hue\" value={displayColor} hsvKey=\"h\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputHsvField title=\"Saturation\" value={displayColor} hsvKey=\"s\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n <InputHsvField title=\"Value\" value={displayColor} hsvKey=\"v\" isFloat={isFloat} onChange={handleDisplayChange} />\r\n </div>\r\n\r\n <div className={classes.inputRow}>\r\n <InputHexField title=\"Hexadecimal\" value={displayColor} isLinear={isLinear} isPropertyLinear={isPropertyLinear} onChange={handleDisplayChange} />\r\n </div>\r\n </div>\r\n </Popover>\r\n );\r\n});\r\n\r\nexport type InputHexProps = PrimitiveProps<Color3 | Color4> & {\r\n isLinear?: boolean;\r\n isPropertyLinear?: boolean;\r\n};\r\n\r\n/**\r\n * Converts a hex string to the same Color type as the original.\r\n * Supports \"#RGB\", \"#RRGGBB\", and \"#RRGGBBAA\" formats.\r\n * For Color4, honors alpha from \"#RRGGBBAA\" input or preserves the original alpha otherwise.\r\n * @param hex - The hex string to convert, in one of the supported formats.\r\n * @param original - The original color, used to determine whether to return a Color3 or Color4 and to preserve alpha if not specified in hex.\r\n * @returns A new Color3 or Color4 instance representing the hex color\r\n */\r\nfunction colorFromHex(hex: string, original: Color3 | Color4): Color3 | Color4 {\r\n const digits = hex.startsWith(\"#\") ? hex.slice(1) : hex;\r\n\r\n // Normalize short hex (RGB => RRGGBB)\r\n if (digits.length === 3) {\r\n hex = `#${digits[0]}${digits[0]}${digits[1]}${digits[1]}${digits[2]}${digits[2]}`;\r\n }\r\n\r\n // 8 hex digits = RRGGBBAA — use Color4.FromHexString which natively handles this\r\n if (digits.length === 8) {\r\n if (original instanceof Color4) {\r\n return Color4.FromHexString(hex);\r\n }\r\n return Color3.FromHexString(hex.slice(0, 7));\r\n }\r\n\r\n // 6 hex digits = RRGGBB (or normalized from 3)\r\n if (original instanceof Color4) {\r\n return Color4.FromColor3(Color3.FromHexString(hex), original.a);\r\n }\r\n return Color3.FromHexString(hex);\r\n}\r\n\r\n/**\r\n * Component which displays the passed in color's HEX value in the currently selected color space.\r\n * When the hex color is changed by user, component calculates the new Color3/4 value and calls onChange.\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 classes = useColorPickerStyles();\r\n const { title, value, onChange, isLinear, isPropertyLinear } = props;\r\n\r\n const displayMismatchesProperty = (isLinear ?? false) !== (isPropertyLinear ?? false);\r\n const displaySpace = isLinear ? \"linear\" : \"gamma\";\r\n const propertySpace = isPropertyLinear ? \"linear\" : \"gamma\";\r\n const isColor4 = value instanceof Color4;\r\n const colorClass = isColor4 ? \"Color4\" : \"Color3\";\r\n\r\n return (\r\n <TextInput\r\n className={classes.inputField}\r\n value={value.toHexString()}\r\n validator={ValidateColorHex}\r\n validateOnlyOnBlur\r\n onChange={(val) => onChange(colorFromHex(val, value))}\r\n infoLabel={\r\n title\r\n ? {\r\n label: title,\r\n info: (\r\n <Body1>\r\n This hex value is in <Body1Strong>{displaySpace}</Body1Strong> space\r\n {displayMismatchesProperty ? (\r\n <Body1>\r\n , but the property stores its color in <Body1Strong>{propertySpace}</Body1Strong> space.\r\n <br />\r\n <br />\r\n The color picker converts automatically, but if you copy this hex into code you will need to convert it:\r\n <br />\r\n <Body1Strong>\r\n {colorClass}.FromHexString(\"{value.toHexString()}\").{isLinear ? \"toGammaSpace()\" : \"toLinearSpace()\"}\r\n </Body1Strong>\r\n </Body1>\r\n ) : (\r\n <Body1>\r\n , which matches the property's stored color space.\r\n <br />\r\n <br />\r\n To copy this hex into code, use\r\n <br />\r\n <Body1Strong>\r\n {colorClass}.FromHexString(\"{value.toHexString()}\")\r\n </Body1Strong>\r\n </Body1>\r\n )}\r\n <br />\r\n <br />\r\n <Link url=\"https://doc.babylonjs.com/preparingArtForBabylon/controllingColorSpace/\" value=\"Read more in our docs!\" />\r\n </Body1>\r\n ),\r\n }\r\n : undefined\r\n }\r\n />\r\n );\r\n};\r\n\r\ntype RgbKey = \"r\" | \"g\" | \"b\";\r\ntype InputRgbFieldProps = PrimitiveProps<Color3 | Color4> & {\r\n rgbKey: RgbKey;\r\n isFloat: boolean;\r\n};\r\n\r\nconst InputRgbField: FunctionComponent<InputRgbFieldProps> = (props) => {\r\n const { value, onChange, title, rgbKey, isFloat } = props;\r\n const classes = useColorPickerStyles();\r\n\r\n const handleChange = useCallback(\r\n (val: number) => {\r\n const newColor = value.clone();\r\n newColor[rgbKey] = isFloat ? val : val / 255.0;\r\n onChange(newColor);\r\n },\r\n [value, onChange, rgbKey, isFloat]\r\n );\r\n\r\n return (\r\n <SpinButton\r\n key={`${rgbKey}-${isFloat ? \"float\" : \"int\"}`} // ensures remount when swapping between int/float, preserving min/max validation\r\n infoLabel={title ? { label: title } : undefined}\r\n className={classes.inputField}\r\n min={0}\r\n max={isFloat ? 1 : 255}\r\n value={isFloat ? value[rgbKey] : Math.round(value[rgbKey] * 255)}\r\n step={isFloat ? 0.01 : 1}\r\n forceInt={!isFloat}\r\n precision={isFloat ? 4 : undefined}\r\n onChange={handleChange}\r\n />\r\n );\r\n};\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\r\ntype HsvKey = \"h\" | \"s\" | \"v\";\r\ntype InputHsvFieldProps = PrimitiveProps<Color3 | Color4> & {\r\n hsvKey: HsvKey;\r\n isFloat: boolean;\r\n};\r\n\r\n// Internal HSV ranges: H ∈ [0,360], S ∈ [0,1], V ∈ [0,1]\r\n// Int mode display: H → 0-360, S → 0-100, V → 0-100\r\n// Float mode display: H → 0-1, S → 0-1, V → 0-1\r\nfunction getHsvDisplayParams(hsvKey: HsvKey, isFloat: boolean) {\r\n if (isFloat) {\r\n // All channels displayed as 0-1\r\n const internalMax = hsvKey === \"h\" ? 360 : 1;\r\n return { max: 1, toDisplay: (v: number) => v / internalMax, toInternal: (v: number) => v * internalMax, step: 0.01, forceInt: false, precision: 4 };\r\n }\r\n // Int mode\r\n const scale = hsvKey === \"h\" ? 1 : 100;\r\n const max = hsvKey === \"h\" ? 360 : 100;\r\n return { max, toDisplay: (v: number) => Math.round(v * scale), toInternal: (v: number) => v / scale, step: 1, forceInt: true, precision: undefined };\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 { value, title, hsvKey, isFloat, onChange } = props;\r\n\r\n const classes = useColorPickerStyles();\r\n const { max, toDisplay, toInternal, step, forceInt, precision } = getHsvDisplayParams(hsvKey, isFloat);\r\n\r\n const handleChange = useCallback(\r\n (val: number) => {\r\n const hsv = rgbaToHsv(value);\r\n hsv[hsvKey] = toInternal(val);\r\n let newColor: Color3 | Color4 = Color3.FromHSV(hsv.h, hsv.s, hsv.v);\r\n if (value instanceof Color4) {\r\n newColor = Color4.FromColor3(newColor, value.a ?? 1);\r\n }\r\n props.onChange(newColor);\r\n },\r\n [value, onChange, hsvKey, toInternal]\r\n );\r\n\r\n return (\r\n <SpinButton\r\n key={`${hsvKey}-${isFloat ? \"float\" : \"int\"}`} // ensures remount when swapping between int/float, preserving min/max validation\r\n infoLabel={title ? { label: title } : undefined}\r\n className={classes.inputField}\r\n min={0}\r\n max={max}\r\n value={toDisplay(rgbaToHsv(value)[hsvKey])}\r\n step={step}\r\n forceInt={forceInt}\r\n precision={precision}\r\n onChange={handleChange}\r\n />\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 { color, onChange } = props;\r\n\r\n const handleChange = useCallback(\r\n (value: number) => {\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 onChange(newColor);\r\n } else {\r\n onChange(Color4.FromColor3(color, value));\r\n }\r\n },\r\n [color, onChange]\r\n );\r\n\r\n return (\r\n <SpinButton\r\n disabled={color instanceof Color3}\r\n min={0}\r\n max={1}\r\n className={classes.inputField}\r\n value={color instanceof Color3 ? 1 : color.a}\r\n step={0.01}\r\n onChange={handleChange}\r\n infoLabel={{\r\n label: \"Alpha\",\r\n info:\r\n color instanceof Color3 ? (\r\n <Body1>\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 property's alpha\r\n property directly, either in code via property.alpha OR via inspector's transparency section.\r\n </Body1>\r\n ) : undefined,\r\n }}\r\n />\r\n );\r\n};\r\n"]}
@@ -17,8 +17,10 @@ export const TextInput = (props) => {
17
17
  }
18
18
  }, [props.value]);
19
19
  const validateValue = (val) => {
20
- const failsValidator = props.validator && !props.validator(val);
21
- return !failsValidator;
20
+ if (!props.validator) {
21
+ return true;
22
+ }
23
+ return props.validator(val);
22
24
  };
23
25
  const tryCommitValue = (currVal) => {
24
26
  // Only commit if valid and different from last committed value
@@ -1 +1 @@
1
- {"version":3,"file":"textInput.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/textInput.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEvF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAOvD,MAAM,CAAC,MAAM,SAAS,GAAsC,CAAC,KAAK,EAAE,EAAE;IAClE,SAAS,CAAC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,EACnE,KAAC,WAAW,OACJ,KAAK,EACT,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,EACvC,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,eAAe,GAC5B,IACA,CACT,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { FunctionComponent, KeyboardEvent, ChangeEvent, FocusEvent } from \"react\";\r\nimport { useContext, useEffect, useRef, useState } from \"react\";\r\nimport type { InputOnChangeData } from \"@fluentui/react-components\";\r\nimport { Input as FluentInput, mergeClasses, useId } from \"@fluentui/react-components\";\r\nimport type { PrimitiveProps } from \"./primitive\";\r\nimport { InfoLabel } from \"./infoLabel\";\r\nimport { HandleKeyDown, HandleOnBlur, useInputStyles } from \"./utils\";\r\nimport { ToolContext } from \"../hoc/fluentToolWrapper\";\r\n\r\nexport type TextInputProps = PrimitiveProps<string> & {\r\n validator?: (value: string) => boolean;\r\n validateOnlyOnBlur?: boolean;\r\n};\r\n\r\nexport const TextInput: FunctionComponent<TextInputProps> = (props) => {\r\n TextInput.displayName = \"TextInput\";\r\n const classes = useInputStyles();\r\n const [value, setValue] = useState(props.value);\r\n const lastCommittedValue = useRef(props.value);\r\n const { size } = useContext(ToolContext);\r\n useEffect(() => {\r\n if (props.value !== lastCommittedValue.current) {\r\n setValue(props.value); // Update local state when props.value changes\r\n lastCommittedValue.current = props.value;\r\n }\r\n }, [props.value]);\r\n\r\n const validateValue = (val: string): boolean => {\r\n const failsValidator = props.validator && !props.validator(val);\r\n return !failsValidator;\r\n };\r\n\r\n const tryCommitValue = (currVal: string) => {\r\n // Only commit if valid and different from last committed value\r\n if (validateValue(currVal) && currVal !== lastCommittedValue.current) {\r\n lastCommittedValue.current = currVal;\r\n props.onChange(currVal);\r\n }\r\n };\r\n\r\n const handleChange = (event: ChangeEvent<HTMLInputElement>, data: InputOnChangeData) => {\r\n event.stopPropagation();\r\n setValue(data.value);\r\n if (!props.validateOnlyOnBlur) {\r\n tryCommitValue(data.value);\r\n }\r\n };\r\n\r\n const handleKeyUp = (event: KeyboardEvent<HTMLInputElement>) => {\r\n event.stopPropagation();\r\n if (!props.validateOnlyOnBlur) {\r\n tryCommitValue(event.currentTarget.value);\r\n }\r\n };\r\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\r\n HandleKeyDown(event);\r\n // When validateOnlyOnBlur is set, also commit on Enter for better UX\r\n if (event.key === \"Enter\" && props.validateOnlyOnBlur) {\r\n tryCommitValue(event.currentTarget.value);\r\n }\r\n };\r\n\r\n const handleBlur = (event: FocusEvent<HTMLInputElement>) => {\r\n HandleOnBlur(event);\r\n if (props.validateOnlyOnBlur) {\r\n tryCommitValue(event.currentTarget.value);\r\n }\r\n };\r\n\r\n const mergedClassName = mergeClasses(classes.inputFill, !validateValue(value) ? classes.invalid : \"\");\r\n\r\n const id = useId(\"input-button\");\r\n return (\r\n <div className={mergeClasses(classes.container, props.className)}>\r\n {props.infoLabel && <InfoLabel {...props.infoLabel} htmlFor={id} />}\r\n <FluentInput\r\n {...props}\r\n input={{ className: classes.inputSlot }}\r\n id={id}\r\n size={size}\r\n value={value}\r\n onChange={handleChange}\r\n onKeyUp={handleKeyUp}\r\n onKeyDown={handleKeyDown}\r\n onBlur={handleBlur}\r\n className={mergedClassName}\r\n />\r\n </div>\r\n );\r\n};\r\n"]}
1
+ {"version":3,"file":"textInput.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/textInput.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC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AE,CAAC,CAAC;IAEtG,MAAM,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC;IACjC,OAAO,CACH,eAAK,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,aAC3D,KAAK,CAAC,SAAS,IAAI,KAAC,SAAS,OAAK,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,GAAI,EACnE,KAAC,WAAW,OACJ,KAAK,EACT,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,EACvC,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,eAAe,GAC5B,IACA,CACT,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { FunctionComponent, KeyboardEvent, ChangeEvent, FocusEvent } from \"react\";\r\nimport { useContext, useEffect, useRef, useState } from \"react\";\r\nimport type { InputOnChangeData } from \"@fluentui/react-components\";\r\nimport { Input as FluentInput, mergeClasses, useId } from \"@fluentui/react-components\";\r\nimport type { PrimitiveProps } from \"./primitive\";\r\nimport { InfoLabel } from \"./infoLabel\";\r\nimport { HandleKeyDown, HandleOnBlur, useInputStyles } from \"./utils\";\r\nimport { ToolContext } from \"../hoc/fluentToolWrapper\";\r\n\r\nexport type TextInputProps = PrimitiveProps<string> & {\r\n validator?: (value: string) => boolean;\r\n validateOnlyOnBlur?: boolean;\r\n};\r\n\r\nexport const TextInput: FunctionComponent<TextInputProps> = (props) => {\r\n TextInput.displayName = \"TextInput\";\r\n const classes = useInputStyles();\r\n const [value, setValue] = useState(props.value);\r\n const lastCommittedValue = useRef(props.value);\r\n const { size } = useContext(ToolContext);\r\n useEffect(() => {\r\n if (props.value !== lastCommittedValue.current) {\r\n setValue(props.value); // Update local state when props.value changes\r\n lastCommittedValue.current = props.value;\r\n }\r\n }, [props.value]);\r\n\r\n const validateValue = (val: string): boolean => {\r\n if (!props.validator) {\r\n return true;\r\n }\r\n return props.validator(val);\r\n };\r\n\r\n const tryCommitValue = (currVal: string) => {\r\n // Only commit if valid and different from last committed value\r\n if (validateValue(currVal) && currVal !== lastCommittedValue.current) {\r\n lastCommittedValue.current = currVal;\r\n props.onChange(currVal);\r\n }\r\n };\r\n\r\n const handleChange = (event: ChangeEvent<HTMLInputElement>, data: InputOnChangeData) => {\r\n event.stopPropagation();\r\n setValue(data.value);\r\n if (!props.validateOnlyOnBlur) {\r\n tryCommitValue(data.value);\r\n }\r\n };\r\n\r\n const handleKeyUp = (event: KeyboardEvent<HTMLInputElement>) => {\r\n event.stopPropagation();\r\n if (!props.validateOnlyOnBlur) {\r\n tryCommitValue(event.currentTarget.value);\r\n }\r\n };\r\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\r\n HandleKeyDown(event);\r\n // When validateOnlyOnBlur is set, also commit on Enter for better UX\r\n if (event.key === \"Enter\" && props.validateOnlyOnBlur) {\r\n tryCommitValue(event.currentTarget.value);\r\n }\r\n };\r\n\r\n const handleBlur = (event: FocusEvent<HTMLInputElement>) => {\r\n HandleOnBlur(event);\r\n if (props.validateOnlyOnBlur) {\r\n tryCommitValue(event.currentTarget.value);\r\n }\r\n };\r\n\r\n const mergedClassName = mergeClasses(classes.inputFill, !validateValue(value) ? classes.invalid : \"\");\r\n\r\n const id = useId(\"input-button\");\r\n return (\r\n <div className={mergeClasses(classes.container, props.className)}>\r\n {props.infoLabel && <InfoLabel {...props.infoLabel} htmlFor={id} />}\r\n <FluentInput\r\n {...props}\r\n input={{ className: classes.inputSlot }}\r\n id={id}\r\n size={size}\r\n value={value}\r\n onChange={handleChange}\r\n onKeyUp={handleKeyUp}\r\n onKeyDown={handleKeyDown}\r\n onBlur={handleBlur}\r\n className={mergedClassName}\r\n />\r\n </div>\r\n );\r\n};\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onerjs/shared-ui-components",
3
- "version": "8.43.1",
3
+ "version": "8.43.3",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",