@leancodepl/styled-tools
Version:
Utilities for styled-components
59 lines (41 loc) • 1.11 kB
Markdown
TypeScript utilities for styled-components with type-safe theme access.
```bash
npm install @leancodepl/styled-tools
yarn add @leancodepl/styled-tools
```
Creates type-safe theme utilities for styled-components with full TypeScript support.
**Returns:** Object containing `theme` proxy and `useTheme` hook
```typescript
// theme.ts
import { mkTheme } from '@leancodepl/styled-tools';
import styled from 'styled-components';
interface AppTheme {
colors: { primary: string; secondary: string };
spacing: { small: string; large: string };
}
export const { theme, useTheme } = mkTheme<AppTheme>();
const Button = styled.button`
color: ${theme.colors.primary};
padding: ${theme.spacing.small};
`;
```
```typescript
import React from 'react';
import { useTheme } from './theme';
function ThemedComponent() {
const theme = useTheme();
return (
<div style={{ backgroundColor: theme.colors.primary }}>
<h1>Themed Component</h1>
</div>
);
}
```