aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/demos/MenusDemo.tsx
blob: c928e6f7927210db1b44a9e535a4b5b8109c4f70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { useState } from 'react'
import { Avatar } from '@astryxdesign/core/Avatar'
import { Button } from '@astryxdesign/core/Button'
import { Card } from '@astryxdesign/core/Card'
import { ContextMenu } from '@astryxdesign/core/ContextMenu'
import { DropdownMenu } from '@astryxdesign/core/DropdownMenu'
import { HStack } from '@astryxdesign/core/HStack'
import { Heading } from '@astryxdesign/core/Heading'
import { HoverCard } from '@astryxdesign/core/HoverCard'
import { MoreMenu } from '@astryxdesign/core/MoreMenu'
import { Popover } from '@astryxdesign/core/Popover'
import { Text } from '@astryxdesign/core/Text'
import { Tooltip } from '@astryxdesign/core/Tooltip'
import { VStack } from '@astryxdesign/core/VStack'

export function MenusDemo() {
  const [popoverOpen, setPopoverOpen] = useState(false)

  return (
    <VStack gap={4}>
      <HStack gap={2} wrap="wrap" vAlign="center">
        <DropdownMenu
          button={{ label: '操作菜单' }}
          items={[
            { label: '编辑', onClick: () => {} },
            { label: '复制', onClick: () => {} },
            { label: '删除', onClick: () => {} },
          ]}
        />
        <MoreMenu
          items={[
            { label: '导出', onClick: () => {} },
            { label: '分享', onClick: () => {} },
            { label: '归档', onClick: () => {} },
          ]}
        />
        <Tooltip content="这是一段提示文字" placement="above">
          <Button label="悬停查看提示" variant="secondary" />
        </Tooltip>
        <Popover
          isOpen={popoverOpen}
          onOpenChange={setPopoverOpen}
          hasAutoFocus={false}
          placement="below"
          label="设置"
          width={260}
          content={
            <VStack gap={2}>
              <Heading level={4}>快捷设置</Heading>
              <Text type="body" color="secondary" as="p">
                弹层可以承载简短设置、筛选或上下文信息。
              </Text>
            </VStack>
          }>
          <Button label="打开浮层" variant="secondary" />
        </Popover>
        <HoverCard
          placement="above"
          content={
            <VStack gap={2} width={220}>
              <HStack gap={2} vAlign="center">
                <Avatar name="林晓" size="md" />
                <VStack gap={0}>
                  <Heading level={5}>林晓</Heading>
                  <Text type="supporting" size="sm">
                    产品设计
                  </Text>
                </VStack>
              </HStack>
              <Text type="body" color="secondary" as="p">
                专注于设计系统与复杂交互体验。
              </Text>
            </VStack>
          }>
          <Button label="悬停查看资料" variant="ghost" />
        </HoverCard>
      </HStack>

      <ContextMenu
        presentation="adaptive"
        items={[
          { label: '剪切', onClick: () => {} },
          { label: '复制', onClick: () => {} },
          { label: '粘贴', onClick: () => {} },
        ]}>
        <Card padding={4}>
          <VStack gap={1} hAlign="center">
            <Text type="label">右键或长按此区域</Text>
            <Text type="supporting" size="sm">
              打开上下文菜单
            </Text>
          </VStack>
        </Card>
      </ContextMenu>
    </VStack>
  )
}