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

feat(Sheet): new component #840

Merged
merged 29 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e5d5039
WEB-1492 feat(BottomSheet): new component
atabel Aug 3, 2023
858f52b
Merge branch 'master' into atoledano-sheet
atabel Aug 3, 2023
7b36788
forwardRef and refactor ActionsBottomSheet
atabel Aug 4, 2023
d9995c3
desktop support
atabel Aug 4, 2023
99f4ca2
fix title divider logic
atabel Aug 4, 2023
81ff7b8
improve stories
atabel Aug 8, 2023
8b7f3d2
BottomSheetRoot
atabel Aug 10, 2023
046301b
tests
atabel Aug 11, 2023
03d6546
missing tests
atabel Aug 11, 2023
ca2b10e
Merge branch 'master' into atoledano-sheet
atabel Aug 11, 2023
45496e9
Merge branch 'master' into atoledano-sheet
atabel Aug 11, 2023
ee13795
Merge branch 'master' into atoledano-sheet
atabel Aug 21, 2023
b58d9f9
rename bottom sheet to just sheet
atabel Aug 21, 2023
b627dbd
fixes from CR
atabel Aug 21, 2023
b67663f
rename tests
atabel Aug 21, 2023
4cbd652
hover effect for close X
atabel Aug 21, 2023
bf064cb
fixes from cr
atabel Aug 21, 2023
853312f
snippets
atabel Aug 21, 2023
52fc6a3
add subtitle and description to info snippet
atabel Aug 21, 2023
fb9a4a8
fix bridge type
atabel Aug 22, 2023
515bd46
fix text
atabel Aug 22, 2023
00e2495
fix scrollbars in desktop]
atabel Aug 22, 2023
509ac2c
move specific sheet native methods from bridge to mistica
atabel Aug 22, 2023
1aad7a0
keep top padding in SheetBody when no title
atabel Aug 22, 2023
60cf078
link to doc in sheet story
atabel Aug 22, 2023
1c842d9
snippets
atabel Aug 23, 2023
87f8616
remove divider in desktop
atabel Aug 23, 2023
be5e558
Merge branch 'master' into atoledano-sheet
atabel Aug 23, 2023
355ae57
update snapshots
atabel Aug 24, 2023
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
133 changes: 133 additions & 0 deletions doc/sheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Sheet

Mística provides a sheet component that can be used to display a modal-like content from over the main content
of the screen.

## Basic usage

You can show any content you want inside the sheet by passing it as a child of the component.

```jsx
import {Sheet} from 'mistica';

const MyComponent = () => {
const [showSheet, setShowSheet] = useState(false);
return (
<>
<ButtonPrimary onPress={() => setShowSheet(true)}>show sheet</ButtonPrimary>
{showSheet && (
<Sheet onClose={() => setShowSheet(false)}>
<Placeholder />
</Sheet>
)}
</>
);
};
```

The sheet will close when the user does the swipe down gesture or when the background overlay is touched. The
`onClose` callback is called when the closing animation finishes, that's the right place to unmount the sheet
as shown in the example above.

You can also close the sheet programmatically using the render prop:

```jsx
import {Sheet} from 'mistica';

const MyComponent = () => {
const [showSheet, setShowSheet] = useState(false);
return (
<>
<ButtonPrimary onPress={() => setShowSheet(true)}>show sheet</ButtonPrimary>
{showSheet && (
<Sheet onClose={() => setShowSheet(false)}>
{({closeModal, modalTitleId}) => (
<>
<Title1 id={modalTitleId}>My sheet</Title1>
<Placeholder />
<ButtonPrimary onPress={closeModal}>Close</ButtonPrimary>
</>
)}
</Sheet>
)}
</>
);
};
```

## Sheet with predefined content

Mística predefines some common sheet patterns for you to use: `RadioListSheet`, `ActionsListSheet`,
`InfoSheet` and `ActionsSheet`. You can see examples in the storybook.

## `showSheet` imperative api

Instead of using React components, there is an alternative way to show a sheet: using the `showSheet`
function. For this to work, you need to render a `<SheetRoot/>` somewhere in your app, typically where you
render the mistica `<ThemeContextProvider/>`, but it could be anywhere.

```jsx
import {SheetRoot} from '@telefonica/mistica';

export const App = () => {
return (
<>
<SheetRoot />
<RestOfYourApp />
</>
);
};
```

Then you can call `showSheet` from anywhere:

```jsx
import {showSheet} from '@telefonica/mistica';

const MyComponent = () => {
return (
<ButtonPrimary
onPress={() =>
showSheet({
type: 'RADIO_LIST',
props: {
title: 'Select an fruit',
items: [
{id: '1', title: 'Apple'},
{id: '2', title: 'Banana'},
{id: '3', title: 'Orange'},
],
},
}).then((result) => {
// The promise is resolved when the sheet is closed
console.log(result);
})
}
>
show sheet
</ButtonPrimary>
);
};
```

### Native implementation

If you are using mistica inside Novum app, you can configure `showSheet` to use the native sheet
implementation with the webview bridge.

```jsx
import {SheetRoot} from '@telefonica/mistica';
import {bottomSheet, isWebViewBridgeAvailable} from '@tef-novum/webview-bridge';

export const App = () => {
return (
<>
<SheetRoot nativeImplementation={isWebViewBridgeAvailable() ? bottomSheet : undefined} />
<RestOfYourApp />
</>
);
};
```

Then when you call `showSheet`, if the code is running inside a webview, it will use the native implementation
instead of the web one.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@swc/core": "^1.3.61",
"@swc/jest": "^0.2.26",
"@telefonica/acceptance-testing": "2.13.0",
"@telefonica/eslint-config": "^1.6.0",
"@telefonica/eslint-config": "^1.7.0",
"@telefonica/prettier-config": "^1.1.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
Expand Down Expand Up @@ -143,7 +143,7 @@
},
"dependencies": {
"@juggle/resize-observer": "^3.3.1",
"@tef-novum/webview-bridge": "^3.8.0",
"@tef-novum/webview-bridge": "^3.27.0",
"@telefonica/libphonenumber": "^2.8.1",
"@vanilla-extract/css": "^1.9.5",
"@vanilla-extract/dynamic": "^2.0.3",
Expand Down
2 changes: 2 additions & 0 deletions playroom/frame-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../css/reset.css';
import * as React from 'react';
import {
ThemeContextProvider,
SheetRoot,
useModalState,
OverscrollColorProvider,
skinVars,
Expand Down Expand Up @@ -64,6 +65,7 @@ const FrameComponent = ({children, theme}: Props): React.ReactNode => (
<ThemeOverriderContextProvider>
{(overridenTheme) => (
<ThemeContextProvider theme={overridenTheme ?? theme}>
<SheetRoot />
<OverscrollColorProvider>
<App skinName={(overridenTheme ?? theme).skin.name}>{children}</App>
</OverscrollColorProvider>
Expand Down
Loading
Loading