@storybook/react-native-ui 8.5.2-alpha.1 → 8.5.2-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/TreeNode.tsx CHANGED
@@ -4,7 +4,7 @@ import { GroupIcon } from './icon/GroupIcon';
4
4
 
5
5
  import { StoryIcon } from './icon/StoryIcon';
6
6
  import { CollapseIcon } from './icon/CollapseIcon';
7
- import React, { ComponentProps, FC } from 'react';
7
+ import React, { ComponentProps, FC, useMemo } from 'react';
8
8
  import { transparentize } from 'polished';
9
9
 
10
10
  export interface NodeProps {
@@ -95,15 +95,15 @@ export const GroupNode: FC<
95
95
  }) {
96
96
  const theme = useTheme();
97
97
 
98
+ const color = useMemo(() => {
99
+ return theme.base === 'dark' ? theme.color.primary : theme.color.ultraviolet;
100
+ }, [theme.base, theme.color.primary, theme.color.ultraviolet]);
101
+
98
102
  return (
99
103
  <BranchNode isExpandable={isExpandable} {...props}>
100
104
  <Wrapper>
101
105
  {isExpandable && <CollapseIcon isExpanded={isExpanded} />}
102
- <GroupIcon
103
- width="14"
104
- height="14"
105
- color={theme.base === 'dark' ? theme.color.primary : theme.color.ultraviolet}
106
- />
106
+ <GroupIcon width={14} height={14} color={color} />
107
107
  </Wrapper>
108
108
  <BranchNodeText>{children}</BranchNodeText>
109
109
  </BranchNode>
@@ -113,11 +113,16 @@ export const GroupNode: FC<
113
113
  export const ComponentNode: FC<ComponentProps<typeof BranchNode>> = React.memo(
114
114
  function ComponentNode({ children, isExpanded, isExpandable, ...props }) {
115
115
  const theme = useTheme();
116
+
117
+ const color = useMemo(() => {
118
+ return theme.color.secondary;
119
+ }, [theme.color.secondary]);
120
+
116
121
  return (
117
122
  <BranchNode isExpandable={isExpandable} {...props}>
118
123
  <Wrapper>
119
124
  {isExpandable && <CollapseIcon isExpanded={isExpanded} />}
120
- <ComponentIcon width={12} height={12} color={theme.color.secondary} />
125
+ <ComponentIcon width={12} height={12} color={color} />
121
126
  </Wrapper>
122
127
  <BranchNodeText>{children}</BranchNodeText>
123
128
  </BranchNode>
@@ -131,14 +136,14 @@ export const StoryNode: FC<ComponentProps<typeof LeafNode>> = React.memo(functio
131
136
  }) {
132
137
  const theme = useTheme();
133
138
 
139
+ const color = useMemo(() => {
140
+ return props.selected ? theme.color.lightest : theme.color.seafoam;
141
+ }, [props.selected, theme.color.lightest, theme.color.seafoam]);
142
+
134
143
  return (
135
144
  <LeafNode {...props}>
136
145
  <Wrapper>
137
- <StoryIcon
138
- width={14}
139
- height={14}
140
- color={props.selected ? theme.color.lightest : theme.color.seafoam}
141
- />
146
+ <StoryIcon width={14} height={14} color={color} />
142
147
  </Wrapper>
143
148
  <LeafNodeText selected={props.selected}>{children}</LeafNodeText>
144
149
  </LeafNode>
@@ -1,18 +1,16 @@
1
- import * as React from 'react';
1
+ import { useMemo } from 'react';
2
2
  import Svg, { Path, SvgProps } from 'react-native-svg';
3
3
  import { useTheme } from '@storybook/react-native-theming';
4
4
 
5
5
  export function CloseFullscreenIcon({ color, width = 14, height = 14, ...props }: SvgProps) {
6
6
  const theme = useTheme();
7
7
 
8
+ const fillColor = useMemo(() => {
9
+ return color ?? theme.color.defaultText;
10
+ }, [color, theme.color.defaultText]);
11
+
8
12
  return (
9
- <Svg
10
- fill={color ?? theme.color.defaultText}
11
- height={height}
12
- viewBox="0 0 16 16"
13
- width={width}
14
- {...props}
15
- >
13
+ <Svg fill={fillColor} height={height} viewBox="0 0 16 16" width={width} {...props}>
16
14
  <Path d="M5.5 0a.5.5 0 01.5.5v4A1.5 1.5 0 014.5 6h-4a.5.5 0 010-1h4a.5.5 0 00.5-.5v-4a.5.5 0 01.5-.5zm5 0a.5.5 0 01.5.5v4a.5.5 0 00.5.5h4a.5.5 0 010 1h-4A1.5 1.5 0 0110 4.5v-4a.5.5 0 01.5-.5zM0 10.5a.5.5 0 01.5-.5h4A1.5 1.5 0 016 11.5v4a.5.5 0 01-1 0v-4a.5.5 0 00-.5-.5h-4a.5.5 0 01-.5-.5zm10 1a1.5 1.5 0 011.5-1.5h4a.5.5 0 010 1h-4a.5.5 0 00-.5.5v4a.5.5 0 01-1 0v-4z" />
17
15
  </Svg>
18
16
  );
@@ -1,5 +1,6 @@
1
1
  import { Path, Svg, SvgProps } from 'react-native-svg';
2
2
  import { useTheme } from '@storybook/react-native-theming';
3
+ import { useMemo } from 'react';
3
4
 
4
5
  export const CollapseAllIcon = ({
5
6
  color, //= '#2E3438',
@@ -9,11 +10,15 @@ export const CollapseAllIcon = ({
9
10
  }: SvgProps) => {
10
11
  const theme = useTheme();
11
12
 
13
+ const fillColor = useMemo(() => {
14
+ return color ?? theme.color.defaultText;
15
+ }, [color, theme.color.defaultText]);
16
+
12
17
  return (
13
18
  <Svg width={width} height={height} viewBox="0 0 14 14" fill="none" {...props}>
14
19
  <Path
15
20
  d="M3.354.146a.5.5 0 10-.708.708l4 4a.5.5 0 00.708 0l4-4a.5.5 0 00-.708-.708L7 3.793 3.354.146zM6.646 9.146a.5.5 0 01.708 0l4 4a.5.5 0 01-.708.708L7 10.207l-3.646 3.647a.5.5 0 01-.708-.708l4-4z"
16
- fill={color ?? theme.color.defaultText}
21
+ fill={fillColor}
17
22
  />
18
23
  </Svg>
19
24
  );
@@ -1,5 +1,7 @@
1
1
  import { Path, Svg, SvgProps } from 'react-native-svg';
2
2
  import { useTheme } from '@storybook/react-native-theming';
3
+ import { useMemo } from 'react';
4
+
3
5
  export const ExpandAllIcon = ({
4
6
  color, //= '#2E3438',
5
7
  width = 14,
@@ -8,11 +10,15 @@ export const ExpandAllIcon = ({
8
10
  }: SvgProps) => {
9
11
  const theme = useTheme();
10
12
 
13
+ const fillColor = useMemo(() => {
14
+ return color ?? theme.color.defaultText;
15
+ }, [color, theme.color.defaultText]);
16
+
11
17
  return (
12
18
  <Svg width={width} height={height} viewBox="0 0 14 14" fill="none" {...props}>
13
19
  <Path
14
20
  d="M7.354.146l4 4a.5.5 0 01-.708.708L7 1.207 3.354 4.854a.5.5 0 11-.708-.708l4-4a.5.5 0 01.708 0zM11.354 9.146a.5.5 0 010 .708l-4 4a.5.5 0 01-.708 0l-4-4a.5.5 0 11.708-.708L7 12.793l3.646-3.647a.5.5 0 01.708 0z"
15
- fill={color ?? theme.color.defaultText}
21
+ fill={fillColor}
16
22
  />
17
23
  </Svg>
18
24
  );
@@ -1,15 +1,20 @@
1
1
  import * as React from 'react';
2
2
  import Svg, { Path, SvgProps } from 'react-native-svg';
3
3
  import { useTheme } from '@storybook/react-native-theming';
4
+ import { useMemo } from 'react';
4
5
 
5
6
  export function FullscreenIcon({ color, width = 14, height = 14, ...props }: SvgProps) {
6
7
  const theme = useTheme();
7
8
 
9
+ const fillColor = useMemo(() => {
10
+ return color ?? theme.color.defaultText;
11
+ }, [color, theme.color.defaultText]);
12
+
8
13
  return (
9
14
  <Svg width={width} height={height} viewBox="0 0 14 14" fill="none" {...props}>
10
15
  <Path
11
16
  d="M1.5 1h2a.5.5 0 010 1h-.793l3.147 3.146a.5.5 0 11-.708.708L2 2.707V3.5a.5.5 0 01-1 0v-2a.5.5 0 01.5-.5zm8.5.5a.5.5 0 01.5-.5h2a.5.5 0 01.5.5v2a.5.5 0 01-1 0v-.793L8.854 5.854a.5.5 0 11-.708-.708L11.293 2H10.5a.5.5 0 01-.5-.5zm2.5 8.5a.5.5 0 01.5.5v2a.5.5 0 01-.5.5h-2a.5.5 0 010-1h.793L8.146 8.854a.5.5 0 11.708-.708L12 11.293V10.5a.5.5 0 01.5-.5zM2 11.293V10.5a.5.5 0 00-1 0v2a.5.5 0 00.5.5h2a.5.5 0 000-1h-.793l3.147-3.146a.5.5 0 10-.708-.708L2 11.293z"
12
- fill={color ?? theme.color.defaultText}
17
+ fill={fillColor}
13
18
  />
14
19
  </Svg>
15
20
  );
@@ -1,4 +1,4 @@
1
- import type { ReactElement } from 'react';
1
+ import { useMemo, type ReactElement } from 'react';
2
2
  import type { API_HashEntry, API_StatusState, API_StatusValue } from '@storybook/core/types';
3
3
 
4
4
  import { useTheme } from '@storybook/react-native-theming';
@@ -21,12 +21,12 @@ function SmallIcons(props: SvgProps) {
21
21
 
22
22
  function LoadingIcons(props: SvgProps) {
23
23
  const theme = useTheme();
24
- return (
25
- <SmallIcons
26
- color={theme.base === 'light' ? theme.color.mediumdark : theme.color.darker}
27
- {...props}
28
- />
29
- );
24
+
25
+ const color = useMemo(() => {
26
+ return theme.base === 'light' ? theme.color.mediumdark : theme.color.darker;
27
+ }, [theme.base, theme.color.darker, theme.color.mediumdark]);
28
+
29
+ return <SmallIcons color={color} {...props} />;
30
30
  }
31
31
 
32
32
  export const statusPriority: API_StatusValue[] = ['unknown', 'pending', 'success', 'warn', 'error'];
@@ -0,0 +1,28 @@
1
+ import { DependencyList, useMemo } from 'react';
2
+ import { ImageStyle, StyleProp, TextStyle, ViewStyle } from 'react-native';
3
+
4
+ /**
5
+ * A hook to memoize a style. Uses `ViewStyle` per default, but can be used with other styles deriving from `FlexStyle` as well, such as `TextStyle`.
6
+ * @param styleFactory The function that returns a style
7
+ * @param deps The dependencies to trigger memoization re-evaluation
8
+ * @see ["Memoize!!! 💾 - a react (native) performance guide"](https://gist.github.com/mrousavy/0de7486814c655de8a110df5cef74ddc)
9
+ * @example
10
+ *
11
+ * // simple object styles
12
+ * const style1 = useStyle(() => ({ height: someDynamicValue }), [someDynamicValue])
13
+ *
14
+ * // array styles
15
+ * const style2 = useStyle(
16
+ * () => [styles.container, props.style, { height: someDynamicValue }],
17
+ * [props.style, someDynamicValue]
18
+ * );
19
+ */
20
+ export const useStyle = <
21
+ TStyle extends ViewStyle | TextStyle | ImageStyle,
22
+ TOutput extends StyleProp<TStyle>
23
+ >(
24
+ styleFactory: () => TOutput,
25
+ deps?: DependencyList
26
+ ): TOutput =>
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ useMemo(styleFactory, deps);