import React, { ReactNode, Fragment } from 'react'
import {styled} from '@linaria/react'
import {ZPX} from '../constants/constants'
import './widget.css'
export type TFontSize = string
export type TFontWeight = 'normal' | 'bold' | '900' | '800' | '700' | '600' |
'500' | '400' | '300' | '200' | '100' | 'bolder' | 'lighter' | 'initial' | 'inherit'
export type TFontSpacing = string
export type TOverflow = 'visible' | 'hidden' | 'scroll' | 'auto' | 'inherit' |
'visible visible' | 'visible hidden' | 'visible scroll' | 'visible auto' | 'visible inherit' |
'hidden visible' | 'hidden hidden' | 'hidden scroll' | 'hidden auto' | 'hidden inherit' |
'scroll visible' | 'scroll hidden' | 'scroll scroll' | 'scroll auto' | 'scroll inherit' |
'auto visible' | 'auto hidden' | 'auto scroll' | 'auto auto' | 'auto inherit' |
'inherit visible' | 'inherit hidden' | 'inherit scroll' | 'inherit auto' | 'inherit inherit'
export type TDisplay = 'flex' | 'inline' | 'block' | 'inline-block' | 'none'
export type TFlexWay = 'fraa' | 'frab' | 'frac' | 'frae' | 'fras' |
'frba' | 'frbb' | 'frbc' | 'frbe' | 'frbs' |
'frca' | 'frcb' | 'frcc' | 'frce' | 'frcs' |
'frea' | 'freb' | 'frec' | 'free' | 'fres' |
'frsa' | 'frsb' | 'frsc' | 'frse' | 'frss' |
'fcaa' | 'fcab' | 'fcac' | 'fcae' | 'fcas' |
'fcba' | 'fcbb' | 'fcbc' | 'fcbe' | 'fcbs' |
'fcca' | 'fccb' | 'fccc' | 'fcce' | 'fccs' |
'fcea' | 'fceb' | 'fcec' | 'fcee' | 'fces' |
'fcsa' | 'fcsb' | 'fcsc' | 'fcse' | 'fcss'
export type TBoxSizing = 'content-box' | 'border-box'
export type TPosition = 'absolute' | 'fixed' | 'relative' | 'static' | 'sticky' | 'inherit'
export type TBgImageType = 'aspectFit' | 'aspectFill'
export type TSafeType = 'top' | 'bottom'
export type TTextDecoration = 'underline' | 'none' | 'line-through'
export type TFlexWrap = 'nowrap' | 'wrap' | 'wrap-reverse' | 'inherit' | 'initial' | 'unset'
export type TFontStyle = 'normal' | 'italic' | 'oblique' | 'inherit'
export type TWhiteSpace = 'normal' | 'nowrap' | 'pre' | 'pre-wrap' | 'pre-line' | 'break-spaces'
export type TPointerEvents = 'auto' | 'none'
export type TStroke = string
export type TLeft = string
export type TRight = string
export type TTop = string
export type TBottom = string
export type TPadding = string
export type TMargin = string
export type TSize = string
export type TRadius = string
export type TColor = string
export type TZIndex = string
export type TOpacity = string
export type TBackDrop = string
export type TMinHeight = string
export type TMaxHeight = string
export type THoverBgColor = string
export type TWordBreak = 'break-all' | 'normal' | 'keep-all' | 'break-word'
export type TFlexShrink = '0' | '1' | 'inherit' | 'initial'
export type TBgGradient = string[]
export type TTextAlign = 'left' | 'right' | 'center' | 'start' | 'end' | 'justify'
export type TJustifyContent = 'center' | 'space-between' | 'space-around' | 'flex-end' | 'flex-start'
export type TBorderWidth = string
export type TBorderStyle = "dotted" | "dashed" | "solid" |
"double" | "groove" | "ridge" | "inset" |
"outset" | "none" | "hidden"
// 块
interface BlockProps{
children?: ReactNode
}
export const Block = (props: BlockProps) => (
{props.children}
)
interface BoxBase {
/**
* 盒子宽度和高度,如:‘50 50’,先写宽度,后写高度,中间用空格隔开。宽高必须同时写上,支持数字、%、auto
* @default 'auto auto'
*/
size?: TSize
/**
* 盒子圆角,如果四个角都要设置圆角,则写成 ‘15’。如果分别设置,则为 ‘12 2 12 2’,左上 右上 右下 左下
* 只能传数值,不能传百分比
*/
radius?: TRadius
overflow?: TOverflow
/**
* @default 'border-box'
*/
boxSizing?: TBoxSizing
/** 盒子背景色 */
bgColor?: TColor
/** 盒子暗黑背景 */
_bgColor?: TColor
/** 盒子背景填充图片 */
bgImage?: TColor
/** 深色模式 盒子背景填充图片 */
_bgImage?:TColor
/** 背景图片适应类型,和 image 的 mode 类似 */
bgImageType?: TBgImageType
position?: TPosition
left?: TLeft
top?: TTop
right?: TRight
bottom?: TBottom
/** 边框阴影颜色。有值,则显示边框阴影。无值,则没边框阴影。 */
shadowColor?: TColor
_shadowColor?: TColor
/** 边框的颜色,目前不支持单边设置,但你可以用 Line 组件实现 */
borderColor?: TColor
_borderColor?: TColor
/** 边框宽度,默认为 '1',且只有当 borderColor 有值时,宽度才生效。目前不支持单边设置,但你可以用 Line 组件实现 */
borderWidth?: TBorderWidth
/** 边框样式,,默认 solid */
borderStyle?: TBorderStyle,
zIndex?: TZIndex
opacity?: TOpacity
/**
* 毛玻璃效果的效果值,一般设置为 20。
*/
backdrop?: TBackDrop
minHeight?: TMinHeight
maxHeight?: TMaxHeight
minWith?: string
maxWith?: string
/** 盒子是否有点击事件,默认为有的 */
pointerEvents?: TPointerEvents
/** Flex 布局时,如果被压缩,可以设置为 0 ,防止变形压缩 */
flexShrink?: TFlexShrink
/** 渐变色,即 linear-gradient(23deg, red, blue) => bgGradient={[23deg, red, blue]} */
bgGradient?: TBgGradient
_bgGradient?: TBgGradient
}
export interface BoxProps extends BoxBase{
/**
* 盒子类型,如果想实现自动换行,此值可设置为 ‘flex’,同时 flexWrap 设置为 'wrap'
*/
display?: TDisplay
/** 布局 padding 形式为: ‘10’ ‘12 4’ ‘12 4 2 5’ */
padding?: TPadding
/** 布局 margin 形式为: ‘10’ ‘12 4’ ‘12 4 2 5’ */
margin?: TMargin
flexWrap?: TFlexWrap
justifyContent?: TJustifyContent
whiteSpace?: TWhiteSpace
fontSize?: TFontSize
color?: TColor
_color?: TColor
fontWeight?: TFontWeight
letterSpacing?: TFontSpacing
lineHeight?: string
textDecoration?: TTextDecoration
stroke?: TStroke
fontStyle?: TFontStyle
wordBreak?: TWordBreak
textAlign?: TTextAlign
}
export const Box = styled.div`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : 'auto'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? 'auto' : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : 'auto'};
box-sizing: ${props => props.boxSizing ? props.boxSizing : 'border-box'};
padding: ${props => props.padding ? (props.padding.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
margin: ${props => props.margin ? (props.margin.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border-radius: ${props => props.radius ? (props.radius.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border: ${props => props.borderColor ? `${(props.borderWidth || 1)+ZPX} ${props.borderStyle || 'solid'} ${props.borderColor}` : 'none'};
overflow: ${props => props.overflow || 'visible'};
background-color: ${props => props.bgColor || 'transparent'};
background-image: ${props => props.bgImage ? props.bgImage : props.bgGradient ? 'linear-gradient(' + props.bgGradient.toString() + ')' : 'none'};
backdrop-filter: ${props => props.backdrop ? `blur(${props.backdrop}px)` : 'none'};
pointer-events: ${props => props.pointerEvents || 'auto'};
white-space: ${props => props.whiteSpace || 'normal'};
min-height: ${props => props.minHeight ? props.minHeight + ZPX : 'auto'};
max-height: ${props => props.maxHeight ? props.maxHeight + ZPX : 'none'};
min-width: ${props => props.minWith ? props.minWith + ZPX : 'auto'};
max-width: ${props => props.maxWith ? props.maxWith + ZPX : 'none'};
background-size: ${props => props.bgImageType === 'aspectFit' ? 'contain' : 'cover'};
background-repeat: no-repeat;
background-position: center;
display: ${props => props.display || 'block'};
flex-wrap: ${props => props.flexWrap || 'nowrap'};
justify-content: ${props => props.justifyContent || 'flex-start'};
box-shadow: ${props => props.shadowColor ? `1${ZPX} 1${ZPX} 10${ZPX} 5${ZPX} ${props.shadowColor}` : 'none'};
position: ${props => props.position || 'static'};
left: ${props => props.left ? props.left + ZPX : 'auto'};
top: ${props => props.top ? props.top + ZPX : 'auto'};
right: ${props => props.right ? props.right + ZPX : 'auto'};
bottom: ${props => props.bottom ? props.bottom + ZPX : 'auto'};
z-index: ${props => props.zIndex ? props.zIndex : 'auto'};
opacity: ${props => props.opacity ? props.opacity : 'inherit'};
font-size: ${props => (props.fontSize || '14') + ZPX};
color: ${props => props.color || '#181818'};
font-style: ${props => props.fontStyle || 'normal'};
font-weight: ${props => props.fontWeight || 'normal'};
letter-spacing: ${props => props.letterSpacing ? props.letterSpacing + ZPX : 'normal'};
line-height: ${props => props.lineHeight ? props.lineHeight + ZPX : 'normal'};
text-decoration: ${props => props.textDecoration ? props.textDecoration : 'none'};
text-align: ${props => props.textAlign ? props.textAlign : 'start'};
opacity: ${props => props.opacity ? props.opacity : 'inherit'};
word-break: ${props => props.wordBreak ? props.wordBreak : 'normal'};
-webkit-text-stroke: ${props => (props.stroke ? (props.stroke.split(' ').length > 0 ? props.stroke.split(' ')[0] + ZPX + ' ' + props.stroke.split(' ')[1] : props.stroke.split(' ')[0]) : 'unset')};
flex-shrink: ${props => props.flexShrink || 'initial'};
`
export interface SafeAreaProps extends BoxBase{
/** 安全盒子类型,top 为顶部自适应安全距离。 bottom 为底部自适应安全距离 */
safe: TSafeType
display?: TDisplay
flexWrap?: TFlexWrap
justifyContent?: TJustifyContent
whiteSpace?: TWhiteSpace
}
export const SafeArea = styled.div`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : 'auto'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? 'auto' : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : 'auto'};
box-sizing: content-box;
padding-top: ${props => (props.safe === 'top' ? sys.statusBarHeight + 'PX' : '0')};
padding-bottom: ${props => (props.safe === 'bottom' ? 'env(safe-area-inset-bottom)': '0')};
border-radius: ${props => props.radius ? (props.radius.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border: ${props => props.borderColor ? `${(props.borderWidth || 1)+ZPX} ${props.borderStyle || 'solid'} ${props.borderColor}` : 'none'};
overflow: ${props => props.overflow || 'visible'};
background-color: ${props => props.bgColor || 'transparent'};
background-image: ${props => props.bgImage ? props.bgImage : props.bgGradient ? 'linear-gradient(' + props.bgGradient.toString() + ')' : 'none'};
backdrop-filter: ${props => props.backdrop ? `blur(${props.backdrop}px)` : 'none'};
pointer-events: ${props => props.pointerEvents || 'auto'};
white-space: ${props => props.whiteSpace || 'normal'};
min-height: ${props => props.minHeight ? props.minHeight + ZPX : 'auto'};
max-height: ${props => props.maxHeight ? props.maxHeight + ZPX : 'none'};
min-width: ${props => props.minWith ? props.minWith + ZPX : 'auto'};
max-width: ${props => props.maxWith ? props.maxWith + ZPX : 'none'};
background-size: ${props => props.bgImageType === 'aspectFit' ? 'contain' : 'cover'};
background-repeat: no-repeat;
background-position: center;
display: ${props => props.display || 'block'};
flex-wrap: ${props => props.flexWrap || 'nowrap'};
justify-content: ${props => props.justifyContent || 'flex-start'};
box-shadow: ${props => props.shadowColor ? `1${ZPX} 1${ZPX} 10${ZPX} 5${ZPX} ${props.shadowColor}` : 'none'};
position: ${props => props.position || 'static'};
left: ${props => props.left ? props.left + ZPX : 'auto'};
top: ${props => props.top ? props.top + ZPX : 'auto'};
right: ${props => props.right ? props.right + ZPX : 'auto'};
bottom: ${props => props.bottom ? props.bottom + ZPX : 'auto'};
z-index: ${props => props.zIndex ? props.zIndex : 'auto'};
opacity: ${props => props.opacity ? props.opacity : 'inherit'};
flex-shrink: ${props => props.flexShrink || 'initial'};
`
export interface FlexProps extends BoxBase{
/** flex 布局类型,如:‘frbc’ 参数为每个样式的关键字母提取。 */
flex: TFlexWay
/** 布局 padding 形式为: ‘10’ ‘12 4’ ‘12 4 2 5’ */
padding?: TPadding
/** 布局 margin 形式为: ‘10’ ‘12 4’ ‘12 4 2 5’ */
margin?: TMargin
fontSize?: TFontSize
color?: TColor
_color?: TColor
fontWeight?: TFontWeight
letterSpacing?: TFontSpacing
lineHeight?: string
textDecoration?: TTextDecoration
stroke?: TStroke
fontStyle?: TFontStyle
wordBreak?: TWordBreak
textAlign?: TTextAlign
}
export const Flex = styled.div`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : 'auto'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? 'auto' : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : 'auto'};
box-sizing: ${props => props.boxSizing ? props.boxSizing : 'border-box'};
padding: ${props => props.padding ? (props.padding.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
margin: ${props => props.margin ? (props.margin.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border-radius: ${props => props.radius ? (props.radius.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border: ${props => props.borderColor ? `${(props.borderWidth || 1)+ZPX} ${props.borderStyle || 'solid'} ${props.borderColor}` : 'none'};
overflow: ${props => props.overflow || 'visible'};
background-color: ${props => props.bgColor || 'transparent'};
background-image: ${props => props.bgImage ? props.bgImage : props.bgGradient ? 'linear-gradient(' + props.bgGradient.toString() + ')' : 'none'};
backdrop-filter: ${props => props.backdrop ? `blur(${props.backdrop}px)` : 'none'};
pointer-events: ${props => props.pointerEvents || 'auto'};
min-height: ${props => props.minHeight ? props.minHeight + ZPX : 'auto'};
max-height: ${props => props.maxHeight ? props.maxHeight + ZPX : 'none'};
min-width: ${props => props.minWith ? props.minWith + ZPX : 'auto'};
max-width: ${props => props.maxWith ? props.maxWith + ZPX : 'none'};
background-size: ${props => props.bgImageType === 'aspectFit' ? 'contain' : 'cover'};
background-repeat: no-repeat;
background-position: center;
display: flex;
box-shadow: ${props => props.shadowColor ? `1${ZPX} 1${ZPX} 10${ZPX} 5${ZPX} ${props.shadowColor}` : 'none'};
position: ${props => props.position || 'static'};
left: ${props => props.left ? props.left + ZPX : 'auto'};
top: ${props => props.top ? props.top + ZPX : 'auto'};
right: ${props => props.right ? props.right + ZPX : 'auto'};
bottom: ${props => props.bottom ? props.bottom + ZPX : 'auto'};
flex-direction: ${props => props.flex[1] === 'c' ? 'column' : 'row'};
justify-content: ${props =>
props.flex[2] === 'c' ? 'center' :
props.flex[2] === 'b' ? 'space-between':
props.flex[2] === 'a' ? 'space-around':
props.flex[2] === 'e' ? 'flex-end':
props.flex[2] === 's' ? 'flex-start': 'center'
};
align-items: ${props =>
props.flex[3] === 'c' ? 'center' :
props.flex[3] === 'b' ? 'space-between':
props.flex[3] === 'a' ? 'space-around':
props.flex[3] === 'e' ? 'flex-end':
props.flex[3] === 's' ? 'flex-start': 'center'
};
z-index: ${props => props.zIndex ? props.zIndex : 'auto'};
opacity: ${props => props.opacity ? props.opacity : 'inherit'};
font-size: ${props => (props.fontSize || '14') + ZPX};
color: ${props => props.color || '#181818'};
font-style: ${props => props.fontStyle || 'normal'};
font-weight: ${props => props.fontWeight || 'normal'};
letter-spacing: ${props => props.letterSpacing ? props.letterSpacing + ZPX : 'normal'};
line-height: ${props => props.lineHeight ? props.lineHeight + ZPX : 'normal'};
text-decoration: ${props => props.textDecoration ? props.textDecoration : 'none'};
text-align: ${props => props.textAlign ? props.textAlign : 'start'};
opacity: ${props => props.opacity ? props.opacity : 'inherit'};
word-break: ${props => props.wordBreak ? props.wordBreak : 'normal'};
-webkit-text-stroke: ${props => (props.stroke ? (props.stroke.split(' ').length > 0 ? props.stroke.split(' ')[0] + ZPX + ' ' + props.stroke.split(' ')[1] : props.stroke.split(' ')[0]) : 'unset')};
flex-shrink: ${props => props.flexShrink || 'initial'};
`
// 点击
export interface PressProps extends BoxProps{
sizeHover?: TSize
bgColorHover?: TColor
leftHover?: TLeft
topHover?: TTop
rightHover?: TRight
bottomHover?: TBottom
shadowColorHover?: TColor
borderColorHover?: TColor
borderWidthHover?: TBorderWidth
borderStyleHover?: TBorderStyle,
zIndexHover?: TZIndex
opacityHover?: TOpacity
backdropHover?: TBackDrop
/** Flex 布局时,如果被压缩,可以设置为 0 ,防止变形压缩 */
flexShrink?: TFlexShrink
/** 渐变色,即 linear-gradient(23deg, red, blue) => bgGradient={[23deg, red, blue]} */
bgGradientHover?: TBgGradient
fontSizeHover?: TFontSize
colorHover?: TColor
fontWeightHover?: TFontWeight
}
export const Press = styled.div`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : 'auto'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? 'auto' : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : 'auto'};
box-sizing: ${props => props.boxSizing ? props.boxSizing : 'border-box'};
padding: ${props => props.padding ? (props.padding.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
margin: ${props => props.margin ? (props.margin.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border-radius: ${props => props.radius ? (props.radius.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border: ${props => props.borderColor ? `${(props.borderWidth || 1)+ZPX} ${props.borderStyle || 'solid'} ${props.borderColor}` : 'none'};
overflow: ${props => props.overflow || 'visible'};
background-color: ${props => props.bgColor || 'transparent'};
background-image: ${props => props.bgImage ? props.bgImage : props.bgGradient ? 'linear-gradient(' + props.bgGradient.toString() + ')' : 'none'};
backdrop-filter: ${props => props.backdrop ? `blur(${props.backdrop}px)` : 'none'};
pointer-events: ${props => props.pointerEvents || 'auto'};
white-space: ${props => props.whiteSpace || 'normal'};
min-height: ${props => props.minHeight ? props.minHeight + ZPX : 'auto'};
max-height: ${props => props.maxHeight ? props.maxHeight + ZPX : 'none'};
min-width: ${props => props.minWith ? props.minWith + ZPX : 'auto'};
max-width: ${props => props.maxWith ? props.maxWith + ZPX : 'none'};
background-size: ${props => props.bgImageType === 'aspectFit' ? 'contain' : 'cover'};
background-repeat: no-repeat;
background-position: center;
display: ${props => props.display || 'block'};
flex-wrap: ${props => props.flexWrap || 'nowrap'};
justify-content: ${props => props.justifyContent || 'flex-start'};
box-shadow: ${props => props.shadowColor ? `1${ZPX} 1${ZPX} 10${ZPX} 5${ZPX} ${props.shadowColor}` : 'none'};
position: ${props => props.position || 'static'};
left: ${props => props.left ? props.left + ZPX : 'auto'};
top: ${props => props.top ? props.top + ZPX : 'auto'};
right: ${props => props.right ? props.right + ZPX : 'auto'};
bottom: ${props => props.bottom ? props.bottom + ZPX : 'auto'};
z-index: ${props => props.zIndex ? props.zIndex : 'auto'};
opacity: ${props => props.opacity ? props.opacity : 'inherit'};
font-size: ${props => (props.fontSize || '14') + ZPX};
color: ${props => props.color || '#181818'};
font-style: ${props => props.fontStyle || 'normal'};
font-weight: ${props => props.fontWeight || 'normal'};
letter-spacing: ${props => props.letterSpacing ? props.letterSpacing + ZPX : 'normal'};
line-height: ${props => props.lineHeight ? props.lineHeight + ZPX : 'normal'};
text-decoration: ${props => props.textDecoration ? props.textDecoration : 'none'};
text-align: ${props => props.textAlign ? props.textAlign : 'start'};
opacity: ${props => props.opacity ? props.opacity : 'inherit'};
word-break: ${props => props.wordBreak ? props.wordBreak : 'normal'};
-webkit-text-stroke: ${props => (props.stroke ? (props.stroke.split(' ').length > 0 ? props.stroke.split(' ')[0] + ZPX + ' ' + props.stroke.split(' ')[1] : props.stroke.split(' ')[0]) : 'unset')};
flex-shrink: ${props => props.flexShrink || 'initial'};
cursor: pointer;
transition: all 0.3s;
&:hover {
width: ${props => (props.sizeHover || props.size) ? ((props.sizeHover || props.size).split(' ')[0].includes('auto') ? 'auto' : (props.sizeHover || props.size).split(' ')[0].includes('(') ? 'calc' + (props.sizeHover || props.size).split(' ')[0].replace(/([\-\+])/g, ' $1 ') : (props.sizeHover || props.size).split(' ')[0].includes('%') ? (props.sizeHover || props.size).split(' ')[0] : (props.sizeHover || props.size).split(' ')[0] + ZPX) : 'auto'};
height: ${props => (props.sizeHover || props.size) ? ((props.sizeHover || props.size).split(' ')[1].includes('auto') ? 'auto' : (props.sizeHover || props.size).split(' ')[1].includes('(') ? 'calc' + (props.sizeHover || props.size).split(' ')[1].replace(/([\-\+])/g, ' $1 ') : (props.sizeHover || props.size).split(' ')[1].includes('%') ? (props.sizeHover || props.size).split(' ')[1] : (props.sizeHover || props.size).split(' ')[1] + ZPX) : 'auto'};
border: ${props => (props.borderColorHover || props.borderColor) ? `${((props.borderWidthHover || props.borderWidth) || 1)+ZPX} ${(props.borderStyleHover || props.borderStyle) || 'solid'} ${(props.borderColorHover || props.borderColor)}` : 'none'};
background-color: ${props => (props.bgColorHover || props.bgColor) || 'transparent'};
backdrop-filter: ${props => (props.backdropHover || props.backdrop) ? `blur(${(props.backdropHover || props.backdrop)}px)` : 'none'};
box-shadow: ${props => (props.shadowColorHover || props.shadowColor) ? `1${ZPX} 1${ZPX} 10${ZPX} 5${ZPX} ${(props.shadowColorHover || props.shadowColor)}` : 'none'};
left: ${props => (props.leftHover || props.left) ? (props.leftHover || props.left) + ZPX : 'auto'};
top: ${props => (props.topHover || props.top) ? (props.topHover || props.top) + ZPX : 'auto'};
right: ${props => (props.rightHover || props.right) ? (props.rightHover || props.right) + ZPX : 'auto'};
bottom: ${props => (props.bottomHover || props.bottom) ? (props.bottomHover || props.bottom) + ZPX : 'auto'};
z-index: ${props => (props.zIndexHover || props.zIndex) ? (props.zIndexHover || props.zIndex) : 'auto'};
opacity: ${props => (props.opacityHover || props.opacity) ? (props.opacityHover || props.opacity) : 'inherit'};
font-size: ${props => ((props.fontSizeHover || props.fontSize) || '14') + ZPX};
color: ${props => (props.colorHover || props.color) || '#181818'};
}
`
export interface LineProps {
/** 自适应安全区域。top 为上边距安全,bottom 为底部安全 */
safe?: TSafeType
/** 线条颜色 */
bgColor?: TColor
_bgColor?: TColor
size?: string
radius?: TRadius
/** Flex 布局时,如果被压缩,可以设置为 0 ,防止变形压缩 */
flexShrink?: TFlexShrink
/** 渐变色,即 linear-gradient(23deg, red, blue) => bgGradient={[23deg, red, blue]} */
bgGradient?: TBgGradient
}
export const Line = styled.div`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : 'auto'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? 'auto' : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : 'auto'};
background-color: ${props => props.bgColor || 'rgba(255,255,255,0)'};
border-radius: ${props => props.radius ? (props.radius.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
padding-top: ${props => (props.safe === 'top' ? 'env(safe-area-inset-top)' : '0')};
padding-bottom: ${props => (props.safe === 'bottom' ? 'env(safe-area-inset-bottom)': '0')};
flex-shrink: ${props => props.flexShrink || 'initial'};
background-image: ${props => props.bgGradient ? 'linear-gradient(' + props.bgGradient.toString() + ')' : 'none'};
`
export interface TextProps{
padding?: TPadding
margin?: TMargin
fontSize?: TFontSize
color?: TColor
_color?: TColor
fontWeight?: TFontWeight
letterSpacing?: TFontSpacing
lineHeight?: string
textDecoration?: TTextDecoration
opacity?: TOpacity
/** 即 -webkit-text-stroke */
stroke?: TStroke
fontStyle?: TFontStyle
wordBreak?: TWordBreak
/** 文字渐变, linear-gradient(to right, #2ea0f9, #5031e7); => gradient={[23deg, red, blue]} */
gradient?: TBgGradient
textAlign?: TTextAlign
size?: TSize
minHeight?: TMinHeight
maxHeight?: TMaxHeight
minWith?: string
maxWith?: string
whiteSpace?: TWhiteSpace
}
export const Text = styled.span`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : 'auto'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? 'auto' : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : 'auto'};
padding: ${props => props.padding ? (props.padding.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
margin: ${props => props.margin ? (props.margin.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
font-size: ${props => (props.fontSize || '14') + ZPX};
color: ${props => (props.gradient ? 'transparent' : props.color) || '#181818'};
font-style: ${props => props.fontStyle || 'normal'};
font-weight: ${props => props.fontWeight || 'normal'};
letter-spacing: ${props => props.letterSpacing ? props.letterSpacing + ZPX : 'normal'};
line-height: ${props => props.lineHeight ? props.lineHeight + ZPX : 'normal'};
text-decoration: ${props => props.textDecoration ? props.textDecoration : 'none'};
opacity: ${props => props.opacity ? props.opacity : 'inherit'};
word-break: ${props => props.wordBreak ? props.wordBreak : 'normal'};
white-space: ${props => props.whiteSpace || 'normal'};
text-align: ${props => props.textAlign ? props.textAlign : 'start'};
-webkit-text-stroke: ${props => (props.stroke ? (props.stroke.split(' ').length > 0 ? props.stroke.split(' ')[0] + ZPX + ' ' + props.stroke.split(' ')[1] : props.stroke.split(' ')[0]) : 'unset')};
background-image: ${props => props.gradient ? 'linear-gradient(' + props.gradient.toString() + ')' : 'none'};
-webkit-background-clip: text;
min-height: ${props => props.minHeight ? props.minHeight + ZPX : 'auto'};
max-height: ${props => props.maxHeight ? props.maxHeight + ZPX : 'none'};
min-width: ${props => props.minWith ? props.minWith + ZPX : 'auto'};
max-width: ${props => props.maxWith ? props.maxWith + ZPX : 'none'};
`
export interface TextEllipsisProps extends TextProps{
/**
* 多选文本自动省略。此值为设置最多显示几行
* @default '1'
*/
line?: string
}
export const TextEllipsis = styled.span`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : 'auto'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? 'auto' : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : 'auto'};
padding: ${props => props.padding ? (props.padding.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
margin: ${props => props.margin ? (props.margin.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
font-size: ${props => (props.fontSize || '14') + ZPX};
color: ${props => (props.gradient ? 'transparent' : props.color) || '#181818'};
font-style: ${props => props.fontStyle || 'normal'};
font-weight: ${props => props.fontWeight || 'normal'};
letter-spacing: ${props => props.letterSpacing ? props.letterSpacing + ZPX : 'normal'};
display: -webkit-box;
line-height: ${props => props.lineHeight ? props.lineHeight + ZPX : 'normal'};
overflow: hidden;
text-overflow: ellipsis;
word-wrap: break-word;
white-space: normal !important;
-webkit-line-clamp: ${props => props.line || '1'};
-webkit-box-orient: vertical;
text-decoration: ${props => props.textDecoration ? props.textDecoration : 'none'};
opacity: ${props => props.opacity ? props.opacity : 'inherit'};
text-align: ${props => props.textAlign ? props.textAlign : 'start'};
-webkit-text-stroke: ${props => (props.stroke ? (props.stroke.split(' ').length > 0 ? props.stroke.split(' ')[0] + ZPX + ' ' + props.stroke.split(' ')[1] : props.stroke.split(' ')[0]) : 'unset')};
background-image: ${props => props.gradient ? 'linear-gradient(' + props.gradient.toString() + ')' : 'none'};
-webkit-background-clip: text;
min-height: ${props => props.minHeight ? props.minHeight + ZPX : 'auto'};
max-height: ${props => props.maxHeight ? props.maxHeight + ZPX : 'none'};
min-width: ${props => props.minWith ? props.minWith + ZPX : 'auto'};
max-width: ${props => props.maxWith ? props.maxWith + ZPX : 'none'};
`
// 图片
interface ImageProps {
size?: TSize
padding?: TPadding
margin?: TMargin
radius?: TRadius
src: string
position?: TPosition
left?: TLeft
top?: TTop
right?: TRight
bottom?: TBottom
zIndex?: TZIndex
opacity?: TOpacity
pointerEvents?: TPointerEvents
}
export const Image = styled.img`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : 'auto'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? 'auto' : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : 'auto'};
padding: ${props => props.padding ? (props.padding.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
margin: ${props => props.margin ? (props.margin.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border-radius: ${props => props.radius ? (props.radius.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
display: block;
position: ${props => props.position || 'static'};
pointer-events: ${props => props.pointerEvents || 'auto'};
left: ${props => props.left ? props.left + ZPX : 'auto'};
top: ${props => props.top ? props.top + ZPX : 'auto'};
right: ${props => props.right ? props.right + ZPX : 'auto'};
bottom: ${props => props.bottom ? props.bottom + ZPX : 'auto'};
z-index: ${props => props.zIndex ? parseInt(props.zIndex) : 'auto'};
opacity: ${props => props.opacity ? parseFloat(props.opacity) : 'inherit'};
`
// Input
interface InputProps {
size?: TSize
padding?: TPadding
margin?: TMargin
radius?: TRadius
position?: TPosition
left?: TLeft
top?: TTop
right?: TRight
bottom?: TBottom
fontSize?: TFontSize
color?: TColor
bgColor?: TColor
pColor?: TColor
fontWeight?: TFontWeight
letterSpacing?: TFontSpacing
placeholder?: string
onInput?: Function
onFocus?: Function
onBlur?: Function
onConfirm?: Function
value?: string | number,
maxlength?: string
type?: 'text' | 'number' | 'idcard' | 'digit' | 'number'
}
export const Input = styled.input`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : '100%'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? '40' + ZPX : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : '80' + ZPX};
padding: ${props => props.padding ? (props.padding.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
margin: ${props => props.margin ? (props.margin.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border-radius: ${props => props.radius ? (props.radius.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
display: 'block'};
box-sizing: 'border-box'};
background-color: ${props => props.bgColor || '#efefef'};
font-size: ${props => (props.fontSize || '14') + ZPX};
color: ${props => props.color || '#181818'};
font-weight: ${props => props.fontWeight || 'normal'};
letter-spacing: ${props => props.letterSpacing ? props.letterSpacing + ZPX : 'normal'};
&::-webkit-input-placeholder{
color: ${props => props.pColor || '#999999'};
}
`
interface TextareaProps extends InputProps{
}
export const Textarea = styled.textarea`
width: ${props => props.size ? (props.size.split(' ')[0].includes('auto') ? 'auto' : props.size.split(' ')[0].includes('(') ? 'calc' + props.size.split(' ')[0].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[0].includes('%') ? props.size.split(' ')[0] : props.size.split(' ')[0] + ZPX) : '100%'};
height: ${props => props.size ? (props.size.split(' ')[1].includes('auto') ? '40' + ZPX : props.size.split(' ')[1].includes('(') ? 'calc' + props.size.split(' ')[1].replace(/([\-\+])/g, ' $1 ') : props.size.split(' ')[1].includes('%') ? props.size.split(' ')[1] : props.size.split(' ')[1] + ZPX) : '80' + ZPX};
padding: ${props => props.padding ? (props.padding.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
margin: ${props => props.margin ? (props.margin.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
border-radius: ${props => props.radius ? (props.radius.replace(/\s/g, ZPX + ' ') + ZPX) : '0' + ZPX};
display: 'block'};
box-sizing: 'border-box'};
background-color: ${props => props.bgColor || '#efefef'};
font-size: ${props => (props.fontSize || '14') + ZPX};
color: ${props => props.color || '#181818'};
font-weight: ${props => props.fontWeight || 'normal'};
letter-spacing: ${props => props.letterSpacing ? props.letterSpacing + ZPX : 'normal'};
&::-webkit-input-placeholder{
color: ${props => props.pColor || '#999999'};
}
`
/** 按钮 */
interface ButtonProps {
loading?: boolean
letterSpacing?: TFontSpacing
children: ReactNode
onClick?: Function
fontSize?: TFontSize
color?: TColor
fontWeight?: TFontWeight
disable?: boolean
size?: TSize
radius?: TRadius
overflow?: TOverflow
boxSizing?: TBoxSizing
bgColor?: TColor
bgImage?: TColor
bgImageType?: TBgImageType
shadowColor?: TColor
borderColor?: TColor
zIndex?: TZIndex
opacity?: TOpacity
margin?: TMargin
/** Flex 布局时,如果被压缩,可以设置为 0 ,防止变形压缩 */
flexShrink?: TFlexShrink
borderWidth?: TBorderWidth
borderStyle?: TBorderStyle
}
export const Button = (props: ButtonProps) => {
const {onClick=() => {},loading=false} = props
return (
)
}
export default {
Block,
Box,
SafeArea,
Press,
Flex,
Line,
Text,
TextEllipsis,
Image,
Input,
Textarea,
Button,
}