Round boi
This commit is contained in:
+26
-40
@@ -1,15 +1,9 @@
|
|||||||
import React from 'react'
|
import {createContext, useCallback, useContext, useId, useMemo} from 'react'
|
||||||
import {type GestureResponderEvent, View} from 'react-native'
|
import {type GestureResponderEvent, View} from 'react-native'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {
|
import {atoms as a, useTheme, type ViewStyleProp, web} from '#/alf'
|
||||||
atoms as a,
|
|
||||||
useBreakpoints,
|
|
||||||
useTheme,
|
|
||||||
type ViewStyleProp,
|
|
||||||
web,
|
|
||||||
} from '#/alf'
|
|
||||||
import {Button, type ButtonColor, ButtonText} from '#/components/Button'
|
import {Button, type ButtonColor, ButtonText} from '#/components/Button'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
@@ -20,7 +14,7 @@ export {
|
|||||||
useDialogControl as usePromptControl,
|
useDialogControl as usePromptControl,
|
||||||
} from '#/components/Dialog'
|
} from '#/components/Dialog'
|
||||||
|
|
||||||
const Context = React.createContext<{
|
const Context = createContext<{
|
||||||
titleId: string
|
titleId: string
|
||||||
descriptionId: string
|
descriptionId: string
|
||||||
}>({
|
}>({
|
||||||
@@ -37,12 +31,15 @@ export function Outer({
|
|||||||
}: React.PropsWithChildren<{
|
}: React.PropsWithChildren<{
|
||||||
control: Dialog.DialogControlProps
|
control: Dialog.DialogControlProps
|
||||||
testID?: string
|
testID?: string
|
||||||
|
/**
|
||||||
|
* Native-specific options for the prompt. Extends `BottomSheetViewProps`
|
||||||
|
*/
|
||||||
nativeOptions?: Omit<BottomSheetViewProps, 'children'>
|
nativeOptions?: Omit<BottomSheetViewProps, 'children'>
|
||||||
}>) {
|
}>) {
|
||||||
const titleId = React.useId()
|
const titleId = useId()
|
||||||
const descriptionId = React.useId()
|
const descriptionId = useId()
|
||||||
|
|
||||||
const context = React.useMemo(
|
const context = useMemo(
|
||||||
() => ({titleId, descriptionId}),
|
() => ({titleId, descriptionId}),
|
||||||
[titleId, descriptionId],
|
[titleId, descriptionId],
|
||||||
)
|
)
|
||||||
@@ -58,7 +55,7 @@ export function Outer({
|
|||||||
<Dialog.ScrollableInner
|
<Dialog.ScrollableInner
|
||||||
accessibilityLabelledBy={titleId}
|
accessibilityLabelledBy={titleId}
|
||||||
accessibilityDescribedBy={descriptionId}
|
accessibilityDescribedBy={descriptionId}
|
||||||
style={web({maxWidth: 400})}>
|
style={web([{maxWidth: 320, borderRadius: 36}])}>
|
||||||
{children}
|
{children}
|
||||||
</Dialog.ScrollableInner>
|
</Dialog.ScrollableInner>
|
||||||
</Context.Provider>
|
</Context.Provider>
|
||||||
@@ -70,7 +67,7 @@ export function TitleText({
|
|||||||
children,
|
children,
|
||||||
style,
|
style,
|
||||||
}: React.PropsWithChildren<ViewStyleProp>) {
|
}: React.PropsWithChildren<ViewStyleProp>) {
|
||||||
const {titleId} = React.useContext(Context)
|
const {titleId} = useContext(Context)
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
nativeID={titleId}
|
nativeID={titleId}
|
||||||
@@ -78,7 +75,7 @@ export function TitleText({
|
|||||||
a.flex_1,
|
a.flex_1,
|
||||||
a.text_2xl,
|
a.text_2xl,
|
||||||
a.font_semi_bold,
|
a.font_semi_bold,
|
||||||
a.pb_sm,
|
a.pb_xs,
|
||||||
a.leading_snug,
|
a.leading_snug,
|
||||||
style,
|
style,
|
||||||
]}>
|
]}>
|
||||||
@@ -92,7 +89,7 @@ export function DescriptionText({
|
|||||||
selectable,
|
selectable,
|
||||||
}: React.PropsWithChildren<{selectable?: boolean}>) {
|
}: React.PropsWithChildren<{selectable?: boolean}>) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {descriptionId} = React.useContext(Context)
|
const {descriptionId} = useContext(Context)
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
nativeID={descriptionId}
|
nativeID={descriptionId}
|
||||||
@@ -103,22 +100,12 @@ export function DescriptionText({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Actions({children}: React.PropsWithChildren<{}>) {
|
export function Actions({children}: {children: React.ReactNode}) {
|
||||||
const {gtMobile} = useBreakpoints()
|
return <View style={[a.w_full, a.gap_sm, a.justify_end]}>{children}</View>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
export function Content({children}: {children: React.ReactNode}) {
|
||||||
<View
|
return <View style={[a.pb_sm]}>{children}</View>
|
||||||
style={[
|
|
||||||
a.w_full,
|
|
||||||
a.gap_md,
|
|
||||||
a.justify_end,
|
|
||||||
gtMobile
|
|
||||||
? [a.flex_row, a.flex_row_reverse, a.justify_start]
|
|
||||||
: [a.flex_col],
|
|
||||||
]}>
|
|
||||||
{children}
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Cancel({
|
export function Cancel({
|
||||||
@@ -130,9 +117,8 @@ export function Cancel({
|
|||||||
cta?: string
|
cta?: string
|
||||||
}) {
|
}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {gtMobile} = useBreakpoints()
|
|
||||||
const {close} = Dialog.useDialogContext()
|
const {close} = Dialog.useDialogContext()
|
||||||
const onPress = React.useCallback(() => {
|
const onPress = useCallback(() => {
|
||||||
close()
|
close()
|
||||||
}, [close])
|
}, [close])
|
||||||
|
|
||||||
@@ -140,7 +126,7 @@ export function Cancel({
|
|||||||
<Button
|
<Button
|
||||||
variant="solid"
|
variant="solid"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
size={gtMobile ? 'small' : 'large'}
|
size={'large'}
|
||||||
label={cta || _(msg`Cancel`)}
|
label={cta || _(msg`Cancel`)}
|
||||||
onPress={onPress}>
|
onPress={onPress}>
|
||||||
<ButtonText>{cta || _(msg`Cancel`)}</ButtonText>
|
<ButtonText>{cta || _(msg`Cancel`)}</ButtonText>
|
||||||
@@ -170,9 +156,8 @@ export function Action({
|
|||||||
testID?: string
|
testID?: string
|
||||||
}) {
|
}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const {gtMobile} = useBreakpoints()
|
|
||||||
const {close} = Dialog.useDialogContext()
|
const {close} = Dialog.useDialogContext()
|
||||||
const handleOnPress = React.useCallback(
|
const handleOnPress = useCallback(
|
||||||
(e: GestureResponderEvent) => {
|
(e: GestureResponderEvent) => {
|
||||||
close(() => onPress?.(e))
|
close(() => onPress?.(e))
|
||||||
},
|
},
|
||||||
@@ -181,9 +166,8 @@ export function Action({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="solid"
|
|
||||||
color={color}
|
color={color}
|
||||||
size={gtMobile ? 'small' : 'large'}
|
size={'large'}
|
||||||
label={cta || _(msg`Confirm`)}
|
label={cta || _(msg`Confirm`)}
|
||||||
onPress={handleOnPress}
|
onPress={handleOnPress}
|
||||||
testID={testID}>
|
testID={testID}>
|
||||||
@@ -220,8 +204,10 @@ export function Basic({
|
|||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<Outer control={control} testID="confirmModal">
|
<Outer control={control} testID="confirmModal">
|
||||||
<TitleText>{title}</TitleText>
|
<Content>
|
||||||
{description && <DescriptionText>{description}</DescriptionText>}
|
<TitleText>{title}</TitleText>
|
||||||
|
{description && <DescriptionText>{description}</DescriptionText>}
|
||||||
|
</Content>
|
||||||
<Actions>
|
<Actions>
|
||||||
<Action
|
<Action
|
||||||
cta={confirmButtonCta}
|
cta={confirmButtonCta}
|
||||||
|
|||||||
Reference in New Issue
Block a user