Nuptial Predicament Mediation

    @esri/calcite-components-react
    TypeScript icon, indicating that this package has built-in type declarations

    0.8.0 • Public • Published

    Calcite Components React

    A set of React components that wrap Calcite Components.

    Installation

    npm install --save @esri/calcite-components-react
    

    This package includes the compatible version of the main component library as a dependency, so no need to install @esri/calcite-components separately.

    Use

    Much like using the standard calcite-components package, you'll need to define the elements on the window first:

    import {
      applyPolyfills,
      defineCustomElements,
    } from "@esri/calcite-components/dist/loader";
    
    // if you're supporting older browsers, apply polyfills
    applyPolyfills().then(() => {
      // define the custom tags on the window
      defineCustomElements(window);
      // after these are defined, render your app as you would normally
      ReactDOM.render(<App />, document.getElementById("root"));
    });

    To ensure the theme works, import the global stylesheet into your app (only do this once):

    import "@esri/calcite-components/dist/calcite/calcite.css";

    Then import any components you'd like to use:

    import {
      CalciteAvatar,
      CalciteButton,
      CalciteIcon,
      CalciteSlider,
    } from "@esri/calcite-components-react";

    Static Assets

    Some components (icon, date-picker) rely on assets being available at a particular path. You'll need to copy these over to your public folder for them to work properly. Something like:

    cp -r node_modules/@esri/calcite-components/dist/calcite/assets/* ./public/assets/

    Why not just use the web components directly?

    Because React uses a synthetic event system, the custom events emitted from calcite components won't work with JSX in React. For example, say you want to update some value when the calcite-slider component changes. When using the standard web components, you need to save a ref to the element, and add a listener:

    const sliderEl = useRef(null);
    const [sliderValue, setSliderValue] = useState(50);
    
    function onUpdate(event) {
      setSliderValue(event.target.value);
    }
    
    // need to access the dom node to set custom event listeners or props that aren't strings / numbers
    // https://stenciljs.com/docs/react#properties-and-events
    useEffect(
      (_) => {
        sliderEl.current.addEventListener("calciteSliderUpdate", onUpdate);
      },
      [sliderEl]
    );

    Using calcite-components-react, these events are connected for you:

    const [sliderValue, setSliderValue] = useState(50);
    <CalciteSlider onCalciteSliderUpdate={(e) => setSliderValue(e.target.value)} />;

    If you're using TypeScript, you'll also get increased type safety for your event listeners, props, etc.

    Contributing

    We welcome contributions to this project. See the main calcite-components CONTRIBUTING.md for an overview of contribution guidelines.

    License

    COPYRIGHT © 2021 Esri

    All rights reserved under the copyright laws of the United States and applicable international laws, treaties, and conventions.

    This material is licensed for use under the Esri Master License Agreement (MLA), and is bound by the terms of that agreement. You may redistribute and use this code without modification, provided you adhere to the terms of the MLA and include this copyright notice.

    See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english

    For additional information, contact: Environmental Systems Research Institute, Inc. Attn: Contracts and Legal Services Department 380 New York Street Redlands, California, USA 92373 USA

    email: contracts@esri.com

    Keywords

    none

    Install

    npm i @esri/calcite-components-react

    DownloadsWeekly Downloads

    48

    Version

    0.8.0

    License

    SEE LICENSE IN LICENSE.md

    Unpacked Size

    501 kB

    Total Files

    33

    Last publish

    Collaborators

    • noahmulfinger
    • ssylvia
    • paulcpederson
    • jgravois
    • patrickarlt
    • nixta
    • odoe
    • jwasilgeo
    • tomwayson
    • benstoltz
    • dbouwman
    • thollingshead
    • hhkaos
    • dpaddock
    • esri_dev
    • driskull
    • jamin415
    • katelynseitz
    • jpurusho
    • rlibed
    • mtschudi
    • ajturner
    • gavinr
    • pranavkulkarni
    • kellyhutchins
    • mjuniper
    • rsteilberg
    • john4818
    • pr3tori4n
    • gbrown-gis
    • haoliang
    • macandcheese
    • jcfranco
    • alan0002
    • drewctate
    • richgwozdz
    • rweber.esri
    • geemike
    • vivzhang
    • juliannemarik
    • julio8a
    • drspacemanphd
    • cpgruber
    • cpalazzoloesri