Skip to content

Commit a6e580b

Browse files
author
mohit
committed
🌟v1.0.9 + added custom transition logic
1 parent 91e12fa commit a6e580b

8 files changed

Lines changed: 48 additions & 29 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ActionSheet-React
22

33
[![Size](https://badgen.net/bundlephobia/minzip/actionsheet-react)](https://bundlephobia.com/result?p=actionsheet-react)
4-
[![npm](https://badgen.net//npm/v/actionsheet-react)](https://bundlephobia.com/result?p=actionsheet-react)
4+
[![npm](https://badgen.net//npm/v/actionsheet-react)](https://www.npmjs.com/package/actionsheet-react)
55

66
An action sheet component for react.
77

@@ -10,8 +10,11 @@ Action Sheet is a component that slides in from bottom and has some list of acti
1010

1111
### 📺 Demo
1212

13-
[code-sandbox link](https://codesandbox.io/s/actionsheet-react-2s5zf)
13+
![demo gif](https://s7.gifyu.com/images/demo_action_sheet.gif)
1414

15+
[code-sandbox simple example](https://codesandbox.io/s/actionsheet-react-2s5zf)
16+
17+
[code-sandbox complex example](https://codesandbox.io/s/actionsheet-react-example-1-0nok0)
1518

1619
### 📦 Installation
1720

@@ -103,19 +106,20 @@ const MyComponent = () => {
103106
| touchEnable | boolean | if true, the sheet can be swiped down on touch devices |
104107
| threshold | number | the minimum distance dragged, so that sheet will slide down. Threshold is measured in **px** , default value is 50 |
105108
| zIndex | number | the default value is **999** |
106-
| closeOnBgTap | Boolean | if true, the sheet is closed when the backgroud overlay is tapped |
107-
109+
| closeOnBgTap | boolean | if true, the sheet is closed when the backgroud overlay is tapped |
110+
| sheetTransition | string | css transition shorthand, default value `all 0.3s ease-in-out` |
111+
| bgTransition | string | css transition shorthand, default value `all 0.5s ease-in-out` |
108112
109113
### 👾 Misc
110114
111-
1. The logic to stop the backgroud from scrolling is not implemented in this package just to keep it simple. To avoid the background from scrolling you can toggle the overflow property of the body tag, you can also use some other way of your choice
115+
1. The logic to stop the backgroud from scrolling is not implemented in this package just to keep it simple. To avoid the background from scrolling you can toggle the overflow property of the body tag, or you can also use some other way of your choice
112116
113117
```javascript
114118
document.body.style.overflow = 'hidden'
115119
document.body.style.overflow = 'auto'
116120
```
117121
118-
2. Mobile browsers generally have pull-to-refresh and when out bottom sheet is open and user drags the sheet down but eventually the browser detects the swipe down gesture and triggers its pull-to-refresh. To control this behavior in Chrome i did this
122+
2. Mobile browsers generally have pull-to-refresh and when action sheet is open and when user drags the sheet down the pull-to-refresh is triggered. To control this behavior either you can disable swipe in action sheet `touchEnable={false}` or you can disable pull-to-refresh.
119123
120124
```css
121125
body{

‎build/index.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface ActionSheetProps {
1111
opacity?: number;
1212
zIndex?: number;
1313
closeOnBgTap?: boolean;
14+
bgTransition?: string;
15+
sheetTransition?: string;
1416
}
1517
export interface ActionSheetRef {
1618
open(): void;

‎build/index.es.js‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/index.es.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/index.js‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/index.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "actionsheet-react",
3-
"version": "1.0.8",
4-
"description": "🌟An awesome react actionsheet component for the web",
3+
"version": "1.0.9",
4+
"description": "🌟A lightweight and flexible action sheet component for the web",
55
"main": "build/index.js",
66
"module": "build/index.es.js",
77
"jsnext:main": "build/index.es.js",
@@ -31,12 +31,10 @@
3131
"test": "echo \"Error: no test specified\" && exit 1"
3232
},
3333
"keywords": [
34-
"react",
34+
"react panel",
3535
"actionsheet",
36-
"web",
37-
"action",
38-
"bottom",
39-
"sheet"
36+
"bottom sheet",
37+
"slide up panel"
4038
],
4139
"author": "mohit23x",
4240
"license": "ISC",

‎src/index.tsx‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,29 @@ export interface ActionSheetProps {
1212
opacity?: number
1313
zIndex?: number
1414
closeOnBgTap?: boolean
15+
bgTransition?: string
16+
sheetTransition?: string
1517
}
1618

1719
export interface ActionSheetRef {
1820
open (): void
1921
close (): void
2022
}
2123

22-
const Comp: React.RefForwardingComponent<ActionSheetRef, ActionSheetProps> = (({ onClose, children, sheetStyle, bgStyle, mouseEnable=true, touchEnable=true, threshold=50, opacity=1, zIndex=998, closeOnBgTap=true }, ref):JSX.Element => {
24+
const Comp: React.RefForwardingComponent<ActionSheetRef, ActionSheetProps> = (({
25+
onClose,
26+
children,
27+
sheetStyle,
28+
bgStyle,
29+
mouseEnable = true,
30+
touchEnable = true,
31+
threshold = 50,
32+
opacity = 1,
33+
zIndex = 998,
34+
closeOnBgTap = true,
35+
bgTransition = "all 0.5s ease-in-out",
36+
sheetTransition="all 0.3s ease-in-out"
37+
}, ref): JSX.Element => {
2338
const [show, setShow] = useState(false);
2439
const [pressed, setPressed] = useState(false)
2540
const sheetRef = useRef<HTMLDivElement>(null);
@@ -136,9 +151,9 @@ const Comp: React.RefForwardingComponent<ActionSheetRef, ActionSheetProps> = (({
136151
right: 0,
137152
bottom: 0,
138153
background: "rgba(0, 0, 0, 0.8)",
139-
transition: "all 0.5s ease",
140154
backfaceVisibility: "hidden",
141155
...bgStyle,
156+
transition: bgTransition,
142157
opacity: show ? opacity : 0,
143158
zIndex: show ? zIndex : -1}}>
144159
</div>
@@ -156,14 +171,14 @@ const Comp: React.RefForwardingComponent<ActionSheetRef, ActionSheetProps> = (({
156171
transform: "translate3d(0, 101%, 0)",
157172
...sheetStyle,
158173
zIndex: zIndex + 1,
159-
transition: pressed ? "all 0.05s linear" : "all 0.3s ease-in-out" }}
174+
transition: pressed ? "all 0.05s linear" : sheetTransition }}
160175
onMouseDown={mouseEnable? onMouseStart : undefined}
161176
onMouseMove={mouseEnable? onMouseMove : undefined}
162177
onMouseUp={mouseEnable ? onSwipeEnd: undefined}
163178
onTouchStart={touchEnable? onSwipeStart: undefined}
164179
onTouchMove={touchEnable? onSwipeMove: undefined}
165180
onTouchEnd={touchEnable? onSwipeEnd: undefined}>
166-
{children? children : <div style={{height: 100}} />}
181+
{children? children : <div style={{height: 150}} />}
167182
</div>
168183
</Fragment>
169184
)

0 commit comments

Comments
 (0)