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

@gzbapp/components

v1.3.5

Published

gzb app components

Downloads

1,151

Readme


name: '@gzbapp/components'

@gzbapp/components 是严格根据 SAPP UI 规范定制的一套组件库,主要用于工作宝应用前台。 SAPP UI 规范定制2.0-更新于2023-05

特点

  • 组件高度自治, 业务解耦
  • 支持深色模式
  • 适配移动端和桌面端
  • 支持多语言

安装

$ yarn add @gzbapp/components

因为 @gzbapp/components SAPP 开发套件的一部分,也可以通过 @gzbapp/packages 安装:

$ yarn add @gzbapp/packages

配置

以 @gdjiami/cli 为例, package.json 配置如下:

{
  // ...
  "jm": {
    "importPlugin": [
      {
        "libraryName": "antd",
        "libraryDirectory": "es",
        "style": "css"
      },
      {
        "libraryName": "@gzbapp/components",
        "libraryDirectory": "es",
        "style": "css"
      }
    ]
  }
}

我们使用了和 antd 一样的源代码组织结构,通过 babel-import-plugin 来实现按需导入代码和样式。

基本用法

初始化多语言

@gzbapp/components 依赖于 @gzbapp/i18n 来实现多语言,所以在入口处,需要进行多语言初始化:

/**
 * App entry
 */
import ready from '@gzbapp/runtime'
import i18n, { initial, addAppBundles, AvailableLanguge } from '@gzbapp/i18n'
import { I18n } from '@gzbapp/components'

import React from 'react'
import ReactDOM from 'react-dom'
import App from '~/containers/App'

ready().then(async () => {
  if (window.GZBSupport) {
    // 初始化 i18n
    await initial({
      supportBackend: true,
      backendName: 'demo',
    })

    // 加载组件库多语言
    await I18n.initial()

    // 本地多语言
    addAppBundles({
      [AvailableLanguge.zh]: {
        hello: '你好',
      },
      [AvailableLanguge.tw]: {
        hello: '你好',
      },
      [AvailableLanguge.en]: {
        hello: 'hello',
      },
    })

    ReactDOM.render(<App />, document.getElementById('root'), () => {
      console.log('首次渲染完成, 耗时 ', performance.now() + ' ms')
    })
  }
})

组件使用

用法和 Antd 一样,具体组件用法见组件 API。

import React from 'react'
import { ScrollView, Button } from '@gzbapp/components'

export default function ButtonDemo() {
  return (
    <ScrollView className="jm-bg-main">
      <div className="jm-btns">
        <Button>hello</Button>
        <Button loading>hello</Button>
        <Button loading danger>
          hello
        </Button>
      </div>
      <Button type="block">hello</Button>
      <Button type="block" danger>
        hello
      </Button>
      <Button type="rounded">hello</Button>
      <Button type="rounded" disabled>
        hello
      </Button>
      <Button type="rounded" danger>
        hello
      </Button>
      <Button type="rounded" danger loading>
        hello
      </Button>
    </ScrollView>
  )
}

因为导入语句会经过 babel-import-plugin 处理, 最终编译结果为:

import ScrollView from '@gzbapp/components/es/scroll-view'
import '@gzbapp/components/es/scroll-view/style/css'
import Button from '@gzbapp/components/es/button'
import '@gzbapp/components/es/button/style/css'

所以说 import-plugin 的配置非常重要,它可以确保按需导入样式和组件。

Typescript 类型

所有组件的 Typescript 类型声明都定义在导出变量 T 中, 例如你可以通过下面的代码导入 Avatar 组件的 AvatarProps

import { T } from '@gzbapp/components'

export interface MyProps extends T.Avatar.AvatarProps {}

SAPP UI 规范定制2.0 更新记录

  1. app-layout组件封装完成(20230706)