-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(utils): restructure browser related utils
- Loading branch information
Showing
33 changed files
with
65 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/lumx-react/src/components/popover/useRestoreFocusOnClose.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/lumx-react/src/components/slideshow/useSlideFocusManagement.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ls/focus/getFirstAndLastFocusable.test.ts → ...er/focus/getFirstAndLastFocusable.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../utils/focus/getFocusableElements.test.ts → ...rowser/focus/getFocusableElements.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions
10
.../utils/browserDoesNotSupportHover.test.js → ...utils/browser/isHoverNotSupported.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import { browserDoesNotSupportHover } from '@lumx/react/utils/browserDoesNotSupportHover'; | ||
import { isHoverNotSupported } from './isHoverNotSupported'; | ||
|
||
const originalMatchMedia = global.matchMedia; | ||
|
||
describe('browserDoesNotSupportHover', () => { | ||
describe('isHoverNotSupported', () => { | ||
afterAll(() => { | ||
global.matchMedia = originalMatchMedia; | ||
}); | ||
|
||
it('should return `false` on browsers that do not support matchMedia', () => { | ||
global.matchMedia = undefined; | ||
expect(browserDoesNotSupportHover()).toBe(false); | ||
expect(isHoverNotSupported()).toBe(false); | ||
}); | ||
|
||
it('should return `false` on browsers that support matchMedia and does support hover', () => { | ||
global.matchMedia = () => ({ matches: false }); | ||
expect(browserDoesNotSupportHover()).toBe(false); | ||
expect(isHoverNotSupported()).toBe(false); | ||
}); | ||
|
||
it('should return `true` on browsers that support matchMedia and does not support hover', () => { | ||
global.matchMedia = () => ({ matches: true }); | ||
expect(browserDoesNotSupportHover()).toBe(true); | ||
expect(isHoverNotSupported()).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/** Return true if the browser does not support pointer hover */ | ||
export const isHoverNotSupported = (): boolean => !!window.matchMedia?.('(hover: none)').matches; |
2 changes: 1 addition & 1 deletion
2
.../utils/browser/getPrefersReducedMotion.ts → ...eact/src/utils/browser/isReducedMotion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { WINDOW } from '@lumx/react/constants'; | ||
|
||
/** Check if user prefers reduced motion */ | ||
export function getPrefersReducedMotion() { | ||
export function isReducedMotion() { | ||
return WINDOW?.matchMedia?.('(prefers-reduced-motion: reduce)').matches; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import partition from 'lodash/partition'; | ||
import { partitionMulti } from './partitionMulti'; | ||
|
||
describe('partitionMulti', () => { | ||
it('should act like partition for single predicate', () => { | ||
const data = [0, 1, 2, 3, 4, 5]; | ||
const isEven = (n: number): boolean => n % 2 === 0; | ||
|
||
const expected = partition(data, isEven); | ||
const actual = partitionMulti(data, [isEven]); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should partition on multiple predicates', () => { | ||
type T = string | number | boolean; | ||
const data: T[] = ['a', 1, 'b', false, true]; | ||
const isString = (s: T): boolean => typeof s === 'string'; | ||
const isNumber = (s: T): boolean => typeof s === 'number'; | ||
|
||
const [strings, numbers, others] = partitionMulti(data, [isString, isNumber]); | ||
|
||
expect(strings).toEqual(['a', 'b']); | ||
expect(numbers).toEqual([1]); | ||
expect(others).toEqual([false, true]); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.