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

feat(Sheet): new component #840

merged 29 commits into from
Aug 24, 2023

Conversation

@atabel atabel changed the title WEB-1492 feat(BottomSheet): new component feat(BottomSheet): new component Aug 3, 2023
@github-actions
Copy link

github-actions bot commented Aug 3, 2023

Size stats

master this branch diff
Total JS 9.42 MB 9.45 MB +36.4 kB
JS without icons 915 kB 951 kB +36 kB
Lib overhead 127 kB 128 kB +417 B
Lib overhead (gzip) 32.9 kB 33 kB +100 B

@github-actions
Copy link

github-actions bot commented Aug 3, 2023

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-hr3e49gef-tuentisre.vercel.app

Built with commit 355ae57.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link

github-actions bot commented Aug 3, 2023

Accessibility report
✔️ No issues found

ℹ️ You can run this locally by executing yarn audit-accessibility.

<>
<ButtonPrimary onPress={() => setShowSheet(true)}>show bottom sheet</ButtonPrimary>
{showSheet && (
<BottomSheet onClose={() => setShowSheet(false)}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that onClose is called when the closing animation finishes, so the idea is not unmounting the component until the transition finishes, that's why I set showSheet to false in onClose handler instead of ButtonPrimary onPress handler

Mística predefines some common bottom sheet patterns for you to use: `RadioListBottomSheet`,
`ActionsListBottomSheet`, `InfoBottomSheet` and `ActionsBottomSheet`. You can see examples in the storybook.

## `showBottomSheet` imperative api
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this equivalent to the confirm(), alert() methods we have for dialogs

export const App = () => {
return (
<>
<BottomSheetRoot />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided to not include this automatically inside ThemeContextProvider to allow webs using mistica to optin to use this. The advantage is that we don't bloat webs with all sheet components JS code if they are not going to use it. Also, it isn't needed to use BottomSheetRoot if you don't wan't to use the imperative api

import {BottomSheetRoot} from '@telefonica/mistica';
import * as webviewBridge from '@tef-novum/webview-bridge';

const nativeImplementation = createNativeSheetImplementationFromWebviewBridge(webviewBridge);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this approach, mistica doesn't need to depend on webview bridge lib, because the native implementation is injected, not imported. I think we could follow a similar approach for alert() confirm() or other components using the bridge. That would allow us to remove the "@tef-novum/webview-bridge" dependency from mistica package.json

Copy link
Member

@pladaria pladaria Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should be able to inject the bridge function "as is" to the Root component.

Something like:

import {openBottomSheet} from '@tef-novum/webview-bridge`;

<BottomSheetRoot nativeImplementation={openBottomSheet} />

and the nativeImplementation prop would be typed as typeof openBottomSheet;

This way everything is tied, types are verified at compile time and we won't need a createNativeSheetImplementationFromWebviewBridge.

Perhaps the bridge dependency could be listed as optionalDependency. I think it would be a problem to fully decouple both implementations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm... I see your point, but that would mean I'd need to re-implement the specific sheet methods in mistica (bottomSheetSingleSelector, bottomSheetActionSelector, bottomSheetInfo, bottomSheetActions)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I've moved these specific sheet methods from the bridge lib to mistica and removed them from webview-bridge (Telefonica/webview-bridge#115)

@atabel atabel marked this pull request as ready for review August 11, 2023 11:16
doc/bottomSheet.md Outdated Show resolved Hide resolved
src/__stories__/bottom-sheet-story.tsx Outdated Show resolved Hide resolved
src/bottom-sheet.tsx Outdated Show resolved Hide resolved
playroom/frame-component.tsx Outdated Show resolved Hide resolved
src/__stories__/bottom-sheet-story.tsx Outdated Show resolved Hide resolved
src/bottom-sheet.tsx Outdated Show resolved Hide resolved
doc/bottomSheet.md Outdated Show resolved Hide resolved
doc/bottomSheet.md Outdated Show resolved Hide resolved
Comment on lines 30 to 74
type SheetPropsByType = {
RADIO_LIST: SheetProps<{
selectedId?: string;
items: Array<{
id: string;
title?: string;
description?: string;
icon?: {
size?: 'small' | 'large';
url: string;
urlDark?: string;
};
}>;
}>;
ACTIONS_LIST: SheetProps<{
items: Array<{
id: string;
title: string;
style?: 'normal' | 'destructive';
icon?: {
url: string;
urlDark?: string;
};
}>;
}>;
INFO: SheetProps<{
items: Array<{
id: string;
title: string;
description?: string;
icon: InfoIcon;
}>;
}>;
ACTIONS: SheetProps<{
button: {
text: string;
};
secondaryButton?: {
text: string;
};
link?: {
text: string;
withChevron?: boolean;
};
}>;
Copy link
Member

@pladaria pladaria Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this could be imported from the bridge, which should be the source of truth for this kind of components

>
{React.Children.map(children, (child) => (
<div>{child}</div>
<div role={role === 'list' ? 'listitem' : undefined}>{child}</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

transform: 'scale(1)',
transform: 'none',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what motivated this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scale(1) creates a new stacking context, that was affecting zindex inside sheet

src/bottom-sheet.tsx Outdated Show resolved Hide resolved

isDraggingRef.current = false;
setDragDistance(0);
if (dragDistance > 50 && (currentYRef.current > window.innerHeight * 0.75 || dragSpeed > 0.5)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe 0.50 would be a better threshold (to close it you must drag a distance >= half the height)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been playing and I think the current values feel more natural, give it a try

src/bottom-sheet.tsx Outdated Show resolved Hide resolved
@atabel
Copy link
Collaborator Author

atabel commented Aug 21, 2023

Should we take into account a scenario in which the content overlaps with the close button? Playroom example

image

I don't think so. It's already managed by SheetBody. And if someone needs some special sheet behavior, it's their responsibility to use proper paddings to no overlap with the close button.

Copy link
Collaborator

@marcoskolodny marcoskolodny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using chrome iOS, it looks like when I scroll the sheet's content, it assumes I'm scrolling the sheet itself, but just for a few milliseconds. After that, it starts scrolling the content.

This happens only sometimes, seems unstable. I used this snippet in Playroom.

I couldn't reproduce this issue in desktop/android devices.

IMG_5784.MP4

@atabel
Copy link
Collaborator Author

atabel commented Aug 22, 2023

Using chrome iOS, it looks like when I scroll the sheet's content, it assumes I'm scrolling the sheet itself, but just for a few milliseconds. After that, it starts scrolling the content.

This happens only sometimes, seems unstable. I used this snippet in Playroom.

I couldn't reproduce this issue in desktop/android devices.

IMG_5784.MP4

hmmm... it's dificult to reproduce, maybe you tapped the grab zone with your finger?

@yceballost
Copy link
Contributor

yceballost commented Aug 22, 2023

Should we take into account a scenario in which the content overlaps with the close button? Playroom example
image

I don't think so. It's already managed by SheetBody. And if someone needs some special sheet behavior, it's their responsibility to use proper paddings to no overlap with the close button.

not really, If I take the Marcos's example and use sheetbody inside without title prop, the content do not respect the top padding
https://tinyurl.com/2c3nx866

Maybe we can solved this case using the same title padding for children when no props is added in SheetBody (?)

Component in Figma
image
image
image

@atabel
Copy link
Collaborator Author

atabel commented Aug 22, 2023

Should we take into account a scenario in which the content overlaps with the close button? Playroom example
image

I don't think so. It's already managed by SheetBody. And if someone needs some special sheet behavior, it's their responsibility to use proper paddings to no overlap with the close button.

not really, If I take the Marcos's example and use sheetbody inside without title prop, the content do not respect the top padding https://tinyurl.com/2c3nx866

Maybe we can solved this case using the same title padding for children when no props is added in SheetBody (?)

Component in Figma image image image

What happens with scroll in those cases?
something like this?
image
looks weird to me

@yceballost
Copy link
Contributor

yceballost commented Aug 23, 2023

Should we take into account a scenario in which the content overlaps with the close button? Playroom example
image

I don't think so. It's already managed by SheetBody. And if someone needs some special sheet behavior, it's their responsibility to use proper paddings to no overlap with the close button.

not really, If I take the Marcos's example and use sheetbody inside without title prop, the content do not respect the top padding tinyurl.com/2c3nx866
Maybe we can solved this case using the same title padding for children when no props is added in SheetBody (?)
Component in Figma image image image

What happens with scroll in those cases? something like this? image looks weird to me

I would solve it exactly the same way as in the dialogs
https://tinyurl.com/2betx7tw

(Is the Divider between title and extra defined in specs? I can't see it in specs)

Copy link
Contributor

@yceballost yceballost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩

@atabel atabel added this pull request to the merge queue Aug 24, 2023
Merged via the queue into master with commit f03ca7c Aug 24, 2023
10 checks passed
@atabel atabel deleted the atoledano-sheet branch August 24, 2023 08:54
tuentisre pushed a commit that referenced this pull request Aug 24, 2023
# [14.21.0](v14.20.1...v14.21.0) (2023-08-24)

### Bug Fixes

* **Cards:** remove min width from all the cards ([#858](#858)) ([029a6ea](029a6ea))
* **Tabs:** remove extra margin in safari ([#857](#857)) ([be8c2f2](be8c2f2))

### Features

* **FeedbackScreens:** updates in icons, paddings and styling ([#852](#852)) ([4b231e6](4b231e6))
* **Sheet:** new component ([#840](#840)) ([f03ca7c](f03ca7c))
* **utilities:** Remove lodash dependency and replace it with custom functions ([#856](#856)) ([dcaf691](dcaf691))
@tuentisre
Copy link
Collaborator

🎉 This PR is included in version 14.21.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants