Giter Club home page Giter Club logo

calcite-components's Introduction

Built With Stencil npm

Calcite Components

Calcite Components, part of Esri's Calcite Design System, is a rich library of flexible, framework-agnostic web components for building applications. View the documentation for component descriptions, examples, and API reference, which includes properties, slots, styles, and themes.

Use the CDN

The most common approach for loading Calcite Components is to use the version hosted on the CDN. The components can be loaded via <script> and <link> tags in the head of your HTML document:

<script
  type="module"
  src="https://unpkg.com/@esri/[email protected]/dist/calcite/calcite.esm.js"
></script>
<link
  rel="stylesheet"
  type="text/css"
  href="https://unpkg.com/@esri/[email protected]/dist/calcite/calcite.css"
/>

Once these tags are added, components can be used like any other HTML element. Only components that are used in the application will be loaded.

Use the NPM package

Calcite Components is also provided as an NPM package. To get started, first install the package, then follow the steps below. Alternatively, you can find examples using different frameworks and build tools here.

npm install @esri/calcite-components

1. Build

Choose one of the two builds provided by Calcite Components.

Custom Elements

Custom Elements is the recommended build when leveraging a frontend framework. To use this build, you will need to set the path to Calcite Components' assets. You can either use local assets, which will be explained in a subsequent step, or assets hosted on the CDN.

import { setAssetPath } from "@esri/calcite-components/dist/components";
// CDN hosted assets
setAssetPath("https://unpkg.com/@esri/calcite-components/dist/calcite/assets");

// Local assets
// setAssetPath(PATH); // PATH depends on framework, more info below

Next, you need to import each component you use from the custom elements build. This will automatically define the custom elements on the window.

import "@esri/calcite-components/dist/components/calcite-button";
import "@esri/calcite-components/dist/components/calcite-icon";
import "@esri/calcite-components/dist/components/calcite-slider";

Distribution

When using the Distribution build, you'll need to define the custom elements on the window. You can also choose between local and CDN hosted assets.

import { defineCustomElements } from "@esri/calcite-components/dist/loader";
// CDN hosted assets
defineCustomElements(window, {
  resourcesUrl: "https://unpkg.com/@esri/calcite-components/dist/calcite/assets"
});

// Local assets
// defineCustomElements(window);

Since you defined the custom elements on the window, you do not need to import individual components.

2. Assets

Some components, such as calcite-icon and calcite-date-picker, rely on assets being available at a particular path. As mentioned, with the NPM package you have the option to provide a local path or the URL to the assets hosted on the CDN. Using the CDN hosted assets can help decrease on disk build size.

To use the assets locally, they need to be copied using a build tool or NPM script. The directory for the local assets must be named assets, which eases the copying process. For example, /public/calcite/assets will work, however /public/calcite-assets will not.

The Calcite Components examples repo demonstrates using local assets in a variety of JavaScript frameworks and build tools. Each example has a README with a framework or build tool specific explanation.

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

3. Styles

Finally, load the Cascading Style Sheet (CSS). This is also dependent on your framework or build tool, however in many cases it can be imported in JavaScript:

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

TypeScript

Stencil provides a full set of typings for all the components in this repo. To make TypeScript aware of these components, just import the library:

import "@esri/calcite-components";

This will provide autocomplete of component names/properties, as well as additional HTML element types:

// created elements will implicitly have the correct type already
const loader = document.createElement("calcite-loader");
document.body.appendChild(loader);
loader.active = true;

// you can also explicitly type an element using the generated types
// the type name will always be formatted like HTML{CamelCaseComponentName}Element
const loader = document.querySelector(".my-loader-element") as HTMLCalciteLoaderElement;
loader.active = true;

Browser Support

Google Chrome

Chrome

Mozilla Firefox

Firefox

Safari

Safari

Microsoft Edge

Edge

Last 2 versions โœ”

Contributing

We welcome contributions to this project. See CONTRIBUTING.md for an overview of contribution guidelines.

License

COPYRIGHT ยฉ 2020 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: [email protected]

calcite-components's People

Contributors

actions-user avatar anveshmekala avatar asangma avatar benelan avatar bpatterson88 avatar caripizza avatar crowjonah avatar dependabot[bot] avatar driskull avatar elijbet avatar eriklharper avatar ffaubry avatar geospatialem avatar github-actions[bot] avatar jcfranco avatar jgibson02 avatar jrowlingson avatar justinhough avatar kat10140 avatar kstinson14 avatar kumargayu avatar macandcheese avatar manaharidahal avatar miketschudi avatar mpriour avatar patrickarlt avatar paulcpederson avatar pr3tori4n avatar vcolavin avatar y0n4 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.