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

[Feature] Update components to use typography tokens or Text component #612

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eee3217
Update button to use typography token
narin Dec 11, 2024
60d3ac9
Update Alert to use typography tokens
narin Dec 13, 2024
e90b806
Rename Text import to RNText
narin Dec 13, 2024
2ce35bb
Update LoadingIndicator to use Text component
narin Dec 13, 2024
dd65d97
Update Snackbar to use typography tokens
narin Dec 13, 2024
2e615d0
Add bold boolean for body variant
narin Dec 13, 2024
9d5789c
Refactor Link component to utilize typography tokens and streamline t…
narin Dec 13, 2024
e1d5336
Refactor SegmentedControl to utilize typography tokens for improved t…
narin Dec 13, 2024
87fa448
Refactor FormText component to utilize typography tokens for improved…
narin Dec 13, 2024
5402a2d
Enhance component styling and parameters
narin Dec 13, 2024
419a80b
Reset default viewport
narin Dec 13, 2024
3b74dde
Version bump: components-v0.28.1-alpha.2
va-mobile-automation-robot Dec 13, 2024
3c2c278
Merge branch 'main' into feature/542-narin-update-components-to-use-t…
narin Dec 13, 2024
3d754e2
Replaced RNText with Text component where possible in FormText. Gener…
narin Dec 13, 2024
56d4301
Merge branch 'feature/542-narin-update-components-to-use-text-tokens-…
narin Dec 13, 2024
3ebba55
Replace RNText in Alert with Text component
narin Dec 13, 2024
ed670bd
Remove unused vars
narin Dec 13, 2024
9fdfbc2
Rename Text import to RNText
narin Dec 13, 2024
bd41f7c
Revert FormText spacers
narin Dec 13, 2024
270ab94
Fix whitespace
narin Dec 13, 2024
0b1e806
Add comment for center prop
narin Dec 13, 2024
55f8107
Add comment about icon alignment
narin Dec 13, 2024
88a50b1
Update Text story argTypes comment to be more generic
narin Dec 16, 2024
6f5c016
Simplify bold conditional
narin Dec 16, 2024
8a37721
Remove fonts section comment
narin Dec 16, 2024
46322b7
Use spacing token instead of marginBottom: 0. Use common textProps fo…
narin Dec 16, 2024
7df1aad
Merge branch 'main' into feature/542-narin-update-components-to-use-t…
narin Dec 16, 2024
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
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@department-of-veterans-affairs/mobile-component-library",
"version": "0.28.1-alpha.1",
"version": "0.28.1-alpha.2",
"description": "VA Design System Mobile Component Library",
"main": "src/index.tsx",
"scripts": {
Expand Down
39 changes: 16 additions & 23 deletions packages/components/src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import {
Insets,
Pressable,
Text,
TextStyle,
View,
ViewStyle,
useWindowDimensions,
} from 'react-native'
import { spacing } from '@department-of-veterans-affairs/mobile-tokens'
import { font, spacing } from '@department-of-veterans-affairs/mobile-tokens'
import React, { FC, useState } from 'react'

import { BaseColor, useColorScheme, useTheme } from '../../utils'
import { Button, ButtonProps, ButtonVariants } from '../Button/Button'
import { Icon, IconProps } from '../Icon/Icon'
import { Spacer } from '../Spacer/Spacer'
import { Text } from '../Text/Text'

/** Convenience function to set children content color correctly with light/dark mode */
export const AlertContentColor = BaseColor
Expand Down Expand Up @@ -83,6 +82,8 @@ export const Alert: FC<AlertProps> = ({
expandable ? initializeExpanded : true,
)

const { typography } = font

const toggleExpand = () => {
if (expanded && analytics?.onCollapse) analytics.onCollapse()
if (!expanded && analytics?.onExpand) analytics.onExpand()
Expand All @@ -92,22 +93,6 @@ export const Alert: FC<AlertProps> = ({
const contentColor = AlertContentColor()
let backgroundColor, borderColor, iconName: IconProps['name']

// TODO: Replace with typography tokens
const headerFont: TextStyle = {
color: contentColor,
fontFamily: 'SourceSansPro-Bold',
fontSize: 20,
lineHeight: 30,
}

// TODO: Replace with typography tokens
const descriptionFont: TextStyle = {
color: contentColor,
fontFamily: 'SourceSansPro-Regular',
fontSize: 20,
lineHeight: 30,
}

switch (variant) {
case 'info':
backgroundColor = theme.vadsColorFeedbackSurfaceInfo
Expand Down Expand Up @@ -143,8 +128,9 @@ export const Alert: FC<AlertProps> = ({
const iconViewStyle: ViewStyle = {
flexDirection: 'row',
// Below keeps icon aligned with first row of text, centered, and scalable
// If Text variant for header changes, token referenced in minHeight must change accordingly
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if there's any good way to rework, but seems unlikely this comment would be noticed in that eventuality.

alignSelf: 'flex-start',
minHeight: headerFont.lineHeight! * fontScale,
minHeight: typography.vadsFontHeadingSmall.lineHeight! * fontScale,
alignItems: 'center',
justifyContent: 'center',
}
Expand All @@ -170,7 +156,12 @@ export const Alert: FC<AlertProps> = ({
const _header = () => {
if (!header) return null

const headerText = <Text style={headerFont}>{header}</Text>
const headerText = (
<Text variant="heading" size="sm" bottomSpacing="none">
{header}
</Text>
)

const a11yLabel = headerA11yLabel || header
const hitSlop: Insets = {
// left border/padding + spacer + icon width
Expand Down Expand Up @@ -254,8 +245,10 @@ export const Alert: FC<AlertProps> = ({
) : null}
{description ? (
<Text
style={descriptionFont}
aria-label={descriptionA11yLabel || description}>
variant="body"
size="lg"
bottomSpacing="none"
a11yLabel={descriptionA11yLabel || description}>
{description}
</Text>
) : null}
Expand Down
26 changes: 10 additions & 16 deletions packages/components/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
Pressable,
PressableStateCallbackType,
Text,
Text as RNText,
TextStyle,
ViewStyle,
} from 'react-native'
import { spacing } from '@department-of-veterans-affairs/mobile-tokens'
import { font, spacing } from '@department-of-veterans-affairs/mobile-tokens'
import React from 'react'

import { useTheme } from '../../utils'
Expand Down Expand Up @@ -45,6 +45,7 @@ export const Button: React.FC<ButtonProps> = ({
testOnlyPressed,
}) => {
const theme = useTheme()
const { typography, family } = font

let bgColor: string,
bgColorPressed: string,
Expand Down Expand Up @@ -114,19 +115,12 @@ export const Button: React.FC<ButtonProps> = ({
* @param pressed - boolean for pressed state
* @returns TextStyle for text
*/
const getTextStyle = (pressed: boolean): TextStyle => {
// TODO: Replace with typography tokens
const font: TextStyle = {
fontFamily: 'SourceSansPro-Bold',
fontSize: 20,
lineHeight: 30,
}

return {
...font,
color: pressed ? textColorPressed : textColor,
}
}
const getTextStyle = (pressed: boolean): TextStyle => ({
...typography.vadsFontBodyLarge,
fontFamily: family.vadsFontFamilySansSerifBold,
marginBottom: spacing.vadsSpaceNone,
color: pressed ? textColorPressed : textColor,
})

return (
<Pressable
Expand All @@ -139,7 +133,7 @@ export const Button: React.FC<ButtonProps> = ({
testID={testID || label}
testOnly_pressed={testOnlyPressed}>
{({ pressed }: PressableStateCallbackType) => (
<Text style={getTextStyle(pressed)}>{label}</Text>
<RNText style={getTextStyle(pressed)}>{label}</RNText>
)}
</Pressable>
)
Expand Down
44 changes: 20 additions & 24 deletions packages/components/src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TextProps,
TextStyle,
} from 'react-native'
import { font, spacing } from '@department-of-veterans-affairs/mobile-tokens'
import { t } from 'i18next'
import React, { FC } from 'react'

Expand Down Expand Up @@ -141,12 +142,25 @@ export const Link: FC<LinkProps> = ({
}) => {
const theme = useTheme()
const launchExternalLink = useExternalLink()
const { typography } = font

// TODO: Replace with typography tokens
const font = {
fontFamily: 'SourceSansPro-Regular',
fontSize: 20,
lineHeight: 30,
let linkColor: string

switch (variant) {
case 'base':
linkColor = theme.vadsColorForegroundDefault
break
default:
linkColor = theme.vadsColorActionForegroundDefault
}

const textStyle: TextStyle = {
...typography.vadsFontBodyLarge,
marginBottom: spacing.vadsSpaceNone,
color: linkColor,
textDecorationColor: linkColor,
textDecorationLine: 'underline',
flexShrink: 1, // RN Text takes full width in row flexbox; shrink to wrap as appropriate
}

let _icon: IconProps
Expand Down Expand Up @@ -213,17 +227,7 @@ export const Link: FC<LinkProps> = ({
break
}

_icon.alignWithTextLineHeight = font.lineHeight

let linkColor: string

switch (variant) {
case 'base':
linkColor = theme.vadsColorForegroundDefault
break
default:
linkColor = theme.vadsColorActionForegroundDefault
}
_icon.alignWithTextLineHeight = textStyle.lineHeight

let ariaValue
if (typeof a11yValue === 'string') {
Expand Down Expand Up @@ -257,14 +261,6 @@ export const Link: FC<LinkProps> = ({
testOnly_pressed: testOnlyPressed,
}

const textStyle: TextStyle = {
...font,
color: linkColor,
textDecorationColor: linkColor,
textDecorationLine: 'underline',
flexShrink: 1, // RN Text takes full width in row flexbox; shrink to wrap as appropriate
}

return (
<ComponentWrapper>
<Pressable {...pressableProps} testID={testID}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import {
Animated,
Easing,
Text,
TextStyle,
View,
ViewStyle,
} from 'react-native'
import { Animated, Easing, View, ViewStyle } from 'react-native'
import React, { useEffect } from 'react'

import { Icon, IconProps } from '../Icon/Icon'
import { Spacer } from '../Spacer/Spacer'
import { Text } from '../Text/Text'
import { useTheme } from '../../utils'

export type LoadingIndicatorProps = {
Expand Down Expand Up @@ -68,22 +62,19 @@ export const LoadingIndicator: React.FC<LoadingIndicatorProps> = ({
fill: theme.vadsColorActionForegroundDefault,
}

const textStyle: TextStyle = {
fontFamily: 'SourceSansPro-Regular',
fontSize: 20,
lineHeight: 30,
textAlign: 'center',
color: theme.vadsColorForegroundDefault,
}

return (
<View style={containerStyle}>
<Animated.View style={{ transform: [{ rotate }] }}>
<Icon {...iconProps} />
</Animated.View>
<Spacer size="xs" />
{text && (
<Text style={textStyle} accessibilityLabel={a11yLabel}>
<Text
variant="body"
size="lg"
a11yLabel={a11yLabel}
bottomSpacing="none"
center>
{text}
</Text>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Pressable, Text, TextStyle, View, ViewStyle } from 'react-native'
import { spacing } from '@department-of-veterans-affairs/mobile-tokens'
import {
Pressable,
Text as RNText,
TextStyle,
View,
ViewStyle,
} from 'react-native'
import { font, spacing } from '@department-of-veterans-affairs/mobile-tokens'
import { useTranslation } from 'react-i18next'
import React, { FC, useEffect } from 'react'
import styled from 'styled-components/native'
Expand Down Expand Up @@ -54,6 +60,7 @@ export const SegmentedControl: FC<SegmentedControlProps> = ({
}) => {
const theme = useTheme()
const { t } = useTranslation()
const { typography } = font

useEffect(() => {
onChange(selected)
Expand Down Expand Up @@ -89,15 +96,10 @@ export const SegmentedControl: FC<SegmentedControlProps> = ({
total: labels.length,
})

// TODO: Replace with typography tokens
const font: TextStyle = {
fontFamily: isSelected ? 'SourceSansPro-Bold' : 'SourceSansPro-Regular',
fontSize: 20,
lineHeight: 30,
}

const textStyle: TextStyle = {
...font,
...typography.vadsFontBodyLarge,
fontFamily: isSelected ? 'SourceSansPro-Bold' : 'SourceSansPro-Regular',
marginBottom: spacing.vadsSpaceNone,
color: theme.vadsColorForegroundDefault,
textAlign: 'center',
Copy link
Contributor

Choose a reason for hiding this comment

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

Did none of the tones work here? Seems like with the Text updates to include bold and center that maybe this could still use the Text component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Couldn't use Text component here due to the allowFontScaling prop used on line 121, unless we add that prop.

}
Expand All @@ -116,9 +118,9 @@ export const SegmentedControl: FC<SegmentedControlProps> = ({
accessibilityState={{ selected: isSelected }}
style={PressableOpacityStyle()}
testID={testIDs?.[index]}>
<Text allowFontScaling={false} style={textStyle}>
<RNText allowFontScaling={false} style={textStyle}>
{label}
</Text>
</RNText>
</Segment>
)
}
Expand Down
Loading
Loading