UNPKG

@octopusdeploy/design-system-components

Version:
91 lines (90 loc) 5.84 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.TextField = TextField; const jsx_runtime_1 = require("react/jsx-runtime"); const css_1 = require("@emotion/css"); const design_system_tokens_1 = require("@octopusdeploy/design-system-tokens"); const React = __importStar(require("react")); const FormDescription_1 = require("../Primitives/FormDescription"); const Input_1 = require("../Primitives/Input"); const InputLabel_1 = require("../Primitives/InputLabel"); const InputValidationMessage_1 = require("../Primitives/InputValidationMessage"); /** * TextField component * @remarks Rollout currently paused — do not use in new code until further notice. * Use `<Text>` instead. * @see <Text> * * @param props - TextFieldProps * @param props.label - The label for the input field * @param props.value - The current value of the input * @param props.type - The input type (text, email, password, etc.) * @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.validationState - The validation state ('error' | 'success'). Only applied when a `validationMessage` is provided; defaults to 'error' in that case. * @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.onChange - The action to perform when the form control field is changed * * @returns TextField component */ function TextField(props) { const { label, value, placeholder, description, validationMessage, validationState, onChange, disabled = false, hasRequiredMarker = false, hasOptionalMarker = false, hasDefaultMarker = false, popover, type = "text", autoFocus = false, readOnly = false, name, prefix, suffix, } = props; // min, max, step only when type is "number" const min = props.type === "number" ? props.min : undefined; const max = props.type === "number" ? props.max : undefined; const step = props.type === "number" ? props.step : undefined; const baseId = React.useId(); const inputId = `textfield-${name ? name + "-" : ""}${baseId}`; const validationDisplayState = validationMessage ? (validationState ?? "error") : "none"; return ((0, jsx_runtime_1.jsxs)("div", { className: (0, css_1.cx)(containerStyles), children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(InputLabel_1.InputLabel, { label: label, htmlFor: inputId, isDisabled: disabled, hasRequiredMarker: hasRequiredMarker, hasOptionalMarker: hasOptionalMarker, hasDefaultMarker: hasDefaultMarker, popover: popover }), description && (0, jsx_runtime_1.jsx)(FormDescription_1.FormDescription, { id: `${inputId}-description`, description: description, isDisabled: disabled })] }), (0, jsx_runtime_1.jsx)(Input_1.Input, { id: inputId, type: type, value: value, placeholder: placeholder, disabled: disabled, required: hasRequiredMarker, readOnly: readOnly, autoFocus: autoFocus, min: min, max: max, step: step, name: name, prefix: prefix, suffix: suffix, onChange: onChange, "aria-describedby": [description ? `${inputId}-description` : null, validationMessage ? `${inputId}-validation` : null].filter(Boolean).join(" ") || undefined, validationDisplayState: validationDisplayState }), (0, jsx_runtime_1.jsx)(InputValidationMessage_1.InputValidationMessage, { message: validationMessage, displayState: validationDisplayState, id: `${inputId}-validation` })] })); } const containerStyles = (0, css_1.css)({ display: "grid", position: "relative", gap: design_system_tokens_1.space[8], width: "100%", maxWidth: "600px", });