Skip to content

Commit 0b5b59b

Browse files
committed
minor refactor with reverse support
1 parent 7533fd8 commit 0b5b59b

12 files changed

Lines changed: 9345 additions & 14462 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
example

README.md

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
An action sheet component for react.
77

88
#### What is an action sheet ?
9+
910
Action Sheet is a component that slides in from bottom and has some list of action for the user. Mostly action sheets are used in native mobile application, but action sheet is a very helpful UI element which can be also be used in websites and PWA.
1011

11-
### 📺 Demo
12+
### 📺 Demo
1213

1314
![demo gif](https://s7.gifyu.com/images/demo_action_sheet.gif)
1415

@@ -30,102 +31,94 @@ npm i actionsheet-react
3031
yarn add actionsheet-react
3132
```
3233

33-
3434
### 👨‍💻 Usage
3535

3636
##### Sample code using Javascript
3737

38-
3938
```javascript
40-
import React, {useRef, Fragment} from 'react'
41-
import ActionSheet from 'actionsheet-react'
39+
import React, { useRef, Fragment } from "react";
40+
import ActionSheet from "actionsheet-react";
4241

4342
const MyComponent = () => {
4443
const ref = useRef();
4544

4645
const handleOpen = () => {
4746
ref.current.open();
48-
}
47+
};
4948

5049
const handleClose = () => {
5150
ref.current.close();
52-
}
53-
54-
return(
51+
};
52+
53+
return (
5554
<Fragment>
56-
<button onClick={handleOpen}>
57-
Open
58-
</button>
59-
<button onClick={handleClose}>
60-
Close
61-
</button>
55+
<button onClick={handleOpen}>Open</button>
56+
<button onClick={handleClose}>Close</button>
6257
<ActionSheet ref={ref}>
63-
<div style={style.content}>
64-
🙂 Hi React Devs!
65-
</div>
58+
<div style={style.content}>🙂 Hi React Devs!</div>
6659
</ActionSheet>
6760
</Fragment>
68-
)
69-
}
61+
);
62+
};
7063

7164
const style = {
7265
content: {
7366
height: 300,
74-
display: 'flex',
75-
justifyContent: 'center',
76-
alignItems: 'center'
77-
}
78-
}
79-
67+
display: "flex",
68+
justifyContent: "center",
69+
alignItems: "center",
70+
},
71+
};
8072
```
8173

8274
##### Sample code using Typescript
8375

84-
8576
```typescript
8677
import ActionSheet, {ActionSheetRef} from 'actionsheet-react';
8778

8879
const MyComponent = () => {
8980
const ref = useRef<ActionSheetRef>();
90-
81+
9182
// ...rest same as above code
9283

9384
```
9485
9586
### 🌮 Props
9687
97-
##### all props are optional
98-
99-
| property name | type | more info |
100-
| --- | --- | --- |
101-
| onClose | callback function | called when the actionsheet is closed |
102-
| children | React Children | all the fancy HTML elements that you want to show in the menu |
103-
| bgStyle | css styles object | these styles are applied to the background black overlay|
104-
|sheetStyle | css styles object | these styles are applied to the sheet component |
105-
| mouseEnable | boolean | if true, the sheet can be dragged down using mouse |
106-
| touchEnable | boolean | if true, the sheet can be swiped down on touch devices |
107-
| threshold | number | the minimum distance dragged, so that sheet will slide down. Threshold is measured in **px** , default value is 50 |
108-
| zIndex | number | the default value is **999** |
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` |
88+
##### all props are optional
89+
90+
| property name | type | more info |
91+
| --------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------ |
92+
| onClose | callback function | called when the actionsheet is closed |
93+
| children | React Children | all the fancy HTML elements that you want to show in the menu |
94+
| bgStyle | css styles object | these styles are applied to the background black overlay |
95+
| sheetStyle | css styles object | these styles are applied to the sheet component |
96+
| mouseEnable | boolean | if true, the sheet can be dragged down using mouse |
97+
| touchEnable | boolean | if true, the sheet can be swiped down on touch devices |
98+
| threshold | number | the minimum distance dragged, so that sheet will slide down. Threshold is measured in **px** , default value is 50 |
99+
| zIndex | number | the default value is **999** |
100+
| closeOnBgTap | boolean | if true, the sheet is closed when the background overlay is tapped |
101+
| reverse | boolean | open the sheet in reverse direction |
102+
| sheetTransition | string | css transition shorthand, default value `transform 0.3s ease-in-out` |
103+
| bgTransition | string | css transition shorthand, default value `opacity 0.5s ease-in-out, z-index 0.5s ease-in-out` |
112104
113105
### 👾 Misc
114106
115107
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
116108
117109
```javascript
118-
document.body.style.overflow = 'hidden'
119-
document.body.style.overflow = 'auto'
110+
document.body.style.overflow = "hidden";
111+
document.body.style.overflow = "auto";
120112
```
121113
122114
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.
123115
124116
```css
125-
body{
126-
overscroll-behavior: contain;
117+
body {
118+
overscroll-behavior: contain;
127119
}
128120
```
129121
130122
### ⛳ Issues/Feature Request/Pull Request
123+
131124
The github repo is always there for you.

build/index.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as React from 'react';
2-
import { ReactNode } from 'react';
1+
import * as React from "react";
2+
import { ReactNode } from "react";
33
export interface ActionSheetProps {
44
onClose?: () => void;
55
children?: ReactNode;
@@ -13,10 +13,11 @@ export interface ActionSheetProps {
1313
closeOnBgTap?: boolean;
1414
bgTransition?: string;
1515
sheetTransition?: string;
16+
reverse?: boolean;
1617
}
1718
export interface ActionSheetRef {
1819
open(): void;
1920
close(): void;
2021
}
21-
declare const ActionSheet: React.ForwardRefExoticComponent<ActionSheetProps & React.RefAttributes<ActionSheetRef>>;
22+
declare const ActionSheet: React.ForwardRefExoticComponent<ActionSheetProps & React.RefAttributes<ActionSheetRef | undefined>>;
2223
export default ActionSheet;

build/index.es.js

Lines changed: 53 additions & 27 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.

0 commit comments

Comments
 (0)