Coder Social home page Coder Social logo

reagent-contextmenu's Introduction

reagent-contextmenu

Context menu components for Reagent.

Takes care of all the little details for creating a context menu.

(Compatible with Bootstrap; already uses UL and LI elements along with the dropdown-menu class.)

Context menu demo

Install

Add this to your project dependencies:

Clojars Project

The Bootstrap CSS is recommended if you don't want to style the menu yourself, along with contextmenu.css (especially for submenus).

Usage

Include the context-menu component in the root of your document:

(defn main-page []
	[:div
	  [:h1 "Page title"]
	  [:span "Some content"]
	  [menu/context-menu]]) ;  <-------

Everytime you want to show a context-menu to the user, you just need to call context! by passing it the :on-context-menu event and the name-function collection.

Name-function pairs should be of the following form: [name fn]. If fn is nil, the menu will mark this item with the disabled class.

If you replace the name-fn by a keyword, it will place a divider.

Finally, you if replace the name-fn by a string, it will be considered a section heading.

Note that the name can be any Reagent component.

[:div {:on-context-menu
       (fn [evt]
         (menu/context! 
          evt
          ["Some title"             ; <---- string is a section title
           ["my-fn" #(prn "my-fn")]
           [[:span "my-other-fn"] #(prn "my-other-fn")] ; <---- the name is a span
           :divider                    ; <--- keyword is a divider
           [[:span 
             [:span.cmd "Copy"] 
             [:span.kbd.text-muted "ctrl-c"]] ; <--- some classes to show a keyboard shortcut
            #(prn "Copy")]
           ["Submenu" 
            ["Submenu title" ["Submenu item 1" #(prn "Item 1")]]]]))}] ; <-- submenus are simply nested menus.

You can style your context menu with CSS and the class context-menu.

Pressing Esc or clicking outside the context-menu will hide it.

The backdrop, which is transparent by default, can be styled using the class context-menu-backdrop.

reagent-contextmenu's People

Contributors

frozenlock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.