@nypl/design-system-react-components 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +1452 -3
  2. package/README.md +389 -3
  3. package/dist/__tests__/fileMock.d.ts +4 -0
  4. package/dist/__tests__/setup.d.ts +2 -0
  5. package/{lib/stories/0-Welcome.stories.d.ts → dist/__tests__/utils/utils.test.d.ts} +1 -1
  6. package/dist/components/Accordion/Accordion.d.ts +21 -0
  7. package/dist/components/Autosuggest/Autosuggest.stories.d.ts +4 -0
  8. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +18 -0
  9. package/dist/components/Button/Button.d.ts +25 -0
  10. package/dist/components/ButtonGroup/ButtonGroup.d.ts +22 -0
  11. package/dist/components/Card/Card.d.ts +51 -0
  12. package/dist/components/Checkbox/Checkbox.d.ts +47 -0
  13. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +49 -0
  14. package/dist/components/ComponentWrapper/ComponentWrapper.d.ts +29 -0
  15. package/dist/components/DatePicker/DatePicker.d.ts +81 -0
  16. package/dist/components/Fieldset/Fieldset.d.ts +22 -0
  17. package/dist/components/Form/Form.d.ts +29 -0
  18. package/dist/components/Grid/SimpleGrid.d.ts +17 -0
  19. package/dist/components/Heading/Heading.d.ts +27 -0
  20. package/dist/components/HelperErrorText/HelperErrorText.d.ts +29 -0
  21. package/dist/components/Hero/Hero.d.ts +40 -0
  22. package/dist/components/HorizontalRule/HorizontalRule.d.ts +11 -0
  23. package/dist/components/Icons/Icon.d.ts +37 -0
  24. package/dist/components/Icons/IconSvgs.d.ts +33 -0
  25. package/dist/components/Image/Image.d.ts +61 -0
  26. package/dist/components/Label/Label.d.ts +20 -0
  27. package/dist/components/Link/Link.d.ts +20 -0
  28. package/dist/components/List/List.d.ts +35 -0
  29. package/dist/components/Logo/Logo.d.ts +26 -0
  30. package/dist/components/Logo/LogoSvgs.d.ts +48 -0
  31. package/dist/components/Modal/Modal.d.ts +33 -0
  32. package/dist/components/Notification/Notification.d.ts +50 -0
  33. package/dist/components/Pagination/Pagination.d.ts +27 -0
  34. package/dist/components/Placeholder/Placeholder.d.ts +10 -0
  35. package/dist/components/ProgressIndicator/ProgressIndicator.d.ts +30 -0
  36. package/dist/components/Radio/Radio.d.ts +43 -0
  37. package/dist/components/RadioGroup/RadioGroup.d.ts +51 -0
  38. package/dist/components/SearchBar/SearchBar.d.ts +61 -0
  39. package/dist/components/Select/Select.d.ts +57 -0
  40. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +39 -0
  41. package/dist/components/SkipNavigation/SkipNavigation.d.ts +17 -0
  42. package/dist/components/Slider/Slider.d.ts +59 -0
  43. package/dist/components/StatusBadge/StatusBadge.d.ts +16 -0
  44. package/dist/components/StructuredContent/StructuredContent.d.ts +28 -0
  45. package/dist/components/StyleGuide/ColorCard.d.ts +12 -0
  46. package/dist/components/Table/Table.d.ts +30 -0
  47. package/dist/components/Tabs/Tabs.d.ts +26 -0
  48. package/dist/components/Template/Template.d.ts +126 -0
  49. package/dist/components/Text/Text.d.ts +16 -0
  50. package/dist/components/TextInput/TextInput.d.ts +79 -0
  51. package/dist/components/Toggle/Toggle.d.ts +42 -0
  52. package/dist/components/VideoPlayer/VideoPlayer.d.ts +38 -0
  53. package/dist/design-system-react-components.cjs.development.js +11648 -0
  54. package/dist/design-system-react-components.cjs.development.js.map +1 -0
  55. package/dist/design-system-react-components.cjs.production.min.js +2 -0
  56. package/dist/design-system-react-components.cjs.production.min.js.map +1 -0
  57. package/dist/design-system-react-components.esm.js +11493 -0
  58. package/dist/design-system-react-components.esm.js.map +1 -0
  59. package/dist/helpers/types.d.ts +1 -0
  60. package/dist/hooks/__tests__/useCarouselStyles.test.d.ts +1 -0
  61. package/dist/hooks/useCarouselStyles.d.ts +17 -0
  62. package/dist/hooks/useNYPLTheme.d.ts +66 -0
  63. package/dist/hooks/useWindowSize.d.ts +10 -0
  64. package/dist/index.d.ts +48 -0
  65. package/dist/index.js +8 -0
  66. package/dist/resources.scss +386 -0
  67. package/dist/styles.css +3 -0
  68. package/dist/theme/components/accordion.d.ts +20 -0
  69. package/dist/theme/components/breadcrumb.d.ts +105 -0
  70. package/dist/theme/components/button.d.ts +120 -0
  71. package/dist/theme/components/buttonGroup.d.ts +11 -0
  72. package/dist/theme/components/card.d.ts +381 -0
  73. package/dist/theme/components/checkbox.d.ts +95 -0
  74. package/dist/theme/components/checkboxGroup.d.ts +14 -0
  75. package/dist/theme/components/componentWrapper.d.ts +12 -0
  76. package/dist/theme/components/customTable.d.ts +624 -0
  77. package/dist/theme/components/datePicker.d.ts +16 -0
  78. package/dist/theme/components/fieldset.d.ts +20 -0
  79. package/dist/theme/components/global.d.ts +73 -0
  80. package/dist/theme/components/globalMixins.d.ts +23 -0
  81. package/dist/theme/components/heading.d.ts +160 -0
  82. package/dist/theme/components/helperErrorText.d.ts +12 -0
  83. package/dist/theme/components/hero.d.ts +499 -0
  84. package/dist/theme/components/horizontalRule.d.ts +15 -0
  85. package/dist/theme/components/icon.d.ts +47755 -0
  86. package/dist/theme/components/image.d.ts +590 -0
  87. package/dist/theme/components/label.d.ts +18 -0
  88. package/dist/theme/components/link.d.ts +62 -0
  89. package/dist/theme/components/list.d.ts +182 -0
  90. package/dist/theme/components/logo.d.ts +477 -0
  91. package/dist/theme/components/notification.d.ts +95 -0
  92. package/dist/theme/components/pagination.d.ts +16 -0
  93. package/dist/theme/components/progressIndicator.d.ts +52 -0
  94. package/dist/theme/components/radio.d.ts +107 -0
  95. package/dist/theme/components/radioGroup.d.ts +14 -0
  96. package/dist/theme/components/searchBar.d.ts +18 -0
  97. package/dist/theme/components/select.d.ts +82 -0
  98. package/dist/theme/components/skeletonLoader.d.ts +102 -0
  99. package/dist/theme/components/skipNavigation.d.ts +25 -0
  100. package/dist/theme/components/slider.d.ts +59 -0
  101. package/dist/theme/components/statusBadge.d.ts +25 -0
  102. package/dist/theme/components/structuredContent.d.ts +326 -0
  103. package/dist/theme/components/tabs.d.ts +136 -0
  104. package/dist/theme/components/template.d.ts +108 -0
  105. package/dist/theme/components/text.d.ts +26 -0
  106. package/dist/theme/components/textInput.d.ts +124 -0
  107. package/dist/theme/components/toggle.d.ts +93 -0
  108. package/dist/theme/components/videoPlayer.d.ts +40 -0
  109. package/dist/theme/foundations/breakpoints.d.ts +23 -0
  110. package/dist/theme/foundations/colors.d.ts +3 -0
  111. package/dist/theme/foundations/global.d.ts +58 -0
  112. package/dist/theme/foundations/radii.d.ts +6 -0
  113. package/dist/theme/foundations/shadows.d.ts +4 -0
  114. package/dist/theme/foundations/spacing.d.ts +82 -0
  115. package/dist/theme/foundations/typography.d.ts +8 -0
  116. package/dist/theme/index.d.ts +20 -0
  117. package/dist/theme/provider.d.ts +3 -0
  118. package/dist/theme/types.d.ts +1 -0
  119. package/dist/utils/componentCategories.d.ts +1 -0
  120. package/dist/utils/interfaces.d.ts +5 -0
  121. package/dist/utils/utils.d.ts +31 -0
  122. package/package.json +132 -20
  123. package/lib/components/Button/Button.d.ts +0 -17
  124. package/lib/components/Button/Button.js +0 -42
  125. package/lib/index.d.ts +0 -1
  126. package/lib/index.js +0 -6
  127. package/lib/stories/0-Welcome.stories.js +0 -19
  128. package/lib/stories/1-Button.stories.d.ts +0 -6
  129. package/lib/stories/1-Button.stories.js +0 -20
package/README.md CHANGED
@@ -1,4 +1,390 @@
1
- # NYPL Design System React Components
2
- ## How to use
3
- This is intended to be used with [NYPL Design System Styles](https://github.com/NYPL/nypl-design-system/tree/master/src/styles)
1
+ # Reservoir Design System
4
2
 
3
+ ![Build Status](https://github.com/nypl/nypl-design-system/actions/workflows/ci.yml/badge.svg?branch=development)
4
+
5
+ [![npm version](https://badge.fury.io/js/%40nypl%2Fdesign-system-react-components.svg)](https://badge.fury.io/js/%40nypl%2Fdesign-system-react-components)
6
+
7
+ The Reservoir Design System (DS) is NYPL’s open-source extensible React library for products and experiences with the accessibility as its foundation. It ships functional, stateless components with consistent NYPL styling. You can learn more about the project and its goals [on the project's wiki](https://github.com/NYPL/nypl-design-system/wiki).
8
+
9
+ Storybook documentation
10
+
11
+ - [Production - deployed to Github Pages](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/welcome--page)
12
+ - [Development/QA - deployed to Vercel](https://nypl-design-system.vercel.app/?path=/story/welcome--page)
13
+
14
+ | Table of Contents | |
15
+ | ----------------- | ----------------------------------------------------------------------------------- |
16
+ | 1. | [Contributing Quickstart](#contributing-quickstart) |
17
+ | 2. | [Developing with NPM Link](#developing-with-npm-link) |
18
+ | 3. | [Using the Design System in Your Product](#using-the-design-system-in-your-product) |
19
+ | 4. | [Using Chakra UI Components](#using-chakra-ui-components) |
20
+ | 5. | [Storybook](#storybook) |
21
+ | 6. | [Typescript Usage](#typescript-usage) |
22
+ | 7. | [Unit Testing](#unit-testing) |
23
+ | 8. | [Accessibility](#accessibility) |
24
+ | 9. | [CDN](#cdn) |
25
+
26
+ ## Contributing Quickstart
27
+
28
+ Follow these steps to setup a local installation of the project:
29
+
30
+ 1. Clone the repo
31
+
32
+ ```sh
33
+ $ git clone https://github.com/NYPL/nypl-design-system.git
34
+ ```
35
+
36
+ 2. Install all the dependencies
37
+
38
+ ```sh
39
+ $ npm install
40
+ ```
41
+
42
+ 3. Run the Storybook instance and view it at `http://localhost:6006`
43
+
44
+ ```sh
45
+ $ npm run storybook
46
+ ```
47
+
48
+ You can now edit styles or templates in the `src` directory, and they will automatically re-build and update in the Storybook instance. Adding new stories or changing story names will require a page refresh.
49
+
50
+ Information about active maintainers, how we run reviews, and more can be found in our wiki page for [Contributing to the Design System](https://github.com/NYPL/nypl-design-system/wiki/Contributing-to-the-React-Library).
51
+
52
+ Follow the [contribution document](/.github/CONTRIBUTING.md) to follow git branching convetions, component creation and update guidelines, testing methodoly, and documentation guidelines.
53
+
54
+ ### Node Version
55
+
56
+ We recommend using Node version 12.22.x since the DS has some issues with versions higher than 12.x. The Github Actions for linting, automated testing, deploying to Github Pages, and releasing to npm are all running on Node 12.x.
57
+
58
+ If you are using `nvm`, the local `.nvmrc` file can be use to set your local Node version with the `nvm use` command (will be set to `12.22.x`).
59
+
60
+ ## Developing with NPM Link
61
+
62
+ To develop with a local version of the Design System:
63
+
64
+ 1. In the Design System directory, run:
65
+
66
+ ```sh
67
+ $ npm link
68
+ ```
69
+
70
+ 2. Go to the consuming application directory and run:
71
+
72
+ ```sh
73
+ $ npm link @nypl/design-system-react-components
74
+ ```
75
+
76
+ 3. Go back to the Design System directory and run the following command. It allos the local Design System to be rebuilt and exported automatically:
77
+
78
+ ```sh
79
+ $ npm start
80
+ ```
81
+
82
+ ### Error Troubleshooting
83
+
84
+ It's possible when running `npm link` that you'll get an `Invalid Hook` issue. If this occurs, it's most likely caused by having two versions of React when trying to run the application while the NYPL DS package is linked. This [Duplicate React](https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react) issue is covered by the React team.
85
+
86
+ To be more specific, you should run the following in your local DS directory, where `[../path/to/application]` is the local directory of the consuming application.
87
+
88
+ ```sh
89
+ $ npm link [../path/to/application]/node_modules/react
90
+ ```
91
+
92
+ Now you should be able to run `npm start` in the DS directory and `npm run dev` (or whatever your application uses) in the application directory and not get an `Invalid Hook` error.
93
+
94
+ ### npm Unlink
95
+
96
+ To unlink the DS codebase:
97
+
98
+ 1. Run `npm unlink` in the Design System directory.
99
+ 2. Run `npm unlink --no-save @nypl/design-system-react-components` in the consuming application.
100
+
101
+ ## Using the Design System in Your Product
102
+
103
+ To use the Design System in your project:
104
+
105
+ 1. Install the DS:
106
+
107
+ ```sh
108
+ $ npm install @nypl/design-system-react-components
109
+ ```
110
+
111
+ 2. Import the styles in your main css file
112
+
113
+ ```css
114
+ @import "~@nypl/design-system-react-components/dist/styles.css";
115
+ ```
116
+
117
+ 3. Import the `DSProvider` component
118
+
119
+ In order to use DS components in a consuming application, there is a necessary step that must be done for component styles to properly render. Consuming applications need to wrap all the DS components with a simple provider component. Fortunately, this only needs to be done once at the top level of the consuming application.
120
+
121
+ Once the following is completed, DS components that internally use Chakra UI will render styles properly.
122
+
123
+ ```jsx
124
+ // your main application file
125
+ import { DSProvider } from "@nypl/design-system-react-components";
126
+
127
+ // ...
128
+ const ApplicationContainer = (props) => {
129
+ // ...
130
+ return (
131
+ <DSProvider>
132
+ <div className="my-app">
133
+ // ...
134
+ {children}
135
+ </div>
136
+ </DSProvider>
137
+ );
138
+ };
139
+ ```
140
+
141
+ 4. Use DS components!
142
+
143
+ Consult Storybook for the list of available components and props that they require.
144
+
145
+ Here's an example with the `Link` component:
146
+
147
+ ```jsx
148
+ import { Link } from "@nypl/design-system-react-components";
149
+
150
+ function NewComponent(props) {
151
+ return <Link href="https://www.hathitrust.org/">HathiTrust</Link>;
152
+ }
153
+ ```
154
+
155
+ Sometimes you may have conflicts, perhaps with `React-Router`. In that case, you can alias your imports:
156
+
157
+ ```jsx
158
+ import * as DS from "@nypl/design-system-react-components";
159
+ import { Link } from "react-router";
160
+
161
+ function NewComponent(props) {
162
+ return (
163
+ <DS.Link>
164
+ <Link to="/license">public domain</Link>
165
+ </DS.Link>
166
+ );
167
+ }
168
+ ```
169
+
170
+ ### NYPL DS, NYPL Header, and NYPL Footer
171
+
172
+ ```jsx
173
+ <body>
174
+ <NYPLHeader />
175
+
176
+ <div class="app">
177
+ <!-- your code here -->
178
+ </div>
179
+
180
+ <NYPLFooter />
181
+ </body>
182
+ ```
183
+
184
+ ## Using Chakra UI Components
185
+
186
+ The Chakra UI component library has been integrated into the Reservoir Design System. We are still progressing towards using Chakra components and patterns to build DS components, and therefore documentation and features are expected to change. While the implementation details of DS components will use Chakra, the DS package itself will export _some_ Chakra components.
187
+
188
+ The list of re-exported Chakra components can be found in the main [index.ts](/src/index.ts) file. They include:
189
+
190
+ - `Box`, `Center`, `Circle`, `Grid`, `GridItem`, `HStack`, `Square`, `Stack`, `VStack`
191
+
192
+ Find more information about the Design System's internal use of Chakra to create and refactor components in the Storybook documentation page. The following two links have the same information but in different formats for your reading preference:
193
+
194
+ - [MDX format](/src/docs/Chakra.stories.mdx)
195
+ - [Storybook page](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/chakra-ui--page)
196
+
197
+ Chakra was integrated into the Design System in version `0.25.0`. For those looking to update to a version greater than or equal `0.25.0`, check out our [Chakra Migration Guide](/CHAKRA_MIGRATION_GUIDE.md).
198
+
199
+ ## CDN
200
+
201
+ You can also use the Design System styles in your project through the `unpkg` CDN:
202
+
203
+ ```jsx
204
+ <link href="https://unpkg.com/@nypl/design-system-react-components/dist/styles.css">
205
+ ```
206
+
207
+ If you need to reference a particular version you can do do by including the version number in the URL:
208
+
209
+ ```jsx
210
+ <link href="https://unpkg.com/@nypl/design-system-react-components@0.9.1/dist/styles.css">
211
+ ```
212
+
213
+ You can check out a working Codepen with unpkg [here](https://codepen.io/edwinguzman/pen/ExmXGKx).
214
+
215
+ ## Storybook
216
+
217
+ The Reservoir Design System leverages Storybook to document all the React components and style guidelines. The Storybook documentation can be found [here](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/welcome--page). For your convenience, the Reservoir Design System components have been organized into logical categories based on both form and function. Please refer to the COMPONENTS section in the Storybook sidebar.
218
+
219
+ ### Documentation Instances
220
+
221
+ There are currently two main instances of the Reservoir Design System Storybook documentation. There are also "preview" sites that are used to quickly and easily view pull request changes.
222
+
223
+ **Production**
224
+
225
+ The production Storybook documentation is deployed to [Github Pages](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/welcome--page). This is the main instance we use to share the latest stable release of the Reservoir Design System. This documentation site is deployed through [Github Actions](/.github/workflows/gh-pages.yml) only on merges to the `release` branch.
226
+
227
+ As of July, 2021, the Github Pages production site gets deployed every two weeks on the same schedule as npm releases.
228
+
229
+ **Development**
230
+
231
+ The development Storybook documentation is deployed to [Vercel](https://nypl-design-system.vercel.app/?path=/story/welcome--page). This development site has all the working updates that get merged to the `development` branch. This means that this site is constantly being updated as pull requests are being merged in. This site is used to see the lastest changes during a working sprint before a production release is made.
232
+
233
+ **Preview Sites**
234
+
235
+ Preview Storybook documentation sites are deployed to Vercel on every commit push to every branch in this repository. They follow a pattern such as `nypl-design-system-[hash]-nypl.vercel.app` where `[hash]` is a random hash created by Vercel. This means that the URL varies and that those instances are eventually shut off. They are not meant to be used as long-term sites but rather for reviewing working changes within the team.
236
+
237
+ ### React Component Documentation
238
+
239
+ When actively developing components or fixing bugs, make sure that the related stories are created or updated. This means updating the respective `[component-name].stories.mdx` file. For information on how to write stories, check out the [Anatomy of a Story](https://github.com/NYPL/nypl-design-system/wiki/Anatomy-of-a-Story) wiki page.
240
+
241
+ For stand-alone document pages in Storybook, you need to:
242
+
243
+ 1. create the `[page-name].stories.mdx` file in `src/docs/`
244
+ 2. add the file reference to the `.storybook/main.js` file in the `stories` array
245
+
246
+ ### React Component Versions
247
+
248
+ To help consuming application developers understand which version of the DS is required for a specific component, each component story page includes the following:
249
+
250
+ - when a component was added to the DS
251
+ - minimum version of the DS required for the latest version of a component
252
+
253
+ **Example Component Version Table**
254
+
255
+ | Component Version | DS Version |
256
+ | ----------------- | ---------- |
257
+ | Added | `0.20.1` |
258
+ | Latest | `0.23.2` |
259
+
260
+ ### Static Build
261
+
262
+ There should be no need to run the static Storybook instance while actively developing -- it's used exclusively for building out the `gh-pages` environment and deploying it to [Github Pages](https://nypl.github.io/nypl-design-system/reservoir/v1/?path=/story/welcome--page). In the event that you do run the static Storybook npm script, run:
263
+
264
+ ```sh
265
+ $ npm run build-storybook:v1
266
+ ```
267
+
268
+ You can then view `/reservoir/v1/index.html` in your browser. _Make sure not to commit this directory_.
269
+
270
+ ## Typescript Usage
271
+
272
+ The Reservoir Design System is built with Typescript. Check out the Design System's [Typescript documentation](/TYPESCRIPT.md) for more information on why we chose to build React components in Typescript and the benefits and the gotchas we encountered.
273
+
274
+ ## Unit Testing
275
+
276
+ The Reservoir Design System runs unit tests with Jest and React Testing Library.
277
+
278
+ To run all tests once:
279
+
280
+ ```sh
281
+ $ npm test
282
+ ```
283
+
284
+ If you're actively writing or updating tests, you can run the tests in watch mode. This will wait for any changes and run when a file is saved:
285
+
286
+ ```sh
287
+ $ npm run test:watch
288
+ ```
289
+
290
+ If you want to run tests on only one specific file, run:
291
+
292
+ ```sh
293
+ $ npm test -- src/[path/to/file]
294
+ ```
295
+
296
+ For example, to test the `Link` component, run:
297
+
298
+ ```sh
299
+ $ npm test -- src/components/Link/Link.test.tsx
300
+ ```
301
+
302
+ ### Snapshot Testing
303
+
304
+ The NYPL DS implements snapshot testing with `react-test-renderer` and `jest`. Using React Testing Library to test our components works well to make sure that what the user sees is what the component should be rendering. There are also some behavioral tests that test user interactions. If, however, a component's DOM or SCSS styling was unintentionally updated, we can catch those bugs through snapshot testing.
305
+
306
+ The `react-test-renderer` package, will create a directory and a file to hold `.snap` files after a unit test is created. Using the `Notification` component as an example, this is the basic layout for a snapshot test:
307
+
308
+ ```tsx
309
+ import renderer from "react-test-renderer";
310
+
311
+ // ...
312
+
313
+ it("Renders the UI snapshot correctly", () => {
314
+ const tree = renderer
315
+ .create(
316
+ <Notification
317
+ id="notificationID"
318
+ notificationHeading="Notification Heading"
319
+ notificationContent={<>Notification content.</>}
320
+ />
321
+ )
322
+ .toJSON();
323
+ expect(tree).toMatchSnapshot();
324
+ });
325
+ ```
326
+
327
+ If this is a new test and we run `npm test`, a [`/__snapshots__/Notification.test.tsx.snap`](/src/components/Notification/__snapshots__/Notification.test.tsx.snap) file is created. This holds the DOM structure as well as any inline CSS that was added.
328
+
329
+ ```tsx
330
+ exports[`Notification Snapshot Renders the UI snapshot correctly 1`] = `
331
+ <aside
332
+ className="notification notification--standard "
333
+ id="notificationID"
334
+ >
335
+ // Removed for brevity...
336
+ </aside>
337
+ `;
338
+ ```
339
+
340
+ Now, if we unintentionally update the `Notification.tsx` component to render a `div` instead of an `aside` element, this test will fail.
341
+
342
+ If you want to update any existing snapshots, re-run the test script as:
343
+
344
+ ```sh
345
+ $ npm test -- --updateSnapshot
346
+ ```
347
+
348
+ Each snapshot file also includes a link to its [Jest Snapshot documentation](https://jestjs.io/docs/snapshot-testing) which is recommended to read!
349
+
350
+ ### Storybook Jest Addon
351
+
352
+ Through the [`@storybook/addon-jest`](https://www.npmjs.com/package/@storybook/addon-jest) plugin, we can see a component's suite of unit tests right Storybook. In the "Addons" panel, a "Test" tab will display all the tests for the current component and whether they pass or fail.
353
+
354
+ After writing new tests, run `npm run test:generate-output` to create a new JSON file that is used by Storybook. This JSON file contains all the test suites for all the components and Storybook picks this up and automatically combines a component with its relevant unit tests. Make sure to commit this file although new builds on Github Pages will recreate this file for the production Storybook instance.
355
+
356
+ ## Accessibility
357
+
358
+ ### Development and Storybook
359
+
360
+ The Reservoir Design System is built with accessibility in mind. By using Chakra UI as our foundational base, the custom DS components built with Chakra have accessibility concerns already implemented. On top of built-in accessible elements, DS components internally work to link labels with input elements, to add correct `aria-*` attributes, to visually hide text but still associate it with the correct element for titles and descriptions, to auto-generate a random `id` attribute if none was passed, and much more.
361
+
362
+ We make use of:
363
+
364
+ - `eslint-plugin-jsx-a11y` for finding accessibility errors through linting and through IDE environments.
365
+ - `jest-axe` for running [`axe-core`](https://github.com/dequelabs/axe-core) on _every_ component's unit test file. This is part of the automated tests that run in Github Actions through the `npm test` command.
366
+ - `@storybook/addon-a11y` for real-time accessibility testing in the browser through Storybook. _Every_ component has a tab that displays violations, passes, and incomplete checks performed by `axe-core`.
367
+
368
+ If applicable, DS components have section(s) on accessibility in their Storybook documentation. For example, in the `Slider`'s [Storybook file](/src/components/Slider/Slider.stories.mdx), there are two "Accessibility" sections for each of the two `Slider` types, "single" and "range". This gives an explanation on additional changes we made to make the combination of elements in the `Slider` component accessible.
369
+
370
+ ### Product Requirements
371
+
372
+ The Reservoir Design System provides accessible stories, but real live data can necessitate additional accessibility requirements beyond what we're committed to in our generic, extensible components. To ensure your products' final result is accessible, please adhere to the accessibility requirements put together by NYPL's accessibility coordinator on [Metronome](http://themetronome.co/).
373
+
374
+ NYPL's Metronome instance is currently password protected. For access to Metronome, please contact NYPL's UX team or Design System team.
375
+
376
+ ## CDN
377
+
378
+ You can also use the Design System styles in your project through the `unpkg` CDN:
379
+
380
+ ```jsx
381
+ <link href="https://unpkg.com/@nypl/design-system-react-components/dist/styles.css">
382
+ ```
383
+
384
+ If you need to reference a particular version you can do do by including the version number in the URL:
385
+
386
+ ```jsx
387
+ <link href="https://unpkg.com/@nypl/design-system-react-components@0.9.1/dist/styles.css">
388
+ ```
389
+
390
+ You can check out a working Codepen with unpkg [here](https://codepen.io/edwinguzman/pen/ExmXGKx).
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file is use to mock asset imports in TSX files, mostly
3
+ * used in our case to mock SVG files.
4
+ */
@@ -0,0 +1,2 @@
1
+ import "@testing-library/jest-dom";
2
+ import "jest-axe/extend-expect";
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+ export declare type AccordionTypes = "default" | "warning" | "error";
3
+ export interface AccordionDataProps {
4
+ accordionType?: AccordionTypes;
5
+ label: string;
6
+ panel: string | React.ReactNode;
7
+ }
8
+ export interface AccordionProps {
9
+ /** Array of data to display, and an optional accordionType */
10
+ accordionData: AccordionDataProps[];
11
+ /** ID that other components can cross reference for accessibility purposes */
12
+ id?: string;
13
+ /** Whether the accordion is open by default only on its initial rendering */
14
+ isDefaultOpen?: boolean;
15
+ }
16
+ /**
17
+ * Accordion component that shows content on toggle. Can be used to display
18
+ * multiple accordion items together.
19
+ */
20
+ export declare const Accordion: import("@chakra-ui/react").ChakraComponent<(props: AccordionProps) => JSX.Element, {}>;
21
+ export default Accordion;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare const AutosuggestLibrary: () => JSX.Element;
3
+ export declare const AutosuggestFish: () => JSX.Element;
4
+ export declare const SearchBarExample: () => JSX.Element;
@@ -0,0 +1,18 @@
1
+ import * as React from "react";
2
+ export declare type BreadcrumbsTypes = "blogs" | "booksAndMore" | "education" | "locations" | "research" | "whatsOn";
3
+ export interface BreadcrumbsDataProps {
4
+ url: string;
5
+ text: string | React.ReactNode;
6
+ }
7
+ export interface BreadcrumbProps {
8
+ /** Breadcrumb links as an array */
9
+ breadcrumbsData: BreadcrumbsDataProps[];
10
+ /** Used to control how the `Hero` component will be rendered. */
11
+ breadcrumbsType?: BreadcrumbsTypes;
12
+ /** className you can add in addition to 'input' */
13
+ className?: string;
14
+ /** ID that other components can cross reference for accessibility purposes */
15
+ id?: string;
16
+ }
17
+ export declare const Breadcrumbs: import("@chakra-ui/react").ChakraComponent<(props: BreadcrumbProps) => JSX.Element, {}>;
18
+ export default Breadcrumbs;
@@ -0,0 +1,25 @@
1
+ import * as React from "react";
2
+ export declare type ButtonElementType = "submit" | "button" | "reset";
3
+ export declare type ButtonTypes = "primary" | "secondary" | "callout" | "pill" | "link" | "noBrand";
4
+ interface ButtonProps {
5
+ /** The button variation to render based on the `ButtonTypes` type.*/
6
+ buttonType?: ButtonTypes;
7
+ /** Additional className to use. */
8
+ className?: string;
9
+ /** ID that other components can cross reference for accessibility purposes. */
10
+ id: string;
11
+ /** Adds 'disabled' property to the button. */
12
+ isDisabled?: boolean;
13
+ /** Trigger the Button's action through the `mouseDown` event handler instead
14
+ * of `onClick`. `false` by default. */
15
+ mouseDown?: boolean;
16
+ /** The action to perform on the `<button>`'s onClick function. */
17
+ onClick?: (event: React.MouseEvent | React.KeyboardEvent) => void;
18
+ /** The HTML button type attribute. */
19
+ type?: ButtonElementType;
20
+ }
21
+ /**
22
+ * Renders a simple `button` element with custom variant styles.
23
+ */
24
+ export declare const Button: import("@chakra-ui/react").ChakraComponent<(props: React.PropsWithChildren<ButtonProps>) => JSX.Element, {}>;
25
+ export default Button;
@@ -0,0 +1,22 @@
1
+ import * as React from "react";
2
+ import { LayoutTypes } from "../../helpers/types";
3
+ export declare type ButtonGroupWidths = "default" | "full";
4
+ interface ButtonGroupProps {
5
+ /** Sets the width to "default" (for "fit-content") or "full". */
6
+ buttonWidth?: ButtonGroupWidths;
7
+ /** Additional className to use. */
8
+ className?: string;
9
+ /** ID that other components can cross reference for accessibility purposes. */
10
+ id?: string;
11
+ /** Set's the disabled state to all the internal `Button` components. */
12
+ isDisabled?: boolean;
13
+ /** Renders the layout of `Button` components in a row or column. */
14
+ layout?: LayoutTypes;
15
+ }
16
+ /**
17
+ * A simple wrapper to group `Button` components together. The layout can be set
18
+ * to row or column and the width of internal `Button` components can be set to
19
+ * the parent's full width or the `Button`'s content width
20
+ */
21
+ export declare const ButtonGroup: import("@chakra-ui/react").ChakraComponent<(props: React.PropsWithChildren<ButtonGroupProps>) => JSX.Element, {}>;
22
+ export default ButtonGroup;
@@ -0,0 +1,51 @@
1
+ import * as React from "react";
2
+ import { LayoutTypes } from "../../helpers/types";
3
+ import { ComponentImageProps } from "../Image/Image";
4
+ interface CardBaseProps {
5
+ /** Optional value to control the alignment of the text and elements. */
6
+ isCentered?: boolean;
7
+ /** Optional value to render the layout in a row or column.
8
+ * Default is `"column"`. */
9
+ layout?: LayoutTypes;
10
+ }
11
+ interface CardWrapperProps {
12
+ /** Optional CSS class name to add. */
13
+ className?: string;
14
+ /** ID that other components can cross reference for accessibility purposes. */
15
+ id?: string;
16
+ /** Main link to use when the full `Card` component should be clickable. */
17
+ mainActionLink?: string;
18
+ /** Additional object for styling the `Card`'s `div` wrapper. */
19
+ styles?: any;
20
+ }
21
+ interface CardImageProps extends ComponentImageProps {
22
+ /** Optional boolean value to control the position of the `CardImage`. */
23
+ isAtEnd?: boolean;
24
+ }
25
+ interface CardActionsProps extends CardBaseProps {
26
+ /** Optional boolean value to control visibility of border on the bottom edge
27
+ * of the card actions element */
28
+ bottomBorder?: boolean;
29
+ /** Optional boolean value to control visibility of border on the top edge of
30
+ * the card actions element */
31
+ topBorder?: boolean;
32
+ }
33
+ export interface CardProps extends CardBaseProps, CardWrapperProps {
34
+ /** Optional hex color value used to set the card background color. */
35
+ backgroundColor?: string;
36
+ /** Optional hex color value used to override the default text color. */
37
+ foregroundColor?: string;
38
+ /** Optional boolean value to control the visibility of a border around
39
+ * the card. */
40
+ isBordered?: boolean;
41
+ /** Object used to create and render the `Image` component. */
42
+ imageProps?: CardImageProps;
43
+ /** Set CardActions to the right content side. This only works in
44
+ * the row layout. */
45
+ isAlignedRightActions?: boolean;
46
+ }
47
+ export declare const CardHeading: import("@chakra-ui/react").ChakraComponent<import("@chakra-ui/react").ChakraComponent<(props: React.PropsWithChildren<import("../Heading/Heading").HeadingProps>) => JSX.Element, {}>, {}>;
48
+ export declare const CardContent: import("@chakra-ui/react").ChakraComponent<(props: React.PropsWithChildren<{}>) => JSX.Element, {}>;
49
+ export declare const CardActions: import("@chakra-ui/react").ChakraComponent<(props: React.PropsWithChildren<CardActionsProps>) => JSX.Element, {}>;
50
+ export declare const Card: import("@chakra-ui/react").ChakraComponent<(props: React.PropsWithChildren<CardProps>) => JSX.Element, {}>;
51
+ export default Card;
@@ -0,0 +1,47 @@
1
+ import * as React from "react";
2
+ import { HelperErrorTextType } from "../HelperErrorText/HelperErrorText";
3
+ interface CheckboxIconProps {
4
+ /** When using the Checkbox as a "controlled" form element, you can specify
5
+ * the Checkbox's checked state using this prop.
6
+ * Learn more about controlled and uncontrolled form fields:
7
+ * https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/ */
8
+ isChecked?: boolean;
9
+ /** Adds the indeterminate state to the `Checkbox`. */
10
+ isIndeterminate?: boolean;
11
+ }
12
+ export interface CheckboxProps extends CheckboxIconProps {
13
+ /** className you can add in addition to 'input' */
14
+ className?: string;
15
+ /** Optional string to populate the HelperErrorText for standard state */
16
+ helperText?: HelperErrorTextType;
17
+ /** ID that other components can cross reference for accessibility purposes */
18
+ id: string;
19
+ /** Optional string to populate the HelperErrorText for the error state
20
+ * when `isInvalid` is true. */
21
+ invalidText?: HelperErrorTextType;
22
+ /** Adds the 'disabled' and `aria-disabled` attributes to the input when true.
23
+ * This also makes the text italic and color scheme gray. */
24
+ isDisabled?: boolean;
25
+ /** Adds the 'aria-invalid' attribute to the input when true. This also makes
26
+ * the color theme "NYPL error" red for the button and text. */
27
+ isInvalid?: boolean;
28
+ /** Adds the 'required' attribute to the input when true. */
29
+ isRequired?: boolean;
30
+ /** The checkbox's label. This will serve as the text content for a `<label>`
31
+ * element if `showlabel` is true, or an "aria-label" if `showLabel` is false. */
32
+ labelText: string | JSX.Element;
33
+ /** The name prop indicates into which group of checkboxes this checkbox
34
+ * belongs. If none is specified, 'default' will be used */
35
+ name?: string;
36
+ /** The action to perform on the `<input>`'s onChange function */
37
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
38
+ /** Offers the ability to hide the helper/invalid text. */
39
+ showHelperInvalidText?: boolean;
40
+ /** Offers the ability to show the checkbox's label onscreen or hide it.
41
+ * Refer to the `labelText` property for more information. */
42
+ showLabel?: boolean;
43
+ /** Populates the value of the input */
44
+ value?: string;
45
+ }
46
+ export declare const Checkbox: import("@chakra-ui/react").ChakraComponent<React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>>, {}>;
47
+ export default Checkbox;
@@ -0,0 +1,49 @@
1
+ import * as React from "react";
2
+ import { HelperErrorTextType } from "../HelperErrorText/HelperErrorText";
3
+ import { LayoutTypes } from "../../helpers/types";
4
+ export interface CheckboxGroupProps {
5
+ /** Any child node passed to the component. */
6
+ children: React.ReactNode;
7
+ /** Populates the initial value of the input */
8
+ defaultValue?: string[];
9
+ /** Optional string to populate the HelperErrorText for standard state */
10
+ helperText?: HelperErrorTextType;
11
+ /** ID that other components can cross reference for accessibility purposes */
12
+ id: string;
13
+ /** Optional string to populate the HelperErrorText for error state */
14
+ invalidText?: HelperErrorTextType;
15
+ /** Adds the 'disabled' prop to the input when true. */
16
+ isDisabled?: boolean;
17
+ /** Set's the `Checkbox`s' wrapper to be full width. */
18
+ isFullWidth?: boolean;
19
+ /** A`dds the 'aria-invalid' attribute to the input and
20
+ * sets the error state when true. */
21
+ isInvalid?: boolean;
22
+ /** Adds the 'required' attribute to the input when true. */
23
+ isRequired?: boolean;
24
+ /** The checkbox group label displayed in a `legend` element if `showlabel` is
25
+ * true, or an "aria-label" if `showLabel` is false. */
26
+ labelText: string;
27
+ /** Renders the checkbox buttons in a row or column (default). */
28
+ layout?: LayoutTypes;
29
+ /** The `name` prop indicates the form group for all the `Checkbox` children. */
30
+ name: string;
31
+ /** The action to perform on the `<input>`'s onChange function */
32
+ onChange?: (value: string[]) => void;
33
+ /** Offers the ability to hide the helper/invalid text. */
34
+ showHelperInvalidText?: boolean;
35
+ /** Offers the ability to show the group's legend onscreen or hide it. Refer
36
+ * to the `labelText` property for more information. */
37
+ showLabel?: boolean;
38
+ /** Whether or not to display the "(Required)" text in the label text.
39
+ * True by default. */
40
+ showRequiredLabel?: boolean;
41
+ }
42
+ /**
43
+ * Wrapper component to wrap `Checkbox` components. Can be displayed in a
44
+ * column or in a row. The `CheckboxGroup` component renders all the necessary
45
+ * wrapping and associated text elements, but the checkbox input elements
46
+ * _need_ to be child `Checkbox` components from the NYPL Design System.
47
+ */
48
+ export declare const CheckboxGroup: import("@chakra-ui/react").ChakraComponent<React.ForwardRefExoticComponent<CheckboxGroupProps & React.RefAttributes<HTMLInputElement>>, {}>;
49
+ export default CheckboxGroup;