Skip to content

Commit 17547f7

Browse files
authored
Port project to TypeScript (#3)
2 parents 39460e6 + 80028aa commit 17547f7

File tree

11 files changed

+305
-3057
lines changed

11 files changed

+305
-3057
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# http://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
indent_style = space
10+
indent_size = 2

.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
node_modules
2-
.DS_Store
3-
*.log
1+
build/
2+
dist/
3+
node_modules/
4+
5+
*.tgz
6+
package-lock.json

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.babelrc
2+
.editorconfig
3+
.idea/
4+
.prettierrc
5+
.travis.yml
6+
.vscode/
7+
build/
8+
index.tsx
9+
tsconfig.json
10+
*.tgz

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 80,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

README.md

Lines changed: 25 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,31 @@
11
# React A11yDialog
22

3-
react-a11y-dialog is a React component for [a11y-dialog](https://github.com/edenspiekermann/a11y-dialog) relying on [React portals](https://reactjs.org/docs/portals.html) to ease the use of accessible dialog windows in React applications.
3+
react-a11y-dialog is a React component for [a11y-dialog](https://github.com/edenspiekermann/a11y-dialog) relying on [React portals](https://reactjs.org/docs/portals.html) to ease the use of accessible dialog windows in React applications. This component does not render anything on the server, and waits for the client bundle to kick in to render the dialog through the React portal.
44

5-
*Note: for React versions **before** 16, use `[email protected]`.*
5+
This is a fork of [Hugo Giraudel's](https://github.com/HugoGiraudel/react-a11y-dialog) project ported over to TypeScript and includes any minor changes/improvements I needed. Version 1.0.0 of this project is the equivalent of what would be react-a11y-dialog 4.1.1, meaning this project can be a drop in replacement.
6+
7+
## Changes in this Fork
8+
9+
- Includes TypeScript definition file
10+
- Added new `onClose()` callback to the `Dialog` component to allow for notifications of when a dialog was closed.
611

712
## Install
813

914
```
10-
npm install --save react-a11y-dialog
15+
npm install --save @allejo/react-a11y-dialog
1116
```
1217

13-
## API
14-
15-
* **Property name**: `id`
16-
* **Type**: string
17-
* **Mandatory**: true
18-
* **Default value**: —
19-
* **Description**: The HTML `id` attribute of the dialog element, internally used by a11y-dialog to manipulate the dialog.
20-
21-
---
22-
23-
* **Property name**: `title`
24-
* **Type**: string | element
25-
* **Mandatory**: true
26-
* **Default value**: —
27-
* **Description**: The title of the dialog, mandatory in the document to provide context to assistive technology. Could be [hidden with CSS](https://hugogiraudel.com/2016/10/13/css-hide-and-seek/) (while remaining accessible).
28-
29-
---
30-
31-
* **Property name**: `dialogRef`
32-
* **Type**: function
33-
* **Mandatory**: false
34-
* **Default value**: no-op
35-
* **Description**: A function called when the component has mounted, receiving the [instance of A11yDialog](http://edenspiekermann.github.io/a11y-dialog/#js-api) so that it can be programmatically accessed later on.
36-
37-
---
38-
39-
* **Property name**: `appRoot`
40-
* **Type**: string | string[]
41-
* **Mandatory**: true
42-
* **Default value**: —
43-
* **Description**: The [selector(s) a11y-dialog need](http://edenspiekermann.github.io/a11y-dialog/#javascript-instantiation) to disable when the dialog is open.
44-
45-
---
46-
47-
* **Property name**: `dialogRoot`
48-
* **Type**: string
49-
* **Mandatory**: true
50-
* **Default value**: —
51-
* **Description**: The container for the dialog to be rendered into ([React portal](https://reactjs.org/docs/portals.html)’s root).
52-
53-
---
54-
55-
* **Property name**: `titleId`
56-
* **Type**: string
57-
* **Mandatory**: false
58-
* **Default value**: `${this.props.id}-title`
59-
* **Description**: The HTML `id` attribute of the dialog’s title element, used by assistive technologies to provide context and meaning to the dialog window.
60-
61-
---
62-
63-
* **Property name**: `closeButtonLabel`
64-
* **Type**: string
65-
* **Mandatory**: false
66-
* **Default value**: “Close this dialog window”
67-
* **Description**: The HTML `aria-label` attribute of the close button, used by assistive technologies to provide extra meaning to the usual cross-mark.
68-
69-
---
70-
71-
* **Property name**: `closeButtonContent`
72-
* **Type**: string | element
73-
* **Mandatory**: false
74-
* **Default value**: `\u00D7` (×)
75-
* **Description**: The string that is the inner HTML of the close button.
76-
77-
---
78-
79-
* **Property name**: `classNames`
80-
* **Type**: object
81-
* **Mandatory**: false
82-
* **Default value**: {}
83-
* **Description**: Object of classes for each HTML element of the dialog element. Keys are: `base`, `overlay`, `element`, `document`, `title`, `closeButton`. See [a11y-dialog docs](http://edenspiekermann.github.io/a11y-dialog/#expected-dom-structure) for reference.
84-
85-
---
86-
87-
* **Property name**: `useDialog`
88-
* **Type**: boolean
89-
* **Mandatory**: false
90-
* **Default value**: `true`
91-
* **Description**: Whether to render a `<dialog>` element or a `<div>` element.
92-
93-
---
94-
95-
* **Property name**: `role`
96-
* **Type**: string
97-
* **Mandatory**: false
98-
* **Default value**: `dialog`
99-
* **Description**: The `role` attribute of the dialog element, either `dialog` (default) or `alertdialog` to make it a modal (preventing closing on click outside of <kbd>ESC</kbd> key).
100-
101-
## Server-side rendering
102-
103-
react-a11y-dialog does not render anything on the server, and waits for the client bundle to kick in to render the dialog through the React portal.
104-
10518
## Example
10619

10720
```jsx
108-
const Dialog = require('react-a11y-dialog')
21+
import * as React from 'react';
22+
import { Dialog, A11yDialog } from '@allejo/react-a11y-dialog';
10923

11024
class MyComponent extends React.Component {
25+
private dialog?: A11yDialog;
26+
11127
handleClick = () => {
112-
this.dialog.show()
28+
this.dialog && this.dialog.show()
11329
}
11430

11531
render () {
@@ -119,11 +35,14 @@ class MyComponent extends React.Component {
11935
Open the dialog
12036
</button>
12137

122-
<Dialog id="my-accessible-dialog"
123-
appRoot="#main"
124-
dialogRoot="#dialog-root"
125-
dialogRef={(dialog) => (this.dialog = dialog)}
126-
title="The dialog title">
38+
<Dialog
39+
id="my-accessible-dialog"
40+
appRoot="#main"
41+
dialogRoot="#dialog-root"
42+
dialogRef={(dialog) => (this.dialog = dialog)}
43+
title="The dialog title"
44+
onClose={() => console.log('I was closed!')}
45+
>
12746
<p>Some content for the dialog.</p>
12847
</Dialog>
12948
</div>
@@ -150,3 +69,7 @@ ReactDOM.render(
15069
</body>
15170
</html>
15271
```
72+
73+
## API
74+
75+
Take a look at the `Props` interface in the [`index.tsx`](./index.tsx) for all of the available props and their relevant documentation.

dist/index.js

Lines changed: 0 additions & 199 deletions
This file was deleted.

0 commit comments

Comments
 (0)