Skip to content

Commit

Permalink
refactor(modal): remove lodash (#244)
Browse files Browse the repository at this point in the history
* refactor(modal): remove lodash

* chore: add changeset
  • Loading branch information
Niznikr authored Aug 2, 2022
1 parent 1835250 commit f2c8830
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .changeset/swift-rules-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@launchpad-ui/modal': patch
'@launchpad-ui/core': patch
---

[Modal] Remove lodash
9 changes: 3 additions & 6 deletions .storybook/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { ArgsStoryFn } from '@storybook/addons';
import type { Args } from '@storybook/api';
import type { StoryContext } from '@storybook/csf';
// @ts-ignore
import type { DecoratorFn, ReactFramework } from '@storybook/react';
import type { DecoratorFn, ReactFramework, StoryFn } from '@storybook/react';
import { Fragment } from 'react';
import { cloneDeep } from 'lodash-es';

Expand All @@ -15,7 +14,7 @@ export const createWithClassesDecorator = (
classes: string[] = [],
renderFunc?: (
props: Args & { className?: string },
originalStoryFn: ArgsStoryFn<React.ReactElement<unknown>>,
originalStoryFn: StoryFn<ReactFramework>,
context: StoryContext<ReactFramework>
) => JSX.Element
): DecoratorFn => {
Expand All @@ -24,9 +23,7 @@ export const createWithClassesDecorator = (
const pseudoStates = classes || [];
const { viewMode, args, name, component } = Context;
// This decorator is explicitly made for react
const originalStoryFn = Context.originalStoryFn as
| ArgsStoryFn<React.ReactElement<unknown>>
| undefined;
const originalStoryFn = Context.originalStoryFn;
// Just render the component without decoration if viewing the docs
if (viewMode === 'docs') {
return storyFn();
Expand Down
2 changes: 0 additions & 2 deletions packages/modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@
"@react-aria/focus": "^3.7.0",
"clsx": "^1.2.0",
"framer-motion": "^6.5.1",
"lodash-es": "^4.17.21",
"no-scroll": "^2.1.1"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"devDependencies": {
"@types/lodash-es": "^4.17.6",
"@types/no-scroll": "^2.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
5 changes: 2 additions & 3 deletions packages/modal/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Close, IconSize } from '@launchpad-ui/icons';
import { FocusScope } from '@react-aria/focus';
import cx from 'clsx';
import { LazyMotion, m } from 'framer-motion';
import { defer } from 'lodash-es';
import noScroll from 'no-scroll';
import { useEffect, useRef } from 'react';

Expand Down Expand Up @@ -72,13 +71,13 @@ const Modal = ({
onCancel && onCancel();
};

defer(noScroll.on);
setTimeout(noScroll.on, 1);
onReady && onReady();
document.body.classList.add('has-modal');
document.addEventListener('keydown', handleEscape);

return () => {
defer(noScroll.off);
setTimeout(noScroll.off, 1);
document.body.classList.remove('has-modal');
document.removeEventListener('keydown', handleEscape);
};
Expand Down
4 changes: 0 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f2c8830

Please sign in to comment.