Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plasma-*: Fix Sheet scroll #1273

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const StoryWithInsideScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down Expand Up @@ -296,7 +296,7 @@ const StoryWithDoubleScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down
4 changes: 2 additions & 2 deletions packages/plasma-b2c/src/components/Sheet/Sheet.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const StoryWithInsideScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down Expand Up @@ -296,7 +296,7 @@ const StoryWithDoubleScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down
8 changes: 4 additions & 4 deletions packages/plasma-new-hope/src/components/Sheet/Sheet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef } from 'react';
import React, { forwardRef, useRef } from 'react';

import { RootProps } from '../../engines';
import { Overlay } from '../Overlay';
Expand Down Expand Up @@ -44,9 +44,9 @@ export const sheetRoot = (Root: RootProps<HTMLDivElement, SheetProps>) =>
},
rootRef,
) => {
const contentWrapperRef = React.useRef<HTMLDivElement>(null);
const contentRef = React.useRef<HTMLDivElement>(null);
const handleRef = React.useRef<HTMLDivElement>(null);
const contentWrapperRef = useRef<HTMLDivElement>(null);
const contentRef = useRef<HTMLDivElement>(null);
const handleRef = useRef<HTMLDivElement>(null);

useOverflow({ opened });
useSheetSwipe({ contentWrapperRef, contentRef, handleRef, throttleMs, onClose });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode, HTMLAttributes } from 'react';
import type { ReactNode, HTMLAttributes } from 'react';

export interface SheetProps extends HTMLAttributes<HTMLDivElement> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const StoryWithInsideScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down Expand Up @@ -296,7 +296,7 @@ const StoryWithDoubleScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const StoryWithInsideScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down Expand Up @@ -296,7 +296,7 @@ const StoryWithDoubleScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down
4 changes: 2 additions & 2 deletions packages/plasma-web/src/components/Sheet/Sheet.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const StoryWithInsideScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down Expand Up @@ -296,7 +296,7 @@ const StoryWithDoubleScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down
4 changes: 2 additions & 2 deletions packages/sdds-serv/src/components/Sheet/Sheet.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const StoryWithInsideScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down Expand Up @@ -296,7 +296,7 @@ const StoryWithDoubleScroll = ({
<div
style={{
height: '150px',
overflow: 'scroll',
overflowY: 'scroll',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
Expand Down
139 changes: 139 additions & 0 deletions website/caldera-online-docs/docs/components/Sheet.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
id: sheet
title: Sheet
---

import { PropsTable, Description } from '@site/src/components';

# Sheet
<Description name="Sheet" />
<PropsTable name="Sheet" />

## Использование
Компонент `Sheet` может содержать любой контент напрямую через `children`.

Также есть возможность добавить любой контент в заголовок и футер с помощью свойств `contentHeader` и `contentFooter`.

```tsx live
import React, { useState } from 'react';
import { Sheet, Button } from '@salutejs/caldera-online';

export function App() {
const [opened, setOpened] = useState(false);

return (
<>
<Button onClick={() => setOpened(true)}>Открыть</Button>

<Sheet opened={opened}
onClose={() => setOpened(false)}
contentHeader={
<div>
<h4>header</h4>
</div>
}
contentFooter={
<div>
<p>footer</p>
</div>
}
>
<div style={{ 'padding-bottom': '300px' }}>body</div>
</Sheet>
</>
);
}
```

## Примеры

### Закрепление заголовка и футера

С помощью свойств `isHeaderFixed` и `isFooterFixed` можно закрепить заголовок и футер.
В этом случае при появлении прокрутки контент будет скроллится под них.

```tsx live
import React, { useState } from 'react';
import { Sheet, Button } from '@salutejs/caldera-online';

export function App() {
const [opened, setOpened] = useState(false);

return (
<>
<Button onClick={() => setOpened(true)}>Открыть</Button>
<Sheet opened={opened}
onClose={() => setOpened(false)}
contentHeader={
<div>
<h4>header</h4>
</div>
}
contentFooter={
<div>
<p>footer</p>
</div>
}
isFooterFixed
isHeaderFixed
>
<div style={{ 'padding-bottom': '300px' }}>body</div>
</Sheet>
</>
);
}
```

### Подложка

Наличие или отсутствие подложки задается с помощью свойства `withOverlay`.

В случае, когда подложка отсутствует, у пользователя появляется возможность взаимодействовать с контентом вне шторки.

```tsx live
import React, { useState } from 'react';
import { Sheet, Button } from '@salutejs/caldera-online';

export function App() {
const [opened, setOpened] = useState(false);

return (
<>
<Button onClick={() => setOpened(!opened)}>
{opened ? 'Закрыть' : 'Открыть'}
</Button>
<Sheet opened={opened}
onClose={() => setOpened(false)}
withOverlay={false}
>
<div style={{ 'padding-bottom': '300px' }}>body</div>
</Sheet>
</>
);
}
```

К подложке можно добавить эффект размытия при помощи свойства `withBlur`.

```tsx live
import React, { useState } from 'react';
import { Sheet, Button } from '@salutejs/caldera-online';

export function App() {
const [opened, setOpened] = useState(false);

return (
<>
<Button onClick={() => setOpened(!opened)}>
{opened ? 'Закрыть' : 'Открыть'}
</Button>
<Sheet opened={opened}
onClose={() => setOpened(false)}
withBlur
>
<div style={{ 'padding-bottom': '300px' }}>body</div>
</Sheet>
</>
);
}
```
Loading