UNPKG

kwikid-components-react

Version:

KwikID's Component Library in React

538 lines (529 loc) 16.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.WithValidation = exports.TextCases = exports.Sizes = exports.Shapes = exports.Disabled = exports.Default = exports.CopyPasteRestricted = void 0; var _react = _interopRequireDefault(require("react")); var _Textarea = _interopRequireDefault(require("./Textarea")); var _Textarea2 = require("./Textarea.constants"); var _Textarea3 = require("./Textarea.defaults"); const _excluded = ["value", "messages", "onInput", "onInputValidate", "onInputCopyDisabled", "onInputPasteDisabled"]; function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } /** * The Textarea component is a multi-line text input field that allows users to enter longer text content. * It supports various shapes, sizes, and validation features for your forms. * * ## Usage * * ```jsx * import { KwikUITextarea } from 'react-kwikui'; * * const [value, setValue] = useState(''); * * const handleInput = (id, value) => { * setValue(value); * }; * * <KwikUITextarea * id="feedback" * label="Your Feedback" * placeholder="Please share your thoughts..." * value={value} * onInput={handleInput} * /> * ``` */ var _default = exports.default = { title: "KwikUI/Inputs/Textarea", component: _Textarea.default, parameters: { componentSubtitle: "Multi-line text input field", docs: { description: { component: "The Textarea component provides a multi-line text input field with various customization options and validation capabilities." } }, a11y: { config: { rules: [{ id: "label-content", enabled: true }] } } }, argTypes: { textCase: { control: "radio", options: _Textarea2.KWIKUI_TEXTAREA__TEXT_CASE__OPTIONS, description: "Controls the text transformation (uppercase, lowercase, or default)", table: { type: { summary: "string" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.textCase } } }, shape: { control: "radio", options: _Textarea2.KWIKUI_TEXTAREA__SHAPE__OPTIONS, description: "The shape of the textarea", table: { type: { summary: "string" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.shape } } }, size: { control: "radio", options: _Textarea2.KWIKUI_TEXTAREA__SIZE__OPTIONS, description: "The size of the textarea", table: { type: { summary: "string" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.size } } }, updateOn: { control: "radio", options: _Textarea2.KWIKUI_TEXTAREA__UPDATE_ON__OPTIONS, description: "When to trigger the input event (on change or blur)", table: { type: { summary: "string" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.updateOn } } }, id: { control: "text", description: "Unique identifier for the textarea", table: { type: { summary: "string" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.id } } }, value: { control: "text", description: "The content of the textarea", table: { type: { summary: "string" }, defaultValue: { summary: '""' } } }, label: { control: "text", description: "Label text for the textarea", table: { type: { summary: "string" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.label } } }, placeholder: { control: "text", description: "Placeholder text when the textarea is empty", table: { type: { summary: "string" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.placeholder } } }, disabled: { control: "boolean", description: "Whether the textarea is disabled", table: { type: { summary: "boolean" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.disabled } } }, required: { control: "boolean", description: "Whether the textarea is required", table: { type: { summary: "boolean" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.required } } }, isInputCopyDisabled: { control: "boolean", description: "Whether copying from the textarea is disabled", table: { type: { summary: "boolean" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.isInputCopyDisabled } } }, isInputPasteDisabled: { control: "boolean", description: "Whether pasting into the textarea is disabled", table: { type: { summary: "boolean" }, defaultValue: { summary: _Textarea3.KWIKUI_TEXTAREA__DEFAULTS.isInputPasteDisabled } } }, messages: { description: "Array of message objects to display (error, info, etc.)", table: { type: { summary: "Array<IKwikUIMessage>" }, defaultValue: { summary: "[]" } } }, customStyles: { control: "object", description: "Custom styles for the textarea and its container", table: { type: { summary: "object" }, defaultValue: { summary: "{ wrapper: {}, container: {}, label: {}, input: {} }" } } }, onInput: { description: "Function called when input value changes", table: { type: { summary: "(id: string, value: string) => void" } } }, onInputValidate: { description: "Function to validate input value", table: { type: { summary: "(id: string, value: string) => { isValid: boolean } | undefined | null" } } }, onInputCopyDisabled: { description: "Function called when a user attempts to copy while copying is disabled", table: { type: { summary: "() => void" } } }, onInputPasteDisabled: { description: "Function called when a user attempts to paste while pasting is disabled", table: { type: { summary: "() => void" } } } } }; /** * Template for rendering the Textarea component */ const Template = _ref => { let { value, messages, onInput, onInputValidate, onInputCopyDisabled, onInputPasteDisabled } = _ref, args = _objectWithoutProperties(_ref, _excluded); const [localValue, setValue] = _react.default.useState(value || ""); const [localMessages, setLocalMessages] = _react.default.useState(messages); const onChangeInput = (id, value) => { setValue(value); }; const onChangeInputValidate = (id, value) => { if (value === "Baiju") { setLocalMessages([{ type: "success", message: "Success" }]); return { isValid: true }; } if (value === "Baiju1") { setLocalMessages([{ type: "info", message: "This is a info message! This is a info message! This is a info message!" }, { type: "error", message: "This is a error message!" }, { type: "warning", message: "This is a warning message!" }, { type: "success", message: "This is a success message!" }]); return { isValid: false }; } setLocalMessages([]); return undefined; }; const onCopyDisabled = () => { console.log("Copy is disabled"); }; const onPasteDisabled = () => { console.log("Paste is disabled"); }; return /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, args, { onInput: onChangeInput, onInputValidate: onChangeInputValidate, onInputCopyDisabled: onCopyDisabled, onInputPasteDisabled: onPasteDisabled, value: localValue, messages: localMessages })); }; /** * Default textarea implementation */ const Default = exports.Default = Template.bind({}); Default.args = _objectSpread(_objectSpread({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS), {}, { label: "Your Message", placeholder: "Type your message here..." }); Default.parameters = { docs: { description: { story: "Default textarea implementation with label and placeholder." } } }; /** * Textarea with different shapes */ const Shapes = () => { return /*#__PURE__*/_react.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "2rem" } }, /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS, { id: "textarea-curved", label: "Curved Shape", shape: "curved", value: "This textarea has curved corners" })), /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS, { id: "textarea-rectangle", label: "Rectangle Shape", shape: "rectangle", value: "This textarea has rectangular corners" })), /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS, { id: "textarea-rounded", label: "Rounded Shape", shape: "rounded", value: "This textarea has rounded corners" }))); }; exports.Shapes = Shapes; Shapes.parameters = { docs: { description: { story: "Textarea with different shape styles: curved, rectangle, and rounded." } } }; /** * Textarea with different sizes */ const Sizes = () => { return /*#__PURE__*/_react.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "2rem" } }, /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS, { id: "textarea-s", label: "Small Size", size: "s", value: "This is a small textarea" })), /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS, { id: "textarea-m", label: "Medium Size (Default)", size: "m", value: "This is a medium textarea" })), /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS, { id: "textarea-l", label: "Large Size", size: "l", value: "This is a large textarea" }))); }; exports.Sizes = Sizes; Sizes.parameters = { docs: { description: { story: "Textarea in different sizes to fit various UI contexts." } } }; /** * Textarea with text transformation */ const TextCases = () => { return /*#__PURE__*/_react.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "2rem" } }, /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS, { id: "textarea-default", label: "Default Text Case", textCase: "default", value: "This text will display as typed" })), /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS, { id: "textarea-upper", label: "Uppercase Text", textCase: "upper", value: "This text will appear in uppercase" })), /*#__PURE__*/_react.default.createElement(_Textarea.default, _extends({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS, { id: "textarea-lower", label: "Lowercase Text", textCase: "lower", value: "This Text Will Appear In Lowercase" }))); }; exports.TextCases = TextCases; TextCases.parameters = { docs: { description: { story: "Textarea with different text transformation options: default, uppercase, and lowercase." } } }; /** * Textarea with validation */ const WithValidation = () => { const [value, setValue] = _react.default.useState(""); const [messages, setMessages] = _react.default.useState([]); const handleInput = (id, inputValue) => { setValue(inputValue); // Validate minimum length if (inputValue.trim().length > 0 && inputValue.trim().length < 10) { setMessages([{ type: "error", message: "Message must be at least 10 characters long" }]); } else if (inputValue.trim().length >= 10) { setMessages([{ type: "success", message: "Valid message length" }]); } else { setMessages([]); } }; return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("p", null, "Enter a message (must be at least 10 characters):"), /*#__PURE__*/_react.default.createElement(_Textarea.default, { id: "validated-textarea", label: "Your Feedback", placeholder: "Please enter at least 10 characters", value: value, onInput: handleInput, messages: messages, required: true })); }; exports.WithValidation = WithValidation; WithValidation.parameters = { docs: { description: { story: "Textarea with validation that ensures minimum content length." } } }; /** * Disabled textarea */ const Disabled = exports.Disabled = Template.bind({}); Disabled.args = _objectSpread(_objectSpread({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS), {}, { id: "disabled-textarea", label: "Disabled Textarea", value: "This textarea is disabled and cannot be edited", disabled: true }); Disabled.parameters = { docs: { description: { story: "Textarea in disabled state." } } }; /** * Textarea with copy/paste restrictions */ const CopyPasteRestricted = exports.CopyPasteRestricted = Template.bind({}); CopyPasteRestricted.args = _objectSpread(_objectSpread({}, _Textarea3.KWIKUI_TEXTAREA__DEFAULTS), {}, { id: "secure-textarea", label: "Secure Input (No Copy/Paste)", placeholder: "Type sensitive information here...", isInputCopyDisabled: true, isInputPasteDisabled: true, value: "This text cannot be copied, and you cannot paste into this field" }); CopyPasteRestricted.parameters = { docs: { description: { story: "Textarea with copy and paste operations disabled for security purposes." } } };