Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(readme): remove redundant sections, fix broken link #11530

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/calcite-components-react/README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Lumina, you are now also providing JSX typings for React 19 users.
Given that more and more people will be shifting to React 19, it would be ideal to point out on this page or somewhere else that wrappers are not required in React 19 (but still supported).

documentation on usage in React in https://qawebgis.esri.com/components/lumina/publishing#using-the-npm-package (generally same as other frameworks, except for need to add a specific /// directive to get the JSX typings)

Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Calcite Components React

A set of React components that wrap [Calcite Components](https://developers.arcgis.com/calcite-design-system/components/). An application using this package is provided in the [`calcite-components-examples`](https://github.com/Esri/calcite-components-examples) repo.
This package provides React wrappers for [Calcite components](https://developers.arcgis.com/calcite-design-system/components/). See the [react example](https://github.com/Esri/calcite-design-system/tree/dev/examples/components/react) for a minimal application using this package.
benelan marked this conversation as resolved.
Show resolved Hide resolved

## Installation

```sh
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.
This package includes the compatible version of the standard `@esri/calcite-components` package, so you do not need to install it separately.

## Choose a build

There are two builds that are provided by the standard `calcite-components` package.
There are two builds provided by the standard components package.

### Custom Elements build

[Custom Elements](developers.arcgis.com/calcite-design-system/get-started#custom-elements) is the recommended build when using frontend frameworks, such as React. To use this build, you will need to set the path to the `calcite-components` assets. You can either use local assets, which will be explained in a subsequent step, or assets hosted on a CDN.
[Custom Elements](developers.arcgis.com/calcite-design-system/get-started#custom-elements) is the recommended build when using frontend frameworks, such as React. To use this build, you will need to set the path to the components assets. You can either use local assets, which will be explained in a subsequent step, or assets hosted on a CDN.

```jsx
import { setAssetPath } from "@esri/calcite-components/dist/components";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the commented out setAssetPath need to removed, or edited to reflect more of a local/different cdn, maybe similar to our doc site example:

setAssetPath("/path-to-your-assets/");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine as it is because it's where React apps commonly serve their assets, e.g. our React example:

setAssetPath(window.location.href);

It's generalized in the doc because it's not the same for all frameworks or build tools, e.g. our rollup example:

setAssetPath(document.currentScript.src);

Copy link
Member Author

@benelan benelan Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could remove the commented snippet for CDN assets though because I think Lumina uses the CDN by default when setAssetPath isn't called.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxpatiiuk is that correct? And is there a new default behavior for defineCustomElements?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could remove the commented snippet for CDN assets though because I think Lumina uses the CDN by default when setAssetPath isn't called.

Correct. in map-components 4.32 we only document setAssetPath for people who don't want to use our CDN/need offline deployment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, defineCustomElements has the same behaviour
Also, if resourceUrl is provided to defineCustomElements, it simply calls setAssetPath for you - equivalent to calling setAssetPath directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path can be simplified:

Suggested change
import { setAssetPath } from "@esri/calcite-components/dist/components";
import { setAssetPath } from "@esri/calcite-components";

Expand All @@ -27,7 +27,7 @@ setAssetPath(window.location.href);
// setAssetPath("https://unpkg.com/@esri/calcite-components/dist/calcite/assets");
```

Next, you need to import each component you use from the standard `calcite-component` package's custom elements build. This will automatically define the custom elements on the window. Then import the same components from `calcite-components-react`.
Next, you need to import each component you use from the standard components package's custom elements build. This will automatically define the custom elements on the window. Then, import the same components from `@esri/calcite-components-react`.

```jsx
import "@esri/calcite-components/dist/components/calcite-button";
Expand All @@ -51,7 +51,7 @@ defineCustomElements(window);
// });
```

Since you manually defined the custom elements on the window, you only need to import the individual components from `calcite-components-react`.
Since you manually defined the custom elements on the window, you only need to import the individual components from `@esri/calcite-components-react`.

```jsx
import { CalciteButton, CalciteIcon, CalciteSlider } from "@esri/calcite-components-react";
Expand All @@ -75,7 +75,7 @@ cp -r node_modules/@esri/calcite-components/dist/calcite/assets/* ./public/asset

## 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:
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:

```jsx
const sliderEl = useRef(null);
Expand All @@ -85,7 +85,7 @@ function onUpdate(event) {
setSliderValue(event.target.value);
}

// need to access the dom node to set custom event listeners for props that aren't strings / numbers
// need to access the DOM node to set custom event listeners for props that aren't strings or numbers
// lit.dev/docs/frameworks/react#why-are-wrappers-needed
useEffect(
(_) => {
Expand All @@ -95,7 +95,7 @@ useEffect(
);
```

Using `calcite-components-react`, these events are connected for you:
Using `@esri/calcite-components-react`, these events are connected for you:

```jsx
const [sliderValue, setSliderValue] = useState(50);
Expand All @@ -106,7 +106,7 @@ If you're using TypeScript, you'll also get increased type safety for your event

## Contributing

We welcome contributions to this project. See the main [calcite-components CONTRIBUTING.md](../../../../CONTRIBUTING.md) for an overview of contribution guidelines.
We welcome contributions to this project. See the [CONTRIBUTING.md](https://github.com/Esri/calcite-design-system/blob/dev/CONTRIBUTING.md) for an overview of contribution guidelines.

## License

Expand Down
42 changes: 7 additions & 35 deletions packages/calcite-components/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
[![downloads per month](https://img.shields.io/npm/dm/@esri/calcite-components?style=flat-square&color=35AC46)](https://www.npmjs.com/package/@esri/calcite-components)
[![commits per month](https://img.shields.io/github/commit-activity/m/esri/calcite-components?style=flat-square&color=EDD317)](https://github.com/Esri/calcite-design-system/graphs/contributors)

# Calcite Components
# 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](https://developers.arcgis.com/calcite-design-system/components/) for component descriptions, examples, and API reference, which includes properties, slots, styles, and theming.
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](https://developers.arcgis.com/calcite-design-system/components/) for component descriptions, examples, and API reference, which includes properties, slots, styles, and theming.

## 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:
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:

<!-- x-release-please-start-version -->

Expand All @@ -32,41 +32,13 @@ Once these tags are added, components can be used like any other HTML element. O

## Use the NPM package

Calcite Components is also provided as an [NPM package](https://www.npmjs.com/package/@esri/calcite-components). To get started, first install the package, then follow the steps below. Alternatively, you can find examples using different frameworks and build tools [here](https://github.com/Esri/calcite-components-examples).

```sh
npm install @esri/calcite-components
```

### 1. Build

Refer to the [Get started](https://developers.arcgis.com/calcite-design-system/get-started/) page for details on setting up a build.

### 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](https://github.com/Esri/calcite-components-examples) 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.

```sh
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:

```js
import "@esri/calcite-components/dist/calcite/calcite.css";
```
Refer to the [Get started](https://developers.arcgis.com/calcite-design-system/get-started/#use-the-npm-package) page for details on setting up the [NPM package](https://www.npmjs.com/package/@esri/calcite-components).

## TypeScript

Refer to the [TypeScript section of the Framework integration](https://developers.arcgis.com/calcite-design-system/resources/frameworks/#typescript) resource page for guidance on setting up TypeScript.
Refer to the [Framework integration](https://developers.arcgis.com/calcite-design-system/resources/frameworks/#typescript) resource page for guidance on setting up TypeScript.

## Browser Support
## Browser support

<table>
<thead>
Expand All @@ -86,7 +58,7 @@ Refer to the [TypeScript section of the Framework integration](https://developer

## Contributing

We welcome contributions to this project. See [CONTRIBUTING.md](./CONTRIBUTING.md) for an overview of contribution guidelines.
We welcome contributions to this project. See [CONTRIBUTING.md](https://github.com/Esri/calcite-design-system/blob/dev/CONTRIBUTING.md) for an overview of contribution guidelines.

## License

Expand Down