Q&A Widget – React SDK

Install the Q&A Widget as an NPM package for first-class React (and TypeScript) support.

Installation

npm install @legionhandtech/lht-react-widgets

React 17+ is a peer dependency. If your project already has React installed you're good to go.

Quick Start

1import { LegionQA } from '@legionhandtech/lht-react-widgets'; 2 3function App() { 4 return ( 5 <LegionQA 6 baseUrl="https://your-legion-domain.com" 7 productId="product-123" 8 username="John" 9 theme="light" 10 /> 11 ); 12}

You can also import from the dedicated sub-path:

import { LegionQA } from '@legionhandtech/lht-react-widgets/qa';

Props Reference

Core Props

PropTypeDefaultDescription
baseUrlstringrequiredBase URL of your Legion deployment
authTokenstringJWT auth token for authenticated features
productIdstringProduct ID to scope questions to a specific product
usernamestring"Anonymous"Display name for the user
pageSizenumber5Number of items per page
theme"light" | "dark""light"Theme preset
showSearchbooleantrueShow the search bar
showAskButtonbooleantrueShow the "Ask a Question" button
widthstring"600px"Widget width (CSS value)
heightstring"800px"Widget height (CSS value)
classNamestringCSS class applied to the outer container
styleReact.CSSPropertiesInline styles merged into the container
onLoad(detail) => voidCalled when the widget iframe finishes loading
onError(message: string) => voidCalled if the widget iframe fails to load

Theming Props

All theming props are optional. When omitted the widget uses its built-in defaults.

PropCSS VariableExample
qaPrimaryColor--qa-primary-color"#228be6"
qaBackgroundColor--qa-background-color"#f8f9fa"
qaTextColor--qa-text-color"#333"
qaSecondaryTextColor--qa-secondary-text-color"#666"
qaBorderColor--qa-border-color"#dee2e6"
qaStaffBadgeColor--qa-staff-badge-color"#e03131"
qaAcceptedColor--qa-accepted-color"#2f9e44"
qaTitleSize--qa-title-size"clamp(16px, 2vmin, 20px)"
qaBodySize--qa-body-size"14px"
qaMetaSize--qa-meta-size"12px"
qaFontFamily--qa-font-family"Inter, sans-serif"
qaCardPadding--qa-card-padding"16px"
qaCardGap--qa-card-gap"12px"
qaBorderRadius--qa-border-radius"8px"
qaCardShadow--qa-card-shadow"0 2px 8px rgba(0,0,0,.1)"
qaButtonRadius--qa-button-radius"4px"
qaVoteButtonSize--qa-vote-button-size"28px"

Imperative Ref API

Use a React ref to call methods on the widget:

1import { useRef } from 'react'; 2import { LegionQA, LegionQAHandle } from '@legionhandtech/lht-react-widgets'; 3 4function App() { 5 const widgetRef = useRef<LegionQAHandle>(null); 6 7 return ( 8 <> 9 <button onClick={() => widgetRef.current?.refresh()}> 10 Refresh Q&A 11 </button> 12 <LegionQA 13 ref={widgetRef} 14 baseUrl="https://your-legion-domain.com" 15 productId="product-123" 16 /> 17 </> 18 ); 19}

Available Methods

MethodDescription
refresh()Reloads the widget iframe

Web Component (from NPM)

If you prefer the <legion-qa> custom element but want to install via NPM instead of a script tag:

import '@legionhandtech/lht-react-widgets/qa-web-component';

Then use it in your HTML or JSX:

1<legion-qa 2 api-url="https://your-legion-domain.com" 3 product-id="product-123" 4 username="John" 5 theme="light"> 6</legion-qa>

TypeScript

The package ships with full TypeScript declarations. All prop interfaces are exported:

1import type { 2 QAWidgetProps, 3 QAThemingProps, 4 LegionQAHandle, 5} from '@legionhandtech/lht-react-widgets';

Callbacks

onLoad

Fired when the widget iframe has loaded. Receives a detail object:

1<LegionQA 2 baseUrl="https://your-legion-domain.com" 3 onLoad={(detail) => { 4 console.log(detail.widget); // "qa" 5 console.log(detail.theme); // "light" | "dark" 6 }} 7/>

onError

Fired if the widget iframe fails to load:

1<LegionQA 2 baseUrl="https://your-legion-domain.com" 3 onError={(message) => console.error(message)} 4/>
Documentation | Legion Hand Technologies