reactstrap#CustomInput TypeScript Examples

The following examples show how to use reactstrap#CustomInput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: place_selector.tsx    From website with Apache License 2.0 4 votes vote down vote up
export function PlaceSelector(props: PlaceSelectorProps): JSX.Element {
  const [childPlaceTypes, setChildPlaceTypes] = useState([]);
  useEffect(() => {
    if (_.isNull(props.selectedPlace.types)) {
      return;
    }
    loadChildPlaceTypes();
  }, [props.selectedPlace]);

  return (
    <Card className={`${SELECTOR_PREFIX}-card`}>
      <Container className={`${SELECTOR_PREFIX}-container`} fluid={true}>
        <div className={`${SELECTOR_PREFIX}-main-selectors`}>
          <div
            className={`${SELECTOR_PREFIX}-section`}
            id={`${SELECTOR_PREFIX}-search-section`}
          >
            <div className={`${SELECTOR_PREFIX}-label`}>Plot places in</div>
            <SearchBar
              places={
                props.selectedPlace.dcid
                  ? { [props.selectedPlace.dcid]: props.selectedPlace.name }
                  : {}
              }
              addPlace={(e) => selectPlace(e, props.onPlaceSelected)}
              removePlace={() =>
                unselectPlace(props.onPlaceSelected, setChildPlaceTypes)
              }
              numPlacesLimit={1}
              customPlaceHolder={props.customSearchPlaceholder}
            />
          </div>
          <div className={`${SELECTOR_PREFIX}-section`}>
            <div className={`${SELECTOR_PREFIX}-label`}>of type</div>
            <div>
              <CustomInput
                id={`${SELECTOR_PREFIX}-place-type`}
                type="select"
                value={props.enclosedPlaceType}
                onChange={(e) =>
                  selectEnclosedPlaceType(e, props.onEnclosedPlaceTypeSelected)
                }
                className="pac-target-input"
              >
                <option value="">Select a place type</option>
                {childPlaceTypes.map((type) => (
                  <option value={type} key={type}>
                    {ENCLOSED_PLACE_TYPE_NAMES[type] || type}
                  </option>
                ))}
              </CustomInput>
            </div>
          </div>
        </div>
        {props.children}
      </Container>
    </Card>
  );

  function loadChildPlaceTypes(): void {
    getParentPlacesPromise(props.selectedPlace.dcid)
      .then((parentPlaces) => {
        const getEnclosedPlaceTypesFn =
          props.getEnclosedPlaceTypes || getEnclosedPlaceTypes;
        const newChildPlaceTypes = getEnclosedPlaceTypesFn(
          props.selectedPlace,
          parentPlaces
        );
        if (_.isEqual(newChildPlaceTypes, childPlaceTypes)) {
          return;
        }
        if (_.isEmpty(newChildPlaceTypes)) {
          alert(
            `Sorry, we don't support ${props.selectedPlace.name}. Please select a different place.`
          );
        } else if (newChildPlaceTypes.length === 1) {
          props.onEnclosedPlaceTypeSelected(newChildPlaceTypes[0]);
        }
        setChildPlaceTypes(newChildPlaceTypes);
      })
      .catch(() => setChildPlaceTypes([]));
  }
}