1.0.0 • Published 1 year ago

@element-public/react-bottom-sheet v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

BottomSheet

Description

Bottom sheets are surfaces containing supplementary content that are anchored to the bottom of the screen.

See live demos on storybook

Storybook BottomSheet Demos

Install bundle from npm-e

npm i @element-public/react-components @element-public/themes

Optional: install the component individually

npm i @element-public/react-bottom-sheet @element-public/themes

Open ~/.npmrc in an editor and add the following line to enable the @element-public scope:

@element-public:registry=https://npm.platforms.engineering

Troubleshooting

See below if you have never installed a package from Bayer's npm-enterprise or run into the following error:

npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR!     npm login

Setup an access token

See the devtools npm-e guide to learn how to create an access token if this is the first time you are using a npm-e package at Bayer or you do not have a line that starts with the following in your ~/.npmrc file:

//npm.platforms.engineering/:_authToken=

this file was copied over from sideSheet, change before merging

Variants

All variants of BottomSheet behave and look like the modal variant at smaller screen sizes.

The elevated and coplanar variants requires a parent wrapper context for layout.

All BottomSheet require a container context, which can typically be <body> in most instances.

Accessibility Concerns

To keep the user-experience for BottomSheet as accessible as possible, it strives to do the following when BottomSheet is at small-screen size and always during the modal variant:

  1. On Bottom Sheet open, set focus on the Bottom Sheet Dismiss button
  2. On Bottom Sheet close, return focus to the last focused element
  3. While open, prevent mouse clicks outbottom the bottom sheet
  4. While open, prevent tabbing to outbottom the Bottom Sheet
  5. Allow the ESC Key to close the Bottom Sheet

It is important that upon closing the BottomSheetReturnFocus event be listened for and return focus managed appropriately in the surrounding application context.

Props

BottomSheet

The BottomSheetWrapper component is necessary for the elevated or coplanar variants.

Example pseudo-code:

<body>
    <header></header>
    <BottomSheetWrapper variant='elevated'>
        <main></main>
        <BottomSheet variant='elevated'></BottomSheet>
    </BottomSheetWrapper>
    <footer></footer>
</body>

The BottomSheetWrapper component can be omitted entirely for modal and floating variants.

Example pseudo-code:

<body>
    <header></header>
    <main></main>
    <BottomSheet></BottomSheet>
    <footer></footer>
</body>

BottomSheetContainer

The BottomSheetContainer component is used as a substitute for a typical <body> context. It is required when attachContainerClassesToBody is set to false on BottomSheet.

The main responsibility of BottomSheetContainer is to control scrolling when the background content is obscured by modal content. This happens at all small-screen sizes for all variants and for the modal variant at all screen sizes.

<body>
    <BottomSheetContainer>
        <header></header>
        <BottomSheetWrapper variant='coplanar'>
            <main></main>
            <BottomSheet variant='coplanar'></BottomSheet>
        </BottomSheetWrapper>
        <footer></footer>
    </BottomSheetContainer>
</body>

Further Reading

Bottom Sheet behaves like a typical modal component at small-screen sizes, and always when in the modal variant.

Bottom Sheet Props

NameTypeDefaultRequiredDescription
allowOutsideClickbooleantruefalseSet to false to stop Bottom Sheet from closing when scrim is clicked when the variant is modal.
attachContainerClassesToBodybooleantruefalseAdd classes to body for when bottom-sheet-container is not present in DOM.
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
detentstring'full-height'falseThe detent in which the sheet should be in when opened. Available values: 'full-height' or 'content-height', from React Modal Sheet.
disableDragbooleanfalsefalseDisable drag for the whole sheet, from React Modal Sheet.
disableScrollLockingbooleanfalsefalseDisable's scroll locking for the documents body element while sheet is opened. Can be useful if you face issues with input elements and the iOS software keyboard, from React Modal Sheet.
headlineTextstringnullfalseThe text to be displayed along bottom the dismiss button in BottomSheet.
initialSnapnumber0falseInitial snap point when sheet is opened (index from snapPoints), from React Modal Sheet.
mountPointobjectundefinedfalseHTML element that should be used as the mount point for the sheet, from React Modal Sheet.
openbooleanundefinedfalseMake the BottomSheet visible using the experience set in variant prop.
prefersReducedMotionbooleanfalsefalseSkip sheet animations (sheet instantly snaps to desired location), from React Modal Sheet.
returnFocusSelectorstring'.lmnt-bottom-sheet-trigger'falseDOM selector to provide a target to return focus. Accepts any valid query (see mdn docs for Element.querySelector). If omitted focus will return to the last focused element upon closing.
rootIdstringnullfalseThe id of the element where the main app is mounted, eg. 'root'. Enables iOS modal effect, from React Modal Sheet.
snapPointsnumbernullfalseEg. -50, 0.5, 100, 0 - where positive values are pixels from the bottom of the screen and negative from the top. Values between 0-1 represent percentages, eg. 0.5 means 50% of window height from the bottom of the sceen, from React Modal Sheet.
tweenConfigobject{ ease: 'easeOut', duration: 0.2 }falseOverrides the config for the sheet tween transition when the sheet is opened, closed, or snapped to a point, from React Modal Sheet.
variantstring'modal'falseThe behavior styles available to bottom sheet: one of modal, floating, elevated, or coplanar.Accepted Values: modal, elevated, floating, coplanar

Bottom Sheet Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalsePrimary content. Accepts any valid markup.

Bottom Sheet Events

NameDefaultRequiredParamsDescription
onClosenullfalseA provided function to fire when Bottom Sheet becomes hidden.
onCloseEndnullfalseCallback fn that is called when the sheet closing animation is completed, from React Modal Sheet.
onCloseStartnullfalseCallback fn that is called when the sheet closing animation starts, from React Modal Sheet.
onOpenEndnullfalseCallback fn that is called when the sheet opening animation is completed, from React Modal Sheet.
onOpenStartnullfalseCallback fn that is called when the sheet opening animation starts, from React Modal Sheet.
onSnapnullfalseCallback fn that is called with the current snap point index when the sheet snaps to a new snap point. Requires snapPoints prop, from React Modal Sheet.

Bottom Sheet Content Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
scrollablebooleanfalsefalseIf true, the content will be scrollable.

Bottom Sheet Content Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalsePrimary content. Accepts any valid markup.

Bottom Sheet Header Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.

Bottom Sheet Header Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalsePrimary content. Accepts any valid markup.

Bottom Sheet Scroller Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.

Bottom Sheet Scroller Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalsePrimary content. Accepts any valid markup.