From 8bbbaed94cb2086747814e994f1a7136cda060bf Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Mon, 15 Apr 2024 08:59:44 -0700 Subject: [PATCH 01/41] Add expanded component state, collapse functionality, collapse icon --- .../components/src/components/Alert/Alert.tsx | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/packages/components/src/components/Alert/Alert.tsx b/packages/components/src/components/Alert/Alert.tsx index 7ba2717a..c9f6200e 100644 --- a/packages/components/src/components/Alert/Alert.tsx +++ b/packages/components/src/components/Alert/Alert.tsx @@ -1,8 +1,8 @@ import { Colors } from '@department-of-veterans-affairs/mobile-tokens' // import { HapticFeedbackTypes } from 'react-native-haptic-feedback' -import { Text, TextStyle, View, ViewStyle } from 'react-native' +import { Pressable, Text, TextStyle, View, ViewStyle } from 'react-native' // ^ ScrollView, -import React, { FC } from 'react' +import React, { FC, useState } from 'react' // ^ , RefObject, useEffect, useState // import { triggerHaptic } from 'utils/haptics' @@ -29,6 +29,7 @@ export type AlertProps = { /** Optional custom content to nest inside Alert * Use AlertContentColor or appropriate component props to set light/dark mode 'base' gray colors */ children?: React.ReactNode + collapsible?: boolean /** Optional primary action button */ primaryButton?: ButtonProps /** Optional secondary action button */ @@ -52,6 +53,7 @@ export const Alert: FC = ({ description, descriptionA11yLabel, children, + collapsible, primaryButton, secondaryButton, // focusOnError = true, @@ -60,6 +62,7 @@ export const Alert: FC = ({ }) => { const colorScheme = useColorScheme() const isDarkMode = colorScheme === 'dark' + const [expanded, setExpanded] = useState(true) // const [scrollRef, viewRef, scrollToAlert] = useAutoScrollToElement() // const [shouldFocus, setShouldFocus] = useState(true) @@ -151,7 +154,7 @@ export const Alert: FC = ({ borderLeftWidth: Sizing._8, padding: Sizing._20, paddingLeft: Sizing._12, // Adds with borderLeftWidth for 20 - width: '100%' // Ensure Alert fills horizontal space, regardless of flexing content + width: '100%', // Ensure Alert fills horizontal space, regardless of flexing content } const iconViewStyle: ViewStyle = { @@ -194,8 +197,22 @@ export const Alert: FC = ({ lineHeight: 30, } + const collapsed = collapsible && !expanded + + const collapseIconDisplay = ( + + + + + ) + const _primaryButton = () => { - if (!primaryButton) return null + if (!primaryButton || collapsed) return null primaryButton.buttonType = isDarkMode ? ButtonVariants.Base @@ -210,7 +227,7 @@ export const Alert: FC = ({ } const _secondaryButton = () => { - if (!secondaryButton) return null + if (!secondaryButton || collapsed) return null secondaryButton.buttonType = isDarkMode ? ButtonVariants.BaseSecondary @@ -238,19 +255,28 @@ export const Alert: FC = ({ {header} ) : null} - {header && (description || children) ? : null} - {description ? ( - - {description} + {!collapsed && ( + + {header && (description || children) ? : null} + {description ? ( + + {description} + + ) : null} + {description && children ? : null} + {children} + {/* {shouldFocus && vibrate()} */} - ) : null} - {description && children ? : null} - {children} - {/* {shouldFocus && vibrate()} */} + )} + {collapsible && ( + setExpanded(!expanded)}> + {collapseIconDisplay} + + )} {_primaryButton()} {_secondaryButton()} From f64e30dc2bad8bd2b0b576c3e23949e4aa9d5db6 Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Mon, 15 Apr 2024 09:42:31 -0700 Subject: [PATCH 02/41] Add collapsible story --- .../src/components/Alert/Alert.stories.tsx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/components/src/components/Alert/Alert.stories.tsx b/packages/components/src/components/Alert/Alert.stories.tsx index ee0a5339..44bb1975 100644 --- a/packages/components/src/components/Alert/Alert.stories.tsx +++ b/packages/components/src/components/Alert/Alert.stories.tsx @@ -59,3 +59,25 @@ export const Info: Story = { }, }, } + +export const Collapsible: Story = { + args: { + variant: 'info', + header: 'Header with enough text to wrap', + description: 'Description', + children: children, + collapsible: true, + primaryButton: { + label: 'Button Text', + onPress: () => { + null + }, + }, + secondaryButton: { + label: 'Button Text', + onPress: () => { + null + }, + }, + }, +} From 721c440f13d523447ec7d2d2a8248cc74da85816 Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Mon, 15 Apr 2024 09:42:57 -0700 Subject: [PATCH 03/41] Remove commented haptics and scrollTo code. Fixed left margin for collapse icon --- .../components/src/components/Alert/Alert.tsx | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/packages/components/src/components/Alert/Alert.tsx b/packages/components/src/components/Alert/Alert.tsx index c9f6200e..e8278722 100644 --- a/packages/components/src/components/Alert/Alert.tsx +++ b/packages/components/src/components/Alert/Alert.tsx @@ -56,35 +56,11 @@ export const Alert: FC = ({ collapsible, primaryButton, secondaryButton, - // focusOnError = true, - // scrollViewRef, testId, }) => { const colorScheme = useColorScheme() const isDarkMode = colorScheme === 'dark' const [expanded, setExpanded] = useState(true) - // const [scrollRef, viewRef, scrollToAlert] = useAutoScrollToElement() - // const [shouldFocus, setShouldFocus] = useState(true) - - // useEffect(() => { - // if ( - // variant === 'error' && - // scrollViewRef?.current && - // (header || description) - // ) { - // scrollRef.current = scrollViewRef.current - // scrollToAlert(-boxPadding) - // } - // setShouldFocus(focusOnError) - // }, [ - // variant, - // header, - // description, - // focusOnError, - // scrollRef, - // scrollToAlert, - // scrollViewRef, - // ]) // TODO: Replace with sizing/dimension tokens const Sizing = { @@ -201,13 +177,13 @@ export const Alert: FC = ({ const collapseIconDisplay = ( + - ) @@ -248,7 +224,6 @@ export const Alert: FC = ({ {header ? ( @@ -260,7 +235,6 @@ export const Alert: FC = ({ {header && (description || children) ? : null} {description ? ( {description} @@ -268,7 +242,6 @@ export const Alert: FC = ({ ) : null} {description && children ? : null} {children} - {/* {shouldFocus && vibrate()} */} )} From 91ccb43cb4ca720555d80d209fbcf86c6b44c160 Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Mon, 15 Apr 2024 11:19:28 -0700 Subject: [PATCH 04/41] Change story header text --- packages/components/src/components/Alert/Alert.stories.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/components/Alert/Alert.stories.tsx b/packages/components/src/components/Alert/Alert.stories.tsx index 44bb1975..0a096201 100644 --- a/packages/components/src/components/Alert/Alert.stories.tsx +++ b/packages/components/src/components/Alert/Alert.stories.tsx @@ -63,7 +63,7 @@ export const Info: Story = { export const Collapsible: Story = { args: { variant: 'info', - header: 'Header with enough text to wrap', + header: 'Header', description: 'Description', children: children, collapsible: true, From 3e09d1dbeb2d471556d8d3382fb21f329221a471 Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Mon, 15 Apr 2024 11:19:56 -0700 Subject: [PATCH 05/41] Refactor to make entire header area pressable --- .../components/src/components/Alert/Alert.tsx | 70 +++++++++++++------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/packages/components/src/components/Alert/Alert.tsx b/packages/components/src/components/Alert/Alert.tsx index e8278722..c4687be1 100644 --- a/packages/components/src/components/Alert/Alert.tsx +++ b/packages/components/src/components/Alert/Alert.tsx @@ -149,14 +149,6 @@ export const Alert: FC = ({ ) - // const vibrate = (): void => { - // if (variant === 'error') { - // triggerHaptic(HapticFeedbackTypes.notificationError) - // } else if (variant === 'warning') { - // triggerHaptic(HapticFeedbackTypes.notificationWarning) - // } - // } - // TODO: Replace with typography tokens const headerFont: TextStyle = { color: contentColor, @@ -217,23 +209,62 @@ export const Alert: FC = ({ ) } + const _headerText = () => { + if (header) { + return {header} + } + + if (description) { + return {description} + } + + return null + } + + const _header = () => { + const a11yLabel = header + ? headerA11yLabel || header + : description + ? descriptionA11yLabel || description + : '' + + if (collapsible) { + return ( + setExpanded(!expanded)} + accessibilityRole="tab" + accessibilityState={{ expanded }} + aria-label={a11yLabel} + style={{ flexDirection: 'row' }}> + {_headerText()} + {collapseIconDisplay} + + ) + } + + return ( + + + {_headerText()} + + + ) + } + return ( {iconDisplay} - {header ? ( - - {header} - - ) : null} + {_header()} {!collapsed && ( {header && (description || children) ? : null} - {description ? ( + {header && description ? ( @@ -245,11 +276,6 @@ export const Alert: FC = ({ )} - {collapsible && ( - setExpanded(!expanded)}> - {collapseIconDisplay} - - )} {_primaryButton()} {_secondaryButton()} From b5f67f3647181d23fce481fa0ac9f603c1fcdfbd Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Mon, 15 Apr 2024 11:21:27 -0700 Subject: [PATCH 06/41] Clean up unneeded imports --- packages/components/src/components/Alert/Alert.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/components/src/components/Alert/Alert.tsx b/packages/components/src/components/Alert/Alert.tsx index c4687be1..d4bd0e46 100644 --- a/packages/components/src/components/Alert/Alert.tsx +++ b/packages/components/src/components/Alert/Alert.tsx @@ -1,12 +1,6 @@ import { Colors } from '@department-of-veterans-affairs/mobile-tokens' -// import { HapticFeedbackTypes } from 'react-native-haptic-feedback' import { Pressable, Text, TextStyle, View, ViewStyle } from 'react-native' -// ^ ScrollView, import React, { FC, useState } from 'react' -// ^ , RefObject, useEffect, useState - -// import { triggerHaptic } from 'utils/haptics' -// import { useAutoScrollToElement } from 'utils/hooks' import { BaseColor, Spacer, useColorScheme } from '../../utils' import { Button, ButtonProps, ButtonVariants } from '../Button/Button' From bed831d95b1547924d1a1314a70406155f8827bf Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Mon, 15 Apr 2024 11:22:30 -0700 Subject: [PATCH 07/41] Clean up prop comments --- packages/components/src/components/Alert/Alert.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/components/src/components/Alert/Alert.tsx b/packages/components/src/components/Alert/Alert.tsx index d4bd0e46..46cb532b 100644 --- a/packages/components/src/components/Alert/Alert.tsx +++ b/packages/components/src/components/Alert/Alert.tsx @@ -23,16 +23,13 @@ export type AlertProps = { /** Optional custom content to nest inside Alert * Use AlertContentColor or appropriate component props to set light/dark mode 'base' gray colors */ children?: React.ReactNode + /** Optional boolean to determine whether the alert should be collapsible */ collapsible?: boolean /** Optional primary action button */ primaryButton?: ButtonProps /** Optional secondary action button */ secondaryButton?: ButtonProps - /** Optional boolean for determining when to focus on error alert boxes (e.g. onSaveClicked). */ - // focusOnError?: boolean - /** Optional ref for the parent scroll view. Used for scrolling to error alert boxes. */ - // scrollViewRef?: RefObject - /** optional testID */ + /** Optional testID */ testId?: string } From 10bcdb68c52841900050f559d5518a339022db39 Mon Sep 17 00:00:00 2001 From: Narin Ratana Date: Mon, 15 Apr 2024 11:24:03 -0700 Subject: [PATCH 08/41] Sort internal functions by display order --- .../components/src/components/Alert/Alert.tsx | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/components/src/components/Alert/Alert.tsx b/packages/components/src/components/Alert/Alert.tsx index 46cb532b..c834046c 100644 --- a/packages/components/src/components/Alert/Alert.tsx +++ b/packages/components/src/components/Alert/Alert.tsx @@ -170,36 +170,6 @@ export const Alert: FC = ({ ) - const _primaryButton = () => { - if (!primaryButton || collapsed) return null - - primaryButton.buttonType = isDarkMode - ? ButtonVariants.Base - : ButtonVariants.Primary - - return ( - <> - -