diff --git a/.storybook/StorybookShell.tsx b/.storybook/StorybookShell.tsx
new file mode 100644
index 00000000..860bfff2
--- /dev/null
+++ b/.storybook/StorybookShell.tsx
@@ -0,0 +1,29 @@
+import type { ReactNode } from 'react'
+import { Appearance, View } from 'react-native'
+import { StyleSheet } from 'react-native-unistyles'
+
+import { ThemeContextProvider, ThemeVariant } from '../src/theme'
+
+import { StorybookToolbar } from './StorybookToolbar'
+
+const initialTheme =
+ Appearance.getColorScheme() === 'dark'
+ ? ThemeVariant.Dark
+ : ThemeVariant.Light
+
+export const StorybookShell = ({ children }: { children: ReactNode }) => (
+
+
+
+ {children}
+
+
+)
+
+const styles = StyleSheet.create(({ semantic }, rt) => ({
+ container: {
+ flex: 1,
+ paddingTop: rt.insets.top,
+ backgroundColor: semantic.colorScheme.color.bg.surface.default.default,
+ },
+}))
diff --git a/.storybook/StorybookToolbar.tsx b/.storybook/StorybookToolbar.tsx
new file mode 100644
index 00000000..0b9318e9
--- /dev/null
+++ b/.storybook/StorybookToolbar.tsx
@@ -0,0 +1,68 @@
+import { IconMoon, IconSun } from '@tabler/icons-react-native'
+import { Appearance, Pressable, Text, View } from 'react-native'
+import {
+ StyleSheet,
+ UnistylesRuntime,
+ useUnistyles,
+} from 'react-native-unistyles'
+
+const THEME_TOGGLE_LABELS = {
+ light: 'Включить тёмную тему',
+ dark: 'Включить светлую тему',
+}
+
+export const StorybookToolbar = () => {
+ const { theme, rt } = useUnistyles()
+ const isDark = rt.themeName === 'dark'
+ const ThemeIcon = isDark ? IconSun : IconMoon
+
+ const toggleTheme = () => {
+ const nextTheme = isDark ? 'light' : 'dark'
+ Appearance.setColorScheme(nextTheme)
+ UnistylesRuntime.setTheme(nextTheme)
+ }
+
+ return (
+
+ Storybook
+
+
+
+
+ )
+}
+
+const styles = StyleSheet.create(({ semantic }) => ({
+ toolbar: {
+ flexDirection: 'row',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ paddingHorizontal: 16,
+ borderBottomWidth: StyleSheet.hairlineWidth,
+ borderBottomColor: semantic.colorScheme.color.border.neutral.default,
+ },
+ title: {
+ flexShrink: 1,
+ fontSize: 16,
+ fontWeight: '600',
+ color: semantic.colorScheme.color.fg.default,
+ },
+ themeButton: {
+ minWidth: 44,
+ minHeight: 44,
+ alignItems: 'center',
+ justifyContent: 'center',
+ paddingHorizontal: 12,
+ paddingVertical: 8,
+ },
+}))
diff --git a/.storybook/index.tsx b/.storybook/index.tsx
index 65accd9d..e7b5489a 100644
--- a/.storybook/index.tsx
+++ b/.storybook/index.tsx
@@ -2,6 +2,7 @@ import '../src/theme/ThemeContext'
import { createAsyncStorage } from '@react-native-async-storage/async-storage'
+import { StorybookShell } from './StorybookShell'
import { StorybookStatusUI } from './StorybookStatusUI'
import { view } from './storybook.requires'
@@ -28,4 +29,10 @@ const StorybookUIRoot = view.getStorybookUI({
},
})
-export default StorybookUIRoot
+const Storybook = () => (
+
+
+
+)
+
+export default Storybook
diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx
index 5443cfe4..3b6433d3 100644
--- a/.storybook/preview.tsx
+++ b/.storybook/preview.tsx
@@ -1,34 +1,14 @@
import type { Preview } from '@storybook/react'
-import { useArgs } from '@storybook/preview-api'
-import { StyleSheet, UnistylesRuntime } from 'react-native-unistyles'
-import { ThemeContextProvider, ThemeVariant } from '../src/theme'
-import { View, Appearance } from 'react-native'
-import React, {
- useEffect,
- useLayoutEffect,
- useRef,
- type FunctionComponent,
- type ReactNode,
-} from 'react'
-
-let currentTheme =
- Appearance.getColorScheme() === 'dark'
- ? ThemeVariant.Dark
- : ThemeVariant.Light
+import { StyleSheet } from 'react-native-unistyles'
+import { View } from 'react-native'
const preview: Preview = {
decorators: [
- (Story, context) => {
- const [args, updateArgs] = useArgs()
-
- return (
-
-
-
-
-
- )
- },
+ (Story) => (
+
+
+
+ ),
],
parameters: {
options: {
@@ -41,60 +21,17 @@ const preview: Preview = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: { matchers: { color: /(background|color)$/i, date: /Date$/ } },
},
- argTypes: {
- theme: {
- options: [ThemeVariant.Light, ThemeVariant.Dark],
- control: { type: 'radio' },
- },
- },
- args: { theme: currentTheme },
}
export default preview
-interface StorybookThemeArgs {
- theme: ThemeVariant
-}
-
-const THEME_NAME_MAP: Record = {
- [ThemeVariant.Light]: 'light',
- [ThemeVariant.Dark]: 'dark',
-}
-
-const Container: FunctionComponent<{
- children: ReactNode
- theme: ThemeVariant
- updateArgs: (args: StorybookThemeArgs) => void
-}> = ({ children, theme, updateArgs }) => {
- const themeSynchronized = useRef(false)
-
- useEffect(() => {
- if (!themeSynchronized.current) {
- themeSynchronized.current = true
- updateArgs({ theme: currentTheme })
- }
- }, [updateArgs])
-
- useLayoutEffect(() => {
- if (themeSynchronized.current) {
- const nextTheme = THEME_NAME_MAP[theme]
- Appearance.setColorScheme(nextTheme)
- UnistylesRuntime.setTheme(nextTheme)
- currentTheme = theme
- }
- }, [theme])
-
- return (
-
- {children}
-
- )
-}
-
-const styles = StyleSheet.create(({ theme }) => ({
+const styles = StyleSheet.create(({ semantic }, rt) => ({
container: {
- width: '100%',
- height: '100%',
- backgroundColor: theme.Surface['surface-card'],
+ flex: 1,
+ padding: 16,
+ backgroundColor:
+ rt.themeName === 'dark'
+ ? semantic.colorScheme.color.bg.surface.canvas.default
+ : semantic.colorScheme.color.bg.surface.default.default,
},
}))
diff --git a/src/components/Checkbox/stories/Checkbox.stories.tsx b/src/components/Checkbox/stories/Checkbox.stories.tsx
index a86a98e5..f09c74d2 100644
--- a/src/components/Checkbox/stories/Checkbox.stories.tsx
+++ b/src/components/Checkbox/stories/Checkbox.stories.tsx
@@ -28,7 +28,6 @@ const meta: Meta = {
parameters: {
controls: {
include: [
- 'theme',
'checked',
'indeterminate',
'disabled',
diff --git a/src/components/Checkbox/stories/CheckboxOverview.stories.tsx b/src/components/Checkbox/stories/CheckboxOverview.stories.tsx
index 7df73726..ab75945f 100644
--- a/src/components/Checkbox/stories/CheckboxOverview.stories.tsx
+++ b/src/components/Checkbox/stories/CheckboxOverview.stories.tsx
@@ -15,7 +15,7 @@ const meta: Meta = {
onCheckedChange: { action: 'onCheckedChange' },
onPress: { action: 'onPress' },
},
- parameters: { controls: { include: ['theme'] } },
+ parameters: { controls: { include: [] } },
render: ({ onCheckedChange, onPress }) => (
= {
},
parameters: {
controls: {
- include: ['theme', 'checked', 'disabled', 'danger', 'label', 'caption'],
+ include: ['checked', 'disabled', 'danger', 'label', 'caption'],
},
},
render: ({ label, caption, ...args }) => {
diff --git a/src/components/RadioButton/stories/RadioButtonOverview.stories.tsx b/src/components/RadioButton/stories/RadioButtonOverview.stories.tsx
index 2800b65c..a97b6271 100644
--- a/src/components/RadioButton/stories/RadioButtonOverview.stories.tsx
+++ b/src/components/RadioButton/stories/RadioButtonOverview.stories.tsx
@@ -12,7 +12,7 @@ const meta: Meta = {
tags: ['version:2.0'],
component: RadioButton,
argTypes: { onPress: { action: 'onPress' } },
- parameters: { controls: { include: ['theme'] } },
+ parameters: { controls: { include: [] } },
render: ({ onPress }) => (
diff --git a/src/components/SelectButton/SelectButton.stories.tsx b/src/components/SelectButton/SelectButton.stories.tsx
index e33f129b..e03aa52f 100644
--- a/src/components/SelectButton/SelectButton.stories.tsx
+++ b/src/components/SelectButton/SelectButton.stories.tsx
@@ -48,7 +48,7 @@ const meta: Meta = {
disabled: { control: 'boolean' },
onPress: { action: 'onPress' },
},
- parameters: { controls: { include: ['theme', 'size', 'disabled'] } },
+ parameters: { controls: { include: ['size', 'disabled'] } },
}
export default meta
@@ -64,9 +64,7 @@ export const Controlled: Story = {
control: { type: 'range', min: 0, max: buttons.length - 1, step: 1 },
},
},
- parameters: {
- controls: { include: ['theme', 'size', 'disabled', 'selectedIndex'] },
- },
+ parameters: { controls: { include: ['size', 'disabled', 'selectedIndex'] } },
render: ({
buttons,
disabled,
diff --git a/src/components/ToggleSwitch/ToggleSwitch.stories.tsx b/src/components/ToggleSwitch/ToggleSwitch.stories.tsx
index e3092802..bb933fe9 100644
--- a/src/components/ToggleSwitch/ToggleSwitch.stories.tsx
+++ b/src/components/ToggleSwitch/ToggleSwitch.stories.tsx
@@ -25,7 +25,7 @@ const meta: Meta = {
},
parameters: {
controls: {
- include: ['theme', 'checked', 'disabled', 'danger', 'label', 'caption'],
+ include: ['checked', 'disabled', 'danger', 'label', 'caption'],
},
},
render: ({ label, caption, ...args }) => {
diff --git a/tsconfig.json b/tsconfig.json
index 294257ba..6929e4e9 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -23,6 +23,7 @@
"jsx": "react-native",
"resolveJsonModule": true
},
+ "include": ["**/*", ".storybook/**/*"],
"exclude": [
"artifacts",
"scripts",