@lumx/react 2.1.0 → 2.1.4
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.
- package/README.md +1 -1
- package/esm/_internal/Button2.js.map +1 -1
- package/esm/_internal/ButtonRoot.js +14 -4
- package/esm/_internal/ButtonRoot.js.map +1 -1
- package/esm/_internal/ClickAwayProvider.js +1 -1
- package/esm/_internal/Dialog2.js +13 -8
- package/esm/_internal/Dialog2.js.map +1 -1
- package/esm/_internal/Flag2.js +1 -3
- package/esm/_internal/Flag2.js.map +1 -1
- package/esm/_internal/IconButton.js +7 -6
- package/esm/_internal/IconButton.js.map +1 -1
- package/esm/_internal/List2.js +16 -9
- package/esm/_internal/List2.js.map +1 -1
- package/esm/_internal/Message2.js +2 -2
- package/esm/_internal/Message2.js.map +1 -1
- package/esm/_internal/SlideshowControls.js +3 -3
- package/esm/_internal/SlideshowControls.js.map +1 -1
- package/esm/_internal/TextField.js +5 -2
- package/esm/_internal/TextField.js.map +1 -1
- package/esm/_internal/Tooltip2.js +1 -1
- package/esm/_internal/getRootClassName.js +17 -1
- package/esm/_internal/getRootClassName.js.map +1 -1
- package/package.json +4 -4
- package/src/components/avatar/Avatar.stories.tsx +1 -1
- package/src/components/button/Button.stories.tsx +95 -10
- package/src/components/button/Button.tsx +2 -0
- package/src/components/button/ButtonRoot.test.tsx +13 -0
- package/src/components/button/ButtonRoot.tsx +10 -1
- package/src/components/button/IconButton.test.tsx +20 -1
- package/src/components/button/IconButton.tsx +20 -7
- package/src/components/button/__snapshots__/ButtonRoot.test.tsx.snap +13 -0
- package/src/components/button/__snapshots__/IconButton.test.tsx.snap +38 -0
- package/src/components/comment-block/CommentBlock.stories.tsx +1 -1
- package/src/components/dialog/Dialog.stories.tsx +45 -3
- package/src/components/dialog/Dialog.tsx +15 -11
- package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +76 -0
- package/src/components/flag/Flag.test.tsx +1 -2
- package/src/components/flag/Flag.tsx +2 -10
- package/src/components/flag/__snapshots__/Flag.test.tsx.snap +0 -15
- package/src/components/image-block/ImageBlock.stories.tsx +1 -1
- package/src/components/link-preview/LinkPreview.stories.tsx +1 -1
- package/src/components/list/List.stories.tsx +7 -1
- package/src/components/list/ListItem.stories.tsx +28 -3
- package/src/components/list/ListItem.tsx +25 -7
- package/src/components/list/__snapshots__/List.test.tsx.snap +23 -3
- package/src/components/list/__snapshots__/ListItem.test.tsx.snap +84 -11
- package/src/components/list/useInteractiveList.tsx +1 -1
- package/src/components/message/Message.tsx +2 -2
- package/src/components/skeleton/SkeletonRectangle.stories.tsx +1 -1
- package/src/components/slideshow/useKeyNavigate.ts +2 -2
- package/src/components/text-field/TextField.stories.tsx +97 -82
- package/src/components/text-field/TextField.tsx +5 -0
- package/src/components/thumbnail/Thumbnail.stories.tsx +1 -1
- package/src/components/user-block/UserBlock.stories.tsx +1 -1
- package/src/stories/generated/Button/Demos.stories.tsx +1 -0
- package/src/stories/knobs/buttonKnob.ts +9 -0
- package/src/stories/knobs/emphasisKnob.ts +8 -0
- package/src/utils/MaterialThemeSwitcher/MaterialThemeSwitcher.tsx +54 -0
- package/src/utils/MaterialThemeSwitcher/index.ts +1 -0
- package/types.d.ts +16 -5
- package/src/stories/knobs/index.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.js","sources":["../../../src/components/text-field/TextField.tsx"],"sourcesContent":["import React, { forwardRef, ReactNode, RefObject, SyntheticEvent, useEffect, useMemo, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\nimport get from 'lodash/get';\nimport { uid } from 'uid';\n\nimport { mdiAlertCircle, mdiCheckCircle, mdiCloseCircle } from '@lumx/icons';\nimport { Emphasis, Icon, IconButton, IconButtonProps, InputHelper, InputLabel, Kind, Size, Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\n\n/**\n * Defines the props of the component.\n */\nexport interface TextFieldProps extends GenericProps {\n /** Chip Group to be rendered before the main text input. */\n chips?: HTMLElement | ReactNode;\n /** Props to pass to the clear button (minus those already set by the TextField props). If not specified, the button won't be displayed. */\n clearButtonProps?: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis'>;\n /** Error message. */\n error?: string | ReactNode;\n /** Whether we force the focus style or not. */\n forceFocusStyle?: boolean;\n /** Whether the text field is displayed with error style or not. */\n hasError?: boolean;\n /** Helper text. */\n helper?: string | ReactNode;\n /** Icon (SVG path). */\n icon?: string;\n /** Native input id property (generated if not provided to link the label element). */\n id?: string;\n /** Reference to the <input> or <textarea> element. */\n inputRef?: RefObject<HTMLInputElement> | RefObject<HTMLTextAreaElement>;\n /** Whether the component is disabled or not. */\n isDisabled?: boolean;\n /** Whether the component is required or not. */\n isRequired?: boolean;\n /** Whether the text field is displayed with valid style or not. */\n isValid?: boolean;\n /** Label text. */\n label?: string;\n /** Max string length the input accepts (constrains the input and displays a character counter). */\n maxLength?: number;\n /** Minimum number of rows displayed in multiline mode (requires `multiline` to be enabled). */\n minimumRows?: number;\n /** Whether the text field is a textarea or an input. */\n multiline?: boolean;\n /** Native input name property. */\n name?: string;\n /** Placeholder text. */\n placeholder?: string;\n /** Reference to the wrapper. */\n textFieldRef?: RefObject<HTMLDivElement>;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Value. */\n value?: string;\n /** On blur callback. */\n onBlur?(event: React.FocusEvent): void;\n /** On change callback. */\n onChange(value: string, name?: string, event?: SyntheticEvent): void;\n /** On focus callback. */\n onFocus?(event: React.FocusEvent): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'TextField';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Default minimum number of rows in the multiline mode.\n */\nconst DEFAULT_MIN_ROWS = 2;\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<TextFieldProps> = {\n theme: Theme.light,\n type: 'text',\n};\n\n/**\n * Hook that allows to calculate the number of rows needed for a text area.\n * @param minimumRows Minimum number of rows that we want to display.\n * @return rows to be used and a callback to recalculate\n */\nconst useComputeNumberOfRows = (\n minimumRows: number,\n): {\n /** number of rows to be used on the text area */\n rows: number;\n /**\n * Callback in order to recalculate the number of rows due to a change on the text area\n */\n recomputeNumberOfRows(target: Element): void;\n} => {\n const [rows, setRows] = useState(minimumRows);\n\n const recompute = (target: Element) => {\n /**\n * HEAD's UP! This part is a little bit tricky. The idea here is to only\n * display the necessary rows on the textarea. In order to dynamically adjust\n * the height on that field, we need to:\n * 1. Set the current amount of rows to the minimum. That will make the scroll appear.\n * 2. With that, we will have the `scrollHeight`, meaning the height of the container adjusted to the current content\n * 3. With the scroll height, we can figure out how many rows we need to use by dividing the scroll height\n * by the line height.\n * 4. With that number, we can readjust the number of rows on the text area. We need to do that here, if we leave that to\n * the state change through React, there are some scenarios (resize, hitting ENTER or BACKSPACE which add or remove lines)\n * when we will not see the update and the rows will be resized to the minimum.\n * 5. In case there is any other update on the component that changes the UI, we need to keep the number of rows\n * on the state in order to allow React to re-render. Therefore, we save them using `useState`\n */\n // eslint-disable-next-line no-param-reassign\n (target as HTMLTextAreaElement).rows = minimumRows;\n let currentRows = target.scrollHeight / (target.clientHeight / minimumRows);\n currentRows = currentRows >= minimumRows ? currentRows : minimumRows;\n // eslint-disable-next-line no-param-reassign\n (target as HTMLTextAreaElement).rows = currentRows;\n\n setRows(currentRows);\n };\n\n return {\n recomputeNumberOfRows: recompute,\n rows,\n };\n};\n\ninterface InputNativeProps {\n id?: string;\n inputRef?: RefObject<HTMLInputElement> | RefObject<HTMLTextAreaElement>;\n isDisabled?: boolean;\n isRequired?: boolean;\n multiline?: boolean;\n maxLength?: number;\n placeholder?: string;\n rows: number;\n type: string;\n name?: string;\n value?: string;\n setFocus(focus: boolean): void;\n recomputeNumberOfRows(target: Element): void;\n onChange(value: string, name?: string, event?: SyntheticEvent): void;\n onFocus?(value: React.FocusEvent): void;\n onBlur?(value: React.FocusEvent): void;\n}\n\nconst renderInputNative: React.FC<InputNativeProps> = (props) => {\n const {\n id,\n isDisabled,\n isRequired,\n placeholder,\n multiline,\n value,\n setFocus,\n onChange,\n onFocus,\n onBlur,\n inputRef,\n rows,\n recomputeNumberOfRows,\n type,\n name,\n ...forwardedProps\n } = props;\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const ref = useRef<HTMLElement>(null);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n // Recompute the number of rows for the first rendering\n if (multiline && ref && ref.current) {\n recomputeNumberOfRows(ref.current);\n }\n }, [ref, multiline, recomputeNumberOfRows, value]);\n\n const onTextFieldFocus = (event: React.FocusEvent) => {\n onFocus?.(event);\n setFocus(true);\n };\n\n const onTextFieldBlur = (event: React.FocusEvent) => {\n onBlur?.(event);\n setFocus(false);\n };\n\n const handleChange = (event: React.ChangeEvent) => {\n onChange(get(event, 'target.value'), name, event);\n };\n\n const Component = multiline ? 'textarea' : 'input';\n const inputProps: any = {\n ...forwardedProps,\n id,\n className: multiline\n ? `${CLASSNAME}__input-native ${CLASSNAME}__input-native--textarea`\n : `${CLASSNAME}__input-native ${CLASSNAME}__input-native--text`,\n placeholder,\n value,\n name,\n disabled: isDisabled,\n required: isRequired,\n onFocus: onTextFieldFocus,\n onBlur: onTextFieldBlur,\n onChange: handleChange,\n ref: mergeRefs(inputRef as any, ref) as any,\n };\n if (multiline) {\n inputProps.rows = rows;\n } else {\n inputProps.type = type;\n }\n return <Component {...inputProps} />;\n};\n\n/**\n * TextField component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const TextField: Comp<TextFieldProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n chips,\n className,\n clearButtonProps,\n disabled,\n error,\n forceFocusStyle,\n hasError,\n helper,\n icon,\n id,\n inputRef,\n isDisabled = disabled,\n isRequired,\n isValid,\n label,\n maxLength,\n minimumRows,\n multiline,\n name,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n textFieldRef,\n theme,\n type,\n value,\n ...forwardedProps\n } = props;\n const textFieldId = useMemo(() => id || `text-field-${uid()}`, [id]);\n const [isFocus, setFocus] = useState(false);\n const { rows, recomputeNumberOfRows } = useComputeNumberOfRows(multiline ? minimumRows || DEFAULT_MIN_ROWS : 0);\n const valueLength = (value || '').length;\n const isNotEmpty = valueLength > 0;\n\n /**\n * Function triggered when the Clear Button is clicked.\n * The idea is to execute the `onChange` callback with an empty string\n * and remove focus from the clear button.\n * @param evt On clear event.\n */\n const onClear = (evt: React.ChangeEvent) => {\n evt.nativeEvent.preventDefault();\n evt.nativeEvent.stopPropagation();\n (evt.currentTarget as HTMLElement).blur();\n\n onChange('');\n };\n\n return (\n <div\n ref={ref}\n className={classNames(\n className,\n handleBasicClasses({\n hasChips: Boolean(chips),\n hasError: !isValid && hasError,\n hasIcon: Boolean(icon),\n hasInput: !multiline,\n hasInputClear: clearButtonProps && isNotEmpty,\n hasLabel: Boolean(label),\n hasPlaceholder: Boolean(placeholder),\n hasTextarea: multiline,\n hasValue: Boolean(value),\n isDisabled,\n isFocus: isFocus || forceFocusStyle,\n isValid,\n prefix: CLASSNAME,\n theme,\n }),\n )}\n >\n {label && (\n <div className={`${CLASSNAME}__header`}>\n <InputLabel\n htmlFor={textFieldId}\n className={`${CLASSNAME}__label`}\n isRequired={isRequired}\n theme={theme}\n >\n {label}\n </InputLabel>\n\n {maxLength && (\n <div className={`${CLASSNAME}__char-counter`}>\n <span>{maxLength - valueLength}</span>\n {maxLength - valueLength === 0 && <Icon icon={mdiAlertCircle} size={Size.xxs} />}\n </div>\n )}\n </div>\n )}\n\n <div className={`${CLASSNAME}__wrapper`} ref={textFieldRef}>\n {icon && (\n <Icon\n className={`${CLASSNAME}__input-icon`}\n color={theme === Theme.dark ? 'light' : undefined}\n icon={icon}\n size={Size.xs}\n />\n )}\n\n {chips && (\n <div className={`${CLASSNAME}__chips`}>\n {chips}\n\n {renderInputNative({\n id: textFieldId,\n inputRef,\n isDisabled,\n isRequired,\n maxLength,\n multiline,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n recomputeNumberOfRows,\n rows,\n setFocus,\n type,\n value,\n name,\n ...forwardedProps,\n })}\n </div>\n )}\n\n {!chips && (\n <div className={`${CLASSNAME}__input-wrapper`}>\n {renderInputNative({\n id: textFieldId,\n inputRef,\n isDisabled,\n isRequired,\n maxLength,\n multiline,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n recomputeNumberOfRows,\n rows,\n setFocus,\n type,\n value,\n name,\n ...forwardedProps,\n })}\n </div>\n )}\n\n {(isValid || hasError) && (\n <Icon\n className={`${CLASSNAME}__input-validity`}\n color={theme === Theme.dark ? 'light' : undefined}\n icon={isValid ? mdiCheckCircle : mdiAlertCircle}\n size={Size.xxs}\n />\n )}\n\n {clearButtonProps && isNotEmpty && (\n <IconButton\n {...clearButtonProps}\n className={`${CLASSNAME}__input-clear`}\n icon={mdiCloseCircle}\n emphasis={Emphasis.low}\n size={Size.s}\n theme={theme}\n onClick={onClear}\n type=\"button\"\n />\n )}\n </div>\n\n {hasError && error && (\n <InputHelper className={`${CLASSNAME}__helper`} kind={Kind.error} theme={theme}>\n {error}\n </InputHelper>\n )}\n\n {helper && (\n <InputHelper className={`${CLASSNAME}__helper`} theme={theme}>\n {helper}\n </InputHelper>\n )}\n </div>\n );\n});\nTextField.displayName = COMPONENT_NAME;\nTextField.className = CLASSNAME;\nTextField.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_MIN_ROWS","DEFAULT_PROPS","theme","Theme","light","type","useComputeNumberOfRows","minimumRows","useState","rows","setRows","recompute","target","currentRows","scrollHeight","clientHeight","recomputeNumberOfRows","renderInputNative","props","id","isDisabled","isRequired","placeholder","multiline","value","setFocus","onChange","onFocus","onBlur","inputRef","name","forwardedProps","ref","useRef","useEffect","current","onTextFieldFocus","event","onTextFieldBlur","handleChange","get","Component","inputProps","className","disabled","required","mergeRefs","TextField","forwardRef","chips","clearButtonProps","error","forceFocusStyle","hasError","helper","icon","isValid","label","maxLength","textFieldRef","textFieldId","useMemo","uid","isFocus","valueLength","length","isNotEmpty","onClear","evt","nativeEvent","preventDefault","stopPropagation","currentTarget","blur","classNames","handleBasicClasses","hasChips","Boolean","hasIcon","hasInput","hasInputClear","hasLabel","hasPlaceholder","hasTextarea","hasValue","prefix","mdiAlertCircle","Size","xxs","dark","undefined","xs","mdiCheckCircle","mdiCloseCircle","Emphasis","low","s","Kind","displayName","defaultProps"],"mappings":";;;;;;;;;;;;;AAWA;;;;AAuDA;;;AAGA,IAAMA,cAAc,GAAG,WAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;AAGA,IAAMG,gBAAgB,GAAG,CAAzB;AAEA;;;;AAGA,IAAMC,aAAsC,GAAG;AAC3CC,EAAAA,KAAK,EAAEC,KAAK,CAACC,KAD8B;AAE3CC,EAAAA,IAAI,EAAE;AAFqC,CAA/C;AAKA;;;;;;AAKA,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,CAC3BC,WAD2B,EAS1B;AAAA,kBACuBC,QAAQ,CAACD,WAAD,CAD/B;AAAA;AAAA,MACME,IADN;AAAA,MACYC,OADZ;;AAGD,MAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,MAAD,EAAqB;AACnC;;;;;;;;;;;;;;AAcA;AACCA,IAAAA,MAAD,CAAgCH,IAAhC,GAAuCF,WAAvC;AACA,QAAIM,WAAW,GAAGD,MAAM,CAACE,YAAP,IAAuBF,MAAM,CAACG,YAAP,GAAsBR,WAA7C,CAAlB;AACAM,IAAAA,WAAW,GAAGA,WAAW,IAAIN,WAAf,GAA6BM,WAA7B,GAA2CN,WAAzD,CAlBmC;;AAoBlCK,IAAAA,MAAD,CAAgCH,IAAhC,GAAuCI,WAAvC;A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B;AAKI,IAAA,IAAI,EAAER,IAAI,CAACS,CALf;AAMI,IAAA,KAAK,EAAE9F,KANX;AAOI,IAAA,OAAO,EAAEiE,OAPb;AAQI,IAAA,IAAI,EAAC;AART,KAtER,CA1CJ,EA6HKd,QAAQ,IAAIF,KAAZ,IACG,oBAAC,WAAD;AAAa,IAAA,SAAS,YAAKrD,SAAL,aAAtB;AAAgD,IAAA,IAAI,EAAEmG,IAAI,CAAC9C,KAA3D;AAAkE,IAAA,KAAK,EAAEjD;AAAzE,KACKiD,KADL,CA9HR,EAmIKG,MAAM,IACH,oBAAC,WAAD;AAAa,IAAA,SAAS,YAAKxD,SAAL,aAAtB;AAAgD,IAAA,KAAK,EAAEI;AAAvD,KACKoD,MADL,CApIR,CADJ;AA2IH,CA9LwE;AA+LzEP,SAAS,CAACmD,WAAV,GAAwBrG,cAAxB;AACAkD,SAAS,CAACJ,SAAV,GAAsB7C,SAAtB;AACAiD,SAAS,CAACoD,YAAV,GAAyBlG,aAAzB;;;;"}
|
|
1
|
+
{"version":3,"file":"TextField.js","sources":["../../../src/components/text-field/TextField.tsx"],"sourcesContent":["import React, { forwardRef, ReactNode, RefObject, SyntheticEvent, useEffect, useMemo, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\nimport get from 'lodash/get';\nimport { uid } from 'uid';\n\nimport { mdiAlertCircle, mdiCheckCircle, mdiCloseCircle } from '@lumx/icons';\nimport { Emphasis, Icon, IconButton, IconButtonProps, InputHelper, InputLabel, Kind, Size, Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\n\n/**\n * Defines the props of the component.\n */\nexport interface TextFieldProps extends GenericProps {\n /** Chip Group to be rendered before the main text input. */\n chips?: HTMLElement | ReactNode;\n /** Props to pass to the clear button (minus those already set by the TextField props). If not specified, the button won't be displayed. */\n clearButtonProps?: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis'>;\n /** Error message. */\n error?: string | ReactNode;\n /** Whether we force the focus style or not. */\n forceFocusStyle?: boolean;\n /** Whether the text field is displayed with error style or not. */\n hasError?: boolean;\n /** Additional element to put at the end of the text field. */\n afterElement?: ReactNode;\n /** Helper text. */\n helper?: string | ReactNode;\n /** Icon (SVG path). */\n icon?: string;\n /** Native input id property (generated if not provided to link the label element). */\n id?: string;\n /** Reference to the <input> or <textarea> element. */\n inputRef?: RefObject<HTMLInputElement> | RefObject<HTMLTextAreaElement>;\n /** Whether the component is disabled or not. */\n isDisabled?: boolean;\n /** Whether the component is required or not. */\n isRequired?: boolean;\n /** Whether the text field is displayed with valid style or not. */\n isValid?: boolean;\n /** Label text. */\n label?: string;\n /** Max string length the input accepts (constrains the input and displays a character counter). */\n maxLength?: number;\n /** Minimum number of rows displayed in multiline mode (requires `multiline` to be enabled). */\n minimumRows?: number;\n /** Whether the text field is a textarea or an input. */\n multiline?: boolean;\n /** Native input name property. */\n name?: string;\n /** Placeholder text. */\n placeholder?: string;\n /** Reference to the wrapper. */\n textFieldRef?: RefObject<HTMLDivElement>;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Value. */\n value?: string;\n /** On blur callback. */\n onBlur?(event: React.FocusEvent): void;\n /** On change callback. */\n onChange(value: string, name?: string, event?: SyntheticEvent): void;\n /** On focus callback. */\n onFocus?(event: React.FocusEvent): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'TextField';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Default minimum number of rows in the multiline mode.\n */\nconst DEFAULT_MIN_ROWS = 2;\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<TextFieldProps> = {\n theme: Theme.light,\n type: 'text',\n};\n\n/**\n * Hook that allows to calculate the number of rows needed for a text area.\n * @param minimumRows Minimum number of rows that we want to display.\n * @return rows to be used and a callback to recalculate\n */\nconst useComputeNumberOfRows = (\n minimumRows: number,\n): {\n /** number of rows to be used on the text area */\n rows: number;\n /**\n * Callback in order to recalculate the number of rows due to a change on the text area\n */\n recomputeNumberOfRows(target: Element): void;\n} => {\n const [rows, setRows] = useState(minimumRows);\n\n const recompute = (target: Element) => {\n /**\n * HEAD's UP! This part is a little bit tricky. The idea here is to only\n * display the necessary rows on the textarea. In order to dynamically adjust\n * the height on that field, we need to:\n * 1. Set the current amount of rows to the minimum. That will make the scroll appear.\n * 2. With that, we will have the `scrollHeight`, meaning the height of the container adjusted to the current content\n * 3. With the scroll height, we can figure out how many rows we need to use by dividing the scroll height\n * by the line height.\n * 4. With that number, we can readjust the number of rows on the text area. We need to do that here, if we leave that to\n * the state change through React, there are some scenarios (resize, hitting ENTER or BACKSPACE which add or remove lines)\n * when we will not see the update and the rows will be resized to the minimum.\n * 5. In case there is any other update on the component that changes the UI, we need to keep the number of rows\n * on the state in order to allow React to re-render. Therefore, we save them using `useState`\n */\n // eslint-disable-next-line no-param-reassign\n (target as HTMLTextAreaElement).rows = minimumRows;\n let currentRows = target.scrollHeight / (target.clientHeight / minimumRows);\n currentRows = currentRows >= minimumRows ? currentRows : minimumRows;\n // eslint-disable-next-line no-param-reassign\n (target as HTMLTextAreaElement).rows = currentRows;\n\n setRows(currentRows);\n };\n\n return {\n recomputeNumberOfRows: recompute,\n rows,\n };\n};\n\ninterface InputNativeProps {\n id?: string;\n inputRef?: RefObject<HTMLInputElement> | RefObject<HTMLTextAreaElement>;\n isDisabled?: boolean;\n isRequired?: boolean;\n multiline?: boolean;\n maxLength?: number;\n placeholder?: string;\n rows: number;\n type: string;\n name?: string;\n value?: string;\n setFocus(focus: boolean): void;\n recomputeNumberOfRows(target: Element): void;\n onChange(value: string, name?: string, event?: SyntheticEvent): void;\n onFocus?(value: React.FocusEvent): void;\n onBlur?(value: React.FocusEvent): void;\n}\n\nconst renderInputNative: React.FC<InputNativeProps> = (props) => {\n const {\n id,\n isDisabled,\n isRequired,\n placeholder,\n multiline,\n value,\n setFocus,\n onChange,\n onFocus,\n onBlur,\n inputRef,\n rows,\n recomputeNumberOfRows,\n type,\n name,\n ...forwardedProps\n } = props;\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const ref = useRef<HTMLElement>(null);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n // Recompute the number of rows for the first rendering\n if (multiline && ref && ref.current) {\n recomputeNumberOfRows(ref.current);\n }\n }, [ref, multiline, recomputeNumberOfRows, value]);\n\n const onTextFieldFocus = (event: React.FocusEvent) => {\n onFocus?.(event);\n setFocus(true);\n };\n\n const onTextFieldBlur = (event: React.FocusEvent) => {\n onBlur?.(event);\n setFocus(false);\n };\n\n const handleChange = (event: React.ChangeEvent) => {\n onChange(get(event, 'target.value'), name, event);\n };\n\n const Component = multiline ? 'textarea' : 'input';\n const inputProps: any = {\n ...forwardedProps,\n id,\n className: multiline\n ? `${CLASSNAME}__input-native ${CLASSNAME}__input-native--textarea`\n : `${CLASSNAME}__input-native ${CLASSNAME}__input-native--text`,\n placeholder,\n value,\n name,\n disabled: isDisabled,\n required: isRequired,\n onFocus: onTextFieldFocus,\n onBlur: onTextFieldBlur,\n onChange: handleChange,\n ref: mergeRefs(inputRef as any, ref) as any,\n };\n if (multiline) {\n inputProps.rows = rows;\n } else {\n inputProps.type = type;\n }\n return <Component {...inputProps} />;\n};\n\n/**\n * TextField component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const TextField: Comp<TextFieldProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n chips,\n className,\n clearButtonProps,\n disabled,\n error,\n forceFocusStyle,\n hasError,\n helper,\n icon,\n id,\n inputRef,\n isDisabled = disabled,\n isRequired,\n isValid,\n label,\n maxLength,\n minimumRows,\n multiline,\n name,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n textFieldRef,\n theme,\n type,\n value,\n afterElement,\n ...forwardedProps\n } = props;\n const textFieldId = useMemo(() => id || `text-field-${uid()}`, [id]);\n const [isFocus, setFocus] = useState(false);\n const { rows, recomputeNumberOfRows } = useComputeNumberOfRows(multiline ? minimumRows || DEFAULT_MIN_ROWS : 0);\n const valueLength = (value || '').length;\n const isNotEmpty = valueLength > 0;\n\n /**\n * Function triggered when the Clear Button is clicked.\n * The idea is to execute the `onChange` callback with an empty string\n * and remove focus from the clear button.\n * @param evt On clear event.\n */\n const onClear = (evt: React.ChangeEvent) => {\n evt.nativeEvent.preventDefault();\n evt.nativeEvent.stopPropagation();\n (evt.currentTarget as HTMLElement).blur();\n\n onChange('');\n };\n\n return (\n <div\n ref={ref}\n className={classNames(\n className,\n handleBasicClasses({\n hasChips: Boolean(chips),\n hasError: !isValid && hasError,\n hasIcon: Boolean(icon),\n hasInput: !multiline,\n hasInputClear: clearButtonProps && isNotEmpty,\n hasLabel: Boolean(label),\n hasPlaceholder: Boolean(placeholder),\n hasTextarea: multiline,\n hasValue: Boolean(value),\n isDisabled,\n isFocus: isFocus || forceFocusStyle,\n isValid,\n prefix: CLASSNAME,\n theme,\n }),\n )}\n >\n {label && (\n <div className={`${CLASSNAME}__header`}>\n <InputLabel\n htmlFor={textFieldId}\n className={`${CLASSNAME}__label`}\n isRequired={isRequired}\n theme={theme}\n >\n {label}\n </InputLabel>\n\n {maxLength && (\n <div className={`${CLASSNAME}__char-counter`}>\n <span>{maxLength - valueLength}</span>\n {maxLength - valueLength === 0 && <Icon icon={mdiAlertCircle} size={Size.xxs} />}\n </div>\n )}\n </div>\n )}\n\n <div className={`${CLASSNAME}__wrapper`} ref={textFieldRef}>\n {icon && (\n <Icon\n className={`${CLASSNAME}__input-icon`}\n color={theme === Theme.dark ? 'light' : undefined}\n icon={icon}\n size={Size.xs}\n />\n )}\n\n {chips && (\n <div className={`${CLASSNAME}__chips`}>\n {chips}\n\n {renderInputNative({\n id: textFieldId,\n inputRef,\n isDisabled,\n isRequired,\n maxLength,\n multiline,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n recomputeNumberOfRows,\n rows,\n setFocus,\n type,\n value,\n name,\n ...forwardedProps,\n })}\n </div>\n )}\n\n {!chips && (\n <div className={`${CLASSNAME}__input-wrapper`}>\n {renderInputNative({\n id: textFieldId,\n inputRef,\n isDisabled,\n isRequired,\n maxLength,\n multiline,\n onBlur,\n onChange,\n onFocus,\n placeholder,\n recomputeNumberOfRows,\n rows,\n setFocus,\n type,\n value,\n name,\n ...forwardedProps,\n })}\n </div>\n )}\n\n {(isValid || hasError) && (\n <Icon\n className={`${CLASSNAME}__input-validity`}\n color={theme === Theme.dark ? 'light' : undefined}\n icon={isValid ? mdiCheckCircle : mdiAlertCircle}\n size={Size.xxs}\n />\n )}\n\n {clearButtonProps && isNotEmpty && (\n <IconButton\n {...clearButtonProps}\n className={`${CLASSNAME}__input-clear`}\n icon={mdiCloseCircle}\n emphasis={Emphasis.low}\n size={Size.s}\n theme={theme}\n onClick={onClear}\n type=\"button\"\n />\n )}\n\n {afterElement && <div className={`${CLASSNAME}__after-element`}>{afterElement}</div>}\n </div>\n\n {hasError && error && (\n <InputHelper className={`${CLASSNAME}__helper`} kind={Kind.error} theme={theme}>\n {error}\n </InputHelper>\n )}\n\n {helper && (\n <InputHelper className={`${CLASSNAME}__helper`} theme={theme}>\n {helper}\n </InputHelper>\n )}\n </div>\n );\n});\nTextField.displayName = COMPONENT_NAME;\nTextField.className = CLASSNAME;\nTextField.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_MIN_ROWS","DEFAULT_PROPS","theme","Theme","light","type","useComputeNumberOfRows","minimumRows","useState","rows","setRows","recompute","target","currentRows","scrollHeight","clientHeight","recomputeNumberOfRows","renderInputNative","props","id","isDisabled","isRequired","placeholder","multiline","value","setFocus","onChange","onFocus","onBlur","inputRef","name","forwardedProps","ref","useRef","useEffect","current","onTextFieldFocus","event","onTextFieldBlur","handleChange","get","Component","inputProps","className","disabled","required","mergeRefs","TextField","forwardRef","chips","clearButtonProps","error","forceFocusStyle","hasError","helper","icon","isValid","label","maxLength","textFieldRef","afterElement","textFieldId","useMemo","uid","isFocus","valueLength","length","isNotEmpty","onClear","evt","nativeEvent","preventDefault","stopPropagation","currentTarget","blur","classNames","handleBasicClasses","hasChips","Boolean","hasIcon","hasInput","hasInputClear","hasLabel","hasPlaceholder","hasTextarea","hasValue","prefix","mdiAlertCircle","Size","xxs","dark","undefined","xs","mdiCheckCircle","mdiCloseCircle","Emphasis","low","s","Kind","displayName","defaultProps"],"mappings":";;;;;;;;;;;;;AAWA;;;;AAyDA;;;AAGA,IAAMA,cAAc,GAAG,WAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;AAGA,IAAMG,gBAAgB,GAAG,CAAzB;AAEA;;;;AAGA,IAAMC,aAAsC,GAAG;AAC3CC,EAAAA,KAAK,EAAEC,KAAK,CAACC,KAD8B;AAE3CC,EAAAA,IAAI,EAAE;AAFqC,CAA/C;AAKA;;;;;;AAKA,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,CAC3BC,WAD2B,EAS1B;AAAA,kBACuBC,QAAQ,CAACD,WAAD,CAD/B;AAAA;AAAA,MACME,IADN;AAAA,MACYC,OADZ;;AAGD,MAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,MAAD,EAAqB;AACnC;;;;;;;;;;;;;;AAcA;AACCA,IAAAA,MAAD,CAAgCH,IAAhC,GAAuCF,WAAvC;AACA,QAAIM,WAAW,GAAGD,MAAM,CAACE,YAAP,IAAuBF,MAAM,CAACG,YAAP,GAAsBR,WAA7C,CAAlB;AACAM,IAAAA,WAAW,GAAGA,WAAW,IAAIN,WAAf,GAA6BM,WAA7B,GAA2CN,WAAzD,CAlBmC;;AAoBlCK,IAAAA,MAAD,CAAgCH,IAAhC,GAAuCI,WAAvC;AAEAH,IAAAA,OAAO,CAACG,WAAD,CAAP;AACH,GAvBD;;AAyBA,SAAO;AACHG,IAAAA,qBAA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AAI,EAAER,IAAI,CAACS,CALf;AAMI,IAAA,KAAK,EAAE/F,KANX;AAOI,IAAA,OAAO,EAAEkE,OAPb;AAQI,IAAA,IAAI,EAAC;AART,KAtER,EAkFKR,YAAY,IAAI;AAAK,IAAA,SAAS,YAAK9D,SAAL;AAAd,KAAgD8D,YAAhD,CAlFrB,CA1CJ,EA+HKP,QAAQ,IAAIF,KAAZ,IACG,oBAAC,WAAD;AAAa,IAAA,SAAS,YAAKrD,SAAL,aAAtB;AAAgD,IAAA,IAAI,EAAEoG,IAAI,CAAC/C,KAA3D;AAAkE,IAAA,KAAK,EAAEjD;AAAzE,KACKiD,KADL,CAhIR,EAqIKG,MAAM,IACH,oBAAC,WAAD;AAAa,IAAA,SAAS,YAAKxD,SAAL,aAAtB;AAAgD,IAAA,KAAK,EAAEI;AAAvD,KACKoD,MADL,CAtIR,CADJ;AA6IH,CAjMwE;AAkMzEP,SAAS,CAACoD,WAAV,GAAwBtG,cAAxB;AACAkD,SAAS,CAACJ,SAAV,GAAsB7C,SAAtB;AACAiD,SAAS,CAACqD,YAAV,GAAyBnG,aAAzB;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _objectSpread2, c as _extends, d as _slicedToArray, b as _objectWithoutProperties } from './_rollupPluginBabelHelpers.js';
|
|
2
2
|
import React, { useMemo, cloneElement, useRef, useState, useEffect, forwardRef } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { f as onEscapePressed, g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
4
4
|
import { u as uid } from '../index2.js';
|
|
5
5
|
import { D as DOCUMENT } from './constants.js';
|
|
6
6
|
import get from 'lodash/get';
|
|
@@ -273,6 +273,22 @@ function onEscapePressed(handler) {
|
|
|
273
273
|
handler(evt);
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Handle button key pressed (Enter + Space).
|
|
278
|
+
*
|
|
279
|
+
* @param handler The handler to call.
|
|
280
|
+
* @return The decorated function.
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
function onButtonPressed(handler) {
|
|
284
|
+
return function (evt) {
|
|
285
|
+
if (evt.key !== 'Enter' && evt.key !== ' ') {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
handler(evt);
|
|
290
|
+
};
|
|
291
|
+
}
|
|
276
292
|
|
|
277
293
|
/**
|
|
278
294
|
* The prefix to use for the CSS classes.
|
|
@@ -308,5 +324,5 @@ function getRootClassName(componentName, subComponent) {
|
|
|
308
324
|
return formattedClassName;
|
|
309
325
|
}
|
|
310
326
|
|
|
311
|
-
export { CSS_PREFIX as C, DIALOG_TRANSITION_DURATION as D, NOTIFICATION_TRANSITION_DURATION as N, getBasicClass as a,
|
|
327
|
+
export { CSS_PREFIX as C, DIALOG_TRANSITION_DURATION as D, NOTIFICATION_TRANSITION_DURATION as N, getBasicClass as a, onButtonPressed as b, classnames as c, createCommonjsModule as d, detectHorizontalSwipe as e, onEscapePressed as f, getRootClassName as g, handleBasicClasses as h, onEnterPressed as o };
|
|
312
328
|
//# sourceMappingURL=getRootClassName.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRootClassName.js","sources":["../../../../../node_modules/classnames/index.js","../../../../lumx-core/src/js/utils.ts","../../../../lumx-core/src/js/constants/index.ts","../../../src/utils/getRootClassName.ts"],"sourcesContent":["/*!\n Copyright (c) 2017 Jed Watson.\n Licensed under the MIT License (MIT), see\n http://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = [];\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (!arg) continue;\n\n\t\t\tvar argType = typeof arg;\n\n\t\t\tif (argType === 'string' || argType === 'number') {\n\t\t\t\tclasses.push(arg);\n\t\t\t} else if (Array.isArray(arg) && arg.length) {\n\t\t\t\tvar inner = classNames.apply(null, arg);\n\t\t\t\tif (inner) {\n\t\t\t\t\tclasses.push(inner);\n\t\t\t\t}\n\t\t\t} else if (argType === 'object') {\n\t\t\t\tfor (var key in arg) {\n\t\t\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\t\t\tclasses.push(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn classes.join(' ');\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import classNames from 'classnames';\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport React from 'react';\n\nimport isBoolean from 'lodash/isBoolean';\nimport isEmpty from 'lodash/isEmpty';\nimport kebabCase from 'lodash/kebabCase';\nimport noop from 'lodash/noop';\n\n/**\n * Enhance isEmpty method to also works with numbers.\n *\n * @param value The value to check.\n * @return Whether the input value is empty or != 0.\n */\nconst _isEmpty = (value: any) => {\n if (typeof value === 'number') {\n return value === 0;\n }\n\n return isEmpty(value);\n};\n\n/**\n * Get the basic CSS class for the given type.\n *\n * @param prefix The class name prefix for the generated CSS class.\n * @param type The type of CSS class we want to generate (e.g.: 'color', 'variant', ...).\n * @param value The value of the type of the CSS class (e.g.: 'primary', 'button', ...).\n * @return The basic CSS class.\n */\nexport function getBasicClass({\n prefix,\n type,\n value,\n}: {\n prefix: string;\n type: string;\n value: string | number | boolean | undefined;\n}): string {\n if (isBoolean(value)) {\n if (!value) {\n // False value should not return a class.\n return '';\n }\n const booleanPrefixes = ['has', 'is'];\n\n if (booleanPrefixes.some((booleanPrefix) => type.toString().startsWith(booleanPrefix))) {\n return `${prefix}--${kebabCase(type)}`;\n }\n\n return `${prefix}--is-${kebabCase(type)}`;\n }\n\n return `${prefix}--${kebabCase(type)}-${value}`;\n}\n\n/**\n * Return all basic LumX CSS classes which are available for every components.\n *\n * @see {@link /src/components/index.d.ts} for the possible values of each parameter.\n *\n * @param prefix The class name prefix for the generated CSS class.\n * @param props All the other props you want to generate a class.\n * The rule of thumb: the key is the name of the prop in the class, the value a string that will\n * be used in the classname to represent the value of the given prop.\n * @return All LumX basic CSS classes.\n */\nexport function handleBasicClasses({ prefix, ...props }: { prefix: string; [prop: string]: any }): string {\n const otherClasses: any = {};\n if (!isEmpty(props)) {\n Object.keys(props).forEach((prop) => {\n otherClasses[getBasicClass({ prefix, type: prop, value: props[prop] })] = isBoolean(props[prop])\n ? props[prop]\n : !_isEmpty(props[prop]);\n });\n }\n\n return classNames(prefix, otherClasses);\n}\n\ndeclare type SwipeDirection = 'none' | 'up' | 'down' | 'left' | 'right';\n\n/**\n * Detects swipe direction.\n * Credits: http://javascriptkit.com/javatutors/touchevents2.shtml.\n *\n * @deprecated use `detectHorizontalSwipe` instead if possible (better performance and does not block scroll)\n * @param touchSurface Element that will hold touch events.\n * @param handleSwipe Callback function.\n * @return Function to remove listeners.\n */\nexport function detectSwipe(touchSurface: Element, handleSwipe: (direction: SwipeDirection) => void = noop) {\n let distX: number;\n let distY: number;\n let startX: number;\n let startY: number;\n let direction: SwipeDirection;\n // Required min distance traveled to be considered swipe.\n const threshold = 150;\n // Maximum distance allowed at the same time in perpendicular direction.\n const restraint = 100;\n // Maximum time allowed to travel that distance.\n const allowedTime = 300;\n let elapsedTime: number;\n let startTime: number;\n\n const onTouchStart = (evt: Event) => {\n const [touch] = Array.from((evt as TouchEvent).changedTouches);\n direction = 'none';\n // Const dist = 0;\n startX = touch.pageX;\n startY = touch.pageY;\n // Record time when finger first makes contact with surface.\n startTime = new Date().getTime();\n evt.preventDefault();\n };\n\n const onTouchMove = (evt: Event) => {\n // Prevent scrolling when inside DIV.\n evt.preventDefault();\n };\n\n const onTouchEnd = (evt: Event) => {\n const [touch] = Array.from((evt as TouchEvent).changedTouches);\n // Get horizontal dist traveled by finger while in contact with surface.\n distX = touch.pageX - startX;\n // Get vertical dist traveled by finger while in contact with surface.\n distY = touch.pageY - startY;\n // Get time elapsed.\n elapsedTime = new Date().getTime() - startTime;\n if (elapsedTime <= allowedTime) {\n // First condition for awipe met.\n if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {\n // 2nd condition for horizontal swipe met.\n // If dist traveled is negative, it indicates left swipe.\n direction = distX < 0 ? 'left' : 'right';\n } else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {\n // 2nd condition for vertical swipe met.\n // If dist traveled is negative, it indicates up swipe.\n direction = distY < 0 ? 'up' : 'down';\n }\n }\n handleSwipe(direction);\n evt.preventDefault();\n };\n\n touchSurface.addEventListener('touchstart', onTouchStart, false);\n touchSurface.addEventListener('touchmove', onTouchMove, false);\n touchSurface.addEventListener('touchend', onTouchEnd, false);\n\n return () => {\n touchSurface.removeEventListener('touchstart', onTouchStart, false);\n touchSurface.removeEventListener('touchmove', onTouchMove, false);\n touchSurface.removeEventListener('touchend', onTouchEnd, false);\n };\n}\n\n/**\n * Checks whether or not the browser support passive events.\n * @see https://github.com/Modernizr/Modernizr/blob/6d56d814b9682843313b16060adb25a58d83a317/feature-detects/dom/passiveeventlisteners.js\n */\nfunction isPassiveEventAvailable() {\n let supportsPassiveOption = false;\n try {\n const opts = Object.defineProperty({}, 'passive', {\n get() {\n supportsPassiveOption = true;\n },\n });\n window.addEventListener('testPassiveEventSupport', noop, opts);\n window.removeEventListener('testPassiveEventSupport', noop, opts);\n } catch (e) {\n // ignored\n }\n return supportsPassiveOption;\n}\n\n/**\n * Detects horizontal swipe direction without blocking the browser scroll using passive event.\n * @see http://javascriptkit.com/javatutors/touchevents2.shtml\n * @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md\n */\nexport function detectHorizontalSwipe(touchSurface: Element, handleSwipe: (direction: 'right' | 'left') => void) {\n let startX: number;\n let startY: number;\n // Required min distance traveled to be considered swipe.\n const threshold = 150;\n // Maximum distance allowed at the same time in perpendicular direction.\n const restraint = 150;\n // Maximum time allowed to travel that distance.\n const allowedTime = 300;\n let elapsedTime: number;\n let startTime: number;\n let finished: boolean;\n\n const onTouchStart = (evt: Event) => {\n const [touch] = Array.from((evt as TouchEvent).changedTouches);\n startX = touch.pageX;\n startY = touch.pageY;\n // Record time when finger first makes contact with surface.\n startTime = new Date().getTime();\n finished = false;\n };\n\n const onTouchMove = (evt: Event) => {\n if (finished) {\n return;\n }\n\n elapsedTime = new Date().getTime() - startTime;\n if (elapsedTime > allowedTime) {\n // Touch swipe too long to be considered.\n return;\n }\n\n const [touch] = Array.from((evt as TouchEvent).changedTouches);\n // Get horizontal dist traveled by finger while in contact with surface.\n const distX = touch.pageX - startX;\n // Get vertical dist traveled by finger while in contact with surface.\n const distY = touch.pageY - startY;\n\n if (!(Math.abs(distX) >= threshold && Math.abs(distY) <= restraint)) {\n // Swipe is not horizontal.\n return;\n }\n // Swipe direction.\n const direction = distX < 0 ? 'left' : 'right';\n\n handleSwipe(direction);\n finished = true;\n };\n\n // Activate passive event if possible for better scrolling performance.\n const eventOptions: any = isPassiveEventAvailable() ? { passive: true } : false;\n touchSurface.addEventListener('touchstart', onTouchStart, eventOptions);\n touchSurface.addEventListener('touchmove', onTouchMove, eventOptions);\n\n return () => {\n touchSurface.removeEventListener('touchstart', onTouchStart, eventOptions);\n touchSurface.removeEventListener('touchmove', onTouchMove, eventOptions);\n };\n}\n\ntype KeyboardEventHandler<E extends KeyboardEvent | React.KeyboardEvent> = (event: E) => void;\n\n/**\n * Make sure the pressed key is the enter key before calling the callback.\n *\n * @param handler The handler to call on enter/return press.\n * @return The decorated function.\n */\nexport function onEnterPressed<E extends KeyboardEvent | React.KeyboardEvent>(\n handler: KeyboardEventHandler<E>,\n): KeyboardEventHandler<E> {\n return (evt) => {\n if (evt.key !== 'Enter') {\n return;\n }\n handler(evt);\n };\n}\n\n/**\n * Make sure the pressed key is the escape key before calling the callback.\n *\n * @param handler The handler to call on enter/return press.\n * @return The decorated function.\n */\nexport function onEscapePressed<E extends KeyboardEvent | React.KeyboardEvent>(\n handler: KeyboardEventHandler<E>,\n): KeyboardEventHandler<E> {\n return (evt) => {\n if (evt.key !== 'Escape') {\n return;\n }\n handler(evt);\n };\n}\n","/**\n * The prefix to use for the CSS classes.\n */\nexport const CSS_PREFIX = 'lumx';\n\n/**\n * Key codes.\n */\nexport * from './keycodes';\n\n/**\n * Animation duration constants. Take into consideration that if you change one of these variables,\n * you need to update their scss counterpart as well\n */\nexport const DIALOG_TRANSITION_DURATION = 400;\nexport const NOTIFICATION_TRANSITION_DURATION = 200;\n","import { CSS_PREFIX } from '@lumx/react/constants';\n\nimport kebabCase from 'lodash/kebabCase';\n\n// See https://regex101.com/r/YjS1uI/3\nconst LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;\n\n/**\n * Get the name of the root CSS class of a component based on its name.\n *\n * @param componentName The name of the component. This name should contains the component prefix and be\n * written in PascalCase.\n * @param subComponent Whether the current component is a sub component, if true, define the class according\n * to BEM standards.\n * @return The name of the root CSS class. This classname include the CSS classname prefix and is written in\n * lower-snake-case.\n */\nexport function getRootClassName(componentName: string, subComponent?: boolean): string {\n const formattedClassName = `${CSS_PREFIX}-${kebabCase(componentName)}`;\n\n if (subComponent) {\n return formattedClassName.replace(LAST_PART_CLASSNAME, '$1__$2');\n }\n return formattedClassName;\n}\n"],"names":["_isEmpty","value","isEmpty","getBasicClass","prefix","type","isBoolean","booleanPrefixes","some","booleanPrefix","toString","startsWith","kebabCase","handleBasicClasses","props","otherClasses","Object","keys","forEach","prop","classNames","isPassiveEventAvailable","supportsPassiveOption","opts","defineProperty","get","window","addEventListener","noop","removeEventListener","e","detectHorizontalSwipe","touchSurface","handleSwipe","startX","startY","threshold","restraint","allowedTime","elapsedTime","startTime","finished","onTouchStart","evt","Array","from","changedTouches","touch","pageX","pageY","Date","getTime","onTouchMove","distX","distY","Math","abs","direction","eventOptions","passive","onEnterPressed","handler","key","onEscapePressed","CSS_PREFIX","DIALOG_TRANSITION_DURATION","NOTIFICATION_TRANSITION_DURATION","LAST_PART_CLASSNAME","getRootClassName","componentName","subComponent","formattedClassName","replace"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC,YAAY;AAEb;AACA,CAAC,IAAI,MAAM,GAAG,EAAE,CAAC,cAAc,CAAC;AAChC;AACA,CAAC,SAAS,UAAU,IAAI;AACxB,EAAE,IAAI,OAAO,GAAG,EAAE,CAAC;AACnB;AACA,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAC7C,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAC1B,GAAG,IAAI,CAAC,GAAG,EAAE,SAAS;AACtB;AACA,GAAG,IAAI,OAAO,GAAG,OAAO,GAAG,CAAC;AAC5B;AACA,GAAG,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,QAAQ,EAAE;AACrD,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtB,IAAI,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,EAAE;AAChD,IAAI,IAAI,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC5C,IAAI,IAAI,KAAK,EAAE;AACf,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzB,KAAK;AACL,IAAI,MAAM,IAAI,OAAO,KAAK,QAAQ,EAAE;AACpC,IAAI,KAAK,IAAI,GAAG,IAAI,GAAG,EAAE;AACzB,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,IAA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EAAiDC,YAAjD,EAAiF;AACpF,MAAMC,kBAAkB,aAAMP,UAAN,cAAoBpD,SAAS,CAACyD,aAAD,CAA7B,CAAxB;;AAEA,MAAIC,YAAJ,EAAkB;AACd,WAAOC,kBAAkB,CAACC,OAAnB,CAA2BL,mBAA3B,EAAgD,QAAhD,CAAP;AACH;;AACD,SAAOI,kBAAP;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"getRootClassName.js","sources":["../../../../../node_modules/classnames/index.js","../../../../lumx-core/src/js/utils.ts","../../../../lumx-core/src/js/constants/index.ts","../../../src/utils/getRootClassName.ts"],"sourcesContent":["/*!\n Copyright (c) 2017 Jed Watson.\n Licensed under the MIT License (MIT), see\n http://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = [];\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (!arg) continue;\n\n\t\t\tvar argType = typeof arg;\n\n\t\t\tif (argType === 'string' || argType === 'number') {\n\t\t\t\tclasses.push(arg);\n\t\t\t} else if (Array.isArray(arg) && arg.length) {\n\t\t\t\tvar inner = classNames.apply(null, arg);\n\t\t\t\tif (inner) {\n\t\t\t\t\tclasses.push(inner);\n\t\t\t\t}\n\t\t\t} else if (argType === 'object') {\n\t\t\t\tfor (var key in arg) {\n\t\t\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\t\t\tclasses.push(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn classes.join(' ');\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import classNames from 'classnames';\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport React from 'react';\n\nimport isBoolean from 'lodash/isBoolean';\nimport isEmpty from 'lodash/isEmpty';\nimport kebabCase from 'lodash/kebabCase';\nimport noop from 'lodash/noop';\n\n/**\n * Enhance isEmpty method to also works with numbers.\n *\n * @param value The value to check.\n * @return Whether the input value is empty or != 0.\n */\nconst _isEmpty = (value: any) => {\n if (typeof value === 'number') {\n return value === 0;\n }\n\n return isEmpty(value);\n};\n\n/**\n * Get the basic CSS class for the given type.\n *\n * @param prefix The class name prefix for the generated CSS class.\n * @param type The type of CSS class we want to generate (e.g.: 'color', 'variant', ...).\n * @param value The value of the type of the CSS class (e.g.: 'primary', 'button', ...).\n * @return The basic CSS class.\n */\nexport function getBasicClass({\n prefix,\n type,\n value,\n}: {\n prefix: string;\n type: string;\n value: string | number | boolean | undefined;\n}): string {\n if (isBoolean(value)) {\n if (!value) {\n // False value should not return a class.\n return '';\n }\n const booleanPrefixes = ['has', 'is'];\n\n if (booleanPrefixes.some((booleanPrefix) => type.toString().startsWith(booleanPrefix))) {\n return `${prefix}--${kebabCase(type)}`;\n }\n\n return `${prefix}--is-${kebabCase(type)}`;\n }\n\n return `${prefix}--${kebabCase(type)}-${value}`;\n}\n\n/**\n * Return all basic LumX CSS classes which are available for every components.\n *\n * @see {@link /src/components/index.d.ts} for the possible values of each parameter.\n *\n * @param prefix The class name prefix for the generated CSS class.\n * @param props All the other props you want to generate a class.\n * The rule of thumb: the key is the name of the prop in the class, the value a string that will\n * be used in the classname to represent the value of the given prop.\n * @return All LumX basic CSS classes.\n */\nexport function handleBasicClasses({ prefix, ...props }: { prefix: string; [prop: string]: any }): string {\n const otherClasses: any = {};\n if (!isEmpty(props)) {\n Object.keys(props).forEach((prop) => {\n otherClasses[getBasicClass({ prefix, type: prop, value: props[prop] })] = isBoolean(props[prop])\n ? props[prop]\n : !_isEmpty(props[prop]);\n });\n }\n\n return classNames(prefix, otherClasses);\n}\n\ndeclare type SwipeDirection = 'none' | 'up' | 'down' | 'left' | 'right';\n\n/**\n * Detects swipe direction.\n * Credits: http://javascriptkit.com/javatutors/touchevents2.shtml.\n *\n * @deprecated use `detectHorizontalSwipe` instead if possible (better performance and does not block scroll)\n * @param touchSurface Element that will hold touch events.\n * @param handleSwipe Callback function.\n * @return Function to remove listeners.\n */\nexport function detectSwipe(touchSurface: Element, handleSwipe: (direction: SwipeDirection) => void = noop) {\n let distX: number;\n let distY: number;\n let startX: number;\n let startY: number;\n let direction: SwipeDirection;\n // Required min distance traveled to be considered swipe.\n const threshold = 150;\n // Maximum distance allowed at the same time in perpendicular direction.\n const restraint = 100;\n // Maximum time allowed to travel that distance.\n const allowedTime = 300;\n let elapsedTime: number;\n let startTime: number;\n\n const onTouchStart = (evt: Event) => {\n const [touch] = Array.from((evt as TouchEvent).changedTouches);\n direction = 'none';\n // Const dist = 0;\n startX = touch.pageX;\n startY = touch.pageY;\n // Record time when finger first makes contact with surface.\n startTime = new Date().getTime();\n evt.preventDefault();\n };\n\n const onTouchMove = (evt: Event) => {\n // Prevent scrolling when inside DIV.\n evt.preventDefault();\n };\n\n const onTouchEnd = (evt: Event) => {\n const [touch] = Array.from((evt as TouchEvent).changedTouches);\n // Get horizontal dist traveled by finger while in contact with surface.\n distX = touch.pageX - startX;\n // Get vertical dist traveled by finger while in contact with surface.\n distY = touch.pageY - startY;\n // Get time elapsed.\n elapsedTime = new Date().getTime() - startTime;\n if (elapsedTime <= allowedTime) {\n // First condition for awipe met.\n if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {\n // 2nd condition for horizontal swipe met.\n // If dist traveled is negative, it indicates left swipe.\n direction = distX < 0 ? 'left' : 'right';\n } else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {\n // 2nd condition for vertical swipe met.\n // If dist traveled is negative, it indicates up swipe.\n direction = distY < 0 ? 'up' : 'down';\n }\n }\n handleSwipe(direction);\n evt.preventDefault();\n };\n\n touchSurface.addEventListener('touchstart', onTouchStart, false);\n touchSurface.addEventListener('touchmove', onTouchMove, false);\n touchSurface.addEventListener('touchend', onTouchEnd, false);\n\n return () => {\n touchSurface.removeEventListener('touchstart', onTouchStart, false);\n touchSurface.removeEventListener('touchmove', onTouchMove, false);\n touchSurface.removeEventListener('touchend', onTouchEnd, false);\n };\n}\n\n/**\n * Checks whether or not the browser support passive events.\n * @see https://github.com/Modernizr/Modernizr/blob/6d56d814b9682843313b16060adb25a58d83a317/feature-detects/dom/passiveeventlisteners.js\n */\nfunction isPassiveEventAvailable() {\n let supportsPassiveOption = false;\n try {\n const opts = Object.defineProperty({}, 'passive', {\n get() {\n supportsPassiveOption = true;\n },\n });\n window.addEventListener('testPassiveEventSupport', noop, opts);\n window.removeEventListener('testPassiveEventSupport', noop, opts);\n } catch (e) {\n // ignored\n }\n return supportsPassiveOption;\n}\n\n/**\n * Detects horizontal swipe direction without blocking the browser scroll using passive event.\n * @see http://javascriptkit.com/javatutors/touchevents2.shtml\n * @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md\n */\nexport function detectHorizontalSwipe(touchSurface: Element, handleSwipe: (direction: 'right' | 'left') => void) {\n let startX: number;\n let startY: number;\n // Required min distance traveled to be considered swipe.\n const threshold = 150;\n // Maximum distance allowed at the same time in perpendicular direction.\n const restraint = 150;\n // Maximum time allowed to travel that distance.\n const allowedTime = 300;\n let elapsedTime: number;\n let startTime: number;\n let finished: boolean;\n\n const onTouchStart = (evt: Event) => {\n const [touch] = Array.from((evt as TouchEvent).changedTouches);\n startX = touch.pageX;\n startY = touch.pageY;\n // Record time when finger first makes contact with surface.\n startTime = new Date().getTime();\n finished = false;\n };\n\n const onTouchMove = (evt: Event) => {\n if (finished) {\n return;\n }\n\n elapsedTime = new Date().getTime() - startTime;\n if (elapsedTime > allowedTime) {\n // Touch swipe too long to be considered.\n return;\n }\n\n const [touch] = Array.from((evt as TouchEvent).changedTouches);\n // Get horizontal dist traveled by finger while in contact with surface.\n const distX = touch.pageX - startX;\n // Get vertical dist traveled by finger while in contact with surface.\n const distY = touch.pageY - startY;\n\n if (!(Math.abs(distX) >= threshold && Math.abs(distY) <= restraint)) {\n // Swipe is not horizontal.\n return;\n }\n // Swipe direction.\n const direction = distX < 0 ? 'left' : 'right';\n\n handleSwipe(direction);\n finished = true;\n };\n\n // Activate passive event if possible for better scrolling performance.\n const eventOptions: any = isPassiveEventAvailable() ? { passive: true } : false;\n touchSurface.addEventListener('touchstart', onTouchStart, eventOptions);\n touchSurface.addEventListener('touchmove', onTouchMove, eventOptions);\n\n return () => {\n touchSurface.removeEventListener('touchstart', onTouchStart, eventOptions);\n touchSurface.removeEventListener('touchmove', onTouchMove, eventOptions);\n };\n}\n\ntype KeyboardEventHandler<E extends KeyboardEvent | React.KeyboardEvent> = (event: E) => void;\n\n/**\n * Make sure the pressed key is the enter key before calling the callback.\n *\n * @param handler The handler to call on enter/return press.\n * @return The decorated function.\n */\nexport function onEnterPressed<E extends KeyboardEvent | React.KeyboardEvent>(\n handler: KeyboardEventHandler<E>,\n): KeyboardEventHandler<E> {\n return (evt) => {\n if (evt.key !== 'Enter') {\n return;\n }\n handler(evt);\n };\n}\n\n/**\n * Make sure the pressed key is the escape key before calling the callback.\n *\n * @param handler The handler to call on enter/return press.\n * @return The decorated function.\n */\nexport function onEscapePressed<E extends KeyboardEvent | React.KeyboardEvent>(\n handler: KeyboardEventHandler<E>,\n): KeyboardEventHandler<E> {\n return (evt) => {\n if (evt.key !== 'Escape') {\n return;\n }\n handler(evt);\n };\n}\n\n/**\n * Handle button key pressed (Enter + Space).\n *\n * @param handler The handler to call.\n * @return The decorated function.\n */\nexport function onButtonPressed<E extends KeyboardEvent | React.KeyboardEvent>(\n handler: KeyboardEventHandler<E>,\n): KeyboardEventHandler<E> {\n return (evt) => {\n if (evt.key !== 'Enter' && evt.key !== ' ') {\n return;\n }\n handler(evt);\n };\n}\n","/**\n * The prefix to use for the CSS classes.\n */\nexport const CSS_PREFIX = 'lumx';\n\n/**\n * Key codes.\n */\nexport * from './keycodes';\n\n/**\n * Animation duration constants. Take into consideration that if you change one of these variables,\n * you need to update their scss counterpart as well\n */\nexport const DIALOG_TRANSITION_DURATION = 400;\nexport const NOTIFICATION_TRANSITION_DURATION = 200;\n","import { CSS_PREFIX } from '@lumx/react/constants';\n\nimport kebabCase from 'lodash/kebabCase';\n\n// See https://regex101.com/r/YjS1uI/3\nconst LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;\n\n/**\n * Get the name of the root CSS class of a component based on its name.\n *\n * @param componentName The name of the component. This name should contains the component prefix and be\n * written in PascalCase.\n * @param subComponent Whether the current component is a sub component, if true, define the class according\n * to BEM standards.\n * @return The name of the root CSS class. This classname include the CSS classname prefix and is written in\n * lower-snake-case.\n */\nexport function getRootClassName(componentName: string, subComponent?: boolean): string {\n const formattedClassName = `${CSS_PREFIX}-${kebabCase(componentName)}`;\n\n if (subComponent) {\n return formattedClassName.replace(LAST_PART_CLASSNAME, '$1__$2');\n }\n return formattedClassName;\n}\n"],"names":["_isEmpty","value","isEmpty","getBasicClass","prefix","type","isBoolean","booleanPrefixes","some","booleanPrefix","toString","startsWith","kebabCase","handleBasicClasses","props","otherClasses","Object","keys","forEach","prop","classNames","isPassiveEventAvailable","supportsPassiveOption","opts","defineProperty","get","window","addEventListener","noop","removeEventListener","e","detectHorizontalSwipe","touchSurface","handleSwipe","startX","startY","threshold","restraint","allowedTime","elapsedTime","startTime","finished","onTouchStart","evt","Array","from","changedTouches","touch","pageX","pageY","Date","getTime","onTouchMove","distX","distY","Math","abs","direction","eventOptions","passive","onEnterPressed","handler","key","onEscapePressed","onButtonPressed","CSS_PREFIX","DIALOG_TRANSITION_DURATION","NOTIFICATION_TRANSITION_DURATION","LAST_PART_CLASSNAME","getRootClassName","componentName","subComponent","formattedClassName","replace"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC,YAAY;A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ACpF,MAAMC,kBAAkB,aAAMP,UAAN,cAAoBrD,SAAS,CAAC0D,aAAD,CAA7B,CAAxB;;AAEA,MAAIC,YAAJ,EAAkB;AACd,WAAOC,kBAAkB,CAACC,OAAnB,CAA2BL,mBAA3B,EAAgD,QAAhD,CAAP;AACH;;AACD,SAAOI,kBAAP;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@juggle/resize-observer": "^3.2.0",
|
|
10
|
-
"@lumx/core": "^2.1.
|
|
11
|
-
"@lumx/icons": "^2.1.
|
|
10
|
+
"@lumx/core": "^2.1.4",
|
|
11
|
+
"@lumx/icons": "^2.1.4",
|
|
12
12
|
"@popperjs/core": "^2.5.4",
|
|
13
13
|
"body-scroll-lock": "^3.1.5",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
@@ -123,9 +123,9 @@
|
|
|
123
123
|
"storybook": "start-storybook -s ../site-demo/static/ -p 9000"
|
|
124
124
|
},
|
|
125
125
|
"sideEffects": false,
|
|
126
|
-
"version": "2.1.
|
|
126
|
+
"version": "2.1.4",
|
|
127
127
|
"resolutions": {
|
|
128
128
|
"**/style-loader": "^1.0.0"
|
|
129
129
|
},
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "de78ddf378468c55a56149bcb4568e66a9a88f32"
|
|
131
131
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mdiDelete, mdiEye, mdiPencil, mdiStar } from '@lumx/icons';
|
|
2
2
|
import { AvatarSize, Badge, ColorPalette, Emphasis, Icon, IconButton, Size } from '@lumx/react';
|
|
3
|
-
import { AVATAR_IMAGES, avatarImageKnob, PORTRAIT_IMAGES } from '@lumx/react/stories/knobs';
|
|
3
|
+
import { AVATAR_IMAGES, avatarImageKnob, PORTRAIT_IMAGES } from '@lumx/react/stories/knobs/image';
|
|
4
4
|
import { select } from '@storybook/addon-knobs';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { Button, ColorPalette,
|
|
1
|
+
import React, { Fragment } from 'react';
|
|
2
|
+
import { mdiSend } from '@lumx/icons';
|
|
3
|
+
import { Button, ColorPalette, IconButton } from '@lumx/react';
|
|
4
|
+
import { squareImageKnob } from '@lumx/react/stories/knobs/image';
|
|
5
|
+
import { buttonSize } from '@lumx/react/stories/knobs/buttonKnob';
|
|
6
|
+
import { emphasis } from '@lumx/react/stories/knobs/emphasisKnob';
|
|
4
7
|
import { boolean, select, text } from '@storybook/addon-knobs';
|
|
5
|
-
import React from 'react';
|
|
6
8
|
|
|
7
9
|
export default { title: 'LumX components/button/Button' };
|
|
8
10
|
|
|
@@ -11,11 +13,11 @@ const DEFAULT_PROPS = Button.defaultProps as any;
|
|
|
11
13
|
export const SimpleButton = ({ theme }: any) => {
|
|
12
14
|
return (
|
|
13
15
|
<Button
|
|
14
|
-
emphasis={
|
|
16
|
+
emphasis={emphasis('Emphasis', DEFAULT_PROPS.emphasis)}
|
|
15
17
|
theme={theme}
|
|
16
18
|
rightIcon={select('Right icon', { none: undefined, mdiSend }, undefined)}
|
|
17
19
|
leftIcon={select('Left icon', { none: undefined, mdiSend }, undefined)}
|
|
18
|
-
size={
|
|
20
|
+
size={buttonSize()}
|
|
19
21
|
isSelected={boolean('isSelected', Boolean(DEFAULT_PROPS.isSelected))}
|
|
20
22
|
isDisabled={boolean('isDisabled', Boolean(DEFAULT_PROPS.isDisabled))}
|
|
21
23
|
color={select('color', ColorPalette, DEFAULT_PROPS.color)}
|
|
@@ -37,8 +39,91 @@ export const DisabledWithHref = () => (
|
|
|
37
39
|
</Button>
|
|
38
40
|
);
|
|
39
41
|
|
|
40
|
-
export const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
export const IconButtonWithImage = ({ theme }: any) => (
|
|
43
|
+
<div>
|
|
44
|
+
<IconButton
|
|
45
|
+
theme={theme}
|
|
46
|
+
label="Image label"
|
|
47
|
+
image={squareImageKnob()}
|
|
48
|
+
size={buttonSize()}
|
|
49
|
+
hasBackground={boolean('Has background', false)}
|
|
50
|
+
emphasis={emphasis('Emphasis', DEFAULT_PROPS.emphasis)}
|
|
51
|
+
color={select('color', ColorPalette, DEFAULT_PROPS.color)}
|
|
52
|
+
/>
|
|
53
|
+
</div>
|
|
44
54
|
);
|
|
55
|
+
|
|
56
|
+
export const FullWidthButton = () => <Button fullWidth>Full width button</Button>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Template story to generate all variants for button and icon button.
|
|
60
|
+
*/
|
|
61
|
+
const AllVariantTemplate = (Component: any, props: any) => () => {
|
|
62
|
+
// Major variants.
|
|
63
|
+
const variants = {
|
|
64
|
+
'Default (emphasis high)': {},
|
|
65
|
+
'Full width': { fullWidth: true },
|
|
66
|
+
'Emphasis medium': { emphasis: 'medium' },
|
|
67
|
+
'Emphasis low': { emphasis: 'low' },
|
|
68
|
+
'Has background (emphasis low)': { emphasis: 'low', hasBackground: true },
|
|
69
|
+
'Has background + Full width': { emphasis: 'low', hasBackground: true, fullWidth: true },
|
|
70
|
+
} as const;
|
|
71
|
+
|
|
72
|
+
// Color modifiers.
|
|
73
|
+
const colorModifiers = {
|
|
74
|
+
Default: {},
|
|
75
|
+
'Color: light': { color: 'light' },
|
|
76
|
+
'Color: dark': { color: 'dark' },
|
|
77
|
+
'Color: red': { color: 'red' },
|
|
78
|
+
'Theme: dark': { theme: 'dark' },
|
|
79
|
+
} as const;
|
|
80
|
+
|
|
81
|
+
// State modifiers.
|
|
82
|
+
const stateModifiers = {
|
|
83
|
+
'Default state': {},
|
|
84
|
+
Selected: { isSelected: true },
|
|
85
|
+
Hovered: { isHovered: true },
|
|
86
|
+
Focused: { isFocused: true },
|
|
87
|
+
Active: { isActive: true },
|
|
88
|
+
Disabled: { isDisabled: true },
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div style={{ background: 'lightgray' }}>
|
|
93
|
+
{Object.entries(stateModifiers).map(([stateKey, state]) => (
|
|
94
|
+
<Fragment key={stateKey}>
|
|
95
|
+
<h2>{stateKey}</h2>
|
|
96
|
+
<table style={{ width: '100%' }}>
|
|
97
|
+
<tr>
|
|
98
|
+
<td style={{ whiteSpace: 'nowrap', width: 200 }} />
|
|
99
|
+
{Object.keys(colorModifiers).map((colorKey) => (
|
|
100
|
+
<td key={colorKey}>{colorKey}</td>
|
|
101
|
+
))}
|
|
102
|
+
</tr>
|
|
103
|
+
|
|
104
|
+
{Object.entries(variants).map(([variantKey, variant]: any) => (
|
|
105
|
+
<tr key={variantKey}>
|
|
106
|
+
<td>{variantKey}</td>
|
|
107
|
+
{Object.entries(colorModifiers).map(([colorKey, color]) => (
|
|
108
|
+
<td key={colorKey}>
|
|
109
|
+
<Component {...props} {...variant} {...color} {...state} />
|
|
110
|
+
</td>
|
|
111
|
+
))}
|
|
112
|
+
</tr>
|
|
113
|
+
))}
|
|
114
|
+
</table>
|
|
115
|
+
</Fragment>
|
|
116
|
+
))}
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Check button style variations (color, states, emphasis, etc.)
|
|
123
|
+
*/
|
|
124
|
+
export const ButtonVariations = AllVariantTemplate(Button, { children: 'Button' });
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check icon button style variations (color, states, emphasis, etc.)
|
|
128
|
+
*/
|
|
129
|
+
export const IconButtonVariations = AllVariantTemplate(IconButton, { label: 'Send', icon: mdiSend });
|
|
@@ -168,6 +168,19 @@ describe(`<${ButtonRoot.displayName}>`, () => {
|
|
|
168
168
|
expect(buttonWrapper).toHaveClassName(getBasicClass({ prefix: BUTTON_WRAPPER_CLASSNAME, type, value }));
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
|
+
|
|
172
|
+
it('should be full width', () => {
|
|
173
|
+
const buttonProps: Partial<ButtonRootProps> = {
|
|
174
|
+
fullWidth: true,
|
|
175
|
+
emphasis: Emphasis.high,
|
|
176
|
+
theme: Theme.light,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const { wrapper, button } = setup(buttonProps);
|
|
180
|
+
expect(wrapper).toMatchSnapshot();
|
|
181
|
+
|
|
182
|
+
expect(button).toHaveClassName(getBasicClass({ prefix: BUTTON_CLASSNAME, type: 'fullWidth', value: true }));
|
|
183
|
+
});
|
|
171
184
|
});
|
|
172
185
|
|
|
173
186
|
// 3. Test events.
|
|
@@ -64,7 +64,7 @@ export const BUTTON_CLASSNAME = `${CSS_PREFIX}-button`;
|
|
|
64
64
|
* @return React element.
|
|
65
65
|
*/
|
|
66
66
|
const renderButtonWrapper: React.FC<ButtonRootProps> = (props) => {
|
|
67
|
-
const { color, emphasis, variant } = props;
|
|
67
|
+
const { color, emphasis, variant, fullWidth } = props;
|
|
68
68
|
|
|
69
69
|
const adaptedColor =
|
|
70
70
|
emphasis === Emphasis.low && (color === ColorPalette.light ? ColorPalette.dark : ColorPalette.light);
|
|
@@ -74,6 +74,7 @@ const renderButtonWrapper: React.FC<ButtonRootProps> = (props) => {
|
|
|
74
74
|
color: adaptedColor,
|
|
75
75
|
prefix: BUTTON_WRAPPER_CLASSNAME,
|
|
76
76
|
variant,
|
|
77
|
+
fullWidth,
|
|
77
78
|
}),
|
|
78
79
|
);
|
|
79
80
|
const buttonProps = { ...props, hasBackground: false };
|
|
@@ -105,6 +106,9 @@ export const ButtonRoot: Comp<ButtonRootProps, HTMLButtonElement | HTMLAnchorEle
|
|
|
105
106
|
href,
|
|
106
107
|
isDisabled = disabled,
|
|
107
108
|
isSelected,
|
|
109
|
+
isActive,
|
|
110
|
+
isFocused,
|
|
111
|
+
isHovered,
|
|
108
112
|
linkAs,
|
|
109
113
|
name,
|
|
110
114
|
size,
|
|
@@ -112,6 +116,7 @@ export const ButtonRoot: Comp<ButtonRootProps, HTMLButtonElement | HTMLAnchorEle
|
|
|
112
116
|
theme,
|
|
113
117
|
variant,
|
|
114
118
|
type = 'button',
|
|
119
|
+
fullWidth,
|
|
115
120
|
...forwardedProps
|
|
116
121
|
} = props;
|
|
117
122
|
|
|
@@ -132,10 +137,14 @@ export const ButtonRoot: Comp<ButtonRootProps, HTMLButtonElement | HTMLAnchorEle
|
|
|
132
137
|
emphasis,
|
|
133
138
|
isSelected,
|
|
134
139
|
isDisabled,
|
|
140
|
+
isActive,
|
|
141
|
+
isFocused,
|
|
142
|
+
isHovered,
|
|
135
143
|
prefix: BUTTON_CLASSNAME,
|
|
136
144
|
size,
|
|
137
145
|
theme: emphasis === Emphasis.high && theme,
|
|
138
146
|
variant,
|
|
147
|
+
fullWidth,
|
|
139
148
|
}),
|
|
140
149
|
);
|
|
141
150
|
|
|
@@ -4,6 +4,7 @@ import { mount, shallow } from 'enzyme';
|
|
|
4
4
|
import 'jest-enzyme';
|
|
5
5
|
|
|
6
6
|
import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
|
|
7
|
+
import { mdiClose } from '@lumx/icons';
|
|
7
8
|
|
|
8
9
|
import { IconButton, IconButtonProps } from './IconButton';
|
|
9
10
|
|
|
@@ -24,6 +25,7 @@ const setup = (propsOverride: SetupProps = {}, shallowRendering = true) => {
|
|
|
24
25
|
return {
|
|
25
26
|
buttonRoot: wrapper.find('ButtonRoot'),
|
|
26
27
|
icon: wrapper.find('Icon'),
|
|
28
|
+
img: wrapper.find('img'),
|
|
27
29
|
props,
|
|
28
30
|
wrapper,
|
|
29
31
|
};
|
|
@@ -33,10 +35,27 @@ describe(`<${IconButton.displayName}>`, () => {
|
|
|
33
35
|
// 1. Test render via snapshot (default states of component).
|
|
34
36
|
describe('Snapshots and structure', () => {
|
|
35
37
|
it('should render icon button', () => {
|
|
36
|
-
const { buttonRoot, icon, wrapper } = setup({});
|
|
38
|
+
const { buttonRoot, icon, img, wrapper } = setup({});
|
|
37
39
|
expect(wrapper).toMatchSnapshot();
|
|
38
40
|
expect(buttonRoot).toExist();
|
|
39
41
|
expect(icon).toExist();
|
|
42
|
+
expect(img).not.toExist();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should render icon button with an image', () => {
|
|
46
|
+
const { buttonRoot, icon, img, wrapper } = setup({ image: 'http://foo.com' });
|
|
47
|
+
expect(wrapper).toMatchSnapshot();
|
|
48
|
+
expect(buttonRoot).toExist();
|
|
49
|
+
expect(icon).not.toExist();
|
|
50
|
+
expect(img).toExist();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should render icon button with an image if both props are set', () => {
|
|
54
|
+
const { buttonRoot, icon, img, wrapper } = setup({ image: 'http://foo.com', icon: mdiClose });
|
|
55
|
+
expect(wrapper).toMatchSnapshot();
|
|
56
|
+
expect(buttonRoot).toExist();
|
|
57
|
+
expect(icon).not.toExist();
|
|
58
|
+
expect(img).toExist();
|
|
40
59
|
});
|
|
41
60
|
});
|
|
42
61
|
|
|
@@ -4,12 +4,17 @@ import { Emphasis, Icon, Size, Theme, Tooltip, TooltipProps } from '@lumx/react'
|
|
|
4
4
|
import { BaseButtonProps, ButtonRoot } from '@lumx/react/components/button/ButtonRoot';
|
|
5
5
|
import { Comp, getRootClassName } from '@lumx/react/utils';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Defines the props of the component.
|
|
9
|
-
*/
|
|
10
7
|
export interface IconButtonProps extends BaseButtonProps {
|
|
11
|
-
/**
|
|
12
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Icon (SVG path).
|
|
10
|
+
* If `image` is also set, `image` will be used instead.
|
|
11
|
+
*/
|
|
12
|
+
icon?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Image (image url).
|
|
15
|
+
* Has priority over `icon`.
|
|
16
|
+
*/
|
|
17
|
+
image?: string;
|
|
13
18
|
/**
|
|
14
19
|
* Label text (required for a11y purpose).
|
|
15
20
|
* If you really don't want an aria-label, you can set an empty label (this is not recommended).
|
|
@@ -51,12 +56,20 @@ const DEFAULT_PROPS: Partial<IconButtonProps> = {
|
|
|
51
56
|
* @return React element.
|
|
52
57
|
*/
|
|
53
58
|
export const IconButton: Comp<IconButtonProps, HTMLButtonElement> = forwardRef((props, ref) => {
|
|
54
|
-
const { emphasis, icon, label, size, theme, tooltipProps, hideTooltip, ...forwardedProps } = props;
|
|
59
|
+
const { emphasis, image, icon, label, size, theme, tooltipProps, hideTooltip, ...forwardedProps } = props;
|
|
55
60
|
|
|
56
61
|
return (
|
|
57
62
|
<Tooltip label={hideTooltip ? '' : label} {...tooltipProps}>
|
|
58
63
|
<ButtonRoot ref={ref} {...{ emphasis, size, theme, ...forwardedProps }} aria-label={label} variant="icon">
|
|
59
|
-
|
|
64
|
+
{image ? (
|
|
65
|
+
<img
|
|
66
|
+
// no need to set alt as an aria-label is already set on the button
|
|
67
|
+
alt=""
|
|
68
|
+
src={image}
|
|
69
|
+
/>
|
|
70
|
+
) : (
|
|
71
|
+
<Icon icon={icon as string} />
|
|
72
|
+
)}
|
|
60
73
|
</ButtonRoot>
|
|
61
74
|
</Tooltip>
|
|
62
75
|
);
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`<ButtonRoot> Props should be full width 1`] = `
|
|
4
|
+
<ButtonRoot
|
|
5
|
+
emphasis="high"
|
|
6
|
+
fullWidth={true}
|
|
7
|
+
theme="light"
|
|
8
|
+
>
|
|
9
|
+
<button
|
|
10
|
+
className="lumx-button lumx-button--color-primary lumx-button--emphasis-high lumx-button--theme-light lumx-button--is-full-width"
|
|
11
|
+
type="button"
|
|
12
|
+
/>
|
|
13
|
+
</ButtonRoot>
|
|
14
|
+
`;
|
|
15
|
+
|
|
3
16
|
exports[`<ButtonRoot> Props should not have default color in low or medium emphasis 1`] = `
|
|
4
17
|
<ButtonRoot
|
|
5
18
|
emphasis="low"
|