Skip to content

Commit 9581a69

Browse files
authored
chore: restructure readme (#199)
1 parent d6f53c7 commit 9581a69

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,94 @@
88

99
**react-spring-bottom-sheet** is built on top of **[react-spring]** and **[react-use-gesture]**. It busts the myth that accessibility and supporting keyboard navigation and screen readers are allegedly at odds with delightful, beautiful, and highly animated UIs. Every animation and transition use CSS custom properties instead of manipulating them directly, allowing complete control over the experience from CSS alone.
1010

11-
# Install
11+
# Installation
1212

1313
```bash
1414
npm i react-spring-bottom-sheet
1515
```
1616

17+
# Getting started
18+
19+
## Basic usage
20+
21+
```jsx
22+
import { useState } from 'react'
23+
import { BottomSheet } from 'react-spring-bottom-sheet'
24+
25+
// if setting up the CSS is tricky, you can add this to your page somewhere:
26+
// <link rel="stylesheet" href="https://unpkg.com/react-spring-bottom-sheet/dist/style.css" crossorigin="anonymous">
27+
import 'react-spring-bottom-sheet/dist/style.css'
28+
29+
export default function Example() {
30+
const [open, setOpen] = useState(false)
31+
return (
32+
<>
33+
<button onClick={() => setOpen(true)}>Open</button>
34+
<BottomSheet open={open}>My awesome content here</BottomSheet>
35+
</>
36+
)
37+
}
38+
```
39+
40+
## TypeScript
41+
42+
TS support is baked in, and if you're using the `snapTo` API use `BottomSheetRef`:
43+
44+
```tsx
45+
import { useRef } from 'react'
46+
import { BottomSheet, BottomSheetRef } from 'react-spring-bottom-sheet'
47+
48+
export default function Example() {
49+
const sheetRef = useRef<BottomSheetRef>()
50+
return (
51+
<BottomSheet open ref={sheetRef}>
52+
<button
53+
onClick={() => {
54+
// Full typing for the arguments available in snapTo, yay!!
55+
sheetRef.current.snapTo(({ maxHeight }) => maxHeight)
56+
}}
57+
>
58+
Expand to full height
59+
</button>
60+
</BottomSheet>
61+
)
62+
}
63+
```
64+
65+
## Customizing the CSS
66+
67+
### Using CSS Custom Properties
68+
69+
These are all the variables available to customize the look and feel when using the [provided](/src/style.css) CSS.
70+
71+
```css
72+
:root {
73+
--rsbs-backdrop-bg: rgba(0, 0, 0, 0.6);
74+
--rsbs-bg: #fff;
75+
--rsbs-handle-bg: hsla(0, 0%, 0%, 0.14);
76+
--rsbs-max-w: auto;
77+
--rsbs-ml: env(safe-area-inset-left);
78+
--rsbs-mr: env(safe-area-inset-right);
79+
--rsbs-overlay-rounded: 16px;
80+
}
81+
```
82+
83+
### Custom CSS
84+
85+
It's recommended that you copy from [style.css](/src/style.css) into your own project, and add this to your `postcss.config.js` setup (`npm i postcss-custom-properties-fallback`):
86+
87+
```js
88+
module.exports = {
89+
plugins: {
90+
// Ensures the default variables are available
91+
'postcss-custom-properties-fallback': {
92+
importFrom: require.resolve('react-spring-bottom-sheet/defaults.json'),
93+
},
94+
},
95+
}
96+
```
97+
98+
1799
# [Demos](https://react-spring-bottom-sheet.cocody.dev/)
18100

19101
## [Basic](https://react-spring-bottom-sheet.cocody.dev/fixtures/simple)
@@ -40,7 +122,6 @@ If you provide either a `header` or `footer` prop you'll enable the special beha
40122
41123
In most cases you use a bottom sheet the same way you do with a dialog: you want it to overlay the page and block out distractions. But there are times when you want a bottom sheet but without it taking all the attention and overlaying the entire page. Providing `blocking={false}` helps this use case. By doing so you disable a couple of behaviors that are there for accessibility (focus-locking and more) that prevents a screen reader or a keyboard user from accidentally leaving the bottom sheet.
42124

43-
# [Get started](/GET_STARTED.md)
44125

45126
# API
46127

0 commit comments

Comments
 (0)