Skip to content

Commit 4ea8989

Browse files
jonathanjJonathan Jacobsdannyhw
authored
feat: Improve styling in the addons panel (storybookjs#437)
* fix: Panels should not obey the story's safe area param The panels are part of the Storybook UI, not the story content, they should always take safe area into account so that their UI isn't accidentally rendered in the margins of the device's screen. * fix: KeyboardAvoidingView intrudes on the app content KeyboardAvoidingView renders too much padding when the keyboard is open, which ends up pushing the padding of the view up beyond the keyboard. This is because the bottom inset (safe area inset + nav bar) is not taken into account. * refactor: Extend the theme considerably This deprecates all of the previous theme values and re-organises the theme in a way that the majority of the Storybook UI can be themed this way. * chore: Style each of the panel containers the same way * refactor: Extract tab bar components into a more general file This also renames the components something more intentional than `Button`. * chore: Apply theme values to the addons panel * refactor: Wrap emotion's `useTheme` hook This makes it convenient to return the correct type for the theme. * chore: Apply theme values to the story list panel * chore: Apply theme values to the visibility button * chore: Apply theme values to ondevice-controls addon * chore: Apply theme values to ondevice-knobs addon * chore: Apply theme values to ondevice-backgrounds addon * chore: Apply theme values to ondevice-notes addon * chore: Usability improvements for ondevice-actions - Allow tapping anywhere on a collapsed section to expand it - More compact representation for values * chore: Deep merge a partial theme from Storybook parameters This means users can override only the parts of the theme they're interested in, from `getStorybookUI`. * docs: Update MIGRATION to include theme migration advice * fix: re-add auto args * chore: Remove unused knobs/controls code * fix(ondevice-backgrounds): Fix swatch styling on web * fix(ondevice-controls): Fix control styling on web * fix(ondevice-knobs,ondevice-controls): Fix radio styling on web * chore: Remove commented theme properties * fix: web horizontal scroll --------- Co-authored-by: Jonathan Jacobs <[email protected]> Co-authored-by: Daniel Williams <[email protected]>
1 parent 6f6e530 commit 4ea8989

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1549
-826
lines changed

MIGRATION.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Migration
22

33
- [Migration](#migration)
4+
- [From version 5.3.x to 6.5.x](#from-version-53x-to-65x)
5+
- [Theming](#theming)
46
- [From version 5.2.x to 5.3.x](#from-version-52x-to-53x)
57
- [To main.js configuration](#to-mainjs-configuration)
68
- [Create React App preset](#create-react-app-preset)
@@ -76,6 +78,36 @@
7678
- [Packages renaming](#packages-renaming)
7779
- [Deprecated embedded addons](#deprecated-embedded-addons)
7880

81+
## From version 5.3.x to 6.5.x
82+
83+
### Theming
84+
85+
The theme structure in Storybook 6.5 provides much more granular control over
86+
more of the Storybook UI, including addons, this unfortunately makes it
87+
difficult to provide backwards compatibility. If you were previously using a
88+
custom theme you will now need to migrate it to the new theme.
89+
90+
The themeable values are comprehensively listed in the `Theme` type in
91+
[theme.ts](https://github.com/storybookjs/react-native/blob/next-6.0/app/react-native/src/preview/components/Shared/theme.ts).
92+
93+
Below the old theme keys are listed against a comparable key in the new theme,
94+
although bear in mind that there are many more aspects of the UI that can be
95+
themed now, this is just to help get you started:
96+
97+
- `backgroundColor`: `backgroundColor`
98+
- `storyListBackgroundColor`: `panel.backgroundColor`
99+
- `listItemTextColor`: `storyList.storyTextColor`
100+
- `listItemActiveColor`: `storyList.storySelectedBackgroundColor`
101+
- `listItemActiveTextColor`: `storyList.storySelectedTextColor`
102+
- `headerTextColor`: `storyList.headerTextColor`
103+
- `labelColor`: `inputs.labelTextColor`
104+
- `borderColor`: `panel.borderColor`, `navigation.borderColor`, `inputs.text.borderColor`, `inputs.radio.borderColor`, `inputs.swatch.borderColor`
105+
- `previewBorderColor`: The preview no longer has a border and uses an elevation shadow instead
106+
- `buttonTextColor`: `tabs.inactiveTextColor`, `button.primary.textColor`, `button.secondary.textColor`
107+
- `buttonActiveTextColor`: `tabs.activeTextColor`
108+
- `secondaryLabelColor`: `inputs.slider.valueTextColor`
109+
110+
79111
## From version 5.2.x to 5.3.x
80112

81113
### To main.js configuration

addons/ondevice-actions/src/components/ActionLogger/Inspect.tsx

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React, { useState } from 'react';
2-
import { Button, View, Text, StyleSheet } from 'react-native';
2+
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
33

44
const theme = {
5-
OBJECT_PREVIEW_ARRAY_MAX_PROPERTIES: 10,
6-
OBJECT_PREVIEW_OBJECT_MAX_PROPERTIES: 5,
75
OBJECT_NAME_COLOR: 'rgb(136, 19, 145)',
86
OBJECT_VALUE_NULL_COLOR: 'rgb(128, 128, 128)',
97
OBJECT_VALUE_UNDEFINED_COLOR: 'rgb(128, 128, 128)',
@@ -14,10 +12,7 @@ const theme = {
1412
OBJECT_VALUE_BOOLEAN_COLOR: 'rgb(28, 0, 207)',
1513
OBJECT_VALUE_FUNCTION_PREFIX_COLOR: 'rgb(13, 34, 170)',
1614

17-
ARROW_COLOR: '#6e6e6e',
18-
ARROW_MARGIN_RIGHT: 3,
19-
ARROW_FONT_SIZE: 12,
20-
ARROW_ANIMATION_DURATION: '0',
15+
ARROW_COLOR: '#859499',
2116
};
2217

2318
interface InspectProps {
@@ -27,20 +22,20 @@ interface InspectProps {
2722

2823
const Inspect = ({ name, value }: InspectProps) => {
2924
const [expanded, setExpanded] = useState(false);
25+
const canExpand =
26+
name &&
27+
((Array.isArray(value) && value.length) ||
28+
(value && typeof value === 'object' && Object.keys(value).length));
29+
const toggleExpanded = React.useCallback(() => {
30+
if (canExpand) {
31+
setExpanded((currentValue) => !currentValue);
32+
}
33+
}, [canExpand]);
34+
3035
const toggle = (
31-
<View style={styles.container}>
32-
{name &&
33-
((Array.isArray(value) && value.length) ||
34-
(value &&
35-
typeof value === 'object' &&
36-
!Array.isArray(value) &&
37-
Object.keys(value).length)) ? (
38-
<Button
39-
onPress={() => setExpanded((wasExpanded) => !wasExpanded)}
40-
title={!expanded ? '▶' : '▼'}
41-
/>
42-
) : null}
43-
</View>
36+
<Text style={{ color: canExpand ? theme.ARROW_COLOR : 'transparent', paddingRight: 8 }}>
37+
{expanded ? '▼' : '▶'}
38+
</Text>
4439
);
4540

4641
const nameComponent = name ? (
@@ -51,11 +46,11 @@ const Inspect = ({ name, value }: InspectProps) => {
5146
if (name) {
5247
return (
5348
<>
54-
<View style={styles.row}>
49+
<TouchableOpacity onPress={toggleExpanded} style={styles.row}>
5550
{toggle}
5651
{nameComponent}
5752
<Text>{`: ${value.length === 0 ? '[]' : expanded ? '[' : '[...]'}`}</Text>
58-
</View>
53+
</TouchableOpacity>
5954
{expanded ? (
6055
<View style={styles.expanded}>
6156
{value.map((v, i) => (
@@ -72,26 +67,26 @@ const Inspect = ({ name, value }: InspectProps) => {
7267
);
7368
}
7469
return (
75-
<View>
70+
<>
7671
<Text>[</Text>
7772
{value.map((v, i) => (
7873
<View key={i} style={styles.spacingLeft}>
7974
<Inspect value={v} />
8075
</View>
8176
))}
8277
<Text>]</Text>
83-
</View>
78+
</>
8479
);
8580
}
8681
if (value && typeof value === 'object' && !(value instanceof RegExp)) {
8782
if (name) {
8883
return (
8984
<>
90-
<View style={styles.row}>
85+
<TouchableOpacity style={styles.row} onPress={toggleExpanded}>
9186
{toggle}
9287
{nameComponent}
9388
<Text>{`: ${Object.keys(value).length === 0 ? '{}' : expanded ? '{' : '{...}'}`}</Text>
94-
</View>
89+
</TouchableOpacity>
9590
{expanded ? (
9691
<View style={styles.expanded}>
9792
{Object.entries(value).map(([key, v]) => (
@@ -108,15 +103,15 @@ const Inspect = ({ name, value }: InspectProps) => {
108103
);
109104
}
110105
return (
111-
<View>
106+
<>
112107
<Text>{'{'}</Text>
113108
{Object.entries(value).map(([key, v]) => (
114109
<View key={key}>
115110
<Inspect name={key} value={v} />
116111
</View>
117112
))}
118113
<Text>{'}'}</Text>
119-
</View>
114+
</>
120115
);
121116
}
122117
if (name) {
@@ -129,11 +124,7 @@ const Inspect = ({ name, value }: InspectProps) => {
129124
</View>
130125
);
131126
}
132-
return (
133-
<View>
134-
<Value value={value} />
135-
</View>
136-
);
127+
return <Value value={value} />;
137128
};
138129

139130
function Value({ value }: { value: any }) {
@@ -174,7 +165,6 @@ export default Inspect;
174165

175166
const styles = StyleSheet.create({
176167
spacingLeft: { marginLeft: 20 },
177-
expanded: { marginLeft: 40 },
178-
row: { flexDirection: 'row', alignItems: 'center' },
179-
container: { width: 40, height: 40 },
168+
expanded: { marginLeft: 20 },
169+
row: { paddingBottom: 8, flexDirection: 'row', alignItems: 'center' },
180170
});

addons/ondevice-backgrounds/src/Swatch.tsx

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,54 @@
1+
// @ts-ignore
2+
import styled from '@emotion/native';
13
import PropTypes from 'prop-types';
24
import React from 'react';
3-
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
45

56
interface SwatchProps {
67
name: string;
78
value: string;
89
setBackground: (background: string) => void;
910
}
1011

12+
const PressableSwatch = styled.TouchableOpacity(({ theme }: any) => ({
13+
marginBottom: theme.tokens.spacing3,
14+
borderWidth: theme.inputs.swatch.borderWidth,
15+
borderColor: theme.inputs.swatch.borderColor,
16+
borderRadius: theme.inputs.swatch.outerBorderRadius,
17+
backgroundColor: theme.inputs.swatch.backgroundColor,
18+
paddingVertical: theme.inputs.swatch.paddingVertical,
19+
paddingHorizontal: theme.inputs.swatch.paddingHorizontal,
20+
}));
21+
22+
const ColorSwatch = styled.View(({ theme, color }: any) => ({
23+
height: theme.inputs.swatch.height,
24+
width: '100%',
25+
borderRadius: theme.inputs.swatch.innerBorderRadius,
26+
backgroundColor: color,
27+
}));
28+
29+
const ValueContainer = styled.View(({ theme }: any) => ({
30+
flex: 1,
31+
flexDirection: 'row',
32+
justifyContent: 'space-between',
33+
padding: theme.tokens.spacing1,
34+
paddingBottom: 0,
35+
}));
36+
const NameText = styled.Text(({ theme }: any) => ({
37+
fontSize: theme.inputs.swatch.fontSize,
38+
fontWeight: theme.inputs.swatch.nameTextWeight,
39+
}));
40+
const ValueText = styled.Text(({ theme }: any) => ({
41+
fontSize: theme.inputs.swatch.fontSize,
42+
}));
43+
1144
const Swatch = ({ name, value, setBackground }: SwatchProps) => (
12-
<TouchableOpacity style={styles.container} onPress={() => setBackground(value)}>
13-
<View style={[styles.color, { backgroundColor: value }]} />
14-
<View style={styles.valueContainer}>
15-
<Text>{name}:</Text>
16-
<Text>{value}</Text>
17-
</View>
18-
</TouchableOpacity>
45+
<PressableSwatch onPress={() => setBackground(value)}>
46+
<ColorSwatch color={value} />
47+
<ValueContainer>
48+
<NameText>{name}</NameText>
49+
<ValueText>{value}</ValueText>
50+
</ValueContainer>
51+
</PressableSwatch>
1952
);
2053

2154
Swatch.propTypes = {
@@ -25,20 +58,3 @@ Swatch.propTypes = {
2558
};
2659

2760
export default Swatch;
28-
29-
const styles = StyleSheet.create({
30-
valueContainer: {
31-
padding: 4,
32-
flexDirection: 'row',
33-
justifyContent: 'space-between',
34-
},
35-
color: { flex: 1, height: 40 },
36-
container: {
37-
borderRadius: 4,
38-
borderWidth: 1,
39-
borderColor: 'rgba(0,0,0,0.2)',
40-
marginTop: 10,
41-
marginBottom: 20,
42-
marginHorizontal: 10,
43-
},
44-
});

addons/ondevice-controls/src/ControlsPanel.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ import { useArgs } from './hooks';
77
import NoControlsWarning from './NoControlsWarning';
88
import PropForm from './PropForm';
99

10-
const Touchable = styled.TouchableOpacity(({ theme }) => ({
11-
borderRadius: 2,
12-
borderWidth: 1,
13-
borderColor: theme.borderColor || '#e6e6e6',
14-
padding: 4,
15-
margin: 10,
10+
const ButtonTouchable = styled.TouchableOpacity(({ theme }) => ({
11+
backgroundColor: theme.button.secondary.backgroundColor,
12+
borderRadius: theme.button.secondary.borderRadius,
13+
borderWidth: theme.button.secondary.borderWidth,
14+
borderColor: theme.button.secondary.borderColor,
15+
paddingVertical: theme.button.paddingVertical,
16+
paddingHorizontal: theme.button.paddingHorizontal,
1617
justifyContent: 'center',
1718
alignItems: 'center',
1819
}));
1920

20-
const ResetButton = styled.Text(({ theme }) => ({
21-
color: theme.buttonTextColor || '#999999',
21+
const ButtonText = styled.Text(({ theme }) => ({
22+
color: theme.button.secondary.textColor,
23+
fontSize: theme.button.fontSize,
24+
fontWeight: theme.button.fontWeight,
2225
}));
2326

2427
export declare type SortType = 'alpha' | 'requiredFirst' | 'none';
@@ -86,9 +89,9 @@ const ControlsPanel = ({ api }: { api: API }) => {
8689
return (
8790
<>
8891
<PropForm args={argsObject} isPristine={isPristine} onFieldChange={updateArgsOnFieldChange} />
89-
<Touchable onPress={handleReset}>
90-
<ResetButton>RESET</ResetButton>
91-
</Touchable>
92+
<ButtonTouchable onPress={handleReset}>
93+
<ButtonText>RESET</ButtonText>
94+
</ButtonTouchable>
9295
</>
9396
);
9497
};

addons/ondevice-controls/src/GroupTabs.tsx

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)