跳到主要内容

预定义组件

此库附带预定义函数来创建 BoxText 组件,如导言示例中所示。这些函数以函数的形式而不是现成的组件的形式出现,以便您有机会提供主题对象的类型。这样做将使所有映射到主题值的 props 都具有基于主题中可用内容配置的正确类型。

Box

// In Box.tsx
import {createBox} from '@shopify/restyle';
import {Theme} from './theme';

const Box = createBox<Theme>();

export default Box;

Box 组件带有以下 Restyle 函数backgroundColoropacityvisiblelayoutspacingbordershadowposition

Text

// In Text.tsx
import {createText} from '@shopify/restyle';
import {Theme} from './theme';

const Text = createText<Theme>();

export default Text;

Text 组件带有以下 Restyle 函数colortextDecorationColoropacityvisibletypographytextShadowspacinglayout。它还包括一个 变体,该变体会在主题的 textVariants 键下选择样式。

// In your theme
const theme = createTheme({
...,
textVariants: {
header: {
fontFamily: 'ShopifySans-Bold',
fontWeight: 'bold',
fontSize: 34,
lineHeight: 42.5,
color: 'black',
},
subheader: {
fontFamily: 'ShopifySans-SemiBold',
fontWeight: '600',
fontSize: 28,
lineHeight: 36,
color: 'black',
},
body: {
fontFamily: 'ShopifySans',
fontSize: 16,
lineHeight: 24,
color: 'black',
},
},
});

// In a component
<Text variant="header">Header</Text>