dst-rg 1.0.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.
Files changed (249) hide show
  1. package/.gitlab-ci.yml +43 -0
  2. package/.storybook/main.ts +15 -0
  3. package/.storybook/preview.ts +15 -0
  4. package/README.md +254 -0
  5. package/components.json +21 -0
  6. package/dist/Avatar.png +0 -0
  7. package/dist/assets/index-CCq7hmG3.js +186 -0
  8. package/dist/assets/index-Mg-hjQGu.css +1 -0
  9. package/dist/index.html +15 -0
  10. package/dist/test.png +0 -0
  11. package/dist/vite.svg +1 -0
  12. package/eslint.config.js +29 -0
  13. package/index.html +14 -0
  14. package/package.json +102 -0
  15. package/postcss.config.mjs +11 -0
  16. package/rollup.config.mjs +55 -0
  17. package/src/assets/react.svg +1 -0
  18. package/src/assets/style/animation.css +27 -0
  19. package/src/assets/style/box-shadow.css +25 -0
  20. package/src/assets/style/colors.css +402 -0
  21. package/src/assets/style/dark-theme.css +288 -0
  22. package/src/assets/style/font-size.css +14 -0
  23. package/src/assets/style/gradient.css +3 -0
  24. package/src/assets/style/index.css +12 -0
  25. package/src/assets/style/light-theme.css +148 -0
  26. package/src/assets/style/line-height.css +13 -0
  27. package/src/assets/style/max-width.css +5 -0
  28. package/src/assets/style/radius.css +13 -0
  29. package/src/assets/style/utility-colors.css +166 -0
  30. package/src/components/Accordion/_.stories.tsx +75 -0
  31. package/src/components/Accordion/_.test.tsx +77 -0
  32. package/src/components/Accordion/index.tsx +47 -0
  33. package/src/components/Accordion/type.ts +24 -0
  34. package/src/components/Avatar/_.stories.tsx +179 -0
  35. package/src/components/Avatar/_.style.ts +40 -0
  36. package/src/components/Avatar/_.test.tsx +150 -0
  37. package/src/components/Avatar/_.types.ts +66 -0
  38. package/src/components/Avatar/index.tsx +63 -0
  39. package/src/components/Badge/_.stories.tsx +75 -0
  40. package/src/components/Badge/_.style.ts +53 -0
  41. package/src/components/Badge/_.test.tsx +27 -0
  42. package/src/components/Badge/_.types.ts +11 -0
  43. package/src/components/Badge/index.tsx +42 -0
  44. package/src/components/Breadcrumbs/_.stories.tsx +95 -0
  45. package/src/components/Breadcrumbs/_.test.tsx +29 -0
  46. package/src/components/Breadcrumbs/_.type.ts +15 -0
  47. package/src/components/Breadcrumbs/index.tsx +103 -0
  48. package/src/components/Button/_.stories.tsx +85 -0
  49. package/src/components/Button/_.style.ts +56 -0
  50. package/src/components/Button/_.test.tsx +103 -0
  51. package/src/components/Button/_.types.ts +14 -0
  52. package/src/components/Button/index.tsx +70 -0
  53. package/src/components/Checkbox/_.stories.tsx +96 -0
  54. package/src/components/Checkbox/_.style.ts +24 -0
  55. package/src/components/Checkbox/_.test.tsx +85 -0
  56. package/src/components/Checkbox/_.types.ts +23 -0
  57. package/src/components/Checkbox/index.tsx +93 -0
  58. package/src/components/CheckboxGroup/PaymentCard/_.stories.tsx +104 -0
  59. package/src/components/CheckboxGroup/PaymentCard/_.style.ts +28 -0
  60. package/src/components/CheckboxGroup/PaymentCard/_.test.tsx +58 -0
  61. package/src/components/CheckboxGroup/PaymentCard/_.types.ts +28 -0
  62. package/src/components/CheckboxGroup/PaymentCard/index.tsx +71 -0
  63. package/src/components/CheckboxGroup/PlanCard/_.stories.tsx +165 -0
  64. package/src/components/CheckboxGroup/PlanCard/_.style.ts +32 -0
  65. package/src/components/CheckboxGroup/PlanCard/_.test.tsx +54 -0
  66. package/src/components/CheckboxGroup/PlanCard/_.types.ts +35 -0
  67. package/src/components/CheckboxGroup/PlanCard/index.tsx +53 -0
  68. package/src/components/CheckboxGroup/UserCard/_.stories.tsx +89 -0
  69. package/src/components/CheckboxGroup/UserCard/_.style.ts +42 -0
  70. package/src/components/CheckboxGroup/UserCard/_.test.tsx +66 -0
  71. package/src/components/CheckboxGroup/UserCard/_.types.ts +26 -0
  72. package/src/components/CheckboxGroup/UserCard/index.tsx +75 -0
  73. package/src/components/Dropdown/_.stories.tsx +180 -0
  74. package/src/components/Dropdown/_.style.ts +108 -0
  75. package/src/components/Dropdown/_.test.tsx +334 -0
  76. package/src/components/Dropdown/_.types.ts +12 -0
  77. package/src/components/Dropdown/index.tsx +130 -0
  78. package/src/components/FileUpload/_.stories.tsx +74 -0
  79. package/src/components/FileUpload/_.style.ts +0 -0
  80. package/src/components/FileUpload/_.test.tsx +222 -0
  81. package/src/components/FileUpload/_.types.ts +53 -0
  82. package/src/components/FileUpload/index.tsx +44 -0
  83. package/src/components/ImageMagnify/_.stories.tsx +226 -0
  84. package/src/components/ImageMagnify/_.style.ts +109 -0
  85. package/src/components/ImageMagnify/_.types.ts +44 -0
  86. package/src/components/ImageMagnify/index.tsx +204 -0
  87. package/src/components/Input/_.stories.tsx +177 -0
  88. package/src/components/Input/_.style.ts +79 -0
  89. package/src/components/Input/_.test.tsx +146 -0
  90. package/src/components/Input/_.types.ts +66 -0
  91. package/src/components/Input/index.tsx +231 -0
  92. package/src/components/InputTags/_.stories.tsx +51 -0
  93. package/src/components/InputTags/_.style.ts +28 -0
  94. package/src/components/InputTags/_.test.tsx +123 -0
  95. package/src/components/InputTags/_.types.ts +26 -0
  96. package/src/components/InputTags/index.tsx +140 -0
  97. package/src/components/Message/_.stories.tsx +79 -0
  98. package/src/components/Message/_.style.ts +87 -0
  99. package/src/components/Message/_.test.tsx +73 -0
  100. package/src/components/Message/_.types.ts +13 -0
  101. package/src/components/Message/index.tsx +57 -0
  102. package/src/components/Metric/_.stories.tsx +142 -0
  103. package/src/components/Metric/_.style.ts +14 -0
  104. package/src/components/Metric/_.test.tsx +166 -0
  105. package/src/components/Metric/_.types.ts +18 -0
  106. package/src/components/Metric/index.tsx +100 -0
  107. package/src/components/Modal/_.stories.tsx +93 -0
  108. package/src/components/Modal/_.style.ts +31 -0
  109. package/src/components/Modal/_.test.tsx +90 -0
  110. package/src/components/Modal/_.types.ts +14 -0
  111. package/src/components/Modal/index.tsx +82 -0
  112. package/src/components/Pagination/_.stories.tsx +118 -0
  113. package/src/components/Pagination/_.test.tsx +51 -0
  114. package/src/components/Pagination/index.tsx +256 -0
  115. package/src/components/Pagination/type.ts +48 -0
  116. package/src/components/PriceSlider/_.stories.tsx +107 -0
  117. package/src/components/PriceSlider/_.test.tsx +63 -0
  118. package/src/components/PriceSlider/_.type.tsx +19 -0
  119. package/src/components/PriceSlider/index.tsx +86 -0
  120. package/src/components/Progress/_.stories.tsx +93 -0
  121. package/src/components/Progress/_.style.ts +15 -0
  122. package/src/components/Progress/_.test.tsx +34 -0
  123. package/src/components/Progress/_.types.ts +17 -0
  124. package/src/components/Progress/index.tsx +173 -0
  125. package/src/components/Radio/_.stories.tsx +391 -0
  126. package/src/components/Radio/_.style.ts +33 -0
  127. package/src/components/Radio/_.test.tsx +77 -0
  128. package/src/components/Radio/_.types.ts +14 -0
  129. package/src/components/Radio/index.tsx +59 -0
  130. package/src/components/Select/_.stories.tsx +308 -0
  131. package/src/components/Select/_.style.ts +5 -0
  132. package/src/components/Select/_.types.ts +24 -0
  133. package/src/components/Select/index.tsx +172 -0
  134. package/src/components/Switch/_.stories.tsx +61 -0
  135. package/src/components/Switch/_.test.tsx +69 -0
  136. package/src/components/Switch/_.type.ts +12 -0
  137. package/src/components/Switch/index.tsx +70 -0
  138. package/src/components/Tabs/_.stories.tsx +508 -0
  139. package/src/components/Tabs/_.style.ts +63 -0
  140. package/src/components/Tabs/_.test.tsx +174 -0
  141. package/src/components/Tabs/_.type.ts +19 -0
  142. package/src/components/Tabs/index.tsx +35 -0
  143. package/src/components/Tag/_.stories.tsx +78 -0
  144. package/src/components/Tag/_.style.ts +71 -0
  145. package/src/components/Tag/_.test.tsx +44 -0
  146. package/src/components/Tag/_.types.ts +27 -0
  147. package/src/components/Tag/index.tsx +46 -0
  148. package/src/components/TextArea/_.stories.tsx +62 -0
  149. package/src/components/TextArea/_.style.ts +11 -0
  150. package/src/components/TextArea/_.test.tsx +43 -0
  151. package/src/components/TextArea/_.types.ts +29 -0
  152. package/src/components/TextArea/index.tsx +83 -0
  153. package/src/components/Toast/_.style.tsx +27 -0
  154. package/src/components/Toast/_.type.ts +30 -0
  155. package/src/components/Toast/_.utils.ts +23 -0
  156. package/src/components/Toast/container.tsx +171 -0
  157. package/src/components/Toast/index.tsx +29 -0
  158. package/src/components/Tooltip/_.stories.tsx +106 -0
  159. package/src/components/Tooltip/_.style.ts +27 -0
  160. package/src/components/Tooltip/_.test.tsx +54 -0
  161. package/src/components/Tooltip/_.types.ts +31 -0
  162. package/src/components/Tooltip/index.tsx +80 -0
  163. package/src/components/developers/AmirHossein.tsx +149 -0
  164. package/src/components/developers/Fardin.tsx +130 -0
  165. package/src/components/developers/Maryam.tsx +260 -0
  166. package/src/components/developers/Milad.tsx +431 -0
  167. package/src/components/developers/Rasoul.tsx +198 -0
  168. package/src/components/index.ts +28 -0
  169. package/src/components/ui/accordion.tsx +162 -0
  170. package/src/components/ui/avatars-component/avatar-description.tsx +30 -0
  171. package/src/components/ui/avatars-component/avatar-groups.tsx +68 -0
  172. package/src/components/ui/avatars-component/avatar-single.tsx +50 -0
  173. package/src/components/ui/card.tsx +92 -0
  174. package/src/components/ui/checkbox-group/plan-card/basic/_.test.tsx +66 -0
  175. package/src/components/ui/checkbox-group/plan-card/basic/index.tsx +70 -0
  176. package/src/components/ui/checkbox-group/plan-card/with-header/_.test.tsx +110 -0
  177. package/src/components/ui/checkbox-group/plan-card/with-header/header.test.tsx +96 -0
  178. package/src/components/ui/checkbox-group/plan-card/with-header/header.tsx +74 -0
  179. package/src/components/ui/checkbox-group/plan-card/with-header/index.tsx +65 -0
  180. package/src/components/ui/file-content/File-content.tsx +43 -0
  181. package/src/components/ui/file-uploader-components/file-uploader-box.tsx +76 -0
  182. package/src/components/ui/file-uploader-components/file-uploader-item.tsx +64 -0
  183. package/src/components/ui/icon-wrapper/_.test.tsx +60 -0
  184. package/src/components/ui/icon-wrapper/index.tsx +19 -0
  185. package/src/components/ui/input-component/input-label.tsx +11 -0
  186. package/src/components/ui/number.tsx +18 -0
  187. package/src/components/ui/pagination/card-minimal-center-align.tsx +96 -0
  188. package/src/components/ui/pagination/card-minimal-right-aligne.tsx +90 -0
  189. package/src/components/ui/pagination/default-pagination.tsx +128 -0
  190. package/src/components/ui/pagination/get-pagination-item.tsx +36 -0
  191. package/src/components/ui/pagination/pagination-card-button-group-aligned.tsx +94 -0
  192. package/src/components/ui/pagination/pagination-card-minimal-left-aligned.tsx +90 -0
  193. package/src/components/ui/pagination/pagination-content.tsx +15 -0
  194. package/src/components/ui/pagination/pagination-item.tsx +11 -0
  195. package/src/components/ui/pagination/pagination-link.tsx +42 -0
  196. package/src/components/ui/tab-components/tabs-content.tsx +15 -0
  197. package/src/components/ui/tab-components/tabs-list.tsx +27 -0
  198. package/src/components/ui/tab-components/tabs-trigger.tsx +25 -0
  199. package/src/components/ui/text-content-wrapper.tsx +36 -0
  200. package/src/hooks/useClickOutside.ts +23 -0
  201. package/src/icons/general/ArrowLeft.tsx +31 -0
  202. package/src/icons/general/ArrowRight.tsx +31 -0
  203. package/src/icons/general/activity-heart.tsx +31 -0
  204. package/src/icons/general/activity.tsx +31 -0
  205. package/src/icons/general/anchor.tsx +31 -0
  206. package/src/icons/general/archive.tsx +31 -0
  207. package/src/icons/general/arrow-left.tsx +25 -0
  208. package/src/icons/general/arrow-right.tsx +25 -0
  209. package/src/icons/general/asterisk-01.tsx +31 -0
  210. package/src/icons/general/asterisk-02.tsx +31 -0
  211. package/src/icons/general/at-sign.tsx +31 -0
  212. package/src/icons/general/attention-mark.tsx +43 -0
  213. package/src/icons/general/bookmark-add.tsx +31 -0
  214. package/src/icons/general/bookmark.tsx +31 -0
  215. package/src/icons/general/chevron-left.tsx +25 -0
  216. package/src/icons/general/chevron-right.tsx +25 -0
  217. package/src/icons/general/circle-minues.tsx +25 -0
  218. package/src/icons/general/circle-plus.tsx +25 -0
  219. package/src/icons/general/circle-question-mark.tsx +32 -0
  220. package/src/icons/general/circle.tsx +32 -0
  221. package/src/icons/general/copy.tsx +43 -0
  222. package/src/icons/general/email.tsx +32 -0
  223. package/src/icons/general/home.tsx +25 -0
  224. package/src/icons/general/layer.tsx +36 -0
  225. package/src/icons/general/leading.tsx +19 -0
  226. package/src/icons/general/master-card.tsx +37 -0
  227. package/src/icons/general/minus.tsx +36 -0
  228. package/src/icons/general/plus.tsx +19 -0
  229. package/src/icons/general/remove.tsx +32 -0
  230. package/src/icons/general/slash-divider.tsx +26 -0
  231. package/src/icons/general/tick-box.tsx +37 -0
  232. package/src/icons/general/trailing.tsx +19 -0
  233. package/src/icons/general/unkown-format.tsx +25 -0
  234. package/src/icons/general/visa-card.tsx +38 -0
  235. package/src/icons/general/x-close.tsx +35 -0
  236. package/src/icons/icons.type.ts +7 -0
  237. package/src/index.css +21 -0
  238. package/src/index.ts +3 -0
  239. package/src/lib/utils.ts +6 -0
  240. package/src/lib/zIndexUtils.ts +2 -0
  241. package/src/main.tsx +50 -0
  242. package/src/vite-env.d.ts +1 -0
  243. package/tests/setup.ts +8 -0
  244. package/tsconfig.app.json +31 -0
  245. package/tsconfig.json +7 -0
  246. package/tsconfig.node.json +24 -0
  247. package/tsconfig.rollup.json +12 -0
  248. package/vite.config.ts +20 -0
  249. package/vitest.config.ts +47 -0
@@ -0,0 +1,180 @@
1
+ import { Meta, StoryFn } from "@storybook/react-vite";
2
+ import { useState } from "react";
3
+ import { Dropdown } from ".";
4
+ import { DropdownWrapperProps } from "./_.types";
5
+
6
+ export default {
7
+ title: "Components/Dropdown",
8
+ component: Dropdown,
9
+ tags: ["autodocs"],
10
+ argTypes: {
11
+ direction: {
12
+ control: { type: "radio" },
13
+ options: ["down", "up", "left", "right"],
14
+ },
15
+ alignment: {
16
+ control: { type: "radio" },
17
+ options: ["left", "right", "top", "bottom"],
18
+ },
19
+ autoAdjust: {
20
+ control: { type: "boolean" },
21
+ },
22
+ dropDownClassName: {
23
+ control: { type: "text" },
24
+ },
25
+ open: {
26
+ control: { type: "boolean" },
27
+ },
28
+ },
29
+ } as Meta<DropdownWrapperProps>;
30
+
31
+ // A small menu to display in the dropdown
32
+ const MenuItems = () => (
33
+ <ul className="space-y-2 text-sm text-gray-700">
34
+ <li className="hover:bg-gray-100 px-2 py-1 rounded">Profile</li>
35
+ <li className="hover:bg-gray-100 px-2 py-1 rounded">Settings</li>
36
+ <li className="hover:bg-gray-100 px-2 py-1 rounded">Logout</li>
37
+ </ul>
38
+ );
39
+
40
+ const Template: StoryFn<DropdownWrapperProps> = (args) => (
41
+ <div className="flex justify-center items-center h-64 w-full">
42
+ <Dropdown {...args}>
43
+ <MenuItems />
44
+ </Dropdown>
45
+ </div>
46
+ );
47
+
48
+ export const Default = Template.bind({});
49
+ Default.args = {
50
+ toggleBtn: { children: <>Controlled Menu</> },
51
+ direction: "down",
52
+ alignment: "right",
53
+ autoAdjust: true,
54
+ dropDownClassName: "w-48 p-4",
55
+ };
56
+
57
+ export const Upwards = Template.bind({});
58
+ Upwards.args = {
59
+ ...Default.args,
60
+ direction: "up",
61
+ };
62
+
63
+ export const LeftDirection = Template.bind({});
64
+ LeftDirection.args = {
65
+ ...Default.args,
66
+ direction: "left",
67
+ alignment: "top",
68
+ };
69
+
70
+ export const RightDirection = Template.bind({});
71
+ RightDirection.args = {
72
+ ...Default.args,
73
+ direction: "right",
74
+ alignment: "top",
75
+ };
76
+
77
+ export const LeftDirectionBottom = Template.bind({});
78
+ LeftDirectionBottom.args = {
79
+ ...Default.args,
80
+ direction: "left",
81
+ alignment: "bottom",
82
+ };
83
+
84
+ export const RightDirectionBottom = Template.bind({});
85
+ RightDirectionBottom.args = {
86
+ ...Default.args,
87
+ direction: "right",
88
+ alignment: "bottom",
89
+ };
90
+
91
+ export const AlignLeft = Template.bind({});
92
+ AlignLeft.args = {
93
+ ...Default.args,
94
+ alignment: "left",
95
+ };
96
+
97
+ export const AlignTop = Template.bind({});
98
+ AlignTop.args = {
99
+ ...Default.args,
100
+ direction: "down",
101
+ alignment: "top",
102
+ };
103
+
104
+ export const AlignBottom = Template.bind({});
105
+ AlignBottom.args = {
106
+ ...Default.args,
107
+ direction: "down",
108
+ alignment: "bottom",
109
+ };
110
+
111
+ export const NoAutoAdjust = Template.bind({});
112
+ NoAutoAdjust.args = {
113
+ ...Default.args,
114
+ autoAdjust: false,
115
+ };
116
+
117
+ export const AllDirections = () => {
118
+ const [openStates, setOpenStates] = useState({
119
+ down: false,
120
+ up: false,
121
+ left: false,
122
+ right: false,
123
+ });
124
+
125
+ return (
126
+ <div className="grid grid-cols-2 gap-8 p-8 h-96">
127
+ <div className="flex justify-center items-center">
128
+ <Dropdown
129
+ toggleBtn={{ children: <span>Down</span> }}
130
+ open={openStates.down}
131
+ onOpenChange={(open) => setOpenStates(prev => ({ ...prev, down: open }))}
132
+ direction="down"
133
+ alignment="right"
134
+ dropDownClassName="w-48 p-4"
135
+ >
136
+ <MenuItems />
137
+ </Dropdown>
138
+ </div>
139
+
140
+ <div className="flex justify-center items-center">
141
+ <Dropdown
142
+ toggleBtn={{ children: <span>Up</span> }}
143
+ open={openStates.up}
144
+ onOpenChange={(open) => setOpenStates(prev => ({ ...prev, up: open }))}
145
+ direction="up"
146
+ alignment="right"
147
+ dropDownClassName="w-48 p-4"
148
+ >
149
+ <MenuItems />
150
+ </Dropdown>
151
+ </div>
152
+
153
+ <div className="flex justify-center items-center">
154
+ <Dropdown
155
+ toggleBtn={{ children: <span>Left</span> }}
156
+ open={openStates.left}
157
+ onOpenChange={(open) => setOpenStates(prev => ({ ...prev, left: open }))}
158
+ direction="left"
159
+ alignment="top"
160
+ dropDownClassName="w-48 p-4"
161
+ >
162
+ <MenuItems />
163
+ </Dropdown>
164
+ </div>
165
+
166
+ <div className="flex justify-center items-center">
167
+ <Dropdown
168
+ toggleBtn={{ children: <span>Right</span> }}
169
+ open={openStates.right}
170
+ onOpenChange={(open) => setOpenStates(prev => ({ ...prev, right: open }))}
171
+ direction="right"
172
+ alignment="top"
173
+ dropDownClassName="w-48 p-4"
174
+ >
175
+ <MenuItems />
176
+ </Dropdown>
177
+ </div>
178
+ </div>
179
+ );
180
+ };
@@ -0,0 +1,108 @@
1
+ import { cva } from "class-variance-authority";
2
+
3
+ export const dropdownPlacementVariants = cva("", {
4
+ variants: {
5
+ direction: {
6
+ down: "",
7
+ up: "",
8
+ left: "",
9
+ right: "",
10
+ },
11
+ alignment: {
12
+ left: "",
13
+ right: "",
14
+ top: "",
15
+ bottom: "",
16
+ },
17
+ },
18
+ compoundVariants: [
19
+ // Down direction
20
+ {
21
+ direction: "down",
22
+ alignment: "left",
23
+ class: "origin-top-right right-0 mt-2",
24
+ },
25
+ {
26
+ direction: "down",
27
+ alignment: "right",
28
+ class: "origin-top-left left-0 mt-2",
29
+ },
30
+ {
31
+ direction: "down",
32
+ alignment: "top",
33
+ class: "origin-top-center left-1/2 -translate-x-1/2 mt-2",
34
+ },
35
+ {
36
+ direction: "down",
37
+ alignment: "bottom",
38
+ class: "origin-top-center left-1/2 -translate-x-1/2 mt-2",
39
+ },
40
+ // Up direction
41
+ {
42
+ direction: "up",
43
+ alignment: "left",
44
+ class: "origin-bottom-right right-0 bottom-full mb-2",
45
+ },
46
+ {
47
+ direction: "up",
48
+ alignment: "right",
49
+ class: "origin-bottom-left left-0 bottom-full mb-2",
50
+ },
51
+ {
52
+ direction: "up",
53
+ alignment: "top",
54
+ class: "origin-bottom-center left-1/2 -translate-x-1/2 bottom-full mb-2",
55
+ },
56
+ {
57
+ direction: "up",
58
+ alignment: "bottom",
59
+ class: "origin-bottom-center left-1/2 -translate-x-1/2 bottom-full mb-2",
60
+ },
61
+ // Left direction
62
+ {
63
+ direction: "left",
64
+ alignment: "top",
65
+ class: "origin-top-right top-0 right-full mr-2",
66
+ },
67
+ {
68
+ direction: "left",
69
+ alignment: "bottom",
70
+ class: "origin-bottom-right bottom-0 right-full mr-2",
71
+ },
72
+ {
73
+ direction: "left",
74
+ alignment: "left",
75
+ class: "origin-center right-full mr-2 top-1/2 -translate-y-1/2",
76
+ },
77
+ {
78
+ direction: "left",
79
+ alignment: "right",
80
+ class: "origin-center right-full mr-2 top-1/2 -translate-y-1/2",
81
+ },
82
+ // Right direction
83
+ {
84
+ direction: "right",
85
+ alignment: "top",
86
+ class: "origin-top-left top-0 left-full ml-2",
87
+ },
88
+ {
89
+ direction: "right",
90
+ alignment: "bottom",
91
+ class: "origin-bottom-left bottom-0 left-full ml-2",
92
+ },
93
+ {
94
+ direction: "right",
95
+ alignment: "left",
96
+ class: "origin-center left-full ml-2 top-1/2 -translate-y-1/2",
97
+ },
98
+ {
99
+ direction: "right",
100
+ alignment: "right",
101
+ class: "origin-center left-full ml-2 top-1/2 -translate-y-1/2",
102
+ },
103
+ ],
104
+ defaultVariants: {
105
+ direction: "down",
106
+ alignment: "right",
107
+ },
108
+ });
@@ -0,0 +1,334 @@
1
+ import { cleanup, fireEvent, render } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { Dropdown } from ".";
4
+ import { dropdownPlacementVariants } from "./_.style";
5
+
6
+ vi.mock("@/lib/zIndexUtils", () => ({
7
+ getBackdropZIndex: vi.fn(() => 1000),
8
+ }));
9
+
10
+ describe("Dropdown component", () => {
11
+ beforeEach(() => {
12
+ Object.defineProperty(window, "innerHeight", {
13
+ value: 600,
14
+ writable: true,
15
+ configurable: true,
16
+ });
17
+ });
18
+
19
+ afterEach(() => {
20
+ cleanup();
21
+ vi.clearAllMocks();
22
+ });
23
+
24
+ it("renders the toggle button and does not show children initially", () => {
25
+ const { queryByText } = render(
26
+ <Dropdown toggleBtn={{ children: <span>Open</span> }}>Hello!</Dropdown>
27
+ );
28
+ expect(queryByText("Open")).toBeTruthy();
29
+ expect(queryByText("Hello!")).toBeNull();
30
+ });
31
+
32
+ it("toggles open state when clicked (uncontrolled)", () => {
33
+ const { getByText, queryByText } = render(
34
+ <Dropdown toggleBtn={{ children: <span>Menu</span> }}>
35
+ <div>Content</div>
36
+ </Dropdown>
37
+ );
38
+ const btn = getByText("Menu");
39
+ fireEvent.click(btn);
40
+ expect(queryByText("Content")).toBeTruthy();
41
+ fireEvent.click(btn);
42
+ expect(queryByText("Content")).toBeNull();
43
+ });
44
+
45
+ it("calls onOpenChange when controlled", () => {
46
+ const handleOpenChange = vi.fn();
47
+ const { getByText } = render(
48
+ <Dropdown
49
+ toggleBtn={{ children: <span>Ctrl</span> }}
50
+ open={false}
51
+ onOpenChange={handleOpenChange}
52
+ >
53
+ <div>XYZ</div>
54
+ </Dropdown>
55
+ );
56
+ fireEvent.click(getByText("Ctrl"));
57
+ expect(handleOpenChange).toHaveBeenCalledWith(true);
58
+ });
59
+
60
+ it("closes when clicking outside", () => {
61
+ const { getByText, queryByText, container } = render(
62
+ <div data-testid="outer">
63
+ <Dropdown toggleBtn={{ children: <span>Outside</span> }}>
64
+ <div>Inside</div>
65
+ </Dropdown>
66
+ </div>
67
+ );
68
+ const btn = getByText("Outside");
69
+ fireEvent.click(btn);
70
+ expect(queryByText("Inside")).toBeTruthy();
71
+
72
+ fireEvent.mouseDown(container.querySelector('[data-testid="outer"]')!);
73
+ expect(queryByText("Inside")).toBeNull();
74
+ });
75
+
76
+ it("respects direction prop when autoAdjust is false", () => {
77
+ const { getByText, container } = render(
78
+ <Dropdown
79
+ toggleBtn={{ children: <span>Dir</span> }}
80
+ direction="up"
81
+ alignment="left"
82
+ autoAdjust={false}
83
+ dropDownClassName="my-dd"
84
+ >
85
+ <div>UpContent</div>
86
+ </Dropdown>
87
+ );
88
+ fireEvent.click(getByText("Dir"));
89
+ const dd = container.querySelector(".my-dd")!;
90
+ expect(dd.className).toContain("bottom-full");
91
+ });
92
+
93
+ it("supports left direction", () => {
94
+ const { getByText, container } = render(
95
+ <Dropdown
96
+ toggleBtn={{ children: <span>Left</span> }}
97
+ direction="left"
98
+ alignment="top"
99
+ autoAdjust={false}
100
+ dropDownClassName="my-dd"
101
+ >
102
+ <div>LeftContent</div>
103
+ </Dropdown>
104
+ );
105
+ fireEvent.click(getByText("Left"));
106
+ const dd = container.querySelector(".my-dd")!;
107
+ expect(dd.className).toContain("right-full");
108
+ });
109
+
110
+ it("supports right direction", () => {
111
+ const { getByText, container } = render(
112
+ <Dropdown
113
+ toggleBtn={{ children: <span>Right</span> }}
114
+ direction="right"
115
+ alignment="top"
116
+ autoAdjust={false}
117
+ dropDownClassName="my-dd"
118
+ >
119
+ <div>RightContent</div>
120
+ </Dropdown>
121
+ );
122
+ fireEvent.click(getByText("Right"));
123
+ const dd = container.querySelector(".my-dd")!;
124
+ expect(dd.className).toContain("left-full");
125
+ });
126
+
127
+ it("supports all alignment options", () => {
128
+ const alignments = ["left", "right", "top", "bottom"] as const;
129
+
130
+ alignments.forEach(alignment => {
131
+ const { getByText, container } = render(
132
+ <Dropdown
133
+ toggleBtn={{ children: <span>Align</span> }}
134
+ direction="down"
135
+ alignment={alignment}
136
+ autoAdjust={false}
137
+ dropDownClassName="my-dd"
138
+ >
139
+ <div>AlignContent</div>
140
+ </Dropdown>
141
+ );
142
+ fireEvent.click(getByText("Align"));
143
+ const dd = container.querySelector(".my-dd")!;
144
+ expect(dd.className).toContain("origin-");
145
+ cleanup();
146
+ });
147
+ });
148
+
149
+ it("autoAdjust flips placement based on space", () => {
150
+ Object.defineProperty(window, "innerHeight", {
151
+ value: 100,
152
+ writable: true,
153
+ configurable: true,
154
+ });
155
+ const { getByText, container } = render(
156
+ <Dropdown
157
+ toggleBtn={{ children: <span>Auto</span> }}
158
+ alignment="right"
159
+ autoAdjust
160
+ >
161
+ <div>AutoContent</div>
162
+ </Dropdown>
163
+ );
164
+ fireEvent.click(getByText("Auto"));
165
+ const dd = container.querySelector("[class*='origin']")!;
166
+ expect(dd.className).toContain("origin-top-left ");
167
+ });
168
+
169
+ it("autoAdjust works for horizontal directions", () => {
170
+ Object.defineProperty(window, "innerWidth", {
171
+ value: 100,
172
+ writable: true,
173
+ configurable: true,
174
+ });
175
+ const { getByText, container } = render(
176
+ <Dropdown
177
+ toggleBtn={{ children: <span>Auto</span> }}
178
+ direction="right"
179
+ alignment="top"
180
+ autoAdjust
181
+ >
182
+ <div>AutoContent</div>
183
+ </Dropdown>
184
+ );
185
+ fireEvent.click(getByText("Auto"));
186
+ const dd = container.querySelector("[class*='origin']")!;
187
+ expect(dd.className).toContain("origin-");
188
+ });
189
+
190
+ it("falls back to estHeight = 200 when dropdownRef is null", () => {
191
+ Object.defineProperty(window, "innerHeight", {
192
+ value: 100,
193
+ writable: true,
194
+ configurable: true,
195
+ });
196
+
197
+ const { getByText, container } = render(
198
+ <Dropdown toggleBtn={{ children: <span>Fallback</span> }} autoAdjust>
199
+ <div>FallbackContent</div>
200
+ </Dropdown>
201
+ );
202
+
203
+ const wrapper = container.querySelector("div.relative.inline-block")!;
204
+ wrapper.getBoundingClientRect = () =>
205
+ ({
206
+ top: 90,
207
+ bottom: 90,
208
+ height: 10,
209
+ left: 0,
210
+ right: 0,
211
+ width: 0,
212
+ x: 0,
213
+ y: 0,
214
+ toJSON: () => { },
215
+ } as DOMRect);
216
+
217
+ const dropdown = container.querySelector("div.absolute");
218
+ if (dropdown) {
219
+ dropdown.remove();
220
+ }
221
+
222
+ fireEvent.click(getByText("Fallback"));
223
+
224
+ const dd = container.querySelector("div.absolute");
225
+
226
+ // Since space is limited, it should flip to "up" direction
227
+ const expectedClass = dropdownPlacementVariants({
228
+ direction: "up",
229
+ alignment: "right",
230
+ });
231
+
232
+ expect(dd?.className).toContain(expectedClass);
233
+ });
234
+ });
235
+
236
+ describe("placement 'up' branch in useLayoutEffect", () => {
237
+ beforeEach(() => {
238
+ Object.defineProperty(HTMLDivElement.prototype, "offsetHeight", {
239
+ configurable: true,
240
+ get: () => 200,
241
+ });
242
+ Object.defineProperty(HTMLDivElement.prototype, "offsetWidth", {
243
+ configurable: true,
244
+ get: () => 200,
245
+ });
246
+ Object.defineProperty(window, "innerHeight", {
247
+ configurable: true,
248
+ writable: true,
249
+ value: 150,
250
+ });
251
+ Object.defineProperty(window, "innerWidth", {
252
+ configurable: true,
253
+ writable: true,
254
+ value: 150,
255
+ });
256
+ });
257
+
258
+ afterEach(() => {
259
+ delete (HTMLDivElement.prototype as unknown as { offsetHeight?: number })
260
+ .offsetHeight;
261
+ delete (HTMLDivElement.prototype as unknown as { offsetWidth?: number })
262
+ .offsetWidth;
263
+ delete (window as unknown as { innerHeight?: number }).innerHeight;
264
+ delete (window as unknown as { innerWidth?: number }).innerWidth;
265
+ cleanup();
266
+ });
267
+
268
+ it("sets placement='up' when spaceBelow < estHeight && top > spaceBelow", () => {
269
+ const { getByText, container } = render(
270
+ <Dropdown
271
+ toggleBtn={{
272
+ children: <span>Trigger</span>,
273
+ }}
274
+ autoAdjust
275
+ >
276
+ <div>MenuContent</div>
277
+ </Dropdown>
278
+ );
279
+
280
+ const wrapper = container.querySelector("div.relative.inline-block")!;
281
+ wrapper.getBoundingClientRect = () =>
282
+ ({
283
+ top: 100,
284
+ bottom: 100,
285
+ left: 0,
286
+ right: 0,
287
+ width: 0,
288
+ height: 0,
289
+ x: 0,
290
+ y: 0,
291
+ toJSON: () => { },
292
+ } as DOMRect);
293
+
294
+ fireEvent.click(getByText("Trigger"));
295
+
296
+ const dd = container.querySelector("div.absolute")!;
297
+ expect(dd.className).toContain("origin-bottom-left");
298
+ expect(dd.className).toContain("bottom-full");
299
+ });
300
+
301
+ it("sets placement='left' when spaceRight < estWidth && left > spaceRight", () => {
302
+ const { getByText, container } = render(
303
+ <Dropdown
304
+ toggleBtn={{
305
+ children: <span>Trigger</span>,
306
+ }}
307
+ direction="right"
308
+ autoAdjust
309
+ >
310
+ <div>MenuContent</div>
311
+ </Dropdown>
312
+ );
313
+
314
+ const wrapper = container.querySelector("div.relative.inline-block")!;
315
+ wrapper.getBoundingClientRect = () =>
316
+ ({
317
+ top: 0,
318
+ bottom: 0,
319
+ left: 100,
320
+ right: 100,
321
+ width: 0,
322
+ height: 0,
323
+ x: 0,
324
+ y: 0,
325
+ toJSON: () => { },
326
+ } as DOMRect);
327
+
328
+ fireEvent.click(getByText("Trigger"));
329
+
330
+ const dd = container.querySelector("div.absolute")!;
331
+ expect(dd.className).toContain("origin-");
332
+ expect(dd.className).toContain("right-full");
333
+ });
334
+ });
@@ -0,0 +1,12 @@
1
+ import { ButtonProps } from "../Button/_.types";
2
+
3
+ export interface DropdownWrapperProps {
4
+ children: React.ReactNode;
5
+ toggleBtn: ButtonProps;
6
+ direction?: "down" | "up" | "left" | "right";
7
+ alignment?: "left" | "right" | "top" | "bottom";
8
+ dropDownClassName?: string;
9
+ autoAdjust?: boolean;
10
+ open?: boolean;
11
+ onOpenChange?: (open: boolean) => void;
12
+ }