-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmeta.tsx
86 lines (72 loc) · 2.51 KB
/
meta.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, { createContext } from 'react'
import type { TBackground } from '@primitives/background'
import type { TComponentConfig } from 'autoprops'
import type { TComponentControls } from '@revert/sandbox'
import { Background } from '@primitives/background'
import { Block } from '@primitives/block'
import { SYMBOL_CONTROL_SWITCH } from '@revert/sandbox'
import type { TThemeables } from '@themeables/core'
import type { TThemeableBackgrounds, TThemeableBackground } from './src'
import { setupBackgroundTheme } from './src'
type TDemo = { status: 'default' | 'error' }
type Mappings = {
demo: TDemo,
}
const defaultTheme: TThemeableBackgrounds<Mappings> = {
demo: ({ status }) => ({
color: status === 'default' ? [0xF0, 0xF0, 0xF0, 1] : [0xFF, 0x99, 0x99, 1],
bottomLeftRadius: 10,
bottomRightRadius: 10,
topLeftRadius: 10,
topRightRadius: 10,
}),
}
const OverrideContext: React.Context<TThemeables<TThemeableBackground, Mappings>> = createContext({})
const { BackgroundTheme, createThemeableBackground } = setupBackgroundTheme(OverrideContext)
export const DemoThemeableBackground = createThemeableBackground<TBackground, Mappings>('demo', Background)
const newTheme: TThemeableBackgrounds<Mappings> = {
demo: ({ status }) => ({
color: status === 'default' ? [0x00, 0x00, 0x00, 1] : [0xFF, 0x00, 0x00, 1],
bottomLeftRadius: 10,
bottomRightRadius: 10,
topLeftRadius: 10,
topRightRadius: 10,
}),
}
type TDemoComponent = {
hasTheme: boolean,
withOverride: boolean,
} & TDemo
const overrideTheme: TThemeables<TThemeableBackground, Mappings> = {
demo: ({ status }) => ({
color: status === 'error' ? [144, 24, 56, 1] : [108, 105, 86, 1],
}),
}
export const Component = ({ status, hasTheme, withOverride }: TDemoComponent) => (
<OverrideContext.Provider value={withOverride ? overrideTheme : {}}>
<Block
style={{
width: 100,
height: 100,
}}
>
<BackgroundTheme.Provider value={hasTheme ? newTheme : defaultTheme}>
<DemoThemeableBackground status={status}/>
</BackgroundTheme.Provider>
</Block>
</OverrideContext.Provider>
)
Component.displayName = 'ThemeableBackground'
export const config: TComponentConfig<TDemoComponent> = {
props: {
hasTheme: [true],
withOverride: [true],
status: ['default', 'error'],
},
}
// @ts-ignore
export { default as readme } from './readme.md'
export const controls: TComponentControls<TDemoComponent> = {
hasTheme: SYMBOL_CONTROL_SWITCH,
withOverride: SYMBOL_CONTROL_SWITCH,
}