@neo4j-ndl/react 4.3.4 → 4.3.6

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.
Files changed (48) hide show
  1. package/lib/cjs/_common/utils.js +9 -1
  2. package/lib/cjs/_common/utils.js.map +1 -1
  3. package/lib/cjs/text-input/TextInput.js +33 -2
  4. package/lib/cjs/text-input/TextInput.js.map +1 -1
  5. package/lib/cjs/text-input/stories/index.js +9 -1
  6. package/lib/cjs/text-input/stories/index.js.map +1 -1
  7. package/lib/cjs/text-input/stories/text-input-clearable.story.js +30 -0
  8. package/lib/cjs/text-input/stories/text-input-clearable.story.js.map +1 -0
  9. package/lib/cjs/text-input/stories/text-input-loading-spinner.story.js +31 -0
  10. package/lib/cjs/text-input/stories/text-input-loading-spinner.story.js.map +1 -0
  11. package/lib/cjs/text-input/stories/text-input-with-icons.story.js +1 -3
  12. package/lib/cjs/text-input/stories/text-input-with-icons.story.js.map +1 -1
  13. package/lib/cjs/text-input/stories/text-input.stories.js +61 -35
  14. package/lib/cjs/text-input/stories/text-input.stories.js.map +1 -1
  15. package/lib/cjs/text-link/TextLink.js +3 -4
  16. package/lib/cjs/text-link/TextLink.js.map +1 -1
  17. package/lib/esm/_common/utils.js +7 -0
  18. package/lib/esm/_common/utils.js.map +1 -1
  19. package/lib/esm/text-input/TextInput.js +35 -4
  20. package/lib/esm/text-input/TextInput.js.map +1 -1
  21. package/lib/esm/text-input/stories/index.js +6 -0
  22. package/lib/esm/text-input/stories/index.js.map +1 -1
  23. package/lib/esm/text-input/stories/text-input-clearable.story.js +28 -0
  24. package/lib/esm/text-input/stories/text-input-clearable.story.js.map +1 -0
  25. package/lib/esm/text-input/stories/text-input-loading-spinner.story.js +29 -0
  26. package/lib/esm/text-input/stories/text-input-loading-spinner.story.js.map +1 -0
  27. package/lib/esm/text-input/stories/text-input-with-icons.story.js +3 -5
  28. package/lib/esm/text-input/stories/text-input-with-icons.story.js.map +1 -1
  29. package/lib/esm/text-input/stories/text-input.stories.js +61 -35
  30. package/lib/esm/text-input/stories/text-input.stories.js.map +1 -1
  31. package/lib/esm/text-link/TextLink.js +3 -4
  32. package/lib/esm/text-link/TextLink.js.map +1 -1
  33. package/lib/types/_common/utils.d.ts +1 -0
  34. package/lib/types/_common/utils.d.ts.map +1 -1
  35. package/lib/types/text-input/TextInput.d.ts +5 -1
  36. package/lib/types/text-input/TextInput.d.ts.map +1 -1
  37. package/lib/types/text-input/stories/index.d.ts +4 -0
  38. package/lib/types/text-input/stories/index.d.ts.map +1 -1
  39. package/lib/types/text-input/stories/text-input-clearable.story.d.ts +24 -0
  40. package/lib/types/text-input/stories/text-input-clearable.story.d.ts.map +1 -0
  41. package/lib/types/text-input/stories/text-input-loading-spinner.story.d.ts +24 -0
  42. package/lib/types/text-input/stories/text-input-loading-spinner.story.d.ts.map +1 -0
  43. package/lib/types/text-input/stories/text-input-with-icons.story.d.ts.map +1 -1
  44. package/lib/types/text-input/stories/text-input.stories.d.ts +3 -1
  45. package/lib/types/text-input/stories/text-input.stories.d.ts.map +1 -1
  46. package/lib/types/text-link/TextLink.d.ts +1 -1
  47. package/lib/types/text-link/TextLink.d.ts.map +1 -1
  48. package/package.json +3 -2
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRadius = exports.RadiusDefaults = exports.getSpacing = exports.SpacingDefaults = exports.convertHexToRGB = exports.findFocusableSibling = exports.findFocusableChildren = exports.randomId = exports.useOnClickOutside = exports.useDocumentScrollToggle = exports.needleWarningMessage = exports.removeSpaces = exports.removeNewlines = void 0;
3
+ exports.parseRgbString = exports.getRadius = exports.RadiusDefaults = exports.getSpacing = exports.SpacingDefaults = exports.convertHexToRGB = exports.findFocusableSibling = exports.findFocusableChildren = exports.randomId = exports.useOnClickOutside = exports.useDocumentScrollToggle = exports.needleWarningMessage = exports.removeSpaces = exports.removeNewlines = void 0;
4
4
  exports.isRefObject = isRefObject;
5
5
  exports.findUntil = findUntil;
6
6
  /**
@@ -202,4 +202,12 @@ const getRadius = (spacing, property) => {
202
202
  : undefined;
203
203
  };
204
204
  exports.getRadius = getRadius;
205
+ const parseRgbString = (rgbString) => {
206
+ const match = rgbString.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
207
+ if (!match) {
208
+ throw new Error(`Unable to parse RGB color: ${rgbString}`);
209
+ }
210
+ return [Number(match[1]), Number(match[2]), Number(match[3])];
211
+ };
212
+ exports.parseRgbString = parseRgbString;
205
213
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/_common/utils.ts"],"names":[],"mappings":";;;AAoHA,kCAIC;AAWD,8BA6BC;AAhKD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,0CAAyC;AACzC,iCAMe;AAIR,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAC9C,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AADzB,QAAA,cAAc,kBACW;AAEtC,qCAAqC;AAC9B,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE,CAC5C,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AADvB,QAAA,YAAY,gBACW;AAE7B,MAAM,oBAAoB,GAAG,CAAC,OAAe,EAAE,EAAE,CACtD,OAAO,CAAC,IAAI,CAAC,iBAAiB,OAAO,EAAE,CAAC,CAAC;AAD9B,QAAA,oBAAoB,wBACU;AAE3C,MAAM,gBAAgB,GAAG,CAAC,GAAa,EAAU,EAAE;IACjD,iFAAiF;IACjF,MAAM,aAAa,GAAG,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC;IACtD,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,aAAa,CAAC,CAAC;IAClE,iFAAiF;IACjF,OAAO,aAAa,GAAG,CAAC,C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EAAE,EAAE,CAAC,CAAC;IAE/C,OAAO,OAAO,GAAG,KAAK,KAAK,KAAK,IAAI,GAAG,CAAC;AAC1C,CAAC,CAAC;AARW,QAAA,eAAe,mBAQ1B;AAEW,QAAA,eAAe,GAAG;IAC7B,GAAG,EAAE,GAAG;IACR,OAAO,EAAE,GAAG;IACZ,eAAe,EAAE,SAAS;IAC1B,iBAAiB,EAAE,SAAS;IAC5B,aAAa,EAAE,SAAS;IACxB,gBAAgB,EAAE,SAAS;IAC3B,kBAAkB,EAAE,SAAS;CACrB,CAAC;AAEJ,MAAM,UAAU,GAAG,CACxB,OAA4B,EAC5B,QAAsC,EACtC,EAAE;IACF,OAAO,OAAO;QACZ,CAAC,CAAC,aAAM,CAAC,KAAK,CAAC,OAAO,IAAI,uBAAe,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,UAAU,cAOrB;AAEW,QAAA,cAAc,GAAG;IAC5B,YAAY,EAAE,SAAS;CACxB,CAAC;AAEK,MAAM,SAAS,GAAG,CACvB,OAA2B,EAC3B,QAAqC,EACrC,EAAE;IACF,OAAO,OAAO;QACZ,CAAC,CAAC,aAAM,CAAC,YAAY,CAAC,OAAO,IAAI,sBAAc,CAAC,QAAQ,CAAC,CAAC;QAC1D,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,SAAS,aAOpB","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { tokens } from '@neo4j-ndl/base';\nimport {\n type MouseEvent,\n type TouchEvent,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\n\nimport type { Radius, Spacing } from './types';\n\nexport const removeNewlines = (input: string) =>\n input.replace(/(\\r\\n|\\n|\\r)/gm, '');\n\n/** Remove extra spaces from sting */\nexport const removeSpaces = (input: string) =>\n input.replace(/\\s+/g, ' ').trim();\n\nexport const needleWarningMessage = (message: string) =>\n console.warn(`[🪡 Needle]: ${message}`);\n\nconst getScrollbarSize = (doc: Document): number => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes\n const documentWidth = doc.documentElement.clientWidth;\n const scrollBarSize = Math.abs(window.innerWidth - documentWidth);\n // Firefox with 110% and 120% zoom level return 1px even if there is no scrollbar\n return scrollBarSize > 1 ? scrollBarSize : 0;\n};\n\nconst getPaddingRight = (element: Element): number =>\n parseInt(window.getComputedStyle(element).paddingRight, 10) || 0;\n\n/**\n * Toggles scroll on the provided document.\n * Useful for disabling scroll when a popup is open (ie ContextMenu/Modal)\n */\nexport const useDocumentScrollToggle = () => {\n const bodyPadding = useRef<number>(0);\n\n return useCallback((disable: boolean, doc: Document = document) => {\n if (disable) {\n const existingPaddingRight = getPaddingRight(doc.body);\n bodyPadding.current = existingPaddingRight;\n const newPaddingRight = existingPaddingRight + getScrollbarSize(doc);\n doc.body.style.overflow = 'hidden';\n doc.body.style.paddingRight = `${newPaddingRight}px`;\n } else {\n doc.body.style.overflow = '';\n doc.body.style.paddingRight = `${bodyPadding.current}px`;\n }\n }, []);\n};\n\n/**\n * Detect if there is a click event outside\n * of the provided element\n * Source:\n * https://hashnode.com/post/useonclickoutside-custom-hook-to-detect-the-mouse-click-on-outside-typescript-ckrejmy3h0k5r91s18iu42t28\n */\nexport const useOnClickOutside = <T extends HTMLElement = HTMLElement>(\n ref: React.RefObject<T>,\n handler: (event: MouseEvent | TouchEvent) => void,\n) => {\n useEffect(() => {\n const listener = (event: MouseEvent | TouchEvent) => {\n const el = ref?.current;\n if (!el || el.contains((event?.target as Node) || null)) {\n return;\n }\n\n handler(event); // Call the handler only if the click is outside of the element passed.\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('touchstart', listener as any);\n\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('touchstart', listener as any);\n };\n }, [ref, handler]); // Reload only if ref or handler changes\n};\n\n/**\n * X - char long pseudo-random string\n */\nexport const randomId = (length: number) =>\n Math.random()\n .toString(36)\n .slice(2, length + 2);\n\n// Utility / Type-Guard if the object is a ref\nexport function isRefObject<T>(\n obj: React.RefObject<T> | T,\n): obj is React.RefObject<T> {\n return obj && typeof obj === 'object' && 'current' in obj;\n}\n\n/**\n * Equivalent to prevUntil/nextUntil in jQuery\n * https://api.jquery.com/prevUntil/\n * https://api.jquery.com/nextUntil/\n *\n * Additional functionality is added to circle back\n * to the beginning of a list of siblings if it reaches the end\n * or vice versa.\n */\nexport function findUntil(\n direction: 'next' | 'prev',\n el: Element | ChildNode,\n matchSelector: string,\n): Element | null {\n const element: ChildNode = el;\n\n if (!element.parentElement) {\n return null;\n }\n\n const allSiblings = [...element.parentElement.children].filter((sibling) =>\n sibling.matches(matchSelector),\n );\n\n const index = allSiblings.findIndex((sibling) =>\n sibling.isEqualNode(element),\n );\n\n if (index === -1) {\n return null;\n }\n\n const newIndex =\n direction === 'next'\n ? (index + 1) % allSiblings.length\n : (index - 1 + allSiblings.length) % allSiblings.length;\n\n return allSiblings[newIndex];\n}\n\n/**\n * Find all html elements that are focusable given a parent element\n * @param parentElement the parent element\n * @returns an array of HTML elements\n */\nexport const findFocusableChildren = (parentElement: HTMLElement) => {\n const focusableElements =\n 'a:not([disabled]), button:not([disabled]), input[type=text]:not([disabled]), input[type=checkbox]:not([disabled]), [tabindex]:not([disabled]):not([tabindex=\"-1\"])';\n\n const focusable = Array.from(\n parentElement.querySelectorAll(focusableElements),\n ).filter((element) => {\n if (element instanceof HTMLElement) {\n return true;\n }\n\n return false;\n });\n return focusable;\n};\n\n/**\n * Using the element that currently has focus, finds the previous sibling of the currently focused element that is focusable\n * @param parentRef the parent element\n * @returns the previous focusable element\n */\nexport const findFocusableSibling = (\n parentRef: React.RefObject<HTMLElement | null>,\n direction: 'prev' | 'next',\n): HTMLElement | undefined => {\n const { current } = parentRef;\n const { activeElement } = document;\n\n if (current === null || activeElement === null) {\n return undefined;\n }\n\n const focusable = findFocusableChildren(current);\n const index = focusable.indexOf(activeElement);\n if (index > -1) {\n const siblingElement = focusable[index + (direction === 'next' ? 1 : -1)];\n if (\n siblingElement === undefined ||\n !(siblingElement instanceof HTMLElement)\n ) {\n return undefined;\n }\n return siblingElement;\n }\n return undefined;\n};\n\n/**\n * Convert hex color to rgb format\n *\n * @param hex color in hex code format\n * @returns color in rgb format rgb(_, _, _)\n */\nexport const convertHexToRGB = (hex: string) => {\n hex = hex.replace(/^#/, '');\n\n const red = parseInt(hex.substring(0, 2), 16);\n const green = parseInt(hex.substring(2, 4), 16);\n const blue = parseInt(hex.substring(4, 6), 16);\n\n return `rgb(${red}, ${green}, ${blue})`;\n};\n\nexport const SpacingDefaults = {\n gap: '4',\n padding: '4',\n paddingBlockEnd: undefined,\n paddingBlockStart: undefined,\n paddingInline: undefined,\n paddingInlineEnd: undefined,\n paddingInlineStart: undefined,\n} as const;\n\nexport const getSpacing = (\n spacing: Spacing | undefined,\n property: keyof typeof SpacingDefaults,\n) => {\n return spacing\n ? tokens.space[spacing || SpacingDefaults[property]]\n : undefined;\n};\n\nexport const RadiusDefaults = {\n borderRadius: undefined,\n};\n\nexport const getRadius = (\n spacing: Radius | undefined,\n property: keyof typeof RadiusDefaults,\n) => {\n return spacing\n ? tokens.borderRadius[spacing || RadiusDefaults[property]]\n : undefined;\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/_common/utils.ts"],"names":[],"mappings":";;;AAoHA,kCAIC;AAWD,8BA6BC;AAhKD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,0CAAyC;AACzC,iCAMe;AAIR,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAC9C,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AADzB,QAAA,cAAc,kBACW;AAEtC,qCAAqC;AAC9B,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE,CAC5C,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AADvB,QAAA,YAAY,gBACW;AAE7B,MAAM,oBAAoB,GAAG,CAAC,OAAe,EAAE,EAAE,CACtD,OAAO,CAAC,IAAI,CAAC,iBAAiB,OAAO,EAAE,CAAC,CAAC;AAD9B,QAAA,oBAAoB,wBACU;AAE3C,MAAM,gBAAgB,GAAG,CAAC,GAAa,EAAU,EAAE;IACjD,iFAAiF;IACjF,MAAM,aAAa,GAAG,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC;IACtD,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,aAAa,CAAC,CAAC;IAClE,iFAAiF;IACjF,OAAO,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,OAAgB,EAAU,EAAE,CACnD,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;AAEnE;;;GAGG;AACI,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,MAAM,WAAW,GAAG,IAAA,cAAM,EAA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,EAAE,SAAS;CACrB,CAAC;AAEJ,MAAM,UAAU,GAAG,CACxB,OAA4B,EAC5B,QAAsC,EACtC,EAAE;IACF,OAAO,OAAO;QACZ,CAAC,CAAC,aAAM,CAAC,KAAK,CAAC,OAAO,IAAI,uBAAe,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,UAAU,cAOrB;AAEW,QAAA,cAAc,GAAG;IAC5B,YAAY,EAAE,SAAS;CACxB,CAAC;AAEK,MAAM,SAAS,GAAG,CACvB,OAA2B,EAC3B,QAAqC,EACrC,EAAE;IACF,OAAO,OAAO;QACZ,CAAC,CAAC,aAAM,CAAC,YAAY,CAAC,OAAO,IAAI,sBAAc,CAAC,QAAQ,CAAC,CAAC;QAC1D,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,CAAC;AAPW,QAAA,SAAS,aAOpB;AAEK,MAAM,cAAc,GAAG,CAAC,SAAiB,EAA4B,EAAE;IAC5E,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAChE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,8BAA8B,SAAS,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { tokens } from '@neo4j-ndl/base';\nimport {\n type MouseEvent,\n type TouchEvent,\n useCallback,\n useEffect,\n useRef,\n} from 'react';\n\nimport type { Radius, Spacing } from './types';\n\nexport const removeNewlines = (input: string) =>\n input.replace(/(\\r\\n|\\n|\\r)/gm, '');\n\n/** Remove extra spaces from sting */\nexport const removeSpaces = (input: string) =>\n input.replace(/\\s+/g, ' ').trim();\n\nexport const needleWarningMessage = (message: string) =>\n console.warn(`[🪡 Needle]: ${message}`);\n\nconst getScrollbarSize = (doc: Document): number => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes\n const documentWidth = doc.documentElement.clientWidth;\n const scrollBarSize = Math.abs(window.innerWidth - documentWidth);\n // Firefox with 110% and 120% zoom level return 1px even if there is no scrollbar\n return scrollBarSize > 1 ? scrollBarSize : 0;\n};\n\nconst getPaddingRight = (element: Element): number =>\n parseInt(window.getComputedStyle(element).paddingRight, 10) || 0;\n\n/**\n * Toggles scroll on the provided document.\n * Useful for disabling scroll when a popup is open (ie ContextMenu/Modal)\n */\nexport const useDocumentScrollToggle = () => {\n const bodyPadding = useRef<number>(0);\n\n return useCallback((disable: boolean, doc: Document = document) => {\n if (disable) {\n const existingPaddingRight = getPaddingRight(doc.body);\n bodyPadding.current = existingPaddingRight;\n const newPaddingRight = existingPaddingRight + getScrollbarSize(doc);\n doc.body.style.overflow = 'hidden';\n doc.body.style.paddingRight = `${newPaddingRight}px`;\n } else {\n doc.body.style.overflow = '';\n doc.body.style.paddingRight = `${bodyPadding.current}px`;\n }\n }, []);\n};\n\n/**\n * Detect if there is a click event outside\n * of the provided element\n * Source:\n * https://hashnode.com/post/useonclickoutside-custom-hook-to-detect-the-mouse-click-on-outside-typescript-ckrejmy3h0k5r91s18iu42t28\n */\nexport const useOnClickOutside = <T extends HTMLElement = HTMLElement>(\n ref: React.RefObject<T>,\n handler: (event: MouseEvent | TouchEvent) => void,\n) => {\n useEffect(() => {\n const listener = (event: MouseEvent | TouchEvent) => {\n const el = ref?.current;\n if (!el || el.contains((event?.target as Node) || null)) {\n return;\n }\n\n handler(event); // Call the handler only if the click is outside of the element passed.\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.addEventListener('touchstart', listener as any);\n\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('mousedown', listener as any);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n document.removeEventListener('touchstart', listener as any);\n };\n }, [ref, handler]); // Reload only if ref or handler changes\n};\n\n/**\n * X - char long pseudo-random string\n */\nexport const randomId = (length: number) =>\n Math.random()\n .toString(36)\n .slice(2, length + 2);\n\n// Utility / Type-Guard if the object is a ref\nexport function isRefObject<T>(\n obj: React.RefObject<T> | T,\n): obj is React.RefObject<T> {\n return obj && typeof obj === 'object' && 'current' in obj;\n}\n\n/**\n * Equivalent to prevUntil/nextUntil in jQuery\n * https://api.jquery.com/prevUntil/\n * https://api.jquery.com/nextUntil/\n *\n * Additional functionality is added to circle back\n * to the beginning of a list of siblings if it reaches the end\n * or vice versa.\n */\nexport function findUntil(\n direction: 'next' | 'prev',\n el: Element | ChildNode,\n matchSelector: string,\n): Element | null {\n const element: ChildNode = el;\n\n if (!element.parentElement) {\n return null;\n }\n\n const allSiblings = [...element.parentElement.children].filter((sibling) =>\n sibling.matches(matchSelector),\n );\n\n const index = allSiblings.findIndex((sibling) =>\n sibling.isEqualNode(element),\n );\n\n if (index === -1) {\n return null;\n }\n\n const newIndex =\n direction === 'next'\n ? (index + 1) % allSiblings.length\n : (index - 1 + allSiblings.length) % allSiblings.length;\n\n return allSiblings[newIndex];\n}\n\n/**\n * Find all html elements that are focusable given a parent element\n * @param parentElement the parent element\n * @returns an array of HTML elements\n */\nexport const findFocusableChildren = (parentElement: HTMLElement) => {\n const focusableElements =\n 'a:not([disabled]), button:not([disabled]), input[type=text]:not([disabled]), input[type=checkbox]:not([disabled]), [tabindex]:not([disabled]):not([tabindex=\"-1\"])';\n\n const focusable = Array.from(\n parentElement.querySelectorAll(focusableElements),\n ).filter((element) => {\n if (element instanceof HTMLElement) {\n return true;\n }\n\n return false;\n });\n return focusable;\n};\n\n/**\n * Using the element that currently has focus, finds the previous sibling of the currently focused element that is focusable\n * @param parentRef the parent element\n * @returns the previous focusable element\n */\nexport const findFocusableSibling = (\n parentRef: React.RefObject<HTMLElement | null>,\n direction: 'prev' | 'next',\n): HTMLElement | undefined => {\n const { current } = parentRef;\n const { activeElement } = document;\n\n if (current === null || activeElement === null) {\n return undefined;\n }\n\n const focusable = findFocusableChildren(current);\n const index = focusable.indexOf(activeElement);\n if (index > -1) {\n const siblingElement = focusable[index + (direction === 'next' ? 1 : -1)];\n if (\n siblingElement === undefined ||\n !(siblingElement instanceof HTMLElement)\n ) {\n return undefined;\n }\n return siblingElement;\n }\n return undefined;\n};\n\n/**\n * Convert hex color to rgb format\n *\n * @param hex color in hex code format\n * @returns color in rgb format rgb(_, _, _)\n */\nexport const convertHexToRGB = (hex: string) => {\n hex = hex.replace(/^#/, '');\n\n const red = parseInt(hex.substring(0, 2), 16);\n const green = parseInt(hex.substring(2, 4), 16);\n const blue = parseInt(hex.substring(4, 6), 16);\n\n return `rgb(${red}, ${green}, ${blue})`;\n};\n\nexport const SpacingDefaults = {\n gap: '4',\n padding: '4',\n paddingBlockEnd: undefined,\n paddingBlockStart: undefined,\n paddingInline: undefined,\n paddingInlineEnd: undefined,\n paddingInlineStart: undefined,\n} as const;\n\nexport const getSpacing = (\n spacing: Spacing | undefined,\n property: keyof typeof SpacingDefaults,\n) => {\n return spacing\n ? tokens.space[spacing || SpacingDefaults[property]]\n : undefined;\n};\n\nexport const RadiusDefaults = {\n borderRadius: undefined,\n};\n\nexport const getRadius = (\n spacing: Radius | undefined,\n property: keyof typeof RadiusDefaults,\n) => {\n return spacing\n ? tokens.borderRadius[spacing || RadiusDefaults[property]]\n : undefined;\n};\n\nexport const parseRgbString = (rgbString: string): [number, number, number] => {\n const match = rgbString.match(/rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)/);\n if (!match) {\n throw new Error(`Unable to parse RGB color: ${rgbString}`);\n }\n return [Number(match[1]), Number(match[2]), Number(match[3])];\n};\n"]}
@@ -39,8 +39,10 @@ const jsx_runtime_1 = require("react/jsx-runtime");
39
39
  const classnames_1 = __importDefault(require("classnames"));
40
40
  const react_1 = require("react");
41
41
  const messages_1 = require("../_common/messages");
42
+ const use_semi_controlled_input_1 = require("../_common/use-semi-controlled-input");
42
43
  const utils_1 = require("../_common/utils");
43
44
  const icons_1 = require("../icons");
45
+ const loading_spinner_1 = require("../loading-spinner");
44
46
  const skeleton_1 = require("../skeleton");
45
47
  const tooltip_1 = require("../tooltip");
46
48
  const typography_1 = require("../typography");
@@ -52,7 +54,14 @@ const typography_1 = require("../typography");
52
54
  *
53
55
  */
54
56
  const TextInput = (_a) => {
55
- var { label, isFluid, errorText, helpText, leadingElement, trailingElement, showRequiredOrOptionalLabel = false, moreInformationText, size = 'medium', placeholder, value, tooltipProps, htmlAttributes, isDisabled, isReadOnly, isRequired, onChange, className, style, isSkeletonLoading = false, skeletonProps, ref } = _a, restProps = __rest(_a, ["label", "isFluid", "errorText", "helpText", "leadingElement", "trailingElement", "showRequiredOrOptionalLabel", "moreInformationText", "size", "placeholder", "value", "tooltipProps", "htmlAttributes", "isDisabled", "isReadOnly", "isRequired", "onChange", "className", "style", "isSkeletonLoading", "skeletonProps", "ref"]);
57
+ var { label, isFluid, errorText, helpText, leadingElement, trailingElement, showRequiredOrOptionalLabel = false, moreInformationText, size = 'medium', placeholder, value, tooltipProps, htmlAttributes, isDisabled, isReadOnly, isRequired, onChange, isClearable = false, className, style, isSkeletonLoading = false, isLoading = false, skeletonProps, ref } = _a, restProps = __rest(_a, ["label", "isFluid", "errorText", "helpText", "leadingElement", "trailingElement", "showRequiredOrOptionalLabel", "moreInformationText", "size", "placeholder", "value", "tooltipProps", "htmlAttributes", "isDisabled", "isReadOnly", "isRequired", "onChange", "isClearable", "className", "style", "isSkeletonLoading", "isLoading", "skeletonProps", "ref"]);
58
+ const [internalState, internalOnChange] = (0, use_semi_controlled_input_1.useSemiControlledInput)({
59
+ inputType: 'text',
60
+ isControlled: value !== undefined,
61
+ onChange,
62
+ state: value !== null && value !== void 0 ? value : '',
63
+ });
64
+ const hintId = (0, react_1.useId)();
56
65
  const containerWrappingClasses = (0, classnames_1.default)(`ndl-text-input`, className, {
57
66
  'ndl-disabled': isDisabled,
58
67
  'ndl-has-error': errorText,
@@ -73,6 +82,18 @@ const TextInput = (_a) => {
73
82
  const ariaLabel = combinedHtmlInputAttributes['aria-label'];
74
83
  const isCustomLabel = Boolean(label) && typeof label !== 'string';
75
84
  const hasCustomLabelAndNoAriaLabel = isCustomLabel && (ariaLabel === undefined || ariaLabel === '');
85
+ const shouldRenderHint = isClearable || isLoading;
86
+ const handleInputKeyDown = (event) => {
87
+ var _a;
88
+ if (isClearable && event.key === 'Escape' && Boolean(internalState)) {
89
+ event.preventDefault();
90
+ event.stopPropagation();
91
+ internalOnChange === null || internalOnChange === void 0 ? void 0 : internalOnChange({
92
+ target: { value: '' },
93
+ });
94
+ }
95
+ (_a = htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(htmlAttributes, event);
96
+ };
76
97
  (0, react_1.useMemo)(() => {
77
98
  if (!label && !ariaLabel) {
78
99
  (0, utils_1.needleWarningMessage)('A TextInput without a label does not have an aria label, be sure to include an aria label for screen readers. Link: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI');
@@ -85,7 +106,17 @@ const TextInput = (_a) => {
85
106
  'ndl-information-icon-large': size === 'large',
86
107
  'ndl-information-icon-small': size === 'small' || size === 'medium',
87
108
  });
88
- return ((0, jsx_runtime_1.jsxs)("div", { className: containerWrappingClasses, style: style, children: [(0, jsx_runtime_1.jsxs)("label", { className: labelWrappingClasses, children: [!hasEmptyLabelValue && ((0, jsx_runtime_1.jsx)(skeleton_1.Skeleton, Object.assign({ onBackground: "weak", shape: "rectangular" }, skeletonProps, { isLoading: isSkeletonLoading, children: (0, jsx_runtime_1.jsxs)("div", { className: "ndl-label-text-wrapper", children: [(0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: size === 'large' ? 'body-large' : 'body-medium', className: "ndl-label-text", children: label }), Boolean(moreInformationText) && ((0, jsx_runtime_1.jsxs)(tooltip_1.Tooltip, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.root, { type: "simple", children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Trigger, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.trigger, { className: informationIconClasses, hasButtonWrapper: true, children: (0, jsx_runtime_1.jsx)("div", { tabIndex: 0, role: "button", "aria-label": "Information icon", children: (0, jsx_runtime_1.jsx)(icons_1.InformationCircleIconOutline, {}) }) })), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Content, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.content, { children: moreInformationText }))] }))), showRequiredOrOptionalLabel && ((0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: size === 'large' ? 'body-large' : 'body-medium', className: "ndl-form-item-optional", children: isRequired === true ? 'Required' : 'Optional' }))] }) }))), (0, jsx_runtime_1.jsx)(skeleton_1.Skeleton, Object.assign({ onBackground: "weak", shape: "rectangular" }, skeletonProps, { isLoading: isSkeletonLoading, children: (0, jsx_runtime_1.jsxs)("div", { className: "ndl-input-wrapper", children: [leadingElement && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-element-leading ndl-element", children: leadingElement })), (0, jsx_runtime_1.jsx)("input", Object.assign({ readOnly: isReadOnly, disabled: isDisabled, required: isRequired, value: value, placeholder: placeholder, type: "text", onChange: onChange }, combinedHtmlInputAttributes, restProps, { ref: ref })), trailingElement && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-element-trailing ndl-element", children: trailingElement }))] }) }))] }), Boolean(helpText) && !errorText && ((0, jsx_runtime_1.jsx)(skeleton_1.Skeleton, { onBackground: "weak", shape: "rectangular", isLoading: isSkeletonLoading, children: (0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: size === 'large' ? 'body-medium' : 'body-small', className: "ndl-form-message", children: helpText }) })), Boolean(errorText) && (
109
+ return ((0, jsx_runtime_1.jsxs)("div", { className: containerWrappingClasses, style: style, children: [(0, jsx_runtime_1.jsxs)("label", { className: labelWrappingClasses, children: [!hasEmptyLabelValue && ((0, jsx_runtime_1.jsx)(skeleton_1.Skeleton, Object.assign({ onBackground: "weak", shape: "rectangular" }, skeletonProps, { isLoading: isSkeletonLoading, children: (0, jsx_runtime_1.jsxs)("div", { className: "ndl-label-text-wrapper", children: [(0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: size === 'large' ? 'body-large' : 'body-medium', className: "ndl-label-text", children: label }), Boolean(moreInformationText) && ((0, jsx_runtime_1.jsxs)(tooltip_1.Tooltip, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.root, { type: "simple", children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Trigger, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.trigger, { className: informationIconClasses, hasButtonWrapper: true, children: (0, jsx_runtime_1.jsx)("div", { tabIndex: 0, role: "button", "aria-label": "Information icon", children: (0, jsx_runtime_1.jsx)(icons_1.InformationCircleIconOutline, {}) }) })), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Content, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.content, { children: moreInformationText }))] }))), showRequiredOrOptionalLabel && ((0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: size === 'large' ? 'body-large' : 'body-medium', className: "ndl-form-item-optional", children: isRequired === true ? 'Required' : 'Optional' }))] }) }))), (0, jsx_runtime_1.jsx)(skeleton_1.Skeleton, Object.assign({ onBackground: "weak", shape: "rectangular" }, skeletonProps, { isLoading: isSkeletonLoading, children: (0, jsx_runtime_1.jsxs)("div", { className: "ndl-input-wrapper", children: [(leadingElement || (isLoading && !trailingElement)) && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-element-leading ndl-element", children: isLoading ? ((0, jsx_runtime_1.jsx)(loading_spinner_1.LoadingSpinner, { size: size === 'large' ? 'medium' : 'small', className: size === 'large'
110
+ ? 'ndl-medium-spinner'
111
+ : 'ndl-small-spinner' })) : (leadingElement) })), (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)('ndl-input-container', {
112
+ 'ndl-clearable': isClearable,
113
+ }), children: [(0, jsx_runtime_1.jsx)("input", Object.assign({ ref: ref, readOnly: isReadOnly, disabled: isDisabled, required: isRequired, value: internalState, placeholder: placeholder, type: "text", onChange: internalOnChange, "aria-describedby": shouldRenderHint ? hintId : undefined }, combinedHtmlInputAttributes, { onKeyDown: handleInputKeyDown }, restProps)), shouldRenderHint && ((0, jsx_runtime_1.jsxs)("span", { id: hintId, className: "ndl-text-input-hint", children: [isLoading && 'Loading ', isClearable && 'Press Escape to clear input.'] })), isClearable && Boolean(internalState) && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-element-clear ndl-element", children: (0, jsx_runtime_1.jsx)("button", { tabIndex: -1, "aria-hidden": true, type: "button", title: "Clear input (Esc)", onClick: () => {
114
+ internalOnChange === null || internalOnChange === void 0 ? void 0 : internalOnChange({
115
+ target: { value: '' },
116
+ });
117
+ }, children: (0, jsx_runtime_1.jsx)(icons_1.XMarkIconOutline, { className: "n-size-4" }) }) }))] }), trailingElement && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-element-trailing ndl-element", children: isLoading && !leadingElement ? ((0, jsx_runtime_1.jsx)(loading_spinner_1.LoadingSpinner, { size: size === 'large' ? 'medium' : 'small', className: size === 'large'
118
+ ? 'ndl-medium-spinner'
119
+ : 'ndl-small-spinner' })) : (trailingElement) }))] }) }))] }), Boolean(helpText) && !errorText && ((0, jsx_runtime_1.jsx)(skeleton_1.Skeleton, { onBackground: "weak", shape: "rectangular", isLoading: isSkeletonLoading, children: (0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: size === 'large' ? 'body-medium' : 'body-small', className: "ndl-form-message", children: helpText }) })), Boolean(errorText) && (
89
120
  // TODO v4: We might want to have a min width for the container for the messages to help skeleton loading.
90
121
  // Currently the message fills 100% of the width while the rest of the text input has a set width.
91
122
  (0, jsx_runtime_1.jsx)(skeleton_1.Skeleton, Object.assign({ onBackground: "weak", shape: "rectangular", width: "fit-content" }, skeletonProps, { isLoading: isSkeletonLoading, children: (0, jsx_runtime_1.jsxs)("div", { className: "ndl-form-message", children: [(0, jsx_runtime_1.jsx)("div", { className: "ndl-error-icon", children: (0, jsx_runtime_1.jsx)(icons_1.ExclamationCircleIconSolid, {}) }), (0, jsx_runtime_1.jsx)(typography_1.Typography, { className: "ndl-error-text", variant: size === 'large' ? 'body-medium' : 'body-small', children: errorText })] }) })))] }));
@@ -1 +1 @@
1
- {"version":3,"file":"TextInput.js","sourceRoot":"","sources":["../../../src/text-input/TextInput.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,4DAAoC;AACpC,iCAKe;AAEf,kDAA8E;AAE9E,4CAAwD;AACxD,oCAGkB;AAClB,0CAAuC;AACvC,wCAAqC;AACrC,8CAA2C;AA8D3C;;;;;;GAMG;AAEI,MAAM,SAAS,GAAG,CAAC,EAwBa,EAAE,EAAE;QAxBjB,EACxB,KAAK,EACL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,cAAc,EACd,eAAe,EACf,2BAA2B,GAAG,KAAK,EACn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,EAAC,kBAAkB,YAE3B,QAAQ,GACE,GACJ,CACZ,EACA,OAAO,CAAC,SAAS,CAAC,IAAI;YACrB,0GAA0G;YAC1G,kGAAkG;YAClG,uBAAC,mBAAQ,kBACP,YAAY,EAAC,MAAM,EACnB,KAAK,EAAC,aAAa,EACnB,KAAK,EAAC,aAAa,IACf,aAAa,IACjB,SAAS,EAAE,iBAAiB,YAE5B,iCAAK,SAAS,EAAC,kBAAkB,aAC/B,gCAAK,SAAS,EAAC,gBAAgB,YAC7B,uBAAC,kCAA0B,KAAG,GAC1B,EACN,uBAAC,uBAAU,IACT,SAAS,EAAC,gBAAgB,EAC1B,OAAO,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,YAEvD,SAAS,GACC,IACT,IACG,CACZ,IACG,CACP,CAAC;AACJ,CAAC,CAAC;AAhMW,QAAA,SAAS,aAgMpB","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport classNames from 'classnames';\nimport {\n type InputHTMLAttributes,\n type ReactElement,\n type ReactNode,\n useMemo,\n} from 'react';\n\nimport { customLabelAndNoAriaLabelWarningMessage } from '../_common/messages';\nimport { type CommonProps, type TooltipObjectProps } from '../_common/types';\nimport { needleWarningMessage } from '../_common/utils';\nimport {\n ExclamationCircleIconSolid,\n InformationCircleIconOutline,\n} from '../icons';\nimport { Skeleton } from '../skeleton';\nimport { Tooltip } from '../tooltip';\nimport { Typography } from '../typography';\n\ntype TextInputProps = {\n /** Assistive text displayed below the input */\n helpText?: string | ReactNode;\n\n /** Error message displayed below the input. When provided, it overrides `helpText` and shows an error icon */\n errorText?: string | ReactNode;\n\n /** Leading element rendered inside the input */\n leadingElement?: ReactElement;\n\n /** Trailing element rendered inside the input */\n trailingElement?: ReactElement;\n\n /** Size of the input */\n size?: 'small' | 'medium' | 'large';\n\n /** Whether the input is read-only */\n isReadOnly?: boolean;\n\n /**\n * Whether to display the Required/Optional label next to the field label.\n * Shows Required if isRequired is true, otherwise shows Optional.\n * @default false\n */\n showRequiredOrOptionalLabel?: boolean;\n\n /** Whether the input is disabled */\n isDisabled?: boolean;\n\n /** Whether the input is required */\n isRequired?: boolean;\n\n /** The current value of the input */\n value?: React.ComponentPropsWithoutRef<'input'>['value'];\n\n /** Placeholder text displayed when the input is empty */\n placeholder?: React.ComponentPropsWithoutRef<'input'>['placeholder'];\n\n /** Callback function triggered when the input value changes */\n onChange?: React.ComponentPropsWithoutRef<'input'>['onChange'];\n\n /** Whether the input should take the full available width */\n isFluid?: boolean;\n\n /** Text displayed in the information tooltip shown next to the label */\n moreInformationText?: React.ReactNode;\n\n /** The label displayed above the input */\n label?: string | React.ReactNode;\n\n /** Props for the Tooltip component used by the information icon */\n tooltipProps?: TooltipObjectProps;\n\n /** Whether to render skeletons instead of content */\n isSkeletonLoading?: boolean;\n\n /** Additional props forwarded to the underlying Skeleton components */\n skeletonProps?: React.ComponentProps<typeof Skeleton>;\n};\n\n/**\n *\n *\n * TextInput Component\n *\n *\n */\n\nexport const TextInput = ({\n label,\n isFluid,\n errorText,\n helpText,\n leadingElement,\n trailingElement,\n showRequiredOrOptionalLabel = false,\n moreInformationText,\n size = 'medium',\n placeholder,\n value,\n tooltipProps,\n htmlAttributes,\n isDisabled,\n isReadOnly,\n isRequired,\n onChange,\n className,\n style,\n isSkeletonLoading = false,\n skeletonProps,\n ref,\n ...restProps\n}: CommonProps<'input', TextInputProps>) => {\n const containerWrappingClasses = classNames(`ndl-text-input`, className, {\n 'ndl-disabled': isDisabled,\n 'ndl-has-error': errorText,\n 'ndl-has-icon': leadingElement || trailingElement || errorText,\n 'ndl-has-leading-icon': leadingElement,\n 'ndl-has-trailing-icon': trailingElement || errorText,\n 'ndl-large': size === 'large',\n 'ndl-medium': size === 'medium',\n 'ndl-read-only': isReadOnly,\n 'ndl-small': size === 'small',\n });\n\n const hasEmptyLabelValue =\n label === undefined || label === null || label === '';\n\n const labelWrappingClasses = classNames('ndl-form-item-label', {\n 'ndl-fluid': isFluid,\n 'ndl-form-item-no-label': hasEmptyLabelValue,\n });\n\n const combinedHtmlInputAttributes: InputHTMLAttributes<HTMLInputElement> = {\n ...htmlAttributes,\n className: classNames('ndl-input', htmlAttributes?.className),\n };\n const ariaLabel = combinedHtmlInputAttributes['aria-label'];\n const isCustomLabel = Boolean(label) && typeof label !== 'string';\n const hasCustomLabelAndNoAriaLabel =\n isCustomLabel && (ariaLabel === undefined || ariaLabel === '');\n\n useMemo(() => {\n if (!label && !ariaLabel) {\n needleWarningMessage(\n 'A TextInput without a label does not have an aria label, be sure to include an aria label for screen readers. Link: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI',\n );\n }\n\n if (hasCustomLabelAndNoAriaLabel) {\n needleWarningMessage(customLabelAndNoAriaLabelWarningMessage);\n }\n }, [label, ariaLabel, hasCustomLabelAndNoAriaLabel]);\n\n const informationIconClasses = classNames({\n 'ndl-information-icon-large': size === 'large',\n 'ndl-information-icon-small': size === 'small' || size === 'medium',\n });\n\n return (\n <div className={containerWrappingClasses} style={style}>\n {/* We enable implicit label wrapping */}\n {/* Source: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI */}\n <label className={labelWrappingClasses}>\n {!hasEmptyLabelValue && (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n <div className=\"ndl-label-text-wrapper\">\n <Typography\n variant={size === 'large' ? 'body-large' : 'body-medium'}\n className=\"ndl-label-text\"\n >\n {label}\n </Typography>\n {Boolean(moreInformationText) && (\n <Tooltip {...tooltipProps?.root} type=\"simple\">\n <Tooltip.Trigger\n {...tooltipProps?.trigger}\n className={informationIconClasses}\n hasButtonWrapper\n >\n <div\n tabIndex={0}\n role=\"button\"\n aria-label=\"Information icon\"\n >\n <InformationCircleIconOutline />\n </div>\n </Tooltip.Trigger>\n <Tooltip.Content {...tooltipProps?.content}>\n {moreInformationText}\n </Tooltip.Content>\n </Tooltip>\n )}\n {showRequiredOrOptionalLabel && (\n <Typography\n variant={size === 'large' ? 'body-large' : 'body-medium'}\n className=\"ndl-form-item-optional\"\n >\n {isRequired === true ? 'Required' : 'Optional'}\n </Typography>\n )}\n </div>\n </Skeleton>\n )}\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n <div className=\"ndl-input-wrapper\">\n {leadingElement && (\n <div className=\"ndl-element-leading ndl-element\">\n {leadingElement}\n </div>\n )}\n <input\n readOnly={isReadOnly}\n disabled={isDisabled}\n required={isRequired}\n value={value}\n placeholder={placeholder}\n type=\"text\"\n onChange={onChange}\n {...combinedHtmlInputAttributes}\n {...restProps}\n ref={ref}\n />\n {trailingElement && (\n <div className=\"ndl-element-trailing ndl-element\">\n {trailingElement}\n </div>\n )}\n </div>\n </Skeleton>\n </label>\n {Boolean(helpText) && !errorText && (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n isLoading={isSkeletonLoading}\n >\n <Typography\n variant={size === 'large' ? 'body-medium' : 'body-small'}\n className=\"ndl-form-message\"\n >\n {helpText}\n </Typography>\n </Skeleton>\n )}\n {Boolean(errorText) && (\n // TODO v4: We might want to have a min width for the container for the messages to help skeleton loading.\n // Currently the message fills 100% of the width while the rest of the text input has a set width.\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n width=\"fit-content\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n <div className=\"ndl-form-message\">\n <div className=\"ndl-error-icon\">\n <ExclamationCircleIconSolid />\n </div>\n <Typography\n className=\"ndl-error-text\"\n variant={size === 'large' ? 'body-medium' : 'body-small'}\n >\n {errorText}\n </Typography>\n </div>\n </Skeleton>\n )}\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"TextInput.js","sourceRoot":"","sources":["../../../src/text-input/TextInput.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,4DAAoC;AACpC,iCAMe;AAEf,kDAA8E;AAE9E,oFAA8E;AAC9E,4CAAwD;AACxD,oCAIkB;AAClB,wDAAoD;AACpD,0CAAuC;AACvC,wCAAqC;AACrC,8CAA2C;AAoE3C;;;;;;GAMG;AAEI,MAAM,SAAS,GAAG,CAAC,EA0Ba,EAAE,EAAE;QA1BjB,EACxB,KAAK,EACL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,cAAc,EACd,eAAe,EACf,2BAA2B,GAAG,KAAK,EACnC,mBAAmB,EACnB,IAAI,GAAG,QAAQ,EACf,WAAW,EACX,KAAK,EACL,YAAY,EACZ,cAAc,EACd,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,GAAG,KAAK,EACnB,SAAS,EACT,KAAK,EACL,iBAAiB,GAAG,KAAK,EACzB,SAAS,GAAG,KAAK,EACjB,aAAa,EACb,GAAG,OAEkC,EADlC,SAAS,cAzBY,+VA0BzB,CADa;IAEZ,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,kDAAsB,EAAC;QAC/D,SAAS,EAAE,MAAM;QACjB,YAAY,EAAE,KAAK,KAAK,SAAS;QACjC,QAAQ;QACR,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE;KACnB,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAA,aAAK,GAAE,CAAC;IAEvB,MAAM,wBAAwB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AAC,CAAC,mBAAmB,GAEzB,CACH,CAAC,CAAC,CAAC,CACF,eAAe,CAChB,GACG,CACP,IACG,IACG,IACL,EACP,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,IAAI,CAClC,uBAAC,mBAAQ,IACP,YAAY,EAAC,MAAM,EACnB,KAAK,EAAC,aAAa,EACnB,SAAS,EAAE,iBAAiB,YAE5B,uBAAC,uBAAU,IACT,OAAO,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,EACxD,SAAS,EAAC,kBAAkB,YAE3B,QAAQ,GACE,GACJ,CACZ,EACA,OAAO,CAAC,SAAS,CAAC,IAAI;YACrB,0GAA0G;YAC1G,kGAAkG;YAClG,uBAAC,mBAAQ,kBACP,YAAY,EAAC,MAAM,EACnB,KAAK,EAAC,aAAa,EACnB,KAAK,EAAC,aAAa,IACf,aAAa,IACjB,SAAS,EAAE,iBAAiB,YAE5B,iCAAK,SAAS,EAAC,kBAAkB,aAC/B,gCAAK,SAAS,EAAC,gBAAgB,YAC7B,uBAAC,kCAA0B,KAAG,GAC1B,EACN,uBAAC,uBAAU,IACT,SAAS,EAAC,gBAAgB,EAC1B,OAAO,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,YAEvD,SAAS,GACC,IACT,IACG,CACZ,IACG,CACP,CAAC;AACJ,CAAC,CAAC;AA3QW,QAAA,SAAS,aA2QpB","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport classNames from 'classnames';\nimport {\n type InputHTMLAttributes,\n type ReactElement,\n type ReactNode,\n useId,\n useMemo,\n} from 'react';\n\nimport { customLabelAndNoAriaLabelWarningMessage } from '../_common/messages';\nimport { type CommonProps, type TooltipObjectProps } from '../_common/types';\nimport { useSemiControlledInput } from '../_common/use-semi-controlled-input';\nimport { needleWarningMessage } from '../_common/utils';\nimport {\n ExclamationCircleIconSolid,\n InformationCircleIconOutline,\n XMarkIconOutline,\n} from '../icons';\nimport { LoadingSpinner } from '../loading-spinner';\nimport { Skeleton } from '../skeleton';\nimport { Tooltip } from '../tooltip';\nimport { Typography } from '../typography';\n\ntype TextInputProps = {\n /** Assistive text displayed below the input */\n helpText?: string | ReactNode;\n\n /** Error message displayed below the input. When provided, it overrides `helpText` and shows an error icon */\n errorText?: string | ReactNode;\n\n /** Leading element rendered inside the input */\n leadingElement?: ReactElement;\n\n /** Trailing element rendered inside the input */\n trailingElement?: ReactElement;\n\n /** Size of the input */\n size?: 'small' | 'medium' | 'large';\n\n /** Whether the input is read-only */\n isReadOnly?: boolean;\n\n /**\n * Whether to display the Required/Optional label next to the field label.\n * Shows Required if isRequired is true, otherwise shows Optional.\n * @default false\n */\n showRequiredOrOptionalLabel?: boolean;\n\n /** Whether the input is disabled */\n isDisabled?: boolean;\n\n /** Whether the input is required */\n isRequired?: boolean;\n\n /** The current value of the input */\n value?: React.ComponentPropsWithoutRef<'input'>['value'];\n\n /** Placeholder text displayed when the input is empty */\n placeholder?: React.ComponentPropsWithoutRef<'input'>['placeholder'];\n\n /** Callback function triggered when the input value changes */\n onChange?: React.ComponentPropsWithoutRef<'input'>['onChange'];\n\n /** Whether the input should take the full available width */\n isFluid?: boolean;\n\n /** Text displayed in the information tooltip shown next to the label */\n moreInformationText?: React.ReactNode;\n\n /** The label displayed above the input */\n label?: string | React.ReactNode;\n\n /** Props for the Tooltip component used by the information icon */\n tooltipProps?: TooltipObjectProps;\n\n /** Whether to render skeletons instead of content */\n isSkeletonLoading?: boolean;\n\n /** Additional props forwarded to the underlying Skeleton components */\n skeletonProps?: React.ComponentProps<typeof Skeleton>;\n\n /** Whether to show the clear button */\n isClearable?: boolean;\n\n /** Whether to show the loading spinner */\n isLoading?: boolean;\n};\n\n/**\n *\n *\n * TextInput Component\n *\n *\n */\n\nexport const TextInput = ({\n label,\n isFluid,\n errorText,\n helpText,\n leadingElement,\n trailingElement,\n showRequiredOrOptionalLabel = false,\n moreInformationText,\n size = 'medium',\n placeholder,\n value,\n tooltipProps,\n htmlAttributes,\n isDisabled,\n isReadOnly,\n isRequired,\n onChange,\n isClearable = false,\n className,\n style,\n isSkeletonLoading = false,\n isLoading = false,\n skeletonProps,\n ref,\n ...restProps\n}: CommonProps<'input', TextInputProps>) => {\n const [internalState, internalOnChange] = useSemiControlledInput({\n inputType: 'text',\n isControlled: value !== undefined,\n onChange,\n state: value ?? '',\n });\n const hintId = useId();\n\n const containerWrappingClasses = classNames(`ndl-text-input`, className, {\n 'ndl-disabled': isDisabled,\n 'ndl-has-error': errorText,\n 'ndl-has-icon': leadingElement || trailingElement || errorText,\n 'ndl-has-leading-icon': leadingElement,\n 'ndl-has-trailing-icon': trailingElement || errorText,\n 'ndl-large': size === 'large',\n 'ndl-medium': size === 'medium',\n 'ndl-read-only': isReadOnly,\n 'ndl-small': size === 'small',\n });\n\n const hasEmptyLabelValue =\n label === undefined || label === null || label === '';\n\n const labelWrappingClasses = classNames('ndl-form-item-label', {\n 'ndl-fluid': isFluid,\n 'ndl-form-item-no-label': hasEmptyLabelValue,\n });\n\n const combinedHtmlInputAttributes: InputHTMLAttributes<HTMLInputElement> = {\n ...htmlAttributes,\n className: classNames('ndl-input', htmlAttributes?.className),\n };\n const ariaLabel = combinedHtmlInputAttributes['aria-label'];\n const isCustomLabel = Boolean(label) && typeof label !== 'string';\n const hasCustomLabelAndNoAriaLabel =\n isCustomLabel && (ariaLabel === undefined || ariaLabel === '');\n const shouldRenderHint = isClearable || isLoading;\n\n const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (isClearable && event.key === 'Escape' && Boolean(internalState)) {\n event.preventDefault();\n event.stopPropagation();\n internalOnChange?.({\n target: { value: '' },\n } as React.ChangeEvent<HTMLInputElement>);\n }\n htmlAttributes?.onKeyDown?.(event);\n };\n\n useMemo(() => {\n if (!label && !ariaLabel) {\n needleWarningMessage(\n 'A TextInput without a label does not have an aria label, be sure to include an aria label for screen readers. Link: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI',\n );\n }\n\n if (hasCustomLabelAndNoAriaLabel) {\n needleWarningMessage(customLabelAndNoAriaLabelWarningMessage);\n }\n }, [label, ariaLabel, hasCustomLabelAndNoAriaLabel]);\n\n const informationIconClasses = classNames({\n 'ndl-information-icon-large': size === 'large',\n 'ndl-information-icon-small': size === 'small' || size === 'medium',\n });\n\n return (\n <div className={containerWrappingClasses} style={style}>\n {/* We enable implicit label wrapping */}\n {/* Source: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI */}\n <label className={labelWrappingClasses}>\n {!hasEmptyLabelValue && (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n <div className=\"ndl-label-text-wrapper\">\n <Typography\n variant={size === 'large' ? 'body-large' : 'body-medium'}\n className=\"ndl-label-text\"\n >\n {label}\n </Typography>\n {Boolean(moreInformationText) && (\n <Tooltip {...tooltipProps?.root} type=\"simple\">\n <Tooltip.Trigger\n {...tooltipProps?.trigger}\n className={informationIconClasses}\n hasButtonWrapper\n >\n <div\n tabIndex={0}\n role=\"button\"\n aria-label=\"Information icon\"\n >\n <InformationCircleIconOutline />\n </div>\n </Tooltip.Trigger>\n <Tooltip.Content {...tooltipProps?.content}>\n {moreInformationText}\n </Tooltip.Content>\n </Tooltip>\n )}\n {showRequiredOrOptionalLabel && (\n <Typography\n variant={size === 'large' ? 'body-large' : 'body-medium'}\n className=\"ndl-form-item-optional\"\n >\n {isRequired === true ? 'Required' : 'Optional'}\n </Typography>\n )}\n </div>\n </Skeleton>\n )}\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n <div className=\"ndl-input-wrapper\">\n {(leadingElement || (isLoading && !trailingElement)) && (\n <div className=\"ndl-element-leading ndl-element\">\n {isLoading ? (\n <LoadingSpinner\n size={size === 'large' ? 'medium' : 'small'}\n className={\n size === 'large'\n ? 'ndl-medium-spinner'\n : 'ndl-small-spinner'\n }\n />\n ) : (\n leadingElement\n )}\n </div>\n )}\n <div\n className={classNames('ndl-input-container', {\n 'ndl-clearable': isClearable,\n })}\n >\n <input\n ref={ref}\n readOnly={isReadOnly}\n disabled={isDisabled}\n required={isRequired}\n value={internalState}\n placeholder={placeholder}\n type=\"text\"\n onChange={internalOnChange}\n aria-describedby={shouldRenderHint ? hintId : undefined}\n {...combinedHtmlInputAttributes}\n onKeyDown={handleInputKeyDown}\n {...restProps}\n />\n {shouldRenderHint && (\n <span id={hintId} className=\"ndl-text-input-hint\">\n {isLoading && 'Loading '}\n {isClearable && 'Press Escape to clear input.'}\n </span>\n )}\n {isClearable && Boolean(internalState) && (\n <div className=\"ndl-element-clear ndl-element\">\n <button\n tabIndex={-1}\n aria-hidden={true}\n type=\"button\"\n title=\"Clear input (Esc)\"\n onClick={() => {\n internalOnChange?.({\n target: { value: '' },\n } as React.ChangeEvent<HTMLInputElement>);\n }}\n >\n <XMarkIconOutline className=\"n-size-4\" />\n </button>\n </div>\n )}\n </div>\n {trailingElement && (\n <div className=\"ndl-element-trailing ndl-element\">\n {isLoading && !leadingElement ? (\n <LoadingSpinner\n size={size === 'large' ? 'medium' : 'small'}\n className={\n size === 'large'\n ? 'ndl-medium-spinner'\n : 'ndl-small-spinner'\n }\n />\n ) : (\n trailingElement\n )}\n </div>\n )}\n </div>\n </Skeleton>\n </label>\n {Boolean(helpText) && !errorText && (\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n isLoading={isSkeletonLoading}\n >\n <Typography\n variant={size === 'large' ? 'body-medium' : 'body-small'}\n className=\"ndl-form-message\"\n >\n {helpText}\n </Typography>\n </Skeleton>\n )}\n {Boolean(errorText) && (\n // TODO v4: We might want to have a min width for the container for the messages to help skeleton loading.\n // Currently the message fills 100% of the width while the rest of the text input has a set width.\n <Skeleton\n onBackground=\"weak\"\n shape=\"rectangular\"\n width=\"fit-content\"\n {...skeletonProps}\n isLoading={isSkeletonLoading}\n >\n <div className=\"ndl-form-message\">\n <div className=\"ndl-error-icon\">\n <ExclamationCircleIconSolid />\n </div>\n <Typography\n className=\"ndl-error-text\"\n variant={size === 'large' ? 'body-medium' : 'body-small'}\n >\n {errorText}\n </Typography>\n </div>\n </Skeleton>\n )}\n </div>\n );\n};\n"]}
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.TextInputFullSource = exports.TextInputLoadingSource = exports.TextInputSizesSource = exports.TextInputPasswordSource = exports.TextInputWithIconsSource = exports.TextInputNumberSource = exports.TextInputEmailSource = exports.TextInputInformationIconSource = exports.TextInputErrorSource = exports.TextInputReadonlySource = exports.TextInputDisabledSource = exports.TextInputOptionalSource = exports.TextInputRequiredSource = exports.TextInputDefaultSource = exports.TextInputFull = exports.TextInputLoading = exports.TextInputSizes = exports.TextInputPassword = exports.TextInputWithIcons = exports.TextInputNumber = exports.TextInputEmail = exports.TextInputInformationIcon = exports.TextInputError = exports.TextInputReadonly = exports.TextInputDisabled = exports.TextInputOptional = exports.TextInputRequired = exports.TextInputDefault = void 0;
26
+ exports.TextInputLoadingSpinnerSource = exports.TextInputClearableSource = exports.TextInputFullSource = exports.TextInputLoadingSource = exports.TextInputSizesSource = exports.TextInputPasswordSource = exports.TextInputWithIconsSource = exports.TextInputNumberSource = exports.TextInputEmailSource = exports.TextInputInformationIconSource = exports.TextInputErrorSource = exports.TextInputReadonlySource = exports.TextInputDisabledSource = exports.TextInputOptionalSource = exports.TextInputRequiredSource = exports.TextInputDefaultSource = exports.TextInputLoadingSpinner = exports.TextInputClearable = exports.TextInputFull = exports.TextInputLoading = exports.TextInputSizes = exports.TextInputPassword = exports.TextInputWithIcons = exports.TextInputNumber = exports.TextInputEmail = exports.TextInputInformationIcon = exports.TextInputError = exports.TextInputReadonly = exports.TextInputDisabled = exports.TextInputOptional = exports.TextInputRequired = exports.TextInputDefault = void 0;
27
27
  var text_input_default_story_1 = require("./text-input-default.story");
28
28
  Object.defineProperty(exports, "TextInputDefault", { enumerable: true, get: function () { return __importDefault(text_input_default_story_1).default; } });
29
29
  var text_input_required_story_1 = require("./text-input-required.story");
@@ -52,7 +52,12 @@ var text_input_loading_story_1 = require("./text-input-loading.story");
52
52
  Object.defineProperty(exports, "TextInputLoading", { enumerable: true, get: function () { return __importDefault(text_input_loading_story_1).default; } });
53
53
  var text_input_full_story_1 = require("./text-input-full.story");
54
54
  Object.defineProperty(exports, "TextInputFull", { enumerable: true, get: function () { return __importDefault(text_input_full_story_1).default; } });
55
+ var text_input_clearable_story_1 = require("./text-input-clearable.story");
56
+ Object.defineProperty(exports, "TextInputClearable", { enumerable: true, get: function () { return __importDefault(text_input_clearable_story_1).default; } });
57
+ var text_input_loading_spinner_story_1 = require("./text-input-loading-spinner.story");
58
+ Object.defineProperty(exports, "TextInputLoadingSpinner", { enumerable: true, get: function () { return __importDefault(text_input_loading_spinner_story_1).default; } });
55
59
  const export_stories_utils_1 = require("../../_common/export-stories-utils");
60
+ const text_input_clearable_story_raw_1 = __importDefault(require("./text-input-clearable.story?raw"));
56
61
  const text_input_default_story_raw_1 = __importDefault(require("./text-input-default.story?raw"));
57
62
  const text_input_disabled_story_raw_1 = __importDefault(require("./text-input-disabled.story?raw"));
58
63
  const text_input_email_story_raw_1 = __importDefault(require("./text-input-email.story?raw"));
@@ -60,6 +65,7 @@ const text_input_error_story_raw_1 = __importDefault(require("./text-input-error
60
65
  const text_input_full_story_raw_1 = __importDefault(require("./text-input-full.story?raw"));
61
66
  const text_input_information_icon_story_raw_1 = __importDefault(require("./text-input-information-icon.story?raw"));
62
67
  const text_input_loading_story_raw_1 = __importDefault(require("./text-input-loading.story?raw"));
68
+ const text_input_loading_spinner_story_raw_1 = __importDefault(require("./text-input-loading-spinner.story?raw"));
63
69
  const text_input_number_story_raw_1 = __importDefault(require("./text-input-number.story?raw"));
64
70
  const text_input_optional_story_raw_1 = __importDefault(require("./text-input-optional.story?raw"));
65
71
  const text_input_password_story_raw_1 = __importDefault(require("./text-input-password.story?raw"));
@@ -81,4 +87,6 @@ exports.TextInputPasswordSource = (0, export_stories_utils_1.removeLicenseHeader
81
87
  exports.TextInputSizesSource = (0, export_stories_utils_1.removeLicenseHeader)(text_input_sizes_story_raw_1.default);
82
88
  exports.TextInputLoadingSource = (0, export_stories_utils_1.removeLicenseHeader)(text_input_loading_story_raw_1.default);
83
89
  exports.TextInputFullSource = (0, export_stories_utils_1.removeLicenseHeader)(text_input_full_story_raw_1.default);
90
+ exports.TextInputClearableSource = (0, export_stories_utils_1.removeLicenseHeader)(text_input_clearable_story_raw_1.default);
91
+ exports.TextInputLoadingSpinnerSource = (0, export_stories_utils_1.removeLicenseHeader)(text_input_loading_spinner_story_raw_1.default);
84
92
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/text-input/stories/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;;;;AAEH,uEAAyE;AAAhE,6IAAA,OAAO,OAAoB;AACpC,yEAA2E;AAAlE,+IAAA,OAAO,OAAqB;AACrC,yEAA2E;AAAlE,+IAAA,OAAO,OAAqB;AACrC,yEAA2E;AAAlE,+IAAA,OAAO,OAAqB;AACrC,yEAA2E;AAAlE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A,wBAAwB,GAAG,IAAA,0CAAmB,EACzD,yCAA2B,CAC5B,CAAC;AACW,QAAA,uBAAuB,GAAG,IAAA,0CAAmB,EACxD,uCAA0B,CAC3B,CAAC;AACW,QAAA,oBAAoB,GAAG,IAAA,0CAAmB,EACrD,oCAAuB,CACxB,CAAC;AACW,QAAA,sBAAsB,GAAG,IAAA,0CAAmB,EACvD,sCAAyB,CAC1B,CAAC;AACW,QAAA,mBAAmB,GAAG,IAAA,0CAAmB,EAAC,mCAAsB,CAAC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nexport { default as TextInputDefault } from './text-input-default.story';\nexport { default as TextInputRequired } from './text-input-required.story';\nexport { default as TextInputOptional } from './text-input-optional.story';\nexport { default as TextInputDisabled } from './text-input-disabled.story';\nexport { default as TextInputReadonly } from './text-input-readonly.story';\nexport { default as TextInputError } from './text-input-error.story';\nexport { default as TextInputInformationIcon } from './text-input-information-icon.story';\nexport { default as TextInputEmail } from './text-input-email.story';\nexport { default as TextInputNumber } from './text-input-number.story';\nexport { default as TextInputWithIcons } from './text-input-with-icons.story';\nexport { default as TextInputPassword } from './text-input-password.story';\nexport { default as TextInputSizes } from './text-input-sizes.story';\nexport { default as TextInputLoading } from './text-input-loading.story';\nexport { default as TextInputFull } from './text-input-full.story';\n\nimport { removeLicenseHeader } from '../../_common/export-stories-utils';\nimport TextInputDefaultSourceRaw from './text-input-default.story?raw';\nimport TextInputDisabledSourceRaw from './text-input-disabled.story?raw';\nimport TextInputEmailSourceRaw from './text-input-email.story?raw';\nimport TextInputErrorSourceRaw from './text-input-error.story?raw';\nimport TextInputFullSourceRaw from './text-input-full.story?raw';\nimport TextInputInformationIconSourceRaw from './text-input-information-icon.story?raw';\nimport TextInputLoadingSourceRaw from './text-input-loading.story?raw';\nimport TextInputNumberSourceRaw from './text-input-number.story?raw';\nimport TextInputOptionalSourceRaw from './text-input-optional.story?raw';\nimport TextInputPasswordSourceRaw from './text-input-password.story?raw';\nimport TextInputReadonlySourceRaw from './text-input-readonly.story?raw';\nimport TextInputRequiredSourceRaw from './text-input-required.story?raw';\nimport TextInputSizesSourceRaw from './text-input-sizes.story?raw';\nimport TextInputWithIconsSourceRaw from './text-input-with-icons.story?raw';\n\nexport const TextInputDefaultSource = removeLicenseHeader(\n TextInputDefaultSourceRaw,\n);\nexport const TextInputRequiredSource = removeLicenseHeader(\n TextInputRequiredSourceRaw,\n);\nexport const TextInputOptionalSource = removeLicenseHeader(\n TextInputOptionalSourceRaw,\n);\nexport const TextInputDisabledSource = removeLicenseHeader(\n TextInputDisabledSourceRaw,\n);\nexport const TextInputReadonlySource = removeLicenseHeader(\n TextInputReadonlySourceRaw,\n);\nexport const TextInputErrorSource = removeLicenseHeader(\n TextInputErrorSourceRaw,\n);\nexport const TextInputInformationIconSource = removeLicenseHeader(\n TextInputInformationIconSourceRaw,\n);\nexport const TextInputEmailSource = removeLicenseHeader(\n TextInputEmailSourceRaw,\n);\nexport const TextInputNumberSource = removeLicenseHeader(\n TextInputNumberSourceRaw,\n);\nexport const TextInputWithIconsSource = removeLicenseHeader(\n TextInputWithIconsSourceRaw,\n);\nexport const TextInputPasswordSource = removeLicenseHeader(\n TextInputPasswordSourceRaw,\n);\nexport const TextInputSizesSource = removeLicenseHeader(\n TextInputSizesSourceRaw,\n);\nexport const TextInputLoadingSource = removeLicenseHeader(\n TextInputLoadingSourceRaw,\n);\nexport const TextInputFullSource = removeLicenseHeader(TextInputFullSourceRaw);\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/text-input/stories/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;;;;AAEH,uEAAyE;AAAhE,6IAAA,OAAO,OAAoB;AACpC,yEAA2E;AAAlE,+IAAA,OAAO,OAAqB;AACrC,yEAA2E;AAAlE,+IAAA,OAAO,OAAqB;AACrC,yEAA2E;AAAlE,+IAAA,OAAO,OAAqB;AACrC,yEAA2E;AAAlE,+IAAA,OAAO,OAAqB;AACrC,mEAAqE;AAA5D,yIAAA,OAAO,OAAkB;AAClC,yFAA0F;AAAjF,8JAAA,OAAO,OAA4B;AAC5C,mEAAqE;AAA5D,yIAAA,OAAO,OAAkB;AAClC,qEAAuE;AAA9D,2IAAA,OAAO,OAAmB;AACnC,6EAA8E;AAArE,kJAAA,OAAO,OAAsB;AACtC,yEAA2E;AAAlE,+IAAA,OAAO,OAAqB;AACrC,mEAAqE;AAA5D,yIAAA,OAAO,OAAkB;AAClC,uEAAyE;AAAhE,6IAAA,OAAO,OAAoB;AACpC,iEAAmE;AAA1D,uIAAA,OAAO,OAAiB;AACjC,2EAA6E;AAApE,iJAAA,OAAO,OAAsB;AACtC,uFAAwF;AAA/E,4JAAA,OAAO,OAA2B;AAE3C,6EAAyE;AACzE,sGAA2E;AAC3E,kGAAuE;AACvE,oGAAyE;AACzE,8FAAmE;AACnE,8FAAmE;AACnE,4FAAiE;AACjE,oHAAwF;AACxF,kGAAuE;AACvE,kHAAsF;AACtF,gGAAqE;AACrE,oGAAyE;AACzE,oGAAyE;AACzE,oGAAyE;AACzE,oGAAyE;AACzE,8FAAmE;AACnE,wGAA4E;AAE/D,QAAA,sBAAsB,GAAG,IAAA,0CAAmB,EACvD,sCAAyB,CAC1B,CAAC;AACW,QAAA,uBAAuB,GAAG,IAAA,0CAAmB,EACxD,uCAA0B,CAC3B,CAAC;AACW,QAAA,uBAAuB,GAAG,IAAA,0CAAmB,EACxD,uCAA0B,CAC3B,CAAC;AACW,QAAA,uBAAuB,GAAG,IAAA,0CAAmB,EACxD,uCAA0B,CAC3B,CAAC;AACW,QAAA,uBAAuB,GAAG,IAAA,0CAAmB,EACxD,uCAA0B,CAC3B,CAAC;AACW,QAAA,oBAAoB,GAAG,IAAA,0CAAmB,EACrD,oCAAuB,CACxB,CAAC;AACW,QAAA,8BAA8B,GAAG,IAAA,0CAAmB,EAC/D,+CAAiC,CAClC,CAAC;AACW,QAAA,oBAAoB,GAAG,IAAA,0CAAmB,EACrD,oCAAuB,CACxB,CAAC;AACW,QAAA,qBAAqB,GAAG,IAAA,0CAAmB,EACtD,qCAAwB,CACzB,CAAC;AACW,QAAA,wBAAwB,GAAG,IAAA,0CAAmB,EACzD,yCAA2B,CAC5B,CAAC;AACW,QAAA,uBAAuB,GAAG,IAAA,0CAAmB,EACxD,uCAA0B,CAC3B,CAAC;AACW,QAAA,oBAAoB,GAAG,IAAA,0CAAmB,EACrD,oCAAuB,CACxB,CAAC;AACW,QAAA,sBAAsB,GAAG,IAAA,0CAAmB,EACvD,sCAAyB,CAC1B,CAAC;AACW,QAAA,mBAAmB,GAAG,IAAA,0CAAmB,EAAC,mCAAsB,CAAC,CAAC;AAClE,QAAA,wBAAwB,GAAG,IAAA,0CAAmB,EACzD,wCAA2B,CAC5B,CAAC;AACW,QAAA,6BAA6B,GAAG,IAAA,0CAAmB,EAC9D,8CAAgC,CACjC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nexport { default as TextInputDefault } from './text-input-default.story';\nexport { default as TextInputRequired } from './text-input-required.story';\nexport { default as TextInputOptional } from './text-input-optional.story';\nexport { default as TextInputDisabled } from './text-input-disabled.story';\nexport { default as TextInputReadonly } from './text-input-readonly.story';\nexport { default as TextInputError } from './text-input-error.story';\nexport { default as TextInputInformationIcon } from './text-input-information-icon.story';\nexport { default as TextInputEmail } from './text-input-email.story';\nexport { default as TextInputNumber } from './text-input-number.story';\nexport { default as TextInputWithIcons } from './text-input-with-icons.story';\nexport { default as TextInputPassword } from './text-input-password.story';\nexport { default as TextInputSizes } from './text-input-sizes.story';\nexport { default as TextInputLoading } from './text-input-loading.story';\nexport { default as TextInputFull } from './text-input-full.story';\nexport { default as TextInputClearable } from './text-input-clearable.story';\nexport { default as TextInputLoadingSpinner } from './text-input-loading-spinner.story';\n\nimport { removeLicenseHeader } from '../../_common/export-stories-utils';\nimport TextInputClearableSourceRaw from './text-input-clearable.story?raw';\nimport TextInputDefaultSourceRaw from './text-input-default.story?raw';\nimport TextInputDisabledSourceRaw from './text-input-disabled.story?raw';\nimport TextInputEmailSourceRaw from './text-input-email.story?raw';\nimport TextInputErrorSourceRaw from './text-input-error.story?raw';\nimport TextInputFullSourceRaw from './text-input-full.story?raw';\nimport TextInputInformationIconSourceRaw from './text-input-information-icon.story?raw';\nimport TextInputLoadingSourceRaw from './text-input-loading.story?raw';\nimport TextInputLoadingSpinnerSourceRaw from './text-input-loading-spinner.story?raw';\nimport TextInputNumberSourceRaw from './text-input-number.story?raw';\nimport TextInputOptionalSourceRaw from './text-input-optional.story?raw';\nimport TextInputPasswordSourceRaw from './text-input-password.story?raw';\nimport TextInputReadonlySourceRaw from './text-input-readonly.story?raw';\nimport TextInputRequiredSourceRaw from './text-input-required.story?raw';\nimport TextInputSizesSourceRaw from './text-input-sizes.story?raw';\nimport TextInputWithIconsSourceRaw from './text-input-with-icons.story?raw';\n\nexport const TextInputDefaultSource = removeLicenseHeader(\n TextInputDefaultSourceRaw,\n);\nexport const TextInputRequiredSource = removeLicenseHeader(\n TextInputRequiredSourceRaw,\n);\nexport const TextInputOptionalSource = removeLicenseHeader(\n TextInputOptionalSourceRaw,\n);\nexport const TextInputDisabledSource = removeLicenseHeader(\n TextInputDisabledSourceRaw,\n);\nexport const TextInputReadonlySource = removeLicenseHeader(\n TextInputReadonlySourceRaw,\n);\nexport const TextInputErrorSource = removeLicenseHeader(\n TextInputErrorSourceRaw,\n);\nexport const TextInputInformationIconSource = removeLicenseHeader(\n TextInputInformationIconSourceRaw,\n);\nexport const TextInputEmailSource = removeLicenseHeader(\n TextInputEmailSourceRaw,\n);\nexport const TextInputNumberSource = removeLicenseHeader(\n TextInputNumberSourceRaw,\n);\nexport const TextInputWithIconsSource = removeLicenseHeader(\n TextInputWithIconsSourceRaw,\n);\nexport const TextInputPasswordSource = removeLicenseHeader(\n TextInputPasswordSourceRaw,\n);\nexport const TextInputSizesSource = removeLicenseHeader(\n TextInputSizesSourceRaw,\n);\nexport const TextInputLoadingSource = removeLicenseHeader(\n TextInputLoadingSourceRaw,\n);\nexport const TextInputFullSource = removeLicenseHeader(TextInputFullSourceRaw);\nexport const TextInputClearableSource = removeLicenseHeader(\n TextInputClearableSourceRaw,\n);\nexport const TextInputLoadingSpinnerSource = removeLicenseHeader(\n TextInputLoadingSpinnerSourceRaw,\n);\n"]}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ /**
5
+ *
6
+ * Copyright (c) "Neo4j"
7
+ * Neo4j Sweden AB [http://neo4j.com]
8
+ *
9
+ * This file is part of Neo4j.
10
+ *
11
+ * Neo4j is free software: you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation, either version 3 of the License, or
14
+ * (at your option) any later version.
15
+ *
16
+ * This program is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ */
24
+ require("@neo4j-ndl/base/lib/neo4j-ds-styles.css");
25
+ const react_1 = require("@neo4j-ndl/react");
26
+ const Component = () => {
27
+ return ((0, jsx_runtime_1.jsx)(react_1.TextInput, { label: "Clearable", isClearable: true, placeholder: "Type something" }));
28
+ };
29
+ exports.default = Component;
30
+ //# sourceMappingURL=text-input-clearable.story.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-input-clearable.story.js","sourceRoot":"","sources":["../../../../src/text-input/stories/text-input-clearable.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,4CAA6C;AAE7C,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,OAAO,CACL,uBAAC,iBAAS,IAAC,KAAK,EAAC,WAAW,EAAC,WAAW,QAAC,WAAW,EAAC,gBAAgB,GAAG,CACzE,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { TextInput } from '@neo4j-ndl/react';\n\nconst Component = () => {\n return (\n <TextInput label=\"Clearable\" isClearable placeholder=\"Type something\" />\n );\n};\n\nexport default Component;\n"]}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ /**
5
+ *
6
+ * Copyright (c) "Neo4j"
7
+ * Neo4j Sweden AB [http://neo4j.com]
8
+ *
9
+ * This file is part of Neo4j.
10
+ *
11
+ * Neo4j is free software: you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation, either version 3 of the License, or
14
+ * (at your option) any later version.
15
+ *
16
+ * This program is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ */
24
+ require("@neo4j-ndl/base/lib/neo4j-ds-styles.css");
25
+ const react_1 = require("@neo4j-ndl/react");
26
+ const icons_1 = require("@neo4j-ndl/react/icons");
27
+ const Component = () => {
28
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "n-flex n-flex-col n-gap-token-16", children: [(0, jsx_runtime_1.jsx)(react_1.TextInput, { label: "Default loading", isLoading: true, placeholder: "Placeholder" }), (0, jsx_runtime_1.jsx)(react_1.TextInput, { label: "With leading element", isLoading: true, leadingElement: (0, jsx_runtime_1.jsx)(icons_1.CalendarDaysIconOutline, {}), placeholder: "Placeholder" }), (0, jsx_runtime_1.jsx)(react_1.TextInput, { label: "With trailing element", isLoading: true, trailingElement: (0, jsx_runtime_1.jsx)(icons_1.CalendarDaysIconOutline, {}), placeholder: "Placeholder" }), (0, jsx_runtime_1.jsx)(react_1.TextInput, { label: "With leading and trailing element", isLoading: true, leadingElement: (0, jsx_runtime_1.jsx)(icons_1.CalendarDaysIconOutline, {}), trailingElement: (0, jsx_runtime_1.jsx)(icons_1.CalendarDaysIconOutline, {}), placeholder: "Placeholder" })] }));
29
+ };
30
+ exports.default = Component;
31
+ //# sourceMappingURL=text-input-loading-spinner.story.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-input-loading-spinner.story.js","sourceRoot":"","sources":["../../../../src/text-input/stories/text-input-loading-spinner.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,4CAA6C;AAC7C,kDAAiE;AAEjE,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,OAAO,CACL,iCAAK,SAAS,EAAC,kCAAkC,aAC/C,uBAAC,iBAAS,IAAC,KAAK,EAAC,iBAAiB,EAAC,SAAS,QAAC,WAAW,EAAC,aAAa,GAAG,EACzE,uBAAC,iBAAS,IACR,KAAK,EAAC,sBAAsB,EAC5B,SAAS,QACT,cAAc,EAAE,uBAAC,+BAAuB,KAAG,EAC3C,WAAW,EAAC,aAAa,GACzB,EACF,uBAAC,iBAAS,IACR,KAAK,EAAC,uBAAuB,EAC7B,SAAS,QACT,eAAe,EAAE,uBAAC,+BAAuB,KAAG,EAC5C,WAAW,EAAC,aAAa,GACzB,EACF,uBAAC,iBAAS,IACR,KAAK,EAAC,mCAAmC,EACzC,SAAS,QACT,cAAc,EAAE,uBAAC,+BAAuB,KAAG,EAC3C,eAAe,EAAE,uBAAC,+BAAuB,KAAG,EAC5C,WAAW,EAAC,aAAa,GACzB,IACE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { TextInput } from '@neo4j-ndl/react';\nimport { CalendarDaysIconOutline } from '@neo4j-ndl/react/icons';\n\nconst Component = () => {\n return (\n <div className=\"n-flex n-flex-col n-gap-token-16\">\n <TextInput label=\"Default loading\" isLoading placeholder=\"Placeholder\" />\n <TextInput\n label=\"With leading element\"\n isLoading\n leadingElement={<CalendarDaysIconOutline />}\n placeholder=\"Placeholder\"\n />\n <TextInput\n label=\"With trailing element\"\n isLoading\n trailingElement={<CalendarDaysIconOutline />}\n placeholder=\"Placeholder\"\n />\n <TextInput\n label=\"With leading and trailing element\"\n isLoading\n leadingElement={<CalendarDaysIconOutline />}\n trailingElement={<CalendarDaysIconOutline />}\n placeholder=\"Placeholder\"\n />\n </div>\n );\n};\n\nexport default Component;\n"]}
@@ -27,9 +27,7 @@ const icons_1 = require("@neo4j-ndl/react/icons");
27
27
  const react_2 = require("react");
28
28
  const Component = () => {
29
29
  const [searchValue, setSearchValue] = (0, react_2.useState)('');
30
- return ((0, jsx_runtime_1.jsx)(react_1.TextInput, { label: "Search", leadingElement: (0, jsx_runtime_1.jsx)(icons_1.MagnifyingGlassIconOutline, {}), trailingElement: (0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { onClick: () => setSearchValue(''), description: "clear search", children: (0, jsx_runtime_1.jsx)(icons_1.XMarkIconOutline, {}) }), placeholder: "Search...", value: searchValue, onChange: (e) => setSearchValue(e.target.value), htmlAttributes: {
31
- type: 'text',
32
- } }));
30
+ return ((0, jsx_runtime_1.jsx)(react_1.TextInput, { label: "With icons", leadingElement: (0, jsx_runtime_1.jsx)(icons_1.DatabasePlugIcon, {}), trailingElement: (0, jsx_runtime_1.jsx)(icons_1.DatabasePlusIcon, {}), value: searchValue, onChange: (e) => setSearchValue(e.target.value) }));
33
31
  };
34
32
  exports.default = Component;
35
33
  //# sourceMappingURL=text-input-with-icons.story.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-input-with-icons.story.js","sourceRoot":"","sources":["../../../../src/text-input/stories/text-input-with-icons.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,4CAA8D;AAC9D,kDAGgC;AAChC,iCAAiC;AAEjC,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IAEnD,OAAO,CACL,uBAAC,iBAAS,IACR,KAAK,EAAC,QAAQ,EACd,cAAc,EAAE,uBAAC,kCAA0B,KAAG,EAC9C,eAAe,EACb,uBAAC,uBAAe,IACd,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,EACjC,WAAW,EAAC,cAAc,YAE1B,uBAAC,wBAAgB,KAAG,GACJ,EAEpB,WAAW,EAAC,WAAW,EACvB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC/C,cAAc,EAAE;YACd,IAAI,EAAE,MAAM;SACb,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { CleanIconButton, TextInput } from '@neo4j-ndl/react';\nimport {\n MagnifyingGlassIconOutline,\n XMarkIconOutline,\n} from '@neo4j-ndl/react/icons';\nimport { useState } from 'react';\n\nconst Component = () => {\n const [searchValue, setSearchValue] = useState('');\n\n return (\n <TextInput\n label=\"Search\"\n leadingElement={<MagnifyingGlassIconOutline />}\n trailingElement={\n <CleanIconButton\n onClick={() => setSearchValue('')}\n description=\"clear search\"\n >\n <XMarkIconOutline />\n </CleanIconButton>\n }\n placeholder=\"Search...\"\n value={searchValue}\n onChange={(e) => setSearchValue(e.target.value)}\n htmlAttributes={{\n type: 'text',\n }}\n />\n );\n};\n\nexport default Component;\n"]}
1
+ {"version":3,"file":"text-input-with-icons.story.js","sourceRoot":"","sources":["../../../../src/text-input/stories/text-input-with-icons.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,4CAA6C;AAC7C,kDAA4E;AAC5E,iCAAiC;AAEjC,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IAEnD,OAAO,CACL,uBAAC,iBAAS,IACR,KAAK,EAAC,YAAY,EAClB,cAAc,EAAE,uBAAC,wBAAgB,KAAG,EACpC,eAAe,EAAE,uBAAC,wBAAgB,KAAG,EACrC,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAC/C,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { TextInput } from '@neo4j-ndl/react';\nimport { DatabasePlugIcon, DatabasePlusIcon } from '@neo4j-ndl/react/icons';\nimport { useState } from 'react';\n\nconst Component = () => {\n const [searchValue, setSearchValue] = useState('');\n\n return (\n <TextInput\n label=\"With icons\"\n leadingElement={<DatabasePlugIcon />}\n trailingElement={<DatabasePlusIcon />}\n value={searchValue}\n onChange={(e) => setSearchValue(e.target.value)}\n />\n );\n};\n\nexport default Component;\n"]}