Skip to content

Commit

Permalink
Isolate @storybook/addon-docs imports
Browse files Browse the repository at this point in the history
  • Loading branch information
narin committed Nov 9, 2023
1 parent 51b03a2 commit 1feef56
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'react-native'
import React from 'react'

import { webStorybookColorScheme } from '../../utils/storybook'
import { webStorybookColorScheme } from '../../utils'

export enum ButtonVariants {
Base,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import styled from 'styled-components/native'

import { ComponentWrapper } from '../../wrapper'
import { PressableOpacityStyle } from '../../utils'
import { webStorybookColorScheme } from '../../utils/storybook'
import { webStorybookColorScheme } from '../../utils'

/**
* Props for {@link SegmentedControl}
Expand Down
19 changes: 18 additions & 1 deletion packages/components/src/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import { PressableStateCallbackType, StyleProp, ViewStyle } from 'react-native'
import {
ColorSchemeName,
PressableStateCallbackType,
StyleProp,
ViewStyle,
} from 'react-native'

/** Function for web Storybook to override setting colorScheme based on UI toggle button */
export function webStorybookColorScheme(): ColorSchemeName {
// If not web Storybook, set with RN useColorScheme hook
if (!process.env.STORYBOOK_WEB) {
return null
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
const storybookDarkMode = require('storybook-dark-mode')
return storybookDarkMode.useDarkMode() ? 'dark' : 'light'
}

/**
* Convenience function for handling TouchableOpacity styling on Pressable component
Expand Down
14 changes: 1 addition & 13 deletions packages/components/src/utils/storybook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Subtitle,
Title,
} from '@storybook/addon-docs'
import { ColorSchemeName, Linking, Text, View } from 'react-native'
import { Linking, Text, View } from 'react-native'

type DocProps = {
name: string
Expand Down Expand Up @@ -51,15 +51,3 @@ export const generateDocs = ({ name, docUrl }: DocProps) => ({
</>
),
})

/** Function for web Storybook to override setting colorScheme based on UI toggle button */
export function webStorybookColorScheme(): ColorSchemeName {
// If not web Storybook, set with RN useColorScheme hook
if (!process.env.STORYBOOK_WEB) {
return null
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
const storybookDarkMode = require('storybook-dark-mode')
return storybookDarkMode.useDarkMode() ? 'dark' : 'light'
}

0 comments on commit 1feef56

Please sign in to comment.