Skip to content

Commit 561e4a2

Browse files
authored
feat: controls compatibility (#680)
* feat: controls compatibility * more types * fix: range type * fix: web select multiple * fix remove comment * fix: web fast refresh * fix: remove useless test
1 parent 648bf0f commit 561e4a2

File tree

15 files changed

+850
-96
lines changed

15 files changed

+850
-96
lines changed

examples/expo-example/App.test.tsx

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

examples/expo-example/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// fixes fast refresh on web
2+
import '@expo/metro-runtime';
13
import { Text, View } from 'react-native';
24

35
function App() {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Text, ScrollView, Appearance } from 'react-native';
2+
3+
const ComponentExample = (props: any) => {
4+
return (
5+
<ScrollView>
6+
<Text style={{ color: Appearance.getColorScheme() === 'dark' ? 'white' : 'black' }}>
7+
{JSON.stringify(props, null, 2)}
8+
</Text>
9+
</ScrollView>
10+
);
11+
};
12+
13+
export default {
14+
component: ComponentExample,
15+
argTypes: {
16+
boolean: { control: 'boolean' },
17+
color: { control: 'color' },
18+
colorWithPresets: {
19+
control: {
20+
type: 'color',
21+
presetColors: ['#ff0', 'pink', { color: '#00f', title: 'mystery' }],
22+
},
23+
},
24+
colorStartOpen: { control: { type: 'color', startOpen: true } },
25+
date: { control: 'date' },
26+
file: { control: { type: 'file', accept: '.png' }, name: 'Image Urls' },
27+
number: { control: 'number' },
28+
object: { control: 'object' },
29+
radio: { control: { type: 'radio', options: ['a', 'b', 'c'] } },
30+
radioWithLabels: {
31+
control: { type: 'radio', options: ['a', 'b', 'c'], labels: ['alpha', 'beta', 'gamma'] },
32+
},
33+
inlineRadio: { control: { type: 'inline-radio', options: ['a', 'b', 'c'] } },
34+
select: { control: 'select', options: ['a', 'b', 'c', 'double space'] },
35+
multiSelect: { control: { type: 'multi-select' }, options: ['a', 'b', 'c', 'double space'] },
36+
range: { control: 'range' },
37+
rangeCustom: { control: { type: 'range', min: 0, max: 1000, step: 100 } },
38+
text: { control: 'text' },
39+
},
40+
};
41+
42+
export const Undefined = {
43+
args: {},
44+
};
45+
46+
const DEFAULT_NESTED_OBJECT = {
47+
text: 'Hello world',
48+
boolean: true,
49+
array: ['One', 'Two', 'Three'],
50+
object: { a: 1, b: 2, c: 3 },
51+
};
52+
53+
export const Defined = {
54+
args: {
55+
boolean: true,
56+
color: '#ff0',
57+
colorWithPresets: 'pink',
58+
colorStartOpen: 'orange',
59+
date: new Date(2010, 1, 1),
60+
file: ['https://storybook.js.org/images/placeholders/350x150.png'],
61+
number: 10,
62+
object: DEFAULT_NESTED_OBJECT,
63+
radio: 'a',
64+
radioWithLabels: 'b',
65+
inlineRadio: 'c',
66+
select: 'b',
67+
multiSelect: ['a'],
68+
range: 15,
69+
rangeCustom: 10,
70+
text: 'hello',
71+
},
72+
};

packages/ondevice-controls/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"deep-equal": "^1.0.1",
3838
"prop-types": "^15.7.2",
3939
"react-native-modal-datetime-picker": "^14.0.0",
40-
"react-native-modal-selector": "^2.1.1",
4140
"tinycolor2": "^1.4.1"
4241
},
4342
"devDependencies": {

packages/ondevice-controls/src/PropField.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@ import React, { ComponentType } from 'react';
22
import { styled } from '@storybook/react-native-theming';
33
import TypeMap from './types';
44
import { ArgType } from './ControlsPanel';
5-
6-
type ControlTypes =
7-
| 'text'
8-
| 'number'
9-
| 'color'
10-
| 'boolean'
11-
| 'object'
12-
| 'select'
13-
| 'array'
14-
| 'date'
15-
| 'button'
16-
| 'radio';
5+
import { ControlTypes } from './sharedTypes';
176

187
export interface Knob {
198
name: string;

packages/ondevice-controls/src/components/RadioSelect.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const RadioContainer = styled.View(({ isInline }: any) => ({
1111
flexDirection: isInline ? 'row' : 'column',
1212
alignItems: isInline ? 'center' : 'flex-start',
1313
flexWrap: 'wrap',
14-
rowGap: 10,
14+
gap: 10,
1515
}));
1616

1717
const RadioTouchable = styled.TouchableOpacity(() => ({
@@ -20,21 +20,20 @@ const RadioTouchable = styled.TouchableOpacity(() => ({
2020
}));
2121

2222
const RadioCircle = styled.View(({ theme }) => ({
23-
width: 15,
24-
height: 15,
23+
width: 16,
24+
height: 16,
2525
borderWidth: 1,
2626
borderColor: theme.appBorderColor,
27-
borderRadius: 15,
27+
borderRadius: '100%',
2828
backgroundColor: theme.background.content,
2929
alignItems: 'center',
3030
justifyContent: 'center',
31-
padding: 2,
3231
}));
3332

3433
const RadioInnerCircle = styled.View(({ theme, selected }: any) => ({
35-
height: '100%',
36-
width: '100%',
37-
borderRadius: 10,
34+
width: 8,
35+
height: 8,
36+
borderRadius: '100%',
3837
backgroundColor: selected ? theme.color.positive : 'transparent',
3938
}));
4039

0 commit comments

Comments
 (0)