UNPKG

@octopusdeploy/design-system-components

Version:
82 lines (81 loc) 4.53 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberField = NumberField; const jsx_runtime_1 = require("react/jsx-runtime"); const React = __importStar(require("react")); const TextField_1 = require("../TextField/TextField"); const parseHelpers_1 = require("../utils/parseHelpers"); /** * NumberField A form input for entering numbers. * * @remarks Rollout currently paused — do not use in new code until further notice. * Use `<Text>` instead. * @see <DeprecatedNumber> from @octopusdeploy/design-system-octopus-components * * @param props - NumberFieldProps * @param props.label - The label for the input field * @param props.value - The current value of the input * @param props.placeholder - The placeholder text to display when input is empty * @param props.description - The description text to display below the input * @param props.validationMessage - Validation message to display * @param props.disabled - Whether the field is disabled * @param props.hasRequiredMarker - Whether the field is required * @param props.hasOptionalMarker - Whether to show optional marker * @param props.hasDefaultMarker - Whether this field has a default value marker * @param props.popover - PopoverBasicHelp component to display additional help information e.g. <PopoverBasicHelp placement="right-start" description="A popover" /> * @param props.autoFocus - Whether to autofocus the input * @param props.readOnly - Whether the input is readonly * @param props.name - The name attribute for the input * @param props.prefix - The prefix to display before the input - can be a string or a icon it cannot be interactive * @param props.suffix - The suffix to display after the input - can be a string or a button with ghost importance and medium size only * @param props.min - The minimum value allowed * @param props.max - The maximum value allowed * @param props.step - The step value for the number input * @param props.onChange - The action to perform when the form control field is changed * * @returns NumberField component */ function NumberField(props) { const { label, value, placeholder, description, validationMessage, disabled = false, hasRequiredMarker = false, hasOptionalMarker = false, hasDefaultMarker = false, popover, autoFocus = false, readOnly = false, name, prefix, suffix, min, max, step, onChange, } = props; const handleChange = React.useCallback((newValue) => { const parsedNumber = newValue ? (0, parseHelpers_1.safeParseFloat)(String(newValue), 0) : undefined; if (onChange) { onChange(parsedNumber); } }, [onChange]); return ((0, jsx_runtime_1.jsx)(TextField_1.TextField, { type: "number", label: label, value: value, placeholder: placeholder, description: description, validationMessage: validationMessage, disabled: disabled, hasRequiredMarker: hasRequiredMarker, hasOptionalMarker: hasOptionalMarker, hasDefaultMarker: hasDefaultMarker, popover: popover, autoFocus: autoFocus, readOnly: readOnly, name: name, prefix: prefix, suffix: suffix, min: min, max: max, step: step, onChange: handleChange })); } exports.default = NumberField;