@cds/react
6.15.1 • Public • PublishedClarity Core is a suite of Web Components from theClarity Design System. Because Reactdoesn't fully interoperate with custom elements we have developed this library of React components that wrap Clarity Web Components
(Optional): Install the Clarity Core package from npm.
npm install @cds/core --save
Install the Clarity React package from npm.
npm install @cds/react --save
Import desired component into your JavaScript or TypeScript
import{CdsModal,CdsModalActions,CdsModalContent,CdsModalHeader}from'@cds/react/modal';
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*/}<CdsModalonCloseChange={this.handleCloseModalClick.bind(this,false)}><CdsModalHeader><h3cds-text="title">My Modal</h3></CdsModalHeader><CdsModalContent><divcds-layout="vertical gap:md p-y:xs"><pcds-text="body">Lorem Ipsum</p></div></CdsModalContent><CdsModalActions><divcds-layout="horizontal gap:sm align:right"><CdsButtononClick={this.handleCloseModalClick.bind(this,false)}action="outline"> Cancel</CdsButton><CdsButtononClick={this.handleCloseModalClick.bind(this,false)}>Ok</CdsButton></div></CdsModalActions></CdsModal>;
In Reactrefs provide a way to access DOM nodes orReact elements created in the render method. Because web components' lifecycle lives outside of react'slifecycle our components provide a way to use refs when the underlying web component has finished rendering:
importReactfrom'react';import{CdsButton}from'@cds/react/button';exportdefaultclassAppextendsReact.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><CdsButtonref={this.buttonRef}>Mybutton</CdsButton></div>);}}
Package Sidebar
Install
npm i @cds/react
Repository
Homepage
Weekly Downloads
290
Version
6.15.1
License
MIT
Unpacked Size
448 kB
Total Files
177