@hzblj/kara-components 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/lib/module/atoms/badge/badge.android.js +8 -2
- package/lib/module/atoms/badge/badge.android.js.map +1 -1
- package/lib/module/atoms/button/button-tokens.js +39 -0
- package/lib/module/atoms/button/button-tokens.js.map +1 -1
- package/lib/module/atoms/button/button.android.js +40 -12
- package/lib/module/atoms/button/button.android.js.map +1 -1
- package/lib/module/atoms/button/button.ios.js +5 -2
- package/lib/module/atoms/button/button.ios.js.map +1 -1
- package/lib/module/atoms/checkbox/checkbox.android.js +17 -2
- package/lib/module/atoms/checkbox/checkbox.android.js.map +1 -1
- package/lib/module/atoms/date-picker/date-picker.android.js +72 -0
- package/lib/module/atoms/date-picker/date-picker.android.js.map +1 -0
- package/lib/module/atoms/date-picker/{date-picker.js → date-picker.ios.js} +4 -7
- package/lib/module/atoms/date-picker/date-picker.ios.js.map +1 -0
- package/lib/module/atoms/date-picker/index.js +1 -1
- package/lib/module/atoms/date-picker/index.js.map +1 -1
- package/lib/module/atoms/fab/fab.android.js +5 -3
- package/lib/module/atoms/fab/fab.android.js.map +1 -1
- package/lib/module/atoms/glass-view/glass-fallback.js +5 -2
- package/lib/module/atoms/glass-view/glass-fallback.js.map +1 -1
- package/lib/module/atoms/icon/icon.android.js +10 -12
- package/lib/module/atoms/icon/icon.android.js.map +1 -1
- package/lib/module/atoms/icon/icon.ios.js +15 -3
- package/lib/module/atoms/icon/icon.ios.js.map +1 -1
- package/lib/module/atoms/icon/index.js +0 -1
- package/lib/module/atoms/icon/index.js.map +1 -1
- package/lib/module/atoms/index.js +1 -1
- package/lib/module/atoms/index.js.map +1 -1
- package/lib/module/atoms/list/list.android.js +8 -2
- package/lib/module/atoms/list/list.android.js.map +1 -1
- package/lib/module/atoms/picker/index.js +1 -1
- package/lib/module/atoms/picker/index.js.map +1 -1
- package/lib/module/atoms/picker/picker.android.js +87 -0
- package/lib/module/atoms/picker/picker.android.js.map +1 -0
- package/lib/module/atoms/picker/{picker.js → picker.ios.js} +1 -1
- package/lib/module/atoms/picker/picker.ios.js.map +1 -0
- package/lib/module/atoms/rn-icon/index.js +5 -0
- package/lib/module/atoms/rn-icon/index.js.map +1 -0
- package/lib/module/atoms/rn-icon/rn-icon.android.js +29 -0
- package/lib/module/atoms/rn-icon/rn-icon.android.js.map +1 -0
- package/lib/module/atoms/rn-icon/rn-icon.ios.js +29 -0
- package/lib/module/atoms/rn-icon/rn-icon.ios.js.map +1 -0
- package/lib/module/atoms/rn-icon/rn-icon.types.js +4 -0
- package/lib/module/atoms/rn-icon/rn-icon.types.js.map +1 -0
- package/lib/module/atoms/surface/surface.android.js +33 -5
- package/lib/module/atoms/surface/surface.android.js.map +1 -1
- package/lib/module/atoms/switch/switch.android.js +14 -1
- package/lib/module/atoms/switch/switch.android.js.map +1 -1
- package/lib/module/glyph/glyph-button.android.js +25 -0
- package/lib/module/glyph/glyph-button.android.js.map +1 -0
- package/lib/module/glyph/glyph-button.ios.js +33 -0
- package/lib/module/glyph/glyph-button.ios.js.map +1 -0
- package/lib/module/glyph/glyph-button.types.js +4 -0
- package/lib/module/glyph/glyph-button.types.js.map +1 -0
- package/lib/module/glyph/glyph.android.js +20 -0
- package/lib/module/glyph/glyph.android.js.map +1 -0
- package/lib/module/glyph/glyph.ios.js +24 -0
- package/lib/module/glyph/glyph.ios.js.map +1 -0
- package/lib/module/glyph/glyph.types.js +4 -0
- package/lib/module/glyph/glyph.types.js.map +1 -0
- package/lib/module/glyph/index.js +8 -0
- package/lib/module/glyph/index.js.map +1 -0
- package/lib/module/glyph/rn-glyph.android.js +25 -0
- package/lib/module/glyph/rn-glyph.android.js.map +1 -0
- package/lib/module/glyph/rn-glyph.ios.js +26 -0
- package/lib/module/glyph/rn-glyph.ios.js.map +1 -0
- package/lib/module/molecules/collapsible/collapsible.android.js +2 -2
- package/lib/module/molecules/collapsible/collapsible.android.js.map +1 -1
- package/lib/module/molecules/labeled-content/labeled-content.js +2 -1
- package/lib/module/molecules/labeled-content/labeled-content.js.map +1 -1
- package/lib/module/molecules/list-item/list-item.js +2 -1
- package/lib/module/molecules/list-item/list-item.js.map +1 -1
- package/lib/module/molecules/navigation-bar/navigation-bar.android.js +8 -4
- package/lib/module/molecules/navigation-bar/navigation-bar.android.js.map +1 -1
- package/lib/module/molecules/radio-group/radio-group.android.js +5 -0
- package/lib/module/molecules/radio-group/radio-group.android.js.map +1 -1
- package/lib/module/molecules/radio-group/radio-group.ios.js +2 -2
- package/lib/module/molecules/radio-group/radio-group.ios.js.map +1 -1
- package/lib/module/molecules/search-bar/search-bar.js +10 -23
- package/lib/module/molecules/search-bar/search-bar.js.map +1 -1
- package/lib/module/molecules/stepper/stepper.android.js +7 -5
- package/lib/module/molecules/stepper/stepper.android.js.map +1 -1
- package/lib/module/organisms/alert/alert.android.js +42 -13
- package/lib/module/organisms/alert/alert.android.js.map +1 -1
- package/lib/module/organisms/context-menu/context-menu.android.js +82 -31
- package/lib/module/organisms/context-menu/context-menu.android.js.map +1 -1
- package/lib/module/organisms/context-menu/context-menu.ios.js +37 -16
- package/lib/module/organisms/context-menu/context-menu.ios.js.map +1 -1
- package/lib/module/organisms/fab-menu/fab-menu.android.js +6 -2
- package/lib/module/organisms/fab-menu/fab-menu.android.js.map +1 -1
- package/lib/module/organisms/fab-menu/fab-menu.ios.js +15 -6
- package/lib/module/organisms/fab-menu/fab-menu.ios.js.map +1 -1
- package/lib/module/organisms/form/form.android.js +1 -0
- package/lib/module/organisms/form/form.android.js.map +1 -1
- package/lib/module/organisms/index.js +0 -1
- package/lib/module/organisms/index.js.map +1 -1
- package/lib/module/organisms/menu/menu.android.js +51 -33
- package/lib/module/organisms/menu/menu.android.js.map +1 -1
- package/lib/typescript/atoms/button/button-tokens.d.ts +6 -1
- package/lib/typescript/atoms/date-picker/date-picker.d.ts +1 -2
- package/lib/typescript/atoms/date-picker/date-picker.ios.d.ts +3 -0
- package/lib/typescript/atoms/glass-view/glass-fallback.d.ts +4 -1
- package/lib/typescript/atoms/glass-view/glass-view.types.d.ts +1 -1
- package/lib/typescript/atoms/icon/icon.ios.d.ts +4 -0
- package/lib/typescript/atoms/icon/icon.types.d.ts +18 -1
- package/lib/typescript/atoms/icon/index.d.ts +0 -1
- package/lib/typescript/atoms/index.d.ts +1 -1
- package/lib/typescript/atoms/list/list.types.d.ts +9 -0
- package/lib/typescript/atoms/picker/picker.d.ts +1 -2
- package/lib/typescript/atoms/picker/picker.ios.d.ts +2 -0
- package/lib/typescript/atoms/rn-icon/index.d.ts +2 -0
- package/lib/typescript/atoms/rn-icon/rn-icon.d.ts +1 -0
- package/lib/typescript/atoms/rn-icon/rn-icon.ios.d.ts +3 -0
- package/lib/typescript/atoms/rn-icon/rn-icon.types.d.ts +5 -0
- package/lib/typescript/glyph/glyph-button.d.ts +1 -0
- package/lib/typescript/glyph/glyph-button.ios.d.ts +2 -0
- package/lib/typescript/glyph/glyph-button.types.d.ts +10 -0
- package/lib/typescript/glyph/glyph.d.ts +1 -0
- package/lib/typescript/glyph/glyph.ios.d.ts +3 -0
- package/lib/typescript/glyph/glyph.types.d.ts +13 -0
- package/lib/typescript/glyph/index.d.ts +5 -0
- package/lib/typescript/glyph/rn-glyph.d.ts +1 -0
- package/lib/typescript/glyph/rn-glyph.ios.d.ts +3 -0
- package/lib/typescript/molecules/scroll-edge-container/scroll-edge-container.types.d.ts +3 -0
- package/lib/typescript/organisms/context-menu/context-menu.types.d.ts +28 -2
- package/lib/typescript/organisms/fab-menu/fab-menu.types.d.ts +1 -1
- package/lib/typescript/organisms/form/form.types.d.ts +5 -0
- package/lib/typescript/organisms/index.d.ts +0 -1
- package/package.json +5 -7
- package/src/atoms/badge/badge.android.tsx +5 -2
- package/src/atoms/button/button-tokens.ts +49 -0
- package/src/atoms/button/button.android.tsx +46 -12
- package/src/atoms/button/button.ios.tsx +5 -2
- package/src/atoms/checkbox/checkbox.android.tsx +21 -4
- package/src/atoms/date-picker/date-picker.android.tsx +74 -0
- package/src/atoms/date-picker/date-picker.ios.tsx +27 -0
- package/src/atoms/fab/fab.android.tsx +4 -1
- package/src/atoms/glass-view/glass-fallback.tsx +5 -2
- package/src/atoms/glass-view/glass-view.types.ts +1 -1
- package/src/atoms/icon/icon.android.tsx +11 -7
- package/src/atoms/icon/icon.ios.tsx +25 -5
- package/src/atoms/icon/icon.types.ts +18 -24
- package/src/atoms/icon/index.ts +0 -1
- package/src/atoms/index.ts +1 -1
- package/src/atoms/list/list.android.tsx +12 -1
- package/src/atoms/list/list.types.ts +9 -0
- package/src/atoms/picker/picker.android.tsx +88 -0
- package/src/atoms/rn-icon/index.ts +2 -0
- package/src/atoms/rn-icon/rn-icon.android.tsx +28 -0
- package/src/atoms/rn-icon/rn-icon.ios.tsx +28 -0
- package/src/atoms/rn-icon/rn-icon.types.ts +8 -0
- package/src/atoms/surface/surface.android.tsx +28 -4
- package/src/atoms/switch/switch.android.tsx +24 -3
- package/src/glyph/glyph-button.android.tsx +25 -0
- package/src/glyph/glyph-button.ios.tsx +37 -0
- package/src/glyph/glyph-button.types.ts +12 -0
- package/src/glyph/glyph.android.tsx +12 -0
- package/src/glyph/glyph.ios.tsx +15 -0
- package/src/glyph/glyph.types.ts +15 -0
- package/src/glyph/index.ts +5 -0
- package/src/glyph/rn-glyph.android.tsx +14 -0
- package/src/glyph/rn-glyph.ios.tsx +16 -0
- package/src/molecules/collapsible/collapsible.android.tsx +2 -2
- package/src/molecules/labeled-content/labeled-content.tsx +2 -1
- package/src/molecules/list-item/list-item.tsx +2 -1
- package/src/molecules/navigation-bar/navigation-bar.android.tsx +11 -4
- package/src/molecules/radio-group/radio-group.android.tsx +11 -2
- package/src/molecules/radio-group/radio-group.ios.tsx +2 -2
- package/src/molecules/scroll-edge-container/scroll-edge-container.types.ts +3 -0
- package/src/molecules/search-bar/search-bar.tsx +4 -9
- package/src/molecules/stepper/stepper.android.tsx +3 -3
- package/src/organisms/alert/alert.android.tsx +44 -7
- package/src/organisms/context-menu/context-menu.android.tsx +71 -37
- package/src/organisms/context-menu/context-menu.ios.tsx +40 -18
- package/src/organisms/context-menu/context-menu.types.ts +29 -3
- package/src/organisms/fab-menu/fab-menu.android.tsx +3 -2
- package/src/organisms/fab-menu/fab-menu.ios.tsx +13 -12
- package/src/organisms/fab-menu/fab-menu.types.ts +1 -1
- package/src/organisms/form/form.android.tsx +1 -1
- package/src/organisms/form/form.types.ts +5 -0
- package/src/organisms/index.ts +0 -1
- package/src/organisms/menu/menu.android.tsx +36 -30
- package/CHANGELOG.md +0 -14
- package/lib/module/atoms/countdown/countdown-frame.js +0 -115
- package/lib/module/atoms/countdown/countdown-frame.js.map +0 -1
- package/lib/module/atoms/countdown/countdown-units.js +0 -25
- package/lib/module/atoms/countdown/countdown-units.js.map +0 -1
- package/lib/module/atoms/countdown/countdown.android.js +0 -53
- package/lib/module/atoms/countdown/countdown.android.js.map +0 -1
- package/lib/module/atoms/countdown/countdown.ios.js +0 -50
- package/lib/module/atoms/countdown/countdown.ios.js.map +0 -1
- package/lib/module/atoms/countdown/countdown.types.js +0 -4
- package/lib/module/atoms/countdown/countdown.types.js.map +0 -1
- package/lib/module/atoms/countdown/index.js +0 -5
- package/lib/module/atoms/countdown/index.js.map +0 -1
- package/lib/module/atoms/date-picker/date-picker.js.map +0 -1
- package/lib/module/atoms/icon/icon-names.js +0 -53
- package/lib/module/atoms/icon/icon-names.js.map +0 -1
- package/lib/module/atoms/picker/picker.js.map +0 -1
- package/lib/module/organisms/rn-context-menu/index.js +0 -5
- package/lib/module/organisms/rn-context-menu/index.js.map +0 -1
- package/lib/module/organisms/rn-context-menu/rn-context-menu.android.js +0 -101
- package/lib/module/organisms/rn-context-menu/rn-context-menu.android.js.map +0 -1
- package/lib/module/organisms/rn-context-menu/rn-context-menu.ios.js +0 -44
- package/lib/module/organisms/rn-context-menu/rn-context-menu.ios.js.map +0 -1
- package/lib/module/organisms/rn-context-menu/rn-context-menu.types.js +0 -4
- package/lib/module/organisms/rn-context-menu/rn-context-menu.types.js.map +0 -1
- package/lib/typescript/atoms/countdown/countdown-frame.d.ts +0 -17
- package/lib/typescript/atoms/countdown/countdown-units.d.ts +0 -5
- package/lib/typescript/atoms/countdown/countdown.d.ts +0 -1
- package/lib/typescript/atoms/countdown/countdown.ios.d.ts +0 -2
- package/lib/typescript/atoms/countdown/countdown.types.d.ts +0 -21
- package/lib/typescript/atoms/countdown/index.d.ts +0 -2
- package/lib/typescript/atoms/icon/icon-names.d.ts +0 -50
- package/lib/typescript/organisms/rn-context-menu/index.d.ts +0 -2
- package/lib/typescript/organisms/rn-context-menu/rn-context-menu.d.ts +0 -1
- package/lib/typescript/organisms/rn-context-menu/rn-context-menu.ios.d.ts +0 -2
- package/lib/typescript/organisms/rn-context-menu/rn-context-menu.types.d.ts +0 -33
- package/src/atoms/countdown/countdown-frame.tsx +0 -123
- package/src/atoms/countdown/countdown-units.ts +0 -37
- package/src/atoms/countdown/countdown.android.tsx +0 -49
- package/src/atoms/countdown/countdown.ios.tsx +0 -46
- package/src/atoms/countdown/countdown.types.ts +0 -24
- package/src/atoms/countdown/index.ts +0 -2
- package/src/atoms/date-picker/date-picker.tsx +0 -26
- package/src/atoms/icon/icon-names.ts +0 -53
- package/src/organisms/rn-context-menu/index.ts +0 -2
- package/src/organisms/rn-context-menu/rn-context-menu.android.tsx +0 -90
- package/src/organisms/rn-context-menu/rn-context-menu.ios.tsx +0 -47
- package/src/organisms/rn-context-menu/rn-context-menu.types.ts +0 -36
- /package/src/atoms/picker/{picker.tsx → picker.ios.tsx} +0 -0
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {AlertDialog,
|
|
1
|
+
import {AlertDialog, Text as ComposeText, TextButton} from '@expo/ui/jetpack-compose'
|
|
2
2
|
import {useAppTheme} from '@hzblj/kara-theme'
|
|
3
3
|
|
|
4
4
|
import {useHostGuard} from '../../host-context'
|
|
5
5
|
import type {AlertComponent, AlertProps} from './alert.types'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Material's `AlertDialog`, built from its slots — title, text, confirm and dismiss buttons. Content passed as plain
|
|
9
|
+
* children has no slot to land in, and the dialog draws empty. The actions mirror the iOS alert: the confirm label
|
|
10
|
+
* (in the destructive colour when asked) and Cancel.
|
|
11
|
+
*/
|
|
7
12
|
export const Alert: AlertComponent = ({
|
|
8
13
|
confirmLabel = 'OK',
|
|
14
|
+
destructive = false,
|
|
9
15
|
message,
|
|
10
16
|
onConfirm,
|
|
11
17
|
onDismiss,
|
|
@@ -20,18 +26,49 @@ export const Alert: AlertComponent = ({
|
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
return (
|
|
23
|
-
<AlertDialog
|
|
24
|
-
|
|
29
|
+
<AlertDialog
|
|
30
|
+
colors={{
|
|
31
|
+
containerColor: theme.color('surface.primary'),
|
|
32
|
+
textContentColor: theme.color('content.secondary'),
|
|
33
|
+
titleContentColor: theme.color('content.primary'),
|
|
34
|
+
}}
|
|
35
|
+
onDismissRequest={onDismiss}
|
|
36
|
+
>
|
|
37
|
+
<AlertDialog.Title>
|
|
25
38
|
<ComposeText color={theme.colorString('content.primary')} style={theme.typography.headingXs}>
|
|
26
39
|
{title}
|
|
27
40
|
</ComposeText>
|
|
28
|
-
|
|
41
|
+
</AlertDialog.Title>
|
|
42
|
+
{message ? (
|
|
43
|
+
<AlertDialog.Text>
|
|
29
44
|
<ComposeText color={theme.colorString('content.secondary')} style={theme.typography.body}>
|
|
30
45
|
{message}
|
|
31
46
|
</ComposeText>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
</AlertDialog.Text>
|
|
48
|
+
) : null}
|
|
49
|
+
<AlertDialog.ConfirmButton>
|
|
50
|
+
<TextButton
|
|
51
|
+
onClick={() => {
|
|
52
|
+
// As on iOS, where any action closes the alert and reports it through `onDismiss`.
|
|
53
|
+
onConfirm?.()
|
|
54
|
+
onDismiss()
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
<ComposeText
|
|
58
|
+
color={theme.colorString(destructive ? 'content.destructive' : 'content.accent')}
|
|
59
|
+
style={theme.typography.body}
|
|
60
|
+
>
|
|
61
|
+
{confirmLabel}
|
|
62
|
+
</ComposeText>
|
|
63
|
+
</TextButton>
|
|
64
|
+
</AlertDialog.ConfirmButton>
|
|
65
|
+
<AlertDialog.DismissButton>
|
|
66
|
+
<TextButton onClick={onDismiss}>
|
|
67
|
+
<ComposeText color={theme.colorString('content.accent')} style={theme.typography.body}>
|
|
68
|
+
Cancel
|
|
69
|
+
</ComposeText>
|
|
70
|
+
</TextButton>
|
|
71
|
+
</AlertDialog.DismissButton>
|
|
35
72
|
</AlertDialog>
|
|
36
73
|
)
|
|
37
74
|
}
|
|
@@ -1,56 +1,90 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {Text as ComposeText, DropdownMenu, DropdownMenuItem, Host} from '@expo/ui/jetpack-compose'
|
|
2
|
+
import {useSx} from '@hzblj/kara-sx'
|
|
3
3
|
import {useAppTheme} from '@hzblj/kara-theme'
|
|
4
|
-
import {useCallback,
|
|
5
|
-
|
|
6
|
-
import {useHostGuard} from '../../host-context'
|
|
4
|
+
import {useCallback, useState} from 'react'
|
|
5
|
+
import {Pressable, StyleSheet, View} from 'react-native'
|
|
7
6
|
import type {MenuAction} from '../menu'
|
|
8
|
-
import type {ContextMenuComponent, ContextMenuProps} from './context-menu.types'
|
|
7
|
+
import type {ContextMenuComponent, ContextMenuExclusionProps, ContextMenuProps} from './context-menu.types'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The menu's anchor: a point at the trigger's bottom start, so the dropdown opens just under it. The host lies outside
|
|
11
|
+
* the touch path — the dropdown is a popup window of its own, which takes its touches regardless.
|
|
12
|
+
*/
|
|
13
|
+
const styles = StyleSheet.create({
|
|
14
|
+
anchor: {bottom: 0, height: 1, left: 0, position: 'absolute', width: 1},
|
|
15
|
+
})
|
|
9
16
|
|
|
10
|
-
type
|
|
17
|
+
type MenuRowProps = {
|
|
11
18
|
action: MenuAction
|
|
12
19
|
onDismiss: () => void
|
|
13
20
|
}
|
|
14
21
|
|
|
15
|
-
/** A row's `
|
|
16
|
-
const
|
|
22
|
+
/** A row's `onClick` closes over its own action, so memoising it needs a component per row. */
|
|
23
|
+
const MenuRow = ({action, onDismiss}: MenuRowProps) => {
|
|
17
24
|
const theme = useAppTheme()
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}),
|
|
24
|
-
],
|
|
25
|
-
[action, onDismiss]
|
|
26
|
-
)
|
|
25
|
+
|
|
26
|
+
const onClick = useCallback(() => {
|
|
27
|
+
onDismiss()
|
|
28
|
+
action.onPress()
|
|
29
|
+
}, [action, onDismiss])
|
|
27
30
|
|
|
28
31
|
return (
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
<DropdownMenuItem onClick={onClick}>
|
|
33
|
+
<DropdownMenuItem.Text>
|
|
34
|
+
<ComposeText
|
|
35
|
+
color={theme.colorString(action.destructive ? 'content.destructive' : 'content.primary')}
|
|
36
|
+
style={theme.typography.body}
|
|
37
|
+
>
|
|
38
|
+
{action.label}
|
|
39
|
+
</ComposeText>
|
|
40
|
+
</DropdownMenuItem.Text>
|
|
41
|
+
</DropdownMenuItem>
|
|
36
42
|
)
|
|
37
43
|
}
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
/**
|
|
46
|
+
* The trigger stays a plain React Native subtree; a long press on it expands a Compose `DropdownMenu` anchored under
|
|
47
|
+
* it. The host behind the menu mounts on the first long press and stays — a list of triggers that are only scrolled
|
|
48
|
+
* past never builds one. `preview` and `onPreviewPress` are iOS-only: Material has no lifted preview.
|
|
49
|
+
*/
|
|
50
|
+
const ContextMenuRoot = ({actions, children, testID, ...props}: ContextMenuProps) => {
|
|
51
|
+
const {onPreviewPress: _onPreviewPress, preview: _preview, ...sx} = props
|
|
52
|
+
const theme = useAppTheme()
|
|
53
|
+
const style = useSx(sx)
|
|
54
|
+
const [isHostMounted, setIsHostMounted] = useState(false)
|
|
42
55
|
const [expanded, setExpanded] = useState(false)
|
|
56
|
+
|
|
57
|
+
const open = useCallback(() => {
|
|
58
|
+
setIsHostMounted(true)
|
|
59
|
+
setExpanded(true)
|
|
60
|
+
}, [])
|
|
61
|
+
|
|
43
62
|
const dismiss = useCallback(() => setExpanded(false), [])
|
|
44
|
-
const triggerModifiers = useMemo(() => [combinedClickable({onLongClick: () => setExpanded(true)})], [])
|
|
45
63
|
|
|
46
64
|
return (
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
<Pressable onLongPress={open} style={style} testID={testID}>
|
|
66
|
+
{children}
|
|
67
|
+
{isHostMounted ? (
|
|
68
|
+
<Host
|
|
69
|
+
colorScheme={theme.dark ? 'dark' : 'light'}
|
|
70
|
+
pointerEvents="none"
|
|
71
|
+
seedColor={theme.materialSeed}
|
|
72
|
+
style={styles.anchor}
|
|
73
|
+
>
|
|
74
|
+
<DropdownMenu expanded={expanded} onDismissRequest={dismiss}>
|
|
75
|
+
<DropdownMenu.Items>
|
|
76
|
+
{actions.map(action => (
|
|
77
|
+
<MenuRow action={action} key={action.label} onDismiss={dismiss} />
|
|
78
|
+
))}
|
|
79
|
+
</DropdownMenu.Items>
|
|
80
|
+
</DropdownMenu>
|
|
81
|
+
</Host>
|
|
82
|
+
) : null}
|
|
83
|
+
</Pressable>
|
|
55
84
|
)
|
|
56
85
|
}
|
|
86
|
+
|
|
87
|
+
/** A touchable inside the trigger already claims its own long press on Android, so this only has to group. */
|
|
88
|
+
const Exclusion = ({children}: ContextMenuExclusionProps) => <View>{children}</View>
|
|
89
|
+
|
|
90
|
+
export const ContextMenu: ContextMenuComponent = Object.assign(ContextMenuRoot, {Exclusion})
|
|
@@ -1,24 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {iconResourceName} from '@hzblj/kara-native'
|
|
2
|
+
import {
|
|
3
|
+
type ContextMenuItem,
|
|
4
|
+
ContextMenu as NativeContextMenu,
|
|
5
|
+
ContextMenuExclusion as NativeContextMenuExclusion,
|
|
6
|
+
} from '@hzblj/kara-native/swift-ui'
|
|
7
|
+
import {useSx} from '@hzblj/kara-sx'
|
|
8
|
+
import {useCallback, useMemo} from 'react'
|
|
9
|
+
import type {ContextMenuComponent, ContextMenuExclusionProps, ContextMenuProps} from './context-menu.types'
|
|
2
10
|
|
|
3
|
-
|
|
4
|
-
|
|
11
|
+
const ContextMenuRoot = ({actions, children, onPreviewPress, preview, testID, ...sx}: ContextMenuProps) => {
|
|
12
|
+
const style = useSx(sx)
|
|
5
13
|
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
/** The native side hands back an id; the index is the one identity every action has. */
|
|
15
|
+
const items = useMemo<ContextMenuItem[]>(
|
|
16
|
+
() =>
|
|
17
|
+
actions.map((action, index) => ({
|
|
18
|
+
destructive: action.destructive,
|
|
19
|
+
id: String(index),
|
|
20
|
+
image: action.icon ? iconResourceName(action.icon) : undefined,
|
|
21
|
+
title: action.label,
|
|
22
|
+
})),
|
|
23
|
+
[actions]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const onSelectItem = useCallback((id: string) => actions[Number(id)]?.onPress(), [actions])
|
|
8
27
|
|
|
9
28
|
return (
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
</SwiftUIContextMenu.Items>
|
|
21
|
-
<SwiftUIContextMenu.Trigger>{children}</SwiftUIContextMenu.Trigger>
|
|
22
|
-
</SwiftUIContextMenu>
|
|
29
|
+
<NativeContextMenu
|
|
30
|
+
items={items}
|
|
31
|
+
onPreviewPress={onPreviewPress}
|
|
32
|
+
onSelectItem={onSelectItem}
|
|
33
|
+
preview={preview}
|
|
34
|
+
style={style}
|
|
35
|
+
testID={testID}
|
|
36
|
+
>
|
|
37
|
+
{children}
|
|
38
|
+
</NativeContextMenu>
|
|
23
39
|
)
|
|
24
40
|
}
|
|
41
|
+
|
|
42
|
+
const Exclusion = ({children}: ContextMenuExclusionProps) => (
|
|
43
|
+
<NativeContextMenuExclusion>{children}</NativeContextMenuExclusion>
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
export const ContextMenu: ContextMenuComponent = Object.assign(ContextMenuRoot, {Exclusion})
|
|
@@ -1,10 +1,36 @@
|
|
|
1
|
+
import type {ResponsiveViewSx} from '@hzblj/kara-sx'
|
|
1
2
|
import type {ReactNode} from 'react'
|
|
2
|
-
|
|
3
3
|
import type {MenuAction} from '../menu'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A context menu on a React Native subtree — a card in a list, say — opened by a long press. iOS: a
|
|
7
|
+
* `UIContextMenuInteraction`, with an optional React Native `preview` lifted while the menu is open and a callback for
|
|
8
|
+
* a tap on it. Android: a Material dropdown under the subtree. The trigger is ordinary React Native layout, so it
|
|
9
|
+
* needs no `Screen` or `Island`.
|
|
10
|
+
*/
|
|
11
|
+
export type ContextMenuProps = ResponsiveViewSx & {
|
|
6
12
|
actions: MenuAction[]
|
|
13
|
+
/** The trigger, laid out as usual. */
|
|
7
14
|
children: ReactNode
|
|
15
|
+
/** iOS: the user tapped the lifted preview, committing to it — open the detail the card stands for. */
|
|
16
|
+
onPreviewPress?: () => void
|
|
17
|
+
/**
|
|
18
|
+
* iOS: lifted in place of the trigger while the menu is open — a larger version of the card, say. A snapshot of the
|
|
19
|
+
* trigger when unset. Mounted only once a finger has rested on the trigger, so a list of cards does not pay for
|
|
20
|
+
* every preview up front.
|
|
21
|
+
*/
|
|
22
|
+
preview?: ReactNode
|
|
23
|
+
testID?: string
|
|
8
24
|
}
|
|
9
25
|
|
|
10
|
-
export type
|
|
26
|
+
export type ContextMenuExclusionProps = {
|
|
27
|
+
children: ReactNode
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type ContextMenuComponent = ((props: ContextMenuProps) => ReactNode) & {
|
|
31
|
+
/**
|
|
32
|
+
* A region of the trigger that must not open the menu — a button inside the card. On iOS the interaction covers the
|
|
33
|
+
* whole trigger, so a long press on that button would otherwise open the card's menu.
|
|
34
|
+
*/
|
|
35
|
+
Exclusion: (props: ContextMenuExclusionProps) => ReactNode
|
|
36
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import {useAppTheme} from '@hzblj/kara-theme'
|
|
8
8
|
import {useCallback, useState} from 'react'
|
|
9
9
|
import {Icon} from '../../atoms/icon'
|
|
10
|
+
import {Glyph} from '../../glyph'
|
|
10
11
|
import {useHostGuard} from '../../host-context'
|
|
11
12
|
import type {MenuAction} from '../menu'
|
|
12
13
|
import type {FabMenuComponent, FabMenuProps} from './fab-menu.types'
|
|
@@ -46,7 +47,7 @@ const FabMenuRow = ({action, onSelect}: FabMenuRowProps) => {
|
|
|
46
47
|
* content — rather than a row of its own. The pills take the button's colours, so the menu reads as the button
|
|
47
48
|
* unfolding rather than a second surface.
|
|
48
49
|
*/
|
|
49
|
-
export const FabMenu: FabMenuComponent = ({actions, icon
|
|
50
|
+
export const FabMenu: FabMenuComponent = ({actions, icon}: FabMenuProps) => {
|
|
50
51
|
useHostGuard('FabMenu')
|
|
51
52
|
|
|
52
53
|
const theme = useAppTheme()
|
|
@@ -66,7 +67,7 @@ export const FabMenu: FabMenuComponent = ({actions, icon = 'add'}: FabMenuProps)
|
|
|
66
67
|
onCheckedChange={setExpanded}
|
|
67
68
|
>
|
|
68
69
|
<ToggleFloatingActionButton.Icon>
|
|
69
|
-
<Icon color="content.on.bg" name={icon} />
|
|
70
|
+
{icon ? <Icon color="content.on.bg" name={icon} /> : <Glyph color="content.on.bg" name="plus" />}
|
|
70
71
|
</ToggleFloatingActionButton.Icon>
|
|
71
72
|
</ToggleFloatingActionButton>
|
|
72
73
|
</FloatingActionButtonMenu.Button>
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {Button, Menu} from '@expo/ui/swift-ui'
|
|
2
|
-
import
|
|
1
|
+
import {Button, Image, Label, Menu} from '@expo/ui/swift-ui'
|
|
2
|
+
import {iconResourceName} from '@hzblj/kara-native'
|
|
3
3
|
|
|
4
|
-
import {Icon
|
|
4
|
+
import {Icon} from '../../atoms/icon'
|
|
5
5
|
import {VStack} from '../../atoms/v-stack'
|
|
6
|
+
import {Glyph} from '../../glyph'
|
|
6
7
|
import {useHostGuard} from '../../host-context'
|
|
7
8
|
import type {FabMenuComponent, FabMenuProps} from './fab-menu.types'
|
|
8
9
|
|
|
9
10
|
/** Matches `Fab`, so a screen can switch between the two without the button changing shape. */
|
|
10
11
|
const FAB_SIZE = 56
|
|
11
12
|
|
|
12
|
-
export const FabMenu: FabMenuComponent = ({actions, icon
|
|
13
|
+
export const FabMenu: FabMenuComponent = ({actions, icon, testID}: FabMenuProps) => {
|
|
13
14
|
useHostGuard('FabMenu')
|
|
14
15
|
|
|
15
16
|
return (
|
|
@@ -24,19 +25,19 @@ export const FabMenu: FabMenuComponent = ({actions, icon = 'add', testID}: FabMe
|
|
|
24
25
|
shadow="btn.accent"
|
|
25
26
|
w={FAB_SIZE}
|
|
26
27
|
>
|
|
27
|
-
<Icon color="content.on.bg" name={icon} />
|
|
28
|
+
{icon ? <Icon color="content.on.bg" name={icon} /> : <Glyph color="content.on.bg" name="plus" />}
|
|
28
29
|
</VStack>
|
|
29
30
|
}
|
|
30
31
|
testID={testID}
|
|
31
32
|
>
|
|
32
33
|
{actions.map(action => (
|
|
33
|
-
<Button
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
<Button key={action.label} onPress={action.onPress} role={action.destructive ? 'destructive' : 'default'}>
|
|
35
|
+
{/* A menu row is the system's Label: our icon is its image, from the asset catalog, and UIKit sizes it. */}
|
|
36
|
+
<Label
|
|
37
|
+
icon={action.icon ? <Image assetName={iconResourceName(action.icon)} /> : undefined}
|
|
38
|
+
title={action.label}
|
|
39
|
+
/>
|
|
40
|
+
</Button>
|
|
40
41
|
))}
|
|
41
42
|
</Menu>
|
|
42
43
|
)
|
|
@@ -10,7 +10,7 @@ import type {MenuAction} from '../menu'
|
|
|
10
10
|
*/
|
|
11
11
|
export type FabMenuProps = {
|
|
12
12
|
actions: MenuAction[]
|
|
13
|
-
/** The closed button's icon.
|
|
13
|
+
/** The closed button's icon — one of the app's. A plus by default. */
|
|
14
14
|
icon?: IconName
|
|
15
15
|
testID?: string
|
|
16
16
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type {ReactNode} from 'react'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A settings form — SwiftUI `Form` with its grouped sections, Material cards on Android. On iOS it scrolls like a
|
|
5
|
+
* `List`, so it needs a height from outside: a `Screen`, or an `Island` with `matchContents={false}` and a height. In
|
|
6
|
+
* an island that sizes itself to its content it has no height and shows nothing.
|
|
7
|
+
*/
|
|
3
8
|
export type FormProps = {
|
|
4
9
|
children: ReactNode
|
|
5
10
|
testID?: string
|
package/src/organisms/index.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {Text as ComposeText, DropdownMenu} from '@expo/ui/jetpack-compose'
|
|
2
|
-
import {clickable} from '@expo/ui/jetpack-compose/modifiers'
|
|
1
|
+
import {Text as ComposeText, DropdownMenu, DropdownMenuItem} from '@expo/ui/jetpack-compose'
|
|
3
2
|
import {useAppTheme} from '@hzblj/kara-theme'
|
|
4
|
-
import {useCallback,
|
|
3
|
+
import {useCallback, useState} from 'react'
|
|
5
4
|
import {HStack} from '../../atoms/h-stack'
|
|
6
5
|
import {Icon} from '../../atoms/icon'
|
|
7
|
-
import {Spacer} from '../../atoms/spacer'
|
|
8
6
|
import {Text} from '../../atoms/text'
|
|
9
|
-
import {
|
|
7
|
+
import {Glyph} from '../../glyph'
|
|
10
8
|
import {useHostGuard} from '../../host-context'
|
|
11
9
|
import type {MenuAction, MenuComponent, MenuProps} from './menu.types'
|
|
12
10
|
|
|
@@ -15,48 +13,56 @@ type MenuItemProps = {
|
|
|
15
13
|
onDismiss: () => void
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
/** A row's `clickable` closes over its own action, so memoising it needs a component per row. */
|
|
19
16
|
const MenuItem = ({action, onDismiss}: MenuItemProps) => {
|
|
20
17
|
const theme = useAppTheme()
|
|
21
|
-
const
|
|
22
|
-
() => [
|
|
23
|
-
clickable(() => {
|
|
24
|
-
onDismiss()
|
|
25
|
-
action.onPress()
|
|
26
|
-
}),
|
|
27
|
-
],
|
|
28
|
-
[action, onDismiss]
|
|
29
|
-
)
|
|
18
|
+
const color = action.destructive ? 'content.destructive' : 'content.primary'
|
|
30
19
|
|
|
31
20
|
return (
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
<DropdownMenuItem
|
|
22
|
+
elementColors={{leadingIconColor: theme.color(color), textColor: theme.color(color)}}
|
|
23
|
+
onClick={() => {
|
|
24
|
+
onDismiss()
|
|
25
|
+
action.onPress()
|
|
26
|
+
}}
|
|
36
27
|
>
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
<DropdownMenuItem.Text>
|
|
29
|
+
<ComposeText color={theme.colorString(color)} style={theme.typography.body}>
|
|
30
|
+
{action.label}
|
|
31
|
+
</ComposeText>
|
|
32
|
+
</DropdownMenuItem.Text>
|
|
33
|
+
{action.icon ? (
|
|
34
|
+
<DropdownMenuItem.LeadingIcon>
|
|
35
|
+
<Icon color={color} name={action.icon} size="s20" />
|
|
36
|
+
</DropdownMenuItem.LeadingIcon>
|
|
37
|
+
) : null}
|
|
38
|
+
</DropdownMenuItem>
|
|
39
39
|
)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Material's dropdown menu, anchored to its trigger. The items live in the `Items` slot, which Compose presents in
|
|
44
|
+
* its own popup — anywhere else they would be laid out in place, on top of the trigger.
|
|
45
|
+
*/
|
|
42
46
|
export const Menu: MenuComponent = ({actions, label}: MenuProps) => {
|
|
43
47
|
useHostGuard('Menu')
|
|
44
48
|
|
|
49
|
+
const theme = useAppTheme()
|
|
45
50
|
const [expanded, setExpanded] = useState(false)
|
|
46
51
|
const dismiss = useCallback(() => setExpanded(false), [])
|
|
47
52
|
|
|
48
53
|
return (
|
|
49
|
-
<
|
|
50
|
-
<
|
|
51
|
-
<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
<DropdownMenu color={theme.color('surface.primary')} expanded={expanded} onDismissRequest={dismiss}>
|
|
55
|
+
<DropdownMenu.Trigger>
|
|
56
|
+
<HStack align="center" onPress={() => setExpanded(true)} spacing="s4">
|
|
57
|
+
<Text color="content.accent">{label}</Text>
|
|
58
|
+
<Glyph color="content.accent" name="chevronDown" size="s16" />
|
|
59
|
+
</HStack>
|
|
60
|
+
</DropdownMenu.Trigger>
|
|
61
|
+
<DropdownMenu.Items>
|
|
55
62
|
{actions.map(action => (
|
|
56
63
|
<MenuItem action={action} key={action.label} onDismiss={dismiss} />
|
|
57
64
|
))}
|
|
58
|
-
</DropdownMenu>
|
|
59
|
-
|
|
60
|
-
</VStack>
|
|
65
|
+
</DropdownMenu.Items>
|
|
66
|
+
</DropdownMenu>
|
|
61
67
|
)
|
|
62
68
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# @hzblj/kara-components
|
|
2
|
-
|
|
3
|
-
## 0.1.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- [`f919c7b`](https://github.com/hzblj/kara-ui/commit/f919c7b06f3798cebd58eef1581076bf1ee61cd1) Thanks [@hzblj](https://github.com/hzblj)! - First release of the kara-ui design system: theme and tokens, the `sx` engine, atoms, molecules, organisms and `Screen`, native tabs (`@hzblj/kara-ui/router`), the KaraUI native module (Liquid Glass, scroll edge effect, native countdown, context menu with preview, rich tooltip, FAB menu), and `KaraProvider` with theme overrides — colours, the app's own fonts, the Material seed, and Material You dynamic colour on Android. Text uses the platform's face by default. Install `@hzblj/kara-ui`; the scoped packages are its building blocks.
|
|
8
|
-
|
|
9
|
-
### Patch Changes
|
|
10
|
-
|
|
11
|
-
- Updated dependencies [[`f919c7b`](https://github.com/hzblj/kara-ui/commit/f919c7b06f3798cebd58eef1581076bf1ee61cd1)]:
|
|
12
|
-
- @hzblj/kara-theme@0.1.0
|
|
13
|
-
- @hzblj/kara-sx@0.1.0
|
|
14
|
-
- @hzblj/kara-native@0.1.0
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { MAX_FONT_SCALE, useAppTheme } from '@hzblj/kara-theme';
|
|
4
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
5
|
-
import { StyleSheet, Text, useWindowDimensions, View } from 'react-native';
|
|
6
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
-
const SECOND_MS = 1000;
|
|
8
|
-
const HOUR = 3600;
|
|
9
|
-
const DAY = 86_400;
|
|
10
|
-
const DIVIDER = ' / ';
|
|
11
|
-
|
|
12
|
-
/** Wakes a beat after the shape changes, so the frame never reads the boundary second twice. */
|
|
13
|
-
const SHAPE_CHANGE_SLACK_MS = 50;
|
|
14
|
-
const remainingSeconds = endsAt => Math.max(0, Math.round((endsAt - Date.now()) / SECOND_MS));
|
|
15
|
-
const countdownShape = endsAt => {
|
|
16
|
-
const remaining = remainingSeconds(endsAt);
|
|
17
|
-
return {
|
|
18
|
-
days: Math.floor(remaining / DAY),
|
|
19
|
-
hasHours: remaining >= HOUR
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/** When the next segment drops out — the last day, then the last hour — or `null` once only minutes are left. */
|
|
24
|
-
const nextShapeChange = (endsAt, {
|
|
25
|
-
days,
|
|
26
|
-
hasHours
|
|
27
|
-
}) => {
|
|
28
|
-
if (days > 0) {
|
|
29
|
-
return endsAt - (days * DAY - 0.5) * SECOND_MS;
|
|
30
|
-
}
|
|
31
|
-
if (hasHours) {
|
|
32
|
-
return endsAt - (HOUR - 0.5) * SECOND_MS;
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/** The countdown's shape changes twice at most, so this re-renders twice at most — never once a second. */
|
|
38
|
-
const useCountdownShape = endsAt => {
|
|
39
|
-
const [shape, setShape] = useState(() => countdownShape(endsAt));
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
let timeout;
|
|
42
|
-
const update = () => {
|
|
43
|
-
const next = countdownShape(endsAt);
|
|
44
|
-
setShape(current => current.days === next.days && current.hasHours === next.hasHours ? current : next);
|
|
45
|
-
const changesAt = nextShapeChange(endsAt, next);
|
|
46
|
-
if (changesAt !== null) {
|
|
47
|
-
timeout = setTimeout(update, Math.max(0, changesAt - Date.now()) + SHAPE_CHANGE_SLACK_MS);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
update();
|
|
51
|
-
return () => clearTimeout(timeout);
|
|
52
|
-
}, [endsAt]);
|
|
53
|
-
return shape;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/** The widest string the countdown can show in its current shape, with zeros standing in for the digits. */
|
|
57
|
-
const countdownTemplate = ({
|
|
58
|
-
days,
|
|
59
|
-
hasHours
|
|
60
|
-
}, [day, hour, minute, second]) => {
|
|
61
|
-
let template = '';
|
|
62
|
-
if (days > 0) {
|
|
63
|
-
template += `${'0'.repeat(String(days).length)}${day}${DIVIDER}`;
|
|
64
|
-
}
|
|
65
|
-
if (hasHours) {
|
|
66
|
-
template += `00${hour}${DIVIDER}`;
|
|
67
|
-
}
|
|
68
|
-
return `${template}00${minute}${DIVIDER}00${second}`;
|
|
69
|
-
};
|
|
70
|
-
const styles = StyleSheet.create({
|
|
71
|
-
template: {
|
|
72
|
-
opacity: 0
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
/**
|
|
76
|
-
* What gives the native countdown its size: an invisible React Native text of exactly the shape it draws, set the way
|
|
77
|
-
* `RnText` sets the same variant, so the countdown takes the space any text of that variant would — and the native view
|
|
78
|
-
* laid over it has to match it to the point. Accessibility reads the native view, never this.
|
|
79
|
-
*/
|
|
80
|
-
export const CountdownFrame = ({
|
|
81
|
-
children,
|
|
82
|
-
endsAt,
|
|
83
|
-
testID,
|
|
84
|
-
units,
|
|
85
|
-
variant
|
|
86
|
-
}) => {
|
|
87
|
-
const theme = useAppTheme();
|
|
88
|
-
const {
|
|
89
|
-
fontScale
|
|
90
|
-
} = useWindowDimensions();
|
|
91
|
-
const shape = useCountdownShape(endsAt);
|
|
92
|
-
const template = useMemo(() => countdownTemplate(shape, units), [shape, units]);
|
|
93
|
-
const style = theme.typography[variant];
|
|
94
|
-
|
|
95
|
-
/** As in `RnText`: React Native grows the glyphs but not the line, so the line grows here by the same capped factor. */
|
|
96
|
-
const lineHeight = style.lineHeight * Math.min(fontScale, MAX_FONT_SCALE);
|
|
97
|
-
return /*#__PURE__*/_jsxs(View, {
|
|
98
|
-
testID: testID,
|
|
99
|
-
children: [/*#__PURE__*/_jsx(View, {
|
|
100
|
-
accessibilityElementsHidden: true,
|
|
101
|
-
importantForAccessibility: "no-hide-descendants",
|
|
102
|
-
style: styles.template,
|
|
103
|
-
children: /*#__PURE__*/_jsx(Text, {
|
|
104
|
-
maxFontSizeMultiplier: MAX_FONT_SCALE,
|
|
105
|
-
numberOfLines: 1,
|
|
106
|
-
style: [style, {
|
|
107
|
-
fontVariant: ['tabular-nums'],
|
|
108
|
-
lineHeight
|
|
109
|
-
}],
|
|
110
|
-
children: template
|
|
111
|
-
})
|
|
112
|
-
}), children]
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
//# sourceMappingURL=countdown-frame.js.map
|