npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pixui-react-imageviewer

v0.0.2

Published

pixui-react-imageviewer

Downloads

7

Readme

ImageViewer组件(react)

组件功能

在pixui页面中自适应展示大图。功能逐渐完善中,目前仅支持图片静态展示。后续将逐渐支持滑动、缩放,旋转等功能。

组件实现

基于preact框架

支持属性

| 属性名 | 取值 | | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | src |必传属性:string ,所需展示的大图的url | | onClose | 必传属性:Function ,触发关闭时执行的回调函数 | | backgroundStyle |可选属性:CSSProperties ,底层背景样式,通常为全屏的半透明黑色遮罩,如不传值,则默认为{width:'100%',height:'100%',display: 'flex',flexDirection: 'row',justifyContent: 'center',alignItems: 'center',} | | imageBoxStyle | 可选属性:CSSProperties ,当希望ImageViewer中要展示的图片有背景框时使用;如不传值,则默认没有背景框。 | | imageAreaStyle | 可选属性:CSSProperties ,主要用于控制图片显示的大小和范围。当前图片的长或宽大于该属性所指定的大小范围时,将自适应等比例缩小到该范围内,并完整展示。 在不传入任何值的情况下,图片默认显示范围为 imageBoxStyle 大小的 80% 80%。 | | imageStyle | 可选属性:CSSProperties,图片样式。** 注意,不可以在该样式中传入width、height等指定图片大小的属性,图片大小在组件中会根据imageArea尺寸自适应计算,在imageStyle中指定图片大小无法保证图片的自适应展示 ** | | closeOnClickOutside | 可选属性:boolean,默认为true。点击图片以外的区域关闭imageViewer。如该属性为false,则必须自己实现关闭imageViewer的方法。 |

ImageViewer组件模型

imageViewer组件模型

使用注意事项

  1. 因pixui在元素布局和尺寸上的特性,如果要使用该组件实现图片全屏居中展示的预期效果,需要将该组件放在所需展示界面的root节点下,以保证该组件能以正确的布局展示内容。

使用示例

示例代码

import { Component } from 'preact'
import { ImageViewer } from 'pixuireactcomponents';
import { Images } from './Images';

export class ImageViewerDemo extends Component<any, {
    isViewerOpen: boolean;
    imageUrl:string;
}> {
    constructor(props) {
        super(props);
        this.state = {
            isViewerOpen: false,
            imageUrl:'',
        };
    }

    onOpenImageViewer (url) {
        console.log('onOpen');
        this.setState({
            isViewerOpen: true,
            imageUrl:url,
        })
    }

    onCloseImageViewer = () => {
        console.log('onClose');
        this.setState({
            isViewerOpen: false,
        })
    }

    render() {
        return (
            <div style={{
                width: '100%',
                height: '100%',
            }}>
                {/* <ImageViewer>应在root节点下才能保证全屏居中展示 */}
                {this.state.isViewerOpen && <ImageViewer
                    src={this.state.imageUrl}
                    onClose={this.onCloseImageViewer}
                    imageAreaStyle={{
                        width: '80%',
                        height: '80%',
                    }}
                />}

                <div style={{
                    backgroundColor: 'rgba(125,0,0,0.8)',
                    display: 'flex',
                    flexDirection: 'row',
                    justifyContent: 'center',
                    alignItems: 'center',
                    width: '50%',
                    height: '50%',
                }}>
                    <img src={Images.bg1}
                        style={{ width: '166px', height: '102.4px' }}
                        onClick={()=>this.onOpenImageViewer(Images.bg1)} />
                                            <img src={Images.bg2}
                        style={{ width: '166px', height: '102.4px' }}
                        onClick={()=>this.onOpenImageViewer(Images.bg2)} />
                </div>
            </div>
        );
    }
}