New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@_y/acss-rn

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@_y/acss-rn

基于React Native实现的Atomic CSS,用于快速简易地便编写RN对象样式。

latest
npmnpm
Version
1.0.1
Version published
Maintainers
3
Created
Source

ACSS RN版本

基于React Native实现的Atomic CSS,用于快速简易地便编写RN对象样式。

安装

npm install --save  @_y/acss-rn

用法

基础版本

import React from 'react';
import  { V, T } from '@_y/acss-rn'
export default class App extends React.Component {
  render() {
    return (
        <V mt="40">
            <T c="#123212">测试测试</T>  
        </V>
    );
  }
}

进阶版本

封装组件,并传递props样式

import React from 'react';
import  { V, T } from '@_y/acss-rn'

// Button
export default function(props) {
    return (
        <V {...props}><T c_fff={props.c_fff}>这是一个按钮</T></V>
    );
}

//调用
import Button from './components/Button'
export default class App extends React.Component {
  render() {
    return (
        <V mt="40">
            <Button bg={"yellow"} c_fff w="50" d="block"></Button>
            <Button bg={"gray"} c_fff w="50" d="block"></Button>  
            <Button bg={"blue"} c_fff w="50" d="block"></Button>  
            <Button bg={"red"} c_fff w="50" d="block"></Button>    
        </V>
    );
  }
}

详情API查询

styled-components

对外API对应作用使用
VView类似于HTML中的div<Div mt="10"></Div>
TText不同与HMTL中的P,类似于span<P mt="10">aaaaaa</P>
ImgImageHTML中的img
ImgBgImageBackground
ComponentStyled/封装对象,使其拥有ACSS样式CustomStyle(View)
SpeedCustomComponent/快速创建组件SpeedCustomComponent(View)

自定义样式组件

方式一

快速创建组件

定义

const V = SpeedCustomComponent(View)

使用

<V mt="50"><T>快速创建组件</T></V>

方式二

自定义属性类型

定义组件,以Text为例子

首先封装成带有ACSS样式的组件

const TStyled = styled(Text)`${props => Acss(props)};`;

再封装成高阶组件,可处理props,最后返回自定义的组件。

const T = ({ ttu, ttc, children, ...otherProps }) => {
  let text = children;
  // 安卓设置了这个属性文字直接就不显示了
  let isAndriod = Platform.OS !== "ios" ? true : false;
  if (ttu && isAndriod) {
    //变成小写
    text = text.toUpperCase();
  } else if (ttc && isAndriod) {
    //变成大写
    text = titleCase(text);
  }
  return (
    <TStyled
      ttu={isAndriod ? false : ttu}
      ttc={isAndriod ? false : ttc}
      {...otherProps}
    >
      {text}
    </TStyled>
  );
};

单位转换问题

根据屏幕大小给予不同dp 基数320px的屏幕16px为基准。

屏幕大小size
<32014px
<36116px~18px
<41418px~22px
<100118px~22px

ppx, rpx, dpx, spx, toPpx, toRpx, toDpx, toSpx, vh, vw, statusBarHeight

二维码体验Demo

安装expo app:https://expo.io/tools

ACSS支持API一览

不对应命名规则的各类API

特殊单位

API对应
wpwidth:${props.wp};单位是%
hpheight:${props.hp};单位是%
wrapmargin-left:${toPpx(16)}px; margin-right:${toPpx(16)}px
rowpadding-left:${toPpx(16)}px; padding-right:${toPpx(16)}px

其余按照命名规则存在的API

background

API对应
bgbackground
bgcbackground-color

text transform

API对应
tactext-align:center;
tartext-align:right;
ttutext-transform: uppercase
ttctext-transform: capitalize

flexbox

API对应
asfealign-self: flex-end;
aifsalign-items: flex-start;
fdrflex-direction: row;
fdcflex-direction: column;
fwnflex-wrap: nowrap;
aicalign-items: center;
jcsbjustify-content: space-between;
jccjustify-content: center;`
jcfejustify-content: flex-end;
f1flex:1;

font

API对应
fsfont-size: ${toPpx(props.fs)}px;
fwfont-weight:${props.fw};
ccolor: ${props.c};
c_lcolor: ${color.l};
c_mcolor: ${color.m};
c_scolor: ${color.s};
c_xscolor: ${color.xs};
c_000color: #000;};
c_fffcolor: #fff;};
c_primarycolor: ${color.primary}font-weight:${props.fw};`
c_dangercolor: ${color.danger}
c_successcolor: ${color.success}
c_warningcolor: ${color.warning}`

position

API对应
prposition:relative;
paposition:absolute;
t0top:0;
l0left:0;
r0right:0;
b0bottom:0;

border

API对应
brborder-radius:${props.br}px;

宽高

API对应
wwidth:${toPpx(props.w)}px;
hheight:${toPpx(props.h)}px;
lhline-height:${toPpx(props.lh)}px;

margin

API对应
mtmargin-top:${toPpx(props.mt)}px;
mrmargin-right:${toPpx(props.mr)}px;
mbmargin-bottom:${toPpx(props.mb)}px;
mlmargin-left:${toPpx(props.ml)}px;

padding

API对应
ppadding:${toPpx(props.p)}px;
ptpadding-top:${toPpx(props.pt)}px;
prpadding-right:${toPpx(props.pr)}px;
pbpadding-bottom:${toPpx(props.pb)}px
plpadding-left:${toPpx(props.pl)}px;

opacity

API对应
oopacity:${toPpx(props.o)};

FAQs

Package last updated on 14 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts