adds typings for react-aria-live (#37996)

* adds typings for react-aria-live

* added typescript version

* formatting

* fixed lint error

* updated return type of LiveMessenger children

* formatting
This commit is contained in:
AJ Livingston
2019-09-04 18:53:44 -04:00
committed by Ron Buckton
parent 21e7a33c41
commit bd8c74539c
4 changed files with 90 additions and 0 deletions

25
types/react-aria-live/index.d.ts vendored Normal file
View File

@@ -0,0 +1,25 @@
// Type definitions for react-aria-live 2.0
// Project: https://github.com/AlmeroSteyn/react-aria-live#readme
// Definitions by: AJ Livingston <https://github.com/ajliv>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
export class LiveAnnouncer extends React.Component {
announcePolite(message: string, id?: string): void;
announceAssertive(message: string, id?: string): void;
}
export const LiveMessage: React.StatelessComponent<{
'aria-live': 'assertive' | 'polite';
clearOnUnmount?: boolean | 'true' | 'false';
message: string;
}>;
export const LiveMessenger: React.StatelessComponent<{
children(contextProps: {
announceAssertive(message: string, id?: string): void;
announcePolite(message: string, id?: string): void;
}): React.ReactNode;
}>;

View File

@@ -0,0 +1,39 @@
import * as React from 'react';
import { render } from 'react-dom';
import { LiveAnnouncer, LiveMessage, LiveMessenger } from 'react-aria-live';
render(
<LiveAnnouncer>
<LiveMessage
aria-live='polite'
message='hello'
clearOnUnmount
/>
</LiveAnnouncer>,
document.getElementById('main')
);
render(
<LiveAnnouncer>
<LiveMessenger>
{({ announcePolite, announceAssertive }) =>
<>
<button
onClick={() => {
announcePolite('Polite message');
}}>
Press me for a polite message
</button>
<button
onClick={() => {
announceAssertive('Assertive message', 'UniqueId');
}}>
Press me for an assertive message
</button>
</>
}
</LiveMessenger>
</LiveAnnouncer>,
document.getElementById('main')
);

View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"react-aria-live-tests.tsx"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }