Code Monkey home page Code Monkey logo

breaking-point's Introduction

BREAKING-POINT

" I don’t know; every man has his breaking point."

  • Red, The Shawshank Redemption

BREAKING-POINT lets you quickly define and subscribe to screen breakpoints in your re-frame application.

Add the following to the :dependencies vector in your project.clj file.

[breaking-point "0.1.2"]

And in your ns:

(ns your-ns
  (:require [breaking-point.core :as bp]))

breaking-point gif not found

API

::bp/set-breakpoints

::bp/set-breakpoints takes a hash-map with the following shape:

key type default required?
:breakpoints [keyword int keyword int ... keyword] yes
:debounce-ms int 0 no

Breakpoints takes a series of keywords alternating with ints that will be used as breakpoints. Make sure the breakpoints are ascending in value. Here is an example:

(re-frame/dispatch-sync [::bp/set-breakpoints
                         {;; required
                          :breakpoints [:mobile
                                        768
                                        :tablet
                                        992
                                        :small-monitor
                                        1200
                                        :large-monitor]

                          ;; optional
                          :debounce-ms 166
                          }])

You can have as many breakpoints as you want and name them whatever you want, just be sure to alternate keywords with ascending ints.

When you disptach ::bp/set-breakpoints, it will register subscriptions based on the provided keywords and breakpoints that you supplied.

(re-frame/subscribe [::bp/screen-width]) ;; will be an int
(re-frame/subscribe [::bp/screen-height]) ;; will be an int
(re-frame/subscribe [::bp/screen]) ;; will be one of the following: :mobile, :tablet, :small-monitor, :large-monitor

(re-frame/subscribe [::bp/orientation]) ;; will be either :portrait or :landscape
(re-frame/subscribe [::bp/landscape?]) ;; true if width is >= height
(re-frame/subscribe [::bp/portrait?]) ;; true if height > width

;; these will be based on the breakpoint names that you provide
(re-frame/subscribe [::bp/mobile?]) ;; true if screen-width is < 768
(re-frame/subscribe [::bp/tablet?]) ;; true if screen-width is >= 768 and < 992
(re-frame/subscribe [::bp/small-monitor?]) ;; true if window width is >= 992 and < 1200
(re-frame/subscribe [::bp/large-monitor?]) ;; true if window width is >= 1200

Note, ::bp/set-breakpoints should only be dispatched once when the application first loads.

Usage

Create a new re-frame application and add the +breaking-point option.

lein new re-frame foo +breaking-point

Questions

If you have questions, I can usually be found hanging out in the clojurians #reagent slack channel (my handle is @gadfly361).

License

Copyright © 2018 Matthew Jaoudi

Distributed under the The MIT License (MIT).

breaking-point's People

Contributors

gadfly361 avatar

Watchers

James Cloos 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.