packages/components/src/stories/dev_zh.stories.mdx
通用组件需要符合 w3 规范 。满足可访问性中的快捷键要求,其它可访问性要素可以适当满足。
组件统一放在 src/components 文件夹下, 以 Button 为例,在 src/components 下新建名为 button 的目录。
├── button
│ ├── button.tsx # 组件本体
│ ├── index.ts # 导出组件
│ ├── interface.ts # 组件接口
│ ├── readme.stories.mdx # 组件文档
│ ├── button.stories.tsx # 组件 stories
│ └── styled.tsx # styled-component 编写组件样式
组件内部应该处理好主题配置(目前主要是颜色相关的 css 属性),不应该写死颜色。
import styled, { css } from 'styled-components';
import { applyDefaultTheme } from 'styles';
const myComponent = styled.div.attrs(applyDefaultTheme)`
color: ${(props) => props.theme.palette.primary};
`;
这样不管组件是否被 themeProvider 包裹,都能正常展示主题色。