Skip to content

Commit 6785992

Browse files
committed
docs: improve examples
1 parent 0da3776 commit 6785992

12 files changed

+97
-53
lines changed

docs/assets/snack.js

+33-35
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,45 @@ function appendSnackLink() {
1010
if (usage) {
1111
var pre = usage.nextElementSibling;
1212

13-
while (
14-
pre.firstChild.tagName !== 'CODE' ||
15-
pre.firstChild.className !== 'language-js'
13+
if (
14+
pre &&
15+
pre.firstChild.tagName === 'CODE' &&
16+
pre.firstChild.className === 'language-js'
1617
) {
17-
pre = pre.nextElementSibling;
18-
}
19-
20-
if (!pre) {
21-
return;
22-
}
18+
var link;
19+
var insert = true;
2320

24-
var link;
25-
var insert = true;
21+
if (pre.nextElementSibling && pre.nextElementSibling.dataset.snack) {
22+
link = pre.nextElementSibling;
23+
insert = false;
24+
} else {
25+
link = document.createElement('a');
26+
link.dataset.snack = true;
27+
link.target = '_blank';
28+
link.innerHTML =
29+
'Try this example on Snack <svg width="14px" height="14px" viewBox="0 0 16 16" style="vertical-align: -1px"><g stroke="none" stroke-width="1" fill="none"><polyline stroke="currentColor" points="8.5 0.5 15.5 0.5 15.5 7.5"></polyline><path d="M8,8 L15.0710678,0.928932188" stroke="currentColor"></path><polyline stroke="currentColor" points="9.06944444 3.5 1.5 3.5 1.5 14.5 12.5 14.5 12.5 6.93055556"></polyline></g></svg>';
30+
}
2631

27-
if (pre.nextElementSibling && pre.nextElementSibling.dataset.snack) {
28-
link = pre.nextElementSibling;
29-
insert = false;
30-
} else {
31-
link = document.createElement('a');
32-
link.dataset.snack = true;
33-
link.target = '_blank';
34-
link.innerHTML =
35-
'Try this example on Snack <svg width="14px" height="14px" viewBox="0 0 16 16" style="vertical-align: -1px"><g stroke="none" stroke-width="1" fill="none"><polyline stroke="currentColor" points="8.5 0.5 15.5 0.5 15.5 7.5"></polyline><path d="M8,8 L15.0710678,0.928932188" stroke="currentColor"></path><polyline stroke="currentColor" points="9.06944444 3.5 1.5 3.5 1.5 14.5 12.5 14.5 12.5 6.93055556"></polyline></g></svg>';
36-
}
37-
38-
var href =
39-
'https://snack.expo.io?name=' +
40-
encodeURIComponent(document.title + ' Example') +
41-
'&description=' +
42-
encodeURIComponent(window.location.href) +
43-
'&code=' +
44-
encodeURIComponent(pre.textContent);
32+
var heading = document.querySelector('h1');
33+
var href =
34+
'https://snack.expo.io?name=' +
35+
encodeURIComponent(
36+
heading ? heading.textContent : document.title + ' Example'
37+
) +
38+
'&description=' +
39+
encodeURIComponent(window.location.href) +
40+
'&code=' +
41+
encodeURIComponent(pre.textContent);
4542

46-
if (link.href === href) {
47-
return;
48-
}
43+
if (link.href === href) {
44+
return;
45+
}
4946

50-
link.href = href;
47+
link.href = href;
5148

52-
if (insert) {
53-
pre.insertAdjacentElement('afterend', link);
49+
if (insert) {
50+
pre.insertAdjacentElement('afterend', link);
51+
}
5452
}
5553
}
5654
}

example/src/BottomNavigationExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class ButtomNavigationExample extends React.Component<
3434
{},
3535
State
3636
> {
37-
static title = 'Bottom navigation';
37+
static title = 'Bottom Navigation';
3838

3939
state = {
4040
index: 0,

example/src/ExampleList.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as React from 'react';
44
import { FlatList } from 'react-native';
55
import { List, Divider, withTheme } from 'react-native-paper';
6+
import AppbarExample from './AppbarExample';
67
import BottomNavigationExample from './BottomNavigationExample';
78
import ButtonExample from './ButtonExample';
89
import CardExample from './CardExample';
@@ -11,19 +12,19 @@ import ChipExample from './ChipExample';
1112
import DialogExample from './DialogExample';
1213
import DividerExample from './DividerExample';
1314
import FABExample from './FABExample';
15+
import IconButtonExample from './IconButtonExample';
1416
import ListAccordionExample from './ListAccordionExample';
1517
import ListSectionExample from './ListSectionExample';
1618
import ProgressBarExample from './ProgressBarExample';
1719
import RadioButtonExample from './RadioButtonExample';
1820
import RadioButtonGroupExample from './RadioButtonGroupExample';
19-
import RippleExample from './RippleExample';
2021
import SearchbarExample from './SearchbarExample';
2122
import SnackbarExample from './SnackbarExample';
2223
import SurfaceExample from './SurfaceExample';
2324
import SwitchExample from './SwitchExample';
2425
import TextExample from './TextExample';
2526
import TextInputExample from './TextInputExample';
26-
import AppbarExample from './AppbarExample';
27+
import TouchableRippleExample from './TouchableRippleExample';
2728
import type { Theme } from 'react-native-paper/types';
2829

2930
type Props = {
@@ -41,18 +42,19 @@ export const examples = {
4142
dialog: DialogExample,
4243
divider: DividerExample,
4344
fab: FABExample,
45+
iconButton: IconButtonExample,
4446
listAccordion: ListAccordionExample,
4547
listSection: ListSectionExample,
4648
progressbar: ProgressBarExample,
4749
radio: RadioButtonExample,
4850
radioGroup: RadioButtonGroupExample,
49-
ripple: RippleExample,
5051
searchbar: SearchbarExample,
5152
snackbar: SnackbarExample,
5253
surface: SurfaceExample,
5354
switch: SwitchExample,
5455
text: TextExample,
5556
textInput: TextInputExample,
57+
touchableRipple: TouchableRippleExample,
5658
};
5759

5860
const data = Object.keys(examples).map(id => ({ id, data: examples[id] }));

example/src/IconButtonExample.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* @flow */
2+
3+
import * as React from 'react';
4+
import { View, StyleSheet } from 'react-native';
5+
import { IconButton, Colors, withTheme } from 'react-native-paper';
6+
import type { Theme } from 'react-native-paper/types';
7+
8+
type Props = {
9+
theme: Theme,
10+
};
11+
12+
type State = {
13+
loading: boolean,
14+
};
15+
16+
class ButtonExample extends React.Component<Props, State> {
17+
static title = 'Icon Button';
18+
19+
render() {
20+
const { colors } = this.props.theme;
21+
22+
return (
23+
<View style={[styles.container, { backgroundColor: colors.background }]}>
24+
<IconButton icon="add-a-photo" size={24} onPress={() => {}} />
25+
<IconButton
26+
icon="https"
27+
size={24}
28+
color={Colors.green500}
29+
onPress={() => {}}
30+
/>
31+
</View>
32+
);
33+
}
34+
}
35+
36+
const styles = StyleSheet.create({
37+
container: {
38+
flex: 1,
39+
flexDirection: 'row',
40+
padding: 8,
41+
},
42+
});
43+
44+
export default withTheme(ButtonExample);

example/src/ProgressBarExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type State = {
1414
};
1515

1616
class ProgressBarExample extends React.Component<Props, State> {
17-
static title = 'Progress bar';
17+
static title = 'Progress Bar';
1818

1919
state = {
2020
progress: 0,

example/src/RadioButtonExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type State = {
2020
};
2121

2222
class RadioButtonExample extends React.Component<Props, State> {
23-
static title = 'Radio button';
23+
static title = 'Radio Button';
2424

2525
state = {
2626
checked: 'normal',

example/src/RadioButtonGroupExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type State = {
1414
};
1515

1616
class RadioButtonGroupExample extends React.Component<Props, State> {
17-
static title = 'Radio button group';
17+
static title = 'Radio Button Group';
1818

1919
state = {
2020
value: 'first',

example/src/RippleExample.js renamed to example/src/TouchableRippleExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type Props = {
99
};
1010

1111
class RippleExample extends React.Component<Props> {
12-
static title = 'Ripples';
12+
static title = 'TouchableRipple';
1313

1414
render() {
1515
const {

src/components/Appbar/Appbar.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export const DEFAULT_APPBAR_HEIGHT = 56;
4949
* render() {
5050
* return (
5151
* <Appbar style={styles.bottom}>
52-
* <Appbar.Action icon="archive" onPress={() => {}} />
53-
* <Appbar.Action icon="mail" onPress={() => {}} />
54-
* <Appbar.Action icon="label" onPress={() => {}} />
55-
* <Appbar.Action icon="delete" onPress={() => {}} />
52+
* <Appbar.Action icon="archive" onPress={() => console.log('Pressed archive')} />
53+
* <Appbar.Action icon="mail" onPress={() => console.log('Pressed mail')} />
54+
* <Appbar.Action icon="label" onPress={() => console.log('Pressed label')} />
55+
* <Appbar.Action icon="delete" onPress={() => console.log('Pressed delete')} />
5656
* </Appbar>
5757
* );
5858
* }

src/components/Chip.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type State = {
9090
* import { Chip } from 'react-native-paper';
9191
*
9292
* const MyComponent = () => (
93-
* <Chip icon="info" onPress={() => {}}>Example Chip</Chip>
93+
* <Chip icon="info" onPress={() => console.log('Pressed')}>Example Chip</Chip>
9494
* );
9595
*
9696
* export default MyComponent;

src/components/FAB/FAB.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type Props = {
6969
* <FAB
7070
* small
7171
* icon="add"
72-
* onPress={() => {}}
72+
* onPress={() => console.log('Pressed')}
7373
* />
7474
* );
7575
*

src/components/FAB/FABGroup.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ type State = {
103103
* open={this.state.open}
104104
* icon={this.state.open ? 'today' : 'add'}
105105
* actions={[
106-
* { icon: 'add', onPress: () => {} },
107-
* { icon: 'star', label: 'Star', onPress: () => {} },
108-
* { icon: 'email', label: 'Email', onPress: () => {} },
109-
* { icon: 'notifications', label: 'Remind', onPress: () => {} },
106+
* { icon: 'add', onPress: () => console.log('Pressed add') },
107+
* { icon: 'star', label: 'Star', onPress: () => console.log('Pressed star')},
108+
* { icon: 'email', label: 'Email', onPress: () => console.log('Pressed email') },
109+
* { icon: 'notifications', label: 'Remind', onPress: () => console.log('Pressed notifications') },
110110
* ]}
111111
* onStateChange={({ open }) => this.setState({ open })}
112112
* onPress={() => {

0 commit comments

Comments
 (0)