-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add alt text limit to image dialog (#5611)
* Add alt text limit to image dialog * GIF alt text too * Fix * tweaks, save alt on dialog dismiss * simplify close behavior * use state in gif alt * state --------- Co-authored-by: Hailey <[email protected]>
- Loading branch information
1 parent
6dfd57e
commit 76d63f9
Showing
5 changed files
with
231 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react' | ||
import {View} from 'react-native' | ||
|
||
import {MAX_ALT_TEXT} from '#/lib/constants' | ||
import {CharProgress} from '#/view/com/composer/char-progress/CharProgress' | ||
import {atoms as a, useTheme} from '#/alf' | ||
|
||
export function AltTextCounterWrapper({ | ||
altText, | ||
children, | ||
}: { | ||
altText?: string | ||
children: React.ReactNode | ||
}) { | ||
const t = useTheme() | ||
return ( | ||
<View style={[a.flex_row]}> | ||
<CharProgress | ||
style={[ | ||
a.flex_col_reverse, | ||
a.align_center, | ||
a.mr_xs, | ||
{minWidth: 50, gap: 1}, | ||
]} | ||
textStyle={[{marginRight: 0}, a.text_sm, t.atoms.text_contrast_medium]} | ||
size={26} | ||
count={altText?.length || 0} | ||
max={MAX_ALT_TEXT} | ||
/> | ||
{children} | ||
</View> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,56 @@ | ||
import React from 'react' | ||
import {View} from 'react-native' | ||
import {StyleProp, TextStyle, View, ViewStyle} from 'react-native' | ||
// @ts-ignore no type definition -prf | ||
import ProgressCircle from 'react-native-progress/Circle' | ||
// @ts-ignore no type definition -prf | ||
import ProgressPie from 'react-native-progress/Pie' | ||
|
||
import {MAX_GRAPHEME_LENGTH} from 'lib/constants' | ||
import {usePalette} from 'lib/hooks/usePalette' | ||
import {s} from 'lib/styles' | ||
import {MAX_GRAPHEME_LENGTH} from '#/lib/constants' | ||
import {usePalette} from '#/lib/hooks/usePalette' | ||
import {s} from '#/lib/styles' | ||
import {Text} from '../../util/text/Text' | ||
|
||
const DANGER_LENGTH = MAX_GRAPHEME_LENGTH | ||
|
||
export function CharProgress({count}: {count: number}) { | ||
export function CharProgress({ | ||
count, | ||
max, | ||
style, | ||
textStyle, | ||
size, | ||
}: { | ||
count: number | ||
max?: number | ||
style?: StyleProp<ViewStyle> | ||
textStyle?: StyleProp<TextStyle> | ||
size?: number | ||
}) { | ||
const maxLength = max || MAX_GRAPHEME_LENGTH | ||
const pal = usePalette('default') | ||
const textColor = count > DANGER_LENGTH ? '#e60000' : pal.colors.text | ||
const circleColor = count > DANGER_LENGTH ? '#e60000' : pal.colors.link | ||
const textColor = count > maxLength ? '#e60000' : pal.colors.text | ||
const circleColor = count > maxLength ? '#e60000' : pal.colors.link | ||
return ( | ||
<> | ||
<Text style={[s.mr10, s.tabularNum, {color: textColor}]}> | ||
{MAX_GRAPHEME_LENGTH - count} | ||
<View style={style}> | ||
<Text style={[s.mr10, s.tabularNum, {color: textColor}, textStyle]}> | ||
{maxLength - count} | ||
</Text> | ||
<View> | ||
{count > DANGER_LENGTH ? ( | ||
{count > maxLength ? ( | ||
<ProgressPie | ||
size={30} | ||
size={size ?? 30} | ||
borderWidth={4} | ||
borderColor={circleColor} | ||
color={circleColor} | ||
progress={Math.min( | ||
(count - MAX_GRAPHEME_LENGTH) / MAX_GRAPHEME_LENGTH, | ||
1, | ||
)} | ||
progress={Math.min((count - maxLength) / maxLength, 1)} | ||
/> | ||
) : ( | ||
<ProgressCircle | ||
size={30} | ||
size={size ?? 30} | ||
borderWidth={1} | ||
borderColor={pal.colors.border} | ||
color={circleColor} | ||
progress={count / MAX_GRAPHEME_LENGTH} | ||
progress={count / maxLength} | ||
/> | ||
)} | ||
</View> | ||
</> | ||
</View> | ||
) | ||
} |
Oops, something went wrong.