@abstraks-dev/ui-library 1.0.5 → 1.1.5

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.
package/README.md CHANGED
@@ -15,14 +15,14 @@ import { Button, Card, TextInput } from 'ui-library';
15
15
  import 'ui-library/dist/styles/main.css';
16
16
 
17
17
  function App() {
18
- return (
19
- <div>
20
- <Card>
21
- <TextInput label="Name" placeholder="Enter your name" />
22
- <Button variant="primary">Submit</Button>
23
- </Card>
24
- </div>
25
- );
18
+ return (
19
+ <div>
20
+ <Card>
21
+ <TextInput label='Name' placeholder='Enter your name' />
22
+ <Button variant='primary'>Submit</Button>
23
+ </Card>
24
+ </div>
25
+ );
26
26
  }
27
27
  ```
28
28
 
@@ -59,9 +59,41 @@ npm run build-css:compressed
59
59
 
60
60
  ## Deployment
61
61
 
62
- This library is automatically deployed to npm using GitHub Actions.
62
+ This library supports both manual and automated deployment to npm using GitHub Actions.
63
63
 
64
- ### Automatic Deployment
64
+ ### Automated Version Bumping
65
+
66
+ The library includes automated version bumping based on commit message conventions:
67
+
68
+ #### Conventional Commits
69
+
70
+ Use these commit message prefixes to automatically bump versions:
71
+
72
+ - **`feat:`** or **`feature:`** → **Minor version bump** (1.0.0 → 1.1.0)
73
+ - **`fix:`** or **`bugfix:`** → **Patch version bump** (1.0.0 → 1.0.1)
74
+ - **`feat!:`** or **`BREAKING CHANGE`** → **Major version bump** (1.0.0 → 2.0.0)
75
+
76
+ #### Examples:
77
+
78
+ ```bash
79
+ git commit -m "feat: add new Button component variants" # Minor bump
80
+ git commit -m "fix: resolve focus issue in TextInput" # Patch bump
81
+ git commit -m "feat!: remove deprecated props from Card" # Major bump
82
+ ```
83
+
84
+ #### Using Auto Tool
85
+
86
+ You can also use the configured `auto` tool:
87
+
88
+ ```bash
89
+ # Automatic release based on PR labels
90
+ npm run release
91
+
92
+ # Or use auto directly
93
+ npx auto shipit
94
+ ```
95
+
96
+ ### Manual Deployment
65
97
 
66
98
  - Push a version tag (e.g., `v1.0.0`) to trigger automatic deployment
67
99
  - The workflow will run tests, build the library, and publish to npm
@@ -85,7 +117,6 @@ git tag v1.0.0
85
117
  git push origin v1.0.0
86
118
  ```
87
119
 
88
-
89
120
  # UI Library Testing
90
121
 
91
122
  This document explains how to run and write tests for the UI Library components.
@@ -130,6 +161,7 @@ src/
130
161
  We have comprehensive unit tests for:
131
162
 
132
163
  ### Components
164
+
133
165
  - **Button** - 9 tests covering props, events, states, and rendering
134
166
  - **Heading** - 8 tests covering different heading levels and props
135
167
  - **Label** - 12 tests covering label text, required states, and children
@@ -137,6 +169,7 @@ We have comprehensive unit tests for:
137
169
  - **MenuHover** - 8 tests covering toggle behavior, CSS classes, and props
138
170
 
139
171
  ### Icons
172
+
140
173
  - **ChevronDown** - 8 tests covering SVG properties, styling, and props
141
174
  - **ArrowRight** - 10 tests covering multi-path SVG structure and props
142
175
 
@@ -145,17 +178,20 @@ We have comprehensive unit tests for:
145
178
  ## 🧪 Testing Framework
146
179
 
147
180
  ### Tech Stack
181
+
148
182
  - **Jest** - Test runner and assertion library
149
183
  - **React Testing Library** - Component testing utilities
150
184
  - **@testing-library/user-event** - User interaction simulation
151
185
  - **@testing-library/jest-dom** - Extended Jest matchers
152
186
 
153
187
  ### Configuration
188
+
154
189
  - **Jest Config**: `jest.config.json`
155
- - **Babel Config**: `babel.config.json`
190
+ - **Babel Config**: `babel.config.json`
156
191
  - **Setup File**: `src/setupTests.js`
157
192
 
158
193
  ### Key Features
194
+
159
195
  - **CSS Import Mocking** - CSS files are automatically mocked
160
196
  - **Custom Test ID Attribute** - Uses `data-test-id` instead of `data-testid`
161
197
  - **SVG Testing** - Proper handling of SVG components
@@ -172,85 +208,90 @@ import userEvent from '@testing-library/user-event';
172
208
  import { YourComponent } from '../YourComponent';
173
209
 
174
210
  describe('YourComponent', () => {
175
- test('renders correctly', () => {
176
- render(<YourComponent />);
177
-
178
- expect(screen.getByRole('button')).toBeInTheDocument();
179
- });
180
-
181
- test('handles user interaction', async () => {
182
- const user = userEvent.setup();
183
- const handleClick = jest.fn();
184
-
185
- render(<YourComponent onClick={handleClick} />);
186
-
187
- await user.click(screen.getByRole('button'));
188
- expect(handleClick).toHaveBeenCalledTimes(1);
189
- });
211
+ test('renders correctly', () => {
212
+ render(<YourComponent />);
213
+
214
+ expect(screen.getByRole('button')).toBeInTheDocument();
215
+ });
216
+
217
+ test('handles user interaction', async () => {
218
+ const user = userEvent.setup();
219
+ const handleClick = jest.fn();
220
+
221
+ render(<YourComponent onClick={handleClick} />);
222
+
223
+ await user.click(screen.getByRole('button'));
224
+ expect(handleClick).toHaveBeenCalledTimes(1);
225
+ });
190
226
  });
191
227
  ```
192
228
 
193
229
  ### Testing Patterns
194
230
 
195
231
  #### 1. **Component Rendering**
232
+
196
233
  ```jsx
197
234
  test('renders with default props', () => {
198
- render(<Button>Click me</Button>);
199
-
200
- const button = screen.getByRole('button');
201
- expect(button).toBeInTheDocument();
202
- expect(button).toHaveTextContent('Click me');
235
+ render(<Button>Click me</Button>);
236
+
237
+ const button = screen.getByRole('button');
238
+ expect(button).toBeInTheDocument();
239
+ expect(button).toHaveTextContent('Click me');
203
240
  });
204
241
  ```
205
242
 
206
243
  #### 2. **Props Testing**
244
+
207
245
  ```jsx
208
246
  test('applies custom className', () => {
209
- render(<Button additionalClassName="custom">Test</Button>);
210
-
211
- const button = screen.getByRole('button');
212
- expect(button).toHaveClass('button', 'custom');
247
+ render(<Button additionalClassName='custom'>Test</Button>);
248
+
249
+ const button = screen.getByRole('button');
250
+ expect(button).toHaveClass('button', 'custom');
213
251
  });
214
252
  ```
215
253
 
216
254
  #### 3. **User Interactions**
255
+
217
256
  ```jsx
218
257
  test('handles click events', async () => {
219
- const user = userEvent.setup();
220
- const handleClick = jest.fn();
221
-
222
- render(<Button onClick={handleClick}>Click</Button>);
223
-
224
- await user.click(screen.getByRole('button'));
225
- expect(handleClick).toHaveBeenCalledTimes(1);
258
+ const user = userEvent.setup();
259
+ const handleClick = jest.fn();
260
+
261
+ render(<Button onClick={handleClick}>Click</Button>);
262
+
263
+ await user.click(screen.getByRole('button'));
264
+ expect(handleClick).toHaveBeenCalledTimes(1);
226
265
  });
227
266
  ```
228
267
 
229
268
  #### 4. **State Testing**
269
+
230
270
  ```jsx
231
271
  test('toggles state when clicked', async () => {
232
- const user = userEvent.setup();
233
- render(<Checkbox labelText="Test" setName="test" />);
234
-
235
- const checkbox = screen.getByRole('checkbox');
236
-
237
- expect(checkbox).not.toBeChecked();
238
- await user.click(checkbox);
239
- expect(checkbox).toBeChecked();
272
+ const user = userEvent.setup();
273
+ render(<Checkbox labelText='Test' setName='test' />);
274
+
275
+ const checkbox = screen.getByRole('checkbox');
276
+
277
+ expect(checkbox).not.toBeChecked();
278
+ await user.click(checkbox);
279
+ expect(checkbox).toBeChecked();
240
280
  });
241
281
  ```
242
282
 
243
283
  #### 5. **SVG/Icon Testing**
284
+
244
285
  ```jsx
245
286
  test('renders SVG with correct attributes', () => {
246
- render(<ChevronDown size={32} color="blue" />);
247
-
248
- const svg = document.querySelector('svg');
249
- expect(svg).toHaveAttribute('width', '32');
250
- expect(svg).toHaveAttribute('height', '32');
251
-
252
- const path = svg.querySelector('path');
253
- expect(path).toHaveAttribute('stroke', 'blue');
287
+ render(<ChevronDown size={32} color='blue' />);
288
+
289
+ const svg = document.querySelector('svg');
290
+ expect(svg).toHaveAttribute('width', '32');
291
+ expect(svg).toHaveAttribute('height', '32');
292
+
293
+ const path = svg.querySelector('path');
294
+ expect(path).toHaveAttribute('stroke', 'blue');
254
295
  });
255
296
  ```
256
297
 
@@ -277,7 +318,7 @@ screen.getByTestId('custom-component')
277
318
 
278
319
  // Query variants
279
320
  getBy* // Throws error if not found
280
- queryBy* // Returns null if not found
321
+ queryBy* // Returns null if not found
281
322
  findBy* // Async, waits for element to appear
282
323
  ```
283
324
 
@@ -306,7 +347,7 @@ screen.logTestingPlaygroundURL();
306
347
  ## 📊 Coverage Goals
307
348
 
308
349
  - **Statements**: 80%+
309
- - **Branches**: 80%+
350
+ - **Branches**: 80%+
310
351
  - **Functions**: 80%+
311
352
  - **Lines**: 80%+
312
353
 
@@ -315,7 +356,7 @@ Current coverage is low because we only have tests for a few components. Add tes
315
356
  ## 🚀 Next Steps
316
357
 
317
358
  1. **Add tests for remaining components** - Cover all components in the library
318
- 2. **Integration tests** - Test component interactions and workflows
359
+ 2. **Integration tests** - Test component interactions and workflows
319
360
  3. **Visual regression tests** - Consider adding Chromatic or similar tools
320
361
  4. **Performance tests** - Test rendering performance for complex components
321
362
  5. **Accessibility tests** - Add automated a11y testing
@@ -324,7 +365,6 @@ Current coverage is low because we only have tests for a few components. Add tes
324
365
 
325
366
  Happy testing! 🧪✨
326
367
 
327
-
328
368
  # Accessibility Utilities Usage Guide
329
369
 
330
370
  ## Overview
@@ -334,8 +374,10 @@ The `utils/accessibility.js` module provides safe, SSR-compatible utilities for
334
374
  ## Available Utilities
335
375
 
336
376
  ### `announceToScreenReader(message, priority, timeout)`
377
+
337
378
  Safe screen reader announcements using ARIA live regions.
338
- - **Parameters**:
379
+
380
+ - **Parameters**:
339
381
  - `message` (string): Message to announce
340
382
  - `priority` ('polite'|'assertive'): Announcement priority (default: 'polite')
341
383
  - `timeout` (number): Cleanup timeout in ms (default: 1000)
@@ -343,14 +385,18 @@ Safe screen reader announcements using ARIA live regions.
343
385
  - **SSR Safe**: Yes (returns no-op function)
344
386
 
345
387
  ### `createLiveRegion(priority)`
388
+
346
389
  Creates a persistent live region for multiple announcements.
390
+
347
391
  - **Parameters**:
348
392
  - `priority` ('polite'|'assertive'): Announcement priority (default: 'polite')
349
393
  - **Returns**: Object with `announce(message)` and `destroy()` methods
350
394
  - **SSR Safe**: Yes (returns no-op methods)
351
395
 
352
396
  ### `safeFocus(element, options)`
397
+
353
398
  Safely focuses an element with fallback handling.
399
+
354
400
  - **Parameters**:
355
401
  - `element` (HTMLElement|string): Element or selector to focus
356
402
  - `options` (object): Focus options (optional)
@@ -362,10 +408,12 @@ Safely focuses an element with fallback handling.
362
408
  ### ✅ Components Using Accessibility Utilities
363
409
 
364
410
  1. **Error.jsx**
411
+
365
412
  - Uses built-in ARIA live regions (no manual utilities needed)
366
413
  - Serves as example of proper component-level accessibility
367
414
 
368
415
  2. **Form.jsx**
416
+
369
417
  - **Updated**: Uses `safeFocus` for error field focusing
370
418
  - **Updated**: Uses `announceToScreenReader` for form validation announcements
371
419
  - **Location**: Lines 1-4 (imports), Line 184 (focus call)
@@ -377,21 +425,25 @@ Safely focuses an element with fallback handling.
377
425
  ### ✅ Stories Using Accessibility Utilities
378
426
 
379
427
  1. **Avatar.stories.js**
428
+
380
429
  - **Updated**: Replaced manual DOM manipulation with `announceToScreenReader`
381
430
  - **Removed**: 13 lines of unsafe DOM manipulation code
382
431
  - **Benefits**: SSR safety, consistent behavior, proper cleanup
383
432
 
384
433
  2. **AnimationGroup.stories.js**
434
+
385
435
  - **Updated**: Replaced manual DOM manipulation with `announceToScreenReader`
386
436
  - **Removed**: 15 lines of unsafe DOM manipulation code
387
437
  - **Benefits**: Better positioning, consistent ARIA attributes
388
438
 
389
439
  3. **AnimationToggle.stories.js**
440
+
390
441
  - **Updated**: Uses `safeFocus` for focus management
391
442
  - **Updated**: Uses `announceToScreenReader` for state announcements
392
443
  - **Benefits**: Safer focus operations, proper error handling
393
444
 
394
445
  4. **Card.stories.js**
446
+
395
447
  - **Updated**: Replaced manual DOM manipulation with `announceToScreenReader`
396
448
  - **Updated**: Uses `safeFocus` for ellipses menu focus management
397
449
  - **Removed**: 14 lines of duplicate DOM manipulation code
@@ -405,15 +457,18 @@ Safely focuses an element with fallback handling.
405
457
  ### 🔄 Potential Future Updates
406
458
 
407
459
  1. **AnimationToggle.jsx** (Component level)
460
+
408
461
  - Could use `safeFocus` for internal focus management
409
462
  - Currently relies on native focus which works well
410
463
 
411
464
  2. **Crud.jsx**
465
+
412
466
  - Has built-in screen reader announcements (lines 538-542)
413
467
  - Could potentially use `createLiveRegion` for efficiency with many operations
414
468
  - Current implementation is already quite good
415
469
 
416
470
  3. **Button.jsx**
471
+
417
472
  - Has comprehensive ARIA support
418
473
  - Focus management handled by browser - no updates needed
419
474
 
@@ -425,10 +480,11 @@ Safely focuses an element with fallback handling.
425
480
  ### ❓ Stories with Existing Accessibility Patterns
426
481
 
427
482
  1. **Crud.stories.js**
483
+
428
484
  - Has comprehensive ARIA live regions built into component
429
485
  - No manual DOM manipulation found - well implemented
430
486
 
431
- 2. **Button.stories.js**
487
+ 2. **Button.stories.js**
432
488
  - Uses component's built-in ARIA features
433
489
  - No manual screen reader code found - good as is
434
490
 
@@ -437,11 +493,13 @@ Safely focuses an element with fallback handling.
437
493
  ### ✅ When to Use These Utilities
438
494
 
439
495
  1. **Use `announceToScreenReader`** when:
496
+
440
497
  - Making dynamic announcements in Storybook stories
441
498
  - Announcing user actions or state changes
442
499
  - Providing feedback for asynchronous operations
443
500
 
444
501
  2. **Use `createLiveRegion`** when:
502
+
445
503
  - Making multiple announcements in succession
446
504
  - Need more control over announcement timing
447
505
  - Building components with frequent status updates
@@ -454,6 +512,7 @@ Safely focuses an element with fallback handling.
454
512
  ### ❌ When NOT to Use These Utilities
455
513
 
456
514
  1. **Don't use for**:
515
+
457
516
  - Form elements with native focus handling
458
517
  - Components with built-in ARIA live regions
459
518
  - Simple static content that doesn't need announcements
@@ -483,16 +542,19 @@ Safely focuses an element with fallback handling.
483
542
  ## Testing Recommendations
484
543
 
485
544
  ### Screen Reader Testing
545
+
486
546
  - Test with NVDA, JAWS, VoiceOver to verify announcements
487
547
  - Verify announcements work in different browser environments
488
548
  - Test SSR scenarios to ensure no client-side errors
489
549
 
490
- ### Focus Management Testing
550
+ ### Focus Management Testing
551
+
491
552
  - Test keyboard navigation flows
492
553
  - Verify focus indicators are visible
493
554
  - Test with dynamic content scenarios
494
555
 
495
556
  ### Cross-browser Testing
557
+
496
558
  - Verify utilities work across different browsers
497
559
  - Test in high contrast mode
498
560
  - Verify reduced motion preferences are respected
@@ -508,8 +570,6 @@ Safely focuses an element with fallback handling.
508
570
 
509
571
  This comprehensive integration ensures the UI library follows accessibility best practices while maintaining clean, maintainable code.
510
572
 
511
-
512
-
513
573
  # Deployment Guide
514
574
 
515
575
  This guide explains how to deploy the UI library to npm using the automated GitHub Actions workflow.
@@ -544,13 +604,13 @@ Ensure your `package.json` has:
544
604
 
545
605
  ```json
546
606
  {
547
- "name": "your-package-name",
548
- "version": "1.0.0",
549
- "main": "dist/index.js",
550
- "files": ["dist"],
551
- "scripts": {
552
- "build": "npm run build-command"
553
- }
607
+ "name": "your-package-name",
608
+ "version": "1.0.0",
609
+ "main": "dist/index.js",
610
+ "files": ["dist"],
611
+ "scripts": {
612
+ "build": "npm run build-command"
613
+ }
554
614
  }
555
615
  ```
556
616
 
@@ -572,6 +632,7 @@ git push origin v1.0.0
572
632
  ```
573
633
 
574
634
  The workflow will:
635
+
575
636
  1. ✅ Run all tests
576
637
  2. ✅ Build the library
577
638
  3. ✅ Publish to npm
@@ -595,6 +656,7 @@ Use this for immediate deployment or when you want to control the version bump:
595
656
  The deployment workflow performs these steps:
596
657
 
597
658
  ### 1. Testing Phase
659
+
598
660
  - ✅ Checkout code
599
661
  - ✅ Setup Node.js
600
662
  - ✅ Install dependencies
@@ -602,6 +664,7 @@ The deployment workflow performs these steps:
602
664
  - ✅ Generate coverage report
603
665
 
604
666
  ### 2. Build and Deploy Phase
667
+
605
668
  - ✅ Build the library
606
669
  - ✅ Version management
607
670
  - ✅ Verify build artifacts
@@ -611,17 +674,20 @@ The deployment workflow performs these steps:
611
674
  ## Monitoring Deployment
612
675
 
613
676
  ### Check GitHub Actions
677
+
614
678
  1. Go to Actions tab in your repository
615
679
  2. Click on the running/completed workflow
616
680
  3. Review logs for each step
617
681
  4. Verify success or investigate failures
618
682
 
619
683
  ### Verify NPM Publication
684
+
620
685
  1. Check [npmjs.com](https://www.npmjs.com/package/your-package-name)
621
686
  2. Verify the new version is available
622
687
  3. Test installation: `npm install your-package-name@latest`
623
688
 
624
689
  ### Test Installation
690
+
625
691
  ```bash
626
692
  # Create a test project
627
693
  mkdir test-installation && cd test-installation
@@ -639,24 +705,29 @@ node -e "console.log(require('your-package-name'))"
639
705
  ### Common Issues
640
706
 
641
707
  **❌ NPM_TOKEN not set**
708
+
642
709
  - Error: `npm ERR! need auth`
643
710
  - Solution: Verify the NPM_TOKEN secret is correctly configured
644
711
 
645
712
  **❌ Package name already exists**
713
+
646
714
  - Error: `npm ERR! 403 Forbidden`
647
715
  - Solution: Choose a unique package name or scope it (`@username/package-name`)
648
716
 
649
717
  **❌ Build failures**
718
+
650
719
  - Error: Various build errors
651
720
  - Solution: Run `npm run build` locally first to identify issues
652
721
 
653
722
  **❌ Test failures**
723
+
654
724
  - Error: Tests fail in CI
655
725
  - Solution: Ensure all tests pass locally with `npm test`
656
726
 
657
727
  ### Debug Steps
658
728
 
659
729
  1. **Local verification**:
730
+
660
731
  ```bash
661
732
  npm ci
662
733
  npm test
@@ -665,6 +736,7 @@ node -e "console.log(require('your-package-name'))"
665
736
  ```
666
737
 
667
738
  2. **Check workflow logs**:
739
+
668
740
  - Go to Actions → Failed workflow → Click on failed step
669
741
  - Review error messages and stack traces
670
742
 
@@ -676,17 +748,20 @@ node -e "console.log(require('your-package-name'))"
676
748
  ## Best Practices
677
749
 
678
750
  ### Version Management
751
+
679
752
  - Use semantic versioning (semver)
680
753
  - Document changes in CHANGELOG.md
681
754
  - Test thoroughly before releasing
682
755
 
683
756
  ### Quality Gates
757
+
684
758
  - All tests must pass
685
759
  - Code coverage maintained
686
760
  - Build artifacts verified
687
761
  - Documentation updated
688
762
 
689
763
  ### Release Notes
764
+
690
765
  - Use descriptive commit messages
691
766
  - Tag releases with clear version numbers
692
767
  - Maintain changelog for users
@@ -701,6 +776,7 @@ node -e "console.log(require('your-package-name'))"
701
776
  ## Support
702
777
 
703
778
  If you encounter issues:
779
+
704
780
  1. Check this guide first
705
781
  2. Review GitHub Actions logs
706
782
  3. Verify npm token permissions
@@ -228,7 +228,7 @@ $css-vars: (
228
228
  gray-700: $gray-700,
229
229
  gray-800: $gray-800,
230
230
  gray-900: $gray-900,
231
- black: $black,
231
+ 'black': $black,
232
232
  color-muted-blue: $color-muted-blue,
233
233
  heading-one: $heading-one,
234
234
  heading-two: $heading-two,
@@ -3,17 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _ScrollHandler = require("./ScrollHandler");
7
- Object.keys(_ScrollHandler).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _ScrollHandler[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _ScrollHandler[key];
14
- }
15
- });
16
- });
17
6
  var _useWindowSize = require("./useWindowSize");
18
7
  Object.keys(_useWindowSize).forEach(function (key) {
19
8
  if (key === "default" || key === "__esModule") return;
@@ -1,4 +1,3 @@
1
- export * from './ScrollHandler';
2
1
  export * from './useWindowSize';
3
2
  export * from './accessibility';
4
3
  export * from './validation';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abstraks-dev/ui-library",
3
- "version": "1.0.5",
3
+ "version": "1.1.5",
4
4
  "description": "User Interface library",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = require("react");
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _reactRouterDom = require("react-router-dom");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const ScrollHandler = ({
12
- location
13
- }) => {
14
- (0, _react.useEffect)(() => {
15
- const element = document.getElementById(location.hash);
16
- setTimeout(() => {
17
- window.scrollTo({
18
- behavior: element ? 'smooth' : 'auto',
19
- top: element ? element.offsetTop : 0
20
- });
21
- }, 100);
22
- }, [location]);
23
- return null;
24
- };
25
- ScrollHandler.propTypes = {
26
- location: _propTypes.default.shape({
27
- hash: _propTypes.default.string
28
- }).isRequired
29
- };
30
- var _default = exports.default = (0, _reactRouterDom.withRouter)(ScrollHandler);
@@ -1,26 +0,0 @@
1
- import { useEffect } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { withRouter } from 'react-router-dom';
4
-
5
- const ScrollHandler = ({ location }) => {
6
- useEffect(() => {
7
- const element = document.getElementById(location.hash);
8
-
9
- setTimeout(() => {
10
- window.scrollTo({
11
- behavior: element ? 'smooth' : 'auto',
12
- top: element ? element.offsetTop : 0,
13
- });
14
- }, 100);
15
- }, [location]);
16
-
17
- return null;
18
- };
19
-
20
- ScrollHandler.propTypes = {
21
- location: PropTypes.shape({
22
- hash: PropTypes.string,
23
- }).isRequired,
24
- };
25
-
26
- export default withRouter(ScrollHandler);