Как связать Algolia и @ material-ui - PullRequest
0 голосов
/ 22 мая 2019

Это документация о том, как создать базовый SearchBox элемент только из поля ввода в Алголии.Проблема в том, что в конечном итоге Алголия выглядит довольно некрасиво

Вот тут-то и поступает материал-пользовательский интерфейс. Я использовал AppBar, перед которым содержится поисковый элемент, поэтому я подумал о том, чтобы создать экземпляр SearchBox внутри моего AppBar.js компонента, но с проприетарной * material-ui InputBase (вместо скучного html input).

Ниже я вставлю код, который у меня есть, но он отказывается компилироватьс InputBase (а точнее его ассоциированным реквизитом), используемым для создания пользовательского элемента SearchBox.

Если у кого-либо есть опыт работы с различными API-интерфейсами, подобными этому, или вы думаете, что знаете, что происходитНе стесняйтесь, дайте мне знать!

import React from 'react';
import PropTypes from 'prop-types';
import AppBar from '@material-ui/core/Appbar';
import Toolbar from '@material-ui/core/Toolbar';
import Typography from '@material-ui/core/Typography';
import InputBase from '@material-ui/core/InputBase';
import {fade} from '@material-ui/core/styles/colorManipulator';
import {withStyles} from "@material-ui/core/styles";
import SearchIcon from '@material-ui/icons/Search';
import { connectSearchBox } from 'react-instantsearch-dom';

const styles = theme => ({
    root:{
        width: '100%',
    },
    grow:{
        flexGrow: 1,
    },
    menuButton:{
        marginLeft: -12,
        marginRight: 20,
    },
    title:{
        display: 'none',
        [theme.breakpoints.up('sm')]:{
            display: 'block',
        },
    },
    search:{
        position: 'relative',
        borderRadius: theme.shape.borderRadius,
        backgroundColor: fade(theme.palette.common.white, 0.15),
        '&:hover':{
            backgroundColor: fade(theme.palette.common.white, 0.25),
        },
        marginLeft: 0,
        width: '100%',
        [theme.breakpoints.up('sm')]:{
            marginLeft: theme.spacing.unit,
            width: 'auto',
        },
    },
    searchIcon:{
        width: theme.spacing.unit * 9,
        height: '100%',
        position: 'absolute',
        pointerEvents: 'none',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
    },
    inputRoot:{
        color: 'inherit',
        width: '100%',
    },
    inputInput:{
        paddingTop: theme.spacing.unit,
        paddingRight: theme.spacing.unit,
        paddingBottom: theme.spacing.unit,
        paddingLeft: theme.spacing.unit * 10,
        transition: theme.transitions.create('width'),
        width: '100%',
        [theme.breakpoints.up('sm')]:{
            width: 120,
            '&:focus':{
                width: 200,
            },
        },
    },
});

function SearchBox({currentRefinement, refine}, props){
    const {classes} = props;
    return(
        <InputBase
            type='search'
            value={currentRefinement}
            onChange={event => refine(event.currentTarget.value)}
            placeholder="Search for Destination by Name, State, and keywords..."
            classes={{
                root: classes.inputRoot,
                input: classes.inputInput,
            }}
        />
    );
}


const CustomSearchBox = connectSearchBox(SearchBox);

function SearchAppBar(props){
    const {classes} = props;
    return(
        <div className={classes.root}>
            <AppBar position="static">
                <Toolbar>
                    <Typography className={classes.title} variant="h6" color='inherit' noWrap>
                    title
                    </Typography>
                    <div className={classes.grow}/>
                    <div className={classes.search}>
                        <div className={classes.searchIcon}>
                            <SearchIcon/>
                        </div>
                        <CustomSearchBox/>
                    </div>
                </Toolbar>
            </AppBar>
        </div>
    );
}

SearchAppBar.propTypes = {
    classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(SearchAppBar);

(как вы, вероятно, можете сказать, я очень увлекся документацией - я ничего особенного не пробовал)

enter image description here

...