import React from "react"; import { Meta, StoryFn } from "@storybook/react"; import { helpersArgTypes } from "../../../../.storybook/helpers"; import characters from "../../../common/utils/characters"; import { TextField, TextFieldProps } from "../TextField"; export default { title: "Forms/TextField", component: TextField, argTypes: { leftIcon: { ...helpersArgTypes.exampleIcon, }, rightElement: { ...helpersArgTypes.exampleIcon, }, intent: { ...helpersArgTypes.exampleIntent, }, }, } as Meta; const Template: StoryFn = (args) => ; export const Default = Template.bind({}); Default.args = { fullWidth: false, placeholder: "placeholder text", readOnly: false, disabled: false, }; /** Text field with default value that contains a zero width/invisible character. * As long as the character exists, an alert is raised for every value change with a delay of 500ms. * Instead of an alert, something more sophisticated like a clean up action should be offered in production. */ export const InvisibleCharacterWarning = Template.bind({}); const invisibleCharacterWarningProps: TextFieldProps = { ...Default.args, invisibleCharacterWarning: { callback: (codePoints) => { if (codePoints.size) { const codePointsString = [...Array.from(codePoints)] .map((n) => { const info = characters.invisibleZeroWidthCharacters.codePointMap.get(n); return info?.fullLabel; }) .join(", "); alert("Invisible character detected in input string. Code points: " + codePointsString); } }, callbackDelay: 500, }, onChange: () => { /** needs to be defined, else the invisible character warning callback will not be triggered. */ }, defaultValue: "Invisible character ->โ€‹<-", }; InvisibleCharacterWarning.args = invisibleCharacterWarningProps; /** Text field showing that emoji (โœ”๏ธ variation-selector, ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ ZWJ, #๏ธโƒฃ keycap) * are NOT reported as invisible characters, while a genuine ZWS still is. */ export const InvisibleCharacterWarningWithEmoji = Template.bind({}); const invisibleCharacterWarningWithEmojiProps: TextFieldProps = { ...Default.args, invisibleCharacterWarning: { callback: (codePoints) => { if (codePoints.size) { const codePointsString = [...codePoints] .map((n) => characters.invisibleZeroWidthCharacters.codePointMap.get(n)?.fullLabel) .join(", "); alert("Invisible character detected in input string. Code points: " + codePointsString); } }, callbackDelay: 500, }, onChange: () => {}, // ZWS should be flagged; โœ”๏ธ ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ #๏ธโƒฃ should NOT be flagged defaultValue: "Check\u200B โœ”๏ธ ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ #๏ธโƒฃ", }; InvisibleCharacterWarningWithEmoji.args = invisibleCharacterWarningWithEmojiProps;