Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support shortcuts text on ActionList(OK-30711) #5887

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions packages/components/src/actions/ActionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import {
Heading,
Icon,
SizableText,
XStack,
YStack,
} from '../../primitives';
import { Popover } from '../Popover';
import { Shortcut } from '../Shortcut';
import { Trigger } from '../Trigger';

import type { IIconProps, IKeyOfIcons } from '../../primitives';
Expand All @@ -33,6 +35,7 @@ export interface IActionListItemProps {
onPress?: (close: () => void) => void | Promise<boolean | void>;
disabled?: boolean;
testID?: string;
shortcutKeys?: string[];
}

export function ActionListItem({
Expand All @@ -44,6 +47,7 @@ export function ActionListItem({
disabled,
onClose,
testID,
shortcutKeys,
originalix marked this conversation as resolved.
Show resolved Hide resolved
}: IActionListItemProps & {
onClose: () => void;
}) {
Expand Down Expand Up @@ -86,24 +90,38 @@ export function ActionListItem({
onPress={handlePress}
testID={testID}
>
{icon ? (
<Icon
name={icon}
size="$5"
mr="$3"
$md={{ size: '$6' }}
color={destructive ? '$iconCritical' : '$icon'}
{...iconProps}
/>
) : null}
<SizableText
textAlign="left"
size="$bodyMd"
$md={{ size: '$bodyLg' }}
color={destructive ? '$textCritical' : '$text'}
>
{label}
</SizableText>
<XStack jc="space-between" flex={1}>
<XStack>
{icon ? (
<Icon
name={icon}
size="$5"
mr="$3"
$md={{ size: '$6' }}
color={destructive ? '$iconCritical' : '$icon'}
{...iconProps}
/>
) : null}
<SizableText
textAlign="left"
size="$bodyMd"
$md={{ size: '$bodyLg' }}
color={destructive ? '$textCritical' : '$text'}
>
{label}
</SizableText>
</XStack>
{(platformEnv.isDesktop || platformEnv.isNativeIOSPad) &&
shortcutKeys?.length ? (
<XStack>
<Shortcut>
{shortcutKeys.map((key) => (
<Shortcut.Key key={key}>{key}</Shortcut.Key>
))}
</Shortcut>
</XStack>
) : null}
</XStack>
originalix marked this conversation as resolved.
Show resolved Hide resolved
</ButtonFrame>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Stack,
YStack,
} from '@onekeyhq/components';
import { shortcutsKeys } from '@onekeyhq/shared/src/shortcuts/shortcutsKeys.enum';

import { Layout } from './utils/Layout';

Expand Down Expand Up @@ -166,6 +167,7 @@ const ActionListDemo3 = () => (
{
label: 'Action2',
icon: 'PlaceholderOutline',
shortcutKeys: [shortcutsKeys.CmdOrCtrl, 'k'],
originalix marked this conversation as resolved.
Show resolved Hide resolved
onPress: () => {
console.log('action2');
},
Expand Down Expand Up @@ -243,6 +245,49 @@ const ActionListGallery = () => (
</Stack>
),
},
{
title: 'shortcuts',
element: (
<ActionList
title="Action List(Close demo)"
renderTrigger={
<Button onPress={() => console.log('trigger')}>
Action List
</Button>
}
sections={[
{
items: [
{
label: 'just close it',
icon: 'PlaceholderOutline',
shortcutKeys: [
shortcutsKeys.CmdOrCtrl,
shortcutsKeys.Alt,
'k',
],
onPress: () => {
console.log('action1');
},
},
{
label: 'async action(fail)',
icon: 'PlaceholderOutline',
shortcutKeys: [shortcutsKeys.CmdOrCtrl, 'o'],
onPress: () =>
new Promise((resolve) => {
setTimeout(() => {
alert('fail');
resolve(false);
}, 1000);
}),
},
],
},
]}
/>
),
},
originalix marked this conversation as resolved.
Show resolved Hide resolved
{
title: 'Long Press',
element: (
Expand Down
Loading