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

className and better style support #5

Merged
merged 4 commits into from
Feb 26, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.npmrc
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ Then use it in your app:

```jsx
import React from "react";
/* Library comes with some super basic MenuButtons: */
/* Library comes with some super basic MenuButtons. You can import default styles and use them as a starting point.
The example below shows how to use the `classNames` prop to style the menu, popover, and arrow elements with something like Tailwind.*/
import { HighlightMenu, MenuButton } from "react-highlight-menu";

export default function App() {
return (
<div className="app">
<div className="tailwind-menu-example">
<HighlightMenu
target=".app"
allowedPlacements={["top", "bottom"]}
classNames={{
menu: "flex gap-1 p-1",
popover: "bg-white shadow-lg rounded-md border border-gray-200",
arrow: "fill-white",
}}
target=".tailwind-menu-example"
withoutStyles={true}
menu={({ selectedText = "", setClipboard, setMenuOpen }) => (
<>
<MenuButton
className="p-2 rounded-md hover:bg-gray-100 text-gray-700"
title="Copy to clipboard"
icon="clipboard"
onClick={() =>
Expand All @@ -41,8 +48,8 @@ export default function App() {
})
}
/>

<MenuButton
className="p-2 rounded-md hover:bg-gray-100 text-gray-700"
title="Search Google"
onClick={() => {
window.open(
Expand All @@ -54,12 +61,14 @@ export default function App() {
icon="magnifying-glass"
/>
<MenuButton
className="p-2 rounded-md hover:bg-gray-100 text-gray-700"
title="Close menu"
onClick={() => setMenuOpen(false)}
icon="x-mark"
/>
</>
)}
allowedPlacements={["top", "bottom"]}
/>
</div>
);
Expand All @@ -74,3 +83,23 @@ export default function App() {
- **allowedPlacements** - array of allowed placements `-'auto' | 'auto-start' | 'auto-end' | 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'right' | 'right-start' | 'right-end' | 'left' | 'left-start' | 'left-end'`
- **offset** - distance in pixels from highlighted words. `10`
- **zIndex** - zIndex of the popover `999999999`

## Customization

- **withoutStyles** - if true, the menu will be only styled with props that help it to function. And we the following classnames can be targeted for styling:
- `.rhm-popover` - for the popover element
- `.rhm-menu` - for the menu element
- `.rhm-button` - for the button element
- `.rhm-arrow` - for the arrow element
- `.rhm-anchor` - for the anchor element
- **classNames** - an object where classnames can be passed to the menu, popover, and arrow elements.
- `menu` - for the menu element
- `popover` - for the popover element
- `arrow` - for the arrow element

## Development

```bash
npm install
npm run dev
```
Loading
Loading