diff --git a/README.md b/README.md
index 2bcf0df..6020539 100644
--- a/README.md
+++ b/README.md
@@ -81,6 +81,49 @@ const Button = component.button<{}>`
`
```
+## Theme
+
+Example how to use themes.
+
+```typescript
+// Main component inside application (`App.svelte`)
+
+
+
+
+ Some test text
+
+
+// Component with theme usage
+import component from '@teiler/svelte'
+
+const Component = component.div`
+ color: ${({ theme }) => theme.fontColor};
+`
+
+export { Component }
+```
+
+To add typing for Typescript applications you need to add `extend` inside declaration file (`d.ts`)
+```typescript
+import type { CustomTheme } from "./App.svelte";
+
+declare module '@teiler/core' {
+ export interface DefaultTheme extends CustomTheme {}
+}
+```
+
## Sew a Pattern
This tool simplifies the creation of consistent and reusable visual styles for components across various web frameworks. It provides a pattern-based approach, where patterns serve as blueprints for defining the visual style of components.
diff --git a/packages/core/src/constructor.test.ts b/packages/core/src/constructor.test.ts
index b75cd3d..d73dbcd 100644
--- a/packages/core/src/constructor.test.ts
+++ b/packages/core/src/constructor.test.ts
@@ -49,18 +49,18 @@ describe('component', () => {
const styleSheet = createStyleSheet({})
const test = jest.fn(component)
- test(styleSheet, [[['color: red;'], []]], [])
+ test(styleSheet, [[['color: red;'], []]], {})
expect(test).toHaveReturnedWith(['teiler-wq229y'])
})
test('should create style from styles with props', () => {
const styleSheet = createStyleSheet({})
- const test = jest.fn(component)
+ const test = jest.fn(component<{ color: string }>)
- test(styleSheet, [[['color: ', ';'], [({ color }) => color]]], [{ color: 'red' }])
+ test(styleSheet, [[['color: ', ';'], [({ color }) => color]]], { color: 'blue' })
- expect(test).toHaveReturnedWith(['teiler-10upe3l'])
+ expect(test).toHaveReturnedWith(['teiler-1r77qux'])
})
})
@@ -77,7 +77,7 @@ describe('global', () => {
test('should create style from styles with props', () => {
const styleSheet = createStyleSheet({})
- const test = jest.fn(global)
+ const test = jest.fn(global<{ color: string }>)
test(styleSheet, [[['body { color: ', '; }'], [({ color }) => color]]], { color: 'blue' })
diff --git a/packages/core/src/constructor.ts b/packages/core/src/constructor.ts
index 7bfab68..515c83e 100644
--- a/packages/core/src/constructor.ts
+++ b/packages/core/src/constructor.ts
@@ -3,7 +3,13 @@ import type { Sheet } from './sheet'
import { compile, transpile } from './css'
import hash from './hash'
-type Expression = (props: Props) => string | boolean
+type DefaultTheme = {[key: string]: string | boolean}
+
+type Arguments = {
+ theme?: DefaultTheme
+} & Props
+
+type Expression = (props: Arguments) => string | boolean
type StyleDefinition = {
id: string
name: string
@@ -60,7 +66,7 @@ function insert(sheet: Sheet, definitions: StyleDefinition[]): string[] {
}, [])
}
-function component(sheet: Sheet, styles: Array