Skip to content

Commit

Permalink
Ready for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
TimRoe committed Nov 6, 2023
1 parent 6d77409 commit 826690f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as DesignTokens from '@department-of-veterans-affairs/mobile-tokens'
import {
Pressable,
Text,
TextStyle,
TouchableOpacity,
View,
ViewStyle,
useColorScheme,
Expand All @@ -12,7 +12,7 @@ import React, { FC, useEffect } from 'react'
import styled from 'styled-components/native'

import { ComponentWrapper } from '../../wrapper'
import { webStorybookColorScheme } from '../../utils'
import { PressableOpacityStyle, webStorybookColorScheme } from '../../utils'

/**
* Props for {@link SegmentedControl}
Expand Down Expand Up @@ -41,7 +41,7 @@ type SegmentProps = {
widthPct: string
}

const Segment = styled(TouchableOpacity)<SegmentProps>`
const Segment = styled(Pressable)<SegmentProps>`
border-radius: 8px;
padding-vertical: 7px;
width: ${(props) => props.widthPct};
Expand Down Expand Up @@ -124,11 +124,12 @@ export const SegmentedControl: FC<SegmentedControlProps> = ({
isSelected={isSelected}
key={index}
widthPct={`${100 / labels.length}%`}
accessibilityLabel={accessibilityLabel}
aria-label={accessibilityLabel}
accessibilityHint={a11yHints ? a11yHints[index] : ''}
accessibilityValue={accessibilityValue}
accessibilityRole={'tab'}
role={'tab'}
accessibilityState={{ selected: isSelected }}
style={PressableOpacityStyle()}
testID={testIDs?.[index]}>
<Text allowFontScaling={false} style={textStyle}>
{label}
Expand All @@ -139,7 +140,7 @@ export const SegmentedControl: FC<SegmentedControlProps> = ({

return (
<ComponentWrapper>
<View style={viewStyle} accessibilityRole="tablist">
<View style={viewStyle} role="tablist">
{labels.map((label, index) => buildSegment(label, index))}
</View>
</ComponentWrapper>
Expand Down
12 changes: 12 additions & 0 deletions packages/components/src/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ export function webStorybookColorScheme(): ColorSchemeName {
const storybookDarkMode = require('storybook-dark-mode')
return storybookDarkMode.useDarkMode() ? 'dark' : 'light'
}

/**
* Convenience function for handling TouchableOpacity styling on Pressable component
* @param styles - RN styling to apply to Pressable component besides on press opacity
*/
export function PressableOpacityStyle(styles?: ViewStyle) {
if (styles) {
return ({pressed}) => [{opacity: pressed ? 0.2 : 1, ...styles}]
}

return ({pressed}) => [{opacity: pressed ? 0.2 : 1}]
}

0 comments on commit 826690f

Please sign in to comment.