EN · DE · RU · FR · ES

#2675: AdvancedPopperInput.jsx

projectforge-webapp/src/components/design/popper/AdvancedPopperInput.jsx Type: JavaScript/React · Role: Component · Source: projectforge-webapp/src/components/design/popper/AdvancedPopperInput.jsx 60 lines · 53 code · 2 comments · 5 blank
React popper/dropdown component using Popper.js for positioned overlay menus, autocomplete suggestions, and tooltips.

Code Structure

Imports from: ../index, ./Popper.module.scss, classnames, prop-types, react

Has PropTypes for: AdvancedPopperInput

Uses CSS Modules for styling.

Source Code (abridged)

import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { Input } from '../index';
import styles from './Popper.module.scss';

function AdvancedPopperInput(
    {
        children,
        dark = false,
        // Extract 'dispatch' so it's not passed to the input tag
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
        dispatch,
        forwardRef,
        icon,
        onCancel,
        onKeyDown,
        ...props
    },
) {
    const handleKeyDown = (event) => {
        if (onCancel && event.key === 'Escape') {
            onCancel();
        }

        if (onKeyDown) {
            onKeyDown(event);
        }
    };

    return (
        <div className={classNames(styles.input, { [styles.dark]: dark })}>
            <Input
                ref={forwardRef}
                icon={icon}
                className={styles.container}
                autoComplete="off"
                {...props}
                onKeyDown={handleKeyDown}
            />
            {children}
        </div>
    );
}

AdvancedPopperInput.propTypes = {
    id: PropTypes.string.isRequired,
    onChange: PropTypes.func.isRequired,
    children: PropTypes.node,
    dark: PropTypes.bool,
    dispatch: PropTypes.func,
    forwardRef: PropTypes.shape({}),
    icon: PropTypes.shape({}),
    onCancel: PropTypes.func,
    onKeyDown: PropTypes.func,
    placeholder: PropTypes.string,
    value: PropTypes.string,
};

export default AdvancedPopperInput;

Git History

3685edd6c lift to react 18 wip
033629f77 fix typescript eslint bugs
d217c9aff reworked autocompletion design to new materialize inputs
8667f1f6c new input materialize design
031c85102 extend advanced popper input