Skip to content

Commit

Permalink
Merge branch 'feature/415-narin-snackbar-hook-offset' of github.com:d…
Browse files Browse the repository at this point in the history
…epartment-of-veterans-affairs/va-mobile-library into feature/415-narin-snackbar-hook-offset
  • Loading branch information
narin committed Aug 9, 2024
2 parents b55dbe3 + bd5f8bf commit 3e867e7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 7 additions & 8 deletions packages/components/src/components/Snackbar/Snackbar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ export default meta

type Story = StoryObj<SnackbarProps>

const isWeb = Platform.OS !== 'web'

/**
* Handles rendering the story in non-web platforms to have functional Snackbar
* @param props - Arguments from `args` list
* @returns Flat Button display with onPress logic to pull up the Snackbar
*/
const mobileComponentRenderer = (props: SnackbarProps) => {
const { isError, messageA11y, onActionPressed, offset } = props.data || {}
const { show } = useSnackbar()
Expand All @@ -49,15 +52,11 @@ const mobileComponentRenderer = (props: SnackbarProps) => {
})
}

return (
<>
<Button label="Press for Snackbar" onPress={onPressSnackbar} />
</>
)
return <Button label="Press for Snackbar" onPress={onPressSnackbar} />
}

export const _Snackbar: Story = {
render: isWeb ? mobileComponentRenderer : undefined, // Render Snackbar flat in web
render: Platform.OS !== 'web' ? mobileComponentRenderer : undefined, // Render Snackbar flat in web
args: {
message: 'Message moved to Test Folder',
data: {
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/components/Snackbar/Snackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export const Snackbar: FC<SnackbarProps> = (toast) => {
const contentColor = theme.vadsColorForegroundInverse

const containerProps: ViewProps = {
accessibilityViewIsModal: true, // iOS only
tabIndex: 0, // Android only
// Above props prevent screen reader from tap focusing elements behind the Snackbar
style: {
alignItems: 'center',
backgroundColor: theme.vadsColorSurfaceInverse,
Expand Down
5 changes: 3 additions & 2 deletions packages/components/src/components/Snackbar/useSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { SNACKBAR_DEFAULT_OFFSET, modifyToastOptions } from './Snackbar'
import { SnackbarContext } from './SnackbarProvider'

/**
* Passthrough of useToast hook which has been modified to allow for optional
* offset setting
* Hook to manipulate the Snackbar with `show`, `hide`, or `isOpen` to query if already present
*
* Must be wrapped in `SnackbarProvider` to function
*/
export function useSnackbar() {
const toast = Toast.useToast()
Expand Down

0 comments on commit 3e867e7

Please sign in to comment.