@comms-id/acnc-charity-lookup-react

中文文档
0.2.3发布于 2026/10/22SEE LICENSE IN LICENSETypeScriptES Module

React hook and component for the Comms.ID Charity field: charity ABN, accessible, no layout shift, with the data attribution

此软件包已被标记为弃用

Removed. Comms.ID products are served live, nothing to install: https://cdn.comms.id/acnc-charity-lookup/latest.js

原始使用文档
文档目录4 节
  1. What the field does
  2. Your own markup: useAcncCharityLookup
  3. The component
  4. Data attribution

@comms-id/acnc-charity-lookup-react

A React hook and a finished component for the Comms.ID Charity field: the user types the 11-digit ABN of a charity. Accessible, no layout shift, with the data attribution always shown. React 18 or later; it depends on @comms-id/acnc-charity-lookup and nothing else.

import { createAcncCharityLookupBrowserClient } from "@comms-id/acnc-charity-lookup/browser";
import { AcncCharityLookupLookup } from "@comms-id/acnc-charity-lookup-react";

const client = createAcncCharityLookupBrowserClient({ relayUrl: "/api/comms-id/charity" });

export const Form = () => (
  <AcncCharityLookupLookup
    client={client}
    onSelect={(record, timing) => console.log(record, `${timing.ms} ms`)}
  />
);

relayUrl is your own server route, set up with @comms-id/relay: your server signs the call as your registered app, so the browser holds no credential.

What the field does

  • An ABN: eleven digits (spaces and hyphens allowed) are looked up at once in the ACNC register. Letters, or more than eleven digits, are refused in the browser and nothing is sent. Charities are not searched by name.
  • The result is one summary line (legal name, ABN, state and postcode) on a fixed note line, so the page never moves.
  • "No charity found." (the ABN is not an ACNC-registered charity) and "Charity lookup is unavailable" are different messages; an outage offers "Try again".

Your own markup: useAcncCharityLookup

const field = useAcncCharityLookup({ client, onSelect });
return (
  <>
    <input {...field.getInputProps()} />
    <ul {...field.getListboxProps("Matches")} hidden={!field.state.open}>
      {field.state.suggestions.map((s, i) => (
        <li key={s.key} {...field.getOptionProps(i)}>{s.primary}</li>
      ))}
    </ul>
    <p {...field.getStatusProps()}>{field.state.announcement}</p>
  </>
);

The prop getters carry the WAI-ARIA combobox contract: roles, aria-expanded, aria-controls, aria-activedescendant, key handling (arrows, Enter, Escape, Tab) and a polite live region. Render the attribution yourself when you use the hook: it is field.state.attribution.

The component

Props: client (required), label (default "Charity ABN"), onSelect, minChars (3), debounceMs (400), limit (8), settings, idPrefix, name, placeholder, disabled, required, className, listLabel, showTiming (true), renderOption.

Style it with the custom properties --comms-id-text, --comms-id-surface, --comms-id-border, --comms-id-active, --comms-id-radius or the comms-id-acnc-charity-lookup__* class names. It needs no stylesheet.

  • The list floats under the input; opening it moves nothing. The note line has a reserved height.
  • A failed lookup says why and offers "Try again"; it is never shown as "no match".
  • It renders on the server with the same structure, and works under StrictMode.

Data attribution

Charity data comes from the Australian Charities and Not-for-profits Commission (ACNC), via data.gov.au (CC BY 3.0 AU). The component always shows the attribution. Do not hide it.

LICENSE is the consumer client licence. src/ is generated by @comms-id/forge-transformers and is never edited by hand.

版本与发布记录

@comms-id/acnc-charity-lookup-react 共发布 2 个版本,首次发布于 2026/10/22;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.2.3latest2026/10/2212 天前
0.0.0-stage2026/10/2212 天前

关于 @comms-id/acnc-charity-lookup-react 的常见问题

@comms-id/acnc-charity-lookup-react 是什么?

用于通信的React钩子和组件。ID慈善字段:慈善ABN,可访问,无布局移位,与数据归属注意:该包已被作者标记为弃用——Removed. Comms.ID products are served live, nothing to install: https://cdn.comms.id/acnc-charity-lookup/latest.js

如何安装 @comms-id/acnc-charity-lookup-react?

在项目目录运行 npm install @comms-id/acnc-charity-lookup-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@comms-id/acnc-charity-lookup-react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@comms-id/acnc-charity-lookup-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@comms-id/acnc-charity-lookup-react 可以商用吗?

@comms-id/acnc-charity-lookup-react 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@comms-id/acnc-charity-lookup-react 还在维护吗?

最新版本 0.2.3 发布于 2026/10/22(12 天前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/10/22。作者已将其标记为弃用,新项目建议寻找替代方案。