@hyphen/hyphen-components 2.23.0 → 2.24.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.
@@ -14,7 +14,7 @@ export declare const FONT_FAMILY_OPTIONS: ("monospace" | "body" | "brand")[];
14
14
  export declare const FONT_WEIGHT_OPTIONS: ("light" | "normal" | "medium" | "semibold" | "bold")[];
15
15
  export declare const HEADING_SIZE_OPTIONS: ("sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl")[];
16
16
  export declare const HEIGHT_OPTIONS: ("0" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "2xs" | "4xl" | "5xl" | "6xl" | "7xl" | "8xl" | "9xl" | "10xl" | "10" | "15" | "20" | "25" | "30" | "33" | "34" | "40" | "50" | "60" | "70" | "75" | "80" | "90" | "100")[];
17
- export declare const LINE_HEIGHT_OPTIONS: ("base" | "input" | "heading" | "text")[];
17
+ export declare const LINE_HEIGHT_OPTIONS: ("base" | "none" | "input" | "heading" | "text")[];
18
18
  export declare const SPACING_OPTIONS: ("0" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "2xs" | "4xl" | "5xl" | "auto")[];
19
19
  export declare const WIDTH_OPTIONS: ("0" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "2xs" | "4xl" | "5xl" | "6xl" | "7xl" | "8xl" | "9xl" | "10xl" | "10" | "15" | "20" | "25" | "30" | "33" | "34" | "40" | "50" | "60" | "70" | "75" | "80" | "90" | "100")[];
20
20
  export declare const Z_INDEX_OPTIONS: ("0" | "modal" | "popover" | "overlay" | "drawer" | "sticky")[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyphen/hyphen-components",
3
- "version": "2.23.0",
3
+ "version": "2.24.0",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "@hyphen"
@@ -122,9 +122,10 @@
122
122
  "@rollup/rollup-linux-x64-gnu": "^4.21.2"
123
123
  },
124
124
  "dependencies": {
125
- "@hyphen/hyphen-design-tokens": "^4.17.0",
125
+ "@hyphen/hyphen-design-tokens": "^4.18.0",
126
126
  "@popperjs/core": "^2.11.8",
127
127
  "@radix-ui/react-collapsible": "^1.1.1",
128
+ "@radix-ui/react-dropdown-menu": "^2.1.2",
128
129
  "@types/react-modal": "^3.16.3",
129
130
  "classnames": "^2.5.1",
130
131
  "date-fns": "^2.16.1",
@@ -16,6 +16,6 @@ This component is extended from [Radix](https://www.radix-ui.com/primitives/docs
16
16
 
17
17
  ## Controlled
18
18
 
19
- The `isOpen` prop can be used to control the state of the collapsible component.
19
+ The `open` prop can be used to control the state of the collapsible component.
20
20
 
21
21
  <Canvas of={Stories.Controlled} />
@@ -1,5 +1,3 @@
1
- 'use client';
2
-
3
1
  import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
4
2
 
5
3
  const Collapsible = CollapsiblePrimitive.Root;
@@ -0,0 +1,21 @@
1
+ import { Canvas, Meta, ArgTypes } from '@storybook/blocks';
2
+ import { DropdownMenu } from './DropdownMenu';
3
+ import * as Stories from './DropdownMenu.stories';
4
+
5
+ <Meta of={Stories} />
6
+
7
+ # DropdownMenu
8
+
9
+ DropdownMenu components are used to hide or show content based on user interaction.
10
+
11
+ This component is extended from [Radix](https://www.radix-ui.com/primitives/docs/components/dropdown-menu).
12
+
13
+ [API Reference](https://www.radix-ui.com/primitives/docs/components/dropdown-menu#api-reference)
14
+
15
+ <Canvas of={Stories.Uncontrolled} />
16
+
17
+ ## Controlled
18
+
19
+ The `open` prop can be used to control the state of the DropdownMenu component.
20
+
21
+ <Canvas of={Stories.Controlled} />
@@ -0,0 +1,150 @@
1
+ import React from 'react';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+ import { Button } from '../Button/Button';
4
+ import { userEvent, within, expect } from '@storybook/test';
5
+ import {
6
+ DropdownMenu,
7
+ DropdownMenuTrigger,
8
+ DropdownMenuContent,
9
+ DropdownMenuLabel,
10
+ DropdownMenuSeparator,
11
+ DropdownMenuGroup,
12
+ DropdownMenuItem,
13
+ DropdownMenuSub,
14
+ DropdownMenuSubContent,
15
+ DropdownMenuSubTrigger,
16
+ DropdownMenuPortal,
17
+ } from './DropdownMenu';
18
+ import { DropdownMenuShortcut } from './DropdownMenu';
19
+
20
+ const meta: Meta<typeof DropdownMenu> = {
21
+ title: 'Components/DropdownMenu',
22
+ component: DropdownMenu,
23
+ };
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof DropdownMenu>;
27
+
28
+ export const Uncontrolled = () => (
29
+ <DropdownMenu>
30
+ <DropdownMenuTrigger asChild>
31
+ <Button variant="secondary">Open</Button>
32
+ </DropdownMenuTrigger>
33
+ <DropdownMenuContent
34
+ className="w-9xl"
35
+ align="start"
36
+ side="bottom"
37
+ sideOffset={4}
38
+ >
39
+ <DropdownMenuLabel>My Account</DropdownMenuLabel>
40
+ <DropdownMenuSeparator />
41
+ <DropdownMenuGroup>
42
+ <DropdownMenuItem>
43
+ <span>Profile</span>
44
+ <DropdownMenuShortcut>⇧⌘P</DropdownMenuShortcut>
45
+ </DropdownMenuItem>
46
+ <DropdownMenuItem>
47
+ <span>Billing</span>
48
+ <DropdownMenuShortcut>⌘B</DropdownMenuShortcut>
49
+ </DropdownMenuItem>
50
+ <DropdownMenuItem>
51
+ <span>Settings</span>
52
+ <DropdownMenuShortcut>⌘S</DropdownMenuShortcut>
53
+ </DropdownMenuItem>
54
+ <DropdownMenuItem>
55
+ <span>Keyboard shortcuts</span>
56
+ <DropdownMenuShortcut>⌘K</DropdownMenuShortcut>
57
+ </DropdownMenuItem>
58
+ </DropdownMenuGroup>
59
+ <DropdownMenuSeparator />
60
+ <DropdownMenuGroup>
61
+ <DropdownMenuItem>
62
+ <span>Team</span>
63
+ </DropdownMenuItem>
64
+ <DropdownMenuSub>
65
+ <DropdownMenuSubTrigger>
66
+ <span>Invite users</span>
67
+ </DropdownMenuSubTrigger>
68
+ <DropdownMenuPortal>
69
+ <DropdownMenuSubContent>
70
+ <DropdownMenuItem>
71
+ <span>Email</span>
72
+ </DropdownMenuItem>
73
+ <DropdownMenuItem>
74
+ <span>Message</span>
75
+ </DropdownMenuItem>
76
+ <DropdownMenuSeparator />
77
+ <DropdownMenuItem>
78
+ <span>More...</span>
79
+ </DropdownMenuItem>
80
+ </DropdownMenuSubContent>
81
+ </DropdownMenuPortal>
82
+ </DropdownMenuSub>
83
+ <DropdownMenuItem>
84
+ <span>New Team</span>
85
+ <DropdownMenuShortcut>⌘+T</DropdownMenuShortcut>
86
+ </DropdownMenuItem>
87
+ </DropdownMenuGroup>
88
+ <DropdownMenuSeparator />
89
+ <DropdownMenuItem>
90
+ <span>Support</span>
91
+ </DropdownMenuItem>
92
+ <DropdownMenuItem disabled>
93
+ <span>API</span>
94
+ </DropdownMenuItem>
95
+ <DropdownMenuSeparator />
96
+ <DropdownMenuItem>
97
+ <span>Log out</span>
98
+ <DropdownMenuShortcut>⇧⌘Q</DropdownMenuShortcut>
99
+ </DropdownMenuItem>
100
+ </DropdownMenuContent>
101
+ </DropdownMenu>
102
+ );
103
+
104
+ export const Controlled = () => {
105
+ const [isOpen, setIsOpen] = React.useState(false);
106
+
107
+ return (
108
+ <div>
109
+ <p>{`Dropdown is ${isOpen ? 'open' : 'closed'}`}</p>
110
+ <DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
111
+ <DropdownMenuTrigger asChild>
112
+ <Button variant="secondary">Dropdown</Button>
113
+ </DropdownMenuTrigger>
114
+ <DropdownMenuContent
115
+ className="w-9xl"
116
+ align="start"
117
+ side="bottom"
118
+ sideOffset={4}
119
+ >
120
+ <DropdownMenuItem>
121
+ <span>Profile</span>
122
+ <DropdownMenuShortcut>⇧⌘P</DropdownMenuShortcut>
123
+ </DropdownMenuItem>
124
+ <DropdownMenuItem>
125
+ <span>Billing</span>
126
+ <DropdownMenuShortcut>⌘B</DropdownMenuShortcut>
127
+ </DropdownMenuItem>
128
+ <DropdownMenuItem>
129
+ <span>Settings</span>
130
+ <DropdownMenuShortcut>⌘S</DropdownMenuShortcut>
131
+ </DropdownMenuItem>
132
+ <DropdownMenuItem>
133
+ <span>Keyboard shortcuts</span>
134
+ <DropdownMenuShortcut>⌘K</DropdownMenuShortcut>
135
+ </DropdownMenuItem>
136
+ </DropdownMenuContent>
137
+ </DropdownMenu>
138
+ </div>
139
+ );
140
+ };
141
+
142
+ export const ClickOpenDropdown: Story = {
143
+ play: async ({ canvasElement, mount }) => {
144
+ await mount(<Controlled />);
145
+ const canvas = within(canvasElement);
146
+ await expect(canvas.getByText('Dropdown is closed')).toBeInTheDocument();
147
+ await userEvent.click(canvas.getByText('Dropdown'));
148
+ await expect(canvas.getByText('Dropdown is open')).toBeInTheDocument();
149
+ },
150
+ };
@@ -0,0 +1,164 @@
1
+ import React from 'react';
2
+ import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
3
+
4
+ import classNames from 'classnames';
5
+ import { Icon } from '../Icon/Icon';
6
+
7
+ const DropdownMenu = DropdownMenuPrimitive.Root;
8
+
9
+ const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
10
+
11
+ const DropdownMenuGroup = DropdownMenuPrimitive.Group;
12
+
13
+ const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
14
+
15
+ const DropdownMenuSub = DropdownMenuPrimitive.Sub;
16
+
17
+ const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
18
+
19
+ const DropdownMenuItem = React.forwardRef<
20
+ React.ElementRef<typeof DropdownMenuPrimitive.Item>,
21
+ React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
22
+ inset?: boolean;
23
+ }
24
+ >(({ className, inset, ...props }, ref) => (
25
+ <DropdownMenuPrimitive.Item
26
+ ref={ref}
27
+ className={classNames(
28
+ 'font-size-sm position-relative cursor-default display-flex br-sm align-items-center p-sm g-sm outline-none hover:background-color-secondary focus:background-color-secondary',
29
+ inset && 'p-left-md',
30
+ className
31
+ )}
32
+ {...props}
33
+ />
34
+ ));
35
+ DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
36
+
37
+ const DropdownMenuContent = React.forwardRef<
38
+ React.ElementRef<typeof DropdownMenuPrimitive.Content>,
39
+ React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
40
+ >(({ className, sideOffset = 4, ...props }, ref) => (
41
+ <DropdownMenuPrimitive.Portal>
42
+ <DropdownMenuPrimitive.Content
43
+ ref={ref}
44
+ sideOffset={sideOffset}
45
+ className={classNames(
46
+ 'z-index-popover p-xs minw-7xl overflow-hidden br-sm bw-sm border-color-subtle background-color-primary font-color-base shadow-md',
47
+ className
48
+ )}
49
+ style={{
50
+ width: 'var(--radix-dropdown-menu-trigger-width)',
51
+ }}
52
+ {...props}
53
+ />
54
+ </DropdownMenuPrimitive.Portal>
55
+ ));
56
+ DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
57
+
58
+ const DropdownMenuLabel = React.forwardRef<
59
+ React.ElementRef<typeof DropdownMenuPrimitive.Label>,
60
+ React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
61
+ inset?: boolean;
62
+ }
63
+ >(({ className, inset, ...props }, ref) => (
64
+ <DropdownMenuPrimitive.Label
65
+ ref={ref}
66
+ className={classNames(
67
+ 'display-flex align-items-center br-sm p-h-sm p-v-xs font-color-secondary font-size-xs font-weight-medium outline-none',
68
+ inset && 'p-left-md',
69
+ className
70
+ )}
71
+ {...props}
72
+ />
73
+ ));
74
+ DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
75
+
76
+ const DropdownMenuSeparator = React.forwardRef<
77
+ React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
78
+ React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
79
+ >(({ className, ...props }, ref) => (
80
+ <DropdownMenuPrimitive.Separator
81
+ ref={ref}
82
+ className={classNames(
83
+ 'h-2xs m-v-xs bw-top-sm border-color-subtle',
84
+ className
85
+ )}
86
+ style={{
87
+ marginLeft: 'calc(var(--size-spacing-md)*-1)',
88
+ marginRight: 'calc(var(--size-spacing-md)*-1)',
89
+ }}
90
+ {...props}
91
+ />
92
+ ));
93
+ DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
94
+
95
+ const DropdownMenuShortcut = ({
96
+ className,
97
+ ...props
98
+ }: React.HTMLAttributes<HTMLSpanElement>) => {
99
+ return (
100
+ <span
101
+ className={classNames(
102
+ 'm-left-auto font-size-xs font-color-tertiary',
103
+ className
104
+ )}
105
+ style={{ letterSpacing: '0.5px' }}
106
+ {...props}
107
+ />
108
+ );
109
+ };
110
+ DropdownMenuShortcut.displayName = 'DropdownMenuShortcut';
111
+
112
+ const DropdownMenuSubTrigger = React.forwardRef<
113
+ React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
114
+ React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
115
+ inset?: boolean;
116
+ }
117
+ >(({ className, inset, children, ...props }, ref) => (
118
+ <DropdownMenuPrimitive.SubTrigger
119
+ ref={ref}
120
+ className={classNames(
121
+ 'display-flex cursor-default gap-xl align-items-center br-sm p-sm g-sm font-size-sm outline-none focus:background-color-secondary',
122
+ inset && 'p-left-md',
123
+ className
124
+ )}
125
+ {...props}
126
+ >
127
+ {children}
128
+ <Icon name="caret-sm-right" className="m-left-auto" />
129
+ </DropdownMenuPrimitive.SubTrigger>
130
+ ));
131
+ DropdownMenuSubTrigger.displayName =
132
+ DropdownMenuPrimitive.SubTrigger.displayName;
133
+
134
+ const DropdownMenuSubContent = React.forwardRef<
135
+ React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
136
+ React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
137
+ >(({ className, ...props }, ref) => (
138
+ <DropdownMenuPrimitive.SubContent
139
+ ref={ref}
140
+ className={classNames(
141
+ 'z-index-popover minw-7xl overflow-hidden br-sm border-color-subtle bw-sm background-color-primary p-xs font-color-primary shadow-lg',
142
+ className
143
+ )}
144
+ {...props}
145
+ />
146
+ ));
147
+ DropdownMenuSubContent.displayName =
148
+ DropdownMenuPrimitive.SubContent.displayName;
149
+
150
+ export {
151
+ DropdownMenu,
152
+ DropdownMenuTrigger,
153
+ DropdownMenuContent,
154
+ DropdownMenuItem,
155
+ DropdownMenuLabel,
156
+ DropdownMenuSeparator,
157
+ DropdownMenuShortcut,
158
+ DropdownMenuSubContent,
159
+ DropdownMenuSubTrigger,
160
+ DropdownMenuGroup,
161
+ DropdownMenuPortal,
162
+ DropdownMenuSub,
163
+ DropdownMenuRadioGroup,
164
+ };
@@ -7,3 +7,7 @@
7
7
  @import './text-align';
8
8
  @import './white-space';
9
9
  @import './position';
10
+
11
+ .outline-none {
12
+ outline: none;
13
+ }