Skill站外收录 @skilllib/skill-2117939930272415669
frontend-style-guide
规范前端 React 组件的样式开发与维护,统一使用 Mantine 8 的主题化 API 和 CSS 模块方案,禁用内联 style、sx 及 styles 属性,优先采用主题 token 和组件原生 props 进行轻量定制,复杂样式交由模块化 CSS 处理,并确保暗色模式兼容性与可复用组件的一致性。
软件开发 AI 技能
Skills.MD
# Lightdash Frontend Style Guide
Apply these rules when working on any frontend component in `packages/frontend/`.
## Mantine 8 Migration
**CRITICAL**: We are migrating from Mantine 6 to 8. Always upgrade v6 components when you encounter them.
## Component Checklist
When creating/updating components:
- [ ] Use `@mantine-8/core` imports
- [ ] No `style` or `styles` or `sx` props
- [ ] Check Mantine docs/types for available component props
- [ ] Use inline-style component props for styling when available (and follow <=3 props rule)
- [ ] Use CSS modules when component props aren't available or when more than 3 inline-style props are needed
- [ ] Theme values ('md', 'lg', 'xl', or 'ldGray.1', 'ldGray.2', 'ldDark.1', 'ldDark.2', etc) instead of magic numbers
## Quick Migration Guide
```tsx
// ❌ Mantine 6
import { Button, Group } from '@mantine/core';
<Group spacing="xs" noWrap>
<Button sx={{ mt: 20 }}>Click</Button>
</Group>;
// ✅ Mantine 8
import { Button, Group } from '@mantine-8/core';
<Group gap="xs" wrap="nowrap">
<Button mt={20}>Click</Button>
</Group>;
```
## Key Prop Changes
- `spacing` → `gap`
- `noWrap` → `wrap="nowrap"`
- `sx` → Component props (e.g., `mt`, `w`, `c`) or CSS modules
- `leftIcon` → `leftSection`
- `rightIcon` → `rightSection`
## Styling Best Practices
### Core Principle: Theme First
**The goal is to use theme defaults whenever possible.** Style overrides should be the exception, not the rule.
### Styling Hierarchy
1. **Best**: No custom styles (use theme defaults)
2. **Theme extension**: For repeated patterns, add to `mantine8Theme.ts`
3. **Component props**: Simple overrides (1-3 props like `mt="xl" w={240}`)
4. **CSS modules**: Complex styling or more than 3 props
### NEVER Use
- `styles` prop (always use CSS modules instead)
- `sx` prop (it's a v6 prop)
- `style` prop (inline styles)
### Theme Extensions (For Repeated Patterns)
If you find yourself applying the same style override multiple times, add it to the theme in `mantine8Theme.ts`:
```tsx
// In src/mantine8Theme.ts - inside the components object
components: {
Button: Button.extend({
styles: {
root: {
minWidth: '120px',
fontWeight: 600,
}
}
}),
}
```
### Context-Specific Overrides
#### Inline-style Component Props (1-3 simple props)
```tsx
// ✅ Good
<Button mt="xl" w={240} c="blue.6">Submit</Button>
// ❌ Bad - Too many props, use CSS modules instead
<Button mt={20} mb={20} ml={10} mr={10} w={240} c="blue.6" bg="white">Submit</Button>
```
Common inline-style props:
- Layout: `mt`, `mb`, `ml`, `mr`, `m`, `p`, `pt`, `pb`, `pl`, `pr`
- Sizing: `w`, `h`, `maw`, `mah`, `miw`, `mih`
- Colors: `c` (color), `bg` (background)
- Font: `ff`, `fs`, `fw`
- Text: `ta`, `lh`
#### CSS Modules (complex styles or >3 props)
Create a `.module.css` file in the same folder as the component:
```css
/* Component.module.css */
.customCard {
transition: transform 0.2s ease;
cursor: pointer;
}
.customCard:hover {
transform: translateY(-2px);
box-shadow: var(--mantine-shadow-lg);
}
```
```tsx
import styles from './Component.module.css';
<Card className={styles.customCard}>{/* content */}</Card>;
```
**Do NOT include `.css.d.ts` files** - Vite handles this automatically.
## Color Guidelines
**Prefer default component colors** - Mantine handles theme switching automatically.
When you need custom colors, use our custom scales for dark mode compatibility:
```tsx
// ❌ Bad - Standard Mantine colors (poor dark mode support)
<Text c="gray.6">Secondary text</Text>
// ✅ Good - ldGray for borders and neutral elements
<Text c="ldGray.6">Secondary text</Text>
// ✅ Good - ldDark for elements that appear dark in light mode
<Button bg="ldDark.8" c="ldDark.0">Dark button</Button>
// ✅ Good - Foreground/background variables
<Text c="foreground">Primary text</Text>
<Box bg="background">Main background</Box>
```
### Custom Color Scales
| Token | Purpose |
|-------|---------|
| `ldGray.0-9` | Borders, subtle text, neutral UI elements |
| `ldDark.0-9` | Buttons/badges with dark backgrounds in light mode |
| `background` | Page/card backgrounds |
| `foreground` | Primary text color |
### Dark Mode in CSS Modules
Use `@mixin dark` for theme-specific overrides:
```css
.clickableRow {
&:hover {
background-color: var(--mantine-color-ldGray-0);
@mixin dark {
background-color: var(--mantine-color-ldDark-5);
}
}
}
```
Alternative: use CSS `light-dark()` function for single-line theme switching:
```css
.clickableRow:hover {
background-color: light-dark(var(--mantine-color-ldGray-0), var(--mantine-color-ldDark-5));
}
```
## Always Use Theme Tokens
```tsx
// ❌ Bad - Magic numbers
<Box p={16} mt={24}>
// ✅ Good - Theme tokens
<Box p="md" mt="lg">
```
## Remove Dead Styles
Before moving styles to CSS modules, check if they're actually needed:
```tsx
// ❌ Unnecessary - display: block has no effect on flex children
<Flex justify="flex-end">
<Button style={{display: 'block'}}>Submit</Button>
</Flex>
// ✅ Better - Remove the style entirely
<Flex justify="flex-end">
<Button>Submit</Button>
</Flex>
```
## Theme-Aware Component Logic
For JavaScript logic that needs to know the current theme:
```tsx
import { useMantineColorScheme } from '@mantine/core';
const MyComponent = () => {
const { colorScheme } = useMantineColorScheme();
const iconColor = colorScheme === 'dark' ? 'blue.4' : 'blue.6';
// ...
};
```
## Reusable Components
### Modals
- **Always use `MantineModal`** from `components/common/MantineModal` - never use Mantine's Modal directly
- See `stories/Modal.stories.tsx` for usage examples
- For forms inside modals: use `id` on the form and `form="form-id"` on the submit button
- For alerts inside modals: use `Callout` with variants `danger`, `warning`, `info`
### Callouts
- Use `Callout` from `components/common/Callout`
- Variants: `danger`, `warning`, `info`
## Mantine Documentation
List of all components and links to their documentation in LLM-friendly format: `https://mantine.dev/llms.txt`
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「frontend-style-guide」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次