Sha256: dc4aca1bb16e58542b4925e2c0289e066fe84880873a7305f5f96a9da49a6d80

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

class Skr.Components.PrintButton extends Lanes.React.BaseComponent

    propTypes:
        onPrint: React.PropTypes.func


    componentWillMount: ->   window.matchMedia('print')?.addListener(@onWindowPrint)
    componentWillUnmount: -> window.matchMedia('print')?.removeListener(@onWindowPrint)
    onWindowPrint: (mm) ->
        return if mm.matches # true == print is starting, false == complete
        _.delay( =>
            @props.onPrint?(false)
        , 1000)

    print: ->
        _.delay ->
            window.print()
        , 50 # a bit of time for all rendering to complete, and for the loading mask to hide

    onPrintClick: ->
        wait = @props.onPrint?(true)
        if _.isPromise(wait)
            wait.then @print
        else
            @print()

    render: ->
        if @props.iconOnly
            <LC.Icon type="print" onClick={@onPrintClick} />
        else
            <BS.Button className="print" onClick={@onPrintClick} bsSize='small'>
                <LC.Icon type="print" />Print
            </BS.Button>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stockor-0.5.0 client/skr/components/PrintButton.cjsx
stockor-0.4.0 client/skr/components/PrintButton.cjsx