6.10.0 • Published 1 month ago

@cds/react v6.10.0

Weekly downloads
768
License
MIT
Repository
github
Last release
1 month ago

Clarity React Wrappers for Core Web Components npm version

Clarity Core is a suite of Web Components from the Clarity Design System. Because React doesn't fully interoperate with custom elements we have developed this library of React components that wrap Clarity Web Components

Installation

  1. (Optional): Install the Clarity Core package from npm.

    npm install @cds/core --save
  2. Install the Clarity React package from npm.

    npm install @cds/react --save
  3. Import desired component into your JavaScript or TypeScript

    import { CdsModal, CdsModalActions, CdsModalContent, CdsModalHeader } from '@cds/react/modal';
  4. Use React wrapped Web Component in React

    {
      /*
      Example of a modal web component in React with React Shim
      - size - attribute style hook
      - open - setting the 'open' property on the element
      - openChange - listen for the `openChange` custom event
    */
    }
    <CdsModal onCloseChange={this.handleCloseModalClick.bind(this, false)}>
      <CdsModalHeader>
        <h3 cds-text="title">My Modal</h3>
      </CdsModalHeader>
      <CdsModalContent>
        <div cds-layout="vertical gap:md p-y:xs">
          <p cds-text="body">Lorem Ipsum</p>
        </div>
      </CdsModalContent>
      <CdsModalActions>
        <div cds-layout="horizontal gap:sm align:right">
          <CdsButton onClick={this.handleCloseModalClick.bind(this, false)} action="outline">
            Cancel
          </CdsButton>
          <CdsButton onClick={this.handleCloseModalClick.bind(this, false)}>Ok</CdsButton>
        </div>
      </CdsModalActions>
    </CdsModal>;

Using refs

In React refs provide a way to access DOM nodes or React elements created in the render method. Because web components' lifecycle lives outside of react's lifecycle our components provide a way to use refs when the underlying web component has finished rendering:

import React from 'react';
import { CdsButton } from '@cds/react/button';

export default class App extends React.Component<{}, {}> {
  buttonRef: React.RefObject<CdsButton>;

  constructor(props: any) {
    super(props);
    this.buttonRef = React.createRef<CdsButton>();
  }

  componentDidMount() {
    this.buttonRef.current.nativeElement.then(element => {
      element.focus();
    });
  }

  render() {
    return (
      <div>
        <CdsButton ref={this.buttonRef}>My button</CdsButton>
      </div>
    );
  }
}
6.10.0

1 month ago

6.9.2

3 months ago

6.9.1

5 months ago

6.5.0

9 months ago

6.6.1

8 months ago

6.6.0

9 months ago

6.4.5

10 months ago

6.8.0

6 months ago

6.6.2

8 months ago

6.4.6

10 months ago

6.7.0

8 months ago

6.9.0

6 months ago

6.4.3

11 months ago

6.4.4

11 months ago

6.4.2

1 year ago

6.4.1

1 year ago

6.3.2

1 year ago

6.4.0

1 year ago

6.3.1

1 year ago

6.3.0

1 year ago

6.2.5

1 year ago

6.2.4

1 year ago

6.2.1

2 years ago

6.2.0

2 years ago

6.2.3

1 year ago

6.2.2

2 years ago

5.8.4

2 years ago

6.1.6

2 years ago

6.1.5

2 years ago

6.1.2

2 years ago

6.1.4

2 years ago

6.1.3

2 years ago

5.8.3

2 years ago

5.8.2

2 years ago

6.1.0

2 years ago

6.1.1

2 years ago

5.8.1

2 years ago

5.8.0

2 years ago

6.0.1

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

6.0.4

2 years ago

5.7.3

2 years ago

6.0.0-beta.3

2 years ago

6.0.0-beta.4

2 years ago

6.0.0

2 years ago

5.7.2

2 years ago

6.0.0-beta.1

2 years ago

6.0.0-beta.2

2 years ago

5.7.1

2 years ago

5.7.0

2 years ago

6.0.0-next.0

2 years ago

6.0.0-next.1

2 years ago

6.0.0-next.2

2 years ago

6.0.0-next.3

2 years ago

6.0.0-next.4

2 years ago

6.0.0-next.6

2 years ago

5.6.4

2 years ago

5.6.3

2 years ago

5.6.2

2 years ago

5.6.1

2 years ago

5.6.0

3 years ago

5.5.8

3 years ago

5.5.7

3 years ago

5.5.6

3 years ago

5.5.5

3 years ago

5.5.4

3 years ago

5.5.3

3 years ago

5.5.2

3 years ago

5.5.1

3 years ago

5.5.0

3 years ago

5.4.3

3 years ago

5.4.2

3 years ago

5.4.1

3 years ago

5.4.0

3 years ago

5.3.1

3 years ago

5.3.0

3 years ago

5.2.1

3 years ago

5.2.0

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

5.0.0-rc.1

3 years ago

5.0.0-rc.0

3 years ago

5.0.0-next.0

3 years ago