Skip to content

Commit 002e8fe

Browse files
fix(menu): fixed styling on Menu component
Added configuration for labelClassName and badgeClassName. Fixed menu text size and color no able to change viabuttonClassName
1 parent 9d076bc commit 002e8fe

File tree

6 files changed

+97
-52
lines changed

6 files changed

+97
-52
lines changed

.storybook/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
staticDirs: ["../public"],
3-
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
3+
stories: ["../stories/**/*.stories.mdx", "../stories/**/*.stories.@(js|jsx|ts|tsx)"],
44
addons: [
55
"@storybook/addon-links",
66
"@storybook/addon-essentials",

.storybook/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ input {
2424
}
2525
.default-focus-visible {
2626
@apply focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-gray-500 focus-visible:ring-offset-2 dark:ring-gray-400 dark:focus-visible:ring-offset-gray-800;
27+
} /* Last row menu fix */
28+
.menu-popover {
29+
@apply mt-2 -mr-1 origin-top-right;
30+
}
31+
.row:last-child .menu-popover {
32+
@apply bottom-0 mb-10 mt-0 mr-0 origin-bottom-right;
2733
}
2834
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"semantic-release": "semantic-release --branches main"
2727
},
2828
"peerDependencies": {
29-
"framer-motion": "^6.5.1",
29+
"framer-motion": "^ 6.5.1",
3030
"react": ">=17",
31-
"react-dom": "^17.0.1",
31+
"react-dom": ">=17",
3232
"react-icons": "^4.3.1",
3333
"tailwindcss": "^3"
3434
},

src/lib/components/Form/AppMenu.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,37 @@ function AppMenu({
1212
menus,
1313
className,
1414
buttonClassName,
15+
labelClassName,
16+
badgeClassName,
1517
...props
1618
}: MenuProps & {
1719
className?: string;
1820
buttonClassName?: string;
21+
labelClassName?: string;
22+
badgeClassName?: string;
1923
[x: string]: any;
20-
}) {
24+
} & React.HTMLAttributes<HTMLDivElement>) {
2125
return (
2226
<Menu as="div" className={clsxm("relative -ml-px block", className)} {...props}>
2327
<Menu.Button
2428
className={clsxm(
25-
"default-focus group inline-flex items-center justify-center text-sm font-medium text-gray-700 hover:text-gray-900",
29+
"default-focus-visible group inline-flex items-center justify-center text-sm font-medium text-gray-700 hover:text-gray-900",
2630
buttonClassName
2731
)}
2832
>
2933
{label && (
30-
<span className="text-sm font-medium text-gray-700 hover:text-gray-900 dark:text-gray-200 dark:hover:text-gray-50">
34+
<span className={clsxm("hover:text-gray-900 dark:text-gray-200 dark:hover:text-gray-50", labelClassName)}>
3135
{label}
3236
</span>
3337
)}
3438
{icon && icon}
3539
{badge && (
36-
<span className="ml-1.5 rounded bg-gray-200 py-0.5 px-1.5 text-xs font-semibold tabular-nums text-gray-700 ">
40+
<span
41+
className={clsxm(
42+
"ml-1.5 rounded bg-gray-200 py-0.5 px-1.5 text-xs font-semibold tabular-nums text-gray-700",
43+
badgeClassName
44+
)}
45+
>
3746
{badge}
3847
</span>
3948
)}
@@ -59,17 +68,19 @@ function AppMenu({
5968
) : (
6069
<button
6170
onClick={item.onClick}
62-
className={clsxm(
71+
className={clsxm([
6372
!item.role && active && "bg-gray-100 text-gray-900 dark:bg-black/20 dark:text-white",
64-
!item.role && "text-gray-700 dark:text-gray-200",
73+
(!item.role || item.role === "default") && "text-gray-700 dark:text-gray-200",
6574
item.role === "destructive" && active && "bg-red-100 dark:bg-red-700/20",
6675
item.role === "destructive" && "text-red-600 dark:text-red-300",
6776
item.role === "info" && active && "bg-blue-100 dark:bg-blue-700/20",
6877
item.role === "info" && "text-blue-600 dark:text-blue-300",
78+
item.role === "success" && active && "bg-green-100 dark:bg-green-700/20",
79+
item.role === "success" && "text-green-600 dark:text-green-300",
6980
"disabled:cursor-not-allowed disabled:opacity-50",
7081
"block w-full px-4 py-2 text-left text-sm rtl:text-right",
71-
"flex items-center justify-start"
72-
)}
82+
"flex items-center justify-start",
83+
])}
7384
>
7485
{item.icon && <item.icon className="mr-2 h-4 w-4" />}
7586
<span>{item.label}</span>

stories/Button.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22
import { Meta, Story } from '@storybook/react/types-6-0';
3-
import { Button, ButtonProps } from '../lib/components/Button';
3+
import { Button, ButtonProps } from '../src/lib/components/Button';
44
import {
55
FluidButtonColors,
66
FluidButtonSizes,
77
FluidButtonWeights,
8-
} from '../lib/components/FluidUI/FluidTheme';
8+
} from '../src/lib/components/FluidUI/FluidTheme';
99
import { IoIosSend } from 'react-icons/io';
1010

1111
export default {

stories/Form.stories.tsx

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,59 @@
1-
import React from 'react';
2-
import { Meta, Story } from '@storybook/react/types-6-0';
3-
import { Button, ButtonProps } from '../lib/components/Button';
4-
import * as Yup from 'yup';
1+
import React from "react";
2+
import { Meta, Story } from "@storybook/react/types-6-0";
3+
import { Button, ButtonProps } from "../src/lib/components/Button";
4+
import * as Yup from "yup";
55

6-
import {
7-
FluidButtonSizes,
8-
FluidButtonWeights,
9-
} from '../lib/components/FluidUI/FluidTheme';
6+
import { FluidButtonSizes, FluidButtonWeights } from "../src/lib/components/FluidUI/FluidTheme";
107
import {
118
ComboBox,
129
Form,
1310
Input,
11+
Menu,
1412
SubmitButton,
1513
SubmitButtonRef,
1614
Switch,
1715
Textarea,
18-
} from '../lib/components/Form';
19-
import { HiInformationCircle } from 'react-icons/hi';
20-
import { states } from '../lib/helpers/data';
21-
import { useRef, useState } from '@storybook/addons';
16+
} from "../src/lib/components/Form";
17+
import { HiChevronDown, HiDotsVertical, HiInformationCircle, HiPencil, HiTrash } from "react-icons/hi";
18+
import { states } from "../src/lib/helpers/data";
19+
import { useRef, useState } from "@storybook/addons";
20+
import AppMenu from "../src/lib/components/Form/AppMenu";
2221

2322
export default {
24-
title: 'Components/Form',
23+
title: "Components/Form",
2524
component: Button,
2625
args: {
27-
weight: 'normal' as keyof FluidButtonWeights,
28-
size: 'md' as keyof FluidButtonSizes,
26+
weight: "normal" as keyof FluidButtonWeights,
27+
size: "md" as keyof FluidButtonSizes,
2928
disabled: false,
3029
},
3130
} as Meta;
3231

33-
interface StoryButtonProps extends Omit<ButtonProps, 'color'> {}
32+
interface StoryButtonProps extends Omit<ButtonProps, "color"> {}
3433

3534
const Template: Story<StoryButtonProps> = args => {
36-
const submitBtnRef = useRef<HTMLButtonElement>(null);
37-
const [isSubmitted, setIsSubmitted] = useState(null);
35+
const submitBtnRef = useRef<HTMLButtonElement | null>(null);
36+
const [isSubmitted, setIsSubmitted] = useState<any>(null);
3837
const initialValues = {
39-
name: '',
40-
email: '',
41-
message: '',
42-
state: 'California',
38+
name: "",
39+
email: "",
40+
message: "",
41+
state: "California",
4342
saveResponse: false,
4443
};
4544
const validationSchema = Yup.object().shape({
46-
name: Yup.string().required('Name is required'),
45+
name: Yup.string().required("Name is required"),
4746
email: Yup.string()
48-
.email('Invalid email address')
49-
.required('Email is required'),
47+
.email("Invalid email address")
48+
.required("Email is required"),
5049
message: Yup.string().optional(),
51-
state: Yup.string().required('State is required'),
52-
saveResponse: Yup.boolean().required('Save response is required'),
50+
state: Yup.string().required("State is required"),
51+
saveResponse: Yup.boolean().required("Save response is required"),
5352
});
54-
console.log('submitBtnRef', submitBtnRef);
53+
console.log("submitBtnRef", submitBtnRef);
5554
return (
5655
<>
57-
<div className="w-4/5 max-w-lg mx-auto p-4 bg-white dark:bg-stone-900 shadow-lg shadow-gray-400/20 dark:shadow-black/30 rounded-xl">
56+
<div className="w-4/5 max-w-lg mx-auto mt-12 p-4 bg-white dark:bg-stone-900 shadow-lg shadow-gray-400/20 dark:shadow-black/30 rounded-xl">
5857
<Form
5958
initialValues={initialValues}
6059
validationSchema={validationSchema}
@@ -71,16 +70,50 @@ const Template: Story<StoryButtonProps> = args => {
7170
<h1>Thank you for your submission!</h1>
7271
</div>
7372
)}
74-
<h2 className="text-xl font-semibold pb-4 text-gray-700 dark:text-gray-200">
75-
Contact Us
76-
</h2>
73+
<h2 className="text-xl font-semibold pb-4 text-gray-700 dark:text-gray-200">Contact Us</h2>
74+
<div className="relative flex justify-between mb-4">
75+
<div />
76+
<Menu
77+
label={"Actions"}
78+
icon={
79+
<HiChevronDown
80+
className="-mr-1 ml-1 h-5 w-5 flex-shrink-0 text-gray-400 group-hover:text-gray-500 dark:text-gray-400 dark:group-hover:text-gray-50"
81+
aria-hidden="true"
82+
/>
83+
}
84+
header={
85+
<p className="truncate py-3 px-3.5">
86+
<span className="mb-0.5 block text-xs text-gray-500 dark:text-gray-400">Signed in as</span>
87+
<span className="font-semibold text-gray-700 dark:text-gray-300">Guest user</span>
88+
</p>
89+
}
90+
buttonClassName="!ring-offset-2 ring-offset-gray-50 dark:ring-offset-gray-800 rounded-md"
91+
menus={[
92+
{
93+
label: "Edit",
94+
icon: HiPencil,
95+
role: "info",
96+
onClick: () => console.log("edit"),
97+
},
98+
{
99+
role: "separator",
100+
},
101+
{
102+
label: "Delete",
103+
role: "destructive",
104+
icon: HiTrash,
105+
onClick: () => console.log("delete"),
106+
},
107+
]}
108+
/>
109+
</div>
77110
<Input name="name" label="Name" type="text" />
78111
<Input name="email" label="Email" type="email" />
79112
<Textarea
80113
name="message"
81114
label="Message"
82115
description={{
83-
text: 'Please be as detailed as possible.',
116+
text: "Please be as detailed as possible.",
84117
icon: HiInformationCircle,
85118
}}
86119
/>
@@ -91,12 +124,7 @@ const Template: Story<StoryButtonProps> = args => {
91124
</Form>
92125
</div>
93126
<div>
94-
<Button
95-
onClick={() => submitBtnRef.current?.click()}
96-
shape="pill"
97-
weight="outline"
98-
color="green"
99-
>
127+
<Button onClick={() => submitBtnRef.current?.click()} shape="pill" weight="outline" color="green">
100128
Submit Button Ref
101129
</Button>
102130
</div>

0 commit comments

Comments
 (0)