@plexui/react-native 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/es/components/ActionSheet/ActionSheet.js +53 -19
- package/dist/es/components/Alert/Alert.js +163 -0
- package/dist/es/components/Avatar/Avatar.js +20 -8
- package/dist/es/components/BottomActions/BottomActions.js +34 -0
- package/dist/es/components/BottomSheet/BottomSheet.js +85 -17
- package/dist/es/components/Button/Button.js +108 -28
- package/dist/es/components/Card/Card.js +16 -8
- package/dist/es/components/Checkbox/Checkbox.js +67 -99
- package/dist/es/components/Chip/Chip.js +16 -7
- package/dist/es/components/Dialog/Dialog.js +38 -24
- package/dist/es/components/Field/Field.js +91 -0
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +59 -0
- package/dist/es/components/Icon/createIcon.js +13 -2
- package/dist/es/components/Indicator/CircularProgress.js +80 -0
- package/dist/es/components/Indicator/LoadingDots.js +46 -0
- package/dist/es/components/Indicator/LoadingIndicator.js +101 -0
- package/dist/es/components/Indicator/index.js +3 -0
- package/dist/es/components/Input/Input.js +69 -60
- package/dist/es/components/InputGroup/InputGroup.js +130 -0
- package/dist/es/components/List/List.js +175 -59
- package/dist/es/components/Menu/Menu.js +69 -40
- package/dist/es/components/NavigationButton/NavigationButton.js +20 -4
- package/dist/es/components/OTPInput/OTPInput.js +9 -3
- package/dist/es/components/PageControl/PageControl.js +13 -7
- package/dist/es/components/Popover/Popover.js +128 -0
- package/dist/es/components/Progress/Progress.js +142 -0
- package/dist/es/components/ProgressSteps/ProgressSteps.js +207 -0
- package/dist/es/components/RollingNumber/RollingNumber.js +125 -0
- package/dist/es/components/Select/Select.js +97 -34
- package/dist/es/components/Separator/Separator.js +31 -0
- package/dist/es/components/ShimmerText/ShimmerText.js +98 -0
- package/dist/es/components/Stepper/Stepper.js +219 -0
- package/dist/es/components/Switch/Switch.js +26 -12
- package/dist/es/components/TagInput/TagInput.js +121 -0
- package/dist/es/components/Text/Text.js +7 -4
- package/dist/es/components/TextLink/TextLink.js +42 -0
- package/dist/es/components/Textarea/Textarea.js +12 -0
- package/dist/es/components/Tip/Tip.js +193 -0
- package/dist/es/components/Toolbar/Toolbar.js +6 -2
- package/dist/es/components/Tooltip/Tooltip.js +272 -0
- package/dist/es/index.js +20 -2
- package/dist/es/internal/FloatingPanel.js +111 -0
- package/dist/es/internal/fieldStack.js +73 -0
- package/dist/es/internal/floating.js +97 -0
- package/dist/es/internal/ripple.js +119 -0
- package/dist/es/internal/row.js +2 -1
- package/dist/es/internal/transition.js +113 -0
- package/dist/es/theme/ThemeProvider.js +41 -9
- package/dist/es/theme/material.js +37 -7
- package/dist/types/components/ActionSheet/ActionSheet.d.ts +15 -7
- package/dist/types/components/Alert/Alert.d.ts +51 -0
- package/dist/types/components/Avatar/Avatar.d.ts +4 -2
- package/dist/types/components/BottomActions/BottomActions.d.ts +18 -0
- package/dist/types/components/BottomSheet/BottomSheet.d.ts +4 -2
- package/dist/types/components/Button/Button.d.ts +20 -5
- package/dist/types/components/Card/Card.d.ts +14 -1
- package/dist/types/components/Checkbox/Checkbox.d.ts +4 -3
- package/dist/types/components/Chip/Chip.d.ts +12 -1
- package/dist/types/components/Dialog/Dialog.d.ts +9 -5
- package/dist/types/components/Field/Field.d.ts +64 -0
- package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +42 -0
- package/dist/types/components/Indicator/CircularProgress.d.ts +34 -0
- package/dist/types/components/Indicator/LoadingDots.d.ts +17 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +46 -0
- package/dist/types/components/Indicator/index.d.ts +3 -0
- package/dist/types/components/Input/Input.d.ts +13 -3
- package/dist/types/components/InputGroup/InputGroup.d.ts +71 -0
- package/dist/types/components/List/List.d.ts +57 -14
- package/dist/types/components/Menu/Menu.d.ts +4 -0
- package/dist/types/components/NavigationButton/NavigationButton.d.ts +11 -3
- package/dist/types/components/OTPInput/OTPInput.d.ts +10 -1
- package/dist/types/components/PageControl/PageControl.d.ts +11 -1
- package/dist/types/components/Popover/Popover.d.ts +86 -0
- package/dist/types/components/Progress/Progress.d.ts +56 -0
- package/dist/types/components/ProgressSteps/ProgressSteps.d.ts +61 -0
- package/dist/types/components/RollingNumber/RollingNumber.d.ts +36 -0
- package/dist/types/components/Select/Select.d.ts +36 -8
- package/dist/types/components/Separator/Separator.d.ts +19 -0
- package/dist/types/components/ShimmerText/ShimmerText.d.ts +28 -0
- package/dist/types/components/Stepper/Stepper.d.ts +61 -0
- package/dist/types/components/Switch/Switch.d.ts +5 -5
- package/dist/types/components/TagInput/TagInput.d.ts +44 -0
- package/dist/types/components/TextLink/TextLink.d.ts +30 -0
- package/dist/types/components/Textarea/Textarea.d.ts +19 -0
- package/dist/types/components/Tip/Tip.d.ts +71 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +9 -1
- package/dist/types/components/Tooltip/Tooltip.d.ts +84 -0
- package/dist/types/index.d.ts +20 -2
- package/dist/types/internal/FloatingPanel.d.ts +70 -0
- package/dist/types/internal/fieldStack.d.ts +48 -0
- package/dist/types/internal/floating.d.ts +71 -0
- package/dist/types/internal/ripple.d.ts +17 -0
- package/dist/types/internal/row.d.ts +15 -3
- package/dist/types/internal/transition.d.ts +37 -0
- package/dist/types/theme/ThemeProvider.d.ts +28 -4
- package/dist/types/theme/material.d.ts +20 -6
- package/dist/types/theme/types.d.ts +8 -0
- package/package.json +2 -2
- package/src/components/ActionSheet/ActionSheet.tsx +107 -38
- package/src/components/Alert/Alert.tsx +279 -0
- package/src/components/Avatar/Avatar.tsx +21 -9
- package/src/components/BottomActions/BottomActions.tsx +54 -0
- package/src/components/BottomSheet/BottomSheet.tsx +111 -25
- package/src/components/Button/Button.tsx +170 -35
- package/src/components/Card/Card.tsx +33 -9
- package/src/components/Checkbox/Checkbox.tsx +89 -124
- package/src/components/Chip/Chip.tsx +49 -6
- package/src/components/Dialog/Dialog.tsx +68 -37
- package/src/components/Field/Field.tsx +227 -0
- package/src/components/FloatingLabelInput/FloatingLabelInput.tsx +144 -0
- package/src/components/Icon/createIcon.tsx +16 -6
- package/src/components/Indicator/CircularProgress.tsx +141 -0
- package/src/components/Indicator/LoadingDots.tsx +79 -0
- package/src/components/Indicator/LoadingIndicator.tsx +166 -0
- package/src/components/Indicator/index.ts +3 -0
- package/src/components/Input/Input.tsx +126 -97
- package/src/components/InputGroup/InputGroup.tsx +261 -0
- package/src/components/List/List.tsx +345 -88
- package/src/components/Menu/Menu.tsx +83 -41
- package/src/components/NavigationButton/NavigationButton.tsx +35 -5
- package/src/components/OTPInput/OTPInput.tsx +21 -2
- package/src/components/PageControl/PageControl.tsx +36 -8
- package/src/components/Popover/Popover.tsx +261 -0
- package/src/components/Progress/Progress.tsx +255 -0
- package/src/components/ProgressSteps/ProgressSteps.tsx +415 -0
- package/src/components/RollingNumber/RollingNumber.tsx +189 -0
- package/src/components/Select/Select.tsx +175 -71
- package/src/components/Separator/Separator.tsx +51 -0
- package/src/components/ShimmerText/ShimmerText.tsx +144 -0
- package/src/components/Stepper/Stepper.tsx +386 -0
- package/src/components/Switch/Switch.tsx +26 -12
- package/src/components/TagInput/TagInput.tsx +227 -0
- package/src/components/Text/Text.tsx +8 -4
- package/src/components/TextLink/TextLink.tsx +77 -0
- package/src/components/Textarea/Textarea.tsx +23 -0
- package/src/components/Tip/Tip.tsx +410 -0
- package/src/components/Toolbar/Toolbar.tsx +27 -2
- package/src/components/Tooltip/Tooltip.tsx +478 -0
- package/src/index.ts +36 -2
- package/src/internal/FloatingPanel.tsx +199 -0
- package/src/internal/fieldStack.tsx +179 -0
- package/src/internal/floating.ts +131 -0
- package/src/internal/ripple.tsx +132 -0
- package/src/internal/row.ts +16 -3
- package/src/internal/transition.ts +124 -0
- package/src/theme/ThemeProvider.tsx +65 -15
- package/src/theme/material.ts +39 -7
- package/src/theme/types.ts +8 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isValidElement, useId, useLayoutEffect, useState, type ReactNode } from "react"
|
|
1
|
+
import { isValidElement, useId, useLayoutEffect, useMemo, useState, type ReactNode } from "react"
|
|
2
2
|
import { Animated, Easing, PanResponder, Platform, Pressable, ScrollView, StyleSheet, View, useWindowDimensions, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
3
|
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
|
4
4
|
import { childrenOfType, flattenChildren } from "../../internal/children"
|
|
@@ -6,6 +6,7 @@ import { useKeyboardHeight } from "../../internal/keyboard"
|
|
|
6
6
|
import { iosDim, Overlay, ANDROID_DIM } from "../../internal/Overlay"
|
|
7
7
|
import { withAlpha } from "../../theme/material"
|
|
8
8
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
9
|
+
import { BarItemContext, type BarItemStyle } from "../Button/Button"
|
|
9
10
|
import { NavigationButton } from "../NavigationButton/NavigationButton"
|
|
10
11
|
import { Text } from "../Text/Text"
|
|
11
12
|
|
|
@@ -235,8 +236,9 @@ export function BottomSheetBase({
|
|
|
235
236
|
}, [open, drag])
|
|
236
237
|
const keyboard = useKeyboardHeight(open)
|
|
237
238
|
const m = theme.material
|
|
238
|
-
// Android's sheet:
|
|
239
|
-
|
|
239
|
+
// Android's sheet: 35dp top corners, concentric with its bar's 46dp circles 12 in from its top and sides (23 + 12),
|
|
240
|
+
// the dialog's background (white, near-black in dark mode)
|
|
241
|
+
const radius = android ? 35 : theme.length("--dialog-sheet-radius", 38)
|
|
240
242
|
// iOS: the panel of the phone layer, --mobile-surface-elevated-plain-primary (Dialog.module.css), white in light and
|
|
241
243
|
// the elevated near-black in dark
|
|
242
244
|
const background = android
|
|
@@ -244,7 +246,8 @@ export function BottomSheetBase({
|
|
|
244
246
|
? m.surfaceContainer
|
|
245
247
|
: m.surfaceContainerLowest
|
|
246
248
|
: theme.color("--mobile-surface-elevated-plain-primary", theme.color("--color-surface-elevated", theme.colors.background))
|
|
247
|
-
|
|
249
|
+
// Android's sheet title: 17/22 Medium, centered in its bar, as iOS's
|
|
250
|
+
const titleType = android ? { fontSize: 17, lineHeight: 22 } : { fontSize: theme.length("--toolbar-title-font-size", 17), lineHeight: theme.length("--toolbar-title-line-height", 22) }
|
|
248
251
|
const titleId = useId()
|
|
249
252
|
const web = Platform.OS === "web"
|
|
250
253
|
// The web names the dialog by its title; a phone keeps the modal view
|
|
@@ -257,15 +260,36 @@ export function BottomSheetBase({
|
|
|
257
260
|
const maxWidth = android && width > screen ? Math.max(width * 0.8, Math.min(480, width)) : undefined
|
|
258
261
|
const closeSize = theme.length("--dialog-sheet-close-size", 44)
|
|
259
262
|
const margin = theme.length("--mobile-layout-margin", 16)
|
|
260
|
-
// Android
|
|
263
|
+
// Android: content scrolled under the bar fades out under it; the footer's height sets the room under the content
|
|
264
|
+
const [scrolled, setScrolled] = useState(false)
|
|
265
|
+
const [footerHeight, setFooterHeight] = useState(0)
|
|
266
|
+
// Android's sheet has no handle: the whole sheet takes the drag. With a title its bar is the reference's sheet bar,
|
|
267
|
+
// over the content: Close in a 46dp glass circle 12 under the top edge and 12 from the side (in line with the
|
|
268
|
+
// content's cards), concentric with the sheet's corner, the title 17/22 Medium centered between the circles' places
|
|
269
|
+
// (69 in all). Content scrolled under it shows through the sheet's color at
|
|
270
|
+
// 63% over a light blur, let go over its last 32dp (12 past the bar), with no line
|
|
271
|
+
const barItem = useMemoBarItem(background)
|
|
261
272
|
const header = android ? (
|
|
262
|
-
|
|
263
|
-
{
|
|
264
|
-
<
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
273
|
+
title != null ? (
|
|
274
|
+
<View onStartShouldSetResponderCapture={gesture.chrome} style={styles.androidBar}>
|
|
275
|
+
<SheetBarFade fill={background} shown={scrolled} />
|
|
276
|
+
<View style={styles.androidCircle}>
|
|
277
|
+
{dismissible ? (
|
|
278
|
+
<BarItemContext.Provider value={barItem}>
|
|
279
|
+
<NavigationButton action="close" accessibilityLabel={closeLabel} onPress={close} />
|
|
280
|
+
</BarItemContext.Provider>
|
|
281
|
+
) : null}
|
|
282
|
+
</View>
|
|
283
|
+
<View style={styles.androidHeading}>
|
|
284
|
+
<Text nativeID={titleId} accessibilityRole="header" weight="medium" align="center" numberOfLines={1} color={m.onSurface} style={{ fontSize: titleType.fontSize, lineHeight: titleType.lineHeight }}>
|
|
285
|
+
{title}
|
|
286
|
+
</Text>
|
|
287
|
+
</View>
|
|
288
|
+
<View style={styles.androidCircle} />
|
|
289
|
+
</View>
|
|
290
|
+
) : (
|
|
291
|
+
<View onStartShouldSetResponderCapture={gesture.chrome} style={styles.androidGrip} />
|
|
292
|
+
)
|
|
269
293
|
) : dismissible || title != null ? (
|
|
270
294
|
// The web's phone Sheet bar: one 44 row 16 under the top edge, Close at the leading edge and the title alone centered
|
|
271
295
|
// The bar is the web's Toolbar: 16 above the row and --toolbar-padding-bottom under it
|
|
@@ -337,23 +361,52 @@ export function BottomSheetBase({
|
|
|
337
361
|
},
|
|
338
362
|
]}
|
|
339
363
|
>
|
|
340
|
-
{header}
|
|
364
|
+
{android && title != null ? null : header}
|
|
341
365
|
{/* Content taller than the screen scrolls; on iOS the drag stays on the bar, on Android it starts at the
|
|
342
366
|
content's top */}
|
|
343
367
|
<ScrollView
|
|
344
368
|
style={styles.scroll}
|
|
345
|
-
{...(android
|
|
346
|
-
|
|
369
|
+
{...(android
|
|
370
|
+
? {
|
|
371
|
+
...gesture.content,
|
|
372
|
+
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
373
|
+
gesture.content.onScroll(event)
|
|
374
|
+
const under = event.nativeEvent.contentOffset.y > 0
|
|
375
|
+
if (under !== scrolled) setScrolled(under)
|
|
376
|
+
},
|
|
377
|
+
scrollEventThrottle: 16,
|
|
378
|
+
}
|
|
379
|
+
: null)}
|
|
380
|
+
contentContainerStyle={[
|
|
381
|
+
android
|
|
382
|
+
? [
|
|
383
|
+
styles.androidContent,
|
|
384
|
+
title != null ? styles.androidContentUnderBar : null,
|
|
385
|
+
// Over a footer: 8 above its height, which reaches over the sheet's bottom padding
|
|
386
|
+
footer ? { paddingBottom: 8 + Math.max(0, footerHeight - insets.bottom - keyboard) } : null,
|
|
387
|
+
]
|
|
388
|
+
: iosContent,
|
|
389
|
+
contentStyle,
|
|
390
|
+
]}
|
|
347
391
|
keyboardShouldPersistTaps="handled"
|
|
348
392
|
bounces={false}
|
|
349
393
|
>
|
|
350
394
|
{content}
|
|
351
395
|
</ScrollView>
|
|
396
|
+
{/* Android's bar stands over the content, which scrolls under it */}
|
|
397
|
+
{android && title != null ? header : null}
|
|
352
398
|
{footer ? (
|
|
353
399
|
<View
|
|
354
400
|
onStartShouldSetResponderCapture={android ? gesture.chrome : undefined}
|
|
401
|
+
onLayout={android ? (event) => setFooterHeight(event.nativeEvent.layout.height) : undefined}
|
|
355
402
|
style={[
|
|
356
|
-
android
|
|
403
|
+
android
|
|
404
|
+
? [
|
|
405
|
+
styles.androidFooter,
|
|
406
|
+
// Over the sheet's color at 80%, faded in over its top 24dp, down over the gesture bar
|
|
407
|
+
{ paddingBottom: 12 + insets.bottom + keyboard, backgroundImage: `linear-gradient(to bottom, ${withAlpha(background, 0)}, ${withAlpha(background, 0.8)} 24px)` } as ViewStyle,
|
|
408
|
+
]
|
|
409
|
+
: [styles.iosFooter, { paddingHorizontal: margin, paddingBottom: keyboard ? 16 : Math.max(16, insets.bottom) }],
|
|
357
410
|
footer.props.style,
|
|
358
411
|
]}
|
|
359
412
|
>
|
|
@@ -383,11 +436,38 @@ export function BottomSheetBase({
|
|
|
383
436
|
|
|
384
437
|
const isFooter = (child: ReactNode) => isValidElement(child) && child.type === BottomSheetFooter
|
|
385
438
|
|
|
439
|
+
/** The item of an Android sheet's bar: a 46dp glass circle solved against the sheet's color. */
|
|
440
|
+
function useMemoBarItem(canvas: string): BarItemStyle {
|
|
441
|
+
return useMemo(() => ({ height: 46, fontSize: 15, lineHeight: 20, weight: "medium", prominentWeight: "medium", iconSize: 24, gutter: 16, canvas }), [canvas])
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* The fade under an Android sheet's bar once content is under it: the sheet's color at 63% over a light blur (8),
|
|
446
|
+
* reaching 12 past the bar and let go over its last 32 (a mask on the web; a gradient of the color where there is no
|
|
447
|
+
* mask or blur).
|
|
448
|
+
*/
|
|
449
|
+
function SheetBarFade({ fill, shown }: { fill: string; shown: boolean }) {
|
|
450
|
+
const veil = withAlpha(fill, 0.63)
|
|
451
|
+
const style: ViewStyle =
|
|
452
|
+
Platform.OS === "web"
|
|
453
|
+
? ({
|
|
454
|
+
backgroundColor: veil,
|
|
455
|
+
backdropFilter: "blur(8px)",
|
|
456
|
+
WebkitBackdropFilter: "blur(8px)",
|
|
457
|
+
maskImage: "linear-gradient(to bottom, #000 calc(100% - 32px), transparent)",
|
|
458
|
+
WebkitMaskImage: "linear-gradient(to bottom, #000 calc(100% - 32px), transparent)",
|
|
459
|
+
} as ViewStyle)
|
|
460
|
+
: ({ backgroundImage: `linear-gradient(to bottom, ${veil} calc(100% - 32px), ${withAlpha(fill, 0)})` } as ViewStyle)
|
|
461
|
+
return <View pointerEvents="none" style={[styles.androidBarFade, style, { opacity: shown ? 1 : 0 }]} />
|
|
462
|
+
}
|
|
463
|
+
|
|
386
464
|
/**
|
|
387
465
|
* A sheet from the bottom edge: on iOS 26 the sheet of the phone layer (`--dialog-sheet-radius` 38 on its top corners,
|
|
388
466
|
* a bar 16 under its top edge with Close at the leading edge and the title centered, as the web's phone Sheet; no
|
|
389
|
-
* grabber, since its height does not change), on Android
|
|
390
|
-
*
|
|
467
|
+
* grabber, since its height does not change), on Android the reference's sheet (35dp top corners, white, no handle,
|
|
468
|
+
* a bar of 46dp glass circles 12 under the top edge and 12 from the sides, concentric with the corners, with the title
|
|
469
|
+
* 17 Medium centered, the
|
|
470
|
+
* content 12 from the sides, a 20% dim, the screen's width in portrait). Drag it down to close it: its bar on iOS, anywhere on
|
|
391
471
|
* Android (from content that scrolls once it is at its top, and on a phone only from its rows and fields, since its
|
|
392
472
|
* plain parts keep the drag for the scroll).
|
|
393
473
|
* `BottomSheet.Footer` pins actions under the content.
|
|
@@ -401,14 +481,20 @@ const styles = StyleSheet.create({
|
|
|
401
481
|
iosBar: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
402
482
|
iosHeading: { flex: 1, alignItems: "center", justifyContent: "center" },
|
|
403
483
|
scrimTarget: { position: "absolute", top: 0, left: 0, right: 0 },
|
|
404
|
-
// The
|
|
405
|
-
|
|
484
|
+
// The bar: 46dp circles 12 under the top edge and 12 from the sides, 11 under them; with no title the top 8 of the
|
|
485
|
+
// sheet's padding
|
|
486
|
+
androidBar: { position: "absolute", top: 0, left: 0, right: 0, zIndex: 1, flexDirection: "row", alignItems: "center", paddingTop: 12, paddingBottom: 11, paddingHorizontal: 12, gap: 6 },
|
|
487
|
+
androidBarFade: { position: "absolute", top: 0, left: 0, right: 0, bottom: -12 },
|
|
488
|
+
androidCircle: { width: 46, height: 46 },
|
|
489
|
+
androidHeading: { flex: 1, minWidth: 0, alignItems: "center", justifyContent: "center" },
|
|
406
490
|
androidGrip: { height: 8 },
|
|
407
|
-
// The content
|
|
408
|
-
|
|
409
|
-
|
|
491
|
+
// The content 12 from the sides (as a page's groups), 16 over the navigation bar; under a bar 13 under its circles
|
|
492
|
+
// (71 from the sheet's top, 2 under the bar)
|
|
493
|
+
androidContent: { paddingHorizontal: 12, paddingTop: 4, paddingBottom: 16 },
|
|
494
|
+
androidContentUnderBar: { paddingTop: 12 + 46 + 13 },
|
|
410
495
|
iosFooter: { gap: 10, paddingTop: 12 },
|
|
411
496
|
iosFooterEdge: { position: "absolute", top: -15, left: 0, right: 0, bottom: 0 },
|
|
412
|
-
// Android's sheet actions:
|
|
413
|
-
|
|
497
|
+
// Android's sheet actions: 48dp buttons 4 apart, 12 from the sides and above, 12 over the gesture bar, over the
|
|
498
|
+
// content that scrolls under them
|
|
499
|
+
androidFooter: { position: "absolute", left: 0, right: 0, bottom: 0, gap: 4, paddingHorizontal: 12, paddingTop: 12 },
|
|
414
500
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, Fragment, isValidElement, useContext, useEffect, useState, type ReactNode } from "react"
|
|
1
|
+
import { createContext, Fragment, isValidElement, useContext, useEffect, useState, type ComponentRef, type ReactNode, type Ref } from "react"
|
|
2
2
|
import {
|
|
3
3
|
ActivityIndicator,
|
|
4
4
|
Animated,
|
|
@@ -16,8 +16,9 @@ import Svg, { Circle } from "react-native-svg"
|
|
|
16
16
|
import { flattenChildren } from "../../internal/children"
|
|
17
17
|
import { Glass } from "../../internal/Glass"
|
|
18
18
|
import { useAndroidGlass } from "../../internal/BarBackdrop"
|
|
19
|
+
import { useRipple } from "../../internal/ripple"
|
|
19
20
|
import { curves } from "../../internal/motion"
|
|
20
|
-
import { barShadow, stateLayer, withAlpha } from "../../theme/material"
|
|
21
|
+
import { accentText, barShadow, controlHighlight, dangerText, stateLayer, withAlpha } from "../../theme/material"
|
|
21
22
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
22
23
|
import type { Theme } from "../../theme/types"
|
|
23
24
|
import { IconDefaultsProvider } from "../Icon/createIcon"
|
|
@@ -30,7 +31,11 @@ export type ControlSize = "3xs" | "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2x
|
|
|
30
31
|
export type ButtonProps = Omit<PressableProps, "children" | "style"> & {
|
|
31
32
|
/** @default "primary" */
|
|
32
33
|
color?: ButtonColor
|
|
33
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* iOS's styles are Filled (`solid`), Tinted or Gray (`soft`) and Plain (`ghost`); it has no outlined button, so on
|
|
36
|
+
* iOS `outline` is the Gray button (the neutral soft fill, the label in the button's color). Android draws the
|
|
37
|
+
* outline. @default "solid"
|
|
38
|
+
*/
|
|
34
39
|
variant?: ButtonVariant
|
|
35
40
|
/**
|
|
36
41
|
* Height step of the Plex UI scale. iOS takes the native sizes of the phone layer (small 28, medium 34, large 50);
|
|
@@ -62,6 +67,8 @@ export type ButtonProps = Omit<PressableProps, "children" | "style"> & {
|
|
|
62
67
|
/** Icons and text; an icon element takes the label's color and the size of the button's icons. */
|
|
63
68
|
children?: ReactNode
|
|
64
69
|
style?: StyleProp<ViewStyle>
|
|
70
|
+
/** The button's native view: an ActionSheet's `source`, a measure. */
|
|
71
|
+
ref?: Ref<ComponentRef<typeof View>>
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
type Metrics = {
|
|
@@ -108,6 +115,8 @@ export type BarItemStyle = {
|
|
|
108
115
|
* action is the accent's ink, as Android's classic bars draw them.
|
|
109
116
|
*/
|
|
110
117
|
plain?: boolean
|
|
118
|
+
/** A bottom bar's item (Android: a confirm there keeps its circle, not a top bar's text pill). */
|
|
119
|
+
bottom?: boolean
|
|
111
120
|
}
|
|
112
121
|
|
|
113
122
|
export const BarItemContext = createContext<BarItemStyle | null>(null)
|
|
@@ -126,6 +135,13 @@ export const BarFieldContext = createContext<{
|
|
|
126
135
|
canvas?: string
|
|
127
136
|
} | null>(null)
|
|
128
137
|
|
|
138
|
+
/**
|
|
139
|
+
* A ghost Button in a List: in its `header` it is the list header's text action, in a `row` (a Button among a List's
|
|
140
|
+
* rows) the row is the button, as the web's ghost Button in a FieldGroup's header or in a `[data-row]`. Null elsewhere.
|
|
141
|
+
*/
|
|
142
|
+
export type ListAction = "header" | "row"
|
|
143
|
+
export const ListActionContext = createContext<ListAction | null>(null)
|
|
144
|
+
|
|
129
145
|
/** The control icon size a button size falls back to (Button.module.css). */
|
|
130
146
|
const CONTROL_ICON: Record<ControlSize, string> = { "3xs": "xs", "2xs": "sm", xs: "sm", sm: "md", md: "md", lg: "md", xl: "md", "2xl": "lg", "3xl": "lg" }
|
|
131
147
|
|
|
@@ -137,16 +153,16 @@ const ANDROID_SIZE = (size: ControlSize) => (["3xs", "2xs", "xs", "sm"].includes
|
|
|
137
153
|
|
|
138
154
|
export function buttonMetrics(theme: Theme, size: ControlSize, shape: "round" | "square" = "round", uniform = false): Metrics {
|
|
139
155
|
if (theme.isAndroid) {
|
|
140
|
-
// Android's buttons: the big one 48dp with a
|
|
141
|
-
// corners (square); the steps under it keep the
|
|
142
|
-
//
|
|
156
|
+
// Android's buttons: the big one 48dp with a 15 Medium label, a pill in the redesigned screens (round) or 8dp
|
|
157
|
+
// corners (square); the steps under it keep the shape and a 14 label. No shape morphs on a press or a selection,
|
|
158
|
+
// as the Android look has none
|
|
143
159
|
const step = ANDROID_SIZE(size)
|
|
144
160
|
const height = step === "XS" ? 32 : step === "S" ? 40 : 48
|
|
145
161
|
const corner = shape === "round" ? height / 2 : step === "XS" ? 6 : 8
|
|
146
162
|
return {
|
|
147
163
|
height,
|
|
148
164
|
gutter: step === "XS" ? 12 : step === "S" ? 16 : 20,
|
|
149
|
-
fontSize: 14,
|
|
165
|
+
fontSize: step === "M" ? 15 : 14,
|
|
150
166
|
lineHeight: 20,
|
|
151
167
|
iconSize: uniform ? (step === "XS" ? 18 : step === "S" ? 20 : 24) : step === "XS" ? 16 : 20,
|
|
152
168
|
gap: step === "XS" ? 4 : 6,
|
|
@@ -211,11 +227,11 @@ export function buttonColors(theme: Theme, color: ButtonColor, variant: ButtonVa
|
|
|
211
227
|
}
|
|
212
228
|
// The phone CSS: the tertiary label in every style (iOS 27's disabled content-area button), the fill of a gray
|
|
213
229
|
// button behind a solid or soft one
|
|
230
|
+
// An outline button is iOS's Gray (below): disabled, the gray fill as the others
|
|
214
231
|
return {
|
|
215
|
-
background: variant === "
|
|
232
|
+
background: variant === "ghost" ? "transparent" : theme.color("--button-mobile-disabled-background"),
|
|
216
233
|
pressed: "transparent",
|
|
217
234
|
text: theme.colors.labelTertiary,
|
|
218
|
-
border: variant === "outline" ? theme.colors.border : undefined,
|
|
219
235
|
}
|
|
220
236
|
}
|
|
221
237
|
const colors = ((): Colors => {
|
|
@@ -227,6 +243,15 @@ export function buttonColors(theme: Theme, color: ButtonColor, variant: ButtonVa
|
|
|
227
243
|
? { background: c(`background-${color}-solid`), pressed: c(`background-${color}-solid-active`), text: c(`text-${color}-solid`) }
|
|
228
244
|
: { background: c(`background-${color}-soft`), pressed: c(`background-${color}-soft-active`), text: c(`text-${color}-soft`) }
|
|
229
245
|
case "outline":
|
|
246
|
+
// iOS has no outlined button: its styles are Filled, Tinted, Gray and Plain. An outline button is the Gray
|
|
247
|
+
// one there, the neutral soft fill with the label in the button's color
|
|
248
|
+
if (theme.isIOS) {
|
|
249
|
+
return {
|
|
250
|
+
background: selected ? c(`background-${color}-outline-active`) : c("background-secondary-soft"),
|
|
251
|
+
pressed: c("background-secondary-soft-active"),
|
|
252
|
+
text: c(`text-${color}-outline`),
|
|
253
|
+
}
|
|
254
|
+
}
|
|
230
255
|
return {
|
|
231
256
|
background: selected ? c(`background-${color}-outline-active`) : "transparent",
|
|
232
257
|
pressed: c(`background-${color}-outline-active`),
|
|
@@ -390,9 +415,115 @@ function renderChildren(children: ReactNode, metrics: Metrics) {
|
|
|
390
415
|
/**
|
|
391
416
|
* A button after the platform: an iOS 26 capsule (the native sizes of the Plex UI phone layer, its colors and glass)
|
|
392
417
|
* or the Android button (a pill, 14 Medium, the Plex colors; a disabled one keeps its fill and dims its label to
|
|
393
|
-
* half). Props follow @plexui/ui.
|
|
418
|
+
* half). Props follow @plexui/ui. A ghost Button in a List's header or among its rows is drawn as the list's text action
|
|
419
|
+
* (`ListActionContext`).
|
|
394
420
|
*/
|
|
395
|
-
export function Button({
|
|
421
|
+
export function Button(props: ButtonProps) {
|
|
422
|
+
const list = useContext(ListActionContext)
|
|
423
|
+
const bar = useContext(BarItemContext)
|
|
424
|
+
if (list != null && bar == null && props.variant === "ghost") return <ListActionButton {...props} place={list} />
|
|
425
|
+
return <ButtonBody {...props} />
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* A ghost Button as a List draws an action. In a row (iOS 27.2's button cell): the row's 17/22 Regular words where a
|
|
430
|
+
* row's label starts, tinted (the accent for `primary`, `secondary` and `info`, red for `danger`), an icon after them at
|
|
431
|
+
* the row's trailing edge, the row's press fill, no chevron; on Android a 50dp row with the 16sp words 20 in, in the
|
|
432
|
+
* accent or the error color, pressed in the list selector. In a header: iOS's list header action, tinted 17/22 text on
|
|
433
|
+
* the title's line with a 44pt target; Android's 14sp Medium in the accent on the header's line. `style` reaches the
|
|
434
|
+
* row (`justifyContent: "center"` centres the words, as the web's `data-align="center"`).
|
|
435
|
+
*/
|
|
436
|
+
function ListActionButton({
|
|
437
|
+
place,
|
|
438
|
+
color = "primary",
|
|
439
|
+
disabled = false,
|
|
440
|
+
loading = false,
|
|
441
|
+
inert: inertProp = loading,
|
|
442
|
+
children,
|
|
443
|
+
style,
|
|
444
|
+
onPressIn,
|
|
445
|
+
onPressOut,
|
|
446
|
+
accessibilityState,
|
|
447
|
+
...rest
|
|
448
|
+
}: ButtonProps & { place: ListAction }) {
|
|
449
|
+
const theme = useTheme()
|
|
450
|
+
const android = theme.isAndroid
|
|
451
|
+
const [pressed, setPressed] = useState(false)
|
|
452
|
+
const inert = disabled || inertProp
|
|
453
|
+
const row = place === "row"
|
|
454
|
+
const tinted = color === "primary" || color === "secondary" || color === "info"
|
|
455
|
+
const base =
|
|
456
|
+
color === "danger"
|
|
457
|
+
? android
|
|
458
|
+
? dangerText(theme)
|
|
459
|
+
: theme.color("--color-text-danger")
|
|
460
|
+
: tinted
|
|
461
|
+
? android
|
|
462
|
+
? accentText(theme)
|
|
463
|
+
: // The web's phone rows tint an action with the info text (#0169cc, blue-200 in the dark)
|
|
464
|
+
theme.color("--color-text-info", theme.colors.accent)
|
|
465
|
+
: buttonColors(theme, color, "ghost", false, false).text
|
|
466
|
+
const ink = disabled ? (android ? withAlpha(base, 0.5) : theme.colors.labelTertiary) : !row && pressed && !android ? lighten(theme, base) : base
|
|
467
|
+
// Android: a row's words 16/20, a header's 15/20 Medium (the web's FieldGroup header action)
|
|
468
|
+
const type = android
|
|
469
|
+
? row
|
|
470
|
+
? { fontSize: 16, lineHeight: 20 }
|
|
471
|
+
: { fontSize: 15, lineHeight: 20 }
|
|
472
|
+
: row
|
|
473
|
+
? { fontSize: theme.length("--field-row-label-font-size", 17), lineHeight: theme.length("--field-row-label-line-height", 22) }
|
|
474
|
+
: { fontSize: theme.length("--field-group-title-font-size", 17), lineHeight: theme.length("--field-group-title-line-height", 22) }
|
|
475
|
+
const parts = flattenChildren(children)
|
|
476
|
+
// Words and then an icon: the words take the room, so the icon ends the row
|
|
477
|
+
const trailingIcon = row && parts.length > 1 && isValidElement(parts[parts.length - 1])
|
|
478
|
+
const content = parts.map((part, index) =>
|
|
479
|
+
typeof part === "string" || typeof part === "number" ? (
|
|
480
|
+
<Text key={`label-${index}`} weight={android && !row ? "medium" : "regular"} numberOfLines={row ? undefined : 1} style={[type, trailingIcon && index < parts.length - 1 ? styles.grow : null]}>
|
|
481
|
+
{part}
|
|
482
|
+
</Text>
|
|
483
|
+
) : (
|
|
484
|
+
<Fragment key={`part-${index}`}>{part}</Fragment>
|
|
485
|
+
),
|
|
486
|
+
)
|
|
487
|
+
const fill = row && pressed && !inert ? (android ? controlHighlight(theme.scheme) : theme.color("--field-row-press-background")) : undefined
|
|
488
|
+
// The header's words stand on the title's line: their target reaches over and under it to 44 (48 on Android)
|
|
489
|
+
const reach = row ? 0 : Math.max(0, ((android ? 48 : 44) - type.lineHeight) / 2)
|
|
490
|
+
return (
|
|
491
|
+
<Pressable
|
|
492
|
+
accessibilityRole="button"
|
|
493
|
+
accessibilityState={{ disabled: inert, busy: loading, ...accessibilityState }}
|
|
494
|
+
aria-busy={loading}
|
|
495
|
+
disabled={inert}
|
|
496
|
+
hitSlop={row ? undefined : { top: reach, bottom: reach, left: 8, right: 8 }}
|
|
497
|
+
onPressIn={(event) => {
|
|
498
|
+
setPressed(true)
|
|
499
|
+
onPressIn?.(event)
|
|
500
|
+
}}
|
|
501
|
+
onPressOut={(event) => {
|
|
502
|
+
setPressed(false)
|
|
503
|
+
onPressOut?.(event)
|
|
504
|
+
}}
|
|
505
|
+
{...rest}
|
|
506
|
+
style={[
|
|
507
|
+
styles.row,
|
|
508
|
+
row
|
|
509
|
+
? { alignSelf: "stretch", justifyContent: "flex-start", minHeight: android ? 50 : theme.length("--field-row-min-height", 52), paddingHorizontal: android ? 21 : theme.length("--list-row-inset", 20), gap: 8 }
|
|
510
|
+
: { flexShrink: 0, gap: 4 },
|
|
511
|
+
fill ? { backgroundColor: fill } : null,
|
|
512
|
+
!row && android && pressed && !inert ? { opacity: 0.6 } : null,
|
|
513
|
+
style,
|
|
514
|
+
]}
|
|
515
|
+
>
|
|
516
|
+
<TextColorProvider value={ink}>
|
|
517
|
+
{/* A row's symbol is 24 (`--field-row-icon-symbol-size`), as the arrow of a link that leaves the app */}
|
|
518
|
+
<IconDefaultsProvider size={android ? 24 : row ? theme.length("--field-row-icon-symbol-size", 24) : theme.length("--control-icon-size-md", 20)} color={ink}>
|
|
519
|
+
{loading ? <ActivityIndicator color={ink} size="small" /> : content}
|
|
520
|
+
</IconDefaultsProvider>
|
|
521
|
+
</TextColorProvider>
|
|
522
|
+
</Pressable>
|
|
523
|
+
)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function ButtonBody({
|
|
396
527
|
color = "primary",
|
|
397
528
|
variant = "solid",
|
|
398
529
|
size = "md",
|
|
@@ -476,8 +607,9 @@ export function Button({
|
|
|
476
607
|
const corners = android && selected ? metrics.selectedRadius : metrics.radius
|
|
477
608
|
// An icon in a group's capsule takes the group's 38dp slot, a circle of its own the bar's height
|
|
478
609
|
const width = uniform ? (android && bar?.inGroup ? 38 : metrics.height) : undefined
|
|
479
|
-
// Android's press on a bar's icon: its borderless ripple, a 40dp circle (20dp radius) centered on the icon,
|
|
480
|
-
// wider than a group's slot
|
|
610
|
+
// Android's press on a bar's icon: its borderless ripple, a 40dp circle (20dp radius) centered on the icon, inside
|
|
611
|
+
// a 46dp glass circle and a little wider than a group's slot (the reference's selector of mask 1, radius 20); a label
|
|
612
|
+
// in a bar ripples in its own pill
|
|
481
613
|
const dot = android && bar && uniform && width ? 40 : 0
|
|
482
614
|
// Android's press of a button standing on its own (a bar's have none): it shrinks to 0.98 in 80ms on the default
|
|
483
615
|
// curve and comes back on release in 350ms on an overshoot of 1.2, just past its size and back
|
|
@@ -494,21 +626,37 @@ export function Button({
|
|
|
494
626
|
: { toValue: 1, duration: 350, easing: curves.overshoot(1.2), useNativeDriver: false },
|
|
495
627
|
).start()
|
|
496
628
|
}
|
|
497
|
-
//
|
|
498
|
-
|
|
629
|
+
// Android's press in a bar: the list selector on its glass circles and pills, the content color at 20% on an accent
|
|
630
|
+
// one, the ink at 7% (#121A1D21) in a plain bar; a filled button's is the list selector; any other's Material's
|
|
631
|
+
// pressed state layer of its label
|
|
632
|
+
const pressLayer =
|
|
633
|
+
android && bar
|
|
634
|
+
? bar.plain
|
|
635
|
+
? withAlpha(colors.text, 0.07)
|
|
636
|
+
: accentAction
|
|
637
|
+
? withAlpha(colors.text, 0.2)
|
|
638
|
+
: listSelector(theme.scheme)
|
|
639
|
+
: android && variant === "solid"
|
|
640
|
+
? listSelector(theme.scheme)
|
|
641
|
+
: withAlpha(colors.text, stateLayer.pressed)
|
|
642
|
+
// Android's press: the ripple from the touch point, the platform's on a device and drawn here on the web, in the
|
|
643
|
+
// button's shape (its corners clip it) or a bar's bare icon's 40dp circle
|
|
644
|
+
const ripple = useRipple(
|
|
645
|
+
pressLayer,
|
|
646
|
+
android && !nativeRipple,
|
|
647
|
+
still,
|
|
648
|
+
dot && width ? { width: dot, height: dot, borderRadius: dot / 2, top: (metrics.height - dot) / 2, start: (width - dot) / 2 } : undefined,
|
|
649
|
+
)
|
|
499
650
|
const handleIn = (event: GestureResponderEvent) => {
|
|
500
651
|
setPressed(true)
|
|
501
652
|
scaleTo(true)
|
|
502
|
-
if (
|
|
503
|
-
glow.stopAnimation()
|
|
504
|
-
glow.setValue(still ? 1 : 0)
|
|
505
|
-
if (!still) Animated.timing(glow, { toValue: 1, duration: 80, easing: Easing.linear, useNativeDriver: false }).start()
|
|
506
|
-
}
|
|
653
|
+
if (android && !nativeRipple && !(disabled || inertProp)) ripple.start(event)
|
|
507
654
|
onPressIn?.(event)
|
|
508
655
|
}
|
|
509
656
|
const handleOut = (event: GestureResponderEvent) => {
|
|
510
657
|
setPressed(false)
|
|
511
658
|
scaleTo(false)
|
|
659
|
+
ripple.end()
|
|
512
660
|
onPressOut?.(event)
|
|
513
661
|
}
|
|
514
662
|
const inert = disabled || inertProp
|
|
@@ -610,21 +758,7 @@ export function Button({
|
|
|
610
758
|
</IconDefaultsProvider>
|
|
611
759
|
</TextColorProvider>
|
|
612
760
|
)
|
|
613
|
-
|
|
614
|
-
// Material's pressed state layer of its label
|
|
615
|
-
const pressLayer = android && bar ? withAlpha(colors.text, 0.07) : android && variant === "solid" ? listSelector(theme.scheme) : withAlpha(colors.text, stateLayer.pressed)
|
|
616
|
-
const layer =
|
|
617
|
-
theme.isAndroid && !nativeRipple && pressed && !inert ? (
|
|
618
|
-
<Animated.View
|
|
619
|
-
pointerEvents="none"
|
|
620
|
-
style={[
|
|
621
|
-
dot && width
|
|
622
|
-
? { position: "absolute", width: dot, height: dot, borderRadius: dot / 2, top: (metrics.height - dot) / 2, start: (width - dot) / 2, opacity: glow }
|
|
623
|
-
: StyleSheet.absoluteFill,
|
|
624
|
-
{ backgroundColor: pressLayer },
|
|
625
|
-
]}
|
|
626
|
-
/>
|
|
627
|
-
) : null
|
|
761
|
+
const layer = ripple.layer
|
|
628
762
|
const pressable = {
|
|
629
763
|
accessibilityRole: "button" as const,
|
|
630
764
|
accessibilityState: { disabled: inert, selected, busy: loading, ...accessibilityState },
|
|
@@ -666,4 +800,5 @@ const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
|
|
|
666
800
|
const styles = StyleSheet.create({
|
|
667
801
|
row: { flexDirection: "row", alignItems: "center", justifyContent: "center" },
|
|
668
802
|
fromTop: { alignSelf: "stretch", transformOrigin: "top" },
|
|
803
|
+
grow: { flexGrow: 1, flexShrink: 1 },
|
|
669
804
|
})
|
|
@@ -2,14 +2,17 @@ import { cloneElement, createContext, isValidElement, useContext, type ReactElem
|
|
|
2
2
|
import { Image, Platform, Pressable, StyleSheet, View, type ImageSourcePropType, type StyleProp, type ViewStyle } from "react-native"
|
|
3
3
|
import { flattenChildren } from "../../internal/children"
|
|
4
4
|
import { space } from "../../internal/spacing"
|
|
5
|
-
import { controlHighlight } from "../../theme/material"
|
|
5
|
+
import { controlHighlight, withAlpha } from "../../theme/material"
|
|
6
6
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
7
7
|
import type { Theme } from "../../theme/types"
|
|
8
8
|
import { materialType } from "../../theme/typography"
|
|
9
|
-
import {
|
|
9
|
+
import { IconDefaultsProvider } from "../Icon/createIcon"
|
|
10
|
+
import { Text, TextColorProvider } from "../Text/Text"
|
|
10
11
|
|
|
11
12
|
export type CardVariant = "outline" | "solid" | "ghost"
|
|
12
13
|
export type CardSize = "sm" | "md" | "lg"
|
|
14
|
+
/** A fill of the palette: the accent, the Plex primary, or a semantic color. */
|
|
15
|
+
export type CardColor = "accent" | "primary" | "info" | "success" | "warning" | "caution" | "danger" | "discovery"
|
|
13
16
|
|
|
14
17
|
export type CardProps = {
|
|
15
18
|
children: ReactNode
|
|
@@ -17,6 +20,12 @@ export type CardProps = {
|
|
|
17
20
|
variant?: CardVariant
|
|
18
21
|
/** The padding: 12, 16 or 20 on a phone. @default "md" */
|
|
19
22
|
size?: CardSize
|
|
23
|
+
/**
|
|
24
|
+
* Fills the card with a color of the palette (`--color-background-<color>-solid`, the accent for `accent`) in place
|
|
25
|
+
* of its variant's surface: the title, the text and the icons in the color made for it (`--color-text-<color>-solid`),
|
|
26
|
+
* the description that color at 80%. The press is a veil of that text color.
|
|
27
|
+
*/
|
|
28
|
+
color?: CardColor
|
|
20
29
|
/** Makes the whole card a button. */
|
|
21
30
|
onPress?: () => void
|
|
22
31
|
/** Shows the press of a card whose own parts take it. */
|
|
@@ -27,7 +36,7 @@ export type CardProps = {
|
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
/** `padding`: the card's own (0 on a ghost card); `inset`: its size's, which a picture's caption keeps. */
|
|
30
|
-
type CardContext = { padding: number; inset: number; radius: number; theme: Theme }
|
|
39
|
+
type CardContext = { padding: number; inset: number; radius: number; theme: Theme; ink?: string }
|
|
31
40
|
const Context = createContext<CardContext | null>(null)
|
|
32
41
|
|
|
33
42
|
function useCard(part: string) {
|
|
@@ -67,8 +76,15 @@ export function cardSurface(theme: Theme, variant: CardVariant) {
|
|
|
67
76
|
* section card of a settings screen (16dp corners, no border, the white card on the gray page; `solid` a gray fill),
|
|
68
77
|
* 16dp padding, Title M and Body M, pressed in the list selector as a List row.
|
|
69
78
|
*/
|
|
70
|
-
|
|
79
|
+
/** A colored card's fill and the color of what stands on it. */
|
|
80
|
+
export function cardColors(theme: Theme, color: CardColor) {
|
|
81
|
+
if (color === "accent") return { fill: theme.colors.accent, ink: theme.color("--color-text-accent-solid", "#FFFFFF") }
|
|
82
|
+
return { fill: theme.color(`--color-background-${color}-solid`), ink: theme.color(`--color-text-${color}-solid`, "#FFFFFF") }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function CardRoot({ children, variant = "outline", size = "md", color, onPress, interactive = false, accessibilityLabel, testID, style }: CardProps) {
|
|
71
86
|
const theme = useTheme()
|
|
87
|
+
const tint = color ? cardColors(theme, color) : null
|
|
72
88
|
const inset = theme.isAndroid ? (size === "lg" ? 24 : size === "sm" ? 12 : 16) : theme.length(`--card-padding-${size}`, PADDING[size])
|
|
73
89
|
// A ghost card has no padding, as the web's: its parts stand at its edges, unclipped (it has no fill to clip to)
|
|
74
90
|
const ghost = variant === "ghost"
|
|
@@ -83,11 +99,19 @@ function CardRoot({ children, variant = "outline", size = "md", onPress, interac
|
|
|
83
99
|
? cloneElement(child as ReactElement<CardMediaProps & EdgeProps>, { first: index === 0, last: index === parts.length - 1 })
|
|
84
100
|
: child,
|
|
85
101
|
)
|
|
86
|
-
const box = [styles.card, { padding, gap, borderRadius: radius }, ghost ? styles.ghost : null, cardSurface(theme, variant), style]
|
|
87
|
-
const content =
|
|
102
|
+
const box = [styles.card, { padding, gap, borderRadius: radius }, ghost && !tint ? styles.ghost : null, tint ? { backgroundColor: tint.fill } : cardSurface(theme, variant), style]
|
|
103
|
+
const content = tint ? (
|
|
104
|
+
<Context.Provider value={{ padding, inset, radius, theme, ink: tint.ink }}>
|
|
105
|
+
<TextColorProvider value={tint.ink}>
|
|
106
|
+
<IconDefaultsProvider color={tint.ink}>{body}</IconDefaultsProvider>
|
|
107
|
+
</TextColorProvider>
|
|
108
|
+
</Context.Provider>
|
|
109
|
+
) : (
|
|
110
|
+
<Context.Provider value={{ padding, inset, radius, theme }}>{body}</Context.Provider>
|
|
111
|
+
)
|
|
88
112
|
if (onPress || interactive) {
|
|
89
113
|
// Android: the press of a row in a section (the settings list selector), as a List row's
|
|
90
|
-
const layer = theme.isAndroid ? controlHighlight(theme.scheme) : theme.color("--alpha-08")
|
|
114
|
+
const layer = tint ? withAlpha(tint.ink, 0.12) : theme.isAndroid ? controlHighlight(theme.scheme) : theme.color("--alpha-08")
|
|
91
115
|
// The ripple on a device, clipped to the card's corners; a layer elsewhere
|
|
92
116
|
const nativeRipple = theme.isAndroid && Platform.OS === "android"
|
|
93
117
|
return (
|
|
@@ -153,11 +177,11 @@ function CardTitle({ children }: { children: ReactNode }) {
|
|
|
153
177
|
CardTitle.displayName = "Card.Title"
|
|
154
178
|
|
|
155
179
|
function CardDescription({ children }: { children: ReactNode }) {
|
|
156
|
-
const { theme } = useCard("Card.Description")
|
|
180
|
+
const { theme, ink } = useCard("Card.Description")
|
|
157
181
|
const type = theme.isAndroid ? materialType.bodyMedium : { fontSize: theme.length("--card-description-font-size", 15), lineHeight: theme.length("--card-description-line-height", 20) }
|
|
158
182
|
return (
|
|
159
183
|
<Text
|
|
160
|
-
color={theme.isAndroid ? "secondary" : theme.color("--card-description-color", theme.colors.textSecondary)}
|
|
184
|
+
color={ink ? withAlpha(ink, 0.8) : theme.isAndroid ? "secondary" : theme.color("--card-description-color", theme.colors.textSecondary)}
|
|
161
185
|
style={[{ fontSize: type.fontSize, lineHeight: type.lineHeight }, theme.isIOS ? { marginTop: -space(theme, 1.5) } : null]}
|
|
162
186
|
>
|
|
163
187
|
{children}
|